Ignore:
Timestamp:
Apr 14, 2015, 10:20:16 PM (9 years ago)
Author:
chronos
Message:
  • Removed: Spaces on end of line.
  • Modified: Tabs converted to spaces.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/NetworkConfigRouterOS/NetworkConfigRouterOS.php

    r735 r738  
    2828  function DoStart()
    2929  {
    30         $this->System->Pages['zdarma'] = 'PageFreeAccess';
     30    $this->System->Pages['zdarma'] = 'PageFreeAccess';
    3131    $this->System->FormManager->RegisterClass('NetworkInterfaceUpDown', array(
    3232      'Title' => 'Změny stavu rozhraní',
     
    4444}
    4545
    46 class PageFreeAccess extends Page 
     46class PageFreeAccess extends Page
    4747{
    4848  var $FullTitle = 'Přístup zdarma k Internetu';
     
    5151  var $AddressList = 'free-access';
    5252  var $Timeout;
    53  
     53
    5454  function __construct($System)
    5555  {
    56         parent::__construct($System);
    57         $this->Timeout = 24 * 60 * 60;
     56    parent::__construct($System);
     57    $this->Timeout = 24 * 60 * 60;
    5858  }
    59  
    60         function Show()
    61         {
    62                 $IPAddress = GetRemoteAddress();
    63                 if(IsInternetAddr($IPAddress))
    64                         return('<p>Internet zdarma je dostupný pouze z vnitřní sítě.</p>'); 
    65                 $Time = time();
    66        
    67                 $DbResult = $this->Database->select('NetworkFreeAccess', '*', '(IPAddress="'.$IPAddress.
    68                         '") ORDER BY Time DESC LIMIT 1');
    69                 if($DbResult->num_rows > 0)
    70                 {
    71                         $DbRow = $DbResult->fetch_assoc();
    72                         $ActivationTime = MysqlDateTimeToTime($DbRow['Time']);
    73       if(($ActivationTime + $this->Timeout) < $Time) 
     59
     60  function Show()
     61  {
     62    $IPAddress = GetRemoteAddress();
     63    if(IsInternetAddr($IPAddress))
     64      return('<p>Internet zdarma je dostupný pouze z vnitřní sítě.</p>');
     65    $Time = time();
     66
     67    $DbResult = $this->Database->select('NetworkFreeAccess', '*', '(IPAddress="'.$IPAddress.
     68      '") ORDER BY Time DESC LIMIT 1');
     69    if($DbResult->num_rows > 0)
     70    {
     71      $DbRow = $DbResult->fetch_assoc();
     72      $ActivationTime = MysqlDateTimeToTime($DbRow['Time']);
     73      if(($ActivationTime + $this->Timeout) < $Time)
    7474      {
    75         $Activated = false;
    76       } else $Activated = true;                 
    77                 } else $Activated = false;
    78                
    79                 if(array_key_exists('a', $_GET))
    80                 {
    81                   if($_GET['a'] == 'activate')
    82                   {
    83                         if($Activated == false)
    84                         {
    85                                 $DbResult = $this->Database->insert('NetworkFreeAccess',
    86                                         array('IPAddress' => $IPAddress, 'Time' => TimeToMysqlDateTime(time()),
    87                                         'Configured' => 0));
    88                                 $ActivationTime = $Time;
    89                                 $Activated = true;
    90                         }
    91                   }     
    92                 }
    93                 $Output = '<div style="text-align:center;"><h3>Vítejte v síti ZděchovNET</h3></div>';
    94                 //$Output .= 'Vaše adresa IP je: '.GetRemoteAddress().'<br/>';         
    95                 $Output .= '<p>Pro přístup k Internetu zdarma sdílenou rychlostí 128/128 kbit/s klikněte na odkaz níže.
    96                         Internet bude zpřístupněn po dobu 24 hodin. Po uplynutí této doby je potřeba provést novou aktivaci.</p>';
    97                 $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>';
    98                
    99                 $PrefixMultiplier = new PrefixMultiplier();
    100                 if($Activated) $Output .= 'Aktivováno. Vyprší za '.$PrefixMultiplier->Add($ActivationTime + $this->Timeout - $Time, '', 4, 'Time');
    101                   else $Output .= '<a href="?a=activate">Aktivovat</a>';
    102                
    103                 return($Output);
     75        $Activated = false;
     76      } else $Activated = true;
     77    } else $Activated = false;
     78
     79    if(array_key_exists('a', $_GET))
     80    {
     81      if($_GET['a'] == 'activate')
     82      {
     83        if($Activated == false)
     84        {
     85          $DbResult = $this->Database->insert('NetworkFreeAccess',
     86            array('IPAddress' => $IPAddress, 'Time' => TimeToMysqlDateTime(time()),
     87            'Configured' => 0));
     88          $ActivationTime = $Time;
     89          $Activated = true;
     90        }
     91      }
     92    }
     93    $Output = '<div style="text-align:center;"><h3>Vítejte v síti ZděchovNET</h3></div>';
     94    //$Output .= 'Vaše adresa IP je: '.GetRemoteAddress().'<br/>';
     95    $Output .= '<p>Pro přístup k Internetu zdarma sdílenou rychlostí 128/128 kbit/s klikněte na odkaz níže.
     96      Internet bude zpřístupněn po dobu 24 hodin. Po uplynutí této doby je potřeba provést novou aktivaci.</p>';
     97    $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>';
     98
     99    $PrefixMultiplier = new PrefixMultiplier();
     100    if($Activated) $Output .= 'Aktivováno. Vyprší za '.$PrefixMultiplier->Add($ActivationTime + $this->Timeout - $Time, '', 4, 'Time');
     101      else $Output .= '<a href="?a=activate">Aktivovat</a>';
     102
     103    return($Output);
    104104  }
    105105}
     
    107107class ScheduleConfigureFreeAccess extends SchedulerTask
    108108{
    109         function Execute()
    110         {
    111                 $Output = '';
    112                 $Commands = array();
    113                 $DbResult = $this->Database->select('NetworkFreeAccess', '`Id`, `IPAddress`', '(`Configured`=0)');
    114                 while($DbRow = $DbResult->fetch_assoc())
    115                 {
    116                         $Commands[] = '/ip firewall address-list add address='.$DbRow['IPAddress'].
    117                         ' list=free-access timeout=1d';
    118                 }
    119                 $DbResult = $this->Database->update('NetworkFreeAccess', '`Configured`=0', array('Configured' => 1));
    120                
    121                 $Routerboard = new Routerboard($this->System->Config['MainRouter']['HostName']);
    122                 $Routerboard->UserName = $this->System->Config['MainRouter']['UserName'];
    123                 $Routerboard->Timeout = $this->System->Config['MainRouter']['ConnectTimeout'];
    124                 $Routerboard->Debug = true;
    125                 $Routerboard->ExecuteBatch(implode(';', $Commands));
    126                                        
    127                 return($Output);
    128         }
     109  function Execute()
     110  {
     111    $Output = '';
     112    $Commands = array();
     113    $DbResult = $this->Database->select('NetworkFreeAccess', '`Id`, `IPAddress`', '(`Configured`=0)');
     114    while($DbRow = $DbResult->fetch_assoc())
     115    {
     116      $Commands[] = '/ip firewall address-list add address='.$DbRow['IPAddress'].
     117      ' list=free-access timeout=1d';
     118    }
     119    $DbResult = $this->Database->update('NetworkFreeAccess', '`Configured`=0', array('Configured' => 1));
     120
     121    $Routerboard = new Routerboard($this->System->Config['MainRouter']['HostName']);
     122    $Routerboard->UserName = $this->System->Config['MainRouter']['UserName'];
     123    $Routerboard->Timeout = $this->System->Config['MainRouter']['ConnectTimeout'];
     124    $Routerboard->Debug = true;
     125    $Routerboard->ExecuteBatch(implode(';', $Commands));
     126
     127    return($Output);
     128  }
    129129}
Note: See TracChangeset for help on using the changeset viewer.