Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
upload.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Generated Header (not documented yet)
9  *
10  * @author Anakeen 2000
11  * @version $Id: upload.php,v 1.10 2004/03/22 15:21:40 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage ACCESS
15  */
16 /**
17  */
18 // ---------------------------------------------------------------
19 // $Id: upload.php,v 1.10 2004/03/22 15:21:40 eric Exp $
20 // $Source: /home/cvsroot/anakeen/freedom/core/Action/Access/upload.php,v $
21 // ---------------------------------------------------------------
22 include_once ("Class.QueryDb.php");
23 include_once ("Class.Application.php");
24 include_once ("Class.User.php");
25 include_once ("Class.Acl.php");
26 include_once ("Class.Domain.php");
27 include_once ("Class.MailAccount.php");
28 include_once ("Class.Permission.php");
29 include_once ("Lib.Http.php");
30 // -----------------------------------
31 function upload(&$action)
32 {
33  // -----------------------------------
34  global $_FILES;
35  $action->log->debug("UPLOAD");
36  // select the first user if not set
37  // What user are we working on ? ask session.
38  $filename = ($_FILES["upfile"]["tmp_name"]);
39 
40  if (!file_exists($filename)) {
41  $action->ExitError("File not found : $filename : " . $_FILES["upfile"]["name"]);
42  }
43  $content = file($filename);
44 
45  $tnewacl = array();
46  while (list($k, $v) = each($content)) {
47  switch (substr($v, 0, 1)) {
48  case "U":
49  changeuser($action, substr($v, 2));
50  break;
51 
52  case "A":
53  changeacl($action, substr($v, 2));
54  break;
55  }
56  }
57 
58  redirect($action, "ACCESS", "USER_ACCESS");
59 }
60 
61 function changeuser(&$action, $line, $verbose = false)
62 {
63 
64  $col = explode("|", $line);
65  // eric.brison@local|hb7Qj/yFqxCGs|eric|brison|N|all@local;
66  list($uname, $udom) = explode("@", $col[0]);
67  $udom = chop($udom);
68  $use = new User($action->dbaccess);
69  $domain = new Domain($action->dbaccess);
70  $domain->Set($udom);
71 
72  $use->SetLogin($uname, $domain->iddomain);
73  $use->password = $col[1];
74  $use->firstname = $col[2];
75  $use->lastname = $col[3];
76  $use->isgroup = $col[4];
77  if ($use->IsAffected()) {
78  $err = $use->Modify(true);
79  if ($err != "") print $err;
80 
81  if ($verbose) printf(_("user %s %s has been modified\n") , $use->firstname, $use->lastname);
82  } else {
83  $use->iddomain = $domain->iddomain;
84  $use->login = $uname;
85  $err = $use->Add(true);
86  if ($err != "") print $err;
87  if ($verbose) printf(_("user %s %s has been added\n") , $use->firstname, $use->lastname);
88  }
89  // add mail account if needed
90  if ($use->iddomain != 1) {
91  $mailapp = new Application();
92  if ($mailapp->Exists("MAILADMIN")) {
93  $mailapp->Set("MAILADMIN", $action->parent);
94  $uacc = new MailAccount($mailapp->GetParam("MAILDB") , $use->id);
95  $uacc->iddomain = $use->iddomain;
96  $uacc->iduser = $use->id;
97  $uacc->login = $use->login;
98  if ($uacc->isAffected()) $uacc->Modify(true);
99  else $uacc->Add(true);
100  }
101  }
102  // add group
103  $groups = explode(";", $col[5]);
104 
105  $group = new Group($action->dbaccess, $use->id);
106  if ($group->isAffected()) $group->delete(true);
107 
108  while (list($kg, $gd) = each($groups)) {
109 
110  list($grname, $grdomain) = explode("@", $gd);
111 
112  $gr = new User($action->dbaccess);
113  $gd = new Domain($action->dbaccess);
114  $grdomain = chop($grdomain);
115  $gd->Set($grdomain);
116 
117  $gr->SetLogin($grname, $gd->iddomain);
118  if ($gr->IsAffected()) {
119  $group->iduser = $use->id;
120  $group->idgroup = $gr->id;
121  $group->add(true);
122  }
123  }
124 }
125 function changeacl(&$action, $line, $verbose = false)
126 {
127  // INCIDENT|all@cir.fr|INCIDENT_READ;INCIDENT
128  $col = explode("|", $line);
129  if (!is_array($col)) continue;
130  if (count($col) != 3) continue;
131  if (substr($line, 0, 1) == "#") continue; // comment line
132  $app = new Application($action->dbaccess);
133  $app->Set($col[0], $action->parent);
134 
135  list($uname, $udom) = explode("@", $col[1]);
136  $udom = chop($udom);
137 
138  $use = new User($action->dbaccess);
139  $domain = new Domain($action->dbaccess);
140  $domain->Set($udom);
141 
142  $use->SetLogin($uname, $domain->iddomain);
143  // update the permission in database
144  // first remove then add
145  $perm = new Permission($action->dbaccess, array(
146  $use->id,
147  $app->id
148  ));
149  if (!$perm->IsAffected()) {
150  $perm->Affect(array(
151  "id_user" => $use->id,
152  "id_application" => $app->id
153  ));
154  }
155  $taclname = explode(";", $col[2]);
156 
157  if (count($taclname) > 0) {
158  $perm->Delete();
159  $taclid = array();
160  foreach ($taclname as $aclname) {
161  $unp = false; // is negative privilege ?
162  $aclname = chop($aclname);
163  if (substr($aclname, 0, 1) == "-") {
164  $aclname = substr($aclname, 1);
165  $unp = true;
166  };
167  // search acl id
168  $acl = new Acl($action->dbaccess);
169  $acl->Set($aclname, $app->id);
170 
171  if ($acl->id == "") continue;
172 
173  if ($unp) {
174  $taclid[] = - $acl->id;
175  } else {
176  $taclid[] = $acl->id;
177  }
178  }
179 
180  foreach ($taclid as $aclid) {
181  $perm->id_acl = $aclid;
182 
183  if ($aclid != 0) {
184  //print "ADD "."-".$perm->id_application."-". $perm->id_user."-". $perm->id_acl."<BR>";
185  $err = $perm->Add();
186  if ($err != "") print $err;
187  if ($verbose) printf(_("add acl %s for %s %s\n") , $perm->id_acl, $use->firstname, $use->lastname);
188  }
189  }
190  }
191 }
192 ?>
← centre documentaire © anakeen - published under CC License - Dynacase