-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.GroupOffice.php
More file actions
84 lines (74 loc) · 3.11 KB
/
exec.GroupOffice.php
File metadata and controls
84 lines (74 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
if(!isset($GLOBALS["CLASS_SOCKETS"])){if(!class_exists("sockets")){include_once("/usr/share/artica-postfix/ressources/class.sockets.inc");}$GLOBALS["CLASS_SOCKETS"]=new sockets();}if(function_exists("posix_getuid")){if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");}}
include_once(dirname(__FILE__).'/ressources/class.templates.inc');
include_once(dirname(__FILE__).'/ressources/class.group-office.inc');
include_once(dirname(__FILE__).'/ressources/class.user.inc');
include_once(dirname(__FILE__)."/framework/frame.class.inc");
$user=new usersMenus();
if(!$user->GROUPOFFICE_INSTALLED){exit();}
$param=$argv[1];
if(preg_match("#--verbose#",implode(" ",$argv))){$GLOBALS["VERBOSE"]=true;}
if($param=='--all'){_GetServers();exit();}
if(preg_match('#--user=(.+)#',$param,$re)){fixuser(trim($re[1]));exit();}
_GetServers();
function fixuser($uid){
$ct=new user($uid);
$ou=$ct->ou;
$ldap=new clladp();
$dn="ou=www,ou=$ou,dc=organizations,$ldap->suffix";
$pattern="(&(objectclass=apacheConfig)(apacheServerName=*))";
$attr=array();
$sr =@ldap_search($ldap->ldap_connection,$ldap->suffix,$pattern,$attr);
$hash=ldap_get_entries($ldap->ldap_connection,$sr);
for($i=0;$i<$hash["count"];$i++){
$root=$hash[$i]["apachedocumentroot"][0];
$wwwservertype=trim($hash[$i]["wwwservertype"][0]);
$apacheservername=trim($hash[$i]["apacheservername"][0]);
$dn=$hash[$i]["dn"];
if($wwwservertype<>"GROUPOFFICE"){continue;}
$server_database=str_replace(" ","_",$apacheservername);
$server_database=str_replace(".","_",$server_database);
$server_database=str_replace("-","_",$server_database);
$groupoffice=new GroupOffice($server_database);
$groupoffice->UpdateUser($uid);
}
}
function _GetServers(){
$ldap=new clladp();
$pattern="(&(objectclass=apacheConfig)(apacheServerName=*))";
$attr=array();
$sr =@ldap_search($ldap->ldap_connection,$ldap->suffix,$pattern,$attr);
$hash=ldap_get_entries($ldap->ldap_connection,$sr);
//print_r($hash);
for($i=0;$i<$hash["count"];$i++){
$root=$hash[$i]["apachedocumentroot"][0];
$wwwservertype=trim($hash[$i]["wwwservertype"][0]);
$apacheservername=trim($hash[$i]["apacheservername"][0]);
$dn=$hash[$i]["dn"];
if($wwwservertype<>"GROUPOFFICE"){continue;}
if(preg_match("#ou=www,ou=(.+?),dc=organizations#",$dn,$re) ){$ou=$re[1];}
$server_database=str_replace(" ","_",$apacheservername);
$server_database=str_replace(".","_",$server_database);
$server_database=str_replace("-","_",$server_database);
ImportUsers(trim($ou),$server_database);
}
}
function ImportUsers($ou,$database){
if($database==null){
writelogs("$ou -> database is null",__FUNCTION__,__FILE__,__LINE__);
return;
}
$ldap=new clladp();
$dn="ou=users,ou=$ou,dc=organizations,$ldap->suffix";
$pattern="(&(objectclass=userAccount)(cn=*))";
$attr=array("uid","uidNumber");
$sr =@ldap_search($ldap->ldap_connection,$ldap->suffix,$pattern,$attr);
$hash=ldap_get_entries($ldap->ldap_connection,$sr);
for($i=0;$i<$hash["count"];$i++){
$uid=$hash[$i]["uid"][0];
$uidNumber=$hash[$i]["uidnumber"][0];
$groupoffice=new GroupOffice($database);
$groupoffice->UpdateUser($uid);
}
}
?>