当前位置: 首页>>代码示例>>PHP>>正文


PHP Host::insert方法代码示例

本文整理汇总了PHP中Host::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Host::insert方法的具体用法?PHP Host::insert怎么用?PHP Host::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Host的用法示例。


在下文中一共展示了Host::insert方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionAdd

 public function actionAdd()
 {
     $msgHost = "";
     $request = Yii::app()->getRequest();
     if (!empty($_POST)) {
         $ip = trim($request->getPost("ip"));
         $admin = trim($request->getPost("admin"));
         $username = trim($request->getPost("username"));
         $password = trim($request->getPost("password"));
         $provider = trim($request->getPost("provider"));
         $status = trim($request->getPost("status"));
         if ($ip == "") {
             $msgHost = "主机IP选项不能留空";
         } else {
             if (strlen($ip) > 64) {
                 $msgHost = "输入不能大于64个字符";
             }
         }
         if ($msgHost == "") {
             $host = array('ip' => $ip, 'admin' => $admin, 'username' => $username, 'password' => $password, 'provider' => $provider, 'status' => $status);
             try {
                 $res = new Host();
                 $res->_attributes = $host;
                 $res->insert();
                 $this->redirect(array('list'));
             } catch (CDbException $re) {
                 throw CDbException($re);
             }
         }
     }
     $this->render('add', array('r' => Yii::app()->request->baseUrl . '/', 'msgHost' => $msgHost));
 }
开发者ID:humor-zo,项目名称:woc-yii,代码行数:32,代码来源:HostController.php

示例2: import_assets_csv


//.........这里部分代码省略.........
        //IP
        if (!ossim_valid($param[0], OSS_IP_ADDR, 'illegal:' . _("IP"))) {
            $response['line_errors'][$cont][] = array("IP", ossim_get_error_clean());
            $response['status'] = false;
        }
        //Hostname
        if (empty($param[1])) {
            $param[1] = $param[0];
        } else {
            if (!ossim_valid($param[1], OSS_SCORE, OSS_ALPHA, OSS_PUNC, 'illegal:' . _("Hostname"))) {
                $response['line_errors'][$cont][] = array("Hostname", ossim_get_error_clean());
                $response['status'] = false;
                ossim_clean_error();
            }
        }
        //FQDNs
        if (!empty($param[2])) {
            $fqdns_list = explode(",", $param[2]);
            foreach ($fqdns_list as $k => $fqdn) {
                if (!ossim_valid(trim($fqdn), OSS_NULLABLE, OSS_ALPHA, OSS_PUNC, 'illegal:' . _("FQDN/Aliases"))) {
                    $response['line_errors'][$cont][] = array("FQDN/Aliases", ossim_get_error_clean());
                    $response['status'] = false;
                    ossim_clean_error();
                }
            }
        }
        //Description
        if (!ossim_valid($param[3], OSS_NULLABLE, OSS_SCORE, OSS_ALPHA, OSS_PUNC, OSS_AT, 'illegal:' . _("Description"))) {
            $response['line_errors'][$cont][] = array("Description", ossim_get_error_clean());
            $response['status'] = false;
            ossim_clean_error();
        }
        //Asset
        if ($param[4] == '') {
            $param[4] = 2;
        } else {
            if (!ossim_valid($param[4], OSS_NULLABLE, OSS_DIGIT, 'illegal:' . _("Asset value"))) {
                $response['line_errors'][$cont][] = array("Asset", ossim_get_error_clean());
                $response['status'] = false;
                ossim_clean_error();
            }
        }
        //NAT
        if (!ossim_valid($param[5], OSS_NULLABLE, OSS_IP_ADDR, 'illegal:' . _("NAT"))) {
            $response['line_errors'][$cont][] = array("NAT", ossim_get_error_clean());
            $response['status'] = false;
            ossim_clean_error();
        }
        //Sensors
        $sensors = array();
        if (!empty($param[6])) {
            $sensor_name = array();
            $list = explode(",", $param[6]);
            $sensors_list = array_intersect($list, $my_allowed_sensors);
            if (!empty($sensors_list)) {
                foreach ($sensors_list as $sensor) {
                    $sensors[] = Sensor::get_sensor_name($conn, $sensor);
                }
            } else {
                $response['line_errors'][$cont][] = array("Sensors", _("You need at least one allowed Sensor"));
                $response['status'] = false;
                ossim_clean_error();
            }
        } else {
            $response['line_errors'][$cont][] = array("Sensors", _("Column Sensors is empty"));
            $response['status'] = false;
            ossim_clean_error();
        }
        $list_os = array("Windows", "Linux", "FreeBSD", "NetBSD", "OpenBSD", "MacOS", "Solaris", "Cisco", "AIX", "HP-UX", "Tru64", "IRIX", "BSD/OS", "SunOS", "Plan9", "IPhone");
        //Operating System
        if (!empty($param[7]) && !in_array($param[7], $list_os)) {
            $param[7] = "Unknown";
        }
        if ($response['status'] == true) {
            //Parameters
            $ip = $param[0];
            $hostname = $param[1];
            $asset = $param[4];
            $threshold_c = 30;
            $threshold_a = 30;
            $rrd_profile = "";
            $alert = 0;
            $persistence = 0;
            $nat = $param[5];
            $descr = $param[3];
            $os = $param[7];
            $fqdns = $param[2];
            $latitude = '';
            $longitude = '';
            $icon = 0;
            if (!Host::in_host($conn, $ip)) {
                Host::insert($conn, $ip, $hostname, $asset, $threshold_c, $threshold_a, $rrd_profile, $alert, $persistence, $nat, $sensors, $descr, $os, $mac, $mac_vendor, $latitude, $longitude, $fqdns, $icon);
            } else {
                Host::update($conn, $ip, $hostname, $asset, $threshold_c, $threshold_a, $rrd_profile, $alert, $persistence, $nat, $sensors, $descr, $os, $mac, $mac_vendor, $latitude, $longitude, $fqdns, $icon);
            }
        }
    }
    $response['read_line'] = $cont;
    return $response;
}
开发者ID:jhbsz,项目名称:ossimTest,代码行数:101,代码来源:import_hosts.php

