-
Notifications
You must be signed in to change notification settings - Fork 69
/
index.php
292 lines (255 loc) · 8.94 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
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
<?php
require_once dirname(__FILE__) . '/php/vendor/autoload.php';
require_once dirname(__FILE__) . "/php/webApp.php";
require_once dirname(__FILE__) . '/php/util.php';
write_log("-------NEW REQUEST RECEIVED-------", "ALERT");
scriptDefaults();
$defaults = checkDefaults();
$forceSSL = $defaults['forceSSL'] ?? false;
if ($forceSSL === "false") $forceSSL = false;
write_log("ForceSSL is set to $forceSSL");
if ((empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off") && $forceSSL) {
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
write_log("Force is on, redirecting to: $redirect","ERROR");
if (isDomainAvailable($redirect)) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();
}
}
if (!session_started()) {
session_start();
}
writeSessionArray($defaults);
$GLOBALS['time'] = microtime(true);
if (substr_count($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") && hasGzip()) ob_start("ob_gzhandler"); else ob_start();
$messages = checkFiles();
if (isset($_GET['logout'])) {
clearSession();
$url = fetchUrl();
echo "<script language='javascript'>
document.location.href='$url';
</script>";
}
checkUpdate();
?>
<!doctype html>
<html>
<head>
<title>Flex TV</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Plex Voice Automation for Google Assistant">
<meta name="msapplication-config" content="./img/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="apple-touch-icon" sizes="180x180" href="./img/apple-icon.png">
<link rel="icon" type="image/png" href="./img/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="./img/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="./manifest.json">
<link rel="mask-icon" href="./img/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="./img/favicon.ico">
<style>
.fade-in{
-webkit-animation: fade-in 2s ease;
-moz-animation: fade-in ease-in-out 2s both;
-o-animation: fade-in ease-in-out 2s both;
animation: fade-in 2s ease;
visibility: visible;
-webkit-backface-visibility: hidden;
}
@-webkit-keyframes fade-in{0%{opacity:0;} 100%{opacity:1;}}
@-moz-keyframes fade-in{0%{opacity:0} 100%{opacity:1}}
@-o-keyframes fade-in{0%{opacity:0} 100%{opacity:1}}
@keyframes fade-in{0%{opacity:0} 100%{opacity:1}}
</style>
<link rel="stylesheet" href="css/loader_main.css">
<link href="./css/lib/dist/critical.css" rel="stylesheet">
</head>
<body style="background-color:black">
<div id="loader-wrapper">
<div id="loader"></div>
<div class="loader-section section-left"></div>
<div class="loader-section section-right"></div>
</div>
<div id="bgwrap">
</div>
<script>
<?php echo fetchBackground();?>
</script>
<div id="bodyWrap">
<?php
$code = false;
foreach ($_GET as $key => $value) {
//write_log("hey, got a key named $key with a value of $value.");
if ($key == "pinID") {
write_log("We have a PIN: $value");
$code = $value;
}
}
$apiToken = $_SESSION['apiToken'] ?? false;
$getToken = $_GET['apiToken'] ?? false;
$user = $token = false;
if ($code || $apiToken || $getToken) {
$GLOBALS['login'] = false;
$result = false;
if (!$apiToken) $result = plexSignIn($code);
if ($getToken) $user = verifyApiToken($_GET['apiToken']);
if ($user) $token = $user['apiToken'] ?? false;
if ($token) $apiToken = $token;
if ($result || $apiToken) {
if ($result == "Not allowed.") {
showError();
} else {
define('LOGGED_IN', true);
require_once dirname(__FILE__) . '/php/body.php';
write_log("Making body!");
$defaults['token'] = $token;
$bodyData = makeBody($defaults);
$body = $bodyData[0];
$_SESSION['theme'] = $bodyData[1];
echo $body;
}
}
} else {
showLogin();
}
$execution_time = (microtime(true) - $GLOBALS['time']);
function showLogin() {
$GLOBALS['login'] = true;
echo '
<div class="loginBox">
<div class="login-box">
<div class="card loginCard">
<div class="card-block">
<b><h3 class="loginLabel card-title">Welcome to Flex TV!</h3></b>
<img class="loginLogo" src="./img/phlex-med.png" alt="Card image">
<h6 class="loginLabel card-subtitle text-muted">Please log in below to begin.</h6>
</div>';
$rev = checkRevision(true);
if ($rev) echo "<div id='revision' class='meta'>Revision: $rev</div>";
echo ' <div class="card-block">
<div id="loginForm">
<button class="btn btn-raised btn-primary" id="plexAuth">DO IT!</button>
<br><br>
<a href="http://phlexchat.com/Privacy.html" class="card-link">Privacy Policy</a>
</div>
</div>
</div>
</div>' .
headerhtml();
}
function showError() {
write_log("A new user tried to sign in, but new users are not allowed!","ERROR");
$GLOBALS['login'] = true;
echo '
<div class="loginBox">
<div class="login-box">
<div class="card loginCard">
<div class="card-block">
<b><h3 class="loginLabel card-title">NOT ALLOWED!</h3></b>
<img class="loginLogo" src="./img/phlex-med.png" alt="Card image">
<h6 class="loginLabel card-subtitle text-muted">Sorry, the administrator has disabled new logins.</h6>
</div>
</div>
</div>' .
headerhtml();
}
?>
</div>
<div class="modal fade" id="alertModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="alertTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="alertBody">
<p>Modal body text goes here.</p>
</div>
</div>
</div>
</div>
<meta id="messages" data-array="<?php if (count($messages)) echo urlencode(json_encode($messages)); ?>"/>
<script type="text/javascript" src="./js/lib/dist/ui.js"></script>
<script type="text/javascript" src="./js/lib/dist/support.js" async></script>
<link href="./css/lib/dist/support.css" rel="stylesheet">
<link href="./css/main.css" rel="stylesheet">
<?php if ($_SESSION['theme']) echo '<link href="./css/dark.css" rel="stylesheet">'.PHP_EOL?>
<link rel="stylesheet" media="(max-width: 400px)" href="css/main_max_400.css">
<link rel="stylesheet" media="(max-width: 600px)" href="css/main_max_600.css">
<link rel="stylesheet" media="(min-width: 600px)" href="css/main_min_600.css">
<link rel="stylesheet" media="(min-width: 2000px)" href="css/main_min_2000.css">
<?php
if ($GLOBALS['login']) {
echo '<script type="text/javascript" src="./js/login.js" async></script>';
} else {
echo '<script type="text/javascript" src="./js/main.js" async></script>';
}
?>
<script>
var noWorker = true;
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js').then(function (registration) {
console.log("Service worker registered.");
noWorker = false;
}).catch(function (err) {
console.log('ServiceWorker registration failed: ', err);
});
}
if (typeof window.history.pushState === 'function') {
window.history.pushState({}, "Hide", '<?php echo $_SERVER['PHP_SELF'];?>');
}
var messageBox = [];
// We call this inside the login window if necessary, or main.js. Ignore lint warnings.
function loopMessages(messages) {
console.log("Function fired.");
var messageArray = messages;
messageBox = messages;
$.each(messageArray, function () {
if (messageArray[0] === undefined) return false;
var keepLooping = showMessage(messageArray[0].title, messageArray[0].message, messageArray[0].url);
messageBox.splice(0, 1);
if (!keepLooping) return false;
})
}
function showMessage(title, message, url) {
if (Notification.permission === 'granted') {
var notification = new Notification(title, {
icon: './img/avatar.png',
body: message
});
if (url) {
notification.onclick = function () {
window.open(url);
};
}
return true;
} else {
if (url !== "") {
message = "<a href='" + url + "'>"+message+"</a>";
} else {
message = "<p>" + message + "</p>";
}
if (Notification.permission !== 'denied') {
Notification.requestPermission().then(function (result) {
if ((result === 'denied') || (result === 'default')) {
$('#alertTitle').text(title);
$('#alertBody').html(message);
$('#alertModal').modal('show');
}
});
} else {
$('#alertTitle').text(title);
$('#alertBody').html(message);
$('#alertModal').modal('show');
}
return false;
}
}
</script>
</body>
</html>