feat: checkbox for only wildcard domains

This commit is contained in:
Rekryt
2024-09-03 20:11:08 +03:00
parent c89cb6b4b3
commit 2169ca6b84
7 changed files with 49 additions and 8 deletions

View File

@@ -6,6 +6,7 @@ use Amp\ByteStream\BufferException;
use Amp\Http\Server\Request; use Amp\Http\Server\Request;
use OpenCCK\App\Service\IPListService; use OpenCCK\App\Service\IPListService;
use OpenCCK\Domain\Entity\Site;
use OpenCCK\Infrastructure\API\App; use OpenCCK\Infrastructure\API\App;
use Monolog\Logger; use Monolog\Logger;
@@ -32,4 +33,16 @@ abstract class AbstractIPListController extends AbstractController {
* @return string * @return string
*/ */
abstract public function getBody(): string; abstract public function getBody(): string;
/**
* @return array<string, Site>
*/
protected function getSites(): array {
$wildcard = !!($this->request->getQueryParameter('wildcard') ?? '');
return array_map(static function (Site $siteEntity) use ($wildcard) {
$site = clone $siteEntity;
$site->domains = $siteEntity->getDomains($wildcard);
return $site;
}, $this->service->sites);
}
} }

View File

@@ -16,9 +16,9 @@ class JsonController extends AbstractIPListController {
$data = $this->request->getQueryParameter('data') ?? ''; $data = $this->request->getQueryParameter('data') ?? '';
if (count($sites)) { if (count($sites)) {
$items = array_filter($this->service->sites, fn(Site $siteEntity) => in_array($siteEntity->name, $sites)); $items = array_filter($this->getSites(), fn(Site $siteEntity) => in_array($siteEntity->name, $sites));
} else { } else {
$items = $this->service->sites; $items = $this->getSites();
} }
return json_encode($data == '' ? $items : array_map(fn(Site $siteEntity) => $siteEntity->$data, $items)); return json_encode($data == '' ? $items : array_map(fn(Site $siteEntity) => $siteEntity->$data, $items));
} }

View File

@@ -20,10 +20,10 @@ class MikrotikController extends AbstractIPListController {
$response = []; $response = [];
if (count($sites)) { if (count($sites)) {
foreach ($sites as $site) { foreach ($sites as $site) {
$response = array_merge($response, $this->generateList($site, $this->service->sites[$site]->$data)); $response = array_merge($response, $this->generateList($site, $this->getSites()[$site]->$data));
} }
} else { } else {
foreach ($this->service->sites as $siteEntity) { foreach ($this->getSites() as $siteEntity) {
$response = array_merge($response, $this->generateList($siteEntity->name, $siteEntity->$data)); $response = array_merge($response, $this->generateList($siteEntity->name, $siteEntity->$data));
} }
} }

View File

@@ -37,11 +37,11 @@ class SwitchyController extends AbstractIPListController {
foreach ($sites as $site) { foreach ($sites as $site) {
$domains = array_merge( $domains = array_merge(
$domains, $domains,
array_map($this->wildcardFormat(...), $this->service->sites[$site]->$data) array_map($this->wildcardFormat(...), $this->getSites()[$site]->$data)
); );
} }
} else { } else {
foreach ($this->service->sites as $siteEntity) { foreach ($this->getSites() as $siteEntity) {
$domains = array_merge($domains, array_map($this->wildcardFormat(...), $siteEntity->$data)); $domains = array_merge($domains, array_map($this->wildcardFormat(...), $siteEntity->$data));
} }
} }

View File

@@ -21,10 +21,10 @@ class TextController extends AbstractIPListController {
$response = []; $response = [];
if (count($sites)) { if (count($sites)) {
foreach ($sites as $site) { foreach ($sites as $site) {
$response = array_merge($response, $this->service->sites[$site]->$data); $response = array_merge($response, $this->getSites()[$site]->$data);
} }
} else { } else {
foreach ($this->service->sites as $siteEntity) { foreach ($this->getSites() as $siteEntity) {
$response = array_merge($response, $siteEntity->$data); $response = array_merge($response, $siteEntity->$data);
} }
} }

View File

@@ -601,6 +601,14 @@ use OpenCCK\App\Controller\TextController;
} }
.main-formSelect {} .main-formSelect {}
.main-formSelect_site {} .main-formSelect_site {}
.main-formItemCheckbox {
margin: 0 6px 0 0;
}
.main-formItemCheckboxLabel {
line-height: 1;
font-size: 14px;
font-weight: normal;
}
</style> </style>
</head> </head>
<body> <body>
@@ -639,6 +647,10 @@ use OpenCCK\App\Controller\TextController;
</span> </span>
<span class="main-formItemComment">Don't choose sites if you want to get everything</span> <span class="main-formItemComment">Don't choose sites if you want to get everything</span>
</label> </label>
<label class="main-formItem main-formItem_wide">
<input class="main-formItemCheckbox" type="checkbox" name="wildcard" value="1" />
<span class="main-formItemCheckboxLabel">Only wildcard domains</span>
</label>
</section> </section>
<section> <section>
<button type="submit">Submit</button> <button type="submit">Submit</button>

