-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmastodon.php
128 lines (112 loc) · 3.86 KB
/
mastodon.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
<?php
/**
* instances:
*
*
*/
use DecodoMastodonService\Controller\Router;
use Dotenv\Dotenv;
require_once __DIR__ . '/bootstrap.php';
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();
define('CURRENT_USER', ($_COOKIE['isAdmin'] ?? ''));
$cookiePath = "/";
$router = new Router();
$routingData = $router::route('/mastodon');
if ($routingData['method'] === 'GET') {
if ($routingData['viewport'] === 'login') {
$username = $_GET['user'] ?? '';
$password = $_GET['password'] ?? '';
if ($username === $_ENV['ADMIN'] && $password === $_ENV['PASSWORD']) {
$cookieExpire = time() + (60 * 60 * 24);
setcookie("isAdmin", $_GET['user'], $cookieExpire, $cookiePath);
header('location: ' . HOME_URL . '#logged-in');
exit;
}
header('location: ' . HOME_URL . '#login-failed');
exit;
} elseif ($routingData['viewport'] === 'logout') {
setcookie("isAdmin", "", time() - 3600, $cookiePath);
unset ($_COOKIE['isAdmin']);
header('location: ' . HOME_URL . '#logged-out');
exit;
}
if (file_exists(__DIR__ . '/Viewport/' . $routingData['viewport'] . '.php')) {
include_once __DIR__ . '/Viewport/' . $routingData['viewport'] . '.php';
exit;
}
}
include_once __DIR__ . '/Viewport/error.php';
exit;
//$requestAction = (isset($_GET['action']) && !empty($_GET['action']) ? trim($_GET['action']) : '');
//$requestId = (isset($_GET['id']) && (int)$_GET['id'] > 0 ? (int)$_GET['id'] : 0);
//$requestInstance = (isset($_GET['instance']) && !empty($_GET['instance']) ? trim($_GET['instance']) : '');
//
//if (isset($_GET['logout']) && !empty($_GET['logout'])) {
// $requestAction = 'logout';
//}
//
//if ($requestId > 0 && !empty($requestInstance)) {
// $requestAction = 'getInstance';
//}
//
//switch ($requestAction) {
// default:
// include_once __DIR__ . '/Viewport/mainList.php';
// break;
//
// case 'renewInstance':
// $helper = new MainHelper();
//
// if (isset($helper->instanceController::$instances[$requestInstance])) {
// $helper->instanceController->getCachedSingleInstanceTrends($helper->instanceController::$instances[$requestInstance], true);
// $helper->instanceController->getCachedSingleInstanceStats($helper->instanceController::$instances[$requestInstance], true);
// header('location: ' . HOME_URL . '#renewInstance-' . $requestInstance);
// exit;
// }
//
// header('location: ' . HOME_URL . '#renewInstance-' . $requestInstance . '-fail');
// exit;
// break;
//
// case 'logout':
// setcookie("isAdmin", "", time() - 3600, $cookiePath);
// unset ($_COOKIE['isAdmin']);
// header('location: /mastodon/#logout');
// exit;
// break;
//
// case 'login':
// $username = $_GET['user'] ?? '';
// $password = $_GET['password'] ?? '';
// if ($username === $_ENV['ADMIN'] && $password === $_ENV['PASSWORD']) {
// $cookieExpire = time() + (60 * 60 * 24);
// setcookie("isAdmin", $_GET['user'], $cookieExpire, $cookiePath);
// header('location: ' . HOME_URL . '#logged-in');
// exit;
// }
// header('location: ' . HOME_URL . '#login-failed');
// exit;
//
// case 'stats':
// include_once __DIR__ . '/Viewport/getInstanceStats.php';
// break;
//
// case 'getInstance':
// include_once __DIR__ . '/Viewport/getInstance.php';
// break;
//
// case 'test':
//
// echo '<pre>' . print_r([
// '' => $_ENV,
// ], 1) . __FILE__ . ' ' . __LINE__ . '</pre>';
// exit;
// break;
//
// case 'reset':
// $helper = new MainHelper();
// $helper->getTrendCollection(true);
// header('location: ' . HOME_URL . '#reset');
// exit;
//}