tentacle.class.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Bibliotheca
  4. *
  5. * Copyright 2018-2023 Johannes Keßler
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.
  19. */
  20. /**
  21. * Class Tentacle
  22. * Tools management
  23. */
  24. class Tentacle {
  25. /**
  26. * the global DB object
  27. *
  28. * @var mysqli
  29. */
  30. private mysqli $_DB;
  31. /**
  32. * The user object to query with
  33. *
  34. * @var Doomguy
  35. */
  36. private Doomguy $_User;
  37. /**
  38. * Tentacle constructor.
  39. *
  40. * @param mysqli $databaseConnectionObject
  41. * @param Doomguy $userObj
  42. *
  43. */
  44. public function __construct(mysqli $databaseConnectionObject, Doomguy $userObj) {
  45. $this->_DB = $databaseConnectionObject;
  46. $this->_User = $userObj;
  47. }
  48. /**
  49. * Validate if given action is a valid tool and if the user has access
  50. *
  51. * @param string $identifier
  52. * @return array
  53. */
  54. public function validate(string $identifier): array {
  55. $ret = array();
  56. $queryStr = "SELECT `name`,`description`,`action`
  57. FROM `".DB_PREFIX."_tool`
  58. WHERE ".$this->_User->getSQLRightsString()."
  59. AND `action` = '".$this->_DB->real_escape_string($identifier)."'";
  60. if(QUERY_DEBUG) Summoner::sysLog("[QUERY] ".__METHOD__." query: ".Summoner::cleanForLog($queryStr));
  61. try {
  62. $query = $this->_DB->query($queryStr);
  63. if ($query !== false && $query->num_rows > 0) {
  64. $ret = $query->fetch_assoc();
  65. }
  66. } catch (Exception $e) {
  67. Summoner::cleanForLog("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
  68. if(QUERY_DEBUG) Summoner::sysLog("[DEBUG] ".__METHOD__." mysql query: ".$queryStr);
  69. }
  70. return $ret;
  71. }
  72. /**
  73. * Default creation info based on current user
  74. *
  75. * @return array
  76. */
  77. public function getDefaultCreationInfo(): array {
  78. return array(
  79. 'id' => $this->_User->param('id'),
  80. 'group' => $this->_User->param('baseGroupId'),
  81. 'rights' => 'rwxrwxr--'
  82. );
  83. }
  84. }