[services-cvs] CVS services/etc/misc

CVS User miham root at tempel.bibl.u-szeged.hu
2004. Nov. 23., K, 17:38:37 CET


Update of /var/lib/cvs/services/etc/misc
In directory tempel:/tmp/cvs-serv26466

Added Files:
	convertM4toDB.php generateDHCP.php generateDNS.php 
	generateEW.php listDB.php machines.db updateDB.php 
	updateM4.php vlans.db 
Log Message:
Az utobbi napok PHP termese



--- /var/lib/cvs/services/etc/misc/convertM4toDB.php	2004/11/23 16:38:37	NONE
+++ /var/lib/cvs/services/etc/misc/convertM4toDB.php	2004/11/23 16:38:37	1.1
#!/usr/bin/php4 -q
<?
require_once 'cachedb.php';

$data  = file('geplista.m4');
$vlans = file('vlans.m4');

$HSRPList = array();
foreach ($vlans as $actLine) {
    if (substr($actLine, 0, 11) != "ujHSRPentry")
        continue;

    $actData = explode(',', substr(trim($actLine), 12, -4));

    $actStruct = array();
    $localName = array_shift($actData);
    $actStruct["name"] = substr(trim($localName), 1, -1);
    $localDesc = array_shift($actData);
    $actStruct["desc"] = substr(trim($localDesc), 1, -1);
    $actStruct["num"]  = trim(array_shift($actData));
    $actStruct["ipba"] = array_shift($actData);
    $actStruct["ipla"] = trim(array_shift($actData));
    $actStruct["nets"] = array_shift($actData);
    $actStruct["flag"] = array_shift($actData);
    $actStruct["out"] = array_shift($actData);
    $actStruct["in"] = array_shift($actData);

    $HSRPList[$actStruct["name"]] = $actStruct;
}
if (write_cachedb("vlans", $HSRPList))
    exit(0);
else {
    write_error("Error: Unable to write DB file!");
    exit(1);
}

$GEPList = array();
foreach ($data as $actLine) {
    if (substr($actLine, 0, 10) != "ujGEPentry")
        continue;

    $actData = explode(",", substr(trim($actLine), 11, -4));
    
    $actStruct = array();
    $actStruct["mac"]   = strtoupper(array_shift($actData));
    $actStruct["sn"]    = array_shift($actData);
    $actStruct["msn"]   = array_shift($actData);
    $actStruct["level"] = substr(array_shift($actData), 1, -1);
    $actStruct["room"]  = substr(array_shift($actData), 1, -1);
    $actStruct["rack"]  = substr(array_shift($actData), 1, -1);
    $actStruct["rapo"]  = substr(array_shift($actData), 1, -1);
    $actStruct["swp"]   = substr(array_shift($actData), 1, -1);
    $localVlan = array_shift($actData);
    if (!strlen($localVlan))
        $localVlan = "?";
    else
        $localVlan = substr($localVlan, 1, -1);
    $actStruct["vlan"]  = $localVlan;
    $localUser = array_shift($actData);
    if (substr($localUser, 0, 1) == '"')
        $localUser = substr($localUser, 1, -1);
    $actStruct["user"]  = $localUser;
    $actStruct["host"]  = array_shift($actData);
    $actStruct["subd"]  = array_shift($actData);
    $actStruct["ip"]    = array_shift($actData);

    $GEPList[] = $actStruct;
}

if (write_cachedb("machines", $GEPList))
    exit(0);
else {
    write_error("Error: Unable to write DB file!");
    exit(1);
}
?>
--- /var/lib/cvs/services/etc/misc/generateDHCP.php	2004/11/23 16:38:37	NONE
+++ /var/lib/cvs/services/etc/misc/generateDHCP.php	2004/11/23 16:38:37	1.1
#!/usr/bin/php4 -q
<?
require_once 'cachedb.php';

