diff --git a/interface/lib/classes/json_handler.inc.php b/interface/lib/classes/json_handler.inc.php index de8dd5ba0dd254053821ae910f3a868ba943597f..fb0811d31420f6dd6833857194a1914d6543f242 100644 --- a/interface/lib/classes/json_handler.inc.php +++ b/interface/lib/classes/json_handler.inc.php @@ -30,45 +30,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -class ISPConfigJSONHandler { - private $methods = array(); - private $classes = array(); - - public function __construct() { - global $app; - - // load main remoting file - $app->load('remoting'); - - // load all remote classes and get their methods - $dir = dirname(realpath(__FILE__)) . '/remote.d'; - $d = opendir($dir); - while($f = readdir($d)) { - if($f == '.' || $f == '..') continue; - if(!is_file($dir . '/' . $f) || substr($f, strrpos($f, '.')) != '.php') continue; - - $name = substr($f, 0, strpos($f, '.')); - - include $dir . '/' . $f; - $class_name = 'remoting_' . $name; - if(class_exists($class_name, false)) { - $this->classes[$class_name] = new $class_name(); - foreach(get_class_methods($this->classes[$class_name]) as $method) { - $this->methods[$method] = $class_name; - } - } - } - closedir($d); - - // add main methods - $this->methods['login'] = 'remoting'; - $this->methods['logout'] = 'remoting'; - $this->methods['get_function_list'] = 'remoting'; - - // create main class - $this->classes['remoting'] = new remoting(array_keys($this->methods)); - } - +class ISPConfigJSONHandler extends ISPConfigRemotingHandlerBase { private function _return_json($code, $message, $data = false) { $ret = new stdClass; $ret->code = $code; diff --git a/interface/lib/classes/remoting_handler_base.inc.php b/interface/lib/classes/remoting_handler_base.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..6393959df8b2c38e5f206f0ab5841a63a397ac4c --- /dev/null +++ b/interface/lib/classes/remoting_handler_base.inc.php @@ -0,0 +1,75 @@ +load('remoting'); + + // load all remoting classes and get their methods + $this->load_remoting_classes(realpath(__DIR__) . '/remote.d/*.inc.php'); + + // load all remoting classes from modules + $this->load_remoting_classes(realpath(__DIR__) . '/../../web/*/lib/classes/remote.d/*.inc.php'); + + // add main methods + $this->methods['login'] = 'remoting'; + $this->methods['logout'] = 'remoting'; + $this->methods['get_function_list'] = 'remoting'; + + // create main class + $this->classes['remoting'] = new remoting(array_keys($this->methods)); + } + + private function load_remoting_classes($glob_pattern) + { + $files = glob($glob_pattern); + + foreach ($files as $file) { + $name = str_replace('.inc.php', '', basename($file)); + $class_name = 'remoting_' . $name; + + include_once $file; + if(class_exists($class_name, false)) { + $this->classes[$class_name] = new $class_name(); + foreach(get_class_methods($this->classes[$class_name]) as $method) { + $this->methods[$method] = $class_name; + } + } + } + } +} diff --git a/interface/lib/classes/rest_handler.inc.php b/interface/lib/classes/rest_handler.inc.php index ceaa7c63be32fc95198769c0398a6f46cc1e4b31..ae3e443d48848e924e830e74fc2748ecd0fc8473 100644 --- a/interface/lib/classes/rest_handler.inc.php +++ b/interface/lib/classes/rest_handler.inc.php @@ -30,46 +30,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -class ISPConfigRESTHandler { - private $methods = array(); - private $classes = array(); - +class ISPConfigRESTHandler extends ISPConfigRemotingHandlerBase { private $api_version = 1; - - public function __construct() { - global $app; - - // load main remoting file - $app->load('remoting'); - - // load all remote classes and get their methods - $dir = dirname(realpath(__FILE__)) . '/remote.d'; - $d = opendir($dir); - while($f = readdir($d)) { - if($f == '.' || $f == '..') continue; - if(!is_file($dir . '/' . $f) || substr($f, strrpos($f, '.')) != '.php') continue; - - $name = substr($f, 0, strpos($f, '.')); - - include $dir . '/' . $f; - $class_name = 'remoting_' . $name; - if(class_exists($class_name, false)) { - $this->classes[$class_name] = new $class_name(); - foreach(get_class_methods($this->classes[$class_name]) as $method) { - $this->methods[$method] = $class_name; - } - } - } - closedir($d); - - // add main methods - $this->methods['login'] = 'remoting'; - $this->methods['logout'] = 'remoting'; - $this->methods['get_function_list'] = 'remoting'; - - // create main class - $this->classes['remoting'] = new remoting(array_keys($this->methods)); - } private function _return_error($code, $codename, $message) { header('HTTP/1.1 ' . $code . ' ' . $codename); diff --git a/interface/lib/classes/soap_handler.inc.php b/interface/lib/classes/soap_handler.inc.php index 704e21b20ba282fc45d661dd2d1b78c66981e0ba..16693e12c92e0d032dbe93dca0950cb186150bf1 100644 --- a/interface/lib/classes/soap_handler.inc.php +++ b/interface/lib/classes/soap_handler.inc.php @@ -30,45 +30,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -class ISPConfigSoapHandler { - private $methods = array(); - private $classes = array(); - - public function __construct() { - global $app; - - // load main remoting file - $app->load('remoting'); - - // load all remote classes and get their methods - $dir = dirname(realpath(__FILE__)) . '/remote.d'; - $d = opendir($dir); - while($f = readdir($d)) { - if($f == '.' || $f == '..') continue; - if(!is_file($dir . '/' . $f) || substr($f, strrpos($f, '.')) != '.php') continue; - - $name = substr($f, 0, strpos($f, '.')); - - include_once $dir . '/' . $f; - $class_name = 'remoting_' . $name; - if(class_exists($class_name, false)) { - $this->classes[$class_name] = new $class_name(); - foreach(get_class_methods($this->classes[$class_name]) as $method) { - $this->methods[$method] = $class_name; - } - } - } - closedir($d); - - // add main methods - $this->methods['login'] = 'remoting'; - $this->methods['logout'] = 'remoting'; - $this->methods['get_function_list'] = 'remoting'; - - // create main class - $this->classes['remoting'] = new remoting(array_keys($this->methods)); - } - +class ISPConfigSoapHandler extends ISPConfigRemotingHandlerBase { public function __call($method, $params) { if(array_key_exists($method, $this->methods) == false) { throw new SoapFault('invalid_method', 'Method ' . $method . ' does not exist'); diff --git a/interface/web/remote/index.php b/interface/web/remote/index.php index 670a9db13b41b62daf99ab425174ac2d9cd03a7f..6352dfe5042745bf24e2670753f7ea03107c160f 100644 --- a/interface/web/remote/index.php +++ b/interface/web/remote/index.php @@ -8,7 +8,7 @@ require_once '../../lib/app.inc.php'; if($conf['demo_mode'] == true) $app->error('This function is disabled in demo mode.'); -$app->load('soap_handler,getconf'); +$app->load('remoting_handler_base,soap_handler,getconf'); $security_config = $app->getconf->get_security_config('permissions'); if($security_config['remote_api_allowed'] != 'yes') die('Remote API is disabled in security settings.'); diff --git a/interface/web/remote/json.php b/interface/web/remote/json.php index 926a9953958afdd2ed8686c3112dce18f2be5351..d6eb8dcbc161888d09d41b9d7dae975ac73e5047 100644 --- a/interface/web/remote/json.php +++ b/interface/web/remote/json.php @@ -8,7 +8,7 @@ require_once '../../lib/app.inc.php'; if($conf['demo_mode'] == true) $app->error('This function is disabled in demo mode.'); -$app->load('json_handler,getconf'); +$app->load('remoting_handler_base,json_handler,getconf'); $security_config = $app->getconf->get_security_config('permissions'); if($security_config['remote_api_allowed'] != 'yes') die('Remote API is disabled in security settings.'); diff --git a/interface/web/remote/rest.php b/interface/web/remote/rest.php index 4f202c6eeedff5c2f51d57dfc6ee9149be738215..381fd426559548329b8e5e67e01c40410e1b14f0 100644 --- a/interface/web/remote/rest.php +++ b/interface/web/remote/rest.php @@ -6,7 +6,7 @@ require_once '../../lib/config.inc.php'; $conf['start_session'] = false; require_once '../../lib/app.inc.php'; -$app->load('rest_handler,getconf'); +$app->load('remoting_handler_base,rest_handler,getconf'); $security_config = $app->getconf->get_security_config('permissions'); if($security_config['remote_api_allowed'] != 'yes') die('Remote API is disabled in security settings.');