示例3: ossim_db

$db = new ossim_db();
$conn = $db->connect();
$asset = 2;
$conf = $GLOBALS["CONF"];
$threshold = $conf->get_conf("threshold");
$alert = 0;
$persistence = 0;
$nat = "";
$sensor_list = Sensor::get_all($conn, "ORDER BY name");
$nsens = count($sensor_list);
$sensors = array();
$num_sens = 0;
foreach ($sensor_list as $sensor) {
    $sensor_name = $sensor->get_name();
    $num_sens++;
    $sensors[] = $sensor_name;
}
$descr = "";
$os = "";
$mac = "";
$mac_vendor = "";
$latitude = 0;
$longitude = 0;
if (!Host::in_host($conn, $ip)) {
    Host::insert($conn, $ip, $ip, $asset, $threshold, $threshold, "", $alert, $persistence, $nat, $sensors, $descr, $os, $mac, $mac_vendor, $latitude, $longitude);
} else {
    echo _("Warning: the host inserted already exists, inventory insert skipped.");
    exit;
}
$db->close($conn);
echo _("Host ") . $host . _(" Successfully inserted into inventory with default values.");
开发者ID:jhbsz,项目名称:ossimTest,代码行数:31,代码来源:newhost_response.php

示例4: foreach

        $sensors[] = $sensor->get_name();
    }
    foreach ($_POST as $key => $value) {
        if (preg_match("/^ip(.+)/", $key, $found)) {
            ossim_valid(POST("{$key}"), OSS_IP_ADDR, 'illegal:' . _("ip"));
            $num = $found[1];
            if (POST("name{$num}") == "") {
                $hostname = POST("{$key}");
            } else {
                $hostname = POST("name{$num}");
                ossim_valid($hostname, OSS_SPACE, OSS_SCORE, OSS_ALPHA, OSS_PUNC, 'illegal:' . _("hostname"));
            }
            if (ossim_error()) {
                die(ossim_error());
            }
            Host::insert($dbconn, POST("{$key}"), $hostname, 2, 60, 60, "", 0, 0, "", $sensors, "");
        }
    }
    ?>
    <script type="text/javascript">
        parent.GB_onclose();
    </script>
    <?php 
}
$ips = hosts_to_insert($dbconn, $report_id);
?>
<form action="add_hosts.php" method="post">
    <input type="hidden" name="action" value="insert">
    <center>
    <table class="transparent" width="85%" align="center">
        <tr>
开发者ID:jhbsz,项目名称:ossimTest,代码行数:31,代码来源:add_hosts.php

示例5: update_db

