-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpools.php
More file actions
387 lines (373 loc) · 11.2 KB
/
pools.php
File metadata and controls
387 lines (373 loc) · 11.2 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
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<?
// ===================================================================
// License: GPL v3 (http://www.gnu.org/licenses/gpl.html)
// Copyright (c) 2016-2025 Sim Roulette, https://sim-roulette.com
// ===================================================================
include("_func.php");
$status=1;
if ($_POST['restart'])
{
foreach ($_POST['check'] as $data)
{
// Выключаем устройства пула
$qry="SELECT c.`device` FROM `card2pool` p
INNER JOIN `cards` c ON c.`number`=p.`card`
WHERE p.`pool`=".(int)$data;
if ($result = mysqli_query($db, $qry))
{
while ($row = mysqli_fetch_assoc($result))
{
mysqli_query($db, "DELETE FROM `modems` WHERE `device`=".$row['device']);
if (flagGet($row['device'],'cron'))
{
if (!flagGet($row['device'],'stop'))
{
flagSet($row['device'],'stop');
}
flagDelete($row['device'],'cron');
}
elseif (flagGet($row['device'],'stop',1)<time()-60)
{
flagDelete($row['device'],'stop');
}
}
$qry="UPDATE `card2pool` SET `done`=0 WHERE `pool`='".(int)$data."'";
mysqli_query($db, $qry);
}
}
header('location:pools.php');
exit();
}
if ($_POST['sub']=='del') // Deleting a SIM card Pool | Удаление Пула СИМ-карт
{
foreach ($_POST['check'] as $data)
{
$a=explode(';',$data);
for ($i=0;$i<count($a);$i++){$a[$i]=(int)$a[$i];}
$qry="DELETE FROM `cards` WHERE `id`='".$a[3]."'";
mysqli_query($db,$qry);
}
header('location:cards.php');
exit();
}
if ($_GET['delete']) // Deleting a SIM card Pool | Удаление Пула СИМ-карт
{
if ($result = mysqli_query($db, 'SELECT * FROM `pools` WHERE `id`='.(int)$_GET['delete']))
{
if ($row = mysqli_fetch_assoc($result))
{
$qry="DELETE FROM `card2pool` WHERE `pool`=".(int)$_GET['delete'];
mysqli_query($db,$qry);
$qry="DELETE FROM `pools` WHERE `id`=".(int)$_GET['delete'];
mysqli_query($db,$qry);
}
}
}
if ($_POST['merge']) // Combining SIM card Pools | Объединение Пулов СИМ-карт
{
$f=0;
foreach ($_POST['check'] as $data)
{
if ($result = mysqli_query($db, 'SELECT * FROM `pools` WHERE `id`='.(int)$data))
{
if (!mysqli_fetch_assoc($result))
{
header('location:pools.php');
exit();
}
}
if ($f)
{
if ($result = mysqli_query($db, 'SELECT * FROM `card2pool` WHERE `pool`='.(int)$data.' ORDER BY `card`'))
{
while ($row = mysqli_fetch_assoc($result))
{
// Transferring numbers to the first pool | Перенос номеров в первый пул
$qry="REPLACE INTO `card2pool` SET `pool`=".(int)$f.", `card`='".$row['card']."'";
mysqli_query($db,$qry);
}
}
// Deleting SIM-cards from the pool | Удаление SIM-карт из пула
$qry="DELETE FROM `card2pool` WHERE `pool`=".(int)$data;
mysqli_query($db,$qry);
// Deleting a processed pool | Удаление обработанного пула
$qry="DELETE FROM `pools` WHERE `id`=".(int)$data;
mysqli_query($db,$qry);
}
else
{
$f=$data;
}
}
header('location:pools.php');
exit();
}
if ($_GET['edit']) // Editing the Pool | Редактирование Пула
{
if ($_POST['save'] && $_POST['title'])
{
if ($_GET['edit']=='new')
{
$poolKey=md5(rand(1111,9999).rand(1111,9999).rand(1111,9999).rand(1111,9999));
$qry="INSERT `pools` SET
`title`='".trim($_POST['title'])."',
`key`='".$poolKey."',
`time`='".time()."'";
}
else
{
$qry="UPDATE `pools` SET
`title`='".trim($_POST['title'])."',
`time`='".time()."'
WHERE `id`=".(int)$_GET['edit'];
}
if ($status=mysqli_query($db,$qry))
{
if (!(int)$_GET['edit'])
{
$_GET['edit']=mysqli_insert_id($db);
}
else
{
$qry="DELETE FROM `card2pool`
WHERE `pool`=".(int)$_GET['edit'];
mysqli_query($db,$qry);
}
foreach ($_POST['check'] as $data)
{
$qry="INSERT `card2pool` SET
`pool`=".(int)$_GET['edit'].",
`card`=".(int)$data;
mysqli_query($db,$qry);
}
header('location:pools.php');
exit();
}
}
elseif ($_POST['save'])
{
$status=0;
}
if ((int)$_GET['edit'])
{
if ($_GET['edit']!='new')
{
if ($result = mysqli_query($db, 'SELECT * FROM `pools` WHERE `id`='.(int)$_GET['edit']))
{
if ($row = mysqli_fetch_assoc($result))
{
$_POST['title']=$row['title'];
}
}
}
$_POST['check']=array();
$balance_td=0;
$qry='SELECT p.*,c.`place`,c.`balance`,d.`title`, o1.`title` AS `operator`, o1.`color` AS `color` FROM `card2pool` p
INNER JOIN `cards` c ON c.`number`=p.`card`
INNER JOIN `devices` d ON d.`id`=c.`device`
LEFT JOIN `operators` o1 ON o1.`name` LIKE CONCAT("%;",c.`operator`,";%")
WHERE p.`card`<>"" AND p.`pool`='.(int)$_GET['edit'].' ORDER BY CHAR_LENGTH(c.`place`),c.`place`';
if ($result = mysqli_query($db, $qry))
{
while ($row = mysqli_fetch_assoc($result))
{
if (hexdec($row['color'])>8388607 || !$row['color']){$color='000';} else {$color='FFF';}
$_POST['check'][]=$row['card'].';'.$row['place'].';'.$row['title'].';'.$row['done'].';'.$row['operator'].';'.$row['color'].';'.$color.';'.$row['balance'];
if ($row['balance']){$balance_td=1;}
}
}
}
sr_header("Редактирование пула СИМ-карт"); // Output page title and title | Вывод титул и заголовок страницы
if (!count($_POST['check']))
{
?>
<div class="status_error">Телефонные номера не выбраны!</div>
<?
}
else
{
if (!$status)
{
?>
<div class="status_error">Вы не ввели название пула либо пул с таким названием уже существует!</div>
<?
}
?>
<form method="post">
Название пула
<br>
<input type="text" name="title" value="<?=$_POST['title']?>" maxlength="32">
<br><br>
<div class="table_box">
<table class="table table_sort table_adaptive">
<thead>
<tr>
<th>№</th>
<th>Номер</th>
<?
if (count($devices)>1 && $_GET['edit']!='new')
{
?>
<th>Агрегатор</th>
<?
}
if ($_GET['edit']!='new'){
?>
<th class="sidebar" style="text-align: right;">Место</th>
<th class="exttab"></th>
<th class="sidebar">Оператор</th>
<? if ($balance_td){?><th style="text-align:right;" class="sidebar">Баланс</th><? } ?>
<?
}
?>
<th></th>
</tr>
</thead>
<?
$n=0;
foreach ($_POST['check'] as $data)
{
$data=explode(";",$data);
?>
<tr<? if ($data[3]){echo ' class="rowsel"';}?>>
<td><?=($n+1)?><input type="hidden" name="check[<?=$n++?>]" value="<?=$data[0]?>"></td>
<td>+<?=$data[0]?></td>
<?
if (count($devices)>1 && $_GET['edit']!='new')
{
?>
<td><?=$data[2]?></td>
<?
}
if ($_GET['edit']!='new'){
?>
<td class="sidebar" align="right"><?=$data[1]?></td>
<td class="exttab" align="right"<? if ($data[5]){?> style="color: #<?=$data[6]?>; background:#<?=$data[5]?>"<? } ?>><?=$data[1]?></td>
<td<? if ($data[5]){?> style="color: #<?=$data[6]?>; background:#<?=$data[5]?>"<? } ?> align="center" class="sidebar"><?=$data[4]?></td>
<?
if ($balance_td)
{
?>
<td align="right" class="sidebar"><?=balance_out($data[7],'')?></td>
<?
}
}
?>
<td align="center"><span onclick="deleteItem(this);"><i class="icon-trash" title="Удалить номер из пула"></i></span></td>
</tr>
<div>
<?
}
?>
</table>
</div>
<br>
<input type="submit" name="save" value="Сохранить" class="green width">
</form>
<?
}
}
else // List of Pools | Список Пулов
{
sr_header("Пулы СИМ-карт"); // Выводим титул и заголовок страницы
$table=array();
if ($_GET['number']){$w='INNER JOIN `card2pool` cp2 ON cp2.`pool`=p.id AND cp2.`card` LIKE "%'.(int)$_GET['number'].'%"';} else {$w='';}
$qry='SELECT
p.*,
(SELECT count(pool) FROM `card2pool` WHERE `pool`=p.id) AS `count`,
(SELECT count(c.id) FROM `card2pool` cp INNER JOIN `cards` c ON c.`number`=cp.`card` WHERE cp.`pool`=p.id) AS `realcount`,
(SELECT sum(c.balance)
FROM `card2pool` cp
INNER JOIN `cards` c ON c.`number`=cp.`card` WHERE cp.`pool`=p.id) AS `balance` FROM `pools` p
'.$w.'
GROUP BY `id`
ORDER BY `title`';
if ($result = mysqli_query($db, $qry))
{
while ($row = mysqli_fetch_assoc($result))
{
if (hexdec($row['color'])>8388607 || !$row['color']){$color='000';} else {$color='FFF';}
if ($row['balance']==''){$row['balance']=0;}
$table[]=array(
'id'=>$row['id'],
'title'=>$row['title'],
'key'=>$row['key'],
'count'=>$row['count'],
'realcount'=>$row['realcount'],
'balance'=>$row['balance'],
'status'=>$row['status'],
'time'=>srdate('H:i d.m.Y',$row['time']),
);
}
}
?>
<form method="get">
<input type="text" name="number" value="<?=$_GET['number']?>" maxlength="15" style="width: 200px;" placeholder="Номер телефона">
<input type="submit" name="save" value="Искать" style="padding: 10px; margin: 5px 0 10px 5px">
</form>
<?
if (count($table))
{
if ($_GET['number'] && count($table)>1)
{
?><div class="tooltip">— Номер найден в нескольких Пулах:</div><br><br><?
}
else if ($_GET['number'])
{
?><div class="tooltip">— Номер найден в одном Пуле</div><br><br><?
}
?>
<form method="post" id="cards" name="cards">
<div class="table_box">
<table class="table">
<thead>
<tr>
<th><input type="checkbox" onclick="SelectGroup(checked,'cards','check')"></th>
<th>Пул</th>
<th style="text-align:right;">Номера</th>
<th class="sidebar" style="text-align:right">Баланс</th>
<th class="sidebar">Модификация</th>
<th class="sidebar">pool_key</th>
<th style="text-align: center;">Действие</th>
</tr>
</thead>
<?
$n=0;
foreach ($table as $data)
{
?>
<tr>
<td><input type="checkbox" name="check[<?=$n++?>]" id="check" value="<?=$data['id']?>"></td>
<td nowrap><span class="but_win" data-id="win_action" data-title='Управление пулом "<?=$data['title']?>"' data-type="ajax_pool_action.php?id=<?=$data['id']?>" data-height="400" data-width="600"><?=$data['title']?></span></td>
<td align="right"><?=num_out($data['realcount']).'/'.num_out($data['count'])?></td>
<td class="sidebar" align="right"><?=balance_out($data['balance'])?></td>
<td class="sidebar"><?=$data['time']?></td>
<td class="sidebar"><span class="legend note" onclick="copy('<?=$data['key']?>');soundClick();"><?=$data['key']?></span></td>
<td align="center"><a href="pools.php?edit=<?=$data['id']?>"><i class="icon-pencil"></i></a> <a href="pools.php?delete=<?=$data['id']?>"><i class="icon-trash" title="Удалить пул, но оставить телефонные номера"></i></a></td>
</tr>
<?
}
?>
</table>
</div>
<br>
<input type="submit" name="merge" value="Объединить Пулы" class="width">
<input type="submit" name="restart" value="Перезапустить Пулы для API" class="width">
</form>
<?
}
elseif ($_GET['number'])
{
?>
<div class="tooltip danger">— Номер <b><?=$_GET['number']?></b> в Пулах не найден!</div>
<?
}
else
{
?>
<div class="tooltip">— Для создания Пула нужно отметить <a href="cards.php">СИМ-карты в списке</a>!</div>
<?
}
}
sr_footer();
?>