function discovery_port2str($type_int, $port) { $port_def = svc_default_port($type_int); if ($port != $port_def) { return ' (' . $port . ')'; } return ''; }
order_result($dchecks, 'name'); foreach ($dchecks as $id => $data) { $label = new CLabel($data['name'], 'selected_checks[' . $id . ']'); $dchecks[$id] = array(new CCheckBox('selected_checks[' . $id . ']', null, null, $id), $label, BR()); if (in_array($data['type'], array(SVC_AGENT, SVC_SNMPv1, SVC_SNMPv2, SVC_SNMPv3))) { $cmbUniquenessCriteria->addItem($id, $data['name']); } } if (count($dchecks)) { $dchecks[] = new CButton('delete_ckecks', S_DELETE_SELECTED); $form->addRow(S_CHECKS, $dchecks); } $cmbChkType = new CComboBox('new_check_type', $new_check_type, "if(add_variable(this, 'type_changed', 1)) submit()"); $cmbChkType->addItems(discovery_check_type2str()); if (isset($_REQUEST['type_changed'])) { $new_check_ports = svc_default_port($new_check_type); } $external_param = new CTable(); if ($new_check_type != SVC_ICMPPING) { $external_param->addRow(array(S_PORTS_SMALL, new CTextBox('new_check_ports', $new_check_ports, 20))); } switch ($new_check_type) { case SVC_SNMPv1: case SVC_SNMPv2: $external_param->addRow(array(S_SNMP_COMMUNITY, new CTextBox('new_check_snmp_community', $new_check_snmp_community))); $external_param->addRow(array(S_SNMP_OID, new CTextBox('new_check_key', $new_check_key))); $form->addVar('new_check_snmpv3_securitylevel', ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV); $form->addVar('new_check_snmpv3_securityname', ''); $form->addVar('new_check_snmpv3_authpassphrase', ''); $form->addVar('new_check_snmpv3_privpassphrase', ''); break;
function insert_drule_form() { $frm_title = S_DISCOVERY_RULE; if (isset($_REQUEST['druleid'])) { if ($rule_data = DBfetch(DBselect('SELECT * FROM drules WHERE druleid=' . $_REQUEST['druleid']))) { $frm_title = S_DISCOVERY_RULE . ' "' . $rule_data['name'] . '"'; } } $form = new CFormTable($frm_title, null, 'post'); $form->SetHelp("web.discovery.rule.php"); if (isset($_REQUEST['druleid'])) { $form->addVar('druleid', $_REQUEST['druleid']); } if (isset($_REQUEST['druleid']) && $rule_data && (!isset($_REQUEST["form_refresh"]) || isset($_REQUEST["register"]))) { $proxy_hostid = $rule_data['proxy_hostid']; $name = $rule_data['name']; $iprange = $rule_data['iprange']; $delay = $rule_data['delay']; $status = $rule_data['status']; //TODO init checks $dchecks = array(); $db_checks = DBselect('SELECT type,ports,key_,snmp_community FROM dchecks WHERE druleid=' . $_REQUEST['druleid']); while ($check_data = DBfetch($db_checks)) { $dchecks[] = array('type' => $check_data['type'], 'ports' => $check_data['ports'], 'key' => $check_data['key_'], 'snmp_community' => $check_data['snmp_community']); } } else { $proxy_hostid = get_request("proxy_hostid", 0); $name = get_request('name', ''); $iprange = get_request('iprange', '192.168.0.1-255'); $delay = get_request('delay', 3600); $status = get_request('status', DRULE_STATUS_ACTIVE); $dchecks = get_request('dchecks', array()); } $new_check_type = get_request('new_check_type', SVC_HTTP); $new_check_ports = get_request('new_check_ports', '80'); $new_check_key = get_request('new_check_key', ''); $new_check_snmp_community = get_request('new_check_snmp_community', ''); $form->addRow(S_NAME, new CTextBox('name', $name, 40)); //Proxy $cmbProxy = new CComboBox("proxy_hostid", $proxy_hostid); $cmbProxy->addItem(0, S_NO_PROXY); $sql = 'SELECT hostid,host ' . ' FROM hosts' . ' WHERE status IN (' . HOST_STATUS_PROXY . ') ' . ' AND ' . DBin_node('hostid') . ' ORDER BY host'; $db_proxies = DBselect($sql); while ($db_proxy = DBfetch($db_proxies)) { $cmbProxy->addItem($db_proxy['hostid'], $db_proxy['host']); } $form->addRow(S_DISCOVERY_BY_PROXY, $cmbProxy); //---------- $form->addRow(S_IP_RANGE, new CTextBox('iprange', $iprange, 27)); $form->addRow(S_DELAY . ' (seconds)', new CNumericBox('delay', $delay, 8)); $form->addVar('dchecks', $dchecks); foreach ($dchecks as $id => $data) { switch ($data['type']) { case SVC_SNMPv1: case SVC_SNMPv2: $external_param = ' "' . $data['snmp_community'] . '":"' . $data['key'] . '"'; break; case SVC_AGENT: $external_param = ' "' . $data['key'] . '"'; break; default: $external_param = null; } $port_def = svc_default_port($data['type']); $dchecks[$id] = array(new CCheckBox('selected_checks[]', null, null, $id), discovery_check_type2str($data['type']), ($port_def == $data['ports'] ? '' : SPACE . '(' . $data['ports'] . ')') . $external_param, BR()); } if (count($dchecks)) { $dchecks[] = new CButton('delete_ckecks', S_DELETE_SELECTED); $form->addRow(S_CHECKS, $dchecks); } $cmbChkType = new CComboBox('new_check_type', $new_check_type, "if(add_variable(this, 'type_changed', 1)) submit()"); foreach (array(SVC_SSH, SVC_LDAP, SVC_SMTP, SVC_FTP, SVC_HTTP, SVC_POP, SVC_NNTP, SVC_IMAP, SVC_TCP, SVC_AGENT, SVC_SNMPv1, SVC_SNMPv2, SVC_ICMPPING) as $type_int) { $cmbChkType->addItem($type_int, discovery_check_type2str($type_int)); } if (isset($_REQUEST['type_changed'])) { $new_check_ports = svc_default_port($new_check_type); } $external_param = array(); switch ($new_check_type) { case SVC_SNMPv1: case SVC_SNMPv2: $external_param = array_merge($external_param, array(BR(), S_SNMP_COMMUNITY, SPACE, new CTextBox('new_check_snmp_community', $new_check_snmp_community))); $external_param = array_merge($external_param, array(BR(), S_SNMP_OID, new CTextBox('new_check_key', $new_check_key), BR())); break; case SVC_AGENT: $form->addVar('new_check_snmp_community', ''); $external_param = array_merge($external_param, array(BR(), S_KEY, new CTextBox('new_check_key', $new_check_key), BR())); break; case SVC_ICMPPING: $form->addVar('new_check_ports', '0'); default: $form->addVar('new_check_snmp_community', ''); $form->addVar('new_check_key', ''); } $ports_box = $new_check_type == SVC_ICMPPING ? NULL : array(S_PORTS_SMALL, SPACE, new CNumericBox('new_check_ports', $new_check_ports, 5)); $form->addRow(S_NEW_CHECK, array($cmbChkType, SPACE, $ports_box, $external_param, new CButton('add_check', S_ADD)), 'new'); $cmbStatus = new CComboBox("status", $status); foreach (array(DRULE_STATUS_ACTIVE, DRULE_STATUS_DISABLED) as $st) { $cmbStatus->addItem($st, discovery_status2str($st)); } $form->addRow(S_STATUS, $cmbStatus); $form->addItemToBottomRow(new CButton("save", S_SAVE)); if (isset($_REQUEST["druleid"])) { $form->addItemToBottomRow(SPACE); $form->addItemToBottomRow(new CButton("clone", S_CLONE)); $form->addItemToBottomRow(SPACE); $form->addItemToBottomRow(new CButtonDelete(S_DELETE_RULE_Q, url_param("form") . url_param("druleid"))); } $form->addItemToBottomRow(SPACE); $form->addItemToBottomRow(new CButtonCancel()); $form->Show(); }