forked from bbdoc/PoracleWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.php
133 lines (105 loc) · 3.77 KB
/
session.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
<?php
include "./config.php";
include "./include/functions.php";
if(session_status() == PHP_SESSION_NONE){
session_start();
}
$dbnames = explode(",", $dbname);
foreach ($dbnames as &$db) {
$conn = new mysqli($dbhost.":".$dbport, $dbuser, $dbpass, $db);
// Check connection
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: " . $conn->connect_error;
exit();
}
$sql = "SELECT * from humans WHERE id = '".$_SESSION['id']."'";
$result = $conn->query($sql) or die(mysqli_error($conn));
if ( $result->num_rows > 0 ) {
$_SESSION['dbname'] = $db;
}
}
// Set Admin Variables
if (isset($admin_id)) {
$admins = explode(",", $admin_id);
foreach ($admins as &$admin) {
if ($_SESSION['id'] == $admin)
{
$_SESSION['admin_id'] = $_SESSION['id'];
$_SESSION['admin_username'] = $_SESSION['username'];
$_SESSION['admin_dbname'] = $_SESSION['dbname'];
$_SESSION['admin_type'] = $_SESSION['type'];
}
}
}
// Get Config Items from API and Store in Session Variables
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"X-Poracle-Secret: $api_secret\r\n"
)
);
$context = stream_context_create($opts);
// Check that API is Running fine
if (!$api = @file_get_contents("$api_address/api/config/poracleWeb", false, $context) )
{
if (!isset($_SESSION['admin_id']))
{
session_destroy();
header("Location: $redirect_url?return=error_no_api");
exit();
} else
{
$no_api = "True";
}
}
// Get Config Items from API
$config = @file_get_contents("$api_address/api/config/poracleWeb", false, $context);
$json = json_decode($config, true);
if ( $json['status']=="ok" ) {
$_SESSION['locale'] = $json['locale'];
$_SESSION['server_locale'] = $json['locale'];
$_SESSION['providerURL'] = $json['providerURL'];
$_SESSION['staticKey'] = $json['staticKey'][0];
$_SESSION['pvpFilterMaxRank'] = $json['pvpFilterMaxRank'];
$_SESSION['pvpFilterGreatMinCP'] = $json['pvpFilterGreatMinCP'];
$_SESSION['pvpFilterUltraMinCP'] = $json['pvpFilterUltraMinCP'];
$_SESSION['defaultTemplateName'] = $json['defaultTemplateName'];
$_SESSION['everythingFlagPermissions'] = $json['everythingFlagPermissions'];
$_SESSION['maxDistance'] = $json['maxDistance'];
$_SESSION['user_admins'] = array_merge($json['admins']['discord'],$json['admins']['telegram']);
} else if (!isset($_SESSION['admin_id'])) {
session_destroy();
header("Location: $redirect_url?return=error_api_nok");
exit();
} else {
$no_api = "True";
}
// Get Areas from API
$areas = @file_get_contents("$api_address/api/humans/".$_SESSION['id'], false, $context);
$json = json_decode($areas, true);
if ( $json['status']=="ok" ) {
$_SESSION['areas'] = $json['areas'];
} else if ( $json['message'] == "User not found" ) {
header("Location: $redirect_url?$redirect_page");
exit();
} else if (!isset($_SESSION['admin_id'])) {
session_destroy();
header("Location: $redirect_url?return=error_api_nok");
exit();
} else {
$no_api = "True";
}
// Get Delegated Admin from API
$delegated = @file_get_contents("$api_address/api/humans/".$_SESSION['id']."/getAdministrationRoles", false, $context);
$json = json_decode($delegated, true);
$_SESSION['delegated_channels'] = $json['admin'];
$_SESSION['delegated_count'] = count($json['admin']['discord']['channels']) + count($json['admin']['discord']['webhooks']) + count($json['admin']['telegram']['channels']);
if ( $_SESSION['delegated_count'] > 0 || isset($_SESSION['user_admins']) )
{
$_SESSION['delegated_id'] = $_SESSION['id'];
$_SESSION['delegated_username'] = $_SESSION['username'];
$_SESSION['delegated_dbname'] = $_SESSION['dbname'];
$_SESSION['delegated_type'] = $_SESSION['type'];
}
set_locale();