[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare API - Accounts manager for the contacts class * |
---|
| 4 | * This file written by Miles Lott <milosch@groupwhere.org> * |
---|
| 5 | * View and manipulate account records using the contacts class * |
---|
| 6 | * Copyright (C) 2000, 2001 Miles Lott * |
---|
| 7 | * -------------------------------------------------------------------------* |
---|
| 8 | * This library is part of the eGroupWare API * |
---|
| 9 | * http://www.egroupware.org/api * |
---|
| 10 | * ------------------------------------------------------------------------ * |
---|
| 11 | * This library is free software; you can redistribute it and/or modify it * |
---|
| 12 | * under the terms of the GNU Lesser General Public License as published by * |
---|
| 13 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
| 14 | * or any later version. * |
---|
| 15 | * This library is distributed in the hope that it will be useful, but * |
---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
| 18 | * See the GNU Lesser General Public License for more details. * |
---|
| 19 | * You should have received a copy of the GNU Lesser General Public License * |
---|
| 20 | * along with this library; if not, write to the Free Software Foundation, * |
---|
| 21 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
| 22 | \**************************************************************************/ |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | /* |
---|
| 27 | THIS NEEDS WORK!!!!!!!!! - Milosch |
---|
| 28 | But it is a lot closer now... |
---|
| 29 | */ |
---|
| 30 | $GLOBALS['phpgw_info']['server']['global_denied_users'] = array( |
---|
| 31 | 'root' => True, 'bin' => True, 'daemon' => True, |
---|
| 32 | 'adm' => True, 'lp' => True, 'sync' => True, |
---|
| 33 | 'shutdown' => True, 'halt' => True, 'ldap' => True, |
---|
| 34 | 'mail' => True, 'news' => True, 'uucp' => True, |
---|
| 35 | 'operator' => True, 'games' => True, 'gopher' => True, |
---|
| 36 | 'nobody' => True, 'xfs' => True, 'pgsql' => True, |
---|
| 37 | 'mysql' => True, 'postgres' => True, 'oracle' => True, |
---|
| 38 | 'ftp' => True, 'gdm' => True, 'named' => True, |
---|
| 39 | 'alias' => True, 'web' => True, 'sweep' => True, |
---|
| 40 | 'cvs' => True, 'qmaild' => True, 'qmaill' => True, |
---|
| 41 | 'qmaillog' => True, 'qmailp' => True, 'qmailq' => True, |
---|
| 42 | 'qmailr' => True, 'qmails' => True, 'rpc' => True, |
---|
| 43 | 'rpcuser' => True, 'amanda' => True, 'apache' => True, |
---|
| 44 | 'pvm' => True, 'squid' => True, 'ident' => True, |
---|
| 45 | 'nscd' => True, 'mailnull' => True, 'cyrus' => True, |
---|
| 46 | 'backup' => True |
---|
| 47 | ); |
---|
| 48 | |
---|
| 49 | $GLOBALS['phpgw_info']['server']['global_denied_groups'] = array( |
---|
| 50 | 'root' => True, 'bin' => True, 'daemon' => True, |
---|
| 51 | 'sys' => True, 'adm' => True, 'tty' => True, |
---|
| 52 | 'disk' => True, 'lp' => True, 'mem' => True, |
---|
| 53 | 'kmem' => True, 'wheel' => True, 'mail' => True, |
---|
| 54 | 'uucp' => True, 'man' => True, 'games' => True, |
---|
| 55 | 'dip' => True, 'ftp' => True, 'nobody' => True, |
---|
| 56 | 'floppy' => True, 'xfs' => True, 'console' => True, |
---|
| 57 | 'utmp' => True, 'pppusers' => True, 'popusers' => True, |
---|
| 58 | 'slipusers' => True, 'slocate' => True, 'mysql' => True, |
---|
| 59 | 'dnstools' => True, 'web' => True, 'named' => True, |
---|
| 60 | 'dba' => True, 'oinstall' => True, 'oracle' => True, |
---|
| 61 | 'gdm' => True, 'sweep' => True, 'cvs' => True, |
---|
| 62 | 'postgres' => True, 'qmail' => True, 'nofiles' => True, |
---|
| 63 | 'ldap' => True, 'backup' => True |
---|
| 64 | ); |
---|
| 65 | |
---|
| 66 | class accounts_ |
---|
| 67 | { |
---|
| 68 | var $db; |
---|
| 69 | var $contacts; |
---|
| 70 | var $account_id; |
---|
| 71 | var $data; |
---|
| 72 | var $debug = False; |
---|
| 73 | var $qcols = array( |
---|
| 74 | 'fn' => 'fn', |
---|
| 75 | 'n_given' => 'n_given', |
---|
| 76 | 'n_family' => 'n_family', |
---|
| 77 | 'account_lastlogin' => 'account_lastlogin', |
---|
| 78 | 'account_lastloginfrom' => 'account_lastloginfrom', |
---|
| 79 | 'account_lastpwd_change' => 'account_lastpwd_change', |
---|
| 80 | 'account_status' => 'account_status', |
---|
| 81 | 'account_expires' => 'account_expires' |
---|
| 82 | ); |
---|
| 83 | |
---|
| 84 | function accounts_() |
---|
| 85 | { |
---|
| 86 | $this->db = $GLOBALS['phpgw']->db; |
---|
| 87 | $this->contacts = CreateObject('phpgwapi.contacts',0); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | function makeobj() |
---|
| 91 | { |
---|
| 92 | if(!$this->contacts) |
---|
| 93 | { |
---|
| 94 | $this->contacts = CreateObject('phpgwapi.contacts','0'); |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | function read_repository() |
---|
| 99 | { |
---|
| 100 | $this->makeobj(); |
---|
| 101 | |
---|
| 102 | $allValues = $this->contacts->read_single_entry($this->account_id,$this->qcols); |
---|
| 103 | |
---|
| 104 | /* Now dump it into the array */ |
---|
| 105 | $this->data['userid'] = $allValues[0]['lid']; |
---|
| 106 | $this->data['account_id'] = $allValues[0]['id']; |
---|
| 107 | $this->data['account_lid'] = $allValues[0]['lid']; |
---|
| 108 | $this->data['account_type'] = $allValues[0]['tid']; |
---|
| 109 | $this->data['firstname'] = $allValues[0]['n_given']; |
---|
| 110 | $this->data['lastname'] = $allValues[0]['n_family']; |
---|
| 111 | $this->data['fullname'] = $allValues[0]['fn']; |
---|
| 112 | $this->data['lastlogin'] = $allValues[0]['account_lastlogin']; |
---|
| 113 | $this->data['lastloginfrom'] = $allValues[0]['account_lastloginfrom']; |
---|
| 114 | $this->data['lastpasswd_change'] = $allValues[0]['account_lastpwd_change']; |
---|
| 115 | $this->data['status'] = $allValues[0]['account_status']; |
---|
| 116 | $this->data['expires'] = $allValues[0]['account_expires']; |
---|
[547] | 117 | $this->data['agree_terms'] = $allValues[0]['phpgwagreeterm'][0]; |
---|
[2] | 118 | return $this->data; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | function save_repository() |
---|
| 122 | { |
---|
| 123 | $this->makeobj(); |
---|
| 124 | |
---|
| 125 | $entry['id'] = $this->data['account_id']; |
---|
| 126 | $entry['lid'] = $this->data['account_lid']; |
---|
| 127 | $entry['tid'] = $this->data['account_type']; |
---|
| 128 | $entry['fn'] = sprintf("%s %s", $this->data['firstname'], $this->data['lastname']); |
---|
| 129 | $entry['n_family'] = $this->data['lastname']; |
---|
| 130 | $entry['n_given'] = $this->data['firstname']; |
---|
| 131 | $entry['account_lastlogin'] = $this->data['lastlogin']; |
---|
| 132 | $entry['account_lastloginfrom'] = $this->data['lastloginfrom']; |
---|
| 133 | $entry['account_lastpasswd_change'] = $this->data['lastpwd_change']; |
---|
| 134 | $entry['account_status'] = $this->data['status']; |
---|
| 135 | $entry['account_expires'] = $this->data['expires']; |
---|
| 136 | |
---|
| 137 | if($this->debug) { echo '<br>Updating entry:<br>' . var_dump($entry); } |
---|
| 138 | $this->contacts->update($entry['id'],0,$entry,'public','',$entry['tid']); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | function add($account_name, $account_type, $first_name, $last_name, $passwd = False) |
---|
| 142 | { |
---|
| 143 | $this->create($account_name, $account_type, $first_name, $last_name, $passwd); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | function delete($accountid = '') |
---|
| 147 | { |
---|
| 148 | $this->makeobj(); |
---|
| 149 | |
---|
| 150 | if($this->debug) { echo '<br>Deleting entry:<br>' . $account_id; } |
---|
| 151 | $account_id = get_account_id($accountid); |
---|
| 152 | $this->contacts->delete($account_id); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | function get_list($_type='both') |
---|
| 156 | { |
---|
| 157 | $this->makeobj(); |
---|
| 158 | |
---|
| 159 | switch($_type) |
---|
| 160 | { |
---|
| 161 | case 'accounts': |
---|
| 162 | $filter = 'tid=u'; |
---|
| 163 | break; |
---|
| 164 | case 'groups': |
---|
| 165 | $filter = 'tid=g'; |
---|
| 166 | break; |
---|
| 167 | default: |
---|
| 168 | $filter = 'tid=u,tid=g'; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | $allValues = $this->contacts->read(0,0,$this->qcols,'',$filter); |
---|
| 172 | |
---|
| 173 | /* get user information for each user/group */ |
---|
| 174 | for($i=0;$i<count($allValues);$i++) |
---|
| 175 | { |
---|
| 176 | $accounts[] = Array( |
---|
| 177 | 'account_id' => $allValues[$i]['id'], |
---|
| 178 | 'account_lid' => $allValues[$i]['lid'], |
---|
| 179 | 'account_type' => $allValues[$i]['tid'], |
---|
| 180 | 'account_firstname' => $allValues[$i]['n_given'], |
---|
| 181 | 'account_lastname' => $allValues[$i]['n_family'], |
---|
| 182 | 'account_status' => $allValues[$i]['account_status'], |
---|
| 183 | 'account_expires' => $allValues[$i]['account_expires'] |
---|
| 184 | ); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | return $accounts; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | function name2id($account_lid) |
---|
| 191 | { |
---|
| 192 | $qcols = array('id' => 'id'); |
---|
| 193 | $this->makeobj(); |
---|
| 194 | $allValues = $this->contacts->read(0,0,$qcols,'',"lid=".$account_lid); |
---|
| 195 | |
---|
| 196 | if($allValues[0]['id']) |
---|
| 197 | { |
---|
| 198 | return (int)$allValues[0]['id']; |
---|
| 199 | } |
---|
| 200 | else |
---|
| 201 | { |
---|
| 202 | return False; |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | function id2name($account_id) |
---|
| 207 | { |
---|
| 208 | $this->makeobj(); |
---|
| 209 | |
---|
| 210 | $allValues = $this->contacts->read_single_entry($account_id); |
---|
| 211 | if($this->debug) { echo '<br>id2name: '.$allValues[0]['lid']; } |
---|
| 212 | |
---|
| 213 | if($allValues[0]['lid']) |
---|
| 214 | { |
---|
| 215 | return $allValues[0]['lid']; |
---|
| 216 | } |
---|
| 217 | else |
---|
| 218 | { |
---|
| 219 | return False; |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | function get_type($accountid = '') |
---|
| 224 | { |
---|
| 225 | $this->makeobj(); |
---|
| 226 | $account_id = get_account_id($accountid); |
---|
| 227 | |
---|
| 228 | $allValues = $this->contacts->read_single_entry($account_id); |
---|
| 229 | |
---|
| 230 | if ($allValues[0]['tid']) |
---|
| 231 | { |
---|
| 232 | return $allValues[0]['tid']; |
---|
| 233 | } |
---|
| 234 | else |
---|
| 235 | { |
---|
| 236 | return False; |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | function exists($account_lid) |
---|
| 241 | { |
---|
| 242 | $this->makeobj(); |
---|
| 243 | if(is_int($account_lid)) |
---|
| 244 | { |
---|
| 245 | $account_id = $account_lid; |
---|
| 246 | settype($account_lid,'string'); |
---|
| 247 | $account_lid = $this->id2name($account_id); |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | $allValues = $this->contacts->read(0,0,array('n_given' => 'n_given'),'','lid='.$account_lid); |
---|
| 251 | |
---|
| 252 | if ($allValues[0]['id']) |
---|
| 253 | { |
---|
| 254 | return True; |
---|
| 255 | } |
---|
| 256 | else |
---|
| 257 | { |
---|
| 258 | return False; |
---|
| 259 | } |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | function create($account_info) |
---|
| 263 | { |
---|
| 264 | $this->makeobj(); |
---|
| 265 | |
---|
| 266 | if (!$$account_info['account_id']) |
---|
| 267 | { |
---|
| 268 | $account_info['account_id'] = $this->get_nextid(); |
---|
| 269 | } |
---|
| 270 | $owner = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 271 | $entry['id'] = $account_info['account_id']; |
---|
| 272 | $entry['lid'] = $account_info['account_lid']; |
---|
| 273 | $entry['n_given'] = $account_info['account_firstname']; |
---|
| 274 | $entry['n_family'] = $account_info['account_lastname']; |
---|
| 275 | $entry['password'] = $account_info['account_passwd']; |
---|
| 276 | $entry['account_status'] = $account_info['account_status']; |
---|
| 277 | $entry['account_expires'] = $account_info['account_expires']; |
---|
| 278 | |
---|
| 279 | if($this->debug) { echo '<br>Adding entry:<br>' . var_dump($entry); } |
---|
| 280 | /* 'public' access, no category id, tid set to account_type */ |
---|
| 281 | $this->contacts->add(0,$entry,'public','',$account_info['account_type']); |
---|
| 282 | return; |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | function auto_add($accountname, $passwd, $default_prefs = False, $default_acls = False, $expiredate = 0, $account_status = 'A') |
---|
| 286 | { |
---|
| 287 | if (! $expiredate) |
---|
| 288 | { |
---|
| 289 | // expire in 30 days by default |
---|
| 290 | $expiredate = time() + ( ( 60 * 60 ) * (30 * 24) ); |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | $acct_info = array( |
---|
| 294 | 'account_lid' => $accountname, |
---|
| 295 | 'account_type' => 'u', |
---|
| 296 | 'account_passwd' => $passwd, |
---|
| 297 | 'account_firstname' => '', |
---|
| 298 | 'account_lastname' => '', |
---|
| 299 | 'account_status' => $account_status, |
---|
| 300 | 'account_expires' => mktime(2,0,0,date('n',$expiredate), (int)date('d',$expiredate), date('Y',$expiredate)) |
---|
| 301 | ); |
---|
| 302 | $this->create($acct_info); |
---|
| 303 | $accountid = $this->name2id($accountname); |
---|
| 304 | |
---|
| 305 | $this->db->transaction_begin(); |
---|
| 306 | if (!$default_prefs) |
---|
| 307 | { |
---|
| 308 | $default_prefs = 'a:5:{s:6:"common";a:10:{s:9:"maxmatchs";s:2:"15";s:12:"template_set";s:8:"verdilak";s:5:"theme";s:6:"purple";s:13:"navbar_format";s:5:"icons";s:9:"tz_offset";N;s:10:"dateformat";s:5:"m/d/Y";s:10:"timeformat";s:2:"12";s:4:"lang";s:2:"en";s:11:"default_app";N;s:8:"currency";s:1:"$";}s:11:"addressbook";a:1:{s:0:"";s:4:"True";}:s:8:"calendar";a:4:{s:13:"workdaystarts";s:1:"7";s:11:"workdayends";s:2:"15";s:13:"weekdaystarts";s:6:"Monday";s:15:"defaultcalendar";s:9:"month.php";}}'; |
---|
| 309 | // $defaultprefs = 'a:5:{s:6:"common";a:1:{s:0:"";s:2:"en";}s:11:"addressbook";a:1:{s:0:"";s:4:"True";}s:8:"calendar";a:1:{s:0:"";s:13:"workdaystarts";}i:15;a:1:{s:0:"";s:11:"workdayends";}s:6:"Monday";a:1:{s:0:"";s:13:"weekdaystarts";}}'; |
---|
| 310 | $this->db->query("insert into phpgw_preferences (preference_owner, preference_value) values ('".$accountid."', '$default_prefs')",__LINE__,__FILE__); |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | if (!$default_acls) |
---|
| 314 | { |
---|
| 315 | $apps = Array( |
---|
| 316 | 'addressbook', |
---|
| 317 | 'calendar', |
---|
| 318 | 'email', |
---|
| 319 | 'notes', |
---|
| 320 | 'todo', |
---|
| 321 | 'phpwebhosting', |
---|
| 322 | 'manual' |
---|
| 323 | ); |
---|
| 324 | |
---|
| 325 | $this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_rights)values('preferences', 'changepassword', ".$accountid.", 1)",__LINE__,__FILE__); |
---|
| 326 | $this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) values('phpgw_group', '1', ".$accountid.", 1)",__LINE__,__FILE__); |
---|
| 327 | @reset($apps); |
---|
| 328 | while(list($key,$app) = each($apps)) |
---|
| 329 | { |
---|
| 330 | $this->db->query("INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) VALUES ('".$app."', 'run', ".$accountid.", 1)",__LINE__,__FILE__); |
---|
| 331 | } |
---|
| 332 | } |
---|
| 333 | $this->db->transaction_commit(); |
---|
| 334 | return $accountid; |
---|
| 335 | } |
---|
| 336 | } |
---|