1 |
richard.p.wagner |
734 |
<?php |
2 |
|
|
|
3 |
|
|
require_once(BACKEND.'config.backend.inc'); |
4 |
|
|
require_once(BACKEND.'properties.php'); |
5 |
richard.p.wagner |
735 |
require_once(BACKEND.'views.php'); |
6 |
|
|
require_once(BACKEND.'protocols.php'); |
7 |
richard.p.wagner |
734 |
require_once(BACKEND.'node.php'); |
8 |
|
|
|
9 |
|
|
class VOSpace { |
10 |
|
|
|
11 |
richard.p.wagner |
738 |
private $AuthInfo; |
12 |
|
|
|
13 |
|
|
function __construct(){ |
14 |
|
|
$this->AuthInfo = array('username' => Null, |
15 |
|
|
'password' => Null, |
16 |
|
|
'authenticated' => False); |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
function getAuthInfo( $sec_header ) { |
20 |
|
|
|
21 |
|
|
$p = xml_parser_create(); |
22 |
|
|
xml_parse_into_struct($p, $sec_header->any, $vals, $index); |
23 |
|
|
xml_parser_free($p); |
24 |
|
|
|
25 |
|
|
$username = ''; |
26 |
|
|
$password = ''; |
27 |
|
|
foreach( $vals as $element){ |
28 |
|
|
if( strpos($element['tag'], "USERNAMETOKEN") === FALSE ){ |
29 |
|
|
if( strpos($element['tag'], "USERNAME") !== FALSE ) |
30 |
|
|
$this->AuthInfo['username'] = $element['value']; |
31 |
|
|
if( strpos($element['tag'], "PASSWORD") !== FALSE ) |
32 |
|
|
$this->AuthInfo['password'] = $element['value']; |
33 |
|
|
} |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
if( $this->AuthInfo['username'] == 'joe' && |
37 |
|
|
$this->AuthInfo['password'] == 'doe' ){ |
38 |
|
|
$this->AuthInfo['authenticated'] = True; |
39 |
|
|
}else{ |
40 |
|
|
throw new SoapFault("Server", "Not authenticated.", " ", |
41 |
|
|
array(), |
42 |
|
|
"NotAuthenticatedFault"); |
43 |
|
|
} |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
function getAuthorization($method_name){ |
47 |
|
|
if( $this->AuthInfo['username'] == 'joe' |
48 |
|
|
&& $method_name == 'GetProperties') |
49 |
|
|
return False; |
50 |
|
|
else |
51 |
|
|
return True; |
52 |
|
|
} |
53 |
|
|
|
54 |
richard.p.wagner |
735 |
function getViews(){ |
55 |
|
|
global $provided_views; |
56 |
|
|
global $accepted_views; |
57 |
|
|
return array('accepts' => $accepted_views, |
58 |
|
|
'provides' => $provided_views); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
function getProtocols(){ |
62 |
|
|
global $provided_protocols; |
63 |
|
|
global $accepted_protocols; |
64 |
|
|
return array('accepts' => $accepted_protocols, |
65 |
|
|
'provides' => $provided_protocols); |
66 |
|
|
} |
67 |
|
|
|
68 |
richard.p.wagner |
734 |
function getProperties(){ |
69 |
|
|
global $provided_properties; |
70 |
|
|
return array('accepts' => null, |
71 |
|
|
'provides' => $provided_properties, |
72 |
richard.p.wagner |
735 |
'contains' => $provided_properties); |
73 |
richard.p.wagner |
734 |
} |
74 |
|
|
|
75 |
|
|
function listNodes($node_request) { |
76 |
|
|
// get uri to list |
77 |
|
|
// need to parse this for cleanliness at some point |
78 |
|
|
// (trailing slashes, etc.) |
79 |
richard.p.wagner |
735 |
$uri = $node_request->nodes->node->uri; |
80 |
richard.p.wagner |
734 |
|
81 |
|
|
$token=null; |
82 |
|
|
$limit=False; |
83 |
|
|
$detail='min'; |
84 |
|
|
|
85 |
richard.p.wagner |
735 |
if($node_request->token) |
86 |
|
|
$token = $node_request->token; |
87 |
|
|
if($node_request->limit) |
88 |
|
|
$limit = $node_request->limit; |
89 |
|
|
if($node_request->detail) |
90 |
|
|
$detail = $node_request->detail; |
91 |
richard.p.wagner |
734 |
|
92 |
richard.p.wagner |
735 |
$node_list = array('detail' => $detail, |
93 |
|
|
'nodes' => array()); |
94 |
richard.p.wagner |
734 |
|
95 |
richard.p.wagner |
735 |
$path = str_replace( VOSPACE_ROOT, FILE_SYSTEM_ROOT, $uri ); |
96 |
|
|
// error_log(var_export($path.'\n', True), 3, "/var/tmp/my-errors.log"); |
97 |
|
|
// quick check to see if this is a single file |
98 |
|
|
if(is_file($path)){ |
99 |
|
|
$node_uri = str_replace( FILE_SYSTEM_ROOT, VOSPACE_ROOT, $path ); |
100 |
|
|
|
101 |
|
|
$new_node = new Node($node_uri); |
102 |
|
|
if($detail != 'min') |
103 |
|
|
$new_node->populateProperties(); |
104 |
|
|
$node_list['nodes'][0] = $new_node; |
105 |
|
|
}else{ |
106 |
|
|
|
107 |
|
|
// look for wildcards and trailing slashes |
108 |
|
|
if( strpos($path, "*") === FALSE && |
109 |
|
|
$path[strlen($path) - 1] != '/' ){ |
110 |
|
|
$path = $path . "/*"; |
111 |
|
|
} |
112 |
|
|
|
113 |
richard.p.wagner |
734 |
$i = 0; |
114 |
richard.p.wagner |
735 |
foreach (glob($path) as $filename) { |
115 |
|
|
$file = basename($filename); |
116 |
|
|
if ($file != "." && $file != ".." && $file != ".svn") { |
117 |
|
|
$node_uri = str_replace( FILE_SYSTEM_ROOT, VOSPACE_ROOT, $filename ); |
118 |
richard.p.wagner |
734 |
|
119 |
richard.p.wagner |
735 |
$new_node = new Node($node_uri); |
120 |
richard.p.wagner |
734 |
if($detail != 'min') |
121 |
richard.p.wagner |
735 |
$new_node->populateProperties(); |
122 |
|
|
$node_list['nodes'][$i++] = $new_node; |
123 |
|
|
} |
124 |
richard.p.wagner |
734 |
} |
125 |
richard.p.wagner |
735 |
} |
126 |
richard.p.wagner |
734 |
|
127 |
richard.p.wagner |
735 |
if(count($node_list['nodes']) == 0) |
128 |
|
|
unset($node_list['nodes']); |
129 |
|
|
|
130 |
richard.p.wagner |
734 |
return $node_list; |
131 |
|
|
} |
132 |
richard.p.wagner |
735 |
|
133 |
richard.p.wagner |
734 |
} |
134 |
|
|
|
135 |
|
|
?> |