-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmasq.php
More file actions
167 lines (120 loc) · 3.16 KB
/
masq.php
File metadata and controls
167 lines (120 loc) · 3.16 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
<?php
if($_POST['check'] == 1) {
process_form();
} else {
if($_GET['um'] == '1') {
process_unmask();
} else {
print_form();
}
}
function process_unmask() {
include('inc/getperms.php');
include('inc/functions.php');
if($_COOKIE['masq'] == '') {
print_error(array("You're not masqerading."));
die;
}
$newid = $_COOKIE['masq'];
$expire = strtotime(date("F d, Y ") . "23:59:59") + 1;
setcookie('instr_id', $newid, $expire);
setcookie('masq', '');
include('inc/insidehead.php');
print <<<UNMASQ
<div id='content'>
</h1>You've been unmasqed!</h1>
<p>
You now have the same priviledges you did before you started masquerading.
</p>
<p>
<a href='main.php'>Click here</a> to go to the main page, or <a href='masq.php'>click here</a> to masquerade as someone else.
</p>
</div>
UNMASQ;
include('inc/insidefoot.php');
}
function process_form() {
include('inc/getperms.php');
include('inc/functions.php');
if($highest_perm < 3) {
print_error(array("You don't have permission to be here"));
die;
}
if($_COOKIE['masq'] != '') {
$error = "You are already masquerading. Please unmask before impersonating someone else.";
print_error(array($error));
$die;
}
$oldid = $_COOKIE['instr_id'];
$newid = $_POST['instructor'];
$expire = strtotime(date("F d, Y ") . "23:59:59") + 1;
setcookie('masq', $oldid, $expire);
setcookie('instr_id', $newid, $expire);
include('inc/insidehead.php');
print <<<MASQ
<div id='content'>
<h1>Success!</h1>
<p>
On your next page load, you will have the same permissions as instructor $newid, and the "logout" link (at the top of the page) will change to "unmask". To stop masquerading, click the "unmasq" link.
</p>
<p>
<a href='main.php'>Click here</a> to go to the main GSW Evaluations page.
</p>
</div>
MASQ;
include('inc/insidefoot.php');
}
function print_form() {
include('inc/getperms.php');
include('inc/functions.php');
if($highest_perm < 3) {
print_error(array("You don't have permission to be here"));
die;
}
/* get instructor info */
include_once('inc/mysql.php');
$instr_sql = ""
. "SELECT DISTINCT instructors.instr_id,"
. " instr_lname, instr_fname"
. " FROM instructors, permissions"
. " WHERE instructors.instr_id = permissions.instr_id"
. " AND perm_level <= 2"
. " ORDER BY instr_lname"
;
$instr_res = mysql_query($instr_sql);
if(!$instr_res) {
die("Database error (get instructor info): " . mysql_error());
}
$instr_opt = "";
while($row = mysql_fetch_assoc($instr_res)) {
$iid = $row['instr_id'];
$lname = $row['instr_lname'];
$fname = $row['instr_fname'];
if($fname == '') {
$name = $lname;
} else {
$name = "$lname, $fname";
}
$instr_opt .= "\n\t<option value='$iid'>$name ($iid)</option>";
}
$thisdoc = $_SERVER['PHP_SELF'];
include('inc/insidehead.php');
print <<<ENDFORM
<div id='content'>
<h1>Instructor masquerading</h1>
<p>
Select the instructor you wish to impersonate below and click "Masquerade".
</p>
<p>
<form method='post' action='$thisdoc'>
<input type='hidden' name='check' value='1'/>
<select name='instructor'>$instr_opt
</select>
<input type='submit' value='Masquerade'/>
</form>
</p>
</div>
ENDFORM;
include('inc/insidefoot.php');
}
?>