1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/Routerboard.php');
|
---|
4 | include_once(dirname(__FILE__).'/RouterboardAPI.php');
|
---|
5 | include_once(dirname(__FILE__).'/Generators/Common.php');
|
---|
6 |
|
---|
7 | // Config actions
|
---|
8 | include_once(dirname(__FILE__).'/Generators/Signal.php');
|
---|
9 | include_once(dirname(__FILE__).'/Generators/DHCP.php');
|
---|
10 | include_once(dirname(__FILE__).'/Generators/DNS.php');
|
---|
11 | include_once(dirname(__FILE__).'/Generators/Netwatch.php');
|
---|
12 | include_once(dirname(__FILE__).'/Generators/NetwatchImport.php');
|
---|
13 | include_once(dirname(__FILE__).'/Generators/FirewallFilter.php');
|
---|
14 | include_once(dirname(__FILE__).'/Generators/FirewallNAT.php');
|
---|
15 | include_once(dirname(__FILE__).'/Generators/FirewallMangle.php');
|
---|
16 | include_once(dirname(__FILE__).'/Generators/Queue.php');
|
---|
17 |
|
---|
18 | class ModuleNetworkConfigRouterOS extends Module
|
---|
19 | {
|
---|
20 | function __construct(System $System)
|
---|
21 | {
|
---|
22 | parent::__construct($System);
|
---|
23 | $this->Name = 'NetworkConfigRouterOS';
|
---|
24 | $this->Version = '1.0';
|
---|
25 | $this->Creator = 'Chronos';
|
---|
26 | $this->License = 'GNU/GPLv3';
|
---|
27 | $this->Description = 'Mikrotik RouterOS configuration';
|
---|
28 | $this->Dependencies = array(ModuleNetworkConfig::GetName());
|
---|
29 | }
|
---|
30 |
|
---|
31 | function DoStart(): void
|
---|
32 | {
|
---|
33 | $this->System->Pages['zdarma'] = 'PageFreeAccess';
|
---|
34 | ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-dns', 'ConfigRouterOSDNS');
|
---|
35 | ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-dhcp', 'ConfigRouterOSDHCP');
|
---|
36 | ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-signal', 'ConfigRouterOSSignal');
|
---|
37 | ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-netwatch', 'ConfigRouterOSNetwatch');
|
---|
38 | ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-netwatch-import', 'ConfigRouterOSNetwatchImport');
|
---|
39 | ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-firewall-filter', 'ConfigRouterOSFirewallFilter');
|
---|
40 | ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-firewall-nat', 'ConfigRouterOSFirewallNAT');
|
---|
41 | ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-firewall-mangle', 'ConfigRouterOSFirewallMangle');
|
---|
42 | ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-queue', 'ConfigRouterOSQueue');
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | class PageFreeAccess extends Page
|
---|
47 | {
|
---|
48 | public string $AddressList = 'free-access';
|
---|
49 | public int $Timeout;
|
---|
50 |
|
---|
51 | function __construct(System $System)
|
---|
52 | {
|
---|
53 | parent::__construct($System);
|
---|
54 | $this->Title = 'Internet zdarma';
|
---|
55 | $this->Description = 'Přístup zdarma k Internetu';
|
---|
56 | $this->ParentClass = 'PagePortal';
|
---|
57 |
|
---|
58 | $this->Timeout = 24 * 60 * 60;
|
---|
59 | }
|
---|
60 |
|
---|
61 | function Show(): string
|
---|
62 | {
|
---|
63 | $IPAddress = GetRemoteAddress();
|
---|
64 | $Output = 'Vaše IP adresa je: '.$IPAddress.'<br/>';
|
---|
65 | if (IsInternetAddr($IPAddress))
|
---|
66 | {
|
---|
67 | $Output .= '<p>Internet zdarma je dostupný pouze z vnitřní sítě.</p>';
|
---|
68 | return $Output;
|
---|
69 | }
|
---|
70 | $Time = time();
|
---|
71 |
|
---|
72 | $DbResult = $this->Database->select('NetworkFreeAccess', '*', '(IPAddress="'.$IPAddress.
|
---|
73 | '") ORDER BY Time DESC LIMIT 1');
|
---|
74 | if ($DbResult->num_rows > 0)
|
---|
75 | {
|
---|
76 | $DbRow = $DbResult->fetch_assoc();
|
---|
77 | $ActivationTime = MysqlDateTimeToTime($DbRow['Time']);
|
---|
78 | if (($ActivationTime + $this->Timeout) < $Time)
|
---|
79 | {
|
---|
80 | $Activated = false;
|
---|
81 | } else $Activated = true;
|
---|
82 | } else $Activated = false;
|
---|
83 |
|
---|
84 | if (array_key_exists('a', $_GET))
|
---|
85 | {
|
---|
86 | if ($_GET['a'] == 'activate')
|
---|
87 | {
|
---|
88 | if ($Activated == false)
|
---|
89 | {
|
---|
90 | $DbResult = $this->Database->insert('NetworkFreeAccess',
|
---|
91 | array('IPAddress' => $IPAddress, 'Time' => TimeToMysqlDateTime(time()),
|
---|
92 | 'Configured' => 0));
|
---|
93 | $ActivationTime = $Time;
|
---|
94 | $Activated = true;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 | $Output .= '<div style="text-align:center;"><h3>Vítejte v síti ZděchovNET</h3></div>';
|
---|
99 | $Output .= '<p>Pro přístup k Internetu zdarma sdílenou rychlostí 128/128 kbit/s klikněte na odkaz níže.
|
---|
100 | Internet bude zpřístupněn po dobu 24 hodin. Po uplynutí této doby je potřeba provést novou aktivaci.</p>';
|
---|
101 | $Output .= '<p>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í.</p>';
|
---|
102 |
|
---|
103 | $PrefixMultiplier = new PrefixMultiplier();
|
---|
104 | if ($Activated) $Output .= 'Aktivováno. Vyprší za '.$PrefixMultiplier->Add($ActivationTime + $this->Timeout - $Time, '', 4, 'Time');
|
---|
105 | else $Output .= '<a href="?a=activate">Aktivovat</a>';
|
---|
106 |
|
---|
107 | return $Output;
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | class ScheduleConfigureFreeAccess extends SchedulerTask
|
---|
112 | {
|
---|
113 | function Execute(): string
|
---|
114 | {
|
---|
115 | $Output = '';
|
---|
116 | $Commands = array();
|
---|
117 | $DbResult = $this->Database->select('NetworkFreeAccess', '`Id`, `IPAddress`', '(`Configured`=0)');
|
---|
118 | while ($DbRow = $DbResult->fetch_assoc())
|
---|
119 | {
|
---|
120 | $Commands[] = '/ip firewall address-list add address='.$DbRow['IPAddress'].
|
---|
121 | ' list=free-access timeout=1d';
|
---|
122 | }
|
---|
123 | $DbResult = $this->Database->update('NetworkFreeAccess', '`Configured`=0', array('Configured' => 1));
|
---|
124 |
|
---|
125 | $Routerboard = new Routerboard($this->System->Config['MainRouter']['HostName']);
|
---|
126 | $Routerboard->UserName = $this->System->Config['MainRouter']['UserName'];
|
---|
127 | $Routerboard->Timeout = $this->System->Config['MainRouter']['ConnectTimeout'];
|
---|
128 | $Routerboard->Debug = true;
|
---|
129 | $Routerboard->ExecuteBatch(implode(';', $Commands));
|
---|
130 |
|
---|
131 | return $Output;
|
---|
132 | }
|
---|
133 | }
|
---|