forked from Grade-Notifier/GN-Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
240 lines (215 loc) · 10.1 KB
/
index.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
<?php
$arr = array();
$status = '';
$title = '';
$message = '';
$landing = !isset($_POST["submit"]);
function display()
{
global $arr, $status, $title, $message;
$cmd = '';
$cmd = 'python3 src/core/initializegn.py --username=' . escapeshellcmd($_POST["username"]) . ' --password=' . escapeshellcmd($_POST["password"]) . ' --school=' . escapeshellcmd($_POST["school"]) . ' --phone=' . escapeshellcmd($_POST["phone"]);
$message = exec($cmd, $arr);
for ($x = 0; $x < count($arr); $x++) {
if (strpos($arr[$x], 'RENDER::') !== false) {
// Remove RENDER::
$worend = str_replace("RENDER::", "", $arr[$x]);
// Parse the text to get the status and title
//
// Regex matches the following:
// --<key>="<value>" (Will match)
// --<key>=<value> (Will not match)
//
// Contain a single group to capture the
// <value>
preg_match_all("/--?[^=\s]+?=\"([^\"]+)\"?/", $worend, $matches);
$val = $matches[1];
$status = $val[0];
$title = $val[1];
$x++;
// Continue eating until we see the end indicator
// denoted by [END]. This is an extra precaution as
// it should always end with the last item
// in the array
while (strpos($arr[$x], '[END]') === false) {
$message .= nl2br(" $arr[$x]\r\n");
$x++;
}
$message = str_replace("[END]", "", $message);
// We only care about the first returned
// error or success message. Break out early
// to avoid overwritting
break;
}
}
}
if (isset($_POST["submit"])) {
display();
}
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CUNY Grade Notifier</title>
<link type="text/css" rel="stylesheet" href="src/site/site-assets/css/styles.css">
<link href="https://fonts.googleapis.com/css?family=Roboto+Slab:400,700" rel="stylesheet">
<!-- Favicon and icons for other platforms -->
<link rel="apple-touch-icon" sizes="180x180" href="/src/site/site-assets/icons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/src/site/site-assets/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/src/site/site-assets/icons/favicon-16x16.png">
<link rel="manifest" href="/src/site/site-assets/icons/site.webmanifest">
<link rel="mask-icon" href="/src/site/site-assets/icons/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="/src/site/site-assets/icons/favicon.ico">
<meta name="apple-mobile-web-app-title" content="Grade Notifier">
<meta name="application-name" content="Grade Notifier">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-config" content="/src/site/site-assets/icons/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
<script src="src/helper/security/forge/dist/forge.js"></script>
</head>
<body>
<div class="wrapper">
<div class="column column--left">
<?php
if (!$landing) :
if ($status == "ok") :
?>
<img class="status-symbol" alt="Check" src="Assets/site/Check.svg">
<?php
elseif ($status == "error") :
?>
<img class="status-symbol" alt="Exclamation mark" src="Assets/site/Exclamation.svg">
<?php
endif;
endif;
?>
<h1 class="callout">
<?php
if ($landing) :
?>
Get a text when you<br>get your grades!
<?php
elseif ($title) :
echo $title;
endif;
?>
</h1>
<?php
if ($landing) :
?>
<script type="text/javascript">
function encryptPassword() {
let rsa = forge.pki.rsa;
let publicKeyEncoded = <?php echo '`'.file_get_contents("../../private/keys/public.pem").'`'?>;
let publicKey = forge.pki.publicKeyFromPem(publicKeyEncoded);
let ciphertext = publicKey.encrypt(document.userform.password.value, 'RSA-OAEP', {
md: forge.md.sha256.create(),
mgf1: { md: forge.md.sha1.create() }
});
document.userform.password.value = forge.util.encode64(ciphertext)
}
</script>
<div class="callout__divider"></div>
<form name="userform" action=<?php echo $_SERVER['PHP_SELF']; ?> method=POST onSubmit="encryptPassword()">
<input class="input" type="text" name="username" placeholder="Username" required><span class="username-posttext">@login.cuny.edu</span>
<br>
<input class="input input--full-width" type="password" name="password" placeholder="Password" required>
<br>
<!-- <label for="school">School:</label> -->
<select class="input input--select input--full-width" id="school" name="school" required>
<option value="BAR01" disabled>Baruch College</option>
<option value="BMC01">Borough of Manhattan CC</option>
<option value="BCC01">Bronx CC</option>
<option value="BKL01">Brooklyn College</option>
<option value="CTY01">City College</option>
<option value="CSI01">College of Staten Island</option>
<option value="GRD01">Graduate Center</option>
<option value="NCC01">Guttman CC</option>
<option value="HOS01">Hostos CC</option>
<option value="HTR01">Hunter College</option>
<option value="JJC01">John Jay College</option>
<option value="KCC01">Kingsborough CC</option>
<option value="LAG01">LaGuardia CC</option>
<option value="LEH01">Lehman College</option>
<option value="MHC01">Macaulay Honors College</option>
<option value="MEC01">Medgar Evers College</option>
<option value="NYT01">NYC College of Technology</option>
<option value="QNS01" selected>Queens College</option>
<option value="QCC01">Queensborough CC</option>
<option value="SOJ01">School of Journalism</option>
<option value="SLU01">School of Labor&Urban Studies</option>
<option value="LAW01">School of Law</option>
<option value="MED01">School of Medicine</option>
<option value="SPS01">School of Professional Studies</option>
<option value="SPH01">School of Public Health</option>
<option value="UAPC1">University Processing Center</option>
<option value="YRK01">York College</option>
</select>
<br>
<input class="input input--full-width" type="text" name="phone" placeholder="Phone Number" required>
<br>
<input class="submit" type="submit" name="submit" value="Text me!">
</form>
<?php
else :
if ($status == "ok") :
?>
<div class="confirm-message__wrapper">
<?php
echo "<p class=\"confirm-message__text\">";
echo $message;
echo "</p>";
?>
</div>
<?php
endif;
if ($status == "error") :
?>
<div class="confirm-message__wrapper">
<?php
echo "<p class=\"confirm-message__text\">";
echo $message;
echo "</p>";
?>
</div>
<form method="get">
<input class="submit" type="submit" value="Start over">
</form>
<?php
endif;
endif;
?>
<div class="credits">
<h3 class="credit">Made with ❤️ by Ehud Adler</h3>
<h4 class="credit">Big thanks to @ericshermancs</h4>
<h4 class="credit">Also thank you to our server guys @sommerbenjamin and @michaelkolber</h4>
<h4 class="credit">Please see our <a href="https://github.com/Grade-Notifier/GN-Core/blob/master/CONTRIBUTORS.md" title="Contributors">full list of contributors</a>.</h4>
</div>
</div>
<div class="column column--right">
<?php
if ($landing) :
?>
<img class="image" alt="Phone" src="Assets/site/undraw_mobile_life_381t_edited.svg">
<?php
elseif ($status == "ok") :
?>
<img class="image" alt="Phone with check mark" src="Assets/site/undraw_order_confirmed_1m3v.svg">
<?php
elseif ($status == "error") :
?>
<img class="image" alt="Phone with exclamation mark" src="Assets/site/undraw_order_confirmed_1m3v_and_heartbroken_cble.svg">
<?php
else :
?>
<h1>Something went really really wrong... Please let us know and we will fix it ASAP</h1>
<img class="image" alt="Phone with exclamation mark" src="Assets/site/undraw_order_confirmed_1m3v_and_heartbroken_cble.svg">
<?php
endif
?>
</div>
</div>
</body>
</html>