Skip to content

Commit f54f221

Browse files
committed
Web UI: Allow admins to view other user profiles
This includes entire user profile page, plus favorite locations on the map and favorite access points in the search. Editing profile data on behalf of the other user is not provided yet.
1 parent c1eb6f7 commit f54f221

8 files changed

+209
-26
lines changed

3wifi.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@
170170
break;
171171
}
172172

173+
$viewLevel = $UserManager->Level;
174+
if (!is_null($UserManager->vuID))
175+
{
176+
$info = $UserManager->getUserInfo($UserManager->vuID);
177+
$viewLevel = (int)$info['level'];
178+
}
179+
173180
function HasWildcards($str, $wc)
174181
{
175182
return StrInStr($str, $wc[0]) || StrInStr($str, $wc[1]);
@@ -219,10 +226,12 @@ function GenerateFindQuery($cmtid, $ipaddr, $BSSID, $ESSID, $Auth, $Name, $Key,
219226
if ($k >= 6)
220227
$DataCount += $k;
221228

222-
global $UserManager;
229+
global $UserManager, $viewLevel;
223230
$uid = $UserManager->uID;
231+
if (!is_null($UserManager->vuID))
232+
$uid = $UserManager->vuID;
224233

225-
if ((!$UseLocation) && ($UserManager->Level < 2) && ($DataCount < 6))
234+
if ((!$UseLocation) && ($viewLevel < 2) && ($DataCount < 6))
226235
{
227236
$isLimitedRequest = true;
228237
}
@@ -419,7 +428,7 @@ function GenerateFindQuery($cmtid, $ipaddr, $BSSID, $ESSID, $Auth, $Name, $Key,
419428
if (isset($_POST['bssid'])) $bssid = $_POST['bssid'];
420429
if (isset($_POST['essid'])) $essid = $_POST['essid'];
421430
$bssid = preg_replace('/[^0-9A-Fa-f\*]/', '', $bssid);
422-
if ($UserManager->Level > 1)
431+
if ($viewLevel > 1)
423432
{
424433
if (isset($_POST['comment'])) $comment = $_POST['comment'];
425434
if (isset($_POST['ipaddr'])) $ipaddr = $_POST['ipaddr'];
@@ -512,12 +521,12 @@ function GenerateFindQuery($cmtid, $ipaddr, $BSSID, $ESSID, $Auth, $Name, $Key,
512521
$LastId = (int)$row['id'];
513522

514523
$entry = array();
515-
if ($UserManager->Level >= 1) $entry['id'] = (int)$row['id'];
524+
if ($viewLevel >= 1) $entry['id'] = (int)$row['id'];
516525
$entry['time'] = $row['time'];
517526
$entry['comment'] = ($row['cmtid'] == null ? '' : $row['cmtval']);
518527
$ip = _long2ip($row['IP']);
519528
$wanip = _long2ip($row['WANIP']);
520-
if ($UserManager->Level > 1)
529+
if ($viewLevel > 1)
521530
{
522531
$entry['ipport'] = ($ip != '' ? $ip : ($wanip != '' ? $wanip : ''));
523532
if (isLocalIP($entry['ipport'])

index.html

+48-2
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,35 @@
260260
}
261261
});
262262
}
263+
function doReturnView()
264+
{
265+
$.get('user.php?a=token', function(json)
266+
{
267+
if (!json.result)
268+
{
269+
alert(errorStr(json.error));
270+
return false;
271+
} else {
272+
var postdata = '';
273+
postdata += 'token=' + encodeURIComponent(json.token);
274+
postdata += '&uid=0';
275+
postdata += '&view=0';
276+
$.post('user.php?a=setuser', postdata, function(json)
277+
{
278+
if (!json.result)
279+
{
280+
alert(errorStr(json.error));
281+
}
282+
else
283+
{
284+
window.location.reload();
285+
}
286+
return false;
287+
}).fail(onFail);
288+
}
289+
}).fail(onFail);
290+
return false;
291+
}
263292
function loginBtn(force)
264293
{
265294
if (ProfileInfo.isUser == 0 || force)
@@ -342,7 +371,18 @@
342371
{
343372
top.location.href = this.location.href;
344373
}
345-
if (ProfileInfo.isUser == 0) $('a[href=user]').hide();
374+
375+
if (ProfileInfo.isUser == 0)
376+
{
377+
$('a[href=user]').hide();
378+
}
379+
else if (ProfileInfo.viewUser != '')
380+
{
381+
var str = $('#returnbtn > p').html();
382+
str = str.replace(/%username%/g, encodeHTML(ProfileInfo.viewUser));
383+
$('#returnbtn > p').html(str);
384+
$($('a[href=user]')[0]).hide().next().show();
385+
}
346386

347387
if (!isMobile())
348388
{
@@ -408,7 +448,13 @@
408448
</span>
409449
</span>
410450
<a href="javascript://" onclick="loginBtn(false)" style="float: right"><div class=menubtn><p>%login_str%</p></div></a>
411-
<a href="user"><div class="%chk_user%" style="float: right" id=nickname><p>%nick%</p></div></a>
451+
<a href="user"><div class="%chk_user%" style="float: right"><p>%nick%</p></div></a>
452+
<span class=multi style="display: none; float: right">
453+
<a href="user"><div class="%chk_user%"><p>%nick%</p></div></a>
454+
<span class=submenu>
455+
<a href="#" onclick="return doReturnView()"><div class="submbtn" id=returnbtn><p>%l10n_menu_return%</p></div></a>
456+
</span>
457+
</span>
412458
</div>
413459
</div>
414460

index.php

+37-9
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,45 @@ function preparePage(&$content)
7171
$content = str_replace('%broadcast%', $broadcast, $content);
7272

7373
global $UserManager, $l10n, $profile, $lat, $lon, $rad;
74+
$ViewLogin = $UserManager->Login;
75+
$ViewNick = $UserManager->Nick;
76+
$ViewLevel = $UserManager->Level;
77+
$ViewInvites = $UserManager->invites;
78+
$ViewRAPI = $UserManager->ReadApiKey;
79+
$ViewWAPI = $UserManager->WriteApiKey;
80+
$ViewReg = $UserManager->RegDate;
81+
$ViewInviter = $UserManager->InviterNickName;
82+
$ViewUser = '';
83+
84+
if (!is_null($UserManager->vuID))
85+
{
86+
$ViewUser = $ViewNick;
87+
$info = $UserManager->getUserInfo($UserManager->vuID);
88+
$ViewLogin = $info['login'];
89+
$ViewNick = $info['nick'];
90+
$ViewLevel = (int)$info['level'];
91+
$ViewInvites = (int)$info['invites'];
92+
$ViewRAPI = $info['rapikey'];
93+
$ViewWAPI = $info['wapikey'];
94+
$ViewReg = $info['regdate'];
95+
$ViewInviter = $UserManager->getUserNameById($info['puid']);
96+
}
97+
98+
if (empty($ViewRAPI)) $ViewRAPI = $l10n['no_access'];
99+
if (empty($ViewWAPI)) $ViewWAPI = $l10n['no_access'];
100+
74101
$content = str_replace('%login_str%', ($UserManager->isLogged() ? $l10n['menu_logout'] : $l10n['menu_login']), $content);
75102
$content = str_replace('%profile%', $profile, $content);
76103
$content = str_replace('%isUser%', (int)$UserManager->isLogged(), $content);
77-
$content = str_replace('%login%', htmlspecialchars($UserManager->Login), $content);
78-
$content = str_replace('%nick%', htmlspecialchars($UserManager->Nick), $content);
79-
$content = str_replace('%user_access_level%', $UserManager->Level, $content);
80-
$content = str_replace('%user_invites%', $UserManager->invites, $content);
81-
$content = str_replace('%rapikey%', $UserManager->ReadApiKey, $content);
82-
$content = str_replace('%wapikey%', $UserManager->WriteApiKey, $content);
83-
$content = str_replace('%regdate%', $UserManager->RegDate, $content);
84-
$content = str_replace('%refuser%', $UserManager->InviterNickName, $content);
104+
$content = str_replace('%login%', htmlspecialchars($ViewLogin), $content);
105+
$content = str_replace('%nick%', htmlspecialchars($ViewNick), $content);
106+
$content = str_replace('%user_access_level%', $ViewLevel, $content);
107+
$content = str_replace('%user_invites%', $ViewInvites, $content);
108+
$content = str_replace('%view_user%', htmlspecialchars($ViewUser), $content);
109+
$content = str_replace('%rapikey%', $ViewRAPI, $content);
110+
$content = str_replace('%wapikey%', $ViewWAPI, $content);
111+
$content = str_replace('%regdate%', $ViewReg, $content);
112+
$content = str_replace('%refuser%', $ViewInviter, $content);
85113
$content = str_replace('%var_lat%', $lat, $content);
86114
$content = str_replace('%var_lon%', $lon, $content);
87115
$content = str_replace('%var_rad%', $rad, $content);
@@ -175,7 +203,7 @@ function setFloat($in, &$out)
175203
}
176204
}
177205

178-
$profile = 'isUser: %isUser%, Nickname: "%nick%", Level: %user_access_level%, invites: %user_invites%';
206+
$profile = 'isUser: %isUser%, Nickname: "%nick%", Level: %user_access_level%, invites: %user_invites%, viewUser: "%view_user%"';
179207

180208
$theme_base = 'themes';
181209
$themes = scandir("$theme_base/");

l10n/en-US.php

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@
124124
'Login';
125125
$l10n['menu_logout'] =
126126
'Logout';
127+
$l10n['menu_return'] =
128+
'Return to %username%';
127129

128130
/* 404 */
129131
$l10n['msg_404'] =

l10n/ru-RU.php

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@
124124
'Вход';
125125
$l10n['menu_logout'] =
126126
'Выход';
127+
$l10n['menu_return'] =
128+
'Вернуться к %username%';
127129

128130
/* 404 */
129131
$l10n['msg_404'] =

user.class.php

+27-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class User {
4545

4646
public $uID = NULL;
4747
public $puID = NULL;
48+
public $vuID = NULL;
4849
public $InviterNickName = NULL;
4950
public $Login = '';
5051
public $Nick = '';
@@ -55,8 +56,8 @@ class User {
5556
public $Level = self::USER_UNAUTHORIZED;
5657
public $HashIP = NULL;
5758
public $invites = 0;
58-
public $ReadApiKey = 'N/A';
59-
public $WriteApiKey = 'N/A';
59+
public $ReadApiKey = '';
60+
public $WriteApiKey = '';
6061
public $ApiAccess = '';
6162

6263
public $LastUpdate = 0;
@@ -187,6 +188,8 @@ public function saveSession() {
187188
*/
188189
$_SESSION['uID'] = $this->uID;
189190
$_SESSION['puID'] = $this->puID;
191+
if (!is_null($this->vuID))
192+
$_SESSION['view_uid'] = $this->vuID;
190193
$_SESSION['InviterNickName'] = $this->InviterNickName;
191194
$_SESSION['Login'] = $this->Login;
192195
$_SESSION['Nick'] = $this->Nick;
@@ -238,6 +241,7 @@ public function loadSession() {
238241
return false;
239242
}
240243
$this->puID = $_SESSION['puID'];
244+
$this->vuID = $_SESSION['view_uid'];
241245
$this->InviterNickName = $_SESSION['InviterNickName'];
242246
$this->Login = $_SESSION['Login'];
243247
$this->Nick = $_SESSION['Nick'];
@@ -486,6 +490,21 @@ public function admBanReason($uid, $ban_reason)
486490
return self::$mysqli->query("UPDATE users SET ban_reason=$ban_reason,lastupdate=lastupdate WHERE uid=$uid");
487491
}
488492

493+
public function admViewUser($uid)
494+
{
495+
unset($_SESSION['view_uid']);
496+
$this->vuID = NULL;
497+
if (!is_null($uid))
498+
{
499+
$info = $this->getUserInfo($uid);
500+
if (is_null($info['login']))
501+
return false;
502+
$_SESSION['view_uid'] = $uid;
503+
$this->vuID = $uid;
504+
}
505+
return true;
506+
}
507+
489508
public function Registration($Login, $Nick, $Password, $Invite)
490509
{
491510
$Salt = $this->GenerateRandomString(32);
@@ -661,7 +680,12 @@ public function listInvites($uid = null) {
661680
* @param int $uid
662681
* @return array $Invites
663682
*/
664-
if (is_null($uid)) $uid = $this->uID;
683+
if (is_null($uid))
684+
{
685+
$uid = $this->uID;
686+
if (!is_null($this->vuID))
687+
$uid = $this->vuID;
688+
}
665689
if ($uid == NULL) return false;
666690

667691
$sql = 'SELECT time, users.regdate, invite, nick, IF(users.level IS NULL, invites.level, users.level) AS level FROM invites LEFT JOIN users USING(`uid`) WHERE invites.puid='.$this->quote($uid).' ORDER BY time';

user.html

+15-5
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,9 @@
10571057

10581058
function setUserAccount(e, opt)
10591059
{
1060+
if ($('input[name=nick]').val() == '')
1061+
return false;
1062+
10601063
var btn = $(e);
10611064
btnShowLoad(btn, true);
10621065
$.get('user.php?a=token', function(json)
@@ -1070,12 +1073,16 @@
10701073
var postdata = '';
10711074
postdata += 'token=' + encodeURIComponent(json.token);
10721075
postdata += '&uid=' + mgmt_uid;
1073-
if (opt == 'a')
1076+
if (opt == 'level')
10741077
{
10751078
postdata += '&level=' + $('select#user_level').val();
10761079
if (ban_reason != '')
10771080
postdata += '&ban_reason=' + ban_reason;
10781081
}
1082+
else if (opt == 'view')
1083+
{
1084+
postdata += '&view=1';
1085+
}
10791086
else
10801087
{
10811088
postdata += '&invites=' + $('input[name=invites]').val();
@@ -1089,7 +1096,10 @@
10891096
}
10901097
else
10911098
{
1092-
alert("%l10n_msg_user_set_success%");
1099+
if (opt == 'view')
1100+
window.open('#inv', '_blank').focus();
1101+
else
1102+
alert("%l10n_msg_user_set_success%");
10931103
}
10941104
return false;
10951105
}).fail(simpleFail);
@@ -1216,15 +1226,15 @@ <h2 align=center><span class=header_cap>%l10n_msg_user% %nick%</span></h2>
12161226
<tr><td>%l10n_str_reg_date%</td>
12171227
<td><input type="text" name="reg_date" id="reg_date" readonly /></td></tr>
12181228
<tr><td>%l10n_str_level%</td>
1219-
<td><select id="user_level"></select>&nbsp;<select id="ban_reason"></select></td><td><input type="button" value="%l10n_btn_save%" onclick="return setUserAccount(this, 'a')"/><img src="%theme_ajax%" style="display: none;"/></td></tr>
1229+
<td><select id="user_level"></select>&nbsp;<select id="ban_reason"></select></td><td><input type="button" value="%l10n_btn_save%" onclick="return setUserAccount(this, 'level')"/><img src="%theme_ajax%" style="display: none;"/></td></tr>
12201230
<tr><td><label for="pass">%l10n_str_pass%</label></td>
12211231
<td><input type="text" name="pass" id="pass" readonly /></td><td><input type="submit" value="%l10n_btn_reset%"/><img src="%theme_ajax%" style="display: none;"/></td></tr>
12221232
<tr><td>%l10n_str_visited%</td>
12231233
<td><input type="text" name="visited" id="visited" readonly /></td></tr>
12241234
<tr><td>%l10n_str_inv_invited_created%</td>
1225-
<td><a href="#" id="inv_created">0/0</a></td></tr>
1235+
<td><a href="#" id="inv_created" onclick="return setUserAccount(null, 'view')">0/0</a></td></tr>
12261236
<tr><td><label for="invites">%l10n_str_inv_left%</label></td>
1227-
<td colspan=2><input type="number" name="invites" id="invites" min="0" max="100" step="1"/>&nbsp;<input type="button" value="%l10n_btn_save%" onclick="return setUserAccount(this, 'b')"/><img src="%theme_ajax%" style="display: none;"/></td></tr>
1237+
<td colspan=2><input type="number" name="invites" id="invites" min="0" max="100" step="1"/>&nbsp;<input type="button" value="%l10n_btn_save%" onclick="return setUserAccount(this, 'invites')"/><img src="%theme_ajax%" style="display: none;"/></td></tr>
12281238
<tr><td><label for="refuser">%l10n_str_inviter%</label></td>
12291239
<td><input type="text" name="refuser" id="refuser" readonly /></td><td><input type="button" value="%l10n_btn_get%" onclick="return getUserParent(this)"/><img src="%theme_ajax%" style="display: none;"/></td></tr>
12301240
</table>

0 commit comments

Comments
 (0)