Commit d471cf491763c3b150229ebbe0a0948a70397306
1 parent
28c19276
Exists in
master
and in
112 other branches
format; IMPEX in Bases.xml has now attribute isSimulation
Showing
1 changed file
with
575 additions
and
672 deletions
Show diff stats
php/classes/UserMgr.php
... | ... | @@ -13,748 +13,651 @@ define('TTPATH', USERPATH.'TT/'); |
13 | 13 | define('JOBPATH', USERPATH.'jobs/'); |
14 | 14 | */ |
15 | 15 | |
16 | - class UserMgr { | |
17 | - | |
18 | - | |
19 | - public $user, $IP, $userdir; | |
20 | - protected $passwd; | |
21 | - protected $sessionID; | |
22 | - protected $userDirs = array('USERWSDIR' => 'WS', 'USERREQDIR' => 'REQ', 'USERDATADIR' => 'DATA', | |
23 | - 'USERWORKINGDIR' =>'RES', 'USERTTDIR' => 'TT', 'USERJOBDIR' => 'JOBS', | |
24 | - 'USERTEMPDIR' => 'TEMP'); | |
25 | - protected $userMissions; | |
26 | - protected $amdaClient; //client to dd webservice | |
27 | - | |
28 | - public $isFirst = false; | |
29 | - public $isNewInfo = false; | |
30 | - public $isSpecialInfo = null; | |
31 | - | |
32 | - function __construct($username,$password,$sessionID) { | |
33 | - | |
16 | +class UserMgr | |
17 | +{ | |
18 | + public $user, $IP, $userdir; | |
19 | + protected $passwd; | |
20 | + protected $sessionID; | |
21 | + protected $userDirs = array('USERWSDIR' => 'WS', 'USERREQDIR' => 'REQ', 'USERDATADIR' => 'DATA', | |
22 | + 'USERWORKINGDIR' =>'RES', 'USERTTDIR' => 'TT', 'USERJOBDIR' => 'JOBS', | |
23 | + 'USERTEMPDIR' => 'TEMP'); | |
24 | + protected $userMissions; | |
25 | + protected $amdaClient; //client to dd webservice | |
26 | + | |
27 | + public $isFirst = false; | |
28 | + public $isNewInfo = false; | |
29 | + public $isSpecialInfo = null; | |
30 | + | |
31 | + function __construct($username,$password,$sessionID) | |
32 | + { | |
34 | 33 | // if magic quotes is on, stripslashes |
35 | - if(get_magic_quotes_gpc()){ | |
36 | - $in = array(&$_GET, &$_POST, &$_COOKIE); | |
37 | - while(list($k,$v) = each($in)){ | |
38 | - foreach($v as $key => $val){ | |
39 | - if(!is_array($val)){ | |
40 | - $in[$k][$key] = stripslashes($val); | |
41 | - continue; | |
34 | + if(get_magic_quotes_gpc()) | |
35 | + { | |
36 | + $in = array(&$_GET, &$_POST, &$_COOKIE); | |
37 | + while(list($k,$v) = each($in)) | |
38 | + { | |
39 | + foreach($v as $key => $val) | |
40 | + { | |
41 | + if(!is_array($val)) | |
42 | + { | |
43 | + $in[$k][$key] = stripslashes($val); | |
44 | + continue; | |
45 | + } | |
46 | + $in[] =& $in[$k][$key]; | |
47 | + } | |
48 | + } | |
49 | + unset($in); | |
42 | 50 | } |
43 | - $in[] =& $in[$k][$key]; | |
44 | - } | |
45 | - } | |
46 | - unset($in); | |
47 | - } | |
48 | 51 | |
49 | - if (isset($_POST['username'])) { | |
50 | - // Process Guest Login | |
51 | - if (strcasecmp(trim($_POST['username']),"guest") == 0) { | |
52 | - $this->processGuestLogin(); | |
53 | - } | |
54 | - else { | |
55 | - $this->user = trim($_POST['username']); | |
56 | - } | |
57 | - } | |
58 | - else if (isset($username)) | |
59 | - $this->user = trim($username); | |
60 | - | |
61 | - //TODO crypt / decrypt | |
62 | - if (!isset($this->passwd)) { | |
63 | - if (isset($_POST['password'])) | |
64 | - $this->passwd = $_POST['password']; | |
65 | - else if (isset($password)) | |
66 | - $this->passwd = $password; | |
67 | - } | |
68 | - | |
69 | - if (isset($_GET['sessionID'])) | |
70 | - $this->user = $_GET['sessionID']; | |
71 | - else if (isset($sessionID)) | |
72 | - $this->user = $sessionID; | |
73 | - $this->amdaClient = new AmdaClient(); | |
74 | - } | |
75 | - | |
76 | - //TODO if needed?? set session ID | |
77 | - protected function setID() { | |
78 | - | |
79 | - | |
80 | - } | |
81 | - | |
82 | - | |
83 | - public function getIPclient(){ | |
84 | - | |
85 | - /* | |
86 | - REMOTE_ADDR is the only really reliable information, | |
87 | - as it is transmitted to you by your web server that | |
88 | - is handling the request. It can be theoretically | |
89 | - falsified as well, but that is much, much harder | |
90 | - than spoofing a header value, and an entirely different class of attack. | |
91 | -*/ | |
92 | - if (getenv('REMOTE_ADDR')) { | |
93 | - $realIP = getenv('REMOTE_ADDR'); | |
94 | - if ($realIP == '10.10.131.1') { // proxy amdatest et openam | |
95 | - $allIPs = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']); | |
96 | - $realIP = count($allIPs) > 1 ? trim($allIPs[0]) : $_SERVER['HTTP_X_FORWARDED_FOR']; | |
97 | - } | |
98 | - } | |
99 | - else { | |
100 | - //get local IP | |
101 | - $command="hostname -i"; | |
102 | - $realIP = exec($command); | |
103 | - } | |
104 | - return $realIP; | |
105 | - } | |
52 | + if (isset($_POST['username'])) | |
53 | + { | |
54 | + // Process Guest Login | |
55 | + if (strcasecmp(trim($_POST['username']),"guest") == 0) | |
56 | + { | |
57 | + $this->processGuestLogin(); | |
58 | + } | |
59 | + else | |
60 | + { | |
61 | + $this->user = trim($_POST['username']); | |
62 | + } | |
63 | + } | |
64 | + else if (isset($username)) | |
65 | + $this->user = trim($username); | |
66 | + | |
67 | + //TODO crypt / decrypt | |
68 | + if (!isset($this->passwd)) | |
69 | + { | |
70 | + if (isset($_POST['password'])) | |
71 | + $this->passwd = $_POST['password']; | |
72 | + else if (isset($password)) | |
73 | + $this->passwd = $password; | |
74 | + } | |
106 | 75 | |
76 | + if (isset($_GET['sessionID'])) | |
77 | + $this->user = $_GET['sessionID']; | |
78 | + else if (isset($sessionID)) | |
79 | + $this->user = $sessionID; | |
80 | + $this->amdaClient = new AmdaClient(); | |
81 | + } | |
82 | + | |
83 | + //TODO if needed?? set session ID | |
84 | + protected function setID() {} | |
85 | + | |
86 | + public function getIPclient() | |
87 | + { | |
88 | + /* | |
89 | + REMOTE_ADDR is the only really reliable information, | |
90 | + as it is transmitted to you by your web server that | |
91 | + is handling the request. It can be theoretically | |
92 | + falsified as well, but that is much, much harder | |
93 | + than spoofing a header value, and an entirely different class of attack. | |
94 | + */ | |
95 | + if (getenv('REMOTE_ADDR')) | |
96 | + { | |
97 | + $realIP = getenv('REMOTE_ADDR'); | |
98 | + if ($realIP == '10.10.131.1') { // proxy amdatest et openam | |
99 | + $allIPs = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']); | |
100 | + $realIP = count($allIPs) > 1 ? trim($allIPs[0]) : $_SERVER['HTTP_X_FORWARDED_FOR']; | |
101 | + } | |
102 | + } | |
103 | + else | |
104 | + { | |
105 | + //get local IP | |
106 | + $command="hostname -i"; | |
107 | + $realIP = exec($command); | |
108 | + } | |
109 | + return $realIP; | |
110 | + } | |
107 | 111 | |
108 | - public function getUserInfo() | |
109 | - { | |
110 | - return $this->amdaClient->getUserInfo($this->user); | |
111 | - } | |
112 | + public function getUserInfo() | |
113 | + { | |
114 | + return $this->amdaClient->getUserInfo($this->user); | |
115 | + } | |
112 | 116 | |
113 | 117 | /* |
114 | 118 | * Get Available Missions for a User (groups restriction) |
115 | 119 | */ |
116 | - protected function getAvailableMissionsByUser() | |
117 | - { | |
118 | - $res = $this->amdaClient->getUserAvailableMissions($this->user); | |
119 | - | |
120 | - if (!$res['success']) | |
121 | - return array('local' => array(), 'external' => array()); | |
122 | - return array('local' => $res['local'], 'external' => $res['external']); | |
123 | - } | |
120 | + protected function getAvailableMissionsByUser() | |
121 | + { | |
122 | + $res = $this->amdaClient->getUserAvailableMissions($this->user); | |
123 | + | |
124 | + if (!$res['success']) | |
125 | + return array('local' => array(), 'external' => array()); | |
126 | + | |
127 | + return array('local' => $res['local'], 'external' => $res['external']); | |
128 | + } | |
124 | 129 | |
125 | - public function createDir() | |
126 | - { | |
127 | - if (!mkdir($this->userdir, 0755, true)) return false; | |
130 | + public function createDir() | |
131 | + { | |
132 | + if (!mkdir($this->userdir, 0755, true)) return false; | |
128 | 133 | |
129 | - foreach ($this->userDirs as $key => $val) { | |
130 | - if (!mkdir($this->userdir.$val.'/', 0755, true)) return false; | |
131 | - } | |
132 | - return true; | |
133 | - } | |
134 | + foreach ($this->userDirs as $key => $val) | |
135 | + { | |
136 | + if (!mkdir($this->userdir.$val.'/', 0755, true)) return false; | |
137 | + } | |
138 | + return true; | |
139 | + } | |
134 | 140 | |
135 | 141 | /* |
136 | 142 | * Check if special groups with settings exist and user is from these groups |
137 | 143 | * Take the first group from user list |
138 | 144 | */ |
139 | - protected function isSpecialGroup() { | |
140 | - | |
141 | - $specialGrps = new DomDocument("1.0"); | |
142 | - | |
143 | - if (!($specialGrps->load(specialGrpsXml))) | |
144 | - return null; | |
145 | + protected function isSpecialGroup() | |
146 | + { | |
147 | + | |
148 | + $specialGrps = new DomDocument("1.0"); | |
145 | 149 | |
146 | - $info = $this->amdaClient->getUserInfo($this->user); | |
147 | - | |
148 | - $userGrps = explode(',',$info['group']); | |
150 | + if (!($specialGrps->load(specialGrpsXml))) return null; | |
149 | 151 | |
150 | - $specialGrpNode = null; | |
152 | + $info = $this->amdaClient->getUserInfo($this->user); | |
151 | 153 | |
152 | - foreach ($userGrps as $grp) { | |
153 | - $specialGrpNode = $specialGrps->getElementById($grp); | |
154 | - if ($specialGrpNode) break; | |
155 | - } | |
156 | - | |
157 | - return $specialGrpNode; | |
158 | - } | |
154 | + $userGrps = explode(',',$info['group']); | |
155 | + | |
156 | + $specialGrpNode = null; | |
157 | + | |
158 | + foreach ($userGrps as $grp) | |
159 | + { | |
160 | + $specialGrpNode = $specialGrps->getElementById($grp); | |
161 | + if ($specialGrpNode) break; | |
162 | + } | |
163 | + | |
164 | + return $specialGrpNode; | |
165 | + } | |
159 | 166 | |
160 | 167 | /* |
161 | 168 | * Totally replace IMPEX staff in user remote tree |
162 | 169 | */ |
163 | - protected function updateImpex() | |
164 | - { | |
165 | - $myRemoteBases = new DomDocument("1.0"); | |
170 | + protected function updateImpex() | |
171 | + { | |
172 | + $myRemoteBases = new DomDocument("1.0"); | |
166 | 173 | |
167 | - if (!$myRemoteBases->load(USERWSDIR.'RemoteParams.xml')) | |
168 | - return false; | |
169 | - | |
170 | - $myBases = $myRemoteBases->getElementsByTagName('dataCenter'); | |
171 | - | |
174 | + if (!$myRemoteBases->load(USERWSDIR.'RemoteParams.xml')) return false; | |
172 | 175 | |
173 | - if ($myBases->length < 1) | |
174 | - return false; | |
175 | - // Delete all impex staff at first | |
176 | - $i = $myBases->length - 1; | |
177 | - | |
178 | - while ($i > -1) { | |
179 | - $base = $myBases->item($i); | |
180 | - $id = $base->getAttribute('xml:id'); | |
176 | + $myBases = $myRemoteBases->getElementsByTagName('dataCenter'); | |
181 | 177 | |
182 | - if ($id == 'FMI_GUMICS'){ | |
183 | - $simuRemoteBases = new DomDocument("1.0"); | |
184 | - $simuRemoteBases->load(USERWSDIR.'RemoteParams.xml'); | |
185 | - | |
186 | - $gumicsNode = $simuRemoteBases->getElementById('FMI_GUMICS'); | |
187 | - if ($gumicsNode != NULL) | |
188 | - $gumicsRuns = $gumicsNode->getElementsByTagName('runID'); | |
189 | - } | |
190 | - | |
191 | - | |
192 | - | |
193 | - if (($base->hasAttribute('isSimulation')) || $id == "CLWeb") { | |
194 | - $base->parentNode->removeChild($base); | |
195 | - } | |
196 | - $i--; | |
197 | - } | |
198 | - | |
199 | - $remoteBases = new DomDocument("1.0"); | |
200 | - if (!$remoteBases->load(RemoteData.'Bases.xml')) | |
201 | - return false; | |
202 | - $bases = $remoteBases->getElementsByTagName('dataCenter'); | |
203 | - | |
204 | - if ($bases->length < 1) | |
205 | - return false; | |
206 | - | |
207 | - $myRootElement = $myRemoteBases->documentElement; | |
208 | - | |
209 | - // and add impex | |
210 | - foreach ($bases as $base) { | |
211 | - //TODO && $id != 'FMI_GUMICS' or ! hasAttribute('isAddable') | |
212 | - if ($base->hasAttribute('group') && | |
213 | - $base->getAttribute('group') == 'IMPEX') { | |
214 | - | |
215 | - $baseId = $base->getAttribute('xml:id'); | |
216 | - $baseXml = new DomDocument("1.0"); | |
217 | - // no data base description ; skip this data base | |
218 | - if (!file_exists(RemoteData.$baseId.'/base.xml')) continue; | |
178 | + if ($myBases->length < 1) return false; | |
179 | + // Delete all impex staff at first | |
180 | + $i = $myBases->length - 1; | |
219 | 181 | |
220 | - // can't read base.xml ; skip this data base | |
221 | - if (!$baseXml->load(RemoteData.$baseId.'/base.xml')) continue; | |
222 | - | |
223 | - $myBase = $myRemoteBases->importNode($baseXml->getElementById($baseId), true); | |
224 | - $myBase->setAttribute('name', $base->getAttribute('name')); | |
225 | - $myBase->setAttribute('desc', $base->getAttribute('desc')); | |
226 | - | |
227 | - if ($baseId == "FMI_GUMICS"){ | |
228 | - $gumicsSimuReg = $myRemoteBases->getElementById('FMI_GUMICS_Earth_Magnetosphere'); | |
229 | - | |
230 | - if (($gumicsSimuReg != NULL)&& ($gumicsRuns->length > 0)){ | |
231 | - for($c = 0; $c < $gumicsRuns->length; $c++){ | |
232 | - $node = $gumicsRuns->item($c); | |
233 | - $node = $myRemoteBases->importNode($node, true); | |
234 | - $gumicsSimuReg->appendChild($node); | |
235 | - } | |
236 | - } | |
237 | - } | |
238 | - | |
239 | - | |
240 | - $myRootElement->appendChild($myBase); | |
241 | - } | |
242 | - } | |
182 | + while ($i > -1) | |
183 | + { | |
184 | + $base = $myBases->item($i); | |
185 | + $id = $base->getAttribute('xml:id'); | |
186 | + | |
187 | + if ($id == 'FMI_GUMICS') | |
188 | + { | |
189 | + $simuRemoteBases = new DomDocument("1.0"); | |
190 | + $simuRemoteBases->load(USERWSDIR.'RemoteParams.xml'); | |
191 | + | |
192 | + $gumicsNode = $simuRemoteBases->getElementById('FMI_GUMICS'); | |
193 | + if ($gumicsNode != NULL) | |
194 | + $gumicsRuns = $gumicsNode->getElementsByTagName('runID'); | |
195 | + } | |
196 | + | |
197 | + if (($base->hasAttribute('isSimulation')) || $id == "CLWeb") | |
198 | + { | |
199 | + $base->parentNode->removeChild($base); | |
200 | + } | |
201 | + $i--; | |
202 | + } | |
203 | + | |
204 | + $remoteBases = new DomDocument("1.0"); | |
205 | + if (!$remoteBases->load(RemoteData.'Bases.xml')) return false; | |
206 | + | |
207 | + $bases = $remoteBases->getElementsByTagName('dataCenter'); | |
208 | + if ($bases->length < 1) return false; | |
209 | + | |
210 | + $myRootElement = $myRemoteBases->documentElement; | |
211 | + | |
212 | + // and add impex | |
213 | + foreach ($bases as $base) | |
214 | + { | |
215 | + //TODO && $id != 'FMI_GUMICS' or ! hasAttribute('isAddable') | |
216 | + if ($base->hasAttribute('isSimulation')) | |
217 | + { | |
218 | + $baseId = $base->getAttribute('xml:id'); | |
219 | + $baseXml = new DomDocument("1.0"); | |
220 | + // no data base description ; skip this data base | |
221 | + if (!file_exists(RemoteData.$baseId.'/base.xml')) continue; | |
222 | + | |
223 | + // can't read base.xml ; skip this data base | |
224 | + if (!$baseXml->load(RemoteData.$baseId.'/base.xml')) continue; | |
225 | + | |
226 | + $myBase = $myRemoteBases->importNode($baseXml->getElementById($baseId), true); | |
227 | + $myBase->setAttribute('name', $base->getAttribute('name')); | |
228 | + $myBase->setAttribute('desc', $base->getAttribute('desc')); | |
229 | + | |
230 | + if ($baseId == "FMI_GUMICS") | |
231 | + { | |
232 | + $gumicsSimuReg = $myRemoteBases->getElementById('FMI_GUMICS_Earth_Magnetosphere'); | |
233 | + | |
234 | + if (($gumicsSimuReg != NULL)&& ($gumicsRuns->length > 0)) | |
235 | + { | |
236 | + for($c = 0; $c < $gumicsRuns->length; $c++) | |
237 | + { | |
238 | + $node = $gumicsRuns->item($c); | |
239 | + $node = $myRemoteBases->importNode($node, true); | |
240 | + $gumicsSimuReg->appendChild($node); | |
241 | + } | |
242 | + } | |
243 | + } | |
244 | + $myRootElement->appendChild($myBase); | |
245 | + } | |
246 | + } | |
243 | 247 | |
244 | - return $myRemoteBases->save(USERWSDIR.'RemoteParams.xml'); | |
245 | - | |
246 | - } | |
247 | - | |
248 | - /* | |
249 | - * make local data tree from list of missions | |
250 | - */ | |
251 | - protected function makeLocalTree() | |
252 | - { | |
253 | - if (file_exists(DATAPATH.'rank.json')) | |
254 | - $cmpArr = json_decode(file_get_contents(DATAPATH.'rank.json'), true); | |
255 | - else | |
256 | - $cmpArr = null; | |
257 | - | |
258 | - $localMissions = new DomDocument("1.0"); | |
259 | - $localMissions->load(LocalData.'Missions.xml'); | |
260 | - | |
261 | - $xp = new domxpath($localMissions); | |
262 | - $bases = $xp->query("//MissionID[@status='required']"); | |
263 | - | |
264 | - $piBase = new DomDocument("1.0"); | |
265 | - $piBase->formatOutput = true; | |
266 | - $piBase->preserveWhiteSpace = false; | |
267 | - | |
268 | - $localDom = new DomDocument("1.0"); | |
269 | - $BASE = $localDom->createElement('dataRoot'); | |
270 | - $Amda = $localDom->createElement('dataCenter'); | |
271 | - $Amda_name = new DomAttr('name', 'AMDA'); | |
272 | - $Amda->appendChild($Amda_name); | |
273 | - $Amda_desc = new DomAttr('desc', 'AMDA_Internal_Data_Base'); | |
274 | - $Amda->appendChild($Amda_desc); | |
275 | - | |
276 | - $availableMis = $this->userMissions['local']; | |
277 | - | |
278 | - foreach ($bases as $base) { | |
279 | - $xml = LocalData.'DD_'.$base->nodeValue.'.xml'; | |
280 | - $notAvailable = (array_search($base->nodeValue,$availableMis) === FALSE); | |
281 | - if (file_exists($xml)){ | |
282 | - if (!$piBase->load($xml)) | |
283 | - error_log($base->nodeValue,1,email); | |
284 | - $vi = $piBase->getElementsByTagName("mission"); | |
285 | - if ($vi->length > 0) for ($i = 0; $i < $vi->length; $i++){ | |
286 | - $nodeNew = $localDom->importNode($vi->item($i),true); | |
287 | - $nodeNew->setAttribute('available',!$notAvailable); | |
288 | - // set rank by target name if file rank.json exists | |
289 | - if (is_array($cmpArr)) { | |
290 | - $targets = $vi->item($i)->getElementsByTagName('target'); | |
291 | - if ($targets->length > 0) { | |
292 | - // First target is the main one | |
293 | - $target = $targets->item(0); | |
294 | - $index = $cmpArr[$target->nodeValue]; | |
295 | - if ($index) | |
296 | - $nodeNew->setAttribute('rank',$index); | |
297 | - else $nodeNew->setAttribute('rank', 999); | |
298 | - } | |
299 | - } | |
300 | - $Amda->appendChild($nodeNew); | |
301 | - } | |
302 | - } | |
303 | - } | |
304 | - | |
305 | - if ($Amda->hasChildNodes()) $BASE->appendChild($Amda); | |
306 | - $localDom->appendChild($BASE); | |
307 | - | |
308 | - // set access rights at all levels | |
309 | - $xpLoc = new domxpath($localDom); | |
310 | - // get all nodes with 'group' attribute (restricted) | |
311 | - $restrictedTags = $xpLoc->query("//*[@group]"); | |
312 | - | |
313 | - if ($restrictedTags->length > 0) { | |
314 | - $info = $this->amdaClient->getUserInfo($this->user); | |
315 | - $userGrps = explode(',',preg_replace('/\s+/', '',$info['group'])); | |
316 | - | |
317 | - foreach ($restrictedTags as $restriction) { | |
318 | - $group = $restriction->getAttribute('group'); | |
319 | - $available = in_array($group,$userGrps); | |
320 | - // special restrictions | |
321 | - if (!$available && $restriction->getAttribute('restriction')) { | |
322 | - $restriction_type = $restriction->getAttribute('restriction'); | |
323 | - // time restriction | |
324 | - if ($restriction_type == 'time') { | |
325 | - $id_restr = $restriction->getAttribute('xml:id'); | |
326 | - $restrictions = $this->amdaClient->getTimeRestriction(str_replace(":","_",$id_restr)); | |
327 | - if ($restrictions) { | |
328 | - $restriction->setAttribute('restricted', $restrictions['days']); | |
329 | - $dataStop = $restriction->getElementsByTagName('dataStop'); | |
330 | - if ($dataStop->length > 0) { | |
331 | - $globalStop = explode("T", $restrictions['globalstop']); | |
332 | - $dataStop->item(0)->nodeValue = str_replace("-", "/", $globalStop[0]); | |
333 | - } | |
334 | - } | |
335 | - } | |
336 | - // absolute restriction: remove node | |
337 | - else { | |
338 | - $restriction->parentNode->removeChild($restriction); | |
339 | - } | |
340 | - } | |
341 | - else { | |
342 | - // general restriction: disable node | |
343 | - $restriction->setAttribute('restricted', !$available); | |
344 | - } | |
345 | - } | |
346 | - } | |
347 | - | |
348 | - $xsl = new DomDocument("1.0"); | |
349 | - $xsl->load(XMLPATH.'dd2tree.xsl'); | |
350 | - | |
351 | - $xslt = new XSLTProcessor(); | |
352 | - $xslt->importStylesheet($xsl); | |
353 | - | |
354 | - $piBase->loadXML($xslt->transformToXML($localDom)); | |
355 | - | |
356 | - $piBase->save(USERWSDIR.'LocalParams.xml'); | |
357 | - } | |
358 | - | |
248 | + return $myRemoteBases->save(USERWSDIR.'RemoteParams.xml'); | |
249 | + } | |
250 | + | |
359 | 251 | /* |
360 | - * make remote data tree from list of distant bases if it doezn't exist | |
361 | - */ | |
362 | - protected function makeRemoteTree() { | |
363 | - | |
364 | - $remoteBases = new DomDocument("1.0"); | |
365 | - $availableMis = $this->userMissions['external']; | |
252 | +* make remote data tree from list of distant bases if it doezn't exist | |
253 | +*/ | |
254 | + protected function makeRemoteTree() | |
255 | + { | |
256 | + $remoteBases = new DomDocument("1.0"); | |
257 | + $availableMis = $this->userMissions['external']; | |
366 | 258 | |
367 | - if (file_exists(USERWSDIR.'RemoteParams.xml')) | |
368 | - { | |
369 | - // replace IMPEX nodes | |
370 | - $status = $this->updateImpex(); | |
371 | - if (!$status) error_log('IMPEX Remote Base can not be updated',1,email); | |
372 | - // check/change access rights | |
373 | - $remoteBases->load(USERWSDIR.'RemoteParams.xml'); | |
374 | - $bases = $remoteBases->getElementsByTagName('dataCenter'); | |
375 | - $delete = new UserDeleteObsolete(); | |
376 | - if ($bases->length > 0) | |
377 | - foreach ($bases as $base) { | |
378 | - $baseId = $base->getAttribute('xml:id'); | |
379 | - $notAvailable = (array_search($baseId,$availableMis) === FALSE); | |
380 | - $base->setAttribute('available',!$notAvailable); | |
381 | - | |
382 | - if ($base->getAttribute('isSimulation')) continue; | |
383 | - | |
384 | - // Update Info on External Data Sets in UserTree.xml for everything except IMPEX | |
385 | - $dataSets = $base->getElementsByTagName("dataset"); | |
386 | - if ($dataSets->length > 0) { | |
387 | - $baseExtDom = new DomDocument("1.0"); | |
388 | - if (!$baseExtDom->load(RemoteData.$baseId.'/base.xml')) { | |
389 | - $base->setAttribute("desc","ATTENTION!!! This Base set DOES NOT ANY MORE EXIST!!! Remove it from your tree"); | |
390 | - $base->setAttribute('obsolete', true); | |
391 | - error_log('NO '.RemoteData.$baseId.'/base.xml',1,email); | |
392 | - continue; | |
393 | - } | |
394 | - foreach ($dataSets as $dataSet) { | |
395 | - $dataSetID = $dataSet->getAttribute("xml:id"); | |
396 | - $origDataSet = $baseExtDom->getElementById($dataSetID); | |
397 | - if ($origDataSet != null) { | |
398 | - $desc = $origDataSet->getAttribute("desc"); | |
399 | - if ($desc != null) $dataSet->setAttribute("desc", $desc); | |
400 | - } | |
401 | - else { | |
402 | - $delete->setVI($dataSet->getAttribute('name')); | |
403 | - $res = $delete->deleteDerived(); | |
404 | - $res = $delete->deleteConditions(); | |
405 | - $res = $delete->deleteRequests(); | |
406 | - $res = $delete->deleteAliases(); | |
407 | - $dataSet->setAttribute("desc","ATTENTION!!! This data set DOES NOT ANY MORE EXIST!!! Remove it from your tree"); | |
408 | - $dataSet->setAttribute('obsolete', true); | |
409 | - } | |
410 | - } | |
411 | - } | |
412 | - } | |
413 | - | |
414 | - return $remoteBases->save(USERWSDIR.'RemoteParams.xml'); | |
415 | - } | |
259 | + if (file_exists(USERWSDIR.'RemoteParams.xml')) | |
260 | + { | |
261 | + // replace IMPEX nodes | |
262 | + $status = $this->updateImpex(); | |
263 | + | |
264 | + if (!$status) | |
265 | + error_log('IMPEX Remote Base can not be updated',1,email); | |
266 | + // check/change access rights | |
267 | + $remoteBases->load(USERWSDIR.'RemoteParams.xml'); | |
268 | + $bases = $remoteBases->getElementsByTagName('dataCenter'); | |
269 | + | |
270 | + $delete = new UserDeleteObsolete(); | |
271 | + if ($bases->length > 0) | |
272 | + foreach ($bases as $base) | |
273 | + { | |
274 | + $baseId = $base->getAttribute('xml:id'); | |
275 | + $notAvailable = (array_search($baseId,$availableMis) === FALSE); | |
276 | + $base->setAttribute('available',!$notAvailable); | |
277 | + | |
278 | + if ($base->getAttribute('isSimulation')) continue; | |
279 | + // Update Info on External Data Sets in UserTree.xml for everything except IMPEX | |
280 | + $dataSets = $base->getElementsByTagName("dataset"); | |
281 | + if ($dataSets->length > 0) | |
282 | + { | |
283 | + $baseExtDom = new DomDocument("1.0"); | |
284 | + if (!$baseExtDom->load(RemoteData.$baseId.'/base.xml')) | |
285 | + { | |
286 | + $base->setAttribute("desc","ATTENTION!!! This Base set DOES NOT ANY MORE EXIST!!! Remove it from your tree"); | |
287 | + $base->setAttribute('obsolete', true); | |
288 | + error_log('NO '.RemoteData.$baseId.'/base.xml',1,email); | |
289 | + continue; | |
290 | + } | |
291 | + foreach ($dataSets as $dataSet) | |
292 | + { | |
293 | + $dataSetID = $dataSet->getAttribute("xml:id"); | |
294 | + $origDataSet = $baseExtDom->getElementById($dataSetID); | |
295 | + if ($origDataSet != null) | |
296 | + { | |
297 | + $desc = $origDataSet->getAttribute("desc"); | |
298 | + if ($desc != null) $dataSet->setAttribute("desc", $desc); | |
299 | + } | |
300 | + else | |
301 | + { | |
302 | + $delete->setVI($dataSet->getAttribute('name')); | |
303 | + $res = $delete->deleteDerived(); | |
304 | + $res = $delete->deleteConditions(); | |
305 | + $res = $delete->deleteRequests(); | |
306 | + $res = $delete->deleteAliases(); | |
307 | + $dataSet->setAttribute("desc","ATTENTION!!! This data set DOES NOT ANY MORE EXIST!!! Remove it from your tree"); | |
308 | + $dataSet->setAttribute('obsolete', true); | |
309 | + } | |
310 | + } | |
311 | + } | |
312 | + } | |
313 | + | |
314 | + return $remoteBases->save(USERWSDIR.'RemoteParams.xml'); | |
315 | + } | |
416 | 316 | |
417 | - $remoteBases->load(RemoteData.'Bases.xml'); | |
418 | - $bases = $remoteBases->getElementsByTagName('dataCenter'); | |
317 | + $remoteBases->load(RemoteData.'Bases.xml'); | |
318 | + $bases = $remoteBases->getElementsByTagName('dataCenter'); | |
419 | 319 | |
420 | - if ($bases->length == 0) return 'NO REMOTE BASES'; | |
320 | + if ($bases->length == 0) return 'NO REMOTE BASES'; | |
421 | 321 | |
422 | - $paramMgr = new ParamMgr(); | |
423 | - $paramMgr->xmlDom = new DomDocument("1.0"); | |
424 | - $paramMgr->xmlDom->formatOutput = true; | |
425 | - $paramMgr->xmlDom->preserveWhiteSpace = false; | |
322 | + $paramMgr = new ParamMgr(); | |
323 | + $paramMgr->xmlDom = new DomDocument("1.0"); | |
324 | + $paramMgr->xmlDom->formatOutput = true; | |
325 | + $paramMgr->xmlDom->preserveWhiteSpace = false; | |
426 | 326 | |
427 | 327 | |
428 | - $BASE = $paramMgr->xmlDom->createElement('dataRoot'); | |
429 | - $BASE->setAttribute('xml:id','myRemoteData-treeRootNode'); | |
328 | + $BASE = $paramMgr->xmlDom->createElement('dataRoot'); | |
329 | + $BASE->setAttribute('xml:id','myRemoteData-treeRootNode'); | |
430 | 330 | |
431 | - $baseXml = new DomDocument("1.0"); | |
331 | + $baseXml = new DomDocument("1.0"); | |
432 | 332 | |
433 | - foreach ($bases as $base) { | |
434 | - | |
435 | - $toInclude = $base->hasAttribute('default'); | |
436 | - $baseId = $base->getAttribute('xml:id'); | |
437 | - $paramMgr->baseId = $baseId; | |
438 | - | |
439 | - $notAvailable = (array_search($baseId,$availableMis) === FALSE); | |
333 | + foreach ($bases as $base) | |
334 | + { | |
335 | + $toInclude = $base->hasAttribute('default'); | |
336 | + $baseId = $base->getAttribute('xml:id'); | |
337 | + $paramMgr->baseId = $baseId; | |
338 | + | |
339 | + $notAvailable = (array_search($baseId,$availableMis) === FALSE); | |
440 | 340 | |
441 | - // no data base description ; skip this data base | |
442 | - if (!file_exists(RemoteData.$baseId.'/base.xml')) continue; | |
341 | + // no data base description ; skip this data base | |
342 | + if (!file_exists(RemoteData.$baseId.'/base.xml')) continue; | |
443 | 343 | |
444 | - // can't read base.xml ; skip this data base | |
445 | - if (!$baseXml->load(RemoteData.$baseId.'/base.xml')) continue; | |
446 | - | |
447 | - // Some small & well known data centers are included by default: | |
448 | - // Each VI structure and VI (dataset) description at DD Server for them should exist | |
449 | - if ($toInclude) { | |
450 | - | |
451 | - $center = $paramMgr->xmlDom->importNode($baseXml->getElementById($baseId), true); | |
452 | - $datasets = $center->getElementsByTagName('dataset'); | |
453 | - | |
454 | - foreach ($datasets as $dataset){ | |
455 | - // THEMIS => pseudo remote center; everything is predefined | |
456 | - if ($baseId === 'THEMIS') { | |
457 | - $params = $dataset->getElementsByTagName('parameter'); | |
458 | - foreach ($params as $param) | |
344 | + // can't read base.xml ; skip this data base | |
345 | + if (!$baseXml->load(RemoteData.$baseId.'/base.xml')) continue; | |
346 | + | |
347 | + // Some small & well known data centers are included by default: | |
348 | + // Each VI structure and VI (dataset) description at DD Server for them should exist | |
349 | + if ($toInclude) | |
350 | + { | |
351 | + $center = $paramMgr->xmlDom->importNode($baseXml->getElementById($baseId), true); | |
352 | + $datasets = $center->getElementsByTagName('dataset'); | |
353 | + foreach ($datasets as $dataset) | |
354 | + { | |
355 | + // THEMIS => pseudo remote center; everything is predefined | |
356 | + if ($baseId === 'THEMIS') | |
357 | + { | |
358 | + $params = $dataset->getElementsByTagName('parameter'); | |
359 | + foreach ($params as $param) | |
459 | 360 | $paramMgr->makeThemisComponents($param); |
460 | - } | |
461 | - else { | |
462 | - $infoFileName = $paramMgr->getInfoName($dataset->getAttribute('name')); | |
463 | - $paramMgr->localInfo = RemoteData.$baseId.'/'.$infoFileName; | |
464 | - | |
465 | - if (!file_exists($paramMgr->localInfo)) continue; | |
466 | - | |
467 | - $params = $dataset->getElementsByTagName('parameter'); | |
468 | - $paramMgr->remoteViId = $dataset->getAttribute('name'); | |
469 | - foreach ($params as $param) { | |
470 | - $paramMgr->paramId = $param->getAttribute('name'); | |
471 | - $paramGlobalId = $param->getAttribute('xml:id'); | |
472 | - $paramMgr->paramXML = RemoteData.'PARAMS/'.$paramGlobalId.'.xml'; | |
473 | - | |
474 | - if (!file_exists($paramMgr->paramXML)) continue; | |
475 | - if (!$paramMgr->paramDom) | |
476 | - $paramMgr->paramDom = new DomDocument("1.0"); | |
477 | - | |
478 | - $paramMgr->paramDom->load($paramMgr->paramXML); | |
479 | - | |
480 | - if (!$paramMgr->makeComponents($param)) continue; | |
361 | + } | |
362 | + else | |
363 | + { | |
364 | + $infoFileName = $paramMgr->getInfoName($dataset->getAttribute('name')); | |
365 | + $paramMgr->localInfo = RemoteData.$baseId.'/'.$infoFileName; | |
366 | + | |
367 | + if (!file_exists($paramMgr->localInfo)) continue; | |
368 | + | |
369 | + $params = $dataset->getElementsByTagName('parameter'); | |
370 | + $paramMgr->remoteViId = $dataset->getAttribute('name'); | |
371 | + foreach ($params as $param) | |
372 | + { | |
373 | + $paramMgr->paramId = $param->getAttribute('name'); | |
374 | + $paramGlobalId = $param->getAttribute('xml:id'); | |
375 | + $paramMgr->paramXML = RemoteData.'PARAMS/'.$paramGlobalId.'.xml'; | |
376 | + | |
377 | + if (!file_exists($paramMgr->paramXML)) continue; | |
378 | + if (!$paramMgr->paramDom) | |
379 | + $paramMgr->paramDom = new DomDocument("1.0"); | |
380 | + | |
381 | + $paramMgr->paramDom->load($paramMgr->paramXML); | |
382 | + | |
383 | + if (!$paramMgr->makeComponents($param)) continue; | |
384 | + } | |
385 | + } | |
481 | 386 | } |
482 | - } | |
483 | - } | |
484 | - } | |
485 | - else { | |
486 | - $center = $paramMgr->xmlDom->importNode($base, true); | |
487 | - } | |
488 | - | |
489 | - $center->setAttribute('name', $base->getAttribute('name')); | |
490 | - $center->setAttribute('desc', $base->getAttribute('desc')); | |
491 | - $center->setAttribute('available',!$notAvailable); | |
492 | - $BASE->appendChild($center); | |
493 | - | |
494 | - } | |
495 | - $paramMgr->xmlDom->appendChild($BASE); | |
496 | - | |
497 | - return $paramMgr->xmlDom->save(USERWSDIR.'RemoteParams.xml'); | |
387 | + } | |
388 | + else | |
389 | + { | |
390 | + $center = $paramMgr->xmlDom->importNode($base, true); | |
391 | + } | |
392 | + | |
393 | + $center->setAttribute('name', $base->getAttribute('name')); | |
394 | + $center->setAttribute('desc', $base->getAttribute('desc')); | |
395 | + $center->setAttribute('available',!$notAvailable); | |
396 | + $BASE->appendChild($center); | |
397 | + } | |
398 | + $paramMgr->xmlDom->appendChild($BASE); | |
399 | + | |
400 | + return $paramMgr->xmlDom->save(USERWSDIR.'RemoteParams.xml'); | |
498 | 401 | |
499 | - } | |
500 | - | |
501 | - protected function processGuestLogin() { | |
502 | - | |
503 | - if (!$this->check_email_address($_POST['password'])) { | |
504 | - die('<a href="index.html"><h3>Invalid e-mail address. Please, try once more.</h3></a>'); | |
505 | - } | |
506 | - | |
507 | - $passwd = $_POST['password']; | |
508 | - $IP = $this->getIPclient(); | |
509 | - $Guest = new Guest($IP,$passwd); | |
510 | - // email and IP in guests.login | |
511 | - $Guest->registerGuest(); | |
512 | - $Guest->checkGuestTimes(); | |
513 | - $user = $Guest->addGuest(); | |
514 | - | |
515 | - if ($user == "allGuestLoginsInUse") { | |
516 | - die('<a href="index.html"><h3>Sorry, all guest accounts are currently in use. Please, try to login in 30 min.</h3></a>'); | |
517 | - | |
518 | - } | |
519 | - $this->user = $user; | |
520 | - $this->passwd = "guest"; | |
521 | - | |
522 | - } | |
402 | + } | |
403 | + | |
404 | + protected function processGuestLogin() | |
405 | + { | |
406 | + if (!$this->check_email_address($_POST['password'])) | |
407 | + { | |
408 | + die('<a href="index.html"><h3>Invalid e-mail address. Please, try once more.</h3></a>'); | |
409 | + } | |
410 | + | |
411 | + $passwd = $_POST['password']; | |
412 | + $IP = $this->getIPclient(); | |
413 | + $Guest = new Guest($IP,$passwd); | |
414 | + // email and IP in guests.login | |
415 | + $Guest->registerGuest(); | |
416 | + $Guest->checkGuestTimes(); | |
417 | + $user = $Guest->addGuest(); | |
418 | + | |
419 | + if ($user == "allGuestLoginsInUse") | |
420 | + { | |
421 | + die('<a href="index.html"><h3>Sorry, all guest accounts are currently in use. Please, try to login in 30 min.</h3></a>'); | |
422 | + } | |
423 | + | |
424 | + $this->user = $user; | |
425 | + $this->passwd = "guest"; | |
426 | + } | |
523 | 427 | |
524 | 428 | /***************************************************************** |
525 | 429 | * PUBLIC FUNCTIONS |
526 | 430 | *****************************************************************/ |
527 | - // migration from old to new AMDA | |
528 | - public function convertWS() { | |
529 | - | |
530 | - $convert = new UserWsTransfer($this->user); | |
531 | - | |
532 | - $res = $convert->checkWS(); | |
533 | - if (!$res['success']) return $res; | |
534 | - | |
535 | - $res = $convert->transferDerived(); | |
536 | - $msg = $res['msg']; | |
537 | - | |
538 | - $res = $convert->transferTimeTables(); | |
539 | - $msg .= $res['msg']; | |
540 | - | |
541 | - $res = $convert->transferConditions(); | |
542 | - $msg .= $res['msg']; | |
543 | - | |
544 | - $res = $convert->transferRequests(); | |
545 | - $msg .= $res['msg']; | |
546 | - | |
547 | - $res = $convert->transferMyData(); | |
548 | - $msg .= $res['msg']; | |
549 | - | |
550 | - error_log('Transfer workspace from old AMDA for '.$this->user, 1, 'amda@irap.omp.eu'); | |
551 | - return array('success' => true, 'msg' => $msg); | |
552 | - } | |
553 | - | |
554 | - public function setPath() { | |
555 | - | |
556 | - if (isset($_GET['sessionID'])) { | |
557 | - $this->user = $_GET['sessionID']; | |
558 | - $this->userdir = USERPATH."/".$this->user."/"; | |
559 | - } | |
560 | - // for testing purposes | |
561 | - else if (defined('TRANSFERUSER')) { | |
562 | - $this->userdir = BASE_PATH."test/".TRANSFERUSER."/"; | |
563 | - } | |
564 | - else if (isset($this->user)) { | |
565 | - $this->userdir = USERPATH."/".$this->user."/"; | |
566 | - } | |
431 | +// // migration from old to new AMDA | |
432 | +// public function convertWS() { | |
433 | +// | |
434 | +// $convert = new UserWsTransfer($this->user); | |
435 | +// | |
436 | +// $res = $convert->checkWS(); | |
437 | +// if (!$res['success']) return $res; | |
438 | +// | |
439 | +// $res = $convert->transferDerived(); | |
440 | +// $msg = $res['msg']; | |
441 | +// | |
442 | +// $res = $convert->transferTimeTables(); | |
443 | +// $msg .= $res['msg']; | |
444 | +// | |
445 | +// $res = $convert->transferConditions(); | |
446 | +// $msg .= $res['msg']; | |
447 | +// | |
448 | +// $res = $convert->transferRequests(); | |
449 | +// $msg .= $res['msg']; | |
450 | +// | |
451 | +// $res = $convert->transferMyData(); | |
452 | +// $msg .= $res['msg']; | |
453 | +// | |
454 | +// error_log('Transfer workspace from old AMDA for '.$this->user, 1, 'amda@irap.omp.eu'); | |
455 | +// return array('success' => true, 'msg' => $msg); | |
456 | +// } | |
457 | + | |
458 | + public function setPath() | |
459 | + { | |
460 | + if (isset($_GET['sessionID'])) | |
461 | + { | |
462 | + $this->user = $_GET['sessionID']; | |
463 | + $this->userdir = USERPATH."/".$this->user."/"; | |
464 | + } | |
465 | + // for testing purposes | |
466 | + else if (defined('TRANSFERUSER')) | |
467 | + { | |
468 | + $this->userdir = BASE_PATH."test/".TRANSFERUSER."/"; | |
469 | + } | |
470 | + else if (isset($this->user)) | |
471 | + { | |
472 | + $this->userdir = USERPATH."/".$this->user."/"; | |
473 | + } | |
567 | 474 | |
568 | - $usrdir = $this->userdir; | |
569 | - | |
570 | - define ("USERDIR", "$usrdir/"); | |
475 | + $usrdir = $this->userdir; | |
571 | 476 | |
572 | - foreach ($this->userDirs as $key => $val) { | |
573 | - $dir = $usrdir.$val; | |
574 | - define("$key","$dir/"); | |
575 | - } | |
576 | - } | |
477 | + define ("USERDIR", "$usrdir/"); | |
577 | 478 | |
578 | - public function ddCheckUser() { | |
479 | + foreach ($this->userDirs as $key => $val) | |
480 | + { | |
481 | + $dir = $usrdir.$val; | |
482 | + define("$key","$dir/"); | |
483 | + } | |
484 | + } | |
579 | 485 | |
486 | + public function ddCheckUser() | |
487 | + { | |
580 | 488 | $this->IP = $this->getIPclient(); |
581 | 489 | |
582 | 490 | $cmdCheckUser = DDBIN."DDCheckUser ".$this->IP." ".$this->user." 1> /dev/null 2> /dev/null"; |
583 | 491 | system($cmdCheckUser, $res); |
584 | 492 | return $res; |
585 | - } | |
493 | + } | |
586 | 494 | |
587 | - public function ddLogin() { | |
588 | - | |
589 | - $this->IP = $this->getIPclient(); | |
495 | + public function ddLogin() | |
496 | + { | |
497 | + $this->IP = $this->getIPclient(); | |
590 | 498 | |
591 | - $loginCommd = DDBIN."DDHtmlLogin ".$this->user." ".$this->passwd." ".$this->IP; | |
592 | - system($loginCommd, $res); | |
499 | + $loginCommd = DDBIN."DDHtmlLogin ".$this->user." ".$this->passwd." ".$this->IP; | |
500 | + system($loginCommd, $res); | |
593 | 501 | |
594 | - return $res; | |
595 | - } | |
502 | + return $res; | |
503 | + } | |
596 | 504 | |
597 | 505 | |
598 | - public function init() { | |
599 | - | |
600 | - if ($this->ddLogin() != 0) | |
601 | - die('<h2>You are trying to log in as '.$this->user.'<br/> Please check that you entered a valid password</h2>'); | |
602 | - | |
603 | - $this->userdir = USERPATH."/".$this->user."/"; | |
604 | - | |
605 | - if (!is_dir($this->userdir)) | |
606 | - { | |
607 | - if (!$this->createDir()) { | |
608 | - die("Login for ".$this->user." failed: Can't create WS dirs"); | |
609 | - } | |
610 | - $this->isFirst = true; | |
611 | - } | |
612 | - | |
613 | - if (file_exists($this->userdir.'newLogin')) { | |
614 | - copy($this->userdir.'newLogin',$this->userdir.'lastLogin'); | |
615 | - $dt = filemtime($this->userdir.'newLogin'); | |
616 | - touch($this->userdir.'lastLogin', $dt); | |
617 | - } | |
618 | - else | |
619 | - touch($this->userdir.'lastLogin', time() - 5*86400); // last 5 days | |
620 | - | |
621 | - // if new info exists it will be shown to : | |
622 | - // public => to all | |
623 | - // special => to group members | |
624 | - if (file_exists($this->userdir.'newInfo')) | |
625 | - { | |
626 | - $amdaInfo = new AmdaNews($this->user); | |
627 | - // if status = 0 - it is special info to group members only | |
628 | - // else to all | |
629 | - $info = $this->getUserInfo($this->user); | |
630 | - $status = $amdaInfo->makeInfo($info['group']); | |
631 | - | |
632 | - if ($status) $this->isNewInfo = true; | |
633 | - | |
634 | - unlink($this->userdir.'newInfo'); | |
635 | - } | |
636 | - touch($this->userdir.'newLogin'); | |
637 | - | |
638 | - $this->setPath(); | |
506 | + public function init() | |
507 | + { | |
508 | + if ($this->ddLogin() != 0) | |
509 | + die('<h2>You are trying to log in as '.$this->user.'<br/> Please check that you entered a valid password</h2>'); | |
639 | 510 | |
640 | - $this->userMissions = $this->getAvailableMissionsByUser(); | |
641 | - | |
642 | - //$this->makeLocalTree(); | |
643 | - if (!file_exists(USERWSDIR.'LocalParams.xml')) | |
644 | - symlink(DATAPATH.'/LocalParams.xml', USERWSDIR.'LocalParams.xml'); | |
645 | - | |
646 | - $ok = $this->makeRemoteTree(); | |
647 | - | |
648 | - if (!file_exists(USERWORKINGDIR.'DD_Request.res')) | |
649 | - copy(Plot.'DD_Request.res',USERWORKINGDIR.'DD_Request.res'); | |
511 | + $this->userdir = USERPATH."/".$this->user."/"; | |
512 | + | |
513 | + if (!is_dir($this->userdir)) | |
514 | + { | |
515 | + if (!$this->createDir()) | |
516 | + { | |
517 | + die("Login for ".$this->user." failed: Can't create WS dirs"); | |
518 | + } | |
519 | + $this->isFirst = true; | |
520 | + } | |
521 | + | |
522 | + if (file_exists($this->userdir.'newLogin')) | |
523 | + { | |
524 | + copy($this->userdir.'newLogin',$this->userdir.'lastLogin'); | |
525 | + $dt = filemtime($this->userdir.'newLogin'); | |
526 | + touch($this->userdir.'lastLogin', $dt); | |
527 | + } | |
528 | + else | |
529 | + touch($this->userdir.'lastLogin', time() - 5*86400); // last 5 days | |
530 | + | |
531 | + // if new info exists it will be shown to : | |
532 | + // public => to all | |
533 | + // special => to group members | |
534 | + if (file_exists($this->userdir.'newInfo')) | |
535 | + { | |
536 | + $amdaInfo = new AmdaNews($this->user); | |
537 | + // if status = 0 - it is special info to group members only | |
538 | + // else to all | |
539 | + $info = $this->getUserInfo($this->user); | |
540 | + $status = $amdaInfo->makeInfo($info['group']); | |
541 | + | |
542 | + if ($status) $this->isNewInfo = true; | |
543 | + | |
544 | + unlink($this->userdir.'newInfo'); | |
545 | + } | |
546 | + touch($this->userdir.'newLogin'); | |
650 | 547 | |
651 | - if (!file_exists(USERWSDIR.'Request.xml')) | |
652 | - $reqMgr = new RequestMgr(); | |
548 | + $this->setPath(); | |
549 | + $this->userMissions = $this->getAvailableMissionsByUser(); | |
653 | 550 | |
654 | - if (!file_exists(USERWSDIR.'Tt.xml')) | |
655 | - $ttMgr = new TimeTableMgr(); | |
551 | + if (!file_exists(USERWSDIR.'LocalParams.xml')) | |
552 | + symlink(DATAPATH.'/LocalParams.xml', USERWSDIR.'LocalParams.xml'); | |
553 | + | |
554 | + $ok = $this->makeRemoteTree(); | |
656 | 555 | |
657 | - if (!file_exists(USERWSDIR.'Alias.xml')) | |
658 | - $ttMgr = new AliasMgr(); | |
556 | + if (!file_exists(USERWSDIR.'Request.xml')) $reqMgr = new RequestMgr(); | |
557 | + if (!file_exists(USERWSDIR.'Tt.xml')) $ttMgr = new TimeTableMgr(); | |
558 | + if (!file_exists(USERWSDIR.'Alias.xml'))$ttMgr = new AliasMgr(); | |
659 | 559 | |
660 | - //TODO sessionID = user + WSname | |
661 | - $sessionID = $this->user; | |
560 | + //TODO sessionID = user + WSname | |
561 | + $sessionID = $this->user; | |
662 | 562 | |
663 | - /* | |
664 | - * Special groups are defined in the generoc_data/SpecialSettings/Groups.xml | |
665 | - */ | |
666 | - $specialGroup = $this->isSpecialGroup(); | |
667 | - | |
668 | - // Special Info for special groups | |
669 | - if ($specialGroup) { | |
670 | - // Special Settings for special groups - first visit just copying | |
671 | - if ($this->isFirst) { | |
672 | - $grp = $specialGroup->getAttribute('xml:id'); | |
673 | - $tags = $specialGroup->getElementsByTagName('folder'); | |
674 | - | |
675 | - foreach ($tags as $tag) { | |
676 | - $folder = $tag->getAttribute('name'); | |
677 | - foreach (glob(SpecialSettingsDir.$grp."/".$folder."/*") as $file) { | |
678 | - copy($file, $this->userdir.$folder."/".basename($file)); | |
679 | - } | |
680 | - } | |
681 | - // mark to show help information | |
682 | - touch($this->userdir."$grp"."Help"); | |
683 | - } | |
684 | - // add requests | |
685 | - else { | |
686 | - | |
687 | - | |
688 | - } | |
689 | - $grpName = $specialGroup->getAttribute('xml:id'); | |
690 | - $helpName = "$grpName"."Help"; | |
563 | + /* | |
564 | + * Special groups are defined in the generoc_data/SpecialSettings/Groups.xml | |
565 | + */ | |
566 | + $specialGroup = $this->isSpecialGroup(); | |
567 | + | |
568 | + // Special Info for special groups | |
569 | + if ($specialGroup) | |
570 | + { | |
571 | + // Special Settings for special groups - first visit just copying | |
572 | + if ($this->isFirst) | |
573 | + { | |
574 | + $grp = $specialGroup->getAttribute('xml:id'); | |
575 | + $tags = $specialGroup->getElementsByTagName('folder'); | |
576 | + | |
577 | + foreach ($tags as $tag) | |
578 | + { | |
579 | + $folder = $tag->getAttribute('name'); | |
580 | + foreach (glob(SpecialSettingsDir.$grp."/".$folder."/*") as $file) | |
581 | + { | |
582 | + copy($file, $this->userdir.$folder."/".basename($file)); | |
583 | + } | |
584 | + } | |
585 | + // mark to show help information | |
586 | + touch($this->userdir."$grp"."Help"); | |
587 | + } | |
588 | + // add requests | |
589 | + else { } | |
590 | + $grpName = $specialGroup->getAttribute('xml:id'); | |
591 | + $helpName = "$grpName"."Help"; | |
691 | 592 | |
692 | - if (file_exists(HELPPATH.$helpName) && file_exists($this->userdir.$helpName)) | |
693 | - $this->isSpecialInfo = $helpName; | |
593 | + if (file_exists(HELPPATH.$helpName) && file_exists($this->userdir.$helpName)) | |
594 | + $this->isSpecialInfo = $helpName; | |
694 | 595 | |
695 | - } | |
596 | + } | |
597 | + return $sessionID; | |
598 | + } | |
696 | 599 | |
697 | - return $sessionID; | |
698 | - } | |
600 | + public function dirSize($dir) | |
601 | + { | |
602 | + $handle = opendir($dir); | |
603 | + | |
604 | + while ($file = readdir($handle)) | |
605 | + { | |
606 | + if ($file != '..' && $file != '.' && !is_dir($dir.'/'.$file)) | |
607 | + { | |
608 | + $mas += filesize($dir.'/'.$file); | |
609 | + } | |
610 | + else if (is_dir($dir.'/'.$file) && $file != '..' && $file != '.') | |
611 | + { | |
612 | + $mas += $this->dirSize($dir.'/'.$file); | |
613 | + } | |
614 | + } | |
615 | + return $mas; | |
616 | + } | |
699 | 617 | |
700 | - public function dirSize($dir) { | |
618 | + public function getWsSize() | |
619 | + { | |
620 | + $dirsToCheck = array(USERDATADIR, USERTTDIR, USERWORKINGDIR); | |
621 | + $wsSize = 0; | |
622 | + foreach ($dirsToCheck as $dir) | |
623 | + if (is_dir($dir)) $wsSize += $this->dirSize($dir); | |
701 | 624 | |
702 | - $handle = opendir($dir); | |
703 | - | |
704 | - while ($file = readdir($handle)) { | |
705 | - if ($file != '..' && $file != '.' && !is_dir($dir.'/'.$file)) { | |
706 | - $mas += filesize($dir.'/'.$file); | |
707 | - } else if (is_dir($dir.'/'.$file) && $file != '..' && $file != '.') { | |
708 | - $mas += $this->dirSize($dir.'/'.$file); | |
709 | - } | |
710 | - } | |
711 | - return $mas; | |
712 | - } | |
713 | - | |
714 | - | |
715 | - public function getWsSize() { | |
716 | - | |
717 | - $dirsToCheck = array(USERDATADIR, USERTTDIR, USERWORKINGDIR); | |
718 | - $wsSize = 0; | |
719 | - foreach ($dirsToCheck as $dir) | |
720 | - if (is_dir($dir)) $wsSize += $this->dirSize($dir); | |
721 | - | |
722 | - return $wsSize; | |
723 | - } | |
724 | - | |
725 | - public function check_email_address($email) { | |
726 | - //http://www.ilovejackdaniels.com/php/email-address-validation/ | |
727 | - | |
728 | - // First, we check that there's one @ symbol, and that the lengths are right | |
729 | - if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { | |
730 | - // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. | |
731 | - return false; | |
732 | - } | |
733 | - | |
734 | - // Split it into sections to make life easier | |
735 | - $email_array = explode("@", $email); | |
736 | - $local_array = explode(".", $email_array[0]); | |
737 | - for ($i = 0; $i < sizeof($local_array); $i++) { | |
738 | - if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { | |
739 | - return false; | |
740 | - } | |
741 | - } | |
742 | - | |
743 | - if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name | |
744 | - $domain_array = explode(".", $email_array[1]); | |
745 | - if (sizeof($domain_array) < 2) { | |
746 | - return false; // Not enough parts to domain | |
747 | - } | |
748 | - for ($i = 0; $i < sizeof($domain_array); $i++) { | |
749 | - if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { | |
750 | - return false; | |
751 | - } | |
752 | - } | |
753 | - } | |
754 | - return true; | |
755 | - } | |
756 | - | |
757 | - | |
758 | - } | |
625 | + return $wsSize; | |
626 | + } | |
627 | + | |
628 | +// http://www.ilovejackdaniels.com/php/email-address-validation/ | |
629 | + public function check_email_address($email) | |
630 | + { | |
631 | + // First, we check that there's one @ symbol, and that the lengths are right | |
632 | + if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) | |
633 | + { | |
634 | + // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. | |
635 | + return false; | |
636 | + } | |
637 | + | |
638 | + // Split it into sections to make life easier | |
639 | + $email_array = explode("@", $email); | |
640 | + $local_array = explode(".", $email_array[0]); | |
641 | + for ($i = 0; $i < sizeof($local_array); $i++) | |
642 | + { | |
643 | + if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { | |
644 | + return false; | |
645 | + } | |
646 | + } | |
759 | 647 | |
648 | + if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name | |
649 | + $domain_array = explode(".", $email_array[1]); | |
650 | + if (sizeof($domain_array) < 2) { | |
651 | + return false; // Not enough parts to domain | |
652 | + } | |
653 | + for ($i = 0; $i < sizeof($domain_array); $i++) | |
654 | + { | |
655 | + if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { | |
656 | + return false; | |
657 | + } | |
658 | + } | |
659 | + } | |
660 | + return true; | |
661 | + } | |
662 | +} | |
760 | 663 | ?> |
... | ... |