-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModProxyController.php
More file actions
91 lines (67 loc) · 2.52 KB
/
ModProxyController.php
File metadata and controls
91 lines (67 loc) · 2.52 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
<?php
use \Core2\Mod\Proxy;
require_once DOC_ROOT . "core2/inc/classes/Common.php";
require_once DOC_ROOT . "core2/inc/classes/Panel.php";
require_once 'classes/Index/View.php';
require_once 'classes/Index/Request.php';
/**
* @property \Proxy $dataProxy
* @property \ProxyDomains $dataProxyDomains
*/
class ModProxyController extends Common {
/**
* @return string
* @throws Exception
*/
public function action_index(): string {
$base_url = 'index.php?module=proxy';
$panel = new Panel('tab');
$content = [];
$view = new Proxy\Index\View();
if (isset($_GET['edit'])) {
if ( ! empty($_GET['edit'])) {
$proxy = $this->dataProxy->getRowById((int)$_GET['edit']);
if (empty($proxy)) {
throw new Exception('Указанный Proxy не найден');
}
$panel->setTitle("Редактирование proxy", '', $base_url);
} else {
$panel->setTitle("Добавление proxy", '', $base_url);
}
$content[] = $view->getEdit($base_url, $proxy ?? null);
} else {
$panel->addTab('Активные', 'active', $base_url);
$panel->addTab('Не активные', 'inactive', $base_url);
$base_url .= "&tab=" . $panel->getActiveTab();
switch ($panel->getActiveTab()) {
case 'active': $content[] = $view->getTableActive($base_url); break;
case 'inactive': $content[] = $view->getTableInactive($base_url); break;
}
}
$panel->setContent(implode('', $content));
return $panel->render();
}
/**
* Список User агентов браузеров
* @return array
*/
public function getUserAgents(): array {
$content = file_get_contents(__DIR__ . '/assets/user_agents.txt');
$agents = explode("\n", $content);
return $agents ?: [];
}
/**
* Запрос с использованием proxy серверов
* @param string $method
* @param string[] $addresses
* @param array $options
* @return void
* @throws Exception
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function request(string $method, array $addresses, array $options = []): array {
$request = new Request($method, $options);
$request->setAddresses($addresses);
return $request->getResponses();
}
}