Example #1
0
function insert_httptest_form()
{
    $form = new CFormTable(S_SCENARIO, null, 'post');
    $form->SetHelp("web.webmon.httpconf.php");
    if ($_REQUEST['groupid'] > 0) {
        $form->addVar('groupid', $_REQUEST['groupid']);
    }
    $form->addVar('hostid', $_REQUEST['hostid']);
    if (isset($_REQUEST["httptestid"])) {
        $form->addVar("httptestid", $_REQUEST["httptestid"]);
    }
    $name = get_request('name', '');
    $application = get_request('application', '');
    $delay = get_request('delay', 60);
    $status = get_request('status', HTTPTEST_STATUS_ACTIVE);
    $agent = get_request('agent', '');
    $macros = get_request('macros', array());
    $steps = get_request('steps', array());
    if (isset($_REQUEST["httptestid"]) && !isset($_REQUEST["form_refresh"]) || isset($limited)) {
        $httptest_data = DBfetch(DBselect("SELECT wt.*, a.name as application " . " FROM httptest wt,applications a WHERE wt.httptestid=" . $_REQUEST["httptestid"] . " AND a.applicationid=wt.applicationid"));
        $name = $httptest_data['name'];
        $application = $httptest_data['application'];
        $delay = $httptest_data['delay'];
        $status = $httptest_data['status'];
        $agent = $httptest_data['agent'];
        $macros = $httptest_data['macros'];
        $steps = array();
        $db_steps = DBselect('SELECT * FROM httpstep WHERE httptestid=' . $_REQUEST["httptestid"] . ' order by no');
        while ($step_data = DBfetch($db_steps)) {
            $steps[] = $step_data;
        }
    }
    $form->addRow(S_APPLICATION, array(new CTextBox('application', $application, 40), SPACE, new CButton('select_app', S_SELECT, 'return PopUp("popup.php?dstfrm=' . $form->GetName() . '&dstfld1=application&srctbl=applications' . '&srcfld1=name&only_hostid=' . $_REQUEST['hostid'] . '",200,300,"application");')));
    $form->addRow(S_NAME, new CTextBox('name', $name, 40));
    $form->addRow(S_UPDATE_INTERVAL_IN_SEC, new CNumericBox("delay", $delay, 5));
    $cmbAgent = new CEditableComboBox('agent', $agent, 80);
    // IE6
    $cmbAgent->addItem('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)', 'Internet Explorer 6.0 on Windows XP SP2 with .NET Framework 2.0 installed');
    // IE7
    $cmbAgent->addItem('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)', 'Internet Explorer 7.0 on Windows XP SP3 with .NET Framework 3.5 installed');
    // FF 1.5
    $cmbAgent->addItem('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7', 'Mozilla Firefox 1.5.0.7 on Windows XP');
    $cmbAgent->addItem('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7', 'Mozilla Firefox 1.5.0.7 on Linux');
    // FF 2.0
    $cmbAgent->addItem('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.18) Gecko/20081029 Firefox/2.0.0.18', 'Mozilla Firefox 2.0.0.18 on Windows XP');
    $cmbAgent->addItem('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.18) Gecko/20081029 Firefox/2.0.0.18', 'Mozilla Firefox 2.0.0.18 on Linux');
    // FF 3.0
    $cmbAgent->addItem('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1', 'Mozilla Firefox 3.0.1 on Windows XP');
    $cmbAgent->addItem('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1', 'Mozilla Firefox 3.0.1 on Linux');
    // OP 9.0
    $cmbAgent->addItem('Opera/9.02 (Windows NT 5.1; U; en)', 'Opera 9.02 on Windows XP');
    $cmbAgent->addItem('Opera/9.02 (X11; Linux i686; U; en)', 'Opera 9.02 on Linux');
    // OP 9.6
    $cmbAgent->addItem('Opera/9.61 (Windows NT 5.1; U; en) Presto/2.1.1', 'Opera 9.61 on Windows XP');
    $cmbAgent->addItem('Opera/9.61 (X11; Linux i686; U; en) Presto/2.1.1', 'Opera 9.61 on Linux');
    // SF 3.1
    $cmbAgent->addItem('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Version/3.1.2 Safari/525.21', 'Safari 3.1.2 on Windows XP');
    $cmbAgent->addItem('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4; en-us) AppleWebKit/527.2+ (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1', 'Safari 3.1.2 on Intel Mac OS X 10.5.4');
    $cmbAgent->addItem('Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_1 like Mac OS X; fr-fr) AppleWebKit/525.18.1 (KHTML, like Gecko) Mobile/5F136', 'Safari on iPhone');
    $cmbAgent->addItem('Lynx/2.8.4rel.1 libwww-FM/2.14', 'Lynx 2.8.4rel.1 on Linux');
    $cmbAgent->addItem('Googlebot/2.1 (+http://www.google.com/bot.html)', 'Googlebot');
    $form->addRow(S_AGENT, $cmbAgent);
    $cmbStatus = new CComboBox("status", $status);
    foreach (array(HTTPTEST_STATUS_ACTIVE, HTTPTEST_STATUS_DISABLED) as $st) {
        $cmbStatus->addItem($st, httptest_status2str($st));
    }
    $form->addRow(S_STATUS, $cmbStatus);
    $form->addRow(S_VARIABLES, new CTextArea('macros', $macros, 84, 5));
    $tblSteps = new CTableInfo();
    $tblSteps->SetHeader(array(S_NAME, S_TIMEOUT, S_URL, S_REQUIRED, S_STATUS, SPACE));
    if (count($steps) > 0) {
        $first = min(array_keys($steps));
        $last = max(array_keys($steps));
    }
    foreach ($steps as $stepid => $s) {
        if (!isset($s['name'])) {
            $s['name'] = '';
        }
        if (!isset($s['timeout'])) {
            $s['timeout'] = 15;
        }
        if (!isset($s['url'])) {
            $s['url'] = '';
        }
        if (!isset($s['posts'])) {
            $s['posts'] = '';
        }
        if (!isset($s['required'])) {
            $s['required'] = '';
        }
        $up = null;
        if ($stepid != $first) {
            $up = new CLink(S_UP, '#', 'action');
            $up->OnClick("return create_var('" . $form->GetName() . "','move_up'," . $stepid . ", true);");
        }
        $down = null;
        if ($stepid != $last) {
            $down = new CLink(S_DOWN, '#', 'action');
            $down->OnClick("return create_var('" . $form->GetName() . "','move_down'," . $stepid . ", true);");
        }
        $name = new CLink($s['name'], '#', 'action');
        $name->OnClick('return PopUp("popup_httpstep.php?dstfrm=' . $form->GetName() . '&list_name=steps&stepid=' . $stepid . url_param($s['name'], false, 'name') . url_param($s['timeout'], false, 'timeout') . url_param($s['url'], false, 'url') . url_param($s['posts'], false, 'posts') . url_param($s['required'], false, 'required') . url_param($s['status_codes'], false, 'status_codes') . '");');
        if (strlen($s['url']) > 70) {
            $url = new CTag('span', 'yes', substr($s['url'], 0, 35) . SPACE . '...' . SPACE . substr($s['url'], strlen($s['url']) - 25, 25));
            $url->SetHint($s['url']);
        } else {
            $url = $s['url'];
        }
        $tblSteps->addRow(array(array(new CCheckBox('sel_step[]', null, null, $stepid), $name), $s['timeout'] . SPACE . S_SEC_SMALL, $url, $s['required'], $s['status_codes'], array($up, isset($up) && isset($down) ? SPACE : null, $down)));
    }
    $form->addVar('steps', $steps);
    $form->addRow(S_STEPS, array(count($steps) > 0 ? array($tblSteps, BR()) : null, new CButton('add_step', S_ADD, 'return PopUp("popup_httpstep.php?dstfrm=' . $form->GetName() . '");'), count($steps) > 0 ? new CButton('del_sel_step', S_DELETE_SELECTED) : null));
    $form->addItemToBottomRow(new CButton("save", S_SAVE));
    if (isset($_REQUEST["httptestid"])) {
        $form->addItemToBottomRow(SPACE);
        $form->addItemToBottomRow(new CButton("clone", S_CLONE));
        $form->addItemToBottomRow(SPACE);
        $form->addItemToBottomRow(new CButtonDelete(S_DELETE_SCENARIO_Q, url_param("form") . url_param("httptestid") . url_param('hostid')));
    }
    $form->addItemToBottomRow(SPACE);
    $form->addItemToBottomRow(new CButtonCancel());
    $form->Show();
}