Name = 'NetworkConfigRouterOS'; $this->Version = '1.0'; $this->Creator = 'Chronos'; $this->License = 'GNU/GPLv3'; $this->Description = 'Mikrotik RouterOS configuration'; $this->Dependencies = array(ModuleNetworkConfig::GetName()); } function DoStart(): void { $this->System->Pages['zdarma'] = 'PageFreeAccess'; ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-dns', 'ConfigRouterOSDNS'); ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-dhcp', 'ConfigRouterOSDHCP'); ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-signal', 'ConfigRouterOSSignal'); ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-netwatch', 'ConfigRouterOSNetwatch'); ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-netwatch-import', 'ConfigRouterOSNetwatchImport'); ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-firewall-filter', 'ConfigRouterOSFirewallFilter'); ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-firewall-nat', 'ConfigRouterOSFirewallNAT'); ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-firewall-mangle', 'ConfigRouterOSFirewallMangle'); ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-queue', 'ConfigRouterOSQueue'); } } class PageFreeAccess extends Page { public string $AddressList = 'free-access'; public int $Timeout; function __construct(System $System) { parent::__construct($System); $this->Title = 'Internet zdarma'; $this->Description = 'Přístup zdarma k Internetu'; $this->ParentClass = 'PagePortal'; $this->Timeout = 24 * 60 * 60; } function Show(): string { $IPAddress = GetRemoteAddress(); $Output = 'Vaše IP adresa je: '.$IPAddress.'
'; if (IsInternetAddr($IPAddress)) { $Output .= '

Internet zdarma je dostupný pouze z vnitřní sítě.

'; return $Output; } $Time = time(); $DbResult = $this->Database->select('NetworkFreeAccess', '*', '(IPAddress="'.$IPAddress. '") ORDER BY Time DESC LIMIT 1'); if ($DbResult->num_rows > 0) { $DbRow = $DbResult->fetch_assoc(); $ActivationTime = MysqlDateTimeToTime($DbRow['Time']); if (($ActivationTime + $this->Timeout) < $Time) { $Activated = false; } else $Activated = true; } else $Activated = false; if (array_key_exists('a', $_GET)) { if ($_GET['a'] == 'activate') { if ($Activated == false) { $DbResult = $this->Database->insert('NetworkFreeAccess', array('IPAddress' => $IPAddress, 'Time' => TimeToMysqlDateTime(time()), 'Configured' => 0)); $ActivationTime = $Time; $Activated = true; } } } $Output .= '

Vítejte v síti ZděchovNET

'; $Output .= '

Pro přístup k Internetu zdarma sdílenou rychlostí 128/128 kbit/s klikněte na odkaz níže. Internet bude zpřístupněn po dobu 24 hodin. Po uplynutí této doby je potřeba provést novou aktivaci.

'; $Output .= '

Pokud jste platícím zákazníkem a přesto se vám zobrazuje tato stránka, tak pravděpodobně nemáte registrovano v síti vaše klientské zařízení.

'; $PrefixMultiplier = new PrefixMultiplier(); if ($Activated) $Output .= 'Aktivováno. Vyprší za '.$PrefixMultiplier->Add($ActivationTime + $this->Timeout - $Time, '', 4, 'Time'); else $Output .= 'Aktivovat'; return $Output; } } class ScheduleConfigureFreeAccess extends SchedulerTask { function Execute(): string { $Output = ''; $Commands = array(); $DbResult = $this->Database->select('NetworkFreeAccess', '`Id`, `IPAddress`', '(`Configured`=0)'); while ($DbRow = $DbResult->fetch_assoc()) { $Commands[] = '/ip firewall address-list add address='.$DbRow['IPAddress']. ' list=free-access timeout=1d'; } $DbResult = $this->Database->update('NetworkFreeAccess', '`Configured`=0', array('Configured' => 1)); $Routerboard = new Routerboard($this->System->Config['MainRouter']['HostName']); $Routerboard->UserName = $this->System->Config['MainRouter']['UserName']; $Routerboard->Timeout = $this->System->Config['MainRouter']['ConnectTimeout']; $Routerboard->Debug = true; $Routerboard->ExecuteBatch(implode(';', $Commands)); return $Output; } }