24if (!defined(
'NOCSRFCHECK')) {
25 define(
'NOCSRFCHECK',
'1');
27if (!defined(
'NOTOKENRENEWAL')) {
28 define(
'NOTOKENRENEWAL',
'1');
30if (!defined(
'NOREQUIREMENU')) {
31 define(
'NOREQUIREMENU',
'1');
33if (!defined(
'NOREQUIREHTML')) {
34 define(
'NOREQUIREHTML',
'1');
36if (!defined(
'NOREQUIREAJAX')) {
37 define(
'NOREQUIREAJAX',
'1');
39if (!defined(
"NOLOGIN")) {
40 define(
"NOLOGIN",
'1');
42if (!defined(
"NOSESSION")) {
43 define(
"NOSESSION",
'1');
46require
'../main.inc.php';
47require_once NUSOAP_PATH.
'/nusoap.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
49require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
54dol_syslog(
"Call Dolibarr webservices interfaces");
60 $langs->load(
"admin");
61 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
62 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
63 print $langs->trans(
"ToActivateModule");
68$server =
new nusoap_server();
69$server->soap_defencoding =
'UTF-8';
70$server->decode_utf8 =
false;
71$ns =
'http://www.dolibarr.org/ns/';
72$server->configureWSDL(
'WebServicesDolibarrOther', $ns);
76$server->wsdl->schemaTargetNamespace = $ns;
80$server->wsdl->addComplexType(
87 'dolibarrkey' => array(
'name' =>
'dolibarrkey',
'type' =>
'xsd:string'),
88 'sourceapplication' => array(
'name' =>
'sourceapplication',
'type' =>
'xsd:string'),
89 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
90 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
91 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string'),
95$server->wsdl->addComplexType(
102 'result_code' => array(
'name' =>
'result_code',
'type' =>
'xsd:string'),
103 'result_label' => array(
'name' =>
'result_label',
'type' =>
'xsd:string'),
108$server->wsdl->addComplexType(
115 'filename' => array(
'name' =>
'filename',
'type' =>
'xsd:string'),
116 'mimetype' => array(
'name' =>
'mimetype',
'type' =>
'xsd:string'),
117 'content' => array(
'name' =>
'content',
'type' =>
'xsd:string'),
118 'length' => array(
'name' =>
'length',
'type' =>
'xsd:string')
130$styleuse =
'encoded';
137 array(
'authentication' =>
'tns:authentication'),
139 array(
'result' =>
'tns:result',
'dolibarr' =>
'xsd:string',
'os' =>
'xsd:string',
'php' =>
'xsd:string',
'webserver' =>
'xsd:string'),
151 array(
'authentication' =>
'tns:authentication',
'modulepart' =>
'xsd:string',
'file' =>
'xsd:string'),
153 array(
'result' =>
'tns:result',
'document' =>
'tns:document'),
173 dol_syslog(
"Function: getVersions login=".$authentication[
'login']);
175 if ($authentication[
'entity']) {
176 $conf->entity = $authentication[
'entity'];
180 $objectresp = array();
189 $objectresp[
'result'] = array(
'result_code' =>
'OK',
'result_label' =>
'');
197 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
214function getDocument($authentication, $modulepart, $file, $refname =
'')
218 dol_syslog(
"Function: getDocument login=".$authentication[
'login'].
' - modulepart='.$modulepart.
' - file='.$file);
220 if ($authentication[
'entity']) {
221 $conf->entity = $authentication[
'entity'];
224 $objectresp = array();
230 $original_file = $file;
240 $socid = $fuser->socid;
244 if (!$error && (!$file || !$modulepart)) {
246 $errorcode =
'BAD_PARAMETERS';
247 $errorlabel =
"Parameter file and modulepart must be both provided.";
251 $fuser->loadRights();
254 $original_file = str_replace(
"../",
"/", $original_file);
257 if (empty($refname)) {
258 $refname = basename(dirname($original_file).
"/");
263 $accessallowed = $check_access[
'accessallowed'];
264 $sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
265 $original_file = $check_access[
'original_file'];
268 if ($fuser->socid > 0) {
269 if ($sqlprotectagainstexternals) {
270 $resql = $db->query($sqlprotectagainstexternals);
272 $num = $db->num_rows($resql);
275 $obj = $db->fetch_object($resql);
276 if ($fuser->socid != $obj->fk_soc) {
288 if (!$accessallowed) {
289 $errorcode =
'NOT_PERMITTED';
290 $errorlabel =
'Access not allowed';
297 if (preg_match(
'/\.\./', $original_file) || preg_match(
'/[<>|]/', $original_file)) {
298 dol_syslog(
"Refused to deliver file ".$original_file);
299 $errorcode =
'REFUSED';
307 if (file_exists($original_file)) {
308 dol_syslog(
"Function: getDocument $original_file content-type=$type");
310 $f = fopen($original_file,
'r');
311 $content_file = fread($f, filesize($original_file));
314 'filename' => basename($original_file),
316 'content' => base64_encode($content_file),
317 'length' => filesize($original_file)
322 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
323 'document' => $objectret
326 dol_syslog(
"File doesn't exist ".$original_file);
327 $errorcode =
'NOT_FOUND';
336 'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel)
344$server->service(file_get_contents(
"php://input"));
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser=null, $refname='', $mode='read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices to g...
version_webserver()
Return web server version.
version_dolibarr()
Return Dolibarr version.
version_php()
Return PHP version.
version_os($option='')
Return OS version.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getDocument($authentication, $modulepart, $file, $refname='')
Method to get a document by webservice.
getVersions($authentication)
Full methods code.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.