forked from smillie/gas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
248 lines (231 loc) · 11.1 KB
/
edit.php
File metadata and controls
248 lines (231 loc) · 11.1 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php require 'ldapconnect.php'; ?>
<?php
if (!isUserInGroup($con, $user, "gsag")) {
header( 'Location: index.php' );
}
if (isset($_POST['reset'])) {
$u = $_GET['user'];
$search = ldap_search($con, $dn, "(uid=$u)");
$result = ldap_get_entries($con, $search);
$pass = generatePassword();
mt_srand((double)microtime()*1000000);
$salt = pack("CCCCCCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand());
$hashedpass = "{SSHA}" . base64_encode( sha1( $pass . $salt, true) . $salt );
$entry['userpassword'] = $hashedpass;
ldap_modify($con,"uid=".$u.",".$dn,$entry);
$success = "Password for $u reset to '$pass'.";
$mailmessage = <<<EOT
Your GeekSoc password has been reset by an administrator.
Username: $u
New Password: $pass
GeekSoc
http://www.geeksoc.org/
EOT;
mailNotify($result[0]['mail'][0], "[GeekSoc] Your password has been reset", $mailmessage);
ircNotify("Password reset for $u (by $user)");
}
if (isset($_POST['delete'])) {
$u = $_GET['user'];
ldap_delete($con,"uid=".$u.",".$dn);
if (ldap_error($con) != "Success") {
$error = ldap_error($con);
} else {
$success = "User $u has been deleted.";
}
$groups = getGroupsForUser($con, $u);
foreach ($groups as $g) {
$attr['memberUid'] = $u;
ldap_mod_del($con, "cn=" . $g . ",ou=groups,dc=geeksoc,dc=org", $attr);
}
ircNotify("Account deleted: $u (by $user)");
}
else if (isset($_GET['user'])) {
$u = $_GET['user'];
$search = ldap_search($con, $dn, "(uid=$u)");
$result = ldap_get_entries($con, $search);
if (ldap_count_entries($con, $search) == 0) {
$error = "No such user.";
}
}
else {
//header( 'Location: listusers.php' );
}
if (isset($_POST['update'])) {
$entry['cn'] = $_POST['cn'];
if ($entry['studentnumber'] != NULL ) {
$entry['studentnumber'] = $_POST['studentnumber'];
}
$entry['mail'] = $_POST['email'];
switch ($_POST['loginShell']) {
case "/bin/bash":
$entry['loginshell']="/bin/bash";
break;
case "/bin/tcsh":
$entry['loginshell']="/bin/tcsh";
break;
case "/bin/zsh":
$entry['loginshell']="/bin/zsh";
break;
}
$edate = strtotime($_POST['expiry']);
$entry['shadowexpire'] = intval($edate/(60*60*24))+1;
if ($result[0]['haspaid'][0] != NULL ) {
switch ($_POST['hasPaid']) {
case "yes":
$entry['hasPaid'] = "TRUE";
break;
case "no":
$entry['hasPaid'] = "FALSE";
break;
}
}
if ($_POST['notes'] == NULL) {
$notes['notes'] = $result[0]['notes'][0];
ldap_mod_del($con,"uid=".$u.",".$dn,$notes);
} else {
$entry['notes'] = $_POST['notes'];
}
ldap_modify($con,"uid=".$u.",".$dn,$entry);
if (ldap_error($con) != "Success") {
$error = ldap_error($con);
}
$success = "Details updated successfully.";
$search = ldap_search($con, $dn, "(uid=$u)");
$result = ldap_get_entries($con, $search);
}
$pageTitle = ' - Edit User: '.$u;
?>
<?php require 'header.php'; ?>
<?php require 'menu.php'; ?>
<div class="span10">
<div class="row">
<div class="span5">
<?php if (isset($_GET['user']) && !isset($_POST['delete'])) : ?>
<form id="form" class="form-horizontal" action="edit.php?user=<?php echo $u; ?>" method="post">
<fieldset>
<legend>Edit User</legend>
<div class="control-group">
<?php if (isset($error)) : ?>
<div class="alert alert-error">
<?php echo "$error"; ?>
</div>
<?php elseif (isset($success)) : ?>
<div class="alert alert-success">
<?php echo "$success"; ?>
</div>
<?php endif; ?>
<label class="control-label" for="uid">Account Name</label>
<div class="controls">
<span class="input-xlarge uneditable-input"><?php echo $result[0]["uid"][0]; ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="cn">Full Name</label>
<div class="controls">
<input type="text" class="input-xlarge required" name="cn" id="cn" value="<?php echo $result[0]["cn"][0]; ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="studentNumber">Student Number</label>
<div class="controls">
<input type="text" class="input-xlarge digits" name="studentnumber" id="studentnumber" value="<?php echo $result[0]["studentnumber"][0]; ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="email">Email</label>
<div class="controls">
<input type="text" class="input-xlarge required email" name="email" id="email" value="<?php echo $result[0]["mail"][0]; ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="loginShell">Login Shell</label>
<div class="controls">
<select id="loginShell" name="loginShell">
<?php $shell=$result[0]["loginshell"][0]?>
<option <?php echo($shell == "/bin/bash"?' selected="selected"':null) ?>>/bin/bash</option>
<option <?php echo($shell == "/bin/tcsh"?' selected="selected"':null) ?>>/bin/tcsh</option>
<option <?php echo($shell == "/bin/zsh"?' selected="selected"':null) ?>>/bin/zsh</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Groups</label>
<div class="controls">
<span class="uneditable-input input-xlarge">
<?php foreach(getGroupsForUser($con,$u) as $g){ echo "<a href='editgroup.php?group=$g'>$g</a> "; } ?>
</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="status">Account Status</label>
<div class="controls">
<span class="input-xlarge uneditable-input"><?php echo getStatus($result[0]['shadowexpire'][0], $result[0]['haspaid'][0]); ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">Expiry</label>
<div class="controls">
<?php
$expiry = intval($result[0]['shadowexpire'][0])*(60*60*24);
$edate = date("Y-m-d", $expiry);
?>
<input type="text" class="input-xlarge required dateISO" name="expiry" id="expiry" value="<?php echo $edate; ?>">
</div>
</div>
<div class="control-group">
<label class="control-label">Paid?</label>
<div class="controls">
<label class="radio inline">
<input type="radio" name="hasPaid" id="optionsRadios1" value="yes" <?php echo($result[0]['haspaid'][0]== "TRUE"?' checked':null) ?>> Yes
</label>
<label class="radio inline">
<input type="radio" name="hasPaid" id="optionsRadios2" value="no" <?php echo($result[0]['haspaid'][0]== "FALSE"?' checked':null) ?>> No
</label>
</div>
</div>
<div class="control-group">
<label class="control-label" for="notes">Notes</label>
<div class="controls">
<textarea class="input-xlarge" id="notes" name="notes" rows="3"><?php echo $result[0]['notes'][0]; ?></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="notes">Password</label>
<div class="controls">
<button name="reset" type="submit" class="btn btn-small" >Reset Password</button>
</div>
</div>
<div class="form-actions">
<div id="deleteConfromModal" class="modal hide ">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Are you sure?</h3>
</div>
<div class="modal-body">
<p>This will immediately delete <?php echo $result[0]['cn'][0]; ?>'s account from the LDAP directory.</p>
<p><strong>Note:</strong> The home directory will not be deleted.</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal" >Cancel</a>
<button name="delete" type="submit" class="btn btn-danger" ><i class="icon-trash icon-white"></i> Confirm Delete</button>
</div>
</div>
<a data-toggle="modal" href="#deleteConfromModal" class="btn btn-danger"><i class="icon-trash icon-white"></i> Delete</a>
<button type="submit" class="btn btn-primary" name="update" >Update Details</button>
</div>
</fieldset>
</form>
<?php else : ?>
<fieldset>
<legend>Edit User</legend>
<div class="control-group">
<form class="well form-search" action="listusers.php" method='GET'>
<input type="text" name="search" class="input-xlarge search-query">
<button type="submit" class="btn">Search</button>
</form>
</div>
<?php endif; ?>
</div><!--/span-->
</div><!--/row-->
</div><!--/span-->
<?php require 'footer.php'; ?>