function convert_entry(&$entry) {
    if (!isset($GLOBALS['converted'])) {
        $GLOBALS['converted'] = array();
    }
    $actconv  = "    # " . $entry['user'] . " gepe (" . $entry['room'] . ")\n";
    $actconv .= "    host " . $entry['vlan'] . '-' . $entry['host'] . " {\n";
    $actconv .= "      hardware ethernet " . $entry['mac'] . ";\n";
    $actconv .= "      fixed-address " . $entry['host'] . '.' . $entry['subd'] . ".bibl.u-szeged.hu;\n";
    $actconv .= "      option host-name \"" . $entry['host'] . "\";\n";
    $actconv .= "      option domain-name \"" . $entry['subd'] . ".bibl.u-szeged.hu\";\n";
    $actconv .= "    }\n";

    $GLOBALS['converted'][] = $actconv;
}

function get_netmask($netsize) {
    if ($netsize < 0 || $netsize > 32) 
        return "0.0.0.0";

    $netmask = array();
    $i = 1;
    while ($netsize >= 8) {
        $netmask[] = "255";
        $netsize -= 8;
        $i++;
    }
    
    $netmask[] = 256 - pow(2, 8 - $netsize);
    $i++;

    while ($i++ <= 4) {
        $netmask[] = "0";
    }

    return implode(".", $netmask);
}

function write_converted($vlan) {
    $conf  = "subnet " . $vlan['ipba'] . '.' . $vlan['ipla'] . " netmask " . get_netmask($vlan['nets']) . " {\n";
    $conf .= "  option routers " . $vlan['ipba'] . '.' . ($vlan['ipla'] + 1) . ";\n";
    $conf .= "\n";
    $conf .= "  group {\n";
    $conf .= "    # Name: PXE-enabled\n";
    $conf .= "    next-server " . $vlan['ipba'] . '.' . (intval($vlan['ipla']) + 5) . ";\n";
    $conf .= "    filename \"pxelinux.0\";\n";
    $conf .= "\n";
    $conf .= implode("\n", $GLOBALS['converted']);
    $conf .= "  }\n";
    $conf .= "\n";
    $conf .= "  group {\n";
    $conf .= "    # Name: PXE-disabled\n";
    $conf .= "  }\n";
    $conf .= "}\n";

    echo $conf;
}

if ($argc < 2) {
    write_error("Usage: " . $argv[0] . " <vlanname>");
}
$vlanname = $argv[1];

$machinedb =& read_cachedb("machines");
if ($machinedb === FALSE) {
    write_error("Unable to read machine DB!");
    exit(1);
}

$vlans =& read_cachedb("vlans");
if ($vlans === FALSE) {
    write_error("Unable to read vlans DB!");
    exit(1);
}

if (!isset($vlans[$vlanname])) {
    write_error("Unknown VLAN '{$vlanname}'!");
    exit(1);
}

foreach ($machinedb as $actent) {
    if ($actent['vlan'] == $vlanname && $actent['mac'] != 'IDEJONAMAC') {
        convert_entry($actent);
    }
}
write_converted($vlans[$vlanname]);
?>
--- /var/lib/cvs/services/etc/misc/generateDNS.php	2004/11/23 16:38:37	NONE
+++ /var/lib/cvs/services/etc/misc/generateDNS.php	2004/11/23 16:38:37	1.1
#!/usr/bin/php4 -q
<?
require_once 'cachedb.php';

function write_converted(&$vlans, $vlanname) {
    $converted =& $GLOBALS['converted'];
    
    $vland =& $vlans[$vlanname];

    $ipadd = explode('.', $vland['ipba']);
    $iprev = array();
    while (sizeof($ipadd)) {
        array_unshift($iprev, array_pop($ipadd));
    }

    $afh = fopen("zones/db.bibl.u-szeged.hu-" . strtolower($vlanname), 'w');
    $rfh = fopen("zones/db." . implode('.', $iprev) . '-' . $vland['ipla'], 'w');
    if (!$afh || !$rfh) {
        write_error("Unable to open output files for writing!");
        exit(1);
    }
    fwrite($afh, implode('', $converted['a']));
    fclose($afh);
    fwrite($rfh, implode('', $converted['rev']));
    fclose($rfh);
}

