GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (4873)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

plugins/docman/include/soap.php (7 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
require_once ('pre.php');
4
require_once ('session.php');
5
require_once('common/include/Error.class.php');
6
require_once('Docman_Item.class.php');
7
require_once('Docman_ItemFactory.class.php');
8
require_once('common/include/SOAPRequest.class.php');
9
require_once('common/include/MIME.class.php');
10
11
// define fault code constants
12
define('invalid_item_fault', '3017');
0 ignored issues
show
This constant is not in uppercase (expected 'INVALID_ITEM_FAULT').
Loading history...
13
define('invalid_document_fault', '3018');
0 ignored issues
show
This constant is not in uppercase (expected 'INVALID_DOCUMENT_FAULT').
Loading history...
14
define('invalid_folder_fault', '3019');
0 ignored issues
show
This constant is not in uppercase (expected 'INVALID_FOLDER_FAULT').
Loading history...
15
define('PLUGIN_DOCMAN_SOAP_FAULT_UNAVAILABLE_PLUGIN', '3020');
16
define('invalid_operator', '3021');
0 ignored issues
show
This constant is not in uppercase (expected 'INVALID_OPERATOR').
Loading history...
17
18
if (defined('NUSOAP')) {
19
20
//
21
// Type definition
22
//
23
$GLOBALS['server']->wsdl->addComplexType(
24
    'Docman_Item',
25
    'complexType',
26
    'struct',
27
    'sequence',
28
    '',
29
    array(
30
        'item_id' => array('name'=>'item_id', 'type' => 'xsd:int'),
31
        'parent_id' => array('name'=>'parent', 'type' => 'xsd:int'), 
32
        'group_id' => array('name'=>'group_id', 'type' => 'xsd:int'),
33
        'title' => array('name'=>'title', 'type' => 'xsd:string'),
34
        'description' => array('name'=>'description', 'type' => 'xsd:string'),
35
        'create_date' => array('name'=>'create_date', 'type' => 'xsd:int'),
36
        'update_date' => array('name'=>'update_date', 'type' => 'xsd:int'),
37
        'delete_date' => array('name'=>'delete_date', 'type' => 'xsd:int'),
38
        'user_id' => array('name'=>'user_id', 'type'=>'xsd:int'),
39
        'status' => array('name'=>'status', 'type' => 'xsd:int'),
40
        'obsolescence_date' => array('name'=>'obsolescence_date', 'type' => 'xsd:int'),
41
        'rank' => array('name'=>'rank', 'type' => 'xsd:int'),
42
        'item_type' => array('name'=>'item_type', 'type' => 'xsd:int'),
43
    )
44
);
45
46
$GLOBALS['server']->wsdl->addComplexType(
47
    'ArrayOfDocman_Item',
48
    'complexType',
49
    'array',
50
    '',
51
    'SOAP-ENC:Array',
52
    array(),
53
    array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Docman_Item[]')),
54
    'tns:Docman_Item'
55
);
56
57
$GLOBALS['server']->wsdl->addComplexType(
58
    'Permission',
59
    'complexType',
60
    'struct',
61
    'sequence',
62
    '',
63
    array(
64
        'type' => array('name'=>'type', 'type' => 'xsd:string'),
65
        'ugroup_id' => array('name'=>'ugroup_id', 'type' => 'xsd:int'), 
66
    )
67
);
68
69
$GLOBALS['server']->wsdl->addComplexType(
70
    'ArrayOfPermission',
71
    'complexType',
72
    'array',
73
    '',
74
    'SOAP-ENC:Array',
75
    array(),
76
    array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Permission[]')),
77
    'tns:Permission'
78
);
79
80
$GLOBALS['server']->wsdl->addComplexType(
81
    'MetadataValue',
82
    'complexType',
83
    'struct',
84
    'sequence',
85
    '',
86
    array(
87
        'label' => array('name'=>'label', 'type' => 'xsd:string'),
88
        'value' => array('name'=>'value', 'type' => 'xsd:string'), 
89
    )
90
);
91
92
$GLOBALS['server']->wsdl->addComplexType(
93
    'ArrayOfMetadataValue',
94
    'complexType',
95
    'array',
96
    '',
97
    'SOAP-ENC:Array',
98
    array(),
99
    array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:MetadataValue[]')),
100
    'tns:MetadataValue'
101
);
102
103
$GLOBALS['server']->wsdl->addComplexType(
104
    'MetadataListValue',
105
    'complexType',
106
    'struct',
107
    'sequence',
108
    '',
109
    array(
110
        'id' => array('name'=>'id', 'type' => 'xsd:int'),
111
        'name'     => array('name'=>'name', 'type' => 'xsd:string'),
112
    )
113
);
114
115
$GLOBALS['server']->wsdl->addComplexType(
116
    'ArrayOfMetadataListValue',
117
    'complexType',
118
    'array',
119
    '',
120
    'SOAP-ENC:Array',
121
    array(),
122
    array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:MetadataListValue[]')),
123
    'tns:MetadataListValue'
124
);
125
126
$GLOBALS['server']->wsdl->addComplexType(
127
    'Metadata',
128
    'complexType',
129
    'struct',
130
    'sequence',
131
    '',
132
    array(
133
        'label' => array('name'=>'label', 'type' => 'xsd:string'),
134
        'name' => array('name'=>'name', 'type' => 'xsd:string'),
135
        'type' => array('name'=>'type', 'type' => 'xsd:string'),
136
        'isMultipleValuesAllowed' => array('name'=>'isMultipleValuesAllowed', 'type' => 'xsd:int'),
137
        'isEmptyAllowed' => array('name'=>'isEmptyAllowed', 'type' => 'xsd:int'),
138
        'listOfValues' => array('name'=>'listOfValues', 'type' => 'tns:ArrayOfMetadataListValue'), 
139
    )
140
);
141
142
$GLOBALS['server']->wsdl->addComplexType(
143
    'ArrayOfMetadata',
144
    'complexType',
145
    'array',
146
    '',
147
    'SOAP-ENC:Array',
148
    array(),
149
    array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Metadata[]')),
150
    'tns:Metadata'
151
);
152
153
$GLOBALS['server']->wsdl->addComplexType(
154
    'ItemInfo',
155
    'complexType',
156
    'struct',
157
    'sequence',
158
    '',
159
    array(
160
        'id' => array('name'=>'id', 'type' => 'xsd:int'),
161
        'parent_id' => array('name'=>'parent_id', 'type' => 'xsd:int'),
162
        'title' => array('name'=>'title', 'type' => 'xsd:string'),
163
        'filename' => array('name'=>'filename', 'type' => 'xsd:string'),
164
        'type' => array('name'=>'type', 'type' => 'xsd:string'),
165
        'nb_versions' => array('name'=>'nb_versions', 'type' => 'xsd:int'),
166
    )
167
);
168
169
$GLOBALS['server']->wsdl->addComplexType(
170
    'ArrayOfItemInfo',
171
    'complexType',
172
    'array',
173
    '',
174
    'SOAP-ENC:Array',
175
    array(),
176
    array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:ItemInfo[]')),
177
    'tns:ItemInfo'
178
);
179
180
181
}
182
183
/**
184
 * Returns an array containing all the permissions for the specified item.
185
 * The ugroups that have no permission defined in the request take the permission of the parent folder.
186
 */
187
function _get_permissions_as_array($group_id, $item_id, $permissions) {
188
    $permissions_array = array();
189
    
190
    $perms = array('PLUGIN_DOCMAN_READ', 'PLUGIN_DOCMAN_WRITE', 'PLUGIN_DOCMAN_MANAGE');
191
192
    // Get the ugroups of the parent
193
    $ugroups = permission_get_ugroups_permissions($group_id, $item_id, $perms, false);
194
    
195
    // Initialize the ugroup permissions to the same values as the parent folder
196
    foreach ($ugroups as $ugroup) {
0 ignored issues
show
The expression $ugroups of type false|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
197
        $ugroup_id = $ugroup['ugroup']['id'];
198
        $permissions_array[$ugroup_id] = 100;
199
        foreach ($perms as $perm) {
200
            if (isset($ugroup['permissions'][$perm])) {
201
                $permissions_array[$ugroup_id] = Docman_PermissionsManager::getDefinitionIndexForPermission($perm);
202
            }
203
        }
204
    }
205
    
206
    // Set the SOAP-provided permissions
207
    foreach ($permissions as $index => $permission) {
208
        $ugroup_id = $permission->ugroup_id;
209
        if (isset($permissions_array[$ugroup_id])) {
210
            $permissions_array[$ugroup_id] = Docman_PermissionsManager::getDefinitionIndexForPermission($permission->type);
211
        }
212
    }
213
    
214
    return $permissions_array;
215
}
216
217
/**
218
 * Takes an array of metadata objects as provided by the SOAP request:
219
 * 
220
 * Array
221
 * (
222
 *     [0] => stdClass Object
223
 *         (
224
 *             [label] => field_2
225
 *             [value] => This is a string
226
 *         )
227
 * 
228
 *     [1] => stdClass Object
229
 *         (
230
 *             [label] => field_9
231
 *             [value] => 103
232
 *         )
233
 * 
234
 *     [2] => stdClass Object
235
 *         (
236
 *             [label] => field_9
237
 *             [value] => 104
238
 *         )
239
 * )
240
 * 
241
 * And returns an associative array of metadata as required by the Docman Actions:
242
 * 
243
 * Array
244
 * (
245
 *     [field_2] => This is a string
246
 *     [field_9] => Array
247
 *         (
248
 *             [0] => 103
249
 *             [1] => 104
250
 *         )
251
 * )  
252
 */
253
function _get_metadata_as_array($metadata) {
254
    $metadata_array = array();
255
    
256
    foreach ($metadata as $m) {
257
        if (isset($metadata_array[$m->label])) {
258
            if (is_array($metadata_array[$m->label])) {
259
                array_push($metadata_array[$m->label], $m->value);
260
            } else {
261
                $metadata_array[$m->label] = array($metadata_array[$m->label], $m->value);
262
            }
263
        } else {
264
            $metadata_array[$m->label] = $m->value;
265
        }
266
    }
267
268
    return $metadata_array;
269
}
270
271
/**
272
 * Returns the constant value associated to the requested status
273
 */
274
function _get_status_value($status) {
275
    switch ($status) {
276
        case 'draft' : $value = PLUGIN_DOCMAN_ITEM_STATUS_DRAFT; break;
277
        case 'approved' : $value = PLUGIN_DOCMAN_ITEM_STATUS_APPROVED; break;
278
        case 'rejected' : $value = PLUGIN_DOCMAN_ITEM_STATUS_REJECTED; break;
279
        default : $value = PLUGIN_DOCMAN_ITEM_STATUS_NONE; break;
280
    }
281
    
282
    return $value;
283
}
284
285
/**
286
 * Returns the user ID corresponding to the given user name, or null if it doesn't exist
287
 */
288
function _getUserIdByUserName($userName) {
289
    $user = UserManager::instance()->getUserByUserName($userName);
290
    if ($user == null) {
291
        return null;
292
    } else {
293
        return $user->getId();
294
    }
295
}
296
297
/**
298
 * Makes a docman request
299
 *
300
 * @param string       $sessionKey   Session Key
301
 * @param int          $group_id     Group ID
302
 * @param array        $params       Request parameters
303
 * @return unknown                   Request response
304
 */
305
function _makeDocmanRequest($sessionKey, $group_id, $action, $params = array()) {
306
    $actor ="_makeDocmanRequest ($action)";
307
    
308
    if (session_continue($sessionKey)) {
309
        try {
310
            $pm = ProjectManager::instance();
311
            $pm->getGroupByIdForSoap($group_id, $actor);
312
        } catch (SoapFault $e) {
313
            return $e;
314
        }
315
316
        $params['group_id'] = $group_id;
317
        $params['action'] = $action;
318
        $params['confirm'] = true;
319
        
320
        $request =& new SOAPRequest($params);
321
        
322
        $plugin_manager =& PluginManager::instance();
323
        $p =& $plugin_manager->getPluginByName('docman');
324
        if ($p && $plugin_manager->isPluginAvailable($p)) {
325
            // Process request
326
            $result = $p->processSOAP($request);
327
            if ($GLOBALS['Response']->feedbackHasErrors()) {
328
                   $msg = $GLOBALS['Response']->getRawFeedback();
329
                   return new SoapFault(null, $msg, $actor);
330
            } else {
331
                return $result;
332
            }
333
        } else {
334
            return new SoapFault(PLUGIN_DOCMAN_SOAP_FAULT_UNAVAILABLE_PLUGIN, 'Unavailable plugin', $actor);
335
        }  
336
    } else {
337
        return new SoapFault(invalid_session_fault, 'Invalid Session', $actor);
338
    }
339
}
340
341
/**
342
 * Returns an array containing the common item params needed by docman actions
343
 */
344
function _buildItemParams($group_id, $perm_item_id, $title, $description, $status, $type, $permissions, $metadata, $owner, $create_date, $update_date) {
345
    $params = array();
346
    
347
    if ($title !== null)       $params['item']['title'] = $title;
348
    if ($description !== null) $params['item']['description'] = $description;
349
    if ($type !== null)        $params['item']['item_type'] = $type;
350
    if ($status !== null)      $params['item']['status'] = _get_status_value($status);
351
    if ($create_date !== null) $params['item']['create_date'] = $create_date;
352
    if ($update_date !== null) $params['item']['update_date'] = $update_date;
353
    if ($owner !== null)       $params['item']['owner'] = $owner;
354
    if ($permissions !== null) $params['permissions'] = _get_permissions_as_array($group_id, $perm_item_id, $permissions);
355
    if ($metadata !== null)    $params['metadata'] = _get_metadata_as_array($metadata);
356
    
357
    return $params;
358
}
359
360
/**
361
 * This function is like the PHP function array_merge_recursive but prevents returning null when one of the arrays is null
362
 */
363
function _safe_array_merge_recursive($array1, $array2) {
364
    if ($array1 === null) {
365
        $array1 = array();
366
    }
367
    if ($array2 === null) {
368
        $array2 = array();
369
    }
370
    return array_merge_recursive($array1, $array2);
371
}
372
373
/**
374
 * Creates a docman item
375
 *
376
 * @param string       $sessionKey        Session key
377
 * @param int          $group_id          Group ID
378
 * @param int          $parent_id         Parent folder ID
379
 * @param string       $title             Title
380
 * @param string       $description       Description
381
 * @param string       $ordering          Ordering (begin, end)
382
 * @param string       $status            Status (none, draft, approved, rejected)
383
 * @param string       $obsolescence_date Obsolescence date
0 ignored issues
show
There is no parameter named $obsolescence_date. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
384
 * @param string       $type              Type (folder, file, embedded_file, link, empty, wiki)
385
 * @param Array        $permissions       Permissions
386
 * @param Array        $metadata          Metadata values
387
 * @param string       $owner             Owner
388
 * @param string       $create_date       Create date
389
 * @param string       $update_date       Update date
390
 * @param Array        $extraParams       Extra parameters array
391
 */
392
function _createDocmanItem($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $type, $permissions, $metadata, $owner, $create_date, $update_date, $extraParams = array()) {
393
        
394
    $params = _buildItemParams($group_id, $parent_id, $title, $description, $status, $type, $permissions, $metadata, $owner, $create_date, $update_date);
395
    $params['item']['parent_id'] = $parent_id;
396
    $params['ordering'] = $ordering;
397
    
398
    return _makeDocmanRequest($sessionKey, $group_id, 'createItem', _safe_array_merge_recursive($params, $extraParams));
399
}
400
401
/**
402
 * Creates a docman document
403
 */
404
function _createDocmanDocument($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $obsolescence_date, $type, $permissions, $metadata, $owner, $create_date, $update_date, $extraParams = array()) {
405
    if ($obsolescence_date !== null) $extraParams['item']['obsolescence_date'] = $obsolescence_date;
406
    return _createDocmanItem($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $type, $permissions, $metadata, $owner, $create_date, $update_date, $extraParams);
407
}
408
409
/**
410
 * Updates a docman item
411
 */
412
function _updateDocmanItem($sessionKey, $group_id, $item_id, $title, $description, $status, $type, $permissions, $metadata, $owner, $create_date, $update_date, $extraParams = array()) {
413
    
414
    $params = _buildItemParams($group_id, $item_id, $title, $description, $status, $type, $permissions, $metadata, $owner, $create_date, $update_date);
415
    $params['item']['id'] = $item_id;
416
    
417
    $permParams['id'] = $item_id;
418
    $permParams['permissions'] = $params['permissions'];
419
    $result = _makeDocmanRequest($sessionKey, $group_id, 'permissions', $permParams);    
420
    if ($result instanceof SoapFault) {
421
        return $result;
422
    }
423
    $result = _makeDocmanRequest($sessionKey, $group_id, 'update', _safe_array_merge_recursive($params, $extraParams));
424
    if ($result instanceof SoapFault) {
425
        return $result;
426
    }
427
    return true;
428
}
429
430
/**
431
 * Updates a docman document
432
 */
433
function _updateDocmanDocument($sessionKey, $group_id, $item_id, $title, $description, $status, $obsolescence_date, $type, $permissions, $metadata, $owner, $create_date, $update_date, $extraParams = array()) {
434
    if ($obsolescence_date !== null) {
435
        $extraParams['item']['obsolescence_date'] = $obsolescence_date;
436
    }
437
    return _updateDocmanItem($sessionKey, $group_id, $item_id, $title, $description, $status, $type, $permissions, $metadata, $owner, $create_date, $update_date, $extraParams);
438
}
439
//
440
// SOAP function implementations
441
//
442
443
/**
444
* Returns the document object that is at the top of the docman given a group object.
445
*/
446
function getRootFolder($sessionKey,$group_id) {
447
    return _makeDocmanRequest($sessionKey, $group_id, 'getRootFolder');
448
}
449
$soapFunctions[] = array('getRootFolder', 'Returns the document object id that is at the top of the docman given a group object');
450
451
452
/**
453
* Lists the contents of a folder
454
*/
455
function listFolder($sessionKey,$group_id,$item_id) {
456
    $params = array('id' => $item_id, 'report' => 'List');
457
    return _makeDocmanRequest($sessionKey, $group_id, 'show', $params);
458
}
459
$soapFunctions[] = array('listFolder', 'List folder contents', 'tns:ArrayOfDocman_Item');
460
461
function operatorToValue($operator) {
462
    if ($operator == '=') {
463
        return 0;
464
    } else if ($operator == '<') {
465
        return -1;
466
    } else if ($operator == '>') {
467
        return 1;
468
    }
469
}
470
471
function isValidOperator($operator) {
472
    if($operator == '<' ||
473
       $operator == '>' ||
474
       $operator == '=') {
475
        return true;
476
    }
477
    return false;
478
}
479
480
/**
481
 * Returns all the items that match given criterias
482
 */
483
function searchDocmanItem($sessionKey, $group_id, $item_id, $criterias) {
484
    $params = array('id' => $item_id);
485
    foreach($criterias as $criteria) {
486
487
        $params[$criteria->field_name.'_value'] = $criteria->field_value;
488
        if (!isValidOperator($criteria->operator)) {
489
            return new SoapFault(invalid_operator, 'This operator is not valid. Only <, >, = are valid.', 'searchDocmanItem');
490
        }
491
        $params[$criteria->field_name.'_operator']  = operatorToValue($criteria->operator);
492
    }
493
    return _makeDocmanRequest($sessionKey, $group_id, 'search', $params);
494
}
495
$soapFunctions[] = array('searchDocmanItem', 'Returns all the items that match given criterias', 'tns:ArrayOfDocman_Item');
496
497
/**
498
 * Returns the the content of a file (or embedded file) base64 encoded
499
 */
500
function getDocmanFileContents($sessionKey, $group_id, $item_id, $version_number) {
501
    $params = array('item_id' => $item_id);
502
    if ($version_number >= 0) {
503
        $params['version_number'] = $version_number;
504
    }
505
    return _makeDocmanRequest($sessionKey, $group_id, 'getFileContents', $params);
506
}
507
$soapFunctions[] = array('getDocmanFileContents', 'Returns the content of a file (or embedded file) base64 encoded. (version_number = -1 means last)', 'xsd:string');
508
509
/**
510
 * Returns the MD5 checksum of the file (last version) corresponding to the provided item ID.
511
 */
512
function getDocmanFileMD5sum($sessionKey, $group_id, $item_id, $version_number) {
513
    $params = array('item_id' => $item_id, 'version' => $version_number);
514
    return _makeDocmanRequest($sessionKey, $group_id, 'getFileMD5sum', $params);
515
}
516
$soapFunctions[] = array('getDocmanFileMD5sum', 'Returns the MD5 checksum of the file (last version) corresponding to the provided item ID', 'xsd:string');
517
518
519
/**
520
 * Returns the MD5 checksum of the file (all versions) corresponding to the provided item ID.
521
 */
522
function getDocmanFileAllVersionsMD5sum($sessionKey, $group_id, $item_id) {
523
    $params = array('item_id' => $item_id, 'all_versions' => true);
524
    return _makeDocmanRequest($sessionKey, $group_id, 'getFileMD5sum', $params);
525
}
526
$soapFunctions[] = array('getDocmanFileAllVersionsMD5sum', 'Returns the MD5 checksum of the file (all versions) corresponding to the provided item ID', 'tns:ArrayOfstring');
527
528
529
/**
530
 * Returns the metadata of the given project 
531
 */
532
function getDocmanProjectMetadata($sessionKey, $group_id) {
533
534
    $result = _makeDocmanRequest($sessionKey, $group_id, 'getProjectMetadata');
535
    if ($result instanceof SoapFault) {
536
        return $result;
537
    }
538
539
    foreach ($result as &$md) {
540
        $md->listOfValues = array();
541
        if($md->getType() == PLUGIN_DOCMAN_METADATA_TYPE_LIST) {
542
            $md->listOfValues = _makeDocmanRequest($sessionKey, $group_id, 'getMetadataListOfValues', array('label' => $md->getLabel()));
543
         }
544
    }
545
    
546
    return $result;
547
}
548
$soapFunctions[] = array('getDocmanProjectMetadata', 'Returns the metadata of the given project', 'tns:ArrayOfMetadata');
549
550
551
/**
552
 * Returns the tree information of the given project
553
 */
554
function getDocmanTreeInfo($sessionKey, $group_id, $parent_id) {    
555
    return _makeDocmanRequest($sessionKey, $group_id, 'getTreeInfo', array('parent_id' => $parent_id));
556
}
557
$soapFunctions[] = array('getDocmanTreeInfo', 'Returns the tree information of the given project', 'tns:ArrayOfItemInfo');
558
559
560
/**
561
 * Creates a docman folder
562
 */
563
function createDocmanFolder($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $permissions, $metadata, $owner, $create_date, $update_date) {
564
    return _createDocmanItem($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, PLUGIN_DOCMAN_ITEM_TYPE_FOLDER, $permissions, $metadata, $owner, $create_date, $update_date);
565
}
566
$soapFunctions[] = array('createDocmanFolder', 'Create a folder');
567
568
569
/**
570
 * Creates a docman file
571
 */
572
function createDocmanFile($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $obsolescence_date, $permissions, $metadata, $file_size, $file_name, $mime_type, $content, $chunk_offset, $chunk_size, $author, $date, $owner, $create_date, $update_date) {
573
574
    $content = base64_decode($content);
575
    
576
    //ignore mime type coming from the client, guess it instead
577
    //Write the content of the file into a temporary file
578
    //The best accurate results are got when the file has the real extension, therefore use the filename
579
    $tmp     = tempnam(ForgeConfig::get('tmp_dir'), 'Mime-detect');
580
    $tmpname = $tmp .'-'. basename($file_name);
581
    file_put_contents($tmpname, $content);
582
    $mime_type = MIME::instance()->type($tmpname);
583
584
    //remove both files created by tempnam() and file_put_contents()
585
    unlink($tmp);
586
    unlink($tmpname);
587
588
    $extraParams = array(
589
        'chunk_offset'   => $chunk_offset,
590
        'chunk_size'     => $chunk_size,
591
        'file_size'      => $file_size,
592
        'file_name'      => $file_name,
593
        'mime_type'      => $mime_type,
594
        'upload_content' => $content,
595
        'date'           => $date,
596
        'author'         => _getUserIdByUserName($author),
597
    );
598
    
599
    return _createDocmanDocument($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $obsolescence_date, PLUGIN_DOCMAN_ITEM_TYPE_FILE, $permissions, $metadata, $owner, $create_date, $update_date, $extraParams);
600
}
601
$soapFunctions[] = array('createDocmanFile', 'Creates a docman file');
602
603
604
/**
605
 * Creates a docman embedded file
606
 */
607
function createDocmanEmbeddedFile($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $obsolescence_date, $content, $permissions, $metadata, $author, $date, $owner, $create_date, $update_date) {
608
609
    $extraParams = array(
610
        'content' => $content,
611
        'date'    => $date,
612
        'author'  => _getUserIdByUserName($author),
613
    );
614
    
615
    return _createDocmanDocument($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $obsolescence_date, PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE, $permissions, $metadata, $owner, $create_date, $update_date, $extraParams);
616
}
617
$soapFunctions[] = array('createDocmanEmbeddedFile', 'Creates a docman embedded file');
618
619
620
/**
621
 * Creates a docman wiki page
622
 */
623
function createDocmanWikiPage($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $obsolescence_date, $content, $permissions, $metadata, $owner, $create_date, $update_date) {
624
    $extraParams['item']['wiki_page'] = $content;
625
    return _createDocmanDocument($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $obsolescence_date, PLUGIN_DOCMAN_ITEM_TYPE_WIKI, $permissions, $metadata, $owner, $create_date, $update_date, $extraParams);
626
}
627
$soapFunctions[] = array('createDocmanWikiPage', 'Creates a docman wiki page');
628
629
630
/**
631
 * Creates a docman link
632
 */
633
function createDocmanLink($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $obsolescence_date, $content, $permissions, $metadata, $owner, $create_date, $update_date) {
634
    $extraParams['item']['link_url'] = $content;
635
    return _createDocmanDocument($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $obsolescence_date, PLUGIN_DOCMAN_ITEM_TYPE_LINK, $permissions, $metadata, $owner, $create_date, $update_date, $extraParams);
636
}
637
$soapFunctions[] = array('createDocmanLink', 'Creates a docman link');
638
639
640
/**
641
 * Creates a docman embedded file
642
 */
643
function createDocmanEmptyDocument($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $obsolescence_date, $permissions, $metadata, $owner, $create_date, $update_date) {
644
    return _createDocmanDocument($sessionKey, $group_id, $parent_id, $title, $description, $ordering, $status, $obsolescence_date, PLUGIN_DOCMAN_ITEM_TYPE_EMPTY, $permissions, $metadata, $owner, $create_date, $update_date);
645
}
646
$soapFunctions[] = array('createDocmanEmptyDocument', 'Creates a docman empty document');
647
648
649
/**
650
 * Creates a docman file version
651
 */
652
function createDocmanFileVersion($sessionKey, $group_id, $item_id, $label, $changelog, $file_size, $file_name, $mime_type, $content, $chunk_offset, $chunk_size, $author, $date) {
653
        
654
    $params = array(
655
        'id'             => $item_id,
656
        'version'        => array('label' => $label, 'changelog' => $changelog),
657
        'upload_content' => base64_decode($content),
658
        'chunk_offset'   => $chunk_offset,
659
        'chunk_size'     => $chunk_size,
660
        'file_size'      => $file_size,
661
        'file_name'      => $file_name,
662
        'mime_type'      => $mime_type,
663
        'date'           => $date,
664
        'author'         => _getUserIdByUserName($author),
665
    );
666
    
667
    return _makeDocmanRequest($sessionKey, $group_id, 'new_version', $params);
668
}
669
$soapFunctions[] = array('createDocmanFileVersion', 'Creates a docman file version');
670
671
672
/**
673
 * Creates a docman embedded file version
674
 */
675
function createDocmanEmbeddedFileVersion($sessionKey, $group_id, $item_id, $label, $changelog, $content, $author, $date) {
676
677
    $params = array(
678
        'id'        => $item_id,
679
        'version'   => array('label' => $label, 'changelog' => $changelog,),
680
        'content'   => $content,
681
        'date'      => $date,
682
        'author'    => _getUserIdByUserName($author),
683
    );
684
    
685
    return _makeDocmanRequest($sessionKey, $group_id, 'new_version', $params);
686
}
687
$soapFunctions[] = array('createDocmanEmbeddedFileVersion', 'Creates a docman embedded file version');
688
689
690
/**
691
 * Appends a chunk of data to the last version of a file
692
 */
693
function appendDocmanFileChunk($sessionKey, $group_id, $item_id, $content, $chunk_offset, $chunk_size) {
694
695
    $params = array(
696
        'item_id'        => $item_id,
697
        'upload_content' => base64_decode($content),
698
        'chunk_offset'   => $chunk_offset,
699
        'chunk_size'     => $chunk_size,
700
    );
701
        
702
    return _makeDocmanRequest($sessionKey, $group_id, 'appendFileChunk', $params);
703
}
704
$soapFunctions[] = array('appendDocmanFileChunk', 'Appends a chunk of data to the last version of a file');
705
706
707
/**
708
 * Moves an item
709
 */
710
function moveDocmanItem($sessionKey, $group_id, $item_id, $new_parent) {
711
    return _makeDocmanRequest($sessionKey, $group_id, 'move_here', array('item_to_move' => $item_id, 'id' => $new_parent));
712
}
713
$soapFunctions[] = array('moveDocmanItem', 'Moves an item in a new folder', 'xsd:boolean');
714
715
716
717
/**
718
 * Download a file given its item_id and version
719
 */
720
function getDocmanFileChunk($sessionKey, $group_id, $item_id, $version_number, $chunk_offset, $chunk_size) {
721
        $params = array(
722
        'item_id'        => $item_id,
723
        'version_number' => $version_number,
724
        'chunk_offset'   => $chunk_offset,
725
        'chunk_size'     => $chunk_size,
726
    );
727
    
728
    return _makeDocmanRequest($sessionKey, $group_id, 'getFileChunk', $params);
729
}
730
$soapFunctions[] = array('getDocmanFileChunk', 'Returns a part (chunk) of the content, encoded in base64, '.
731
                                               'of the file/embedded file which id item_id of a given version version_number, '.
732
                                               'if the version is not specified it will be the current one, in the project group_id.'.
733
                                               'Returns an error if the group ID does not match with a valid project, or if the item ID '.
734
                                               'does not match with the right group ID, or if the version number does not match with the item ID.', 'xsd:string');
735
736
/**
737
 * Deletes a docman item
738
 */
739
function deleteDocmanItem($sessionKey, $group_id, $item_id) {
740
    return _makeDocmanRequest($sessionKey, $group_id, 'delete', array('id' => $item_id));
741
}
742
$soapFunctions[] = array('deleteDocmanItem', 'Delete an item (document or folder)');
743
744
745
/**
746
 * Enables the monitoring of an item by a user
747
 */
748
function monitorDocmanItem($sessionKey, $group_id, $item_id) {
749
    return _makeDocmanRequest($sessionKey, $group_id, 'monitor', array('id' => $item_id, 'monitor' => true));
750
}
751
$soapFunctions[] = array('monitorDocmanItem', 'Enables the monitoring of an item by a user', 'xsd:boolean');
752
753
754
/**
755
 * Updates a docman folder
756
 */
757
function updateDocmanFolder($sessionKey, $group_id, $item_id, $title, $description, $status, $permissions, $metadata, $owner, $create_date, $update_date) {
758
    return _updateDocmanItem($sessionKey, $group_id, $item_id, $title, $description, $status, PLUGIN_DOCMAN_ITEM_TYPE_FOLDER, $permissions, $metadata, $owner, $create_date, $update_date);
759
}
760
$soapFunctions[] = array('updateDocmanFolder', 'Updates a docman folder');
761
762
763
/**
764
 * Updates a docman file
765
 */
766
function updateDocmanFile($sessionKey, $group_id, $item_id, $title, $description, $status, $obsolescence_date, $permissions, $metadata, $owner, $create_date, $update_date) {
767
    return _updateDocmanDocument($sessionKey, $group_id, $item_id, $title, $description, $status, $obsolescence_date, PLUGIN_DOCMAN_ITEM_TYPE_FILE, $permissions, $metadata, $owner, $create_date, $update_date);
768
}
769
$soapFunctions[] = array('updateDocmanFile', 'Updates a docman file');
770
771
772
/**
773
 * Updates a docman embedded file
774
 */
775
function updateDocmanEmbeddedFile($sessionKey, $group_id, $item_id, $title, $description, $status, $obsolescence_date, $permissions, $metadata, $owner, $create_date, $update_date) {
776
    return _updateDocmanDocument($sessionKey, $group_id, $item_id, $title, $description, $status, $obsolescence_date, PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE, $permissions, $metadata, $owner, $create_date, $update_date);
777
}
778
$soapFunctions[] = array('updateDocmanEmbeddedFile', 'Updates a docman embedded file');
779
780
781
/**
782
 * Updates a docman wiki page
783
 */
784
function updateDocmanWikiPage($sessionKey, $group_id, $item_id, $title, $description, $status, $obsolescence_date, $content, $permissions, $metadata, $owner, $create_date, $update_date) {
785
    if ($content !== null) $extraParams['item']['wiki_page'] = $content;
786
    return _updateDocmanDocument($sessionKey, $group_id, $item_id, $title, $description, $status, $obsolescence_date, PLUGIN_DOCMAN_ITEM_TYPE_WIKI, $permissions, $metadata, $owner, $create_date, $update_date, $extraParams); 
787
}
788
$soapFunctions[] = array('updateDocmanWikiPage', 'Updates a docman wiki page');
789
790
791
/**
792
 * Updates a docman link
793
 */
794
function updateDocmanLink($sessionKey, $group_id, $item_id, $title, $description, $status, $obsolescence_date, $content, $permissions, $metadata, $owner, $create_date, $update_date) {
795
    if ($content !== null) $extraParams['item']['link_url'] = $content;
796
    return _updateDocmanDocument($sessionKey, $group_id, $item_id, $title, $description, $status, $obsolescence_date, PLUGIN_DOCMAN_ITEM_TYPE_LINK, $permissions, $metadata, $owner, $create_date, $update_date, $extraParams); 
797
}
798
$soapFunctions[] = array('updateDocmanLink', 'Updates a docman link'); 
799
800
801
/**
802
 * Updates a docman empty document
803
 */
804
function updateDocmanEmptyDocument($sessionKey, $group_id, $item_id, $title, $description, $status, $obsolescence_date, $permissions, $metadata, $owner, $create_date, $update_date) {
805
    return _updateDocmanDocument($sessionKey, $group_id, $item_id, $title, $description, $status, $obsolescence_date, PLUGIN_DOCMAN_ITEM_TYPE_EMPTY, $permissions, $metadata, $owner, $create_date, $update_date);
806
}
807
$soapFunctions[] = array('updateDocmanEmptyDocument', 'Updates a docman empty document');
808
809
810
//
811
// Functions registering
812
//
813
814
if (defined('NUSOAP')) {
815
    // Soap parameters definition
816
    $GLOBALS['soapParameters'] = array(
817
                      'sessionKey'        => array('xsd:string', 'Session key'),
818
                      'group_id'          => array('xsd:int', 'Group ID'),
819
                      'parent_id'         => array('xsd:int', 'Parent ID'),
820
                      'item_id'           => array('xsd:int', 'item ID'),
821
                      'title'             => array('xsd:string', 'Title'),
822
                      'description'       => array('xsd:string', 'Description'),
823
                      'ordering'          => array('xsd:string', 'Ordering (begin, end)'),
824
                      'status'            => array('xsd:string', 'Status (none, draft, approved, rejected)'),
825
                      'obsolescence_date' => array('xsd:string', 'Obsolescence date (timestamp)'),
826
                      'content'           => array('xsd:string', 'Content'),
827
                      'permissions'       => array('tns:ArrayOfPermission', 'Permissions'),
828
                      'metadata'          => array('tns:ArrayOfMetadataValue', 'Metadata values'),
829
                      'owner'             => array('xsd:string', 'Owner of the item'),
830
                      'create_date'       => array('xsd:string', 'Item creation date (timestamp)'),
831
                      'update_date'       => array('xsd:string', 'Item update date (timestamp)'),
832
                      'author'            => array('xsd:string', 'Version author'),
833
                      'date'              => array('xsd:string', 'Version date (timestamp)'),
834
                      'label'             => array('xsd:string', 'version label'),
835
                      'changelog'         => array('xsd:string', 'Version changelog'),
836
                      'file_size'         => array('xsd:int', 'File size'),
837
                      'file_name'         => array('xsd:string', 'File name'),
838
                      'mime_type'         => array('xsd:string', 'Mime type'),
839
                      'chunk_offset'      => array('xsd:int', 'Chunk offset'),
840
                      'chunk_size'        => array('xsd:int', 'Chunk size'),
841
                      'new_parent'        => array('xsd:int', 'New parent ID'),
842
                      'criterias'         => array('tns:ArrayOfCriteria', 'Criteria'),
843
                      'version_number'    => array('xsd:int', 'Version number'),
844
                  );
845
}
846
/**
847
 * Registers a function on the soap server. The parameters of the function are retrieved by reflexion.
848
 */
849
function _registerFunction($name, $doc, $response = 'xsd:int') {
850
    if (defined('NUSOAP')) {
851
        // WSDL generation
852
        $function = new ReflectionFunction($name);
853
        $parameters = $function->getParameters();
854
        
855
        $usedParameters = array();
856
        foreach ($parameters as $parameter) {
857
        	$usedParameters[] = $parameter->getName();
0 ignored issues
show
Consider using $parameter->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
858
        }
859
        
860
        $soapParameters = $GLOBALS['soapParameters'];
861
    
862
        $parameters = array();
863
        $paramsDoc = '<pre>';
864
865
        foreach ($usedParameters as $usedParameter) {
866
            $parameters[$usedParameter] = $soapParameters[$usedParameter][0];
867
            $paramsDoc .= str_pad($usedParameter, 20).$soapParameters[$usedParameter][1].'<br/>';
868
        }
869
        
870
        $paramsDoc .= '</pre>';
871
        
872
        $GLOBALS['server']->register(
873
            $name,
874
            $parameters,
875
            array($name.'Response' => $response),
876
            $GLOBALS['uri'],
877
            $GLOBALS['uri'].'#'.$name,
878
            'rpc',
879
            'encoded',
880
            "$doc $paramsDoc"
881
        );
882
    } else {
883
        $GLOBALS['server']->addFunction($name);
884
    }
885
}
886
887
/**
888
 * Registers all the functions defined in the $soapFunctions array 
889
 */
890
function _registerFunctions($functions) {
891
    if (is_array($functions)) {
892
        foreach ($functions as $function) {
893
            if (isset($function[2])) {
894
    	        _registerFunction($function[0], $function[1], $function[2]);
895
            } else {
896
                _registerFunction($function[0], $function[1]);
897
            }
898
        }
899
    }
900
}
901
902
_registerFunctions($soapFunctions);
903
904
?>
905