Changeset 167 for www/system


Ignore:
Timestamp:
Mar 24, 2009, 11:44:03 AM (16 years ago)
Author:
george
Message:
  • Přidáno: Stránka pro rozeslání emailů s počátečními hesly.
  • Upraveno: Konfigurační skripty pro nastavení síťových zařízení se systémem RouterOS doplněny o podporu zápisu konfigurace do více samostatných zařízení. Změna se týká konfigurace DHCP serveru a sledování net_watch.
  • Opraveno: Některé nefunkční odkazy na hlavní stránce.
  • Upraveno: Tabulka finance_operations nově převedena na tabulky FinanceOperation a FinanceClaimsLiabilities. Upraveny související stránky.
Location:
www/system
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • www/system/generators

    • Property svn:ignore set to
      id_dsa
      id_dsa.pub
  • www/system/generators/dhcp_routerboard.php

    r161 r167  
    11<?php
     2
     3$SessionDisable = true;
    24include_once('../../global.php');
    35
    4 // Generate DHCP server configuration
    5 /*
    6 $File = fopen('/etc/dhcpd.conf', 'w');
    7 fputs($File, "# DHCP Configuration file\n".
    8 "authoritative;\n".
    9 'option domain-name "zdechov.net";'."\n".
    10 "server-name centrala;\n".
    11 "ddns-update-style ad-hoc;\n".
    12 "default-lease-time 86400;\n".
    13 "max-lease-time 86400;\n".
    14 "ddns-hostname centrala;\n".
    15 "option domain-name-servers 192.168.0.1;\n".
    16 "#option subnet-mask 255.255.0.0;\n\n".
    17 "# nastaveni WINS serveru\n".
    18 "option netbios-name-servers 192.168.0.1;\n".
    19 "option netbios-dd-server 192.168.0.1;\n".
    20 "option netbios-node-type 8;\n".
    21 'option netbios-scope "";'."\n".
    22 "server-identifier 192.168.0.1;\n\n");
    23 */
    24 $Commands = array();
    25 //$MaxSubnet = 1;
    26 $Commands[] = '/ip dhcp-server lease { remove [find]}';
    27 for($i = 0; $i <= 5; $i++)
     6$UserName = 'admin-ssh';
     7
     8$DbResult = $Database->query('SELECT * FROM NetworkSubnet');
     9while($Subnet = $DbResult->fetch_assoc())
    2810{
    29 /*
    30   fputs($File, "subnet 192.168.".$i.".0 netmask 255.255.255.0 {\n".
    31   "  range 192.168.".$i.".128 192.168.".$i.".254;\n".
    32   "  option broadcast-address 192.168.".$i.".255;\n".
    33   "  option routers 192.168.".$i.".1;\n");
    34 */
    35   $DbResult = $Database->select('hosts', '*', "IP LIKE '192.168.".$i."%' ORDER BY IP");
    36   while($Row = $DbResult->fetch_array())
     11  //print_r($Subnet);
     12  $I = explode('.', $Subnet['AddressRange']);
     13  $I = $I[2];
     14  $Commands = array();
     15  $Commands[] = '/ip dhcp-server lease { remove [find server=dhcp'.$I.']}';
     16  $DbResult2 = $Database->query('SELECT * FROM hosts WHERE (IP LIKE "192.168.'.$I.'.%") AND (MAC != "00:00:00:00:00:00") ORDER BY IP');
     17  while($Host = $DbResult2->fetch_assoc())
    3718  {
    38 //    $Data = $Row['name'];
    39 //    if(strlen($Data) < 9) $Data .= "\t";
    40 //    fputs($File, "  host ".$Data."\t{ fixed-address ".$Row['IP'].";\thardware ethernet ".$Row['MAC']."; }\n");
    41     $Commands[] = '/ip dhcp-server lease add mac-address='.$Row['MAC'].' address='.$Row['IP'].' server=dhcp'.$i.' comment='.$Row['name'];
     19    $Commands[] = '/ip dhcp-server lease add mac-address='.$Host['MAC'].' address='.$Host['IP'].' server=dhcp'.$I.' comment='.$Host['name'];
    4220  }
    43  
    44 //  fputs($File, "}\n\n");
     21  $Commands = implode(';', $Commands);
     22  $Command = '/usr/bin/ssh -l '.$UserName.' -i id_dsa '.$Subnet['DHCP'].' "'.$Commands.'"';
     23  echo($Command."\n");
     24  $Output = '';
     25  exec($Command, $Output);
     26  print_r($Output);
     27  echo("\n");
    4528}
    46 //fclose($File);
    47 $Commands = implode(';', $Commands);
    48 $Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa rt-hajda-0 "'.$Commands.'"';
    49 echo($Command);
    50 exec($Command, $Output);
    51 print_r($Output);
    5229
    5330?>
  • www/system/generators/netwatch.php

    r161 r167  
    11<?php
     2
     3$SessionDisable = true;
    24include_once('../../global.php');
    35
    4 $Commands = array();
    5 //$MaxSubnet = 1;
    6 $Commands[] = '/tool netwatch remove [/tool netwatch find]';
    7 //for($i = 0; $i <= 4; $i++)
    8 //{
    9   $DbResult = $Database->select('hosts', '*', 'IP != "" ORDER BY IP');
    10   while($Row = $DbResult->fetch_array())
     6$UserName = 'admin-ssh';
     7
     8$DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet`');
     9while($Router = $DbResult3->fetch_assoc())
     10{
     11  $Commands = array();
     12  $Commands[] = '/tool netwatch remove [find]';
     13  $DbResult = $Database->query('SELECT * FROM `NetworkSubnet` WHERE `DHCP`="'.$Router['DHCP'].'"');
     14  while($Subnet = $DbResult->fetch_assoc())
    1115  {
    12     $Commands[] = '/tool netwatch add host='.$Row['IP'].' interval=1m comment='.$Row['name'];
     16    //print_r($Subnet);
     17    $I = explode('.', $Subnet['AddressRange']);
     18    $I = $I[2];
     19    $DbResult2 = $Database->query('SELECT * FROM hosts WHERE (IP LIKE "192.168.'.$I.'.%") AND (MAC != "00:00:00:00:00:00") ORDER BY IP');
     20    while($Host = $DbResult2->fetch_assoc())
     21    {
     22      $Commands[] = '/tool netwatch add host='.$Host['IP'].' interval=1m comment='.$Host['name'];
     23    }
    1324  }
    14 //}
    15 $Commands = implode(';', $Commands);
    16 $Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa rt-hajda-0 "'.$Commands.'"';
    17 echo($Command);
    18 exec($Command, $Output);
    19 print_r($Output);
     25  $Commands = implode(';', $Commands);
     26  $Command = '/usr/bin/ssh -l '.$UserName.' -i id_dsa '.$Router['DHCP'].' "'.$Commands.'"';
     27  echo($Command."\n");
     28  $Output = '';
     29  exec($Command, $Output);
     30  print_r($Output);
     31  echo("\n");
     32}
    2033
    2134?>
  • www/system/generators/traffic_shaping_routerboard.php

    r163 r167  
    33$Enabled = 1;
    44$ClassesEnabled = 1;
     5$SessionDisable = true;
    56include_once('../../global.php');
    67$Finance = &$System->Modules['Finance'];
     
    2829
    2930$InetInterface = 'ether3';
    30 $Router = '192.168.0.11';
     31$Router = '192.168.0.99';
    3132
    3233$Commands = array();
  • www/system/netwatch_import.php

    r161 r167  
    11<?php
    2 include_once('/a/www/centrala/global.php');
     2$SessionDisable = true;
     3include_once('../global.php');
    34
     5$UserName = 'admin-ssh';
    46$Config['Web']['ShowErrors'] = 1;
    57
    6 $Commands = array();
    7 //$MaxSubnet = 1;
    8 $Commands[] = '/tool netwatch print terse';
    9 $Commands = implode(';', $Commands);
    10 $Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa rt-hajda-0 "'.$Commands.'"';
    11 //echo($Command."\n");
    12 exec($Command, $Output);
    13 array_pop($Output);
    14 //print_r($Output);
     8$DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet`');
     9while($Router = $DbResult3->fetch_assoc())
     10{
     11  $Commands = array();
     12  $Commands[] = '/tool netwatch print terse';
     13  $Commands = implode(';', $Commands);
     14  $Command = '/usr/bin/ssh -l '.$UserName.' -i generators/id_dsa '.$Router['DHCP'].' "'.$Commands.'"';
     15  //echo($Command."\n");
     16  $Output = '';
     17  exec($Command, $Output);
     18  array_pop($Output);
     19  //print_r($Output);
     20  foreach($Output as $Row)
     21  {
     22    $Row = substr($Row, 6);
     23    $RowParts = explode(' ', $Row);
     24    $Properties = array();
     25    foreach($RowParts as $Index => $Item)
     26    {
     27      if(strpos($Item, '=') !== false)
     28      {
     29        $ItemParts = explode('=', $Item);
     30        $Properties[$ItemParts[0]] = $ItemParts[1];
     31      }
     32    }
     33    if($Properties['status'] == 'up')
     34    {
     35      $Online = 1;
     36      $Values = array('online' => $Online,  'last_online' => 'NOW()');
     37    } else
     38    {
     39      $Online = 0;
     40      $Values = array('online' => $Online);
     41    }
    1542
    16 foreach($Output as $Row)
    17 {
    18   $Row = substr($Row, 6);
    19   $RowParts = explode(' ', $Row);
    20   $Properties = array();
    21   foreach($RowParts as $Index => $Item)
    22   {
    23     if(strpos($Item, '=') !== false)
     43    $DbResult = $Database->update('hosts', 'IP="'.$Properties['host'].'"', $Values);
     44    if($Online == 1)
    2445    {
    25       $ItemParts = explode('=', $Item);
    26       $Properties[$ItemParts[0]] = $ItemParts[1];
     46      $DbResult = $Database->select('hosts', 'id', 'IP="'.$Properties['host'].'"');
     47      $DbRow = $DbResult->fetch_array();
     48      $HostId = $DbRow['id'];
     49      $DbResult2 = $Database->select('stat_hosts', '*', '(host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
     50      if($DbResult2->num_rows == 0) $Database->query('REPLACE INTO stat_hosts (host_id, time) VALUES ("'.$HostId.'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');         
     51      $Database->query('UPDATE stat_hosts SET count = count + 1 WHERE (host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
    2752    }
    28   }
    29   if($Properties['status'] == 'up')
    30   {
    31     $Online = 1;
    32     $Values = array('online' => $Online,  'last_online' => 'NOW()');
    33   } else
    34   {
    35     $Online = 0;
    36     $Values = array('online' => $Online);
    37   }
    38 
    39   $DbResult = $Database->update('hosts', 'IP="'.$Properties['host'].'"', $Values);
    40   if($Online == 1)
    41   {
    42     $DbResult = $Database->select('hosts', 'id', 'IP="'.$Properties['host'].'"');
    43     $DbRow = $DbResult->fetch_array();
    44     $HostId = $DbRow['id'];
    45     $DbResult2 = $Database->select('stat_hosts', '*', '(host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
    46     if($DbResult2->num_rows == 0) $Database->query('REPLACE INTO stat_hosts (host_id, time) VALUES ("'.$HostId.'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');         
    47     $Database->query('UPDATE stat_hosts SET count = count + 1 WHERE (host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
    4853  }
    4954}
Note: See TracChangeset for help on using the changeset viewer.