function convert_entry(&$entry) {
    if (!isset($GLOBALS['converted']))
        $GLOBALS['converted'] = array('a' => array(), 'rev' => array());

    $actconv  = "; " . $entry['user'] . " gepe (" . $entry['room'] . ")\n";
    $actconv .= $entry['host'] . "\tIN\tA\t" . $entry['ip'] . "\n";
    $GLOBALS['converted']['a'][] = $actconv;

    $actconv  = "; " . $entry['user'] . " gepe (" . $entry['room'] . ")\n";
    $iplast = explode(".", $entry['ip']);
    $actconv .= array_pop($iplast) . "\tIN\tPTR\t" . $entry['host'] . ".";
    $actconv .= $entry['subd'] . ".bibl.u-szeged.hu.\n";
    $GLOBALS['converted']['rev'][] = $actconv;

}

function sort_hosts($a, $b) {
    $aips = explode(".", $a['ip']);
    $bips = explode(".", $b['ip']);

    for ($i = 0; $i < sizeof($aips); $i++) {
        if ($aips[$i] == $bips[$i])
            continue;
        
        return ($aips[$i] > $bips[$i]) ? 1 : -1;
    }
}

if ($argc < 2) {
    write_error("Usage: " . $argv[0] . " <vlanname>");
}
$vlanname = $argv[1];

$machinedb =& read_cachedb("machines");
if ($machinedb === FALSE) {
    write_error("Unable to read machine DB!");
    exit(1);
}
$vlans =& read_cachedb("vlans");

if ($vlans === FALSE) {
    write_error("Unable to open vlan DB!");
    exit(1);
}

if (!isset($vlans[$vlanname])) {
    write_error("Unknown VLAN '{$vlanname}'!");
}

$hostlist = array();
foreach ($machinedb as $actent) {
    if ($actent['vlan'] == $vlanname && $actent['mac'] != 'IDEJONAMAC') {
        $hostlist[] = $actent;
    }
}
usort($hostlist, "sort_hosts");
foreach ($hostlist as $acthost) {
    convert_entry($acthost);
}

write_converted($vlans, $vlanname);
?>
--- /var/lib/cvs/services/etc/misc/generateEW.php	2004/11/23 16:38:37	NONE
+++ /var/lib/cvs/services/etc/misc/generateEW.php	2004/11/23 16:38:37	1.1
#!/usr/bin/php4 -q
<?
require_once 'cachedb.php';

function write_converted(&$vlans, $vlanname) {
    $converted =& $GLOBALS['converted'];
    
    echo "#!/bin/bash\n\n" . 
         implode('', $converted);
}

function convert_entry(&$entry, &$vland) {
    if (!isset($GLOBALS['converted'])) {
        $GLOBALS['converted'] = array();
        $GLOBALS['converted-help'] = array();
    }
    
    if (isset($GLOBALS['converted-help'][$entry['room']]))
        $GLOBALS['converted-help'][$entry['room']]++;
    else
        $GLOBALS['converted-help'][$entry['room']] = 1;

    if (!($GLOBALS['converted-help'][$entry['room']] % 5))
        $GLOBALS['converted'][] = "sleep 1\n";
        
    $GLOBALS['converted'][] = 'etherwake -b -i eth0.0' . $vland['num'] . 
                              ' ' . $entry['mac'] . "\n";
}

function sort_hosts($a, $b) {
    $aips = explode(".", $a['ip']);
    $bips = explode(".", $b['ip']);

    for ($i = 0; $i < sizeof($aips); $i++) {
        if ($aips[$i] == $bips[$i])
            continue;
        
        return ($aips[$i] > $bips[$i]) ? 1 : -1;
    }
}

if ($argc < 2) {
    write_error("Usage: " . $argv[0] . " <vlanname>");
}
$vlanname = $argv[1];

