diff --git a/hook.php b/hook.php index 969fe791..5110626c 100644 --- a/hook.php +++ b/hook.php @@ -28,21 +28,6 @@ * ------------------------------------------------------------------------- */ -function plugin_datainjection_registerMethods() { - - global $WEBSERVICES_METHOD; - - $methods = ['getModel' => 'methodGetModel', - 'listModels' => 'methodListModels', - 'inject' => 'methodInject', - 'listItemtypes' => 'methodListItemtypes']; - - foreach ($methods as $code => $method) { - $WEBSERVICES_METHOD['datainjection.'.$code] = ['PluginDatainjectionWebservice', $method]; - } -} - - function plugin_datainjection_install() { global $DB; diff --git a/inc/model.class.php b/inc/model.class.php index 041ff133..15238352 100644 --- a/inc/model.class.php +++ b/inc/model.class.php @@ -1029,19 +1029,7 @@ function processUploadedFile($options = []) { $this->loadSpecificModel(); $response = $this->readUploadedFile($options); if (!$this->injectionData) { - if (!isset($options['webservice'])) { - return false; - } - return PluginWebservicesMethodCommon::Error( - $options['protocol'], - WEBSERVICES_ERROR_FAILED, - sprintf( - __( - 'Not data to import', - 'datainjection' - ) - ) - ); + return false; } if ($mode == self::PROCESS) { @@ -1055,15 +1043,8 @@ function processUploadedFile($options = []) { if ($check['status']!= PluginDatainjectionCommonInjectionLib::SUCCESS) { if ($mode == self::PROCESS) { - if (!isset($options['webservice'])) { - Session::addMessageAfterRedirect($check['error_message'], true, ERROR); - return false; - } - return PluginWebservicesMethodCommon::Error( - $options['protocol'], - WEBSERVICES_ERROR_FAILED, - $check['error_message'] - ); + Session::addMessageAfterRedirect($check['error_message'], true, ERROR); + return false; } } diff --git a/inc/webservice.class.php b/inc/webservice.class.php deleted file mode 100644 index b1e5de1d..00000000 --- a/inc/webservice.class.php +++ /dev/null @@ -1,208 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2007-2023 by DataInjection plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/datainjection - * ------------------------------------------------------------------------- - */ - -class PluginDatainjectionWebservice -{ - - - static function methodInject($params, $protocol) { - - if (isset($params['help'])) { - return ['uri' => 'string,mandatory', - 'base64' => 'string,optional', - 'additional' => 'array,optional', - 'models_id' => 'integer, mandatory', - 'entities_id'=> 'integer,mandatory', - 'mandatory' => 'array,optional', - 'uri' => 'uri,mandatory', - 'help' => 'bool,optional']; - } - - $model = new PluginDatainjectionModel(); - - //----------------------------------------------------------------- - //-------------------------- Check parameters --------------------- - //----------------------------------------------------------------- - if (!isset($_SESSION['glpiID'])) { - return PluginWebservicesMethodCommon::Error( - $protocol, - WEBSERVICES_ERROR_NOTAUTHENTICATED - ); - } - - if (!isset($params['uri']) && !isset($params['base64'])) { - return PluginWebservicesMethodCommon::Error( - $protocol, - WEBSERVICES_ERROR_MISSINGPARAMETER, - '', 'uri or base64' - ); - } - - if (!isset($params['models_id'])) { - return PluginWebservicesMethodCommon::Error( - $protocol, - WEBSERVICES_ERROR_MISSINGPARAMETER, - 'models_id' - ); - } - if (!$model->getFromDB($params['models_id'])) { - return PluginWebservicesMethodCommon::Error( - $protocol, WEBSERVICES_ERROR_NOTFOUND, - __('Model unknown', 'datainjection') - ); - - } - if (!$model->can($params['models_id'], READ)) { - return PluginWebservicesMethodCommon::Error( - $protocol, WEBSERVICES_ERROR_NOTALLOWED, - __( - 'You cannot access this model', - 'datainjection' - ) - ); - } - if ($model->fields['step'] < PluginDatainjectionModel::READY_TO_USE_STEP) { - return PluginWebservicesMethodCommon::Error( - $protocol, WEBSERVICES_ERROR_NOTALLOWED, - __( - 'You cannot access this model', - 'datainjection' - ) - ); - } - - //Check entity - if (!isset($params['entities_id'])) { - return PluginWebservicesMethodCommon::Error( - $protocol, - WEBSERVICES_ERROR_MISSINGPARAMETER, - 'entities_id' - ); - } - $entities_id = $params['entities_id']; - if ($entities_id > 0) { - $entity = new Entity(); - if (!$entity->getFromDB($entities_id)) { - return PluginWebservicesMethodCommon::Error( - $protocol, WEBSERVICES_ERROR_NOTFOUND, - __('Entity unknown', 'datainjection') - ); - - } - if (!Session::haveAccessToEntity($entities_id)) { - return PluginWebservicesMethodCommon::Error( - $protocol, WEBSERVICES_ERROR_NOTALLOWED, - __( - 'You cannot access this entity', - 'datainjection' - ) - ); - } - } - - //Mandatory fields - $additional_infos = []; - if (isset($params['additional']) && is_array($params['additional'])) { - $additional_infos = $params['additional']; - } - - //Upload CSV file - $document_name = basename($params['uri']); - $filename = tempnam(PLUGIN_DATAINJECTION_UPLOAD_DIR, 'PWS'); - $response = PluginWebservicesMethodCommon::uploadDocument( - $params, $protocol, $filename, - $document_name - ); - - if (PluginWebservicesMethodCommon::isError($protocol, $response)) { - return $response; - } - - //Uploade successful : now perform import ! - $options = ['file_encoding' => PluginDatainjectionBackend::ENCODING_AUTO, //Detect automatically file encoding - 'webservice' => true, //Use webservice CSV file import - 'original_filename' => $params['uri'], //URI to the CSV file - 'unique_filename' => $filename, //Unique filename - 'mode' => PluginDatainjectionModel::PROCESS, - 'delete_file' => false, //Do not delete file once imported - 'protocol' => $protocol]; //The Webservice protocol used - - $results = []; - $response = $model->processUploadedFile($options); - if (!PluginWebservicesMethodCommon::isError($protocol, $response)) { - $engine = new PluginDatainjectionEngine( - $model, - $additional_infos, - $params['entities_id'] - ); - //Remove first line if header is present - $first = true; - foreach ($model->injectionData->getData() as $id => $data) { - if ($first && $model->getSpecificModel()->isHeaderPresent()) { - $first = false; - } else { - $results[] = $engine->injectLine($data[0], $id); - } - } - $model->cleanData(); - return $results; - } - return $response; - } - - - static function methodGetModel($params, $protocol) { - - $params['itemtype'] = 'PluginDatainjectionModel'; - return PluginWebservicesMethodInventaire::methodGetObject($params, $protocol); - } - - - static function methodListModels($params, $protocol) { - - $params['itemtype'] = 'PluginDatainjectionModel'; - return PluginWebservicesMethodInventaire::methodListObjects($params, $protocol); - } - - - static function methodListItemtypes($params, $protocol) { - - if (isset($params['help'])) { - return ['help' => 'bool,optional']; - } - - if (!isset($_SESSION['glpiID'])) { - return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); - } - - return PluginDatainjectionInjectionType::getItemtypes(); - } - -} diff --git a/setup.php b/setup.php index 6f0f6ed6..ba1c35a3 100644 --- a/setup.php +++ b/setup.php @@ -80,8 +80,6 @@ function plugin_init_datainjection() { // Javascript file $PLUGIN_HOOKS['add_javascript']['datainjection'] = 'js/datainjection.js'; - // Inbtegration with Webservices plugin - $PLUGIN_HOOKS['webservices']['datainjection'] = 'plugin_datainjection_registerMethods'; $INJECTABLE_TYPES = []; } diff --git a/testwebservice.php b/testwebservice.php deleted file mode 100644 index d03bb2c2..00000000 --- a/testwebservice.php +++ /dev/null @@ -1,125 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2007-2023 by DataInjection plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/datainjection - * ------------------------------------------------------------------------- - */ - -if (!extension_loaded("xmlrpc")) { - die("Extension xmlrpc not loaded\n"); -} - -chdir(dirname($_SERVER["SCRIPT_FILENAME"])); -chdir("../../.."); -$url = "/".basename(getcwd()).Plugin::getWebDir('webservices', false)."/xmlrpc.php"; - -$args = []; -if ($_SERVER['argc'] > 1) { - for ($i=1; $i [ - 'method' => "POST", - 'header' => $header, - 'content' => $request - ] - ] - ); - - $file = file_get_contents("http://".$params['host']."/".$params['url'], false, $context); - if (!$file) { - die("+ No response\n"); - } - - $response = xmlrpc_decode($file); - if (!is_array($response)) { - echo $file; - die ("+ Bad response\n"); - } - - if (xmlrpc_is_fault($response)) { - echo("xmlrpc error(".$response['faultCode']."): ".$response['faultString']."\n"); - return false; - } - return $response; -}