-
Notifications
You must be signed in to change notification settings - Fork 4
/
testuser.php
174 lines (145 loc) · 3.37 KB
/
testuser.php
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* testuser.php
*
* In this file there are all the usage examples useful to learn and test all the
* class methods for Zm_User
*
* @author Yannick Lorenz <[email protected]>
* @author Fabrizio La Rosa <[email protected]>
* @version 2.1
* @copyright Copyright (c) 2009, Yannick Lorenz
* @copyright Copyright (c) 2012, Fabrizio La Rosa
* @name test.php
* @filesource
*/
/**
* testuser.php examples
*/
/////////////
// Require //
/////////////
require_once("config.php");
require_once("Zm/Auth.php");
require_once("Zm/User.php");
//////////
// Args //
//////////
if(PHP_SAPI != "cli")
$args = $_GET;
else
$args = parse_args($argv);
if(isset($args["action"]))
{
$action = $args["action"];
}
else
{
echo "No action, exiting\n";
exit (-1);
}
if(isset($args["str"]))
{
$user_name = $args["str"]. "@" . $domain;
}
if(isset($args["onam"]))
$nam_opt = $args["onam"];
if(isset($args["oval"]))
$val_opt = $args["oval"];
///////////
// Login //
///////////
$userpassword = "Password42";
$auth = new Zm_Auth($zimbraserver, $user_name, $userpassword, "user");
$l = $auth->login();
if(is_a($l, "Exception")) {
echo "Error : cannot login to $zimbraserver :-(\n";
print_exception($l);
exit();
}
//////////
// User //
//////////
$userManager = new Zm_User($auth);
// User Exists
if($action == "gux")
{
print_var($user_name, "Check User Existence");
$r = $userManager->userExists($user_name);
if(!$r) {
echo "NO: user $user_name doesn't exist :-(\n";
exit();
} else {
echo "YES : user $user_name exists :-)\n";
}
}
// Get User Informations
if($action == "gui")
{
$r = $userManager->getUserInfo($user_name);
if(is_a($r, "Exception")) {
echo "Error : cannot fetch the infos for user $user_name :-(\n";
print_exception($r);
} else {
print_var($r, "Get User Informations");
echo "OK : got the infos for user $user_name :-)\n";
}
}
// Get User Prefs
if($action == "gup")
{
$r = $userManager->getUserPrefs($user_name);
if(is_a($r, "Exception")) {
echo "Error : cannot fetch prefs for user $user_name :-(\n";
print_exception($r);
} else {
print_var($r, "Get User Prefs");
echo "OK : got prefs for user $user_name :-)\n";
}
}
// Get User Attrs
if($action == "gua")
{
if (!$nam_opt)
$nam_opt = "zimbraMailHost";
$r = $userManager->getUserAttrs($user_name);
if(is_a($r, "Exception")) {
echo "Error : cannot fetch attrs for user $user_name :-(\n";
print_exception($r);
} else {
print_var($r, "Get User Attrs");
echo "OK : got attrs for user $user_name :-)\n";
}
}
// Change User password
if($action == "cup")
{
$r = $userManager->changeUserPassword($user_name, $userpassword, "newPassword42");
if(is_a($r, "Exception")) {
echo "Error : cannot change password for user $user_name :-(\n";
print_exception($r);
} else {
print_var($r, "Change User Password");
echo "OK : password changed for user $user_name :-)\n";
}
}
// Modify Prefs
if($action == "mup")
{
if (!$nam_opt)
$nam_opt = "zimbraPrefMailItemsPerPage";
if (!$val_opt)
$val_opt = "42";
$new_prefs = array($nam_opt=>$val_opt);
print_var($new_prefs, "Modify Prefs");
$r = $userManager->modifyUserPrefs($user_name, $new_prefs);
if(is_a($r, "Exception")) {
echo "Error : cannot modify prefs for $user_name :-(\n";
print_exception($r);
} else {
print_var($r, "Modify Prefs : Response");
echo "OK : modify user prefs for $user_name :-)\n";
}
}
if(!$r) echo "Invalid action!\n";
?>