$machinedb =& read_cachedb("machines");
if ($machinedb === FALSE) {
    write_error("Unable to read machine DB!");
    exit(1);
}
$vlans =& read_cachedb("vlans");

if ($vlans === FALSE) {
    write_error("Unable to open vlan DB!");
    exit(1);
}

if (!isset($vlans[$vlanname])) {
    write_error("Unknown VLAN '{$vlanname}'!");
}
$vland =& $vlans[$vlanname];

$hostlist = array();
foreach ($machinedb as $actent) {
    if ($actent['vlan'] == $vlanname && $actent['mac'] != 'IDEJONAMAC') {
        $hostlist[] = $actent;
    }
}
usort($hostlist, "sort_hosts");
foreach ($hostlist as $acthost) {
    convert_entry($acthost, $vland);
}

write_converted($vlans, $vlanname);
?>
--- /var/lib/cvs/services/etc/misc/listDB.php	2004/11/23 16:38:37	NONE
+++ /var/lib/cvs/services/etc/misc/listDB.php	2004/11/23 16:38:37	1.1
#!/usr/bin/php4
<?
require_once 'cachedb.php';

// {{{ GETOPT replacement
$params = array( 'display' => 'normal', 'columns' => 80, 'helptopic' => 'general' );
$oper = 'help';

if ($argc > 1) {
    array_shift($argv);
    while (sizeof($argv)) {
        switch ($actParam = array_shift($argv)) {
            case '--search':
            case '-s':
                $oper = 'search';
                if (!sizeof($argv)) {
                    write_error("Missing parameter for search!");
                    exit(1);
                } elseif (!validate_search_param($sp = array_shift($argv))) {
                    // Error notification done in validate_search_param() function
                    exit(1);
                } else {
                    $params['searchreq'] = $sp;
                }
                break;

            case '--list':
            case '-l':
                $oper = 'list';
                break;

            case '--short':
            case '-S':
                $params['display'] = 'short';
                if (!isset($params['fields'])) {
                    $params['fields'] = array("room", "user", "host", "subd", "mac");
                }
                break;

            case '--fields':
            case '-F':
                if (!sizeof($argv)) {
                    write_error("Missing parameter for fields!");
                    exit(1);
                } elseif (!validate_display_fields($fields = explode(":", 
                                ($f = array_shift($argv))),$params)) {
                    write_error("Wrong parameter format ({$f}) for fields!");
                    exit(1);
                } else {
                    $fieldlens = array();
                    foreach ($fields as $actf) {
                        $fieldlens[] = get_param_length($actf);
                    }
                    $params['fields'] = $fields;
                    $params['fieldlens'] = $fieldlens;
                }
                break;

            case '--normal':
            case '-N':
                $params['display'] = 'normal';
                break;
            
            case '--long':
            case '-L':
                $params['display'] = 'long';
                break;
            
            case '--force':

[371 lines skipped]
--- /var/lib/cvs/services/etc/misc/machines.db	2004/11/23 16:38:37	NONE
+++ /var/lib/cvs/services/etc/misc/machines.db	2004/11/23 16:38:37	1.1

[372 lines skipped]
--- /var/lib/cvs/services/etc/misc/updateDB.php	2004/11/23 16:38:37	NONE
+++ /var/lib/cvs/services/etc/misc/updateDB.php	2004/11/23 16:38:37	1.1

[513 lines skipped]
--- /var/lib/cvs/services/etc/misc/updateM4.php	2004/11/23 16:38:37	NONE
+++ /var/lib/cvs/services/etc/misc/updateM4.php	2004/11/23 16:38:37	1.1

[620 lines skipped]
--- /var/lib/cvs/services/etc/misc/vlans.db	2004/11/23 16:38:37	NONE
+++ /var/lib/cvs/services/etc/misc/vlans.db	2004/11/23 16:38:37	1.1

[621 lines skipped]




További információk a(z) Services-cvs levelezőlistáról