Ignore:
Timestamp:
Apr 5, 2009, 3:54:46 PM (16 years ago)
Author:
george
Message:
  • Přidáno: Možnost registrace podsítí pro klienty.
  • Upraveno: Skripty pro generování nastavení routerů byly upraveny pro podporu tabulky NetworkSubnet.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/system/generators/nat_routerboard.php

    r174 r187  
    33include_once('../../global.php');
    44
    5 $InetInterface = 'ether3';
    6 $Router = '192.168.0.11';
     5$InetInterface = $Config['MainRouter']['InetInterface'];
    76
    87$Commands = array();
     
    1211while($Member = $DbResult->fetch_assoc())
    1312{
    14   echo($Member['Name']."\n");
     13  echo($Member['Name'].': ');
     14  // Hosts
    1515  $DbResult2 = $Database->select('hosts', '*', '(external_ip <> "") AND (user='.$Member['Id'].') AND (IP != external_ip) ORDER BY id DESC');
    1616  while($Host = $DbResult2->fetch_assoc())
    1717  {
    18     echo($Host['name']."\n");
     18    $Host['name'] = RouterOSIdent($Host['name']);
     19    echo($Host['name'].'('.$Host['IP'].'), ');
    1920    $Commands[] = ' /ip firewall nat add chain=srcnat src-address='.$Host['IP'].' out-interface='.$InetInterface.' action=src-nat to-addresses='.$Host['external_ip'].' comment="'.$Host['name'].'"';
    2021    $Commands[] = ' /ip firewall nat add chain=dstnat dst-address='.$Host['external_ip'].' in-interface='.$InetInterface.' action=dst-nat to-addresses='.$Host['IP'].' comment="'.$Host['name'].'"';
    2122  }
     23
     24  // Subnets
     25  $DbResult2 = $Database->select('NetworkSubnet', '*', 'Member='.$Member['Id']);
     26  while($Subnet = $DbResult2->fetch_assoc())
     27  {
     28    $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']);
     29    echo($Subnet['Name'].'('.$Subnet['AddressRange'].'/'.$Subnet['Mask'].'), ');
     30    $Range = CIDRToAddressRange($Subnet['ExtAddressRange'], $Subnet['ExtMask']);
     31    $Range = $Range['From'].'-'.$Range['To'];
     32    $Commands[] = ' /ip firewall nat add chain=srcnat src-address-list='.$Subnet['AddressRange'].'/'.$Subnet['Mask'].' out-interface='.$InetInterface.' action=src-nat to-addresses='.$Range.' comment="'.$Subnet['Name'].'"';
     33    $Range = CIDRToAddressRange($Subnet['AddressRange'], $Subnet['Mask']);
     34    $Range = $Range['From'].'-'.$Range['To'];
     35    $Commands[] = ' /ip firewall nat add chain=dstnat dst-address-list='.$Subnet['ExtAddressRange'].'/'.$Subnet['ExtMask'].' in-interface='.$InetInterface.' action=dst-nat to-addresses='.$Range.' comment="'.$Subnet['Name'].'"';
     36  }
     37  echo("\n");
    2238}
    2339
     
    2945
    3046$Commands = addslashes(implode(';', $Commands));
    31 $Command = '/usr/bin/ssh -l admin-ssh -i id_dsa '.$Router.' "'.$Commands.'"';
     47$Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Config['MainRouter']['HostName'].' "'.$Commands.'"';
     48$Output = array();
    3249echo($Command."\n");
    33 //exec($Command, $Output);
     50exec($Command, $Output);
    3451//array_pop($Output);
    3552//print_r($Output);
Note: See TracChangeset for help on using the changeset viewer.