-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodcp.php
178 lines (178 loc) · 6.92 KB
/
modcp.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
<?php
/*
* /=======================================================\
* | Panchat v2.0.0 |
* | Copyright (c) P7COMunications LLC 2021 - PANCHO7532 |
* |=======================================================/
* |-> Purpose: Moderation Control Panel
* ---------------------------------------------------------
*/
include 'config.inc.php';
$dataModel = array(
"messages" => array()
);
$moderationModel = array(
"bannedNicknames" => array(),
"bannedIPs" => array(),
"allowedIPsCLS" => array()
);
function xorCrypto($key, $data) {
$result = "";
for($a = 0, $b = 0; $a < strlen($data); $a++, $b++) {
if($b >= strlen($key)) { $b = 0; }
$result .= $data{$a} ^ $key{$b};
}
return $result;
}
function basicFileCheck($filedir, $filedb, $filemod, $dataModel, $moderationModel) {
if(!file_exists($filedir)) {
//checking if data folder exists for begin with
mkdir($filedir);
}
if(!file_exists($filedb)) {
//checking if message database exists
$fileHandler = fopen($filedb, "w");
fwrite($fileHandler, json_encode($dataModel));
fclose($fileHandler);
}
if(!file_exists($filemod)) {
$fileHandler = fopen($filemod, "w");
fwrite($fileHandler, json_encode($moderationModel));
fclose($fileHandler);
}
}
basicFileCheck($filedir, $filedb, $filemod, $dataModel, $moderationModel);
if(isset($_COOKIE['username']) && isset($_COOKIE['passwd'])) {
$username = htmlspecialchars($_COOKIE['username']);
$password = htmlspecialchars($_COOKIE['passwd']);
if(md5(base64_encode(xorCrypto($xorKey, $u1a))) == $username && md5(base64_encode(xorCrypto($xorKey, $u1b))) == $password) {
echo "<!DOCTYPE html><html><head><title>ModCP - Panchat</title></head><body><fieldset><legend>Welcome, $u1a - <a href='modAuth.php?logout=1'>Logout</a></legend>";
} else {
header("Location: error.html");
}
} else {
header("Location: error.html");
}
//all authenticated actions for the panel should go after this line
if($_SERVER["REQUEST_METHOD"] == "POST") {
// it's a POST request
if(isset($_POST["modAction"]) && isset($_POST["modActionValue"])) {
if($_POST["modActionValue"] == "") {
header("Location: modcp.php");
}
$tmpModData = json_decode(file_get_contents($filemod), true);
switch($_POST["modAction"]) {
case "banNick":
//action
$tmpModActionData = base64_encode(xorCrypto($xorKey, htmlspecialchars($_POST["modActionValue"])));
array_push($tmpModData["bannedNicknames"], $tmpModActionData);
$fileHandler = fopen($filemod, "w");
fwrite($fileHandler, json_encode($tmpModData));
fclose($fileHandler);
break;
case "banIP":
//action
$tmpModActionData = base64_encode(xorCrypto($xorKey, htmlspecialchars($_POST["modActionValue"])));
array_push($tmpModData["bannedIPs"], $tmpModActionData);
$fileHandler = fopen($filemod, "w");
fwrite($fileHandler, json_encode($tmpModData));
fclose($fileHandler);
break;
case "allowIPC":
//action
$tmpModActionData = base64_encode(xorCrypto($xorKey, htmlspecialchars($_POST["modActionValue"])));
array_push($tmpModData["allowedIPsCLS"], $tmpModActionData);
$fileHandler = fopen($filemod, "w");
fwrite($fileHandler, json_encode($tmpModData));
fclose($fileHandler);
break;
default:
break;
}
}
}
if(isset($_GET["removeNick"]) && $_GET["removeNick"] != "") {
$tmpModData = json_decode(file_get_contents($filemod), true);
$tmpModData["bannedNicknames"] = array_diff($tmpModData["bannedNicknames"], array($_GET["removeNick"]));
$fileHandler = fopen($filemod, "w");
fwrite($fileHandler, json_encode($tmpModData));
fclose($fileHandler);
}
if(isset($_GET["removeIP"]) && $_GET["removeIP"] != "") {
$tmpModData = json_decode(file_get_contents($filemod), true);
$tmpModData["bannedIPs"] = array_diff($tmpModData["bannedIPs"], array($_GET["removeIP"]));
$fileHandler = fopen($filemod, "w");
fwrite($fileHandler, json_encode($tmpModData));
fclose($fileHandler);
}
if(isset($_GET["removeIPc"]) && $_GET["removeIPc"] != "") {
$tmpModData = json_decode(file_get_contents($filemod), true);
$tmpModData["allowedIPsCLS"] = array_diff($tmpModData["allowedIPsCLS"], array($_GET["removeIPc"]));
$fileHandler = fopen($filemod, "w");
fwrite($fileHandler, json_encode($tmpModData));
fclose($fileHandler);
}
?>
<form action="modcp.php" method="POST">
<p>Banned nicknames:</p>
<ul>
<?php
include 'config.inc.php';
$nickDB = json_decode(file_get_contents($filemod), true);
if(sizeof($nickDB["bannedNicknames"]) == 0) {
echo "<li>[No banned nicknames]";
} else {
foreach($nickDB["bannedNicknames"] as $nicks) {
$tmpnick = xorCrypto($xorKey, base64_decode($nicks));
echo "<li>{$tmpnick} <a href=\"modcp.php?removeNick={$nicks}\">[Remove]</a></li>";
}
}
?>
</ul>
<p>Banned IPs:</p>
<ul>
<?php
include 'config.inc.php';
$ipDB = json_decode(file_get_contents($filemod), true);
if(sizeof($ipDB["bannedIPs"]) == 0) {
echo "<li>[No banned IPs]";
} else {
foreach($ipDB["bannedIPs"] as $ips) {
$tmpip = xorCrypto($xorKey, base64_decode($ips));
echo "<li>{$tmpip} <a href=\"modcp.php?removeIP={$ips}\">[Remove]</a></li>";
}
}
?>
</ul>
<p>Allowed IPs for clear chat:</p>
<ul>
<?php
include 'config.inc.php';
$ipcDB = json_decode(file_get_contents($filemod), true);
if($lockclschat == "disable") {
echo "[WARNING] 'lockclschat' variable is set to \"disabled\", values in this list will not be used.";
}
if(sizeof($ipDB["allowedIPsCLS"]) == 0) {
echo "<li>[No whitelisted IPs]";
} else {
foreach($ipcDB["allowedIPsCLS"] as $ipc) {
$tmpipc = xorCrypto($xorKey, base64_decode($ipc));
echo "<li>{$tmpipc} <a href=\"modcp.php?removeIPc={$ipc}\">[Remove]</a></li>";
}
}
?>
</ul>
<p>Add a record:</p>
Action: <select name="modAction" id="modAction">
<option value="banNick" selected>Ban Nickname</option>
<option value="banIP">Ban IP</option>
<option value="allowIPC">Allow IP (for clear chat)</option>
</select>
<br>
Value: <input type="text" autocomplete="off" name="modActionValue"/>
<input type="submit" value="Submit"/>
<br><a href="index.php">Go to the main page</a>
</form>
</fieldset>
</body>
</html>