コード例 #1
0
function get_vrdat_os($a_iface)
{
    include "config.php";
    $iface_file = $data_dir . "iface.os";
    if (file_exists($iface_file)) {
        unlink($iface_file);
    }
    file_put_contents($iface_file, "", FILE_APPEND | LOCK_EX);
    $vlans_file = $data_dir . "vlans.os";
    if (file_exists($vlans_file)) {
        unlink($vlans_file);
    }
    file_put_contents($vlans_file, "", FILE_APPEND | LOCK_EX);
    $route_file = $data_dir . "route.os";
    if (file_exists($route_file)) {
        unlink($route_file);
    }
    file_put_contents($route_file, "", FILE_APPEND | LOCK_EX);
    foreach ($a_iface as $iface) {
        unset($data_route);
        exec($ifconfig . " | grep 'flags\\|inet ' | awk '\$2~/^flags/{_1=\$1;getline;if(\$1~/^inet/){print _1\"\"\$2\"-\"\$4}}' | sed s/:/-/  | grep " . $iface . ".", $data_route);
        unset($data_addr);
        exec($netstat . " -rn -f inet -W | grep " . $iface . ". | awk '{ print \$1,\$7 }'", $data_addr);
        foreach ($data_route as $a_data) {
            $s_data = explode("-", $a_data);
            $cou = count($s_data);
            if ($cou == 3) {
                $arr_iface = explode(".", $s_data[0]);
                if (count($arr_iface) == 2) {
                    $siface = $arr_iface[0];
                    $svlan = $arr_iface[1];
                    $sip = $s_data[1];
                    $smask = netmask2cidr(long2ip($s_data[2]));
                    file_put_contents($iface_file, $siface . "." . $svlan . "-" . $sip . "/" . $smask . chr(10), FILE_APPEND | LOCK_EX);
                }
            }
        }
        foreach ($data_addr as $row) {
            $srow = explode(" ", $row);
            $cou = count($srow);
            if ($cou == 2) {
                $arr_iface = explode(".", $srow[1]);
                if (count($arr_iface) == 2) {
                    $siface = $arr_iface[0];
                    $svlan = $arr_iface[1];
                    $arr_network = explode("/", $srow[0]);
                    $sip = $arr_network[0];
                    $smask = $arr_network[1];
                    file_put_contents($route_file, $siface . "." . $svlan . "-" . $sip . "/" . $smask . chr(10), FILE_APPEND | LOCK_EX);
                    file_put_contents($vlans_file, $siface . "." . $svlan . chr(10), FILE_APPEND | LOCK_EX);
                }
            }
        }
    }
}
コード例 #2
0
function is_ipv4_valid($ipv4_address, $ipv4_prefixlen = NULL)
{
    if (strpos($ipv4_address, '/') !== FALSE) {
        list($ipv4_address, $ipv4_prefixlen) = explode('/', $ipv4_address);
    }
    if (strpos($ipv4_prefixlen, '.')) {
        $ipv4_prefixlen = netmask2cidr($ipv4_prefixlen);
    }
    // False if prefix less or equal 0 and more 32
    if (is_numeric($ipv4_prefixlen) && ($ipv4_prefixlen < '0' || $ipv4_prefixlen > '32')) {
        return FALSE;
    }
    // False if invalid IPv4 syntax
    if (!Net_IPv4::validateIP($ipv4_address)) {
        return FALSE;
    }
    // False if 0.0.0.0
    if ($ipv4_address == '0.0.0.0') {
        return FALSE;
    }
    return TRUE;
}
コード例 #3
0
function dhcpserver_config($dhcpserver, $ch, $connect_url, $connect_api)
{
    include "config.php";
    $func_role = basename(__FILE__) . " " . __FUNCTION__;
    curl_setopt($ch, CURLOPT_URL, $connect_url . "get_dhcpserver_config");
    curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id_dhcp_server\":\"" . $dhcpserver . "\",\"api\":\"" . $connect_api . "\"}");
    $return = curl_exec($ch);
    if (curl_errno($ch)) {
        echo system_addlog($func_role, "1", "Curl error: " . curl_error($ch));
    } else {
        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($httpcode == "200") {
            $result_json = json_decode($return, true);
            $iface = $result_json["iface"];
            $includes_comx = $result_json["comx"];
            $includes_docx = $result_json["docx"];
            $includes_main = $result_json["main"];
            // Configure DHCP server
            if (file_exists($dhcpserver_config)) {
                unlink($dhcpserver_config);
            }
            if ($iface == "auto") {
                $iface = "eth0";
            }
            $a_iface = explode(",", $iface);
            file_put_contents($dhcpserver_config, "DHCPDARGS=\"" . implode(" ", $a_iface) . "\"" . chr(10), FILE_APPEND | LOCK_EX);
            echo message_addlog($func_role, "File " . $dhcpserver_config . " was created with interfaces '" . $iface . "'");
            // Configure DHCP file
            if (file_exists($dhcp_config)) {
                unlink($dhcp_config);
            }
            echo message_addlog($func_role, "Create file " . $dhcp_config);
            foreach ($includes_main as $row) {
                file_put_contents($dhcp_config, $row . chr(10), FILE_APPEND | LOCK_EX);
            }
            file_put_contents($dhcp_config, "shared-network viva {" . chr(10), FILE_APPEND | LOCK_EX);
            foreach ($a_iface as $row) {
                unset($data);
                $s_row = explode(chr(10), $row);
                $s_iface = $s_row[0];
                exec($ifconfig . " " . $s_iface . " | grep 'inet ' | awk '{print (\$2,\$4)}'", $data);
                foreach ($data as $row) {
                    $srow = explode(" ", $row);
                    $s_ipaddr = $srow[0];
                    $s_mask = long2ip($srow[1]);
                    $s_cidr = netmask2cidr($s_mask);
                    $s_network = get_network($s_ipaddr, $s_cidr);
                    file_put_contents($dhcp_config, "subnet " . $s_network . " netmask " . $s_mask . " { }" . chr(10), FILE_APPEND | LOCK_EX);
                    echo message_addlog($func_role, "Network " . $s_network . "/" . $s_cidr . " was added to file " . $dhcp_config);
                }
            }
            foreach ($includes_comx as $row) {
                if ($row > 0) {
                    $comx_file = "dhcpd_comx_" . $row . ".conf";
                    file_put_contents($dhcp_config, "include \"" . $dhcp_dir . $comx_file . "\";" . chr(10), FILE_APPEND | LOCK_EX);
                    echo message_addlog($func_role, "Include file " . $comx_file . " to file " . $dhcp_config);
                }
            }
            foreach ($includes_docx as $row) {
                if ($row > 0) {
                    $docx_file = "dhcpd_docx_" . $row . ".conf";
                    file_put_contents($dhcp_config, "include \"" . $dhcp_dir . $docx_file . "\";" . chr(10), FILE_APPEND | LOCK_EX);
                    echo message_addlog($func_role, "Include file " . $docx_file . " to file " . $dhcp_config);
                }
            }
            file_put_contents($dhcp_config, "}" . chr(10), FILE_APPEND | LOCK_EX);
            // select all old files which were included to DHCP config and delete them
            unset($data);
            exec($ls . " -al " . $dhcp_dir . " | grep dhcpd_ | awk '{print (\$9)}'", $data);
            foreach ($data as $row) {
                unlink($dhcp_dir . $row);
                echo message_addlog($func_role, "File " . $dhcp_dir . $row . " was deleted");
            }
            // create includes for comx
            if (count($includes_comx) > 0) {
                foreach ($includes_comx as $row) {
                    if ($row > 0) {
                        get_dhcpserver_include($row, "comx", $ch, $connect_url, $connect_api);
                    }
                }
            }
            // create includes for docx
            if (count($includes_docx) > 0) {
                foreach ($includes_docx as $row) {
                    if ($row > 0) {
                        get_dhcpserver_include($row, "docx", $ch, $connect_url, $connect_api);
                    }
                }
            }
            dhcpserver_restart();
        } else {
            $last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
            echo system_addlog($func_role, "1", "Error [" . $httpcode . "] " . $last_url);
        }
    }
}
コード例 #4
0
ファイル: php_gestionRed.php プロジェクト: Juan571/cne
             $rango = strpos($range, $cad);
             $datosh["rango"] = null;
             if (is_bool($rango)) {
                 preg_match_all('/(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})/', $range, $matches);
                 $datosh["rango"] = $matches[1][0] . "->" . $matches[1][1];
                 //substr($des, $descrip, -1);
             }
             $des = fgets($file);
             $cad = "#";
             $pos = strpos($des, $cad);
             $datosh["descripción"] = null;
             if (!is_bool($pos)) {
                 $datosh["descripción"] = strtoupper(substr($des, $pos + 1, -1));
                 $datosh["descripción"] = trim($datosh["descripción"], " \t.");
             }
             $datosh["netmask2cidr"] = netmask2cidr($datosh['mascara']);
             $redSubnet = $datosh["RED"] . "/" . $datosh["netmask2cidr"];
             $rango = getEachIpInRange($redSubnet);
             $numRedes = count($rango);
             $datosh["rangodeipmin"] = $rango[0];
             $datosh["rangodeipmax"] = $rango[$numRedes - 1];
             $hosts[] = $datosh;
         }
         ////IF
         // print_r($datosh);
     }
     //whileee
     echo json_encode($hosts);
     fclose($file);
     break;
 case $action === 'GuardarRed':