function update_db($global_info, $scan)
{
    $db = new ossim_db();
    $conn = $db->connect();
    $array_os = array("win" => "1", "linux" => "2", "cisco" => "3", "freebsd" => "5", "netbsd" => "6", "openbsd" => "7", "hp-ux" => "8", "solaris" => "9", "macos" => "10", "plan9" => "11", "sco" => "12", "aix" => "13", "unix" => "14");
    $ips = $global_info["ips"];
    $sensors = $global_info["sboxs"];
    $nagios = $global_info['nagios'];
    // load protocol ids
    $protocol_ids = array();
    if ($protocol_list = Protocol::get_list($conn)) {
        foreach ($protocol_list as $protocol_data) {
            $protocol_ids[$protocol_data->get_name()] = $protocol_data->get_id();
        }
    }
    for ($i = 0; $i < $ips; $i++) {
        $ip = $global_info["ip_{$i}"];
        if (!empty($ip)) {
            $hosts[] = $ip;
            //gethostbyaddr($ip);
            $os = $scan[$ip]["os"];
            $os_id = 0;
            foreach ($array_os as $k => $v) {
                if (preg_match("/{$k}/i", $os)) {
                    $os_id = $v;
                    break;
                }
            }
            if (Host::in_host($conn, $ip)) {
                echo "* " . gettext("Updating") . " {$ip}..<br/>";
                Host::update($conn, $ip, gethostbyaddr($ip), $global_info["asset"], $global_info["threshold_c"], $global_info["threshold_a"], $global_info["rrd_profile"], 0, 0, $global_info["nat"], $sensors, $global_info["descr"], $scan["{$ip}"]["os"], $scan["{$ip}"]["mac"], $scan["{$ip}"]["mac_vendor"]);
                Host_scan::delete($conn, $ip, 3001);
                //if (isset($global_info["nessus"])) { Host_scan::insert($conn, $ip, 3001, 0); }
            } else {
                echo "<span style='color='blue'>\n";
                echo "* " . gettext("Inserting") . " {$ip}..<br/>\n";
                echo "</span>\n";
                Host::insert($conn, $ip, gethostbyaddr($ip), $global_info["asset"], $global_info["threshold_c"], $global_info["threshold_a"], $global_info["rrd_profile"], 0, 0, $global_info["nat"], $sensors, $global_info["descr"], $scan[$ip]["os"], $scan[$ip]["mac"], $scan[$ip]["mac_vendor"]);
                // if (isset($global_info["nessus"])) { Host_scan::insert($conn, $ip, 3001, 0); }
            }
            if ($os_id != 0) {
                Host_plugin_sid::delete($conn, $ip, 5001);
                Host_plugin_sid::insert($conn, $ip, 5001, $os_id);
            }
            if (!empty($nagios)) {
                if (!Host_scan::in_host_scan($conn, $ip, 2007)) {
                    Host_scan::insert($conn, $ip, 2007, "", $ip, $sensors, "");
                }
            } else {
                if (Host_scan::in_host_scan($conn, $ip, 2007)) {
                    Host_scan::delete($conn, $ip, 2007);
                }
            }
            /* Services */
            Host_plugin_sid::delete($conn, $ip, 5002);
            foreach ($scan[$ip]["services"] as $port_proto => $service) {
                $service["proto"] = $protocol_ids[strtolower(trim($service["proto"]))];
                Host_services::insert($conn, $ip, $service["port"], strftime("%Y-%m-%d %H:%M:%S"), $_SERVER["SERVER_ADDR"], $service["proto"], $service["service"], $service["service"], $service["version"], 1);
                Host_plugin_sid::insert($conn, $ip, 5002, $service["port"]);
            }
            flush();
        }
    }
    // Insert group name
    $groupname = $global_info["groupname"];
    if (!empty($groupname) && !empty($hosts)) {
        $exists_hosts = count(Host_group::get_list($conn, " AND g.name='{$groupname}'")) > 0;
        if ($exists_hosts) {
            echo "<br/>" . _("The group name already exists") . "<br/>";
        } else {
            Host_group::insert($conn, $groupname, $global_info["threshold_c"], $global_info["threshold_a"], $global_info["rrd_profile"], $sensors, $hosts, $global_info["descr"]);
        }
        //if (isset($global_info["nessus"])) { Host_group_scan::insert($conn, $groupname, 3001, 0); }
        if (!empty($nagios)) {
            Host_group_scan::insert($conn, $groupname, 2007, 0);
        }
    }
    $db->close($conn);
}
开发者ID:jhbsz,项目名称:ossimTest,代码行数:79,代码来源:scan_db.php

示例6: _

    include "../hmenu.php";
    $get_param = "withoutmenu=0";
} else {
    $get_param = "ip={$ip}&withoutmenu=1";
}
if (POST('insert')) {
    if ($error == true) {
        $txt_error = "<div>" . _("We Found the following errors") . ":</div><div style='padding:10px;'>" . implode("<br/>", $message_error) . "</div>";
        Util::print_error($txt_error);
        Util::make_form("POST", "newhostform.php?" . $get_param);
        die;
    }
    $db = new ossim_db();
    $conn = $db->connect();
    if (!Host::in_host($conn, $ip)) {
        Host::insert($conn, $ip, $hostname, $asset, $threshold_c, $threshold_a, $rrd_profile, $alert, $persistence, $nat, $sensors, $descr, $os, $mac, $mac_vendor, $latitude, $longitude, $fqdns, $icon);
    } else {
        Host::update($conn, $ip, $hostname, $asset, $threshold_c, $threshold_a, $rrd_profile, $alert, $persistence, $nat, $sensors, $descr, $os, $mac, $mac_vendor, $latitude, $longitude, $fqdns, $icon);
    }
    //if (!empty($nessus)) Host_scan::insert($conn, $ip, 3001, 0);
    Host_scan::delete($conn, $ip, 3001, 0);
    if (!empty($nagios)) {
        if (!Host_scan::in_host_scan($conn, $ip, 2007)) {
            Host_scan::insert($conn, $ip, 2007, "", $hostname, $sensors, $sensors);
        } else {
            if (Host_scan::in_host_scan($conn, $ip, 2007)) {
                Host_scan::delete($conn, $ip, 2007);
            }
        }
    }
    $db->close($conn);
开发者ID:jhbsz,项目名称:ossimTest,代码行数:31,代码来源:newhost.php


注:本文中的Host::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。