@@ -27,44 +27,44 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Validator_Password implements Validator_Base { |
| 29 | 29 | |
| 30 | - public function isValide($value): bool { |
|
| 31 | - $valide = true; |
|
| 30 | + public function isValide($value): bool { |
|
| 31 | + $valide = true; |
|
| 32 | 32 | |
| 33 | - //throw event, so plugins like pwned can interact |
|
| 34 | - Events::throwEvent("validate_password", array( |
|
| 35 | - 'password' => &$value, |
|
| 36 | - 'valide' => &$valide |
|
| 37 | - )); |
|
| 33 | + //throw event, so plugins like pwned can interact |
|
| 34 | + Events::throwEvent("validate_password", array( |
|
| 35 | + 'password' => &$value, |
|
| 36 | + 'valide' => &$valide |
|
| 37 | + )); |
|
| 38 | 38 | |
| 39 | - if (!$valide) { |
|
| 40 | - return false; |
|
| 41 | - } |
|
| 39 | + if (!$valide) { |
|
| 40 | + return false; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - if (strlen($value) < Settings::get("password_min_length", 6)) { |
|
| 44 | - return false; |
|
| 45 | - } |
|
| 43 | + if (strlen($value) < Settings::get("password_min_length", 6)) { |
|
| 44 | + return false; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - if (strlen($value) > Settings::get("password_max_length", 64)) { |
|
| 48 | - //more than 64 characters arent supported |
|
| 49 | - return false; |
|
| 50 | - } |
|
| 47 | + if (strlen($value) > Settings::get("password_max_length", 64)) { |
|
| 48 | + //more than 64 characters arent supported |
|
| 49 | + return false; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - //everything is allowed |
|
| 53 | - return true; |
|
| 54 | - } |
|
| 52 | + //everything is allowed |
|
| 53 | + return true; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function validate($value) { |
|
| 57 | - if ($this->isValide($value)) { |
|
| 58 | - return $value; |
|
| 59 | - } else { |
|
| 60 | - throw new SecurityException("password is not valide!"); |
|
| 61 | - } |
|
| 62 | - } |
|
| 56 | + public function validate($value) { |
|
| 57 | + if ($this->isValide($value)) { |
|
| 58 | + return $value; |
|
| 59 | + } else { |
|
| 60 | + throw new SecurityException("password is not valide!"); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - public static function get (string $value) : string { |
|
| 65 | - $obj = new Validator_Password(); |
|
| 66 | - return $obj->validate($value); |
|
| 67 | - } |
|
| 64 | + public static function get (string $value) : string { |
|
| 65 | + $obj = new Validator_Password(); |
|
| 66 | + return $obj->validate($value); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | } |
| 70 | 70 | |
@@ -27,126 +27,126 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Permissions { |
| 29 | 29 | |
| 30 | - public static function createOrUpdateCategory (string $category, string $title, int $order = 100, string $area = "global") { |
|
| 31 | - //validate values |
|
| 32 | - $category = Validator_AlphaNumeric::get($category); |
|
| 33 | - $title = Validator_AlphaNumeric::get($category); |
|
| 34 | - $area = Validator_AlphaNumeric::get($area); |
|
| 35 | - $order = intval($order); |
|
| 36 | - |
|
| 37 | - Database::getInstance()->execute("INSERT INTO `{praefix}permission_category` ( |
|
| 30 | + public static function createOrUpdateCategory (string $category, string $title, int $order = 100, string $area = "global") { |
|
| 31 | + //validate values |
|
| 32 | + $category = Validator_AlphaNumeric::get($category); |
|
| 33 | + $title = Validator_AlphaNumeric::get($category); |
|
| 34 | + $area = Validator_AlphaNumeric::get($area); |
|
| 35 | + $order = intval($order); |
|
| 36 | + |
|
| 37 | + Database::getInstance()->execute("INSERT INTO `{praefix}permission_category` ( |
|
| 38 | 38 | `category`, `title`, `area`, `show`, `order`, `activated` |
| 39 | 39 | ) VALUES ( |
| 40 | 40 | :category, :title, :area, '1', :order, '1' |
| 41 | 41 | ) ON DUPLICATE KEY UPDATE `title` = :title, `area` = :area, `order` = :order, `activated` = '1'; ", array( |
| 42 | - 'category' => $category, |
|
| 43 | - 'title' => $title, |
|
| 44 | - 'area' => $area, |
|
| 45 | - 'order' => $order |
|
| 46 | - )); |
|
| 47 | - |
|
| 48 | - //clear cache |
|
| 49 | - Cache::clear("permissions", "categories"); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public static function deleteCategory (string $category) { |
|
| 53 | - //validate value |
|
| 54 | - $category = Validator_AlphaNumeric::get($category); |
|
| 55 | - |
|
| 56 | - //delete from database |
|
| 57 | - Database::getInstance()->execute("DELETE FROM `{praefix}permission_category` WHERE `category` = :category; ", array('category' => $category)); |
|
| 58 | - |
|
| 59 | - //clear cache |
|
| 60 | - Cache::clear("permissions", "categories"); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public static function createPermission (string $token, string $title, string $description, string $category = "general", string $owner = "system", int $order = 100) { |
|
| 64 | - //validate values |
|
| 65 | - $token = Validator_Token::get($token); |
|
| 66 | - $title = Validator_String::get($title); |
|
| 67 | - $description = Validator_String::get($description); |
|
| 68 | - $category = Validator_Filename::get($category); |
|
| 69 | - $owner = Validator_AlphaNumeric::get($owner); |
|
| 70 | - $order = intval($order); |
|
| 71 | - |
|
| 72 | - Database::getInstance()->execute("INSERT INTO `{praefix}permissions` ( |
|
| 42 | + 'category' => $category, |
|
| 43 | + 'title' => $title, |
|
| 44 | + 'area' => $area, |
|
| 45 | + 'order' => $order |
|
| 46 | + )); |
|
| 47 | + |
|
| 48 | + //clear cache |
|
| 49 | + Cache::clear("permissions", "categories"); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public static function deleteCategory (string $category) { |
|
| 53 | + //validate value |
|
| 54 | + $category = Validator_AlphaNumeric::get($category); |
|
| 55 | + |
|
| 56 | + //delete from database |
|
| 57 | + Database::getInstance()->execute("DELETE FROM `{praefix}permission_category` WHERE `category` = :category; ", array('category' => $category)); |
|
| 58 | + |
|
| 59 | + //clear cache |
|
| 60 | + Cache::clear("permissions", "categories"); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public static function createPermission (string $token, string $title, string $description, string $category = "general", string $owner = "system", int $order = 100) { |
|
| 64 | + //validate values |
|
| 65 | + $token = Validator_Token::get($token); |
|
| 66 | + $title = Validator_String::get($title); |
|
| 67 | + $description = Validator_String::get($description); |
|
| 68 | + $category = Validator_Filename::get($category); |
|
| 69 | + $owner = Validator_AlphaNumeric::get($owner); |
|
| 70 | + $order = intval($order); |
|
| 71 | + |
|
| 72 | + Database::getInstance()->execute("INSERT INTO `{praefix}permissions` ( |
|
| 73 | 73 | `token`, `title`, `description`, `category`, `owner`, `show`, `order`, `activated` |
| 74 | 74 | ) VALUES ( |
| 75 | 75 | :token, :title, :description, :category, :owner, '1', :order, '1' |
| 76 | 76 | ) ON DUPLICATE KEY UPDATE `title` = :title, `description` = :description, `category` = :category, `owner` = :owner, `order` = :order, `activated` = '1'; ", array( |
| 77 | - 'token' => $token, |
|
| 78 | - 'title' => $title, |
|
| 79 | - 'description' => $description, |
|
| 80 | - 'category' => $category, |
|
| 81 | - 'owner' => $owner, |
|
| 82 | - 'order' => $order |
|
| 83 | - )); |
|
| 84 | - |
|
| 85 | - //clear cache |
|
| 86 | - Cache::clear("permissions", "permission_list"); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public static function deletePermission (string $token) { |
|
| 90 | - //validate value |
|
| 91 | - $token = Validator_Token::get($token); |
|
| 92 | - |
|
| 93 | - //delete from database |
|
| 94 | - Database::getInstance()->execute("DELETE FROM `{praefix}permissions` WHERE `token` = :token; ", array('token' => $token)); |
|
| 95 | - |
|
| 96 | - //cleanup group and user rights table |
|
| 97 | - self::deletePermissionsInGroupAndUserTable($token); |
|
| 98 | - |
|
| 99 | - //clear cache |
|
| 100 | - Cache::clear("permissions", "permission_list"); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - public static function deletePermissionsByOwner (string $owner) { |
|
| 104 | - //cleanup group and user permissions with this specific tokens |
|
| 105 | - Database::getInstance()->execute("DELETE `{praefix}group_rights` FROM `{praefix}group_rights` INNER JOIN `{praefix}permissions` ON `{praefix}permissions`.`token` = `{praefix}group_rights`.`token` WHERE `{praefix}permissions`.`owner` = :owner; ", array( |
|
| 106 | - 'owner' => $owner |
|
| 107 | - )); |
|
| 108 | - |
|
| 109 | - //cleanup group and user permissions with this specific tokens |
|
| 110 | - Database::getInstance()->execute("DELETE `{praefix}user_rights` FROM `{praefix}user_rights` INNER JOIN `{praefix}permissions` ON `{praefix}permissions`.`token` = `{praefix}user_rights`.`token` WHERE `{praefix}permissions`.`owner` = :owner; ", array( |
|
| 111 | - 'owner' => $owner |
|
| 112 | - )); |
|
| 113 | - |
|
| 114 | - //delete from database |
|
| 115 | - Database::getInstance()->execute("DELETE FROM `{praefix}permissions` WHERE `owner` = :owner; ", array('owner' => $owner)); |
|
| 116 | - |
|
| 117 | - //clear cache |
|
| 118 | - Cache::clear("permissions", "permission_list"); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - protected static function deletePermissionsInGroupAndUserTable (string $token) { |
|
| 122 | - //delete permission in groups table |
|
| 123 | - Database::getInstance()->execute("DELETE FROM `{praefix}group_rights` WHERE `token` = :token; ", array('token' => $token)); |
|
| 124 | - |
|
| 125 | - //delete permission in user table |
|
| 126 | - Database::getInstance()->execute("DELETE FROM `{praefix}user_rights` WHERE `token` = :token; ", array('token' => $token)); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - public static function listPermissions (string $category = "") : array { |
|
| 130 | - $suffix = ""; |
|
| 131 | - |
|
| 132 | - if ($category != "") { |
|
| 133 | - $suffix = "_" . Validator_AlphaNumeric::get($category); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - if (Cache::contains("permissions", "permission_list" . $suffix)) { |
|
| 137 | - return Cache::get("permissions", "permission_list" . $suffix); |
|
| 138 | - } else { |
|
| 139 | - if ($category == "") { |
|
| 140 | - $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}permissions` WHERE `activated` = '1' ORDER BY `order`; "); |
|
| 141 | - } else { |
|
| 142 | - $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}permissions` WHERE `category` = :category, AND `activated` = '1' ORDER BY `order`; ", array('category' => $category)); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - Cache::put("permissions", "permission_list" . $suffix, $rows); |
|
| 146 | - |
|
| 147 | - return $rows; |
|
| 148 | - } |
|
| 149 | - } |
|
| 77 | + 'token' => $token, |
|
| 78 | + 'title' => $title, |
|
| 79 | + 'description' => $description, |
|
| 80 | + 'category' => $category, |
|
| 81 | + 'owner' => $owner, |
|
| 82 | + 'order' => $order |
|
| 83 | + )); |
|
| 84 | + |
|
| 85 | + //clear cache |
|
| 86 | + Cache::clear("permissions", "permission_list"); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public static function deletePermission (string $token) { |
|
| 90 | + //validate value |
|
| 91 | + $token = Validator_Token::get($token); |
|
| 92 | + |
|
| 93 | + //delete from database |
|
| 94 | + Database::getInstance()->execute("DELETE FROM `{praefix}permissions` WHERE `token` = :token; ", array('token' => $token)); |
|
| 95 | + |
|
| 96 | + //cleanup group and user rights table |
|
| 97 | + self::deletePermissionsInGroupAndUserTable($token); |
|
| 98 | + |
|
| 99 | + //clear cache |
|
| 100 | + Cache::clear("permissions", "permission_list"); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + public static function deletePermissionsByOwner (string $owner) { |
|
| 104 | + //cleanup group and user permissions with this specific tokens |
|
| 105 | + Database::getInstance()->execute("DELETE `{praefix}group_rights` FROM `{praefix}group_rights` INNER JOIN `{praefix}permissions` ON `{praefix}permissions`.`token` = `{praefix}group_rights`.`token` WHERE `{praefix}permissions`.`owner` = :owner; ", array( |
|
| 106 | + 'owner' => $owner |
|
| 107 | + )); |
|
| 108 | + |
|
| 109 | + //cleanup group and user permissions with this specific tokens |
|
| 110 | + Database::getInstance()->execute("DELETE `{praefix}user_rights` FROM `{praefix}user_rights` INNER JOIN `{praefix}permissions` ON `{praefix}permissions`.`token` = `{praefix}user_rights`.`token` WHERE `{praefix}permissions`.`owner` = :owner; ", array( |
|
| 111 | + 'owner' => $owner |
|
| 112 | + )); |
|
| 113 | + |
|
| 114 | + //delete from database |
|
| 115 | + Database::getInstance()->execute("DELETE FROM `{praefix}permissions` WHERE `owner` = :owner; ", array('owner' => $owner)); |
|
| 116 | + |
|
| 117 | + //clear cache |
|
| 118 | + Cache::clear("permissions", "permission_list"); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + protected static function deletePermissionsInGroupAndUserTable (string $token) { |
|
| 122 | + //delete permission in groups table |
|
| 123 | + Database::getInstance()->execute("DELETE FROM `{praefix}group_rights` WHERE `token` = :token; ", array('token' => $token)); |
|
| 124 | + |
|
| 125 | + //delete permission in user table |
|
| 126 | + Database::getInstance()->execute("DELETE FROM `{praefix}user_rights` WHERE `token` = :token; ", array('token' => $token)); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + public static function listPermissions (string $category = "") : array { |
|
| 130 | + $suffix = ""; |
|
| 131 | + |
|
| 132 | + if ($category != "") { |
|
| 133 | + $suffix = "_" . Validator_AlphaNumeric::get($category); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + if (Cache::contains("permissions", "permission_list" . $suffix)) { |
|
| 137 | + return Cache::get("permissions", "permission_list" . $suffix); |
|
| 138 | + } else { |
|
| 139 | + if ($category == "") { |
|
| 140 | + $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}permissions` WHERE `activated` = '1' ORDER BY `order`; "); |
|
| 141 | + } else { |
|
| 142 | + $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}permissions` WHERE `category` = :category, AND `activated` = '1' ORDER BY `order`; ", array('category' => $category)); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + Cache::put("permissions", "permission_list" . $suffix, $rows); |
|
| 146 | + |
|
| 147 | + return $rows; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | 151 | } |
| 152 | 152 | |
@@ -27,52 +27,52 @@ |
||
| 27 | 27 | |
| 28 | 28 | class FilePermissionsInstaller extends PluginInstaller_Plugin { |
| 29 | 29 | |
| 30 | - public function install(Plugin $plugin, array $install_json): bool { |
|
| 31 | - if (isset($install_json['chmod'])) { |
|
| 32 | - $files = $install_json['chmod']; |
|
| 30 | + public function install(Plugin $plugin, array $install_json): bool { |
|
| 31 | + if (isset($install_json['chmod'])) { |
|
| 32 | + $files = $install_json['chmod']; |
|
| 33 | 33 | |
| 34 | - foreach ($files as $file=>$chmod_value) { |
|
| 35 | - if (strpos($file, "..") !== FALSE) { |
|
| 36 | - throw new IllegalArgumentException("Its not allowed that chmod file path in install.json of plugin '" . $plugin->getName() . "' contains '..' in path."); |
|
| 37 | - } |
|
| 34 | + foreach ($files as $file=>$chmod_value) { |
|
| 35 | + if (strpos($file, "..") !== FALSE) { |
|
| 36 | + throw new IllegalArgumentException("Its not allowed that chmod file path in install.json of plugin '" . $plugin->getName() . "' contains '..' in path."); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - $file_path = ROOT_PATH . $file; |
|
| 39 | + $file_path = ROOT_PATH . $file; |
|
| 40 | 40 | |
| 41 | - if (!file_exists($file_path)) { |
|
| 42 | - //create directory |
|
| 43 | - throw new IllegalStateException("directory '" . htmlentities($file_path) . "' doesnt exists."); |
|
| 41 | + if (!file_exists($file_path)) { |
|
| 42 | + //create directory |
|
| 43 | + throw new IllegalStateException("directory '" . htmlentities($file_path) . "' doesnt exists."); |
|
| 44 | 44 | |
| 45 | - //TODO: remove this line later |
|
| 46 | - //mkdir($file_path); |
|
| 47 | - } |
|
| 45 | + //TODO: remove this line later |
|
| 46 | + //mkdir($file_path); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - if (strlen($chmod_value) != 3) { |
|
| 50 | - throw new IllegalArgumentException("Exception in install.json of plugin '" . $plugin->getName() . "': chmod value has to be a length of 3 characters (like 755)."); |
|
| 51 | - } |
|
| 49 | + if (strlen($chmod_value) != 3) { |
|
| 50 | + throw new IllegalArgumentException("Exception in install.json of plugin '" . $plugin->getName() . "': chmod value has to be a length of 3 characters (like 755)."); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - $chmod_value = "0" . $chmod_value; |
|
| 53 | + $chmod_value = "0" . $chmod_value; |
|
| 54 | 54 | |
| 55 | - if(!chmod($file_path, $chmod_value)) { |
|
| 56 | - throw new IllegalStateException("Cannot change file permissions of directory '". $file_path . "' (plugin: " . $plugin->getName() . "."); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - } |
|
| 55 | + if(!chmod($file_path, $chmod_value)) { |
|
| 56 | + throw new IllegalStateException("Cannot change file permissions of directory '". $file_path . "' (plugin: " . $plugin->getName() . "."); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - return true; |
|
| 62 | - } |
|
| 61 | + return true; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - public function uninstall(Plugin $plugin, array $install_json): bool { |
|
| 65 | - //dont do anything |
|
| 66 | - return true; |
|
| 67 | - } |
|
| 64 | + public function uninstall(Plugin $plugin, array $install_json): bool { |
|
| 65 | + //dont do anything |
|
| 66 | + return true; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public function upgrade(Plugin $plugin, array $install_json): bool { |
|
| 70 | - return $this->install($plugin, $install_json); |
|
| 71 | - } |
|
| 69 | + public function upgrade(Plugin $plugin, array $install_json): bool { |
|
| 70 | + return $this->install($plugin, $install_json); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function getPriority () : int { |
|
| 74 | - return 5; |
|
| 75 | - } |
|
| 73 | + public function getPriority () : int { |
|
| 74 | + return 5; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | } |
| 78 | 78 | |
@@ -27,20 +27,20 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | class SendMailPage extends PageType { |
| 29 | 29 | |
| 30 | - public function getAdditionalHeaderCode(): string { |
|
| 31 | - $base_url = DomainUtils::getBaseURL() . "/"; |
|
| 30 | + public function getAdditionalHeaderCode(): string { |
|
| 31 | + $base_url = DomainUtils::getBaseURL() . "/"; |
|
| 32 | 32 | |
| 33 | - return "<!-- iCheck --> |
|
| 33 | + return "<!-- iCheck --> |
|
| 34 | 34 | <link rel=\"stylesheet\" href=\"" . $base_url . "styles/admin/plugins/iCheck/flat/blue.css\"> |
| 35 | 35 | |
| 36 | 36 | <!-- bootstrap wysihtml5 - text editor --> |
| 37 | 37 | <link rel=\"stylesheet\" href=\"" . $base_url . "styles/admin/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css\">"; |
| 38 | - } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function getFooterScripts(): string { |
|
| 41 | - $base_url = DomainUtils::getBaseURL() . "/"; |
|
| 40 | + public function getFooterScripts(): string { |
|
| 41 | + $base_url = DomainUtils::getBaseURL() . "/"; |
|
| 42 | 42 | |
| 43 | - return "<!-- iCheck --> |
|
| 43 | + return "<!-- iCheck --> |
|
| 44 | 44 | <script src=\"" . $base_url . "styles/admin/plugins/iCheck/icheck.min.js\"></script> |
| 45 | 45 | <!-- Bootstrap WYSIHTML5 --> |
| 46 | 46 | <script src=\"" . $base_url . "styles/admin/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js\"></script> |
@@ -59,79 +59,79 @@ discard block |
||
| 59 | 59 | }); |
| 60 | 60 | }); |
| 61 | 61 | </script>"; |
| 62 | - } |
|
| 63 | - |
|
| 64 | - public function getContent(): string { |
|
| 65 | - $template = new DwooTemplate("pages/sendmail"); |
|
| 66 | - |
|
| 67 | - $template->assign("form_action", DomainUtils::generateURL("admin/sendmail")); |
|
| 68 | - $template->assign("content", ""); |
|
| 69 | - |
|
| 70 | - if (isset($_REQUEST['submit'])) { |
|
| 71 | - //first, check csrf token |
|
| 72 | - if (!Security::checkCSRFToken()) { |
|
| 73 | - $template->assign("error_message", "Wrong CSRF token!"); |
|
| 74 | - |
|
| 75 | - if (isset($_POST['content'])) { |
|
| 76 | - $template->assign("content", $_POST['content']); |
|
| 77 | - } |
|
| 78 | - } else { |
|
| 79 | - $required_fields = array("to_mail", "subject", "content"); |
|
| 80 | - |
|
| 81 | - foreach ($required_fields as $field) { |
|
| 82 | - if (!isset($_POST[$field]) || empty($_POST[$field])) { |
|
| 83 | - $template->assign("error_message", "Please complete form!"); |
|
| 84 | - |
|
| 85 | - if (isset($_POST['content'])) { |
|
| 86 | - $template->assign("content", $_POST['content']); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return $template->getCode(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - //form is complete |
|
| 94 | - |
|
| 95 | - //get values |
|
| 96 | - $to_mail = $_POST['to_mail']; |
|
| 97 | - $subject = $_POST['subject']; |
|
| 98 | - $content = $_POST['content']; |
|
| 99 | - |
|
| 100 | - //check, if mail is valide |
|
| 101 | - if (!(new Validator_Mail())->isValide($to_mail)) { |
|
| 102 | - $template->assign("error_message", "Mail is not valide!"); |
|
| 103 | - |
|
| 104 | - if (isset($_POST['content'])) { |
|
| 105 | - $template->assign("content", $_POST['content']); |
|
| 106 | - } |
|
| 107 | - } else if (!(new Validator_String())->isValide($subject)) { |
|
| 108 | - $template->assign("error_message", "Subject is not valide!"); |
|
| 109 | - |
|
| 110 | - if (isset($_POST['content'])) { |
|
| 111 | - $template->assign("content", $_POST['content']); |
|
| 112 | - } |
|
| 113 | - } else { |
|
| 114 | - //parameters are valide, send mail |
|
| 115 | - |
|
| 116 | - if (MailApi::sendHTMLMail($to_mail, $subject, $content)) { |
|
| 117 | - $template->assign("success_message", "Mail sended successfully!"); |
|
| 118 | - } else { |
|
| 119 | - $template->assign("error_message", "Sending of mail failed!"); |
|
| 120 | - |
|
| 121 | - if (isset($_POST['content'])) { |
|
| 122 | - $template->assign("content", $_POST['content']); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - return $template->getCode(); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - public function listRequiredPermissions(): array { |
|
| 133 | - return array("can_send_board_mails"); |
|
| 134 | - } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + public function getContent(): string { |
|
| 65 | + $template = new DwooTemplate("pages/sendmail"); |
|
| 66 | + |
|
| 67 | + $template->assign("form_action", DomainUtils::generateURL("admin/sendmail")); |
|
| 68 | + $template->assign("content", ""); |
|
| 69 | + |
|
| 70 | + if (isset($_REQUEST['submit'])) { |
|
| 71 | + //first, check csrf token |
|
| 72 | + if (!Security::checkCSRFToken()) { |
|
| 73 | + $template->assign("error_message", "Wrong CSRF token!"); |
|
| 74 | + |
|
| 75 | + if (isset($_POST['content'])) { |
|
| 76 | + $template->assign("content", $_POST['content']); |
|
| 77 | + } |
|
| 78 | + } else { |
|
| 79 | + $required_fields = array("to_mail", "subject", "content"); |
|
| 80 | + |
|
| 81 | + foreach ($required_fields as $field) { |
|
| 82 | + if (!isset($_POST[$field]) || empty($_POST[$field])) { |
|
| 83 | + $template->assign("error_message", "Please complete form!"); |
|
| 84 | + |
|
| 85 | + if (isset($_POST['content'])) { |
|
| 86 | + $template->assign("content", $_POST['content']); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return $template->getCode(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + //form is complete |
|
| 94 | + |
|
| 95 | + //get values |
|
| 96 | + $to_mail = $_POST['to_mail']; |
|
| 97 | + $subject = $_POST['subject']; |
|
| 98 | + $content = $_POST['content']; |
|
| 99 | + |
|
| 100 | + //check, if mail is valide |
|
| 101 | + if (!(new Validator_Mail())->isValide($to_mail)) { |
|
| 102 | + $template->assign("error_message", "Mail is not valide!"); |
|
| 103 | + |
|
| 104 | + if (isset($_POST['content'])) { |
|
| 105 | + $template->assign("content", $_POST['content']); |
|
| 106 | + } |
|
| 107 | + } else if (!(new Validator_String())->isValide($subject)) { |
|
| 108 | + $template->assign("error_message", "Subject is not valide!"); |
|
| 109 | + |
|
| 110 | + if (isset($_POST['content'])) { |
|
| 111 | + $template->assign("content", $_POST['content']); |
|
| 112 | + } |
|
| 113 | + } else { |
|
| 114 | + //parameters are valide, send mail |
|
| 115 | + |
|
| 116 | + if (MailApi::sendHTMLMail($to_mail, $subject, $content)) { |
|
| 117 | + $template->assign("success_message", "Mail sended successfully!"); |
|
| 118 | + } else { |
|
| 119 | + $template->assign("error_message", "Sending of mail failed!"); |
|
| 120 | + |
|
| 121 | + if (isset($_POST['content'])) { |
|
| 122 | + $template->assign("content", $_POST['content']); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + return $template->getCode(); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + public function listRequiredPermissions(): array { |
|
| 133 | + return array("can_send_board_mails"); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | } |
| 137 | 137 | |
@@ -27,15 +27,15 @@ |
||
| 27 | 27 | |
| 28 | 28 | class ClearCachePage extends PageType { |
| 29 | 29 | |
| 30 | - public function getContent(): string { |
|
| 31 | - Registry::singleton()->setSetting("clear_cache", true); |
|
| 30 | + public function getContent(): string { |
|
| 31 | + Registry::singleton()->setSetting("clear_cache", true); |
|
| 32 | 32 | |
| 33 | - $template = new DwooTemplate("pages/clearcache"); |
|
| 33 | + $template = new DwooTemplate("pages/clearcache"); |
|
| 34 | 34 | |
| 35 | - $template->assign("success_message", "Cache cleared successfully!"); |
|
| 35 | + $template->assign("success_message", "Cache cleared successfully!"); |
|
| 36 | 36 | |
| 37 | - return $template->getCode(); |
|
| 38 | - } |
|
| 37 | + return $template->getCode(); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | } |
| 41 | 41 | |
@@ -17,8 +17,8 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined("PLUGIN_INSTALLER")) { |
| 20 | - echo "You cannot access this file directly!"; |
|
| 21 | - exit; |
|
| 20 | + echo "You cannot access this file directly!"; |
|
| 21 | + exit; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -26,8 +26,8 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | 28 | if (!defined("PLUGIN_INSTALLER")) { |
| 29 | - echo "You cannot access this file directly!"; |
|
| 30 | - exit; |
|
| 29 | + echo "You cannot access this file directly!"; |
|
| 30 | + exit; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | //delete plugin tables |
@@ -11,176 +11,176 @@ |
||
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | public static function isModRewriteAvailable () { |
| 14 | - if (function_exists("apache_get_modules")) { |
|
| 15 | - if (in_array('mod_rewrite',apache_get_modules())) { |
|
| 16 | - return true; |
|
| 17 | - } |
|
| 14 | + if (function_exists("apache_get_modules")) { |
|
| 15 | + if (in_array('mod_rewrite',apache_get_modules())) { |
|
| 16 | + return true; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - return false; |
|
| 20 | - } |
|
| 19 | + return false; |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - return false; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public static function startsWith ($haystack, $needle) : bool { |
|
| 26 | - //https://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php |
|
| 22 | + return false; |
|
| 23 | + } |
|
| 27 | 24 | |
| 28 | - $length = strlen($needle); |
|
| 29 | - return (substr($haystack, 0, $length) === $needle); |
|
| 30 | - } |
|
| 25 | + public static function startsWith ($haystack, $needle) : bool { |
|
| 26 | + //https://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php |
|
| 31 | 27 | |
| 32 | - public static function endsWith ($haystack, $needle) : bool { |
|
| 33 | - $length = strlen($needle); |
|
| 28 | + $length = strlen($needle); |
|
| 29 | + return (substr($haystack, 0, $length) === $needle); |
|
| 30 | + } |
|
| 34 | 31 | |
| 35 | - return $length === 0 || (substr($haystack, -$length) === $needle); |
|
| 36 | - } |
|
| 32 | + public static function endsWith ($haystack, $needle) : bool { |
|
| 33 | + $length = strlen($needle); |
|
| 37 | 34 | |
| 38 | - /** |
|
| 39 | - * get IP address of client browser |
|
| 40 | - * |
|
| 41 | - * @return IPv4 / IPv6 address (up to 45 characters) |
|
| 42 | - */ |
|
| 43 | - public static function getClientIP () : string { |
|
| 44 | - //https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php |
|
| 35 | + return $length === 0 || (substr($haystack, -$length) === $needle); |
|
| 36 | + } |
|
| 45 | 37 | |
| 46 | - $ip = ""; |
|
| 38 | + /** |
|
| 39 | + * get IP address of client browser |
|
| 40 | + * |
|
| 41 | + * @return IPv4 / IPv6 address (up to 45 characters) |
|
| 42 | + */ |
|
| 43 | + public static function getClientIP () : string { |
|
| 44 | + //https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php |
|
| 45 | + |
|
| 46 | + $ip = ""; |
|
| 47 | + |
|
| 48 | + if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
| 49 | + $ip = $_SERVER['HTTP_CLIENT_IP']; |
|
| 50 | + } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 51 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 52 | + } else { |
|
| 53 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return $ip; |
|
| 57 | + } |
|
| 47 | 58 | |
| 48 | - if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
| 49 | - $ip = $_SERVER['HTTP_CLIENT_IP']; |
|
| 50 | - } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 51 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 52 | - } else { |
|
| 53 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 54 | - } |
|
| 59 | + public static function strEqs (string $str1, string $str2) : bool { |
|
| 60 | + return strcmp($str1, $str2) === 0; |
|
| 61 | + } |
|
| 55 | 62 | |
| 56 | - return $ip; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public static function strEqs (string $str1, string $str2) : bool { |
|
| 60 | - return strcmp($str1, $str2) === 0; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Generate a random string, using a cryptographically secure |
|
| 65 | - * pseudorandom number generator (random_int) |
|
| 66 | - * |
|
| 67 | - * For PHP 7, random_int is a PHP core function |
|
| 68 | - * For PHP 5.x, depends on https://github.com/paragonie/random_compat |
|
| 69 | - * |
|
| 70 | - * @param int $length How many characters do we want? |
|
| 71 | - * @param string $keyspace A string of all possible characters |
|
| 72 | - * to select from |
|
| 73 | - * |
|
| 74 | - * @link https://stackoverflow.com/questions/4356289/php-random-string-generator/31107425#31107425 |
|
| 75 | - * |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public static function randomString(int $length, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') : string { |
|
| 79 | - $str = ''; |
|
| 80 | - $max = mb_strlen($keyspace, '8bit') - 1; |
|
| 81 | - |
|
| 82 | - for ($i = 0; $i < $length; ++$i) { |
|
| 83 | - $str .= $keyspace[random_int(0, $max)]; |
|
| 84 | - } |
|
| 63 | + /** |
|
| 64 | + * Generate a random string, using a cryptographically secure |
|
| 65 | + * pseudorandom number generator (random_int) |
|
| 66 | + * |
|
| 67 | + * For PHP 7, random_int is a PHP core function |
|
| 68 | + * For PHP 5.x, depends on https://github.com/paragonie/random_compat |
|
| 69 | + * |
|
| 70 | + * @param int $length How many characters do we want? |
|
| 71 | + * @param string $keyspace A string of all possible characters |
|
| 72 | + * to select from |
|
| 73 | + * |
|
| 74 | + * @link https://stackoverflow.com/questions/4356289/php-random-string-generator/31107425#31107425 |
|
| 75 | + * |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public static function randomString(int $length, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') : string { |
|
| 79 | + $str = ''; |
|
| 80 | + $max = mb_strlen($keyspace, '8bit') - 1; |
|
| 81 | + |
|
| 82 | + for ($i = 0; $i < $length; ++$i) { |
|
| 83 | + $str .= $keyspace[random_int(0, $max)]; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return $str; |
|
| 87 | + } |
|
| 85 | 88 | |
| 86 | - return $str; |
|
| 87 | - } |
|
| 89 | + public static function getHostname () : string { |
|
| 90 | + if (function_exists("gethostname")) { |
|
| 91 | + return gethostname(); |
|
| 92 | + } else { |
|
| 93 | + //Or, an option that also works before PHP 5.3 |
|
| 94 | + return php_uname('n'); |
|
| 95 | + } |
|
| 96 | + } |
|
| 88 | 97 | |
| 89 | - public static function getHostname () : string { |
|
| 90 | - if (function_exists("gethostname")) { |
|
| 91 | - return gethostname(); |
|
| 92 | - } else { |
|
| 93 | - //Or, an option that also works before PHP 5.3 |
|
| 94 | - return php_uname('n'); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - public static function sendPOSTRequest (string $url, array $data = array()) { |
|
| 99 | - //check, if allow_url_fopen is enabled |
|
| 100 | - if (PHPUtils::isUrlfopenEnabled()) { |
|
| 101 | - // use key 'http' even if you send the request to https://... |
|
| 102 | - $options = array( |
|
| 103 | - 'http' => array( |
|
| 104 | - 'header' => "Content-type: application/x-www-form-urlencoded\r\n", |
|
| 105 | - 'method' => 'POST', |
|
| 106 | - 'content' => http_build_query($data) |
|
| 107 | - ) |
|
| 108 | - ); |
|
| 109 | - $context = stream_context_create($options); |
|
| 110 | - $result = file_get_contents($url, false, $context); |
|
| 111 | - |
|
| 112 | - if ($result === FALSE) { |
|
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return $result; |
|
| 117 | - } else { |
|
| 118 | - //try to use curl instead |
|
| 119 | - |
|
| 120 | - //https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa |
|
| 121 | - |
|
| 122 | - //create a new curl session |
|
| 123 | - $ch = curl_init(); |
|
| 124 | - |
|
| 125 | - curl_setopt($ch, CURLOPT_URL, $url); |
|
| 126 | - curl_setopt($ch, CURLOPT_POST, 1); |
|
| 127 | - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));//"postvar1=value1&postvar2=value2&postvar3=value3" |
|
| 128 | - |
|
| 129 | - //receive server response |
|
| 130 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 131 | - $result = curl_exec ($ch); |
|
| 132 | - |
|
| 133 | - //close curl session |
|
| 134 | - curl_close ($ch); |
|
| 135 | - |
|
| 136 | - return $result; |
|
| 137 | - } |
|
| 138 | - } |
|
| 98 | + public static function sendPOSTRequest (string $url, array $data = array()) { |
|
| 99 | + //check, if allow_url_fopen is enabled |
|
| 100 | + if (PHPUtils::isUrlfopenEnabled()) { |
|
| 101 | + // use key 'http' even if you send the request to https://... |
|
| 102 | + $options = array( |
|
| 103 | + 'http' => array( |
|
| 104 | + 'header' => "Content-type: application/x-www-form-urlencoded\r\n", |
|
| 105 | + 'method' => 'POST', |
|
| 106 | + 'content' => http_build_query($data) |
|
| 107 | + ) |
|
| 108 | + ); |
|
| 109 | + $context = stream_context_create($options); |
|
| 110 | + $result = file_get_contents($url, false, $context); |
|
| 111 | + |
|
| 112 | + if ($result === FALSE) { |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return $result; |
|
| 117 | + } else { |
|
| 118 | + //try to use curl instead |
|
| 119 | + |
|
| 120 | + //https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa |
|
| 121 | + |
|
| 122 | + //create a new curl session |
|
| 123 | + $ch = curl_init(); |
|
| 124 | + |
|
| 125 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
| 126 | + curl_setopt($ch, CURLOPT_POST, 1); |
|
| 127 | + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));//"postvar1=value1&postvar2=value2&postvar3=value3" |
|
| 128 | + |
|
| 129 | + //receive server response |
|
| 130 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 131 | + $result = curl_exec ($ch); |
|
| 132 | + |
|
| 133 | + //close curl session |
|
| 134 | + curl_close ($ch); |
|
| 135 | + |
|
| 136 | + return $result; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - public static function isUrlfopenEnabled () : bool { |
|
| 141 | - $res = ini_get("allow_url_fopen"); |
|
| 140 | + public static function isUrlfopenEnabled () : bool { |
|
| 141 | + $res = ini_get("allow_url_fopen"); |
|
| 142 | 142 | |
| 143 | - if ($res) { |
|
| 144 | - return true; |
|
| 145 | - } else { |
|
| 146 | - return false; |
|
| 147 | - } |
|
| 148 | - } |
|
| 143 | + if ($res) { |
|
| 144 | + return true; |
|
| 145 | + } else { |
|
| 146 | + return false; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - public static function isCurlAvailable () : bool { |
|
| 151 | - /*if (in_array ('curl', get_loaded_extensions())) { |
|
| 150 | + public static function isCurlAvailable () : bool { |
|
| 151 | + /*if (in_array ('curl', get_loaded_extensions())) { |
|
| 152 | 152 | return true; |
| 153 | 153 | } |
| 154 | 154 | else { |
| 155 | 155 | return false; |
| 156 | 156 | }*/ |
| 157 | 157 | |
| 158 | - return function_exists('curl_version'); |
|
| 159 | - } |
|
| 158 | + return function_exists('curl_version'); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - public static function isGettextAvailable () : bool { |
|
| 162 | - return function_exists("gettext"); |
|
| 163 | - } |
|
| 161 | + public static function isGettextAvailable () : bool { |
|
| 162 | + return function_exists("gettext"); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - public static function clearGetTextCache () { |
|
| 166 | - //clear stats cache, often this clears also gettext cache |
|
| 167 | - clearstatcache(); |
|
| 168 | - } |
|
| 165 | + public static function clearGetTextCache () { |
|
| 166 | + //clear stats cache, often this clears also gettext cache |
|
| 167 | + clearstatcache(); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - public static function checkSessionStarted (bool $throw_exception = true) : bool { |
|
| 171 | - if (session_status() !== PHP_SESSION_ACTIVE) { |
|
| 172 | - if ($throw_exception) { |
|
| 173 | - throw new IllegalStateException("session wasnt started yet."); |
|
| 174 | - } |
|
| 170 | + public static function checkSessionStarted (bool $throw_exception = true) : bool { |
|
| 171 | + if (session_status() !== PHP_SESSION_ACTIVE) { |
|
| 172 | + if ($throw_exception) { |
|
| 173 | + throw new IllegalStateException("session wasnt started yet."); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - return false; |
|
| 177 | - } |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - return true; |
|
| 180 | - } |
|
| 179 | + return true; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - public static function containsStr (string $haystack, string $needle) : bool { |
|
| 183 | - return strpos($haystack, $needle) !== FALSE; |
|
| 184 | - } |
|
| 182 | + public static function containsStr (string $haystack, string $needle) : bool { |
|
| 183 | + return strpos($haystack, $needle) !== FALSE; |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | 186 | } |
@@ -27,34 +27,34 @@ |
||
| 27 | 27 | |
| 28 | 28 | class ApiMethodInstaller extends PluginInstaller_Plugin { |
| 29 | 29 | |
| 30 | - public function install(Plugin $plugin, array $install_json): bool { |
|
| 31 | - if (isset($install_json['api_methods'])) { |
|
| 32 | - foreach ($install_json['api_methods'] as $array) { |
|
| 33 | - $api_method = $array['api_method']; |
|
| 34 | - $classname = $array['class']; |
|
| 35 | - $method = $array['method']; |
|
| 36 | - |
|
| 37 | - //add api method |
|
| 38 | - ApiMethod::addMethod($api_method, $classname, $method, "plugin_" . $plugin->getName()); |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - return true; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function uninstall(Plugin $plugin, array $install_json): bool { |
|
| 46 | - ApiMethod::deleteMethodsByOwner("plugin_" . $plugin->getName()); |
|
| 47 | - |
|
| 48 | - return true; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function upgrade(Plugin $plugin, array $install_json): bool { |
|
| 52 | - //remove api methods first |
|
| 53 | - $this->uninstall($plugin, $install_json); |
|
| 54 | - |
|
| 55 | - //install api methods |
|
| 56 | - return $this->install($plugin, $install_json); |
|
| 57 | - } |
|
| 30 | + public function install(Plugin $plugin, array $install_json): bool { |
|
| 31 | + if (isset($install_json['api_methods'])) { |
|
| 32 | + foreach ($install_json['api_methods'] as $array) { |
|
| 33 | + $api_method = $array['api_method']; |
|
| 34 | + $classname = $array['class']; |
|
| 35 | + $method = $array['method']; |
|
| 36 | + |
|
| 37 | + //add api method |
|
| 38 | + ApiMethod::addMethod($api_method, $classname, $method, "plugin_" . $plugin->getName()); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + return true; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function uninstall(Plugin $plugin, array $install_json): bool { |
|
| 46 | + ApiMethod::deleteMethodsByOwner("plugin_" . $plugin->getName()); |
|
| 47 | + |
|
| 48 | + return true; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function upgrade(Plugin $plugin, array $install_json): bool { |
|
| 52 | + //remove api methods first |
|
| 53 | + $this->uninstall($plugin, $install_json); |
|
| 54 | + |
|
| 55 | + //install api methods |
|
| 56 | + return $this->install($plugin, $install_json); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | } |
| 60 | 60 | |