Commit 7b86e77134b87a96e034b88bb4b82bb3a9926e30

Authored by Elena.Budnik
2 parents bf74fc2d 9140bdbd

conflict with epntap in config resolved

Showing 2 changed files with 680 additions and 603 deletions   Show diff stats
php/classes/UserMgr.php
... ... @@ -13,674 +13,748 @@ define('TTPATH', USERPATH.'TT/');
13 13 define('JOBPATH', USERPATH.'jobs/');
14 14 */
15 15  
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   - }
  16 + class UserMgr {
75 17  
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   - }
83 18  
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);
  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;
106 42 }
107   - return $realIP;
  43 + $in[] =& $in[$k][$key];
  44 + }
  45 + }
  46 + unset($in);
108 47 }
109 48  
110   - public function getUserInfo()
111   - {
112   - return $this->amdaClient->getUserInfo($this->user);
113   - }
114   -
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   - }
127   -
128   - public function createDir()
129   - {
130   - if (!mkdir($this->userdir, 0755, true))
131   - return false;
  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 + }
  106 +
  107 +
  108 + public function getUserInfo()
  109 + {
  110 + return $this->amdaClient->getUserInfo($this->user);
  111 + }
132 112  
133   - foreach ($this->userDirs as $key => $val)
134   - {
135   - if (!mkdir($this->userdir.$val.'/', 0755, true))
136   - return false;
137   - }
138   -
139   - return true;
  113 +/*
  114 +* Get Available Missions for a User (groups restriction)
  115 +*/
  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 + }
  124 +
  125 + public function createDir()
  126 + {
  127 + if (!mkdir($this->userdir, 0755, true)) return false;
  128 +
  129 + foreach ($this->userDirs as $key => $val) {
  130 + if (!mkdir($this->userdir.$val.'/', 0755, true)) return false;
  131 + }
  132 + return true;
140 133 }
141 134  
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");
  135 +/*
  136 +* Check if special groups with settings exist and user is from these groups
  137 +* Take the first group from user list
  138 +*/
  139 + protected function isSpecialGroup() {
  140 +
  141 + $specialGrps = new DomDocument("1.0");
  142 +
  143 + if (!($specialGrps->load(specialGrpsXml)))
  144 + return null;
149 145  
150   - if (!($specialGrps->load(specialGrpsXml)))
151   - return null;
  146 + $info = $this->amdaClient->getUserInfo($this->user);
  147 +
  148 + $userGrps = explode(',',$info['group']);
152 149  
153   - $info = $this->amdaClient->getUserInfo($this->user);
  150 + $specialGrpNode = null;
154 151  
155   - $userGrps = explode(',',$info['group']);
  152 + foreach ($userGrps as $grp) {
  153 + $specialGrpNode = $specialGrps->getElementById($grp);
  154 + if ($specialGrpNode) break;
  155 + }
  156 +
  157 + return $specialGrpNode;
  158 + }
  159 +
  160 +/*
  161 +* Totally replace IMPEX staff in user remote tree
  162 +*/
  163 + protected function updateImpex()
  164 + {
  165 + $myRemoteBases = new DomDocument("1.0");
  166 +
  167 + if (!$myRemoteBases->load(USERWSDIR.'RemoteParams.xml'))
  168 + return false;
156 169  
157   - $specialGrpNode = null;
  170 + $myBases = $myRemoteBases->getElementsByTagName('dataCenter');
158 171  
159   - foreach ($userGrps as $grp)
160   - {
161   - $specialGrpNode = $specialGrps->getElementById($grp);
162   - if ($specialGrpNode) break;
163   - }
164 172  
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   - }
  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');
  181 +
  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;
  219 +
  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 + }
