-
Notifications
You must be signed in to change notification settings - Fork 131
/
manageuser.php
379 lines (322 loc) · 13.5 KB
/
manageuser.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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<?php
include("init.php");
$user = (object)new user();
$action = getArrayVal($_GET, "action");
$id = getArrayVal($_GET, "id");
$mode = getArrayVal($_GET, "mode");
if ($action != "login" and $action != "logout" and $action != "resetpassword" and $action != "loginerror") {
if (!isset($_SESSION["userid"])) {
$template->assign("loginerror", 0);
$template->display("login.tpl");
die();
}
}
//Get Data from $_POST and $_GET filtered and sanitized by htmlpurifier
$cleanGet = cleanArray($_GET);
$cleanPost = cleanArray($_POST);
$template->assign("mode", $mode);
// get the available languages
$languages = getAvailableLanguages();
$template->assign("languages", $languages);
$project = array();
$project['ID'] = $id;
$template->assign("project", $project);
// set css classes for menue buttons
$classes = array("overview" => "overview", "msgs" => "msgs", "tasks" => "tasks", "miles" => "miles", "files" => "files", "users" => "users_active", "tracker" => "tracking");
$mainclasses = array("desktop" => "",
"profil" => "active",
"admin" => ""
);
$template->assign("mainclasses", $mainclasses);
$template->assign("classes", $classes);
/*
* VIEW ROUTES
* These are routes that render HTML views to the browser or create side effects
*/
if ($action == "loginerror") {
$template->display("resetpassword.tpl");
} elseif ($action == "resetpassword") {
$cleanPost["newpass"] = $user->resetPassword($cleanPost["email"]);
if ($cleanPost["newpass"] !== false) {
$langFile = readLangfile($cleanPost["newpass"]['locale']);
$subject = $langfile["projectpasswordsubject"];
$mailcontent = $langfile["hello"] . ",<br /><br/>" .
$langfile["projectpasswordtext"] . "<br /><br />" .
$langfile["newpass"] . ": " . $cleanPost["newpass"]['newpass'] . "<br />" .
$langfile["login"] . ": <a href = \"$url\">$url</a>";
// Send e-mail with new password
$themail = new emailer($settings);
$themail->send_mail($cleanPost["email"], $subject, $mailcontent);
$template->assign("success", 1);
$template->display("resetpassword.tpl");
} else {
$template->assign("loginerror", 1);
$template->display("resetpassword.tpl");
}
} elseif ($action == "login") {
$openid = getArrayVal($_POST, "openid");
$username = getArrayVal($_POST, "username");
$pass = getArrayVal($_POST, "pass");
// Normal login
if ($user->login($username, $pass)) {
$loc = $url . "index.php?mode=login";
header("Location: $loc");
} // Login Error
else {
$template->assign("loginerror", 1);
$template->assign("mailnotify", $settings["mailnotify"]);
$template->display("login.tpl");
}
} elseif ($action == "logout") {
if ($user->logout()) {
header("Location: index.php?mode=logout");
}
} elseif ($action == "addform") {
$title = $langfile['adduser'];
$template->assign("title", $title);
$template->display("adduserform.tpl");
} elseif ($action == "editform") {
$languages_fin = array();
foreach ($languages as $lang) {
$fin = countLanguageStrings($lang);
if (!($langfile[$lang] == "")) {
$lang2 = $langfile[$lang];
} else {
$lang2 = $lang;
}
$lang2 .= " (" . $fin . "%)";
$fin = array("val" => $lang, "str" => $lang2);
array_push($languages_fin, $fin);
}
$template->assign("languages_fin", $languages_fin);
$title = $langfile['edituser'];
$template->assign("title", $title);
$euser = $user->getProfile($userid);
$template->assign("user", $euser);
$template->display("edituserform.tpl");
} elseif ($action == "edit") {
$_SESSION['userlocale'] = $cleanPost["locale"];
$_SESSION['username'] = $cleanPost["name"];
if (!empty($_FILES['userfile']['name'])) {
$fname = $_FILES['userfile']['name'];
$typ = $_FILES['userfile']['type'];
$size = $_FILES['userfile']['size'];
$tmp_name = $_FILES['userfile']['tmp_name'];
$error = $_FILES['userfile']['error'];
$root = "./";
$teilnamen = explode(".", $fname);
$teile = count($teilnamen);
$workteile = $teile - 1;
$erweiterung = $teilnamen[$workteile];
$subname = "";
$allowedFiletypes = array("image/jpeg", "image/png", "image/gif", "image/pjpeg");
if (!in_array($typ, $allowedFiletypes)) {
$loc = $url . "manageuser.php?action=profile&id=$userid";
header("Location: $loc");
die();
}
// If it is a PHP file, treat as plain text so it is not executed when opened in the browser
$allowedExtensions = array(".jpg", ".jpeg", ".gif", ".pjpeg");
if (!in_array($erweiterung, $allowedExtensions)) {
$erweiterung = "txt";
$typ = "text/plain";
}
for ($i = 0; $i < $workteile; $i++) {
$subname .= $teilnamen[$i];
}
list($usec, $sec) = explode(' ', microtime());
$seed = (float)$sec + ((float)$usec * 100000);
srand($seed);
$randval = rand(1, 999999);
$subname = preg_replace("/[^-_0-9a-zA-Z]/", "_", $subname);
$subname = preg_replace("/\W/", "", $subname);
if (strlen($subname) > 200) {
$subname = substr($subname, 0, 200);
}
$fname = $subname . "_" . $randval . "." . $erweiterung;
$datei_final = CL_ROOT . "/files/" . CL_CONFIG . "/avatar/" . $fname;
if (move_uploaded_file($tmp_name, $datei_final)) {
$avatar = $fname;
}
if ($user->edit($userid, $cleanPost["name"], $cleanPost["realname"], $cleanPost["email"], $cleanPost["tel1"], $cleanPost["tel2"], "", $cleanPost["zip"], $cleanPost["gender"], $cleanPost["web"], $cleanPost["address1"], $cleanPost["address2"], $cleanPost["state"], $cleanPost["country"], "", $cleanPost["locale"], $avatar, 0)) {
if (!empty($cleanPost["oldpass"]) and !empty($cleanPost["newpass"]) and !empty($cleanPost["repeatpass"])) {
$user->editpass($userid, $cleanPost["oldpass"], $cleanPost["newpass"], $cleanPost["repeatpass"]);
}
$loc = $url . "manageuser.php?action=profile&id=$userid&mode=edited";
header("Location: $loc");
}
} else {
if ($user->edit($userid, $cleanPost["name"], $cleanPost["realname"], $cleanPost["email"], $cleanPost["tel1"], $cleanPost["tel2"], $cleanPost["company"], $cleanPost["zip"], $cleanPost["gender"], $cleanPost["web"], $cleanPost["address1"], $cleanPost["address2"], $cleanPost["state"], $cleanPost["country"], "", $cleanPost["locale"], "", 0)) {
if (isset($cleanPost["oldpass"]) and isset($cleanPost["newpass"]) and isset($cleanPost["repeatpass"])) {
$user->editpass($userid, $cleanPost["oldpass"], $cleanPost["newpass"], $cleanPost["repeatpass"]);
}
$loc = $url . "manageuser.php?action=profile&id=$userid&mode=edited";
header("Location: $loc");
}
}
} elseif ($action == "del") {
if (!$userpermissions["admin"]["add"]) {
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "$errtxt<br>$noperm");
$template->assign("mode", "error");
$template->display("error.tpl");
die();
}
if ($user->del($id)) {
$loc = $url . "admin.php?action=users&mode=deleted";
header("Location: $loc");
}
} elseif ($action == "profile") {
$start = getArrayVal($_GET, "start");
$end = getArrayVal($_GET, "end");
$profile = $user->getProfile($id);
$title = $langfile['userprofile'];
$template->assign("title", $title);
$template->assign("user", $profile);
// This is done specifically to address an XSS vulnerability
// caused by rendering two user inputs on same line in HTML.
// They must be escaped together and rendered as one.
$template->assign("zipcity", purify(implode(' ', [$profile['zip'], $profile['adress2']])));
$template->display("userprofile.tpl");
} elseif ($action == "showproject") {
if (!chkproject($userid, $id)) {
$errtxt = $langfile["notyourproject"];
$noperm = $langfile["accessdenied"];
$template->assign("mode", "error");
$template->assign("errortext", "$errtxt<br>$noperm");
$template->display("error.tpl");
die();
}
$mainclasses = array("desktop" => "desktop",
"profil" => "profil",
"admin" => "admin"
);
$template->assign("mainclasses", $mainclasses);
$projectObj = (object)new project();
$alluser = $user->getAllUsers(10000);
$users = array();
foreach ($alluser as $all) {
if (!chkproject($all['ID'], $id)) {
array_push($users, $all);
}
}
$members = $projectObj->getProjectMembers($id, 14);
$pro = $projectObj->getProject($id);
$projectname = $pro['name'];
$title = $langfile['members'];
$template->assign("title", $title);
$template->assign("projectname", $projectname);
$template->assign("members", $members);
$template->assign("users", $users);
$template->display("projectmembers.tpl");
} elseif ($action == "onlinelist") {
$onlinelist = $user->getOnlinelist();
if (!empty($onlinelist)) {
echo "<ul>";
foreach ($onlinelist as $online) {
echo "<li>" . "<a class=\"user\" href = \"manageuser.php?action=profile&id=" . $online["ID"] . "\">" . $online["name"] . "</a></li>";
}
echo "</ul>";
}
} elseif ($action == "vcard") {
$theuser = $user->getProfile($id);
$vCard = (object)new vCard($theuser["locale"]);
$vCard->setFirstName($theuser["name"]);
$vCard->setCompany($theuser["company"]);
$vCard->setOrganisation($theuser["company"]);
$vCard->setPostalStreet($theuser["adress"]);
$vCard->setPostalZIP($theuser["zip"]);
$vCard->setWorkZIP($theuser["zip"]);
$vCard->setHomeZIP($theuser["zip"]);
$vCard->setPostalCity($theuser["adress2"]);
$vCard->setHomeCity($theuser["adress2"]);
$vCard->setPostalRegion($theuser["state"]);
$vCard->setPostalCountry($theuser["country"]);
$vCard->setWorkStreet($theuser["adress"]);
$vCard->setWorkCity($theuser["adress2"]);
$vCard->setWorkRegion($theuser["state"]);
$vCard->setWorkCountry($theuser["country"]);
$vCard->setUrlWork($theuser["url"]);
$vCard->setEMail($theuser["email"]);
header('Content-Type: text/x-vcard');
header('Content-Disposition: inline; filename=' . $theuser["name"] . '_' . date("d-m-Y") . '.vcf');
echo $vCard->getCardOutput();
} /*
* DATA ROUTES
* These are routes that render JSON data structures
*/
elseif ($action == "projectMembers") {
if (!chkproject($userid, $id)) {
$errtxt = $langfile["notyourproject"];
$noperm = $langfile["accessdenied"];
$template->assign("mode", "error");
$template->assign("errortext", "$errtxt<br>$noperm");
$template->display("error.tpl");
die();
}
$offset = 0;
if (isset($cleanGet["offset"])) {
$offset = $cleanGet["offset"];
}
$limit = 21;
if (isset($cleanGet["limit"])) {
$limit = $cleanGet["limit"];
}
$projectObj = new project();
$members = $projectObj->listProjectMembers($id, $limit, $offset);
$projectMembers["count"] = $projectObj->countMembers($id);
$projectMembers["items"] = $members;
echo json_encode($projectMembers);
} elseif ($action == "userProjects") {
if ($userpermissions["admin"]["add"] || $userid == $id) {
$offset = 0;
if (isset($cleanGet["offset"])) {
$offset = $cleanGet["offset"];
}
$limit = 10;
if (isset($cleanGet["limit"])) {
$limit = $cleanGet["limit"];
}
$projectObj = (object)new project();
$openProjects = $projectObj->getMyProjects($id, 1, $offset, $limit);
$openProjectsNum = $projectObj->countMyProjects($id);
$i = 0;
if (!empty($openProjects)) {
foreach ($openProjects as &$openProject) {
$projectMembers = $projectObj->getProjectMembers($openProject["ID"], 1000);
$openProject["members"] = $projectMembers;
$i = $i + 1;
}
}
$projects["items"] = $openProjects;
$projects["count"] = $openProjectsNum;
}
if (!empty($projects)) {
echo json_encode($projects);
} else {
echo json_encode(array());
}
} elseif ($action == "userTimetracker") {
if ($userpermissions["admin"]["add"] || $userid == $id) {
$tracker = (object)new timetracker();
$track = array();
$offset = 0;
if (isset($cleanGet["offset"])) {
$offset = $cleanGet["offset"];
}
$limit = 10;
if (isset($cleanGet["limit"])) {
$limit = $cleanGet["limit"];
}
$track = $tracker->getUserTrack($id, 0, 0, 0, 0, $limit, $offset);
$userTrack["items"] = $track;
$trackCount = count($tracker->getUserTrack($id, 0, 0, 0, 0, 10000000));
$userTrack["count"] = $trackCount;
}
if (!empty($userTrack)) {
echo json_encode($userTrack);
} else {
echo json_encode(array());
}
}