forked from serphacker/serposcope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxies.php
330 lines (289 loc) · 11.7 KB
/
proxies.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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<?php
/**
* Serposcope - An open source rank checker for SEO
* http://serphacker.com/serposcope/
*
* @link http://serphacker.com/serposcope Serposcope
* @author SERP Hacker <pierre@serphacker.com>
* @contributor 512Banque https://twitter.com/512banque
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode CC-BY-NC-SA
*
* Redistributions of files must retain the above notice.
*/
if (!file_exists('inc/config.php')) {
header("Location: install/", TRUE, 302);
die();
}
require('inc/config.php');
include('inc/define.php');
include('inc/common.php');
$err = null;
if (!empty($_POST)) {
if (isset($_POST['list-url-proxies'])) {
$options['general']['proxies_list_url'] = trim($_POST['list-url-proxies']);
if($options['general']['proxies_list_url'] == ''){
$db->query("DELETE FROM `".SQL_PREFIX."option` WHERE name = 'general_proxies_list_url'");
}else{
$value = addslashes($options['general']['proxies_list_url']);
$db->query("INSERT INTO `".SQL_PREFIX."option` VALUES ".
"('general_proxies_list_url', '".$value."') ".
"ON DUPLICATE KEY UPDATE value = '".$value."' "
);
}
} else {
// we build the array of proxies
$final = array();
if (!empty($_POST['bulkimport-proxies'])) { // we want to import proxies
$lines = explode("\n", $_POST['bulkimport-proxies']); // we explode with newlines
$linecount = 0;
foreach ($lines as $line) {
++$linecount;
//$line = ltrim($line); //only ltrim
$line = trim($line); // fuck password with space
// check if the line is not empty
if (!empty($line)) {
//we explode again to split with '#'
$proxy_line = explode('#', $line);
if (empty($proxy_line[0])) { // line with single :
$err = "bulkimport error line $linecount : each line should have at least an ip address";
break;
}
$final[] = array(
'type' => $_POST['bulkimport-type'], // sanity check done later
'ip' => $proxy_line[0],
'port' => isset($proxy_line[1]) ? intval($proxy_line[1]) : null,
'user' => isset($proxy_line[2]) ? $proxy_line[2] : null,
'password' => isset($proxy_line[3]) ? $proxy_line[3] : null,
);
}
}
} else {
$final[] = array(
'type' => isset($_POST['type']) ? $_POST['type'] : null,
'ip' => isset($_POST['ip']) ? $_POST['ip'] : null,
'port' => isset($_POST['port']) ? intval($_POST['port']) : null,
'user' => isset($_POST['user']) ? $_POST['user'] : null,
'password' => isset($_POST['password']) ? $_POST['password'] : null
);
}
if ($err == null) {
if (empty($final)) {
$err = "bulkimport error: each line should have at least an ip address";
} else {
$q = "INSERT INTO `" . SQL_PREFIX . "proxy`(type,ip,port,user,password) VALUES ";
foreach ($final as $proxy) {
// we want to add them 1 by 1
if (!isset($proxy['ip'])) {
$err = "ip is mandatory";
} else {
switch ($proxy['type']) {
case "http":
case "socks":
if (!isset($proxy['port']) || !is_numeric($proxy['port'])) {
$err = "invalid port <strong>" . h8(isset($proxy['port']) ? $proxy['port'] : "") . "</strong> for <strong>" . h8($proxy['ip']) . "</strong>";
}
break;
case "iface":
if (!empty($proxy['port']) || !empty($proxy['user']) || !empty($proxy['password'])) {
$err = "iface proxy doesn't need port/username or password";
}
break;
default:
$err = "invalid proxy type";
}
if ($err != null) {
break;
}
$q.="\n(";
$q.="'" . addslashes($proxy['type']) . "',";
$q.="'" . addslashes($proxy['ip']) . "',";
$q.= (empty($proxy['port']) ? "NULL" : intval($proxy['port'])) . ",";
$q.= (empty($proxy['user']) ? "NULL" : "'" . addslashes($proxy['user']) . "'") . ",";
$q.= (empty($proxy['password']) ? "NULL" : "'" . addslashes($proxy['password']) . "'");
$q.="),";
}
}
//save in database if no error
if ($err == null) {
$q = trim($q, ",");
if (!$db->query($q)) {
$err = "sql error $q";
}
}
}
}
}
}
$dbproxies = load_proxies();
include('inc/header.php');
if ($err != null) {
echo "<div class='alert alert-error' >$err</div>";
}
?>
<script>
bAllSelected = false;
$(function() {
$('#selectallproxy').click(function() {
var selected = $('[name="idproxy[]"]');
if (bAllSelected) {
selected.attr('checked', false);
} else {
selected.attr('checked', true);
}
bAllSelected = !bAllSelected;
});
$('#btndeleteproxy').click(function() {
var selected = $('[name="idproxy[]"]:checked');
if (selected.length === 0) {
alert("no proxy selected");
return;
}
var proxiesId = "";
selected.each(function(i, item) {
proxiesId += "&id[]=" + item.value;
});
$.ajax({
type: "POST",
url: "ajax.php",
data: "action=deleteproxy" + proxiesId
}).done(function(rawdata) {
data = JSON.parse(rawdata);
if (data !== null) {
if (data.deleted === true) {
$('[name="idproxy[]"]:checked').parent().parent().remove();
} else {
alert("Can't delete proxies");
}
} else {
alert("unknow error [1]");
}
});
});
$('#btndeleteoffproxy').click(function() {
var selected = $('[state="ERR"]');
if (selected.length === 0) {
alert("no proxy selected");
return;
}
var proxiesId = "";
selected.each(function(i, item) {
proxiesId += "&id[]=" + item.value;
});
$.ajax({
type: "POST",
url: "ajax.php",
data: "action=deleteproxy" + proxiesId
}).done(function(rawdata) {
data = JSON.parse(rawdata);
if (data !== null) {
if (data.deleted === true) {
$('[state="ERR"]').parent().parent().remove();
} else {
alert("Can't delete proxies");
}
} else {
alert("unknow error [1]");
}
});
});
$('#btncheckproxy').click(function() {
var selected = $('[name="idproxy[]"]:checked');
if (selected.length === 0) {
alert("no proxy selected");
return; }
selected.each(function(i, item) {
$.ajax({ type: "POST",
url: "ajax.php",
data: "action=checkproxy&id=" + item.value
}).done(function(rawdata) {
data = JSON.parse(rawdata);
if (data !== null) {
if (data.result === "ok") {
$('#status' + item.value).html("OK");
$('#status' + item.value).css("color", "green");
$('#chkprx_' + item.value).attr("state","OK");
} else {
$('#status' + item.value).html("ERR");
$('#status' + item.value).css("color", "red");
$('#chkprx_' + item.value).attr("state","ERR");
}
} else {
alert("unknow error [1]");
}
});
});
});
});
</script>
<h2>Proxies</h2>
<table class='table'>
<thead>
<td><a href='#' id=selectallproxy>#</a></td>
<td>type</td>
<td>ip</td>
<td>port</td>
<td>user</td>
<td>password</td>
<td>status</td>
</thead>
<tbody>
<?php
foreach ($dbproxies as $proxy) {
echo "<tr>";
echo "<td><input type=checkbox name=idproxy[] id=chkprx_" . $proxy['id'] . " value=" . $proxy['id'] . " /></td>";
echo "<td>" . $proxy['type'] . "</td>";
echo "<td>" . h8($proxy['ip']) . "</td>";
echo "<td>" . $proxy['port'] . "</td>";
echo "<td>" . h8($proxy['user']) . "</td>";
echo "<td>" . h8($proxy['password']) . "</td>";
echo "<td id=status" . $proxy['id'] . " >N/A</td>";
echo "</tr>";
}
?>
<tr>
<td colspan=7>
<button class="btn" id="btndeleteproxy">Delete</button>
<button class="btn" id="btndeleteoffproxy">Delete ERR</button>
<button class="btn" id="btncheckproxy">Check</button>
</td>
</tr>
</tbody>
</table>
<hr/>
<form method=POST>
<h4>Add a proxy</h4>
<table>
<tr>
<td><select name=type class="input-mini">
<option>http</option>
<option>socks</option>
<option>iface</option>
</select>
</td>
<td><input type="text" name="ip" class="input-small" placeholder="ip" /></td>
<td><input type="text" name="port" class=input-mini placeholder="port" /></td>
<td><input type="text" name="user" placeholder="username" /></td>
<td><input type="text" name="password" placeholder="password" /></td>
<td><p><input type="submit" class="btn btn-primary" value="Add" /></p></td>
</tr>
</table>
<hr/>
<h4>Bulk import</h4>
<select name=bulkimport-type class="input-mini">
<option>http</option>
<option>socks</option>
<option>iface</option>
</select>
<textarea name=bulkimport-proxies style="width:100%; height: 120px" placeholder="ip#port#username#password" ></textarea>
<input type=submit class="btn btn-primary" value="Bulk Import" />
</form>
<hr/>
<h4>Lists URL</h4>
<form method=POST>
<p class="help-block">If you use public proxies list,you need to <a href='http://serphacker.com/serposcope/doc/proxies.html' >optimize the configuration</a>.</p>
<textarea name=list-url-proxies style="width:100%; height: 120px" placeholder="http://domain.com/proxies-list.html" ><?php echo h8($options['general']['proxies_list_url']); ?></textarea>
<input type=submit class="btn btn-primary" value="Update proxies list URL" />
</form>
<?php
include('inc/footer.php');
?>