249 243  
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'];
  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 +
  359 +/*
  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'];
260 366  
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);
  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);
277 381  
278   - if ($base->getAttribute('isSimulation')) continue;
  382 + if ($base->getAttribute('isSimulation')) continue;
279 383  
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   - }
  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 + }
317 416  
318   - $remoteBases->load(RemoteData.'Bases.xml');
319   - $bases = $remoteBases->getElementsByTagName('dataCenter');
  417 + $remoteBases->load(RemoteData.'Bases.xml');
  418 + $bases = $remoteBases->getElementsByTagName('dataCenter');
320 419  
321   - if ($bases->length == 0) return 'NO REMOTE BASES';
  420 + if ($bases->length == 0) return 'NO REMOTE BASES';
322 421  
323   - $paramMgr = new ParamMgr();
324   - $paramMgr->xmlDom = new DomDocument("1.0");
325   - $paramMgr->xmlDom->formatOutput = true;
326   - $paramMgr->xmlDom->preserveWhiteSpace = false;
  422 + $paramMgr = new ParamMgr();
  423 + $paramMgr->xmlDom = new DomDocument("1.0");
  424 + $paramMgr->xmlDom->formatOutput = true;
  425 + $paramMgr->xmlDom->preserveWhiteSpace = false;
327 426  
328 427  
329   - $BASE = $paramMgr->xmlDom->createElement('dataRoot');
330   - $BASE->setAttribute('xml:id','myRemoteData-treeRootNode');
  428 + $BASE = $paramMgr->xmlDom->createElement('dataRoot');
  429 + $BASE->setAttribute('xml:id','myRemoteData-treeRootNode');
331 430  
332   - $baseXml = new DomDocument("1.0");
  431 + $baseXml = new DomDocument("1.0");
333 432  
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);
  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);
341 440  
342   - // no data base description ; skip this data base
343   - if (!file_exists(RemoteData.$baseId.'/base.xml')) continue;
  441 + // no data base description ; skip this data base
  442 + if (!file_exists(RemoteData.$baseId.'/base.xml')) continue;
344 443  
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   - }
  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)
  459 + $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;
388 481 }
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);
  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);
399 493  
400   - }
401   - $paramMgr->xmlDom->appendChild($BASE);
  494 + }
  495 + $paramMgr->xmlDom->appendChild($BASE);
402 496  
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   - }
  497 + return $paramMgr->xmlDom->save(USERWSDIR.'RemoteParams.xml');
  498 +
  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 + }
429 523  
430 524 /*****************************************************************
431 525 * PUBLIC FUNCTIONS
432 526 *****************************************************************/
433   - // migration from old to new AMDA
434   - public function convertWS()
435   - {
  527 + // migration from old to new AMDA
  528 + public function convertWS() {
436 529  
437   - $convert = new UserWsTransfer($this->user);
  530 + $convert = new UserWsTransfer($this->user);
438 531  
439   - $res = $convert->checkWS();
440   - if (!$res['success']) return $res;
  532 + $res = $convert->checkWS();
  533 + if (!$res['success']) return $res;
441 534  
442   - $res = $convert->transferDerived();
443   - $msg = $res['msg'];
  535 + $res = $convert->transferDerived();
  536 + $msg = $res['msg'];
444 537  
445   - $res = $convert->transferTimeTables();
446   - $msg .= $res['msg'];
  538 + $res = $convert->transferTimeTables();
  539 + $msg .= $res['msg'];
447 540  
448   - $res = $convert->transferConditions();
449   - $msg .= $res['msg'];
  541 + $res = $convert->transferConditions();
  542 + $msg .= $res['msg'];
450 543  
451   - $res = $convert->transferRequests();
452   - $msg .= $res['msg'];
  544 + $res = $convert->transferRequests();
  545 + $msg .= $res['msg'];
453 546  
454   - $res = $convert->transferMyData();
455   - $msg .= $res['msg'];
  547 + $res = $convert->transferMyData();
  548 + $msg .= $res['msg'];
456 549  
457   - error_log('Transfer workspace from old AMDA for '.$this->user, 1, 'amda@irap.omp.eu');
458   - return array('success' => true, 'msg' => $msg);
459   - }
460   -
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   - }
  550 + error_log('Transfer workspace from old AMDA for '.$this->user, 1, 'amda@irap.omp.eu');
  551 + return array('success' => true, 'msg' => $msg);
  552 + }
477 553  
478   - $usrdir = $this->userdir;
  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 + }
  567 +
  568 + $usrdir = $this->userdir;
  569 +
  570 + define ("USERDIR", "$usrdir/");
479 571  
480   - define ("USERDIR", "$usrdir/");
  572 + foreach ($this->userDirs as $key => $val) {
  573 + $dir = $usrdir.$val;
  574 + define("$key","$dir/");
  575 + }
  576 + }
481 577  
482   - foreach ($this->userDirs as $key => $val)
483   - {
484   - $dir = $usrdir.$val;
485   - define("$key","$dir/");
486   - }
487   - }
  578 + public function ddCheckUser() {
488 579  
489   - public function ddCheckUser()
490   - {
491 580 $this->IP = $this->getIPclient();
492 581  
493 582 $cmdCheckUser = DDBIN."DDCheckUser ".$this->IP." ".$this->user." 1> /dev/null 2> /dev/null";
494 583 system($cmdCheckUser, $res);
495 584 return $res;
496   - }
  585 + }
497 586  
498   - public function ddLogin()
499   - {
500   - $this->IP = $this->getIPclient();
  587 + public function ddLogin() {
501 588  
502   - $loginCommd = DDBIN."DDHtmlLogin ".$this->user." ".$this->passwd." ".$this->IP;
503   - system($loginCommd, $res);
  589 + $this->IP = $this->getIPclient();
504 590  
505   - return $res;
506   - }
  591 + $loginCommd = DDBIN."DDHtmlLogin ".$this->user." ".$this->passwd." ".$this->IP;
  592 + system($loginCommd, $res);
  593 +
  594 + return $res;
  595 + }