View File

@@ -5,9 +5,20 @@ namespace OpenCCK\Domain\Factory;
use OpenCCK\Domain\Entity\Site; use OpenCCK\Domain\Entity\Site;
use OpenCCK\Domain\Helper\IP4Helper; use OpenCCK\Domain\Helper\IP4Helper;
use OpenCCK\Domain\Helper\IP6Helper; use OpenCCK\Domain\Helper\IP6Helper;
use OpenCCK\Infrastructure\API\App;
use stdClass; use stdClass;
class SiteFactory { class SiteFactory {
// prettier-ignore
const TWO_LEVEL_DOMAIN_ZONES = [
"exnet.su","net.ru","org.ru","pp.ru","ru.net","com.ru",
"co.bw","co.ck","co.fk","co.id","co.il","co.in","co.ke","co.ls","co.mz","co.no","co.nz","co.th","co.tz","co.uk","co.uz","co.za","co.zm","co.zw",
"co.ae","co.at", "co.cr", "co.hu","co.jp", "co.kr", "co.ma", "co.ug", "co.ve",
"com.az","com.bh","com.bo","com.by","com.co","com.do","com.ec","com.ee","com.es","com.gr","com.hn","com.hr","com.jo","com.lv","com.ly","com.mk","com.mx","com.my","com.pe","com.ph","com.pk","com.pt","com.ro","com.tn",
"com.ai","com.ar","com.au","com.bd","com.bn","com.br","com.cn","com.cy","com.eg","com.et","com.fj","com.gh","com.gn","com.gt","com.gu","com.hk","com.jm","com.kh","com.kw","com.lb","com.lr","com.mt","com.mv","com.ng","com.ni","com.np","com.nr","com.om","com.pa","com.pl","com.py","com.qa","com.sa","com.sb","com.sg","com.sv","com.sy","com.tr","com.tw","com.ua","com.uy","com.ve","com.vi","com.vn","com.ye",
"in.ua","kiev.ua","me.uk","net.cn","org.cn","org.uk","radio.am","radio.fm","eu.com"
];
/** /**
* @param string $name Name of portal * @param string $name Name of portal
* @param object $config Configuration of portal * @param object $config Configuration of portal
@@ -27,30 +38,35 @@ class SiteFactory {
if (isset($external)) { if (isset($external)) {
if (isset($external->domains)) { if (isset($external->domains)) {
foreach ($external->domains as $url) { foreach ($external->domains as $url) {
App::getLogger()->debug('Loading external domains from ' . $url);
$domains = array_merge($domains, explode("\n", file_get_contents($url))); $domains = array_merge($domains, explode("\n", file_get_contents($url)));
} }
} }
if (isset($external->ip4)) { if (isset($external->ip4)) {
foreach ($external->ip4 as $url) { foreach ($external->ip4 as $url) {
App::getLogger()->debug('Loading external ip4 from ' . $url);
$ip4 = array_merge($ip4, explode("\n", file_get_contents($url))); $ip4 = array_merge($ip4, explode("\n", file_get_contents($url)));
} }
} }
if (isset($external->ip6)) { if (isset($external->ip6)) {
foreach ($external->ip6 as $url) { foreach ($external->ip6 as $url) {
App::getLogger()->debug('Loading external ip6 from ' . $url);
$ip6 = array_merge($ip6, explode("\n", file_get_contents($url))); $ip6 = array_merge($ip6, explode("\n", file_get_contents($url)));
} }
} }
if (isset($external->cidr4)) { if (isset($external->cidr4)) {
foreach ($external->cidr4 as $url) { foreach ($external->cidr4 as $url) {
App::getLogger()->debug('Loading external cidr4 from ' . $url);
$cidr4 = array_merge($cidr4, explode("\n", file_get_contents($url))); $cidr4 = array_merge($cidr4, explode("\n", file_get_contents($url)));
} }
} }
if (isset($external->cidr6)) { if (isset($external->cidr6)) {
foreach ($external->cidr6 as $url) { foreach ($external->cidr6 as $url) {
App::getLogger()->debug('Loading external cidr6 from ' . $url);
$cidr6 = array_merge($cidr6, explode("\n", file_get_contents($url))); $cidr6 = array_merge($cidr6, explode("\n", file_get_contents($url)));
} }
} }