mirror of
https://github.com/rekryt/iplist.git
synced 2025-10-13 00:49:36 +03:00
feat: add net PAC format
This commit is contained in:
27
README.en.md
27
README.en.md
@@ -18,19 +18,20 @@ Demo URL: [https://iplist.opencck.org](https://iplist.opencck.org)
|
|||||||
- **whois, ipcalc (Linux utilities)**
|
- **whois, ipcalc (Linux utilities)**
|
||||||
|
|
||||||
# Formats of Output
|
# Formats of Output
|
||||||
| format | description |
|
| format | description |
|
||||||
|----------|-----------------------|
|
|----------|-------------------------------|
|
||||||
| json | JSON format |
|
| json | JSON format |
|
||||||
| text | Newline-separated |
|
| text | Newline-separated |
|
||||||
| comma | Comma-separated |
|
| comma | Comma-separated |
|
||||||
| mikrotik | MikroTik Script |
|
| mikrotik | MikroTik Script |
|
||||||
| switchy | SwitchyOmega RuleList |
|
| switchy | SwitchyOmega RuleList |
|
||||||
| nfset | Dnsmasq nfset |
|
| nfset | Dnsmasq nfset |
|
||||||
| ipset | Dnsmasq ipset |
|
| ipset | Dnsmasq ipset |
|
||||||
| clashx | ClashX |
|
| clashx | ClashX |
|
||||||
| kvas | Keenetic KVAS |
|
| kvas | Keenetic KVAS |
|
||||||
| bat | Keenetic Routes .bat |
|
| bat | Keenetic Routes .bat |
|
||||||
| amnezia | Amnezia filter list |
|
| amnezia | Amnezia filter list |
|
||||||
|
| pac | Proxy Auto-Configuration file |
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
|
27
README.md
27
README.md
@@ -22,19 +22,20 @@ Demo URL: [https://iplist.opencck.org](https://iplist.opencck.org)
|
|||||||
- whois, ipcalc (linux)
|
- whois, ipcalc (linux)
|
||||||
|
|
||||||
# Форматы выгрузки
|
# Форматы выгрузки
|
||||||
| формат | описание |
|
| формат | описание |
|
||||||
|----------|--------------------------|
|
|----------|-------------------------------|
|
||||||
| json | JSON формат |
|
| json | JSON формат |
|
||||||
| text | Разделение новой строкой |
|
| text | Разделение новой строкой |
|
||||||
| comma | Разделение запятыми |
|
| comma | Разделение запятыми |
|
||||||
| mikrotik | MikroTik Script |
|
| mikrotik | MikroTik Script |
|
||||||
| switchy | SwitchyOmega RuleList |
|
| switchy | SwitchyOmega RuleList |
|
||||||
| nfset | Dnsmasq nfset |
|
| nfset | Dnsmasq nfset |
|
||||||
| ipset | Dnsmasq ipset |
|
| ipset | Dnsmasq ipset |
|
||||||
| clashx | ClashX |
|
| clashx | ClashX |
|
||||||
| kvas | Keenetic KVAS |
|
| kvas | Keenetic KVAS |
|
||||||
| bat | Keenetic Routes .bat |
|
| bat | Keenetic Routes .bat |
|
||||||
| amnezia | Amnezia filter list |
|
| amnezia | Amnezia filter list |
|
||||||
|
| pac | Proxy Auto-Configuration file |
|
||||||
|
|
||||||
## Настройки
|
## Настройки
|
||||||
Конфигурационные файлы хранятся в `config/<группа>/<портал>.json`. Каждый JSON файл представляет собой конфигурацию для конкретного портала, задавая домены для мониторинга и источники начальных данных по IP и CIDR.
|
Конфигурационные файлы хранятся в `config/<группа>/<портал>.json`. Каждый JSON файл представляет собой конфигурацию для конкретного портала, задавая домены для мониторинга и источники начальных данных по IP и CIDR.
|
||||||
|
74
src/App/Controller/PacController.php
Normal file
74
src/App/Controller/PacController.php
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OpenCCK\App\Controller;
|
||||||
|
|
||||||
|
use OpenCCK\Domain\Factory\SiteFactory;
|
||||||
|
use OpenCCK\Domain\Helper\IP4Helper;
|
||||||
|
|
||||||
|
class PacController extends AbstractIPListController {
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBody(): string {
|
||||||
|
$this->setHeaders(['content-type' => 'text/javascript']);
|
||||||
|
|
||||||
|
$sites = SiteFactory::normalizeArray($this->request->getQueryParameters()['site'] ?? []);
|
||||||
|
$data = $this->request->getQueryParameter('data') ?? '';
|
||||||
|
$template = $this->request->getQueryParameter('template') ?? 'PROXY 127.0.0.1:2080; DIRECT';
|
||||||
|
if (!in_array($data, ['domains', 'cidr4'])) {
|
||||||
|
return "# Error: The 'data' GET parameter is must be 'domains' or 'cidr4'";
|
||||||
|
}
|
||||||
|
|
||||||
|
$items = [];
|
||||||
|
if (count($sites)) {
|
||||||
|
foreach ($sites as $site) {
|
||||||
|
$items = array_merge($items, $this->getSites()[$site]->$data);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($this->getSites() as $siteEntity) {
|
||||||
|
$items = array_merge($items, $siteEntity->$data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = ['const items = ['];
|
||||||
|
$response[] = implode(
|
||||||
|
",\n",
|
||||||
|
$data == 'cidr4'
|
||||||
|
? array_map(function (string $item) {
|
||||||
|
$parts = explode('/', $item);
|
||||||
|
$mask = IP4Helper::formatShortIpMask($parts[1] ?? '');
|
||||||
|
return '["' . $parts[0] . '","' . $mask . '"]';
|
||||||
|
}, SiteFactory::normalizeArray($items, true))
|
||||||
|
: array_map(fn(string $item) => '"' . $item . '"', SiteFactory::normalizeArray($items))
|
||||||
|
);
|
||||||
|
$response[] = '];';
|
||||||
|
|
||||||
|
if ($data == 'cidr4') {
|
||||||
|
$response = array_merge($response, [
|
||||||
|
'function FindProxyForURL(url, host) {',
|
||||||
|
' for (cidr of items) {',
|
||||||
|
' if (isInNet(host, cidr[0], cidr[1])) {',
|
||||||
|
' return "' . $template . '";',
|
||||||
|
' }',
|
||||||
|
' }',
|
||||||
|
'',
|
||||||
|
' return "DIRECT";',
|
||||||
|
'}',
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$response = array_merge($response, [
|
||||||
|
'function FindProxyForURL(url, host) {',
|
||||||
|
' for (domain of items) {',
|
||||||
|
' if (host === domain || shExpMatch(host, "*." + domain)) {',
|
||||||
|
' return "' . $template . '";',
|
||||||
|
' }',
|
||||||
|
' }',
|
||||||
|
'',
|
||||||
|
' return "DIRECT";',
|
||||||
|
'}',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode("\n", $response);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user