Changeset 698


Ignore:
Timestamp:
Sep 28, 2014, 10:41:47 PM (10 years ago)
Author:
chronos
Message:
  • Přidáno: Generování reverzních záznamů pro IPv6 DNS.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Global.php

    r682 r698  
    1818include_once(dirname(__FILE__).'/Setup/Setup.php');
    1919include_once(dirname(__FILE__).'/PrefixMultiplier.php');
     20include_once(dirname(__FILE__).'/NetworkAddress.php');
    2021include_once(dirname(__FILE__).'/VCL/General.php');
    2122include_once(dirname(__FILE__).'/VCL/Database.php');
  • trunk/Common/NetworkAddress.php

    r695 r698  
    55  var $Address;
    66  var $Prefix;
    7  
     7
    88  function __construct()
    99  {
     
    1111    $this->Prefix = 0;
    1212  }
    13  
     13
    1414  function GetNetMask()
    1515  {
     
    2121    return(implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255))));
    2222  }
    23  
     23
    2424  function AddressFromString($Value)
    2525  {
     
    2727    $this->Address = ($Parts[0] << 24) | ($Parts[1] << 16) | ($Parts[2] << 8) | $Parts[3];
    2828  }
    29  
     29
    3030  function GetRange()
    3131  {
     
    3737    $To->Address = $From->Address + $HostMask;
    3838    $To->Prefix = 32;
    39     return(array('From' => $From, 'To' => $To));   
     39    return(array('From' => $From, 'To' => $To));
    4040  }
    4141
     
    4949
    5050  function Contain($Address)
    51   {   
     51  {
    5252    $UpperNetmask = $this->GetNetMask();
    5353    if(($this->Prefix < $Address->Prefix) and (($Address->Address & $UpperNetmask) == ($this->Address & $UpperNetmask))) $Result = true;
     
    6262        var $Address;
    6363        var $Prefix;
    64        
     64
    6565        function __construct()
    6666        {
     
    6868                $this->Prefix = 0;
    6969        }
    70        
     70
    7171  function AddressToString()
    7272  {
    7373        return(inet_ntop($this->Address));
    7474  }
    75  
     75
    7676  function AddressFromString($Value)
    7777  {
    7878        $this->Address = inet_pton($Value);
    7979  }
    80        
     80
     81  function GetOctets()
     82  {
     83        $Result = array();
     84        $Data = array_reverse(unpack('C*', $this->Address));
     85        foreach($Data as $Item)
     86        {
     87
     88                $Result[] = dechex($Item & 15);
     89                $Result[] = dechex(($Item >> 4) & 15);
     90        }
     91        return($Result);
     92  }
     93
    8194}
  • trunk/Modules/NetworkConfigLinux/Generators/DNS.php

    r695 r698  
    1717$MinimumTime = 10800;
    1818$TTL = 86400;
    19 $BaseDir = '/home/chronos/Projekty/centrala/trunk/var/named';
     19$BaseDir = '/var/named';
     20//$BaseDir = '/home/chronos/Projekty/centrala/trunk/var/named';
    2021if(!file_exists($BaseDir)) die('Base directory "'.$BaseDir.'" not exists.');
    2122$MailServer = 'centrala';
     
    6869      $Output .= strtolower($Host['Name'])."\tIN\tAAAA\t".$Host['IPv6']."\n";
    6970  }
    70  
     71
    7172  // Alias list
    7273  foreach($DNS['Alias'] as $Alias)
     
    112113  }
    113114
    114   /*
    115   // Generate reverse DNS IPv6 records
     115  // Generate reverse DNS IPv6 records
    116116  foreach($DNS['IPv6Network'] as $Network)
    117117  {
    118     $Parts = explode('.', $Network);
     118    $Parts = explode('/', $Network);
     119    $NetworkAddress = $Parts[0];
     120    $Prefix = $Parts[1];
    119121    $Output = // '$ORIGIN '.$Parts[2].'.'.$Parts[1].'.'.$Parts[0].'.in-addr.arpa'."\n".
    120122    '$TTL '.$DNS['TTL']."\n".
     
    134136    foreach($DNS['Host'] as $Host)
    135137    if(array_key_exists('IPv6', $Host) and ($Host['IPv6'] != ''))
    136     if(substr($Host['IPv6'], 0, strlen($Network)) == $Network)
    137138    {
    138         $Remaining = substr($Host['IPv6'], strlen($Network));
    139       $Remaining = explode(':', $Remaining);
    140       foreach($Remaining)
    141       $Remaining = array_reverse($Remaining);
    142            
     139        $Addr = new NetworkAddressIPv6();
     140        $Addr->AddressFromString($Host['IPv6']);
     141        $Octets = $Addr->GetOctets();
     142        $Octets = array_slice($Octets, 0, (128 - $Prefix) / 4);
     143        $Octets = array_reverse($Octets);
     144        $Octets = implode('.', $Octets);
     145
    143146      $Host['Name'] = strtolower($Host['Name']);
    144       $Output .= implode(':', $Remaining)."\tIN\tPTR\t".$Host['Name'].".".$DNS['Domain'].".\n";
     147      $Output .= $Octets."\tIN\tPTR\t".$Host['Name'].".".$DNS['Domain'].".\n";
    145148    }
    146     $Reverse = implode(':', array_reverse(explode(':', $Network)));   
    147     $File = fopen($DNS['BaseDir'].$Reverse.'.ipv6.arpa.zone', 'w+');
     149
     150    $NetAddr = new NetworkAddressIPv6();
     151    $NetAddr->AddressFromString($NetworkAddress);
     152    $Octets = array_reverse($NetAddr->GetOctets());
     153    $Octets = array_reverse(array_slice($Octets, 0, $Prefix / 4));
     154    $FileName = implode('.', $Octets).'.ipv6.arpa.zone';
     155    $File = fopen($DNS['BaseDir'].$FileName, 'w+');
    148156    fputs($File, $Output);
    149     //echo($Output);
    150157    fclose($File);
    151158  }
    152   */
    153159}
    154160
     
    169175  'Host' => array(),
    170176  'Alias' => array(),
    171   'Network' => array('10.145.64', '10.145.65', '10.145.66', '10.145.67', '10.145.68', 
    172                 '10.145.69', '10.145.70', '10.145.71', '77.92.221', '172.16.0', '172.16.1'),
    173         'IPv6Network' => array('2001:470:9ab9:1'),
     177  'Network' => array('10.145.64', '10.145.65', '10.145.66', '10.145.67', '10.145.68',
     178        '10.145.69', '10.145.70', '10.145.71', '77.92.221', '172.16.0', '172.16.1'),
     179        'IPv6Network' => array('2a00:e580:244::/48'),
    174180);
    175181
     
    232238  'Alias' => array(),
    233239  'Network' => array('81.2.194', '193.86.238', '212.111.4', '77.92.221'),
    234         'IPv6Network' => array('2001:470:9ab9:1'),
     240        'IPv6Network' => array('2a00:e580:244::/48'),
    235241);
    236242
     
    271277  'Host' => array(),
    272278  'Alias' => array(),
    273   'Network' => array('10.145.64', '10.145.65', '10.145.66', '10.145.67', 
     279  'Network' => array('10.145.64', '10.145.65', '10.145.66', '10.145.67',
    274280    '10.145.68', '10.145.69', '10.145.70', '10.145.71'),
    275281        'IPv6Network' => array(),
     
    311317  'Host' => array(),
    312318  'Alias' => array(),
    313   'Network' => array('10.145.64', '10.145.65', '10.145.66', '10.145.67', 
     319  'Network' => array('10.145.64', '10.145.65', '10.145.66', '10.145.67',
    314320        '10.145.68', '10.145.69', '10.145.70', '10.145.71'),
    315321        'IPv6Network' => array(),
Note: See TracChangeset for help on using the changeset viewer.