Commit 175ca164bdb426cfa181cb50c16c31a9671faff6

Authored by Elena.Budnik
1 parent fe923a9d

bad commit of UserMgr in 9b6c46d9ec15951ccc42266263cd7f4ea32e9395

Showing 1 changed file with 168 additions and 120 deletions   Show diff stats
php/classes/UserMgr.php
@@ -21,7 +21,7 @@ class UserMgr @@ -21,7 +21,7 @@ class UserMgr
21 protected $userDirs = array('USERWSDIR' => 'WS', 'USERREQDIR' => 'REQ', 'USERDATADIR' => 'DATA', 21 protected $userDirs = array('USERWSDIR' => 'WS', 'USERREQDIR' => 'REQ', 'USERDATADIR' => 'DATA',
22 'USERWORKINGDIR' =>'RES', 'USERTTDIR' => 'TT', 'USERJOBDIR' => 'JOBS', 22 'USERWORKINGDIR' =>'RES', 'USERTTDIR' => 'TT', 'USERJOBDIR' => 'JOBS',
23 'USERTEMPDIR' => 'TEMP'); 23 'USERTEMPDIR' => 'TEMP');
24 - protected $userMissions; 24 + protected $userGrps;
25 protected $amdaClient; //client to dd webservice 25 protected $amdaClient; //client to dd webservice
26 26
27 public $isFirst = false; 27 public $isFirst = false;
@@ -31,15 +31,11 @@ class UserMgr @@ -31,15 +31,11 @@ class UserMgr
31 function __construct($username = NULL, $password = NULL, $sessionID = NULL) 31 function __construct($username = NULL, $password = NULL, $sessionID = NULL)
32 { 32 {
33 // if magic quotes is on, stripslashes 33 // if magic quotes is on, stripslashes
34 - if(get_magic_quotes_gpc())  
35 - { 34 + if(get_magic_quotes_gpc()) {
36 $in = array(&$_GET, &$_POST, &$_COOKIE); 35 $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 - { 36 + while(list($k,$v) = each($in)) {
  37 + foreach($v as $key => $val) {
  38 + if(!is_array($val)) {
43 $in[$k][$key] = stripslashes($val); 39 $in[$k][$key] = stripslashes($val);
44 continue; 40 continue;
45 } 41 }
@@ -49,15 +45,12 @@ class UserMgr @@ -49,15 +45,12 @@ class UserMgr
49 unset($in); 45 unset($in);
50 } 46 }
51 47
52 - if (isset($_POST['username']))  
53 - { 48 + if (isset($_POST['username'])) {
54 // Process Guest Login 49 // Process Guest Login
55 - if (strcasecmp(trim($_POST['username']),"guest") == 0)  
56 - { 50 + if (strcasecmp(trim($_POST['username']),"guest") == 0) {
57 $this->processGuestLogin(); 51 $this->processGuestLogin();
58 } 52 }
59 - else  
60 - { 53 + else {
61 $this->user = trim($_POST['username']); 54 $this->user = trim($_POST['username']);
62 } 55 }
63 } 56 }
@@ -65,8 +58,7 @@ class UserMgr @@ -65,8 +58,7 @@ class UserMgr
65 $this->user = trim($username); 58 $this->user = trim($username);
66 59
67 //TODO crypt / decrypt 60 //TODO crypt / decrypt
68 - if (!isset($this->passwd))  
69 - { 61 + if (!isset($this->passwd)) {
70 if (isset($_POST['password'])) 62 if (isset($_POST['password']))
71 $this->passwd = $_POST['password']; 63 $this->passwd = $_POST['password'];
72 else if (isset($password)) 64 else if (isset($password))
@@ -77,7 +69,8 @@ class UserMgr @@ -77,7 +69,8 @@ class UserMgr
77 $this->user = $_GET['sessionID']; 69 $this->user = $_GET['sessionID'];
78 else if (isset($sessionID)) 70 else if (isset($sessionID))
79 $this->user = $sessionID; 71 $this->user = $sessionID;
80 - // $this->amdaClient = new AmdaClient(); 72 + //TODO if AmdaClient is needed ?
  73 + $this->amdaClient = new AmdaClient();
81 } 74 }
82 75
83 //TODO if needed?? set session ID 76 //TODO if needed?? set session ID
@@ -94,8 +87,9 @@ class UserMgr @@ -94,8 +87,9 @@ class UserMgr
94 */ 87 */
95 if (getenv('REMOTE_ADDR')) 88 if (getenv('REMOTE_ADDR'))
96 { 89 {
97 - $realIP = getenv('REMOTE_ADDR');  
98 - if ($realIP == '10.10.131.1') { // proxy amdatest et openam 90 + $realIP = getenv('REMOTE_ADDR');
  91 +
  92 + if ($realIP == '10.10.131.1' || $realIP == '10.10.135.119') { // proxy amdatest et openam; amdadev
99 $allIPs = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']); 93 $allIPs = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
100 $realIP = count($allIPs) > 1 ? trim($allIPs[0]) : $_SERVER['HTTP_X_FORWARDED_FOR']; 94 $realIP = count($allIPs) > 1 ? trim($allIPs[0]) : $_SERVER['HTTP_X_FORWARDED_FOR'];
101 } 95 }
@@ -111,52 +105,57 @@ class UserMgr @@ -111,52 +105,57 @@ class UserMgr
111 105
112 public function getUserInfo() 106 public function getUserInfo()
113 { 107 {
114 - return $this->amdaClient->getUserInfo($this->user);  
115 - }  
116 -  
117 -/*  
118 -* Get Available Missions for a User (groups restriction)  
119 -*/  
120 - protected function getAvailableMissionsByUser()  
121 - {  
122 - $res = $this->amdaClient->getUserAvailableMissions($this->user);  
123 -  
124 - if (!$res['success'])  
125 - return array('local' => array(), 'external' => array());  
126 -  
127 - return array('local' => $res['local'], 'external' => $res['external']); 108 + // array("success" => TRUE,
  109 + // "login" => $login,
  110 + // "name" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("name") : "undefined",
  111 + // "first_name" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("first_name") : "undefined",
  112 + // "group" => $this->getUserMemberGroups($login),
  113 + // "email" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("email") : "undefined",
  114 + // "date" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("date") : "undefined",
  115 + // "news" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("news") : "0");
  116 + $info = $this->amdaClient->getUserInfo($this->user);
  117 + $wsSize = intval($this->getWsSize()/1024./1024.);
  118 + $quota = intval($this->getSpecialSettings()/1024./1024.);
  119 + $info['total'] = $quota;
  120 + $info['available'] = $quota - $wsSize;
  121 + $info['used'] = $wsSize;
  122 +
  123 + return $info;
128 } 124 }
129 125
130 public function createDir() 126 public function createDir()
131 { 127 {
132 if (!mkdir($this->userdir, 0755, true)) return false; 128 if (!mkdir($this->userdir, 0755, true)) return false;
133 129
134 - foreach ($this->userDirs as $key => $val)  
135 - { 130 + foreach ($this->userDirs as $key => $val) {
136 if (!mkdir($this->userdir.$val.'/', 0755, true)) return false; 131 if (!mkdir($this->userdir.$val.'/', 0755, true)) return false;
137 } 132 }
138 return true; 133 return true;
139 } 134 }
  135 +
  136 + protected function getUserGrps()
  137 + {
  138 + $info = $this->amdaClient->getUserInfo($this->user);
  139 +
  140 + if ($info['group'] == '')
  141 + return null;
  142 + else
  143 + return explode(',',$info['group']);
  144 + }
140 145
141 -/*  
142 -* Check if special groups with settings exist and user is from these groups  
143 -* Take the first group from user list  
144 -*/ 146 + /*
  147 + * Check if special groups with settings exist and user is from these groups
  148 + * Take the first group from user list
  149 + */
145 protected function isSpecialGroup() 150 protected function isSpecialGroup()
146 { 151 {
147 -  
148 $specialGrps = new DomDocument("1.0"); 152 $specialGrps = new DomDocument("1.0");
149 153
150 if (!($specialGrps->load(specialGrpsXml))) return null; 154 if (!($specialGrps->load(specialGrpsXml))) return null;
151 155
152 - $info = $this->amdaClient->getUserInfo($this->user);  
153 -  
154 - $userGrps = explode(',',$info['group']);  
155 -  
156 $specialGrpNode = null; 156 $specialGrpNode = null;
157 157
158 - foreach ($userGrps as $grp)  
159 - { 158 + foreach ($this->userGrps as $grp) {
160 $specialGrpNode = $specialGrps->getElementById($grp); 159 $specialGrpNode = $specialGrps->getElementById($grp);
161 if ($specialGrpNode) break; 160 if ($specialGrpNode) break;
162 } 161 }
@@ -164,6 +163,31 @@ class UserMgr @@ -164,6 +163,31 @@ class UserMgr
164 return $specialGrpNode; 163 return $specialGrpNode;
165 } 164 }
166 165
  166 + public function getSpecialSettings()
  167 + {
  168 + $userSettings = new DomDocument("1.0");
  169 +
  170 + if (!file_exists(specialSettingsXml) || !$userSettings->load(specialSettingsXml)) {
  171 + return DISK_QUOTA_standard;
  172 + }
  173 +
  174 + $theUser = $userSettings->getElementById($this->user);
  175 + if (!$theUser) {
  176 + return DISK_QUOTA_standard;
  177 + }
  178 +
  179 + $settings = $theUser->getElementsByTagName("setting");
  180 + if ($settings->length == 0) {
  181 + return DISK_QUOTA_standard;
  182 + }
  183 +
  184 + foreach ($settings as $setting) {
  185 + if ($setting->getAttribute("name") == 'DISK_QUOTA')
  186 + return $setting->getAttribute("value");
  187 + }
  188 +
  189 + }
  190 +
167 public function setSpecialSettings() 191 public function setSpecialSettings()
168 { 192 {
169 $userSettings = new DomDocument("1.0"); 193 $userSettings = new DomDocument("1.0");
@@ -185,22 +209,21 @@ class UserMgr @@ -185,22 +209,21 @@ class UserMgr
185 } 209 }
186 210
187 foreach ($settings as $setting) { 211 foreach ($settings as $setting) {
188 - $key = $setting->getAttribute("name");  
189 - $value = $setting->getAttribute("value");  
190 - $isSetting = $setting->hasAttribute("isSetting");  
191 - if ($isSetting) {  
192 - ini_set("$key",$value);  
193 - }  
194 - else {  
195 - // Attention !!! CONSTANT cannot be redefined  
196 - define("$key",$value);  
197 - }  
198 - } 212 + $key = $setting->getAttribute("name");
  213 + $value = $setting->getAttribute("value");
  214 + $isSetting = $setting->hasAttribute("isSetting");
  215 + if ($isSetting) {
  216 + ini_set("$key",$value);
  217 + }
  218 + else {
  219 + // Attention !!! CONSTANT cannot be redefined
  220 + define("$key",$value);
  221 + }
  222 + }
199 } 223 }
200 -  
201 - /*  
202 - * Totally replace IMPEX staff in user remote tree  
203 - */ 224 +/*
  225 +* Totally replace IMPEX staff in user remote tree
  226 +*/
204 protected function updateImpex() 227 protected function updateImpex()
205 { 228 {
206 $myRemoteBases = new DomDocument("1.0"); 229 $myRemoteBases = new DomDocument("1.0");
@@ -289,8 +312,9 @@ class UserMgr @@ -289,8 +312,9 @@ class UserMgr
289 312
290 /* 313 /*
291 * make remote data tree from list of distant bases if it doezn't exist 314 * make remote data tree from list of distant bases if it doezn't exist
292 -*/  
293 - protected function makeRemoteTree() 315 +*/
  316 +
  317 +protected function makeRemoteTree()
294 { 318 {
295 $remoteBases = new DomDocument("1.0"); 319 $remoteBases = new DomDocument("1.0");
296 320
@@ -493,18 +517,15 @@ unlink(USERWSDIR.'RemoteParams.xml'); @@ -493,18 +517,15 @@ unlink(USERWSDIR.'RemoteParams.xml');
493 517
494 public function setPath() 518 public function setPath()
495 { 519 {
496 - if (isset($_GET['sessionID']))  
497 - { 520 + if (isset($_GET['sessionID'])) {
498 $this->user = $_GET['sessionID']; 521 $this->user = $_GET['sessionID'];
499 $this->userdir = USERPATH."/".$this->user."/"; 522 $this->userdir = USERPATH."/".$this->user."/";
500 } 523 }
501 // for testing purposes 524 // for testing purposes
502 - else if (defined('TRANSFERUSER'))  
503 - { 525 + else if (defined('TRANSFERUSER')) {
504 $this->userdir = BASE_PATH."test/".TRANSFERUSER."/"; 526 $this->userdir = BASE_PATH."test/".TRANSFERUSER."/";
505 } 527 }
506 - else if (isset($this->user))  
507 - { 528 + else if (isset($this->user)) {
508 $this->userdir = USERPATH."/".$this->user."/"; 529 $this->userdir = USERPATH."/".$this->user."/";
509 } 530 }
510 531
@@ -512,8 +533,7 @@ unlink(USERWSDIR.'RemoteParams.xml'); @@ -512,8 +533,7 @@ unlink(USERWSDIR.'RemoteParams.xml');
512 533
513 define ("USERDIR", "$usrdir/"); 534 define ("USERDIR", "$usrdir/");
514 535
515 - foreach ($this->userDirs as $key => $val)  
516 - { 536 + foreach ($this->userDirs as $key => $val) {
517 $dir = $usrdir.$val; 537 $dir = $usrdir.$val;
518 define("$key","$dir/"); 538 define("$key","$dir/");
519 } 539 }
@@ -546,17 +566,14 @@ unlink(USERWSDIR.'RemoteParams.xml'); @@ -546,17 +566,14 @@ unlink(USERWSDIR.'RemoteParams.xml');
546 566
547 $this->userdir = USERPATH."/".$this->user."/"; 567 $this->userdir = USERPATH."/".$this->user."/";
548 568
549 - if (!is_dir($this->userdir))  
550 - {  
551 - if (!$this->createDir())  
552 - { 569 + if (!is_dir($this->userdir)) {
  570 + if (!$this->createDir()) {
553 die("Login for ".$this->user." failed: Can't create WS dirs"); 571 die("Login for ".$this->user." failed: Can't create WS dirs");
554 } 572 }
555 $this->isFirst = true; 573 $this->isFirst = true;
556 } 574 }
557 575
558 - if (file_exists($this->userdir.'newLogin'))  
559 - { 576 + if (file_exists($this->userdir.'newLogin')) {
560 copy($this->userdir.'newLogin',$this->userdir.'lastLogin'); 577 copy($this->userdir.'newLogin',$this->userdir.'lastLogin');
561 $dt = filemtime($this->userdir.'newLogin'); 578 $dt = filemtime($this->userdir.'newLogin');
562 touch($this->userdir.'lastLogin', $dt); 579 touch($this->userdir.'lastLogin', $dt);
@@ -582,18 +599,17 @@ unlink(USERWSDIR.'RemoteParams.xml'); @@ -582,18 +599,17 @@ unlink(USERWSDIR.'RemoteParams.xml');
582 touch($this->userdir.'newLogin'); 599 touch($this->userdir.'newLogin');
583 600
584 $this->setPath(); 601 $this->setPath();
585 - // $this->userMissions = $this->getAvailableMissionsByUser(); 602 +
  603 + $this->userGrps = $this->getUserGrps();
  604 +
  605 + if (!$this->makeLocalTree())
  606 + die("Login for ".$this->user." failed: Can't make LocalParams.xml");;
586 607
587 - if (file_exists(USERWSDIR.'LocalParams.xml'))  
588 - unlink(USERWSDIR.'LocalParams.xml');  
589 - // if (!file_exists(USERWSDIR.'LocalParams.xml'))  
590 - symlink(DATAPATH.'/LocalData/LocalParams.xml', USERWSDIR.'LocalParams.xml');  
591 -  
592 $ok = $this->makeRemoteTree(); 608 $ok = $this->makeRemoteTree();
593 609
594 if (!file_exists(USERWSDIR.'Request.xml')) $reqMgr = new RequestMgr(); 610 if (!file_exists(USERWSDIR.'Request.xml')) $reqMgr = new RequestMgr();
595 if (!file_exists(USERWSDIR.'Tt.xml')) $ttMgr = new TimeTableMgr(); 611 if (!file_exists(USERWSDIR.'Tt.xml')) $ttMgr = new TimeTableMgr();
596 - if (!file_exists(USERWSDIR.'Alias.xml'))$ttMgr = new AliasMgr(); 612 + if (!file_exists(USERWSDIR.'Alias.xml')) $ttMgr = new AliasMgr();
597 613
598 //TODO sessionID = user + WSname 614 //TODO sessionID = user + WSname
599 $sessionID = $this->user; 615 $sessionID = $this->user;
@@ -606,53 +622,85 @@ unlink(USERWSDIR.'RemoteParams.xml'); @@ -606,53 +622,85 @@ unlink(USERWSDIR.'RemoteParams.xml');
606 /* 622 /*
607 * Special groups are defined in the generic_data/SpecialSettings/Groups.xml 623 * Special groups are defined in the generic_data/SpecialSettings/Groups.xml
608 */ 624 */
609 - // $specialGroup = $this->isSpecialGroup();  
610 - $specialGroup = false;  
611 - // Special Info for special groups  
612 - if ($specialGroup)  
613 - {  
614 - // Special Settings for special groups - first visit just copying  
615 - if ($this->isFirst)  
616 - {  
617 - $grp = $specialGroup->getAttribute('xml:id');  
618 - $tags = $specialGroup->getElementsByTagName('folder');  
619 -  
620 - foreach ($tags as $tag)  
621 - {  
622 - $folder = $tag->getAttribute('name');  
623 - foreach (glob(SpecialSettingsDir.$grp."/".$folder."/*") as $file)  
624 - {  
625 - copy($file, $this->userdir.$folder."/".basename($file));  
626 - } 625 + if ($this->userGrps) {
  626 + // $specialGroup = $this->isSpecialGroup();
  627 + $specialGroup = false;
  628 + // Special Info for special groups
  629 + if ($specialGroup) {
  630 + // Special Settings for special groups - first visit just copying
  631 + if ($this->isFirst) {
  632 + $grp = $specialGroup->getAttribute('xml:id');
  633 + $tags = $specialGroup->getElementsByTagName('folder');
  634 +
  635 + foreach ($tags as $tag) {
  636 + $folder = $tag->getAttribute('name');
  637 +
  638 + foreach (glob(SpecialSettingsDir.$grp."/".$folder."/*") as $file) {
  639 + copy($file, $this->userdir.$folder."/".basename($file));
  640 + }
  641 + }
  642 + // mark to show help information
  643 + touch($this->userdir."$grp"."Help");
627 } 644 }
628 - // mark to show help information  
629 - touch($this->userdir."$grp"."Help"); 645 + // add requests
  646 + else { }
  647 + $grpName = $specialGroup->getAttribute('xml:id');
  648 + $helpName = "$grpName"."Help";
  649 +
  650 + if (file_exists(HELPPATH.$helpName) && file_exists($this->userdir.$helpName))
  651 + $this->isSpecialInfo = $helpName;
630 } 652 }
631 - // add requests  
632 - else { }  
633 - $grpName = $specialGroup->getAttribute('xml:id');  
634 - $helpName = "$grpName"."Help";  
635 -  
636 - if (file_exists(HELPPATH.$helpName) && file_exists($this->userdir.$helpName))  
637 - $this->isSpecialInfo = $helpName;  
638 -  
639 } 653 }
640 return $sessionID; 654 return $sessionID;
641 } 655 }
642 656
  657 + protected function makeLocalTree()
  658 + {
  659 + if (file_exists(USERWSDIR.'LocalParams.xml'))
  660 + unlink(USERWSDIR.'LocalParams.xml');
  661 +
  662 + if (!copy(DATAPATH.'/LocalData/LocalParams.xml', USERWSDIR.'LocalParams.xml'))
  663 + die("Login for ".$this->user." failed: Can't copy LocalParams.xml");
  664 +
  665 + if ($this->userGrps)
  666 + return $this->updateTreeForGrps(USERWSDIR.'LocalParams.xml');
  667 +
  668 + return true;
  669 + }
  670 +
  671 + protected function updateTreeForGrps($file)
  672 + {
  673 + $xml = new DomDocument("1.0");
  674 +
  675 + if(!$xml->load($file))
  676 + die("Login for ".$this->user." failed: Can't load LocalParams.xml");
  677 +
  678 + $xp = new domxpath($xml);
  679 +
  680 + foreach ($this->userGrps as $grp) {
  681 + $nodes = $xp->query("//*[@group='".$grp."']");
  682 +
  683 + if ($nodes->length > 0)
  684 + foreach ($nodes as $node) {
  685 + $node->removeAttribute('group');
  686 + if ($node->hasAttribute('restriction'))
  687 + $node->removeAttribute('restriction');
  688 + }
  689 + }
  690 +
  691 + return $xml->save($file);
  692 + }
  693 +
643 public function dirSize($dir) 694 public function dirSize($dir)
644 { 695 {
645 $handle = opendir($dir); 696 $handle = opendir($dir);
646 697
647 $mas = 0; 698 $mas = 0;
648 - while ($file = readdir($handle))  
649 - {  
650 - if ($file != '..' && $file != '.' && !is_dir($dir.'/'.$file))  
651 - { 699 + while ($file = readdir($handle)) {
  700 + if ($file != '..' && $file != '.' && !is_dir($dir.'/'.$file)) {
652 $mas += filesize($dir.'/'.$file); 701 $mas += filesize($dir.'/'.$file);
653 } 702 }
654 - else if (is_dir($dir.'/'.$file) && $file != '..' && $file != '.')  
655 - { 703 + else if (is_dir($dir.'/'.$file) && $file != '..' && $file != '.') {
656 $mas += $this->dirSize($dir.'/'.$file); 704 $mas += $this->dirSize($dir.'/'.$file);
657 } 705 }
658 } 706 }
@@ -669,7 +717,7 @@ unlink(USERWSDIR.'RemoteParams.xml'); @@ -669,7 +717,7 @@ unlink(USERWSDIR.'RemoteParams.xml');
669 return $wsSize; 717 return $wsSize;
670 } 718 }
671 719
672 -// http://www.ilovejackdaniels.com/php/email-address-validation/ 720 + // http://www.ilovejackdaniels.com/php/email-address-validation/
673 public function check_email_address($email) 721 public function check_email_address($email)
674 { 722 {
675 // First, we check that there's one @ symbol, and that the lengths are right 723 // First, we check that there's one @ symbol, and that the lengths are right