Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
Location:
trunk/Modules/NetworkConfigLinux/Generators
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/NetworkConfigLinux/Generators/CheckPorts.php

    r819 r873  
    77    $Timeout = 1;
    88    $State = 0;
    9     if($Protocol == 'tcp') $Prefix = '';
    10       else if($Protocol == 'udp') $Prefix = 'udp://';
     9    if ($Protocol == 'tcp') $Prefix = '';
     10      else if ($Protocol == 'udp') $Prefix = 'udp://';
    1111      else throw new Exception('Unsupported protocol "'.$Protocol.'"');
    12     if($Socket = @fsockopen($Prefix.$IP, $Port, $ErrorNumber, $ErrorString, $Timeout))
     12    if ($Socket = @fsockopen($Prefix.$IP, $Port, $ErrorNumber, $ErrorString, $Timeout))
    1313    {
    1414      fclose($Socket);
    1515      $State = 1;
    1616    }
    17     return($State);
     17    return ($State);
    1818  }
    1919 
     
    2929      'LEFT JOIN `NetworkInterface` ON `NetworkInterface`.`Id`=`NetworkPort`.`Interface` '.
    3030      'WHERE (`NetworkPort`.`Enabled`=1) AND (`NetworkInterface`.`LocalIP` !="")');
    31     while($DbRow = $DbResult->fetch_assoc())
     31    while ($DbRow = $DbResult->fetch_assoc())
    3232      $Ports[$DbRow['Id']] = $DbRow;
    3333
    34     foreach($Ports as $Index => $Port)
     34    foreach ($Ports as $Index => $Port)
    3535    {
    36       if($Port['Protocol'] == 0) $Port['Protocol'] = 'tcp';
    37       if($Port['Protocol'] == 1) $Port['Protocol'] = 'udp';
     36      if ($Port['Protocol'] == 0) $Port['Protocol'] = 'tcp';
     37      if ($Port['Protocol'] == 1) $Port['Protocol'] = 'udp';
    3838      $Port['NewOnline'] = $this->CheckPortStatus($Port['LocalIP'], $Port['Number'], $Port['Protocol']);
    3939
    4040      // Update last online time if still online
    41       if($Port['NewOnline'])
     41      if ($Port['NewOnline'])
    4242      {
    4343        $DbResult = $this->Database->update('NetworkPort', '`Id` = "'.$Port['Id'].'"',
     
    4646
    4747      // Update UpDown table
    48       if($Port['Online'] != $Port['NewOnline'])
     48      if ($Port['Online'] != $Port['NewOnline'])
    4949      {
    5050        // Online state changed
     
    6565    $DbResult = $this->Database->select('NetworkPort', '*', '(`Online` = 1) AND '.
    6666      '(`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'")');
    67     while($DbRow = $DbResult->fetch_assoc())
     67    while ($DbRow = $DbResult->fetch_assoc())
    6868    {
    6969      echo('Port '.$DbRow['Number'].' online but time not updated.'."\n");
     
    7171    $DbResult = $this->Database->select('NetworkPort', '*', '(`Online` = 0) AND '.
    7272      '(`LastOnline` >= "'.TimeToMysqlDateTime($StartTime).'")');
    73     while($DbRow = $DbResult->fetch_assoc())
     73    while ($DbRow = $DbResult->fetch_assoc())
    7474    {
    7575      echo('Port '.$DbRow['Number'].' not online but time updated.'."\n");
  • trunk/Modules/NetworkConfigLinux/Generators/DHCP.php

    r790 r873  
    11<?php
    22
    3 if(isset($_SERVER['REMOTE_ADDR'])) die();
     3if (isset($_SERVER['REMOTE_ADDR'])) die();
    44/*
    55include_once('../../global.php');
     
    2323'option netbios-scope "";'."\n".
    2424"server-identifier 192.168.0.1;\n\n");
    25 for($i = 0; $i <= $MaxSubnet; $i++)
     25for ($i = 0; $i <= $MaxSubnet; $i++)
    2626{
    2727  fputs($File, "subnet 192.168.".$i.".0 netmask 255.255.255.0 {\n".
     
    3030  "  option routers 192.168.".$i.".1;\n");
    3131  $DbResult = $Database->select('hosts', '*', "IP LIKE '192.168.".$i."%' ORDER BY IP");
    32   while($Row = $DbResult->fetch_array())
     32  while ($Row = $DbResult->fetch_array())
    3333  {
    3434    $Data = $Row['name'];
    35     if(strlen($Data) < 9) $Data .= "\t";
     35    if (strlen($Data) < 9) $Data .= "\t";
    3636    fputs($File, "  host ".$Data."\t{ fixed-address ".$Row['IP'].";\thardware ethernet ".$Row['MAC']."; }\n");
    3737  }
  • trunk/Modules/NetworkConfigLinux/Generators/DNS.php

    r854 r873  
    1818        "\t\t\t".$DNS['Minimum']."\t; minimum\n".
    1919        "\t\t\t)\n";
    20     foreach($DNS['NameServer'] as $NameServer)
     20    foreach ($DNS['NameServer'] as $NameServer)
    2121    {
    2222      $Output .= "\t\tIN\tNS\t".strtolower($NameServer).".\n";
     
    2626    // Mail server records
    2727    $Priority = 10;
    28     foreach($DNS['MailServer'] as $MailServer)
     28    foreach ($DNS['MailServer'] as $MailServer)
    2929    {
    3030      $Output .="\t\t\tMX\t".$Priority." ".strtolower($MailServer).".\n";
     
    3434        $DNS['Domain'].".\tIN\tTXT\t\"v=spf1 mx -all\"\n".
    3535        $DNS['Domain'].".\tIN\tSPF\t\"v=spf1 mx -all\"\n";
    36     foreach($DNS['MailServer'] as $MailServer)
     36    foreach ($DNS['MailServer'] as $MailServer)
    3737    {
    3838      $Output .= $MailServer.".\tIN\tTXT\t\"v=spf1 a -all\"\n".
     
    4545
    4646    // IPv4 host list
    47     foreach($DNS['Host'] as $Host)
    48     {
    49       if(strlen($Host['Name']) < 8) $Host['Name'] .= "\t";
     47    foreach ($DNS['Host'] as $Host)
     48    {
     49      if (strlen($Host['Name']) < 8) $Host['Name'] .= "\t";
    5050      $Output .= strtolower($Host['Name'])."\tIN\tA\t".$Host['Address']."\n";
    5151    }
    5252
    5353    // IPv6 host list
    54     foreach($DNS['Host'] as $Host)
    55     {
    56       if(strlen($Host['Name']) < 8) $Host['Name'] .= "\t";
    57       if(array_key_exists('IPv6', $Host) and ($Host['IPv6'] != ''))
     54    foreach ($DNS['Host'] as $Host)
     55    {
     56      if (strlen($Host['Name']) < 8) $Host['Name'] .= "\t";
     57      if (array_key_exists('IPv6', $Host) and ($Host['IPv6'] != ''))
    5858        $Output .= strtolower($Host['Name'])."\tIN\tAAAA\t".$Host['IPv6']."\n";
    5959    }
    6060
    6161    // Alias list
    62     foreach($DNS['Alias'] as $Alias)
    63     {
    64       if(strlen($Alias['Name']) < 8) $Alias['Name'] .= "\t";
     62    foreach ($DNS['Alias'] as $Alias)
     63    {
     64      if (strlen($Alias['Name']) < 8) $Alias['Name'] .= "\t";
    6565      $Output .= strtolower($Alias['Name'])."\tIN\tCNAME\t".strtolower($Alias['Target'])."\n";
    6666    }
     
    7171
    7272    // Generate reverse DNS records
    73     foreach($DNS['Network'] as $Network)
     73    foreach ($DNS['Network'] as $Network)
    7474    {
    7575      $Parts = explode('.', $Network);
     
    8383      "\t\t\t\t".$DNS['Minimum']."\t; minimum\n".
    8484      "\t\t\t\t)\n";
    85       foreach($DNS['ReverseNameServer'] as $NameServer)
     85      foreach ($DNS['ReverseNameServer'] as $NameServer)
    8686      {
    87         if(substr($NameServer, -strlen($DNS['Domain'])) == $DNS['Domain'])
     87        if (substr($NameServer, -strlen($DNS['Domain'])) == $DNS['Domain'])
    8888          $Output .= "@\tIN\tNS\t".$NameServer.".\n";
    8989        else $Output .= "\tIN\tNS\t".$NameServer.".\n";
    9090      }
    91       foreach($DNS['Host'] as $Host)
    92         if(substr($Host['Address'], 0, strlen($Network)) == $Network)
     91      foreach ($DNS['Host'] as $Host)
     92        if (substr($Host['Address'], 0, strlen($Network)) == $Network)
    9393        {
    9494          $AddressParts = explode('.', $Host['Address']);
     
    103103
    104104    // Generate reverse DNS IPv6 records
    105     foreach($DNS['IPv6Network'] as $Network)
     105    foreach ($DNS['IPv6Network'] as $Network)
    106106    {
    107107      $Parts = explode('/', $Network);
     
    117117      "\t\t\t\t".$DNS['Minimum']."\t; minimum\n".
    118118      "\t\t\t\t)\n";
    119       foreach($DNS['ReverseNameServer'] as $NameServer)
     119      foreach ($DNS['ReverseNameServer'] as $NameServer)
    120120      {
    121         if(substr($NameServer, -strlen($DNS['Domain'])) == $DNS['Domain'])
     121        if (substr($NameServer, -strlen($DNS['Domain'])) == $DNS['Domain'])
    122122          $Output .= "@\tIN\tNS\t".$NameServer.".\n";
    123123        else $Output .= "\tIN\tNS\t".$NameServer.".\n";
    124124      }
    125       foreach($DNS['Host'] as $Host)
    126         if(array_key_exists('IPv6', $Host) and ($Host['IPv6'] != ''))
     125      foreach ($DNS['Host'] as $Host)
     126        if (array_key_exists('IPv6', $Host) and ($Host['IPv6'] != ''))
    127127        {
    128128          $Addr = new NetworkAddressIPv6();
     
    161161    $BaseDir = '/var/cache/bind';
    162162    //$BaseDir = '/home/chronos/Projekty/centrala/trunk/var/named';
    163     if(!file_exists($BaseDir)) die('Base directory "'.$BaseDir.'" not exists.');
     163    if (!file_exists($BaseDir)) die('Base directory "'.$BaseDir.'" not exists.');
    164164    $MailServer = 'centrala';
    165165
     
    193193      'JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` '.
    194194      'WHERE (`NetworkInterface`.`LocalIP` <> "") AND (`NetworkDevice`.`Used` = 1)');
    195     while($Interface = $DbResult->fetch_assoc())
    196     {
    197       $Name = $Interface['DeviceName'];
    198       if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     195    while ($Interface = $DbResult->fetch_assoc())
     196    {
     197      $Name = $Interface['DeviceName'];
     198      if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    199199      $LocalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP'],
    200200          'IPv6' => $Interface['IPv6']);
     
    205205        'JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` '.
    206206        'WHERE (`NetworkInterface`.`ExternalIP` <> "") AND (`NetworkDevice`.`Used` = 1)');
    207     while($Interface = $DbResult->fetch_assoc())
    208     {
    209       $Name = $Interface['DeviceName'];
    210       if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     207    while ($Interface = $DbResult->fetch_assoc())
     208    {
     209      $Name = $Interface['DeviceName'];
     210      if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    211211      $LocalDNS['Host'][] = array('Name' => $Name.'-ext', 'Address' => $Interface['ExternalIP']);
    212212    }
     
    216216     $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '.
    217217     'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.CZFreeIP <> ""');
    218      while($Interface = $DbResult->fetch_assoc())
     218     while ($Interface = $DbResult->fetch_assoc())
    219219     {
    220220     $Name = $Interface['DeviceName'];
    221      if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     221     if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    222222     $LocalDNS['Host'][] = array('Name' => $Name.'-czfree', 'Address' => $Interface['CZFreeIP']);
    223223     }
     
    226226    // Domain aliases
    227227    $DbResult = $this->Database->select('NetworkDomainAlias', '*');
    228     while($Alias = $DbResult->fetch_assoc())
     228    while ($Alias = $DbResult->fetch_assoc())
    229229    {
    230230      $LocalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
     
    257257        'JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` WHERE '.
    258258        '(`NetworkInterface`.`ExternalIP` != "") AND (`NetworkDevice`.`Used` = 1)');
    259     while($Interface = $DbResult->fetch_assoc())
    260     {
    261       $Name = $Interface['DeviceName'];
    262       if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     259    while ($Interface = $DbResult->fetch_assoc())
     260    {
     261      $Name = $Interface['DeviceName'];
     262      if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    263263      $ExternalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['ExternalIP'],
    264264          'IPv6' => $Interface['IPv6']);
     
    268268    $DbResult = $this->Database->query('SELECT `NetworkDomainAlias`.* FROM `NetworkDomainAlias`');
    269269    // JOIN `NetworkDevice` ON NetworkDomainAlias.Target LIKE NetworkDevice.Name AND NetworkInterface.ExternalIP != ""');
    270     while($Alias = $DbResult->fetch_assoc())
     270    while ($Alias = $DbResult->fetch_assoc())
    271271    {
    272272      $ExternalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
     
    302302        'JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` '.
    303303        'WHERE (`NetworkInterface`.`LocalIP` != "") AND (`NetworkDevice`.`Used` = 1)');
    304     while($Interface = $DbResult->fetch_assoc())
    305     {
    306       $Name = $Interface['DeviceName'];
    307       if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     304    while ($Interface = $DbResult->fetch_assoc())
     305    {
     306      $Name = $Interface['DeviceName'];
     307      if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    308308      $CZFreeDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP']);
    309309    }
     
    312312    $DbResult = $this->Database->query('SELECT `NetworkDomainAlias`.* FROM `NetworkDomainAlias`');
    313313    // JOIN `hosts` ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""');
    314     while($Alias = $DbResult->fetch_assoc())
     314    while ($Alias = $DbResult->fetch_assoc())
    315315    {
    316316      $CZFreeDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
     
    344344    $DbResult = $this->Database->query('SELECT `NetworkInterface`.*, `NetworkDevice`.`Name` AS `DeviceName` FROM `NetworkInterface` '.
    345345        'JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` WHERE `NetworkInterface`.`LocalIP` != ""');
    346     while($Interface = $DbResult->fetch_assoc())
    347     {
    348       $Name = $Interface['DeviceName'];
    349       if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     346    while ($Interface = $DbResult->fetch_assoc())
     347    {
     348      $Name = $Interface['DeviceName'];
     349      if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    350350      //  $CZFreeLocalDNS['Host'][] = array('Name' => $Name.'-czfree', 'Address' => $Interface['LocalIP']);
    351351      $CZFreeLocalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP']);
     
    355355    $DbResult = $this->Database->query('SELECT `NetworkDomainAlias`.* FROM `NetworkDomainAlias`');
    356356    // JOIN `hosts` ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""');
    357     while($Alias = $DbResult->fetch_assoc())
     357    while ($Alias = $DbResult->fetch_assoc())
    358358    {
    359359      $CZFreeLocalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']);
  • trunk/Modules/NetworkConfigLinux/Generators/IPTables.php

    r790 r873  
    11<?php
    2 if(isset($_SERVER['REMOTE_ADDR'])) die();
     2if (isset($_SERVER['REMOTE_ADDR'])) die();
    33include_once('../../../Common/Global.php');
    44
     
    1414// Blocking according IP address
    1515$DbResult = $Database->select('users', '*', 'inet = 0');
    16 while($User = $DbResult->fetch_array())
     16while ($User = $DbResult->fetch_array())
    1717{
    1818  $DbResult2 = $Database->select('hosts', '*', "block<2 AND MAC!='' AND user=".$User['id']);
    19   while($Row = $DbResult2->fetch_array())
     19  while ($Row = $DbResult2->fetch_array())
    2020  {
    2121    exec('/sbin/iptables -t nat -A Block -s '.$Row['IP'].' -j Local');
     
    2323}
    2424$DbResult = $Database->select('users', '*', 'inet = 1');
    25 while($User = $DbResult->fetch_array())
     25while ($User = $DbResult->fetch_array())
    2626{
    2727  $DbResult2 = $Database->select('hosts','*',"block<2 AND MAC!='' AND vpn=1 AND user=".$User['id']);
    28   while($Row = $DbResult2->fetch_array())
     28  while ($Row = $DbResult2->fetch_array())
    2929  {
    3030    exec('/sbin/iptables -t nat -A Block -s '.$Row['IP'].' -j Local');
     
    3636// Blocking according MAC address
    3737$DbResult = $Database->select('users', '*');
    38 while($User = $DbResult->fetch_array())
     38while ($User = $DbResult->fetch_array())
    3939{
    4040  //echo($User['fullname']."\n");
    4141  $DbResult2 = $Database->select('hosts', '*', '(block < 2) AND (MAC != "") AND (user='.$User['id'].') AND (IP != external_ip) ORDER BY id DESC');
    42   while($Row = $DbResult2->fetch_array())
     42  while ($Row = $DbResult2->fetch_array())
    4343  {
    4444    //echo(' '.$Row['name']." ".$Row['MAC']." ");
    45     if($User['inet'] == 0)
     45    if ($User['inet'] == 0)
    4646    {
    47       //if(($Row['block'] == 0) and ($Row['type'] == 1)) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");
     47      //if (($Row['block'] == 0) and ($Row['type'] == 1)) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");
    4848      //    else exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Local");
    4949    } else {
    50       if($Row['vpn'] == 0)
     50      if ($Row['vpn'] == 0)
    5151      {
    5252  $CZFreeLocalIP = $Row['IP'];
    5353        //echo($Row['external_ip']."\n");
    54   //if($Row['name'] == 'TBC')
     54  //if ($Row['name'] == 'TBC')
    5555  //{
    5656        //  exec('/sbin/iptables -t nat -A PreroutingDNAT -m tcp -p tcp --dport 3724 -d '.$Row['external_ip'].' -j DNAT --to-destination '.$Row['IP'].':3725');
    5757        //  exec('/sbin/iptables -t nat -A POSTROUTING -m tcp -p tcp -s '.$Row['IP'].' --sport 3725 -o '.$InetInterface.' -j SNAT --to-source '.$Row['external_ip'].':3724');
    5858  //}
    59         if(strtolower($Row['name']) != 'gate')
     59        if (strtolower($Row['name']) != 'gate')
    6060  {
    61       if($Row['external_ip'] != '')
     61      if ($Row['external_ip'] != '')
    6262          {
    6363            echo($Row['name'].'='.$Row['external_ip']."\n");
     
    7575 //echo('vpn');
    7676        //exec('/sbin/iptables -t nat -A PreroutingDNAT -s '.$Row['IP'].' -p udp -m udp --dport 55556 -j DROP');
    77         if($Row['external_ip'] != '') exec('/sbin/iptables -t nat -A PreroutingDNAT -d '.$Row['external_ip'].' -j ACCEPT');
     77        if ($Row['external_ip'] != '') exec('/sbin/iptables -t nat -A PreroutingDNAT -d '.$Row['external_ip'].' -j ACCEPT');
    7878        exec('/sbin/iptables -t nat -A Block -s '.ToVpnIp($Row)." -j Proxy");
    7979
    80         //if($Row['vpn'] == 1)
     80        //if ($Row['vpn'] == 1)
    8181  //{
    8282    //exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Local");
    83         //} else if($Row['vpn'] == 2) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");
     83        //} else if ($Row['vpn'] == 2) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");
    8484      }
    85       if($Row['czfree_ip'] != '')
     85      if ($Row['czfree_ip'] != '')
    8686      {
    8787        // CZFree
  • trunk/Modules/NetworkConfigLinux/Generators/Latency.php

    r852 r873  
    1414      'FROM `NetworkInterface` '.
    1515      'WHERE (`NetworkInterface`.`Enabled`=1) AND (`NetworkInterface`.`LocalIP` !="")');
    16     while($DbRow = $DbResult->fetch_assoc())
     16    while ($DbRow = $DbResult->fetch_assoc())
    1717    {
    1818      $Hosts[] = $DbRow['LocalIP'];
     
    2323
    2424    $Queries = array();
    25     foreach($Output as $Index => $Line)
     25    foreach ($Output as $Index => $Line)
    2626    {
    2727      $IP = substr($Line, 0, strPos($Line, ' '));
  • trunk/Modules/NetworkConfigLinux/Generators/NAT.php

    r790 r873  
    11<?php
    2 if(isset($_SERVER['REMOTE_ADDR'])) die();
     2if (isset($_SERVER['REMOTE_ADDR'])) die();
    33include_once('../../../Common/Global.php');
    44
     
    1414// Blocking according IP address
    1515$DbResult = $Database->select('users', '*', 'inet = 0');
    16 while($User = $DbResult->fetch_array())
     16while ($User = $DbResult->fetch_array())
    1717{
    1818  $DbResult2 = $Database->select('hosts', '*', "block<2 AND MAC!='' AND user=".$User['id']);
    19   while($Row = $DbResult2->fetch_array())
     19  while ($Row = $DbResult2->fetch_array())
    2020  {
    2121    exec('/sbin/iptables -t nat -A Block -s '.$Row['IP'].' -j Local');
     
    2323}
    2424$DbResult = $Database->select('users', '*', 'inet = 1');
    25 while($User = $DbResult->fetch_array())
     25while ($User = $DbResult->fetch_array())
    2626{
    2727  $DbResult2 = $Database->select('hosts','*',"block<2 AND MAC!='' AND vpn=1 AND user=".$User['id']);
    28   while($Row = $DbResult2->fetch_array())
     28  while ($Row = $DbResult2->fetch_array())
    2929  {
    3030    exec('/sbin/iptables -t nat -A Block -s '.$Row['IP'].' -j Local');
     
    3636// Blocking according MAC address
    3737$DbResult = $Database->select('users', '*');
    38 while($User = $DbResult->fetch_array())
     38while ($User = $DbResult->fetch_array())
    3939{
    4040  //echo($User['fullname']."\n");
    4141  $DbResult2 = $Database->select('hosts','*','block<2 AND MAC!="" AND user='.$User['id'].' ORDER BY id DESC');
    42   while($Row = $DbResult2->fetch_array())
     42  while ($Row = $DbResult2->fetch_array())
    4343  {
    4444    //echo(' '.$Row['name']." ".$Row['MAC']." ");
    45     if($User['inet'] == 0)
     45    if ($User['inet'] == 0)
    4646    {
    47       //if(($Row['block'] == 0) and ($Row['type'] == 1)) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");
     47      //if (($Row['block'] == 0) and ($Row['type'] == 1)) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");
    4848      //    else exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Local");
    4949    } else {
    50       if($Row['vpn'] == 0)
     50      if ($Row['vpn'] == 0)
    5151      {
    5252  $CZFreeLocalIP = $Row['IP'];
    5353        //echo($Row['external_ip']."\n");
    54   //if($Row['name'] == 'TBC')
     54  //if ($Row['name'] == 'TBC')
    5555  //{
    5656        //  exec('/sbin/iptables -t nat -A PreroutingDNAT -m tcp -p tcp --dport 3724 -d '.$Row['external_ip'].' -j DNAT --to-destination '.$Row['IP'].':3725');
    5757        //  exec('/sbin/iptables -t nat -A POSTROUTING -m tcp -p tcp -s '.$Row['IP'].' --sport 3725 -o eth1 -j SNAT --to-source '.$Row['external_ip'].':3724');
    5858  //}
    59         if(strtolower($Row['name']) != 'centrala')
     59        if (strtolower($Row['name']) != 'centrala')
    6060  {
    61       if($Row['external_ip'] != '')
     61      if ($Row['external_ip'] != '')
    6262          {
    6363            echo($Row['name'].'='.$Row['external_ip']."\n");
     
    7575 //echo('vpn');
    7676        //exec('/sbin/iptables -t nat -A PreroutingDNAT -s '.$Row['IP'].' -p udp -m udp --dport 55556 -j DROP');
    77         if($Row['external_ip'] != '') exec('/sbin/iptables -t nat -A PreroutingDNAT -d '.$Row['external_ip'].' -j ACCEPT');
     77        if ($Row['external_ip'] != '') exec('/sbin/iptables -t nat -A PreroutingDNAT -d '.$Row['external_ip'].' -j ACCEPT');
    7878        exec('/sbin/iptables -t nat -A Block -s '.ToVpnIp($Row)." -j Proxy");
    7979
    80         //if($Row['vpn'] == 1)
     80        //if ($Row['vpn'] == 1)
    8181  //{
    8282    //exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Local");
    83         //} else if($Row['vpn'] == 2) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");
     83        //} else if ($Row['vpn'] == 2) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");
    8484      }
    85       if($Row['czfree_ip'] != '')
     85      if ($Row['czfree_ip'] != '')
    8686      {
    8787        // CZFree
  • trunk/Modules/NetworkConfigLinux/Generators/TrafficShaping.php

    r790 r873  
    11<?php
    22
    3 if(isset($_SERVER['REMOTE_ADDR'])) die();
     3if (isset($_SERVER['REMOTE_ADDR'])) die();
    44
    55$Enabled = 1;
     
    3737  exec('/sbin/iptables -t mangle -F PREROUTING');
    3838  exec('/sbin/iptables -t mangle -F POSTROUTING');
    39   if($Enabled)
     39  if ($Enabled)
    4040  {
    4141    //exec('/sbin/iptables -t mangle -A FORWARD -j MARK --set-mark 0');
     
    4848  // In going traffic
    4949  fputs($File, "/sbin/tc qdisc del dev ".$InInterface." root\n");
    50   if($Enabled)
     50  if ($Enabled)
    5151  {
    5252    fputs($File, "/sbin/tc qdisc add dev ".$InInterface." root handle 1:0 htb default 2\n");
     
    5959  // Out going traffic
    6060  fputs($File, "/sbin/tc qdisc del dev ".$OutInterface." root\n");
    61   if($Enabled)
     61  if ($Enabled)
    6262  {
    6363    fputs($File, "/sbin/tc qdisc add dev ".$OutInterface." root handle 1:0 htb default 2\n");
     
    6969  }
    7070
    71   if(!$Enabled) die("Traffic shaping disabled\n");
    72 
    73   if($ClassesEnabled)
     71  if (!$Enabled) die("Traffic shaping disabled\n");
     72
     73  if ($ClassesEnabled)
    7474  {
    7575  $ClassId = 3;
     
    124124
    125125  $DbResult = $Database->select('users', '*, CONCAT(second_name, " ", first_name) as fullname', '(inet=1)');
    126   while($User = $DbResult->fetch_array())
     126  while ($User = $DbResult->fetch_array())
    127127  {
    128128    $UserClassId = $ClassId;
     
    152152
    153153    $DbResult2 = $Database->select('hosts','*',"block=0 AND MAC!='' AND user=".$User['id']);
    154     while($Host = $DbResult2->fetch_array())
    155     //if($Row['name'] != 'WOW')
     154    while ($Host = $DbResult2->fetch_array())
     155    //if ($Row['name'] != 'WOW')
    156156    {
    157157      $HostClassId = $ClassId;
     
    160160      fputs($FileClassInfo, '1:'.$HostClassId.' '.$Host['name']."\n");
    161161      //echo('  Host class id: '.$HostClassId."\n");
    162     //if($User['inet'] == 1)
     162    //if ($User['inet'] == 1)
    163163      {
    164164        $Prio = 1;
    165         if($Host['vpn'] == 1)
     165        if ($Host['vpn'] == 1)
    166166        {
    167           if($Host['external_ip'] != '') $Host['IP'] = $Host['external_ip'];
     167          if ($Host['external_ip'] != '') $Host['IP'] = $Host['external_ip'];
    168168          else $Host['IP'] = ToVpnIp($Host);
    169169        }
    170170
    171         //if($Host['name'] == 'TERMINAL') $SpeedDivider = 0.5;
     171        //if ($Host['name'] == 'TERMINAL') $SpeedDivider = 0.5;
    172172          //else
    173173        $SpeedDivider = 1;
    174174
    175         if($Host['name'] == 'centrala')
     175        if ($Host['name'] == 'centrala')
    176176        {
    177177          $Host['IP'] = $Host['external_ip'];
     
    183183           $TableIn = 'FORWARD';
    184184         }
    185         //if($Row['name'] == 'TERMINAL2') $Prio = 0;
    186         //  if($Row['name'] = 'TERMINAL2') $Prio = 0;
    187         if($Host['name'] == 'voip-hajda') $Protocol = ' -p tcp';
     185        //if ($Row['name'] == 'TERMINAL2') $Prio = 0;
     186        //  if ($Row['name'] = 'TERMINAL2') $Prio = 0;
     187        if ($Host['name'] == 'voip-hajda') $Protocol = ' -p tcp';
    188188        else $Protocol = '';
    189         //  if($Host['name'] == 'KARLOS') $UserMaxSpeedIn = 128000;
     189        //  if ($Host['name'] == 'KARLOS') $UserMaxSpeedIn = 128000;
    190190        /*
    191 if($Host['name'] == 'GAME')
     191if ($Host['name'] == 'GAME')
    192192        {
    193193          exec('/sbin/iptables -t mangle -F game-server');
     
    195195          $TableIn = 'game-server';
    196196        }*/
    197         //if($Host['name'] == 'TBC') continue;
     197        //if ($Host['name'] == 'TBC') continue;
    198198
    199199        // In going traffic
     
    213213      }
    214214      // Free inet
    215       if($Tarify[$User['inet_tarif_now']]['group_id'] == 3)
     215      if ($Tarify[$User['inet_tarif_now']]['group_id'] == 3)
    216216      {
    217217        //exec('/sbin/iptables -t mangle -A '.$TableIn.' -i eth1 -d '.$Host['IP'].$Protocol." -j MARK --set-mark ".$FreeInetClass);
     
    220220      // VoIP devices
    221221/*
    222       if(($Host['name'] == 'HAJDA-VOIP') || ($Host['name'] == 'NAVRATIL-VOIP'))
     222      if (($Host['name'] == 'HAJDA-VOIP') || ($Host['name'] == 'NAVRATIL-VOIP'))
    223223      {
    224224        exec('/sbin/iptables -t mangle -A '.$TableIn." -i eth1 -d ".$Host['IP']." -p udp -j MARK --set-mark ".$VoipClassId);
    225225        exec('/sbin/iptables -t mangle -A '.$TableOut." -o eth1 -s ".$Host['IP']." -p udp -j MARK --set-mark ".$VoipClassId);
    226226      } else
    227       if($Host['name'] == 'GAME')
     227      if ($Host['name'] == 'GAME')
    228228      {
    229229        exec('/sbin/iptables -t mangle -A FORWARD -o eth1 -s '.$Host['IP']." -j game-server");
Note: See TracChangeset for help on using the changeset viewer.