507 596  
508 597  
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   - }
  598 + public function init() {
525 599  
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');
552   -
553   - $this->setPath();
554   -
555   - $this->userMissions = $this->getAvailableMissionsByUser();
  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();
556 639  
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');
  640 + $this->userMissions = $this->getAvailableMissionsByUser();
  641 +
  642 + //$this->makeLocalTree();
  643 + if (!file_exists(USERWSDIR.'LocalParams.xml'))
  644 + symlink(DATAPATH.'/LocalParams.xml', USERWSDIR.'LocalParams.xml');
562 645  
563   - $ok = $this->makeRemoteTree();
  646 + $ok = $this->makeRemoteTree();
  647 +
  648 + if (!file_exists(USERWORKINGDIR.'DD_Request.res'))
  649 + copy(Plot.'DD_Request.res',USERWORKINGDIR.'DD_Request.res');
564 650  
565   - if (!file_exists(USERWSDIR.'Request.xml'))
566   - $reqMgr = new RequestMgr();
  651 + if (!file_exists(USERWSDIR.'Request.xml'))
  652 + $reqMgr = new RequestMgr();
567 653  
568   - if (!file_exists(USERWSDIR.'Tt.xml'))
569   - $ttMgr = new TimeTableMgr();
  654 + if (!file_exists(USERWSDIR.'Tt.xml'))
  655 + $ttMgr = new TimeTableMgr();
570 656  
571   - if (!file_exists(USERWSDIR.'Alias.xml'))
572   - $ttMgr = new AliasMgr();
  657 + if (!file_exists(USERWSDIR.'Alias.xml'))
  658 + $ttMgr = new AliasMgr();
573 659  
574   - //TODO sessionID = user + WSname
575   - $sessionID = $this->user;
  660 + //TODO sessionID = user + WSname
  661 + $sessionID = $this->user;
576 662  
577   - /*
578   - * Special groups are defined in the generoc_data/SpecialSettings/Groups.xml
579   - */
580   - $specialGroup = $this->isSpecialGroup();
  663 + /*
  664 + * Special groups are defined in the generoc_data/SpecialSettings/Groups.xml
  665 + */
  666 + $specialGroup = $this->isSpecialGroup();
581 667  
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";
  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";
607 691  
608   - if (file_exists(HELPPATH.$helpName) && file_exists($this->userdir.$helpName))
609   - {
610   - $this->isSpecialInfo = $helpName;
611   - }
612   - }
613   - return $sessionID;
614   - }
  692 + if (file_exists(HELPPATH.$helpName) && file_exists($this->userdir.$helpName))
  693 + $this->isSpecialInfo = $helpName;
615 694  
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   - }
  695 + }
658 696  
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   - }
  697 + return $sessionID;
  698 + }
  699 +
  700 + public function dirSize($dir) {
  701 +
  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 + }
668 759  
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   -}
686 760 ?>
... ...
php/config.php
... ... @@ -58,8 +58,13 @@ define(&#39;JOBTIMEOUT&#39;, &#39;1&#39;); // one cycle secs to sleep to allow job be executed
58 58 define('PLOT_CYCLES_NUMBER', 500); // cycles number for PNG
59 59 define('JOB_CYCLES_NUMBER', 5); // cycles number for all the jobs
60 60 //define('TIMEOUT', '100'); //TODO secs wait before job is killed OR 'max_execution_time' - kill automatic?
  61 +
61 62 /*-----------------------END BATCH JOBS section --------*/
62 63  
  64 +// EPN-TAP services
  65 +define('EPNTAP_APIS','http://voparis-tap.obspm.fr/__system__/tap/run/tap/sync');
  66 +define('EPNTAP_AMDA','http://cdpp-epntap.irap.omp.eu/__system__/tap/run/tap/sync');
  67 +
63 68 /*----------------------- PHP run-time settings --------*/
64 69 ini_set('memory_limit',128000000);
65 70 ini_set('max_execution_time',600); // max PHP execution
... ... @@ -71,7 +76,6 @@ ini_set(&#39;user_agent&#39;, &#39;Mozilla/5.0 (X11; U; Linux i686; en-US; rv:7.0) Gecko/201
71 76 // ini_set('post_max_size',1050000000);
72 77 /*-----------------------END PHP run-time settings --------*/
73 78  
74   -
75 79 // General Info dirs
76 80 define('DATAPATH', IHM_SRC_DIR.'generic_data/');
77 81 //define('Param', DATAPATH.'Param/');
... ... @@ -84,7 +88,6 @@ define(&#39;SpecialSettingsDir&#39;,DATAPATH.&#39;SpecialSettings/&#39;);
84 88  
85 89 // General Info files
86 90 define('orbitsXml',LocalData.'Orbites.xml');
87   -// define('targetsXml',LocalData.'targets.xml');
88 91 define('FeedbackXml', DATAPATH.'Feedback/Feedback.xml');
89 92 define('specialGrpsXml',SpecialSettingsDir.'Groups.xml');
90 93 define('specialSettingsXml',SpecialSettingsDir.'Settings.xml');
... ...