コード例 #5
0
     $endpt = array();
     $endpt['local'] = hex2ip($entry['cipSecEndPtLocalAddr1']);
     $ip2 = hex2ip($entry['cipSecEndPtLocalAddr2']);
     switch ($entry['cipSecEndPtLocalType']) {
         case 'ipSubnet':
             $endpt['local'] .= '/' . netmask2cidr($ip2);
             break;
         case 'ipAddrRange':
             $endpt['local'] .= ' - ' . $ip2;
             break;
     }
     $endpt['remote'] = hex2ip($entry['cipSecEndPtRemoteAddr1']);
     $ip2 = hex2ip($entry['cipSecEndPtRemoteAddr2']);
     switch ($entry['cipSecEndPtRemoteType']) {
         case 'ipSubnet':
             $endpt['remote'] .= '/' . netmask2cidr($ip2);
             break;
         case 'ipAddrRange':
             $endpt['remote'] .= ' - ' . $ip2;
             break;
     }
     $tunnel_endpt_json[$index_endpt] = $endpt;
 }
 $tunnel_endpt_json = json_encode($tunnel_endpt_json);
 $tunnel_endpt_hash = md5($tunnel_endpt_json);
 // Hash for index
 $tunnel_json = array();
 foreach ($json_oids as $oid) {
     if (isset($tunnel[$oid])) {
         $tunnel_json[$oid] = $tunnel[$oid];
     }