Changeset 735


Ignore:
Timestamp:
Apr 6, 2015, 1:03:33 PM (9 years ago)
Author:
chronos
Message:
  • Added: Support for Internet free access. Unregistered users are redirected to activation page where they can found useful information and activate free access for 24 hours.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Version.php

    r731 r735  
    11<?php
    22
    3 $Revision = 731; // Subversion revision
    4 $DatabaseRevision = 731; // SQL structure revision
    5 $ReleaseTime = strtotime('2015-01-14');
     3$Revision = 735; // Subversion revision
     4$DatabaseRevision = 735; // SQL structure revision
     5$ReleaseTime = strtotime('2015-04-06');
  • trunk/Common/Setup/Updates.php

    r734 r735  
    13061306  $Manager->Execute('ALTER TABLE `ModuleLink`
    13071307        MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT;');
     1308}
     1309
     1310function UpdateTo735($Manager)
     1311{
     1312        $Manager->Execute('CREATE TABLE IF NOT EXISTS `NetworkFreeAccess` (
     1313`Id` int(11) NOT NULL,
     1314`IPAddress` varchar(255) NOT NULL,
     1315`Time` datetime NOT NULL
     1316) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
     1317       
     1318        $Manager->Execute('ALTER TABLE `NetworkFreeAccess`
     1319        ADD PRIMARY KEY (`Id`);');
     1320       
     1321        $Manager->Execute('ALTER TABLE `NetworkFreeAccess`
     1322        MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;');
     1323       
     1324        $Manager->Execute('ALTER TABLE `NetworkFreeAccess` ADD `Configured` INT NOT NULL ;');
     1325        $DbResult = $Manager->Execute('INSERT INTO `SchedulerAction` (`Id`, `Name`, `Class`) VALUES '.
     1326                '(NULL, "Konfigurace internetu zdarma", "ScheduleConfigureFreeAccess");');
     1327        $ActionId = $Manager->Database->insert_id;
     1328        $Manager->Execute('INSERT INTO `Scheduler` (`Id`, `Name`, `Enabled`, `Action`,
     1329                `Log`, `LastExecutedTime`, `ScheduledTime`, `Period`) VALUES (NULL, "Internet zdarma",
     1330                1, '.$ActionId.', "", NULL, "", 5);');
     1331        $Manager->Execute('ALTER TABLE `Scheduler` CHANGE `ScheduledTime` `ScheduledTime` DATETIME NULL;');
    13081332}
    13091333
     
    13721396        729 => array('Revision' => 730, 'Function' => 'UpdateTo730'),
    13731397        730 => array('Revision' => 731, 'Function' => 'UpdateTo731'),
     1398        731 => array('Revision' => 735, 'Function' => 'UpdateTo735'),
    13741399    ));
    13751400  }
  • trunk/Modules/FinanceBankAPI/FinanceBankAPI.php

    r730 r735  
    8888        {
    8989                $Output = '';
    90                 $DbResult = $this->Database->select('FinanceBankAccount', 'Id', '(`AutoImport`=1) AND ((`TimeEnd` IS NULL) OR (`TimeEnd` > NOW()))');
     90                $DbResult = $this->Database->select('FinanceBankAccount', 'Id, Comment',
     91                        '(`AutoImport`=1) AND ((`TimeEnd` IS NULL) OR (`TimeEnd` > NOW()))');
    9192                while($DbRow = $DbResult->fetch_assoc())
    9293                {                       
  • trunk/Modules/NetworkConfigRouterOS/Generators/FirewallMangle.php

    r617 r735  
    133133// Slow free internet
    134134$PacketMark = GetMarkByComment('free-out');
    135 $ItemsFirewall[] = array('chain' => 'inet-1-out', 'out-interface' => $InetInterface, 'action' => 'mark-packet', 'new-packet-mark' => $PacketMark, 'comment' => 'free-out', 'passthrough' => 'no');
     135$ItemsFirewall[] = array('chain' => 'inet-1-out', 'out-interface' => $InetInterface,
     136  'action' => 'mark-packet', 'new-packet-mark' => $PacketMark, 'comment' => 'free-out', 'passthrough' => 'yes');
    136137$PacketMark = GetMarkByComment('free-in');
    137 $ItemsFirewall[] = array('chain' => 'inet-1-in', 'in-interface' => $InetInterface, 'action' => 'mark-packet', 'new-packet-mark' => $PacketMark, 'comment' => 'free-in', 'passthrough' => 'no');
    138 
     138$ItemsFirewall[] = array('chain' => 'inet-1-in', 'in-interface' => $InetInterface,
     139        'action' => 'mark-packet', 'new-packet-mark' => $PacketMark, 'comment' => 'free-in', 'passthrough' => 'no');
     140// Unregistred clients add to address list
     141$ItemsFirewall[] = array('chain' => 'inet-1-out', 'out-interface' => $InetInterface, 'src-address' => '10.145.0.0/16',
     142        'action' => 'add-src-to-address-list', 'address-list' => 'unregistred', 'timeout' => '1d',
     143        'comment' => 'unregistred-clients');
    139144
    140145//print_r($ItemsFirewall);
  • trunk/Modules/NetworkConfigRouterOS/Generators/FirewallNAT.php

    r617 r735  
    109109$Items[] = array('chain' => 'dstnat', 'dst-address' => '212.111.4.174', 'protocol' => 'udp', 'dst-port' => 53, 'in-interface' => $InetInterface, 'action' => 'dst-nat', 'to-addresses' => '10.145.64.8', 'to-ports' => 53, 'comment' => 'DNS_redirection_UDP');
    110110
    111 
    112111// Chain for local interface
    113112$Items[] = array('chain' => 'srcnat', 'out-interface' => $LocalInterface, 'action' => 'jump', 'jump-target' => 'local-out', 'comment' => 'local-out');
    114113$Items[] = array('chain' => 'dstnat', 'in-interface' => $LocalInterface, 'action' => 'jump', 'jump-target' => 'local-in', 'comment' => 'local-in');
     114
     115// Accept free-access clients
     116$Items[] = array('chain' => 'dstnat', 'dst-address' => '!10.145.0.0/16',
     117        'src-address-list' => 'free-access', 'in-interface' => $LocalInterface,
     118        'action' => 'accept', 'comment' => 'Free_access');
     119// Redirect unregistred clients to free access activation page
     120$Items[] = array('chain' => 'dstnat', 'dst-address' => '!10.145.0.0/16',
     121        'src-address-list' => 'unregistred', 'in-interface' => $LocalInterface,
     122        'action' => 'dst-nat', 'to-addresses' => '10.145.64.8', 'to-ports' => 82, 'comment' => 'Redirect_unregistred');
    115123
    116124/*
  • trunk/Modules/NetworkConfigRouterOS/NetworkConfigRouterOS.php

    r696 r735  
    2828  function DoStart()
    2929  {
     30        $this->System->Pages['zdarma'] = 'PageFreeAccess';
    3031    $this->System->FormManager->RegisterClass('NetworkInterfaceUpDown', array(
    3132      'Title' => 'Změny stavu rozhraní',
     
    4243  }
    4344}
     45
     46class PageFreeAccess extends Page
     47{
     48  var $FullTitle = 'Přístup zdarma k Internetu';
     49  var $ShortTitle = 'Internet zdarma';
     50  var $ParentClass = 'PagePortal';
     51  var $AddressList = 'free-access';
     52  var $Timeout;
     53 
     54  function __construct($System)
     55  {
     56        parent::__construct($System);
     57        $this->Timeout = 24 * 60 * 60;
     58  }
     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)
     74      {
     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);
     104  }
     105}
     106
     107class ScheduleConfigureFreeAccess extends SchedulerTask
     108{
     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        }
     129}
  • trunk/Modules/Scheduler/Scheduler.php

    r730 r735  
    6464          $DbResult = $this->Database->query('SELECT `Scheduler`.*, `SchedulerAction`.`Class` AS `Class` FROM `Scheduler` '.
    6565                'LEFT JOIN `SchedulerAction` ON `SchedulerAction`.`Id` = `Scheduler`.`Action` '.
    66                 'WHERE (`Scheduler`.`Enabled`=1) AND (`Scheduler`.`ScheduledTime` > `Scheduler`.`LastExecutedTime`)');
     66                'WHERE (`Scheduler`.`Enabled`=1) AND (((`Scheduler`.`ScheduledTime` < "'.TimeToMysqlDateTime(time()).'") AND '.
     67                ' (`Scheduler`.`LastExecutedTime` < `Scheduler`.`ScheduledTime`)) OR '.
     68                '(`Scheduler`.`ScheduledTime` IS NULL))');
    6769          while($DbRow = $DbResult->fetch_assoc())
    6870          {
     
    7678                          $this->Database->update('Scheduler', 'Id='.$DbRow['Id'],
    7779                          array('Log' => $Output, 'LastExecutedTime' => 'NOW()'));
     80                          if($DbRow['ScheduledTime'] == '') $NewScheduledTime = time() + $DbRow['Period'];
     81                            else $NewScheduledTime = MysqlDateTimeToTime($DbRow['ScheduledTime']) + $DbRow['Period']; 
    7882                        if($DbRow['Period'] != '') $this->Database->update('Scheduler', 'Id='.$DbRow['Id'],
    79                                 array('ScheduledTime' => TimeToMysqlDateTime((MysqlDateTimeToTime($DbRow['ScheduledTime']) + $DbRow['Period']))));                       
     83                                array('ScheduledTime' => TimeToMysqlDateTime($NewScheduledTime)));                       
    8084          }     
    8185          echo('.');
Note: See TracChangeset for help on using the changeset viewer.