mirror of
https://github.com/rekryt/iplist.git
synced 2025-10-12 16:39:35 +03:00
feat: checkbox for only wildcard domains
This commit is contained in:
@@ -6,6 +6,7 @@ use Amp\ByteStream\BufferException;
|
||||
use Amp\Http\Server\Request;
|
||||
|
||||
use OpenCCK\App\Service\IPListService;
|
||||
use OpenCCK\Domain\Entity\Site;
|
||||
use OpenCCK\Infrastructure\API\App;
|
||||
|
||||
use Monolog\Logger;
|
||||
@@ -32,4 +33,16 @@ abstract class AbstractIPListController extends AbstractController {
|
||||
* @return 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);
|
||||
}
|
||||
}
|
||||
|
@@ -16,9 +16,9 @@ class JsonController extends AbstractIPListController {
|
||||
$data = $this->request->getQueryParameter('data') ?? '';
|
||||
|
||||
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 {
|
||||
$items = $this->service->sites;
|
||||
$items = $this->getSites();
|
||||
}
|
||||
return json_encode($data == '' ? $items : array_map(fn(Site $siteEntity) => $siteEntity->$data, $items));
|
||||
}
|
||||
|
@@ -20,10 +20,10 @@ class MikrotikController extends AbstractIPListController {
|
||||
$response = [];
|
||||
if (count($sites)) {
|
||||
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 {
|
||||
foreach ($this->service->sites as $siteEntity) {
|
||||
foreach ($this->getSites() as $siteEntity) {
|
||||
$response = array_merge($response, $this->generateList($siteEntity->name, $siteEntity->$data));
|
||||
}
|
||||
}
|
||||
|
@@ -37,11 +37,11 @@ class SwitchyController extends AbstractIPListController {
|
||||
foreach ($sites as $site) {
|
||||
$domains = array_merge(
|
||||
$domains,
|
||||
array_map($this->wildcardFormat(...), $this->service->sites[$site]->$data)
|
||||
array_map($this->wildcardFormat(...), $this->getSites()[$site]->$data)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
foreach ($this->service->sites as $siteEntity) {
|
||||
foreach ($this->getSites() as $siteEntity) {
|
||||
$domains = array_merge($domains, array_map($this->wildcardFormat(...), $siteEntity->$data));
|
||||
}
|
||||
}
|
||||
|
@@ -21,10 +21,10 @@ class TextController extends AbstractIPListController {
|
||||
$response = [];
|
||||
if (count($sites)) {
|
||||
foreach ($sites as $site) {
|
||||
$response = array_merge($response, $this->service->sites[$site]->$data);
|
||||
$response = array_merge($response, $this->getSites()[$site]->$data);
|
||||
}
|
||||
} else {
|
||||
foreach ($this->service->sites as $siteEntity) {
|
||||
foreach ($this->getSites() as $siteEntity) {
|
||||
$response = array_merge($response, $siteEntity->$data);
|
||||
}
|
||||
}
|
||||
|
@@ -601,6 +601,14 @@ use OpenCCK\App\Controller\TextController;
|
||||
}
|
||||
.main-formSelect {}
|
||||
.main-formSelect_site {}
|
||||
.main-formItemCheckbox {
|
||||
margin: 0 6px 0 0;
|
||||
}
|
||||
.main-formItemCheckboxLabel {
|
||||
line-height: 1;
|
||||
font-size: 14px;
|
||||
font-weight: normal;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -639,6 +647,10 @@ use OpenCCK\App\Controller\TextController;
|
||||
</span>
|
||||
<span class="main-formItemComment">Don't choose sites if you want to get everything</span>
|
||||
</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>
|
||||
<button type="submit">Submit</button>
|
||||
|
@@ -5,9 +5,20 @@ namespace OpenCCK\Domain\Factory;
|
||||
use OpenCCK\Domain\Entity\Site;
|
||||
use OpenCCK\Domain\Helper\IP4Helper;
|
||||
use OpenCCK\Domain\Helper\IP6Helper;
|
||||
use OpenCCK\Infrastructure\API\App;
|
||||
use stdClass;
|
||||
|
||||
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 object $config Configuration of portal
|
||||
@@ -27,30 +38,35 @@ class SiteFactory {
|
||||
if (isset($external)) {
|
||||
if (isset($external->domains)) {
|
||||
foreach ($external->domains as $url) {
|
||||
App::getLogger()->debug('Loading external domains from ' . $url);
|
||||
$domains = array_merge($domains, explode("\n", file_get_contents($url)));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($external->ip4)) {
|
||||
foreach ($external->ip4 as $url) {
|
||||
App::getLogger()->debug('Loading external ip4 from ' . $url);
|
||||
$ip4 = array_merge($ip4, explode("\n", file_get_contents($url)));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($external->ip6)) {
|
||||
foreach ($external->ip6 as $url) {
|
||||
App::getLogger()->debug('Loading external ip6 from ' . $url);
|
||||
$ip6 = array_merge($ip6, explode("\n", file_get_contents($url)));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($external->cidr4)) {
|
||||
foreach ($external->cidr4 as $url) {
|
||||
App::getLogger()->debug('Loading external cidr4 from ' . $url);
|
||||
$cidr4 = array_merge($cidr4, explode("\n", file_get_contents($url)));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($external->cidr6)) {
|
||||
foreach ($external->cidr6 as $url) {
|
||||
App::getLogger()->debug('Loading external cidr6 from ' . $url);
|
||||
$cidr6 = array_merge($cidr6, explode("\n", file_get_contents($url)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user