-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
67 lines (65 loc) · 2.56 KB
/
Copy pathadmin.php
File metadata and controls
67 lines (65 loc) · 2.56 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
<?php
/* Global variables in use:
$isTokenOk --> bool of NONCE and session checks
$tok --> string, new CSRF protection token, to send back to client to use in future requests
$nthReq --> number, the number of requests already made using the current session
$lastTok --> number, previous CSRF Token number (to check in case of page refresh if neccessary)
$isUserLogedIn --> bool, the result of Persona check, if the user is loged in or not (checked on every and each request)
$isAjax --> bool, shows if the request is AJAX or page request.
*/
error_reporting(-1);
include_once ("mimses.php");
// if $beingParanoid set to true, server will verify the user auth in each request with Persona servers, TODO: otherwise it will be checked once per each 12 requests
$beingParanoid = false;
//TODO: keep email adress in BCRYPTED format only
$adminEmail = 'mim3dot@gmail.com';
$admin_page_address = findAdminPageAddress();
// this variable will keep the AJAX requested action name (sent by client);
$act = NULL;
// this var will keep the command we want to send to client
$commandToClient = NULL;
include_once ("persona.php");
include_once ("isajax.php");
include_once ("views.php");
//include_once ("debug.php");
// this is the array var that will carry everything that needs to be sent back to client
$jsonArray = [];
if (!$isAjax) {
echo $header . $login . $footer;
} else {
isset($_POST['act']) ? $act = $_POST['act'] : $act = NULL;
$jsonArray['Client:'] = $_POST;
if ($isTokenOk) {
checkPersona();
if ($isUserLogedIn) {
$jsonArray['snip'] = $view_admin_page;
$commandToClient = 'BuildEditPage';
jsonAnswer();
} else {
jsonAnswer();
}
} else {
echo 'You are a BAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD persone!!!';
die;
}
}
/*************************************************** FUNCTIONS: **************************************************/
function jsonAnswer() {
global $jsonArray;
global $isTokenOk;
global $isUserLogedIn;
global $tok;
global $commandToClient;
$jsonArray['logedIn'] = $isUserLogedIn;
$jsonArray['tokenStatus'] = $isTokenOk;
$jsonArray['tok'] = $tok;
$jsonArray['cmd'] = $commandToClient;
echo json_encode($jsonArray);
}
function findAdminPageAddress() {
$adadd = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://';
$adadd.= $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
return $adadd;
}
/********************************************************** VIEW CONSTRUCTORS ********************************************/
?>