Changeset 213


Ignore:
Timestamp:
May 10, 2009, 12:30:09 PM (16 years ago)
Author:
george
Message:

Opraveno: Skripty pro generování nastavení směrovačů.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/config.sample.php

    r212 r213  
    4747   'Password' => '',
    4848   'InetInterface' => 'ether0',
     49   'ConnectTimeout' => 5,
    4950  ), 
    5051);
  • trunk/system/generators/dhcp_routerboard.php

    r208 r213  
    77while($Subnet = $DbResult->fetch_assoc())
    88{
    9   //print_r($Subnet);
     9  echo($Subnet['DHCP']);
    1010  $I = explode('.', $Subnet['AddressRange']);
    1111  $I = $I[2];
     
    1818  }
    1919  $Commands = implode(';', $Commands);
    20   $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Subnet['DHCP'].' "'.$Commands.'"';
     20  $Command = '/usr/bin/ssh -o ConnectTimeout=5 -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Subnet['DHCP'].' "'.$Commands.'"';
    2121  //echo($Command."\n");
    2222  $Output = '';
  • trunk/system/generators/dns.php

    r211 r213  
    3434"\t\t\tMX\t10 ".$MailServer.".".$BaseDomain.".\n");
    3535
    36 $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetwordInterface.Device WHERE NetworkInterface.LocalIP <> ""');
     36$DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.LocalIP <> ""');
    3737while($Interface = $DbResult->fetch_assoc())
    3838{
     
    4545
    4646// External records in internal server
    47 $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetwordInterface.Device WHERE NetworkInterface.ExternalIP <> ""');
     47$DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.ExternalIP <> ""');
    4848while($Interface = $DbResult->fetch_assoc())
    4949{
     
    117117    if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    118118    $Name = strtolower($Name.'-ext');
    119     $IP = explode('.',$Interafce['ExternalIP']);
    120     fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Name])."-ext.".$BaseDomain.".\n");
     119    $IP = explode('.',$Interface['ExternalIP']);
     120    fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Name)."-ext.".$BaseDomain.".\n");
    121121  }
    122122  fclose($File);
     
    191191  "\t\t\tNS\t".$NameServers[1].".".$BaseDomain.".\n");
    192192
    193   $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetwordInterface.Device WHERE NetworkInterface.ExternalIP LIKE "'.$Network.'.%"');
     193  $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.ExternalIP LIKE "'.$Network.'.%"');
    194194  while($Interface = $DbResult->fetch_assoc())
    195195  {
     
    197197    if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    198198    $Name = strtolower($Name);
    199     if(strlen($Name) < 8) $Name .= "\t";
     199    //if(strlen($Name) < 8) $Name .= "\t";
    200200    $IP = explode('.', $Interface['ExternalIP']);
    201     fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Interface['Name']).".".$BaseDomain.".\n");
     201    fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Name).".".$BaseDomain.".\n");
    202202  }
    203203
     
    254254  fputs($File, $Name."\tIN\tA\t".$Interface['CZFreeIP']."\n");
    255255  fputs($File2, $Name."\tIN\tA\t".$Interface['LocalIP']."\n");
     256  $Name = $Interface['DeviceName'];
     257  if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     258  $Name = strtolower($Name);
    256259  $Name .= '-czfree';
    257260  fputs($File2, $Name."\tIN\tA\t".$Interface['CZFreeIP']."\n");
    258261}
    259262
    260 $DbResult = $Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias` JOIN `hosts`  ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""');
     263$DbResult = $Database->query('SELECT NetworkDomainAlias.* FROM `NetworkDomainAlias`');
     264// JOIN `hosts`  ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""');
    261265while($Alias = $DbResult->fetch_assoc())
    262266{
     
    303307  fputs($File2, $Header);
    304308
    305   $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetwordInterface.Device WHERE NetworkInterface.CZFreeIP LIKE "'.$Network.'.%"');
     309  $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.CZFreeIP LIKE "'.$Network.'.%"');
    306310  while($Interface = $DbResult->fetch_assoc())
    307311  {
     
    309313    if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    310314    $Name = strtolower($Name);
     315    $Name2 = $Name;
    311316    if(strlen($Name) < 8) $Name .= "\t";
    312317    $IP = explode('.', $Interface['CZFreeIP']);
    313     fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Interface['Name']).".".$Domain.".\n");
    314     fputs($File2, $IP[3]."\tIN\tPTR\t".strtolower($Interface['Name'].'-czfree').".".$Domain.".\n");
     318    fputs($File, $IP[3]."\tIN\tPTR\t".strtolower($Name2).".".$Domain.".\n");
     319    fputs($File2, $IP[3]."\tIN\tPTR\t".strtolower($Name2.'-czfree').".".$Domain.".\n");
    315320  }
    316321
  • trunk/system/generators/generate.php

    r197 r213  
    1818      if($Command != '')
    1919      {
    20         //exec($Command, $Output);       
    21         echo($Command."\n");
    22         sleep(5);
     20        exec($Command, $Output);       
     21        //echo($Command."\n");
     22        //sleep(5);
    2323      }
    2424    //echo("Done\n");
  • trunk/system/generators/nat_routerboard.php

    r208 r213  
    1717  while($Interface = $DbResult2->fetch_assoc())
    1818  {
    19     $Name = $Interface['DeviceName'].'-'.$Interface['Name'];
     19    $Name = $Interface['DeviceName'];
     20    if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    2021    $Name = RouterOSIdent($Name);
    2122    echo($Name.'('.$Interface['LocalIP'].'), ');
     
    4748
    4849$Commands = addslashes(implode(';', $Commands));
    49 $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Config['MainRouter']['HostName'].' "'.$Commands.'"';
     50$Command = '/usr/bin/ssh -o ConnectTimeout=5 -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Config['MainRouter']['HostName'].' "'.$Commands.'"';
    5051$Output = array();
    5152//echo($Command."\n");
  • trunk/system/generators/netwatch.php

    r208 r213  
    77while($Router = $DbResult3->fetch_assoc())
    88{
     9  echo($Router['DHCP']."\n");
    910  $Commands = array();
    1011  $Commands[] = '/tool netwatch remove [find]';
     
    1819    while($Interface = $DbResult2->fetch_assoc())
    1920    {
    20       $Commands[] = '/tool netwatch add host='.$Interface['LocalIP'].' interval=1m comment='.$Interface['DeviceName'].'-'.$Interface['Name'];
     21      $Name = $Interface['DeviceName'];
     22      if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     23      $Commands[] = '/tool netwatch add host='.$Interface['LocalIP'].' interval=1m comment='.$Name;
    2124    }
    2225  }
    2326  $Commands = implode(';', $Commands);
    24   $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Router['DHCP'].' "'.$Commands.'"';
     27  $Command = '/usr/bin/ssh -o ConnectTimeout='.$Config['MainRouter']['ConnectTimeout'].' -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Router['DHCP'].' "'.$Commands.'"';
    2528  //echo($Command."\n");
    2629  $Output = '';
  • trunk/system/generators/traffic_shaping_routerboard.php

    r208 r213  
    7575  $Commands[] = ' /queue tree add name='.$Member['Name'].'-in limit-at='.$SpeedOut.' max-limit='.$UserMaxSpeedOut.' parent=main-in queue=wireless-default';
    7676
    77   $DbResult2 = $Database->select('hosts', 'COUNT(*)', '(block = 0) AND (MAC != "") AND (user='.$Member['Id'].')');
    78   $Row = $DbResult2->fetch_array();
     77  $DbResult2 = $Database->select('NetworkDevice', 'COUNT(*)', 'Member='.$Member['Id']);
     78  $Row = $DbResult2->fetch_row();
    7979  $HostCount = $Row[0];
    8080  if($HostCount > 0)
     
    9191  while($Device = $DbResult2->fetch_assoc())
    9292  {
    93     $DbResult3 = $Database->select('NetworkInterface', '*', 'Device = '.$Device['Id']);
     93    $DbResult3 = $Database->select('NetworkInterface', '*', 'Device = '.$Device['Id'].' AND LocalIP != ""');
    9494    while($Interface = $DbResult3->fetch_assoc())
    9595    {
    96       $Name = $Device['Name'].'-'.$Interface['Name'];
     96      $Name = $Device['Name'];
     97      if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    9798      $Name = RouterOSIdent($Name);
    9899      echo($Name.', ');
     
    123124 
    124125  $DbResult2 = $Database->select('NetworkSubnet', '*', 'Member='.$Member['Id']);
    125   while($Subnet = $DbResult2->fetch_array())
     126  while($Subnet = $DbResult2->fetch_assoc())
    126127  {
    127128    $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']);
     
    139140    if($Index > 50)
    140141    {
     142      //print_r($Commands);
    141143      $Commands = addslashes(implode(';', $Commands));
    142144      $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Config['MainRouter']['HostName'].' "'.$Commands.'"';
     
    150152    $Index++;
    151153  }
    152  
    153154  echo("\n");
    154155}
  • trunk/system/netwatch_import.php

    r208 r213  
    88while($Router = $DbResult3->fetch_assoc())
    99{
     10  echo($Router['DHCP']."\n");
    1011  $Commands = array();
    1112  $Commands[] = '/tool netwatch print terse';
    1213  $Commands = implode(';', $Commands);
    13   $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i generators/id_dsa '.$Router['DHCP'].' "'.$Commands.'"';
     14  $Command = '/usr/bin/ssh -o ConnectTimeout=5 -l '.$Config['MainRouter']['UserName'].' -i generators/id_dsa '.$Router['DHCP'].' "'.$Commands.'"';
    1415  //echo($Command."\n");
    1516  $Output = '';
Note: See TracChangeset for help on using the changeset viewer.