-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathaccount.php
311 lines (263 loc) · 9.28 KB
/
account.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
<?php
require_once "../../resources/autoload.php";
use UnityWebPortal\lib\UnitySite;
require_once $LOC_HEADER;
$invalid_ssh_dialogue = "<script type='text/javascript'>
alert('Invalid SSH key. Please verify your public key file is valid.');
</script>";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
switch ($_POST["form_type"]) {
case "addKey":
$added_keys = array();
switch ($_POST["add_type"]) {
case "paste":
$key = $_POST["key"];
if (UnitySite::testValidSSHKey($key)) {
array_push($added_keys, $key);
} else {
echo $invalid_ssh_dialogue;
}
break;
case "import":
$keyfile = $_FILES["keyfile"]["tmp_name"];
$key = file_get_contents($keyfile);
if (UnitySite::testValidSSHKey($key)) {
array_push($added_keys, $key);
} else {
echo $invalid_ssh_dialogue;
}
break;
case "generate":
array_push($added_keys, $_POST["gen_key"]);
break;
case "github":
$gh_user = $_POST["gh_user"];
if (empty($gh_user)) {
break;
}
$keys = UnitySite::getGithubKeys($gh_user);
foreach ($keys as $key) {
if (UnitySite::testValidSSHKey($key)) {
array_push($added_keys, $key);
}
}
break;
}
if (!empty($added_keys)) {
$added_keys = array_map(trim, $added_keys);
$totalKeys = array_merge($USER->getSSHKeys(), $added_keys);
$USER->setSSHKeys($totalKeys, $OPERATOR);
}
break;
case "delKey":
$keys = $USER->getSSHKeys();
unset($keys[intval($_POST["delIndex"])]); // remove key from array
$keys = array_values($keys);
$USER->setSSHKeys($keys, $OPERATOR); // Update user keys
break;
case "loginshell":
if ($_POST["shellSelect"] == "custom") {
$USER->setLoginShell($_POST["shell"], $OPERATOR);
} else {
$USER->setLoginShell($_POST["shellSelect"], $OPERATOR);
}
break;
case "pi_request":
if (!$USER->isPI()) {
if (!$SQL->requestExists($USER->getUID())) {
$USER->getPIGroup()->requestGroup($SEND_PIMESG_TO_ADMINS);
}
}
break;
case "account_deletion_request":
$hasGroups = count($USER->getGroups()) > 0;
if ($hasGroups) {
die();
break;
}
if (!$SQL->accDeletionRequestExists($USER->getUID())) {
$USER->requestAccountDeletion();
}
break;
}
}
?>
<h1>Account Settings</h1>
<hr>
<h5>Account Details</h5>
<p>
<strong>Username</strong> <code><?php echo $USER->getUID(); ?></code>
<br>
<strong>Organization</strong> <code><?php echo $USER->getOrg(); ?></code>
<br>
<strong>Email</strong> <code><?php echo $USER->getMail(); ?></code>
</p>
<hr>
<h5>Account Status</h5>
<?php
$isActive = count($USER->getGroups()) > 0;
$isPI = $USER->isPI();
if ($isPI) {
echo "<p>You are curently a <strong>principal investigator</strong> on the Unity Cluster</p>";
} elseif ($isActive) {
echo "<p>You are curently a <strong>user</strong> on the Unity Cluster</p>";
} else {
echo "<p>You are currently not assigned to any PI, and will be
<strong>unable to use the cluster</strong>. Go to the <a href='groups.php'>My PIs</a>
page to join a PI, or click on the button below if you are a PI</p>";
echo "<p>Students should not request a PI account.</p>";
}
if (!$isPI) {
if ($SQL->accDeletionRequestExists($USER->getUID())) {
echo
"<form action='' method='POST' id='piReq'
onsubmit='return confirm(\"Are you sure you want to request a PI account?\")'>
<input type='hidden' name='form_type' value='pi_request'>";
echo "<input type='submit' value='Request PI Account' disabled>";
echo
"<label style='margin-left: 10px'>
You cannot request PI Account while you have requested account deletion.
</label>";
echo "</form>";
} else {
echo
"<form action='' method='POST' id='piReq'
onsubmit='return confirm(\"Are you sure you want to request a PI account?\")'>
<input type='hidden' name='form_type' value='pi_request'>";
if ($SQL->requestExists($USER->getUID())) {
echo "<input type='submit' value='Request PI Account' disabled>";
echo "<label style='margin-left: 10px'>Your request has been submitted and is currently pending</label>";
} else {
echo "<input type='submit' value='Request PI Account'>";
}
echo "</form>";
}
}
?>
<hr>
<h5>SSH Keys</h5>
<?php
$sshPubKeys = $USER->getSSHKeys(); // Get ssh public key attr
if (count($sshPubKeys) == 0) {
echo "<p>You do not have any SSH public keys, press the button below to add one.</p>";
}
for ($i = 0; $sshPubKeys != null && $i < count($sshPubKeys); $i++) { // loop through keys
echo
"<div class='key-box'>
<textarea spellcheck='false' readonly>" . $sshPubKeys[$i] . "</textarea>
<form action='' id='del-" . $i . "'
onsubmit='return confirm(\"Are you sure you want to delete this SSH key?\");' method='POST'>
<input type='hidden' name='delIndex' value='$i'>
<input type='hidden' name='form_type' value='delKey'>
<input type='submit' value='×'>
</form>
</div>";
}
?>
<button type="button" class="plusBtn btnAddKey">+</button>
<hr>
<form action="" method="POST">
<input type="hidden" name="form_type" value="loginshell">
<select id="loginSelector" name= "shellSelect">
<option value="" disabled hidden>Select Login Shell...</option>
<?php
$cur_shell = $USER->getLoginShell();
$found_selector = false;
foreach ($CONFIG["loginshell"]["shell"] as $shell) {
if ($cur_shell == $shell) {
echo "<option selected>$shell</option>";
$found_selector = true;
} else {
echo "<option>$shell</option>";
}
}
if ($found_selector) {
echo "<option value='custom'>Custom</option>";
} else {
echo "<option value='custom' selected>Custom</option>";
}
?>
</select>
<?php
if ($found_selector) {
echo "<input id='customLoginBox' type='text'
placeholder='Enter login shell path (ie. /bin/bash)' name='shell'>";
} else {
echo "<input id='customLoginBox' type='text'
placeholder='Enter login shell path (ie. /bin/bash)' name='shell' value='$cur_shell'>";
}
?>
<br>
<input type='submit' value='Set Login Shell'>
</form>
<hr>
<h5>Account Deletion</h5>
<?php
$hasGroups = count($USER->getGroups()) > 0;
if ($hasGroups) {
echo "<p>You cannot request to delete your account while you are in a PI group.</p>";
} else {
echo
"<form action='' method='POST' id='accDel'
onsubmit='return confirm(\"Are you sure you want to request an account deletion?\")'>
<input type='hidden' name='form_type' value='account_deletion_request'>";
if ($SQL->accDeletionRequestExists($USER->getUID())) {
echo "<input type='submit' value='Request Account Deletion' disabled>";
echo "<label style='margin-left: 10px'>Your request has been submitted and is currently pending</label>";
} else {
echo "<input type='submit' value='Request Account Deletion'>";
}
echo "</form>";
}
?>
<hr>
<script>
$("button.btnAddKey").click(function() {
openModal("Add New Key", "<?php echo $CONFIG["site"]["prefix"]; ?>/panel/modal/new_key.php");
});
var customLoginBox = $("#customLoginBox");
if (customLoginBox.val() == "") {
// login box is empty, so we hide it by default
// if the login box had a value, that means it would be a custom shell
// and should not hide by default
customLoginBox.hide();
}
$("#loginSelector").change(function() {
var customBox = $("#customLoginBox");
if($(this).val() == "custom") {
customBox.show();
} else {
customBox.hide();
}
});
if ($("#loginSelector").val() == "custom") {
$("#customLoginBox").show();
}
</script>
<style>
.key-box {
position: relative;
width: auto;
height: auto;
max-width: 700px;
}
.key-box input[type=submit] {
position: absolute;
right: 0;
top: 0;
bottom: 0;
padding: 5px;
width: 32px;
border-radius: 0 3px 3px 0;
font-size: 20pt;
margin: 0;
}
.key-box textarea {
word-wrap: break-word;
word-break: break-all;
width: calc(100% - 44px);
border-radius: 3px 0 0 3px;
}
</style>
<?php
require_once $LOC_FOOTER;