mirror of
https://github.com/rekryt/iplist.git
synced 2025-10-12 16:39:35 +03:00
feat: new output formats Dnsmasq nfset and ipset, ClashX, Keenetic KVAS
This commit is contained in:
32
src/App/Controller/ClashxController.php
Normal file
32
src/App/Controller/ClashxController.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OpenCCK\App\Controller;
|
||||||
|
|
||||||
|
class ClashxController extends TextController {
|
||||||
|
const DELIMITER = "\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $response
|
||||||
|
* @return string
|
||||||
|
* Поддерживаемые типы правил в ClashX:
|
||||||
|
* DOMAIN-SUFFIX — для доменов по суффиксу.
|
||||||
|
* DOMAIN — для конкретных доменов.
|
||||||
|
* DOMAIN-KEYWORD — для доменов, содержащих определённые ключевые слова.
|
||||||
|
* IP-CIDR — для IP-адресов и IPv4-сетей.
|
||||||
|
* IP-CIDR6 — для IPv6-сетей.
|
||||||
|
* SRC-IP-CIDR — для исходных IP-адресов или сетей.
|
||||||
|
* SRC-IP-CIDR6 — для исходных IPv6-адресов или сетей.
|
||||||
|
* GEOIP — для определения страны по IP.
|
||||||
|
*/
|
||||||
|
protected function render(array $response): string {
|
||||||
|
$data = $this->request->getQueryParameter('data') ?? '';
|
||||||
|
$handlers = [
|
||||||
|
'domains' => fn(string $row) => 'DOMAIN-SUFFIX,' . $row,
|
||||||
|
'ip4' => fn(string $row) => 'IP-CIDR,' . $row . '/32',
|
||||||
|
'ip6' => fn(string $row) => 'IP-CIDR6,' . $row . '/128',
|
||||||
|
'cidr4' => fn(string $row) => 'IP-CIDR,' . $row,
|
||||||
|
'cidr6' => fn(string $row) => 'IP-CIDR6,' . $row,
|
||||||
|
];
|
||||||
|
return implode($this::DELIMITER, array_map($handlers[$data] ?? fn(string $row) => $row, $response));
|
||||||
|
}
|
||||||
|
}
|
19
src/App/Controller/IpsetController.php
Normal file
19
src/App/Controller/IpsetController.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OpenCCK\App\Controller;
|
||||||
|
|
||||||
|
class IpsetController extends TextController {
|
||||||
|
const DELIMITER = "\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $response
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function render(array $response): string {
|
||||||
|
$data = $this->request->getQueryParameter('data') ?? '';
|
||||||
|
return implode(
|
||||||
|
$this::DELIMITER,
|
||||||
|
array_map(fn(string $row) => 'ipset=/' . $row . '/vpn_' . $data, $response)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
26
src/App/Controller/KvasController.php
Normal file
26
src/App/Controller/KvasController.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OpenCCK\App\Controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format Keenetic (KVAS)
|
||||||
|
*/
|
||||||
|
class KvasController extends TextController {
|
||||||
|
const DELIMITER = "\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $response
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function render(array $response): string {
|
||||||
|
$data = $this->request->getQueryParameter('data') ?? '';
|
||||||
|
$handlers = [
|
||||||
|
'domains' => fn(string $row) => '*' . $row,
|
||||||
|
'ip4' => fn(string $row) => $row . '/32',
|
||||||
|
'ip6' => fn(string $row) => $row . '/128',
|
||||||
|
'cidr4' => fn(string $row) => $row,
|
||||||
|
'cidr6' => fn(string $row) => $row,
|
||||||
|
];
|
||||||
|
return implode($this::DELIMITER, array_map($handlers[$data] ?? fn(string $row) => $row, $response));
|
||||||
|
}
|
||||||
|
}
|
@@ -14,7 +14,7 @@ class MikrotikController extends AbstractIPListController {
|
|||||||
$sites = SiteFactory::normalizeArray($this->request->getQueryParameters()['site'] ?? []);
|
$sites = SiteFactory::normalizeArray($this->request->getQueryParameters()['site'] ?? []);
|
||||||
$data = $this->request->getQueryParameter('data') ?? '';
|
$data = $this->request->getQueryParameter('data') ?? '';
|
||||||
if ($data == '') {
|
if ($data == '') {
|
||||||
return "# Error: The 'data' GET parameter is required in the URL to access this page, but it cannot have the value 'All'";
|
return "# Error: The 'data' GET parameter is required in the URL to access this page";
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = [];
|
$response = [];
|
||||||
|
26
src/App/Controller/NfsetController.php
Normal file
26
src/App/Controller/NfsetController.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OpenCCK\App\Controller;
|
||||||
|
|
||||||
|
class NfsetController extends TextController {
|
||||||
|
const DELIMITER = "\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $response
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function render(array $response): string {
|
||||||
|
$data = $this->request->getQueryParameter('data') ?? '';
|
||||||
|
|
||||||
|
$prefix = 'nftset=/';
|
||||||
|
$suffix = '#inet#fw4#vpn_';
|
||||||
|
$handlers = [
|
||||||
|
'domains' => fn(string $row) => $prefix . $row . '/4' . $suffix . $data,
|
||||||
|
'ip4' => fn(string $row) => $prefix . $row . '/4' . $suffix . $data,
|
||||||
|
'ip6' => fn(string $row) => $prefix . $row . '/6' . $suffix . $data,
|
||||||
|
'cidr4' => fn(string $row) => $prefix . $row . '/4' . $suffix . $data,
|
||||||
|
'cidr6' => fn(string $row) => $prefix . $row . '/6' . $suffix . $data,
|
||||||
|
];
|
||||||
|
return implode($this::DELIMITER, array_map($handlers[$data] ?? fn(string $row) => $row, $response));
|
||||||
|
}
|
||||||
|
}
|
@@ -15,7 +15,7 @@ class TextController extends AbstractIPListController {
|
|||||||
$sites = SiteFactory::normalizeArray($this->request->getQueryParameters()['site'] ?? []);
|
$sites = SiteFactory::normalizeArray($this->request->getQueryParameters()['site'] ?? []);
|
||||||
$data = $this->request->getQueryParameter('data') ?? '';
|
$data = $this->request->getQueryParameter('data') ?? '';
|
||||||
if ($data == '') {
|
if ($data == '') {
|
||||||
return "# Error: The 'data' GET parameter is required in the URL to access this page, but it cannot have the value 'All'";
|
return "# Error: The 'data' GET parameter is required in the URL to access this page";
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = [];
|
$response = [];
|
||||||
@@ -29,9 +29,16 @@ class TextController extends AbstractIPListController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return implode(
|
return $this->render(
|
||||||
$this::DELIMITER,
|
|
||||||
SiteFactory::normalizeArray($response, in_array($data, ['ipv4', 'ipv6', 'cidr4', 'cidr6']))
|
SiteFactory::normalizeArray($response, in_array($data, ['ipv4', 'ipv6', 'cidr4', 'cidr6']))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $response
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function render(array $response): string {
|
||||||
|
return implode($this::DELIMITER, $response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -60,6 +60,10 @@ class IPListService {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function loadConfig(string $name, object $config): void {
|
private function loadConfig(string $name, object $config): void {
|
||||||
|
if (isset($this->sites[$name])) {
|
||||||
|
$this->logger->error(sprintf('Site "%s" already exists', $name));
|
||||||
|
return;
|
||||||
|
}
|
||||||
$this->sites[$name] = SiteFactory::create($name, $config);
|
$this->sites[$name] = SiteFactory::create($name, $config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -619,10 +619,14 @@ use OpenCCK\App\Controller\TextController;
|
|||||||
Format:
|
Format:
|
||||||
<select name="format" class="main-formSelect">
|
<select name="format" class="main-formSelect">
|
||||||
<option value="json">JSON</option>
|
<option value="json">JSON</option>
|
||||||
<option value="mikrotik">MikroTik</option>
|
|
||||||
<option value="text">Text</option>
|
<option value="text">Text</option>
|
||||||
<option value="comma">Comma</option>
|
<option value="comma">Comma</option>
|
||||||
<option value="switchy">Switchy RuleList</option>
|
<option value="mikrotik">MikroTik Script</option>
|
||||||
|
<option value="switchy">SwitchyOmega RuleList</option>
|
||||||
|
<option value="nfset">Dnsmasq nfset</option>
|
||||||
|
<option value="ipset">Dnsmasq ipset</option>
|
||||||
|
<option value="clashx">ClashX</option>
|
||||||
|
<option value="kvas">Keenetic KVAS</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<label class="main-formItem">
|
<label class="main-formItem">
|
||||||
|
@@ -83,17 +83,17 @@ class SiteFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $array
|
* @param array $array
|
||||||
* @param bool $excludeLocalIPs
|
* @param bool $isIpAddresses
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function normalize(array $array, bool $excludeLocalIPs = false): array {
|
public static function normalize(array $array, bool $isIpAddresses = false): array {
|
||||||
return array_values(
|
return array_values(
|
||||||
array_unique(
|
array_unique(
|
||||||
array_filter(
|
array_filter(
|
||||||
$array,
|
$array,
|
||||||
fn(string $item) => !str_starts_with($item, '#') &&
|
fn(string $item) => !str_starts_with($item, '#') &&
|
||||||
strlen($item) > 0 &&
|
strlen($item) > 0 &&
|
||||||
(!$excludeLocalIPs ||
|
(!$isIpAddresses ||
|
||||||
(!str_starts_with($item, '10.') &&
|
(!str_starts_with($item, '10.') &&
|
||||||
!str_starts_with($item, '172.16.') &&
|
!str_starts_with($item, '172.16.') &&
|
||||||
!str_starts_with($item, '192.168.') &&
|
!str_starts_with($item, '192.168.') &&
|
||||||
@@ -105,11 +105,11 @@ class SiteFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $array
|
* @param array $array
|
||||||
* @param bool $excludeLocalIPs
|
* @param bool $isIpAddresses
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function normalizeArray(array $array, bool $excludeLocalIPs = false): array {
|
public static function normalizeArray(array $array, bool $isIpAddresses = false): array {
|
||||||
sort($array);
|
sort($array);
|
||||||
return SiteFactory::normalize($array, $excludeLocalIPs);
|
return SiteFactory::normalize($array, $isIpAddresses);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user