Commit 82193dd446fd96e617219f872fbe7027061ed29d
1 parent
d444ba30
Exists in
master
and in
110 other branches
update RemoteParams.xml
Showing
1 changed file
with
183 additions
and
225 deletions
Show diff stats
php/classes/UserMgr.php
... | ... | @@ -23,6 +23,7 @@ class UserMgr |
23 | 23 | 'USERTEMPDIR' => 'TEMP'); |
24 | 24 | protected $userGrps; |
25 | 25 | protected $amdaClient; //client to dd webservice |
26 | + protected $paramMgr, $baseExtXml; | |
26 | 27 | |
27 | 28 | public $isFirst = false; |
28 | 29 | public $isOldWS = true; |
... | ... | @@ -58,7 +59,6 @@ class UserMgr |
58 | 59 | else if (isset($username)) |
59 | 60 | $this->user = trim($username); |
60 | 61 | |
61 | - //TODO crypt / decrypt | |
62 | 62 | if (!isset($this->passwd)) { |
63 | 63 | if (isset($_POST['password'])) |
64 | 64 | $this->passwd = $_POST['password']; |
... | ... | @@ -222,246 +222,208 @@ class UserMgr |
222 | 222 | } |
223 | 223 | } |
224 | 224 | } |
225 | -/* | |
226 | -* Totally replace IMPEX staff in user remote tree | |
227 | -*/ | |
228 | - protected function updateImpex() | |
229 | - { | |
230 | - $myRemoteBases = new DomDocument("1.0"); | |
231 | - | |
232 | - if (!@$myRemoteBases->load(USERWSDIR.'RemoteParams.xml')) return false; | |
233 | - | |
234 | - $myBases = $myRemoteBases->getElementsByTagName('dataCenter'); | |
235 | - | |
236 | - if ($myBases->length < 1) return false; | |
237 | - // Delete all impex staff at first | |
238 | - $i = $myBases->length - 1; | |
239 | - | |
240 | - while ($i > -1) | |
241 | - { | |
242 | - $base = $myBases->item($i); | |
243 | - $id = $base->getAttribute('xml:id'); | |
244 | - | |
245 | - if ($id == 'FMI_GUMICS') | |
246 | - { | |
247 | - $simuRemoteBases = new DomDocument("1.0"); | |
248 | - $simuRemoteBases->load(USERWSDIR.'RemoteParams.xml'); | |
249 | - | |
250 | - $gumicsNode = $simuRemoteBases->getElementById('FMI_GUMICS'); | |
251 | - if ($gumicsNode != NULL) | |
252 | - $gumicsRuns = $gumicsNode->getElementsByTagName('runID'); | |
253 | - } | |
254 | - | |
255 | - if (($base->hasAttribute('isSimulation')) || $id == "CLWeb") | |
256 | - { | |
257 | - $base->parentNode->removeChild($base); | |
258 | - } | |
259 | - $i--; | |
260 | - } | |
261 | - | |
262 | - $remoteBases = new DomDocument("1.0"); | |
263 | - if (!$remoteBases->load(RemoteData.'Bases.xml')) return false; | |
264 | - | |
265 | - $bases = $remoteBases->getElementsByTagName('dataCenter'); | |
266 | - if ($bases->length < 1) return false; | |
267 | - | |
268 | - $myRootElement = $myRemoteBases->documentElement; | |
269 | - | |
270 | - // and add impex | |
271 | - foreach ($bases as $base) | |
272 | - { | |
273 | - //TODO && $id != 'FMI_GUMICS' or ! hasAttribute('isAddable') | |
274 | - if ($base->hasAttribute('isSimulation')) | |
275 | - { | |
276 | - $baseId = $base->getAttribute('xml:id'); | |
277 | - | |
278 | - $baseXml = new DomDocument("1.0"); | |
279 | - // no data base description ; skip this data base | |
280 | - if (!file_exists(RemoteData.$baseId.'/base.xml')) continue; | |
281 | - | |
282 | - // can't read base.xml ; skip this data base | |
283 | - if (!@$baseXml->load(RemoteData.$baseId.'/base.xml')) continue; | |
284 | - | |
285 | - $myBase = $myRemoteBases->importNode($baseXml->getElementById($baseId), true); | |
286 | - $myBase->setAttribute('name', $base->getAttribute('name')); | |
287 | - $myBase->setAttribute('desc', $base->getAttribute('desc')); | |
288 | - | |
289 | - if ($baseId == "FMI_GUMICS") | |
290 | - { | |
291 | - $gumicsSimuReg = $myRemoteBases->getElementById('FMI_GUMICS_Earth_Magnetosphere'); | |
292 | - | |
293 | - if (($gumicsSimuReg != NULL)&& ($gumicsRuns->length > 0)) | |
294 | - { | |
295 | - for($c = 0; $c < $gumicsRuns->length; $c++) | |
296 | - { | |
297 | - $node = $gumicsRuns->item($c); | |
298 | - $node = $myRemoteBases->importNode($node, true); | |
299 | - $gumicsSimuReg->appendChild($node); | |
300 | - } | |
301 | - } | |
302 | - } | |
303 | - // Check if WebService is ON | |
304 | - $center = new $baseId(); | |
305 | - $myBase->setAttribute('available',$center->monitor()); | |
306 | - | |
307 | - $myRootElement->appendChild($myBase); | |
308 | - } | |
309 | - } | |
310 | - | |
311 | - return $myRemoteBases->save(USERWSDIR.'RemoteParams.xml'); | |
312 | - } | |
313 | - | |
314 | -/* | |
315 | -* make remote data tree from list of distant bases if it doezn't exist | |
316 | -*/ | |
317 | 225 | |
318 | -protected function makeRemoteTree() | |
226 | + /* | |
227 | + * make remote data tree from list of distant bases if it doezn't exist$center->monitor() | |
228 | + */ | |
229 | + protected function makeRemoteTree() | |
319 | 230 | { |
320 | - $remoteBases = new DomDocument("1.0"); | |
321 | - | |
322 | -unlink(USERWSDIR.'RemoteParams.xml'); | |
323 | - if (file_exists(USERWSDIR.'RemoteParams.xml')) | |
324 | - { | |
325 | - // replace IMPEX nodes | |
326 | - $status = $this->updateImpex(); | |
327 | - | |
328 | - if (!$status) | |
329 | - error_log('IMPEX Remote Base can not be updated',1,email); | |
231 | + // unlink(USERWSDIR.'RemoteParams.xml'); | |
232 | + $this->paramMgr = new RemoteParamManager(); | |
233 | + $init_res = $this->paramMgr->init(); | |
234 | + | |
235 | + $this->baseExtXml = new DomDocument("1.0"); | |
236 | + | |
237 | + if ($init_res['success']) { // USERWSDIR.'RemoteParams.xml' exists | |
330 | 238 | // check/change access rights |
331 | - $remoteBases->load(USERWSDIR.'RemoteParams.xml'); | |
332 | - $bases = $remoteBases->getElementsByTagName('dataCenter'); | |
333 | - | |
239 | + $basesWS = $this->paramMgr->xmlDom->getElementsByTagName('dataCenter'); // RemoteParams.xml | |
334 | 240 | $delete = new UserDeleteObsolete(); |
335 | - if ($bases->length > 0) | |
336 | - foreach ($bases as $base) | |
241 | + | |
242 | + $basesWsId = array(); | |
243 | + $basesToAdd = array(); | |
244 | + | |
245 | + if ($basesWS->length > 0) { | |
246 | + | |
247 | + foreach ($basesWS as $base) { | |
248 | + $basesWsId[] = $base->getAttribute('xml:id'); | |
249 | + } | |
250 | + | |
251 | + foreach ($this->paramMgr->Bases as $baseNew) { | |
252 | + if (!in_array($baseNew, $basesWsId)) { | |
253 | + $basesToAdd[] = $baseNew; | |
254 | + } | |
255 | + } | |
256 | + | |
257 | + foreach ($basesWS as $base) | |
337 | 258 | { |
338 | 259 | $baseId = $base->getAttribute('xml:id'); |
339 | - if ($base->getAttribute('isSimulation')) continue; | |
260 | + | |
261 | + if (!$this->baseExtXml->load(RemoteData.$baseId.'/base.xml')) | |
262 | + { | |
263 | + $base->setAttribute("desc","ATTENTION!!! This DataCenter DOES NOT EXIST ANY MORE!!! Remove it from your tree"); | |
264 | + $base->setAttribute('obsolete', true); | |
265 | + | |
266 | + error_log('NO '.RemoteData.$baseId.'/base.xml',1,email); | |
267 | + continue; | |
268 | + } | |
340 | 269 | |
341 | -// $notAvailable = (array_search($baseId,$availableMis) === FALSE); | |
342 | -// $base->setAttribute('available',!$notAvailable); | |
343 | - | |
344 | - // Update Info on External Data Sets in RemoteTree.xml for everything except IMPEX | |
345 | - $dataSets = $base->getElementsByTagName("dataset"); | |
346 | - if ($dataSets->length > 0) | |
347 | - { | |
348 | - $baseExtDom = new DomDocument("1.0"); | |
349 | - if (!$baseExtDom->load(RemoteData.$baseId.'/base.xml')) | |
350 | - { | |
351 | - $base->setAttribute("desc","ATTENTION!!! This Base set DOES NOT ANY MORE EXIST!!! Remove it from your tree"); | |
352 | - $base->setAttribute('obsolete', true); | |
353 | - error_log('NO '.RemoteData.$baseId.'/base.xml',1,email); | |
354 | - continue; | |
270 | + if ($base->hasAttribute('addable')) { | |
271 | + // keep this base tree | |
272 | + // error_log($baseId,1,email); | |
273 | + } | |
274 | + else { | |
275 | + // totally rewrite | |
276 | + if ($base->hasAttribute('isSimulation')) { | |
277 | + $centerNode = $this->makeSimulationBase($baseId); | |
278 | + $center = new $baseId(); | |
279 | + $centerNode->setAttribute('available', $center->monitor()); | |
355 | 280 | } |
356 | - foreach ($dataSets as $dataSet) | |
357 | - { | |
358 | - $dataSetID = $dataSet->getAttribute("xml:id"); | |
359 | - $origDataSet = $baseExtDom->getElementById($dataSetID); | |
360 | - if ($origDataSet != null) | |
361 | - { | |
362 | - $desc = $origDataSet->getAttribute("desc"); | |
363 | - if ($desc != null) $dataSet->setAttribute("desc", $desc); | |
364 | - } | |
365 | - else | |
366 | - { | |
367 | - $delete->setVI($dataSet->getAttribute('name')); | |
368 | - $res = $delete->deleteDerived(); | |
369 | - $res = $delete->deleteConditions(); | |
370 | - $res = $delete->deleteRequests(); | |
371 | - $res = $delete->deleteAliases(); | |
372 | - $dataSet->setAttribute("desc","ATTENTION!!! This data set DOES NOT EXIST ANY MORE !!! Remove it from your tree"); | |
373 | - $dataSet->setAttribute('obsolete', true); | |
374 | - } | |
375 | - } | |
376 | - } | |
377 | - } | |
378 | - | |
379 | - return $remoteBases->save(USERWSDIR.'RemoteParams.xml'); | |
380 | - } | |
381 | - | |
382 | - $remoteBases->load(RemoteData.'Bases.xml'); | |
383 | - $bases = $remoteBases->getElementsByTagName('dataCenter'); | |
384 | - | |
385 | - if ($bases->length == 0) return 'NO REMOTE BASES'; | |
386 | - | |
387 | - $paramMgr = new RemoteParamManager(); | |
388 | - $paramMgr->xmlDom = new DomDocument("1.0"); | |
389 | - $paramMgr->xmlDom->formatOutput = true; | |
390 | - $paramMgr->xmlDom->preserveWhiteSpace = false; | |
391 | - | |
392 | - $BASE = $paramMgr->xmlDom->createElement('dataRoot'); | |
393 | - $BASE->setAttribute('xml:id','myRemoteData-treeRootNode'); | |
394 | - | |
395 | - $baseXml = new DomDocument("1.0"); | |
396 | - | |
397 | - foreach ($bases as $base) | |
398 | - { | |
399 | - $baseId = $base->getAttribute('xml:id'); | |
400 | - $paramMgr->baseId = $baseId; | |
401 | - | |
402 | - // no data base description ; skip this data base | |
403 | - if (!@file_exists(RemoteData.$baseId.'/base.xml')) continue; | |
404 | - | |
405 | - // can't read base.xml ; skip this data base | |
406 | - if (!@$baseXml->load(RemoteData.$baseId.'/base.xml')) continue; | |
407 | - | |
408 | - if ($base->hasAttribute('default')) | |
409 | - { | |
410 | - if ($base->hasAttribute('isSimulation')) | |
411 | - { | |
412 | - $centerNode = $paramMgr->xmlDom->importNode($baseXml->getElementById($baseId), true); | |
413 | - $datasets = $centerNode->getElementsByTagName('dataset'); | |
414 | - foreach ($datasets as $dataset) | |
415 | - { | |
416 | - $infoFileName = $paramMgr->getInfoName($dataset->getAttribute('name')); | |
417 | - $paramMgr->localInfo = RemoteData.$baseId.'/'.$infoFileName; | |
418 | - | |
419 | - if (!@file_exists($paramMgr->localInfo)) continue; | |
420 | - | |
421 | - $params = $dataset->getElementsByTagName('parameter'); | |
422 | - $paramMgr->remoteViId = $dataset->getAttribute('name'); | |
423 | - foreach ($params as $param) | |
424 | - { | |
425 | - $paramMgr->paramId = $param->getAttribute('name'); | |
426 | - $paramGlobalId = $param->getAttribute('xml:id'); | |
427 | - $paramMgr->paramXML = RemoteData.'PARAMS/'.$paramGlobalId.'.xml'; | |
428 | - | |
429 | - if (!@file_exists($paramMgr->paramXML)) continue; | |
430 | - if (!$paramMgr->paramDom) | |
431 | - $paramMgr->paramDom = new DomDocument("1.0"); | |
432 | - | |
433 | - $paramMgr->paramDom->load($paramMgr->paramXML); | |
434 | - | |
435 | - if (!$paramMgr->makeComponents($param)) continue; | |
281 | + else { | |
282 | + $center = new $baseId(); | |
283 | + $centerNode = $center->makeCenterNode($this->paramMgr->xmlDom); | |
284 | + $centerNode->setAttribute('available', TRUE); | |
436 | 285 | } |
286 | + | |
287 | + $centerNode->setAttribute('name', $base->getAttribute('name')); | |
288 | + $centerNode->setAttribute('desc', $base->getAttribute('desc')); | |
289 | + | |
290 | + $base->parentNode->removeChild($base); | |
291 | + | |
292 | + $this->paramMgr->xmlDom->documentElement->appendChild($centerNode); | |
293 | + } | |
294 | + | |
295 | + if ($baseId !== "FMI_GUMICS") { | |
296 | + // Update Info on External Data Sets in RemoteTree.xml | |
297 | + $dataSets = $base->getElementsByTagName("dataset"); | |
298 | + if ($dataSets->length > 0) { | |
299 | + foreach ($dataSets as $dataSet) { | |
300 | + $dataSetID = $dataSet->getAttribute("xml:id"); | |
301 | + $origDataSet = $this->baseExtXml->getElementById($dataSetID); | |
302 | + if ($origDataSet != null) { | |
303 | + $desc = $origDataSet->getAttribute("desc"); | |
304 | + if ($desc != null) $dataSet->setAttribute("desc", $desc); | |
305 | + } | |
306 | + else { | |
307 | + $delete->setVI($dataSet->getAttribute('name')); | |
308 | + $res = $delete->deleteDerived(); | |
309 | + $res = $delete->deleteConditions(); | |
310 | + $res = $delete->deleteRequests(); | |
311 | + $res = $delete->deleteAliases(); | |
312 | + $dataSet->setAttribute("desc","ATTENTION!!! This data set DOES NOT EXIST ANY MORE !!! Remove it from your tree"); | |
313 | + $dataSet->setAttribute('obsolete', true); | |
314 | + } | |
315 | + } | |
316 | + } | |
437 | 317 | } |
438 | 318 | } |
439 | - /* | |
440 | - * Some small & well known data centers are included by default: | |
441 | - * Each VI structure and VI (dataset) description at DDBASE for them should exist | |
442 | - */ | |
443 | - else | |
444 | - { | |
445 | - $center = new $baseId(); | |
446 | - $centerNode = $center->makeCenterNode($paramMgr->xmlDom); | |
319 | + | |
320 | + // New Bases to add | |
321 | + if (count($basesToAdd) > 0) { | |
322 | + foreach ($basesToAdd as $baseToAdd) { | |
323 | + $centerNode = $this->makeNewBase($baseToAdd); | |
324 | + $this->paramMgr->xmlDom->documentElement->appendChild($centerNode); | |
325 | + } | |
447 | 326 | } |
327 | + | |
328 | + return $this->paramMgr->xmlDom->save($this->paramMgr->xmlName); | |
448 | 329 | } |
330 | + } | |
331 | + else if ($init_res['err'] == "RemoteParams file error") { // new RemoteParams.xml | |
332 | + | |
333 | + $this->paramMgr->xmlDom->formatOutput = true; | |
334 | + $this->paramMgr->xmlDom->preserveWhiteSpace = false; | |
335 | + | |
336 | + $BASE = $this->paramMgr->xmlDom->createElement('dataRoot'); | |
337 | + $BASE->setAttribute('xml:id','myRemoteData-treeRootNode'); | |
338 | + | |
339 | + foreach ($this->paramMgr->Bases as $baseId) | |
340 | + { | |
341 | + $centerNode = $this->makeNewBase($baseId); | |
342 | + $BASE->appendChild($centerNode); | |
343 | + } | |
344 | + | |
345 | + $this->paramMgr->xmlDom->appendChild($BASE); | |
346 | + | |
347 | + return $this->paramMgr->xmlDom->save($this->paramMgr->xmlName); | |
348 | + } | |
349 | + } | |
350 | + | |
351 | + protected function makeNewBase($baseId) | |
352 | + { | |
353 | + // no data base description ; skip this data base | |
354 | + if (!@file_exists(RemoteData.$baseId.'/base.xml')) continue; | |
355 | + | |
356 | + // can't read base.xml ; skip this data base | |
357 | + if (!@$this->baseExtXml->load(RemoteData.$baseId.'/base.xml')) continue; | |
358 | + | |
359 | + $base = $this->paramMgr->basesDom->getElementById($baseId); | |
360 | + | |
361 | + if ($base->hasAttribute('default')) | |
362 | + { | |
363 | + if ($base->hasAttribute('isSimulation')) { | |
364 | + $centerNode = $this->makeSimulationBase($baseId); | |
365 | + $center = new $baseId(); | |
366 | + $centerNode->setAttribute('available',$center->monitor()); | |
367 | + } | |
368 | + /* | |
369 | + * Some small & well known data centers are included by default: | |
370 | + * Each VI structure and VI (dataset) description at DDBASE for them should exist | |
371 | + */ | |
449 | 372 | else |
450 | 373 | { |
451 | - $centerNode = $paramMgr->xmlDom->importNode($base, true); | |
374 | + $center = new $baseId(); | |
375 | + $centerNode = $center->makeCenterNode($this->paramMgr->xmlDom); | |
376 | + $centerNode->setAttribute('available', TRUE); | |
452 | 377 | } |
453 | - | |
378 | + | |
454 | 379 | $centerNode->setAttribute('name', $base->getAttribute('name')); |
455 | 380 | $centerNode->setAttribute('desc', $base->getAttribute('desc')); |
456 | - $centerNode->setAttribute('available',isset($notAvailable) ? !$notAvailable : TRUE); | |
457 | - $BASE->appendChild($centerNode); | |
458 | - } | |
459 | - $paramMgr->xmlDom->appendChild($BASE); | |
460 | - | |
461 | - return $paramMgr->xmlDom->save(USERWSDIR.'RemoteParams.xml'); | |
462 | - | |
381 | + | |
382 | + if ($base->hasAttribute('addable')) { | |
383 | + $centerNode->setAttribute('addable', TRUE); | |
384 | + } | |
385 | + } | |
386 | + else | |
387 | + { | |
388 | + $centerNode = $this->paramMgr->xmlDom->importNode($base, true); | |
389 | + $centerNode->setAttribute('available', TRUE); | |
390 | + } | |
391 | + | |
392 | + return $centerNode; | |
463 | 393 | } |
394 | + | |
395 | + protected function makeSimulationBase($baseId) | |
396 | + { | |
397 | + $centerNode = $this->paramMgr->xmlDom->importNode($this->baseExtXml->getElementById($baseId), true); | |
398 | + $datasets = $centerNode->getElementsByTagName('dataset'); | |
399 | + foreach ($datasets as $dataset) | |
400 | + { | |
401 | + $infoFileName = $this->paramMgr->getInfoName($dataset->getAttribute('name')); | |
402 | + $this->paramMgr->localInfo = RemoteData.$baseId.'/'.$infoFileName; | |
464 | 403 | |
404 | + if (!@file_exists($this->paramMgr->localInfo)) continue; | |
405 | + | |
406 | + $params = $dataset->getElementsByTagName('parameter'); | |
407 | + $this->paramMgr->remoteViId = $dataset->getAttribute('name'); | |
408 | + foreach ($params as $param) | |
409 | + { | |
410 | + $this->paramMgr->paramId = $param->getAttribute('name'); | |
411 | + $paramGlobalId = $param->getAttribute('xml:id'); | |
412 | + $this->paramMgr->paramXML = RemoteData.'PARAMS/'.$paramGlobalId.'.xml'; | |
413 | + | |
414 | + if (!@file_exists($this->paramMgr->paramXML)) continue; | |
415 | + if (!$this->paramMgr->paramDom) | |
416 | + $this->paramMgr->paramDom = new DomDocument("1.0"); | |
417 | + | |
418 | + $this->paramMgr->paramDom->load($this->paramMgr->paramXML); | |
419 | + | |
420 | + if (!$this->paramMgr->makeComponents($param)) continue; | |
421 | + } | |
422 | + } | |
423 | + return $centerNode; | |
424 | + } | |
425 | + | |
426 | + | |
465 | 427 | protected function processGuestLogin() |
466 | 428 | { |
467 | 429 | if (!$this->check_email_address($_POST['password'])) |
... | ... | @@ -526,10 +488,6 @@ unlink(USERWSDIR.'RemoteParams.xml'); |
526 | 488 | $this->user = $_GET['sessionID']; |
527 | 489 | $this->userdir = USERPATH."/".$this->user."/"; |
528 | 490 | } |
529 | - // for testing purposes | |
530 | -// else if (defined('TRANSFERUSER')) { | |
531 | -// $this->userdir = BASE_PATH."test/".TRANSFERUSER."/"; | |
532 | -// } | |
533 | 491 | else if (isset($this->user)) { |
534 | 492 | $this->userdir = USERPATH."/".$this->user."/"; |
535 | 493 | } |
... | ... |