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