Ejemplo n.º 1
0
function snmpgeneric_tabhandler($object_id)
{
    //	sg_var_dump_html($_POST);
    if (isset($_POST['asnewobject']) && $_POST['asnewobject'] == "1") {
        $newobject_name = $_POST['object_name'];
        $newobject_label = $_POST['object_label'];
        $newobject_type_id = $_POST['object_type_id'];
        $newobject_asset_no = $_POST['object_asset_no'];
        if (sg_checkObjectNameUniqueness($newobject_name, $newobject_type_id)) {
            $object_id = commitAddObject($newobject_name, $newobject_label, $newobject_type_id, $newobject_asset_no);
            $_POST['asnewobject'] = "0";
            parse_str($_SERVER['QUERY_STRING'], $query_string);
            $query_string['object_id'] = $object_id;
            $_SERVER['QUERY_STRING'] = http_build_query($query_string);
            list($path, $qs) = explode('?', $_SERVER['REQUEST_URI'], 2);
            $_SERVER['REQUEST_URI'] = $path . '?' . $_SERVER['QUERY_STRING'];
            // switch to new object
            echo '<body>';
            echo '<body onload="document.forms[\'newobject\'].submit();">';
            echo '<form method=POST id=newobject action=' . $_SERVER['REQUEST_URI'] . '>';
            foreach ($_POST as $name => $value) {
                echo "<input type=hidden name={$name} value={$value}>";
            }
            echo '<input type=submit id="submitbutton" tabindex="1" value="Show List">';
            echo '</from></body>';
            exit;
        } else {
            showError("Object with name: \"{$newobject_name}\" already exists!!!");
            $_POST['snmpconfig'] = "0";
        }
    }
    // save snmp settings
    if (isset($_POST['save']) && $_POST['save'] == "1") {
        // TODO save only on success !!
        $object = spotEntity('object', $object_id);
        $snmpvalues[0] = 'SNMP';
        $snmpnames = array('host', 'version', 'community');
        if ($_POST['version'] == "v3") {
            $snmpnames = array_merge($snmpnames, array('sec_level', 'auth_protocol', 'auth_passphrase', 'priv_protocol', 'priv_passphrase'));
        }
        foreach ($snmpnames as $key => $value) {
            if (isset($_POST[$value])) {
                switch ($value) {
                    case "auth_passphrase":
                    case "priv_passphrase":
                        $snmpvalues[$key + 1] = base64_encode($_POST[$value]);
                        break;
                    default:
                        $snmpvalues[$key + 1] = $_POST[$value];
                }
            }
        }
        //	sg_var_dump_html($snmpvalues);
        $newsnmpstr = implode($snmpvalues, ":");
        $snmpstr = strtok($object['comment'], "\n\r");
        $snmpstrarray = explode(':', $snmpstr);
        $setcomment = "set";
        if ($snmpstrarray[0] == "SNMP") {
            if ($newsnmpstr == $snmpstr) {
                $setcomment = "ok";
            } else {
                $setcomment = "update";
            }
        }
        if ($setcomment != "ok") {
            if ($setcomment == "update") {
                $comment = str_replace($snmpstr, $newsnmpstr, $object['comment']);
            } else {
                $comment = "{$newsnmpstr}\n" . $object['comment'];
            }
            //	echo "$snmpnewstr ".$object['comment']." --> $comment";
            commitUpdateObject($object_id, $object['name'], NULL, $object['has_problems'], NULL, $comment);
            showNotice("{$setcomment} SNMP Settings: {$newsnmpstr}");
        }
    }
    if (isset($_POST['snmpconfig']) && $_POST['snmpconfig'] == '1') {
        snmpgeneric_list($object_id);
    } else {
        snmpgeneric_snmpconfig($object_id);
    }
}
Ejemplo n.º 2
0
function snmpgeneric_tabhandler($object_id)
{
    if (isset($_POST['snmpconfig'])) {
        if ($_POST['snmpconfig'] == '1') {
            snmpgeneric_list($object_id);
        }
    } else {
        snmpgeneric_snmpconfig($object_id);
    }
}