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


PHP Asset_host::save_in_db方法代码示例

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


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

示例1: import_assets_from_csv


//.........这里部分代码省略.........
                        $summary['general']['statistics']['errors']++;
                        continue;
                    }
                }
                //Check IPs
                if ($can_i_modify_ips == TRUE) {
                    $aux_ips = explode(',', $csv_ips);
                    foreach ($aux_ips as $ip) {
                        $host_ids = Asset_host::get_id_by_ips($conn, $ip, $ctx);
                        unset($host_ids[$host_id]);
                        if (!empty($host_ids)) {
                            $c_error_msg = _('IP') . ' ' . $csv_ips . ' ' . _("not allowed. IP {$ip} already exists for this entity");
                            $summary['by_hosts'][$num_line]['errors']['IP'] = $c_error_msg;
                            $summary['general']['statistics']['errors']++;
                            break;
                        } else {
                            $cnd_1 = Session::get_net_where() != '' && !Session::only_ff_net();
                            $cnd_2 = Asset_host::is_ip_in_cache_cidr($conn, $ip, $ctx, TRUE);
                            if ($cnd_1 && !$cnd_2) {
                                $c_error_msg = sprintf(_("Error! The IP %s is not allowed. Please check with your account admin for more information"), $csv_ips);
                                $summary['by_hosts'][$num_line]['errors']['IP'] = $c_error_msg;
                                $summary['general']['statistics']['errors']++;
                                break;
                            }
                        }
                    }
                } else {
                    $c_error_msg = _('Host') . ' ' . $name . ': ' . _("IP address not allowed. IP address cannot be modified");
                    $summary['by_hosts'][$num_line]['status'] = 'warning';
                    $summary['general']['warnings']['errors']++;
                    $summary['by_hosts'][$num_line]['warnings']['IP'] = $c_error_msg;
                }
                //Setting new values
                if (count($summary['by_hosts'][$num_line]['errors']) == 0) {
                    $host->set_ctx($ctx);
                    $host->set_name($name);
                    $host->set_descr($descr);
                    if ($is_in_db == FALSE) {
                        if ($can_i_modify_ips == TRUE) {
                            if (is_array($aux_ips) && !empty($aux_ips)) {
                                $ips = array();
                                foreach ($aux_ips as $ip) {
                                    $ips[$ip] = array('ip' => $ip, 'mac' => NULL);
                                }
                                $host->set_ips($ips);
                            }
                        }
                        $host->set_sensors($sensors);
                    }
                    if (!empty($fqdns)) {
                        $host->set_fqdns($fqdns);
                    }
                    $host->set_external($external);
                    $host->set_location($latitude, $longitude);
                    $host->set_asset_value($asset_value);
                    $host->set_devices($devices);
                    $host->save_in_db($conn, FALSE);
                    //Save Operating System
                    if (!empty($os)) {
                        Asset_host_properties::save_property_in_db($conn, $host_id, 3, $os, 2);
                    }
                    $summary['general']['statistics']['saved']++;
                    $summary['by_hosts'][$num_line]['data'] = $is_in_db == TRUE ? _('Asset updated') : _('New asset inserted');
                    //Keep warnings
                    if ($summary['by_hosts'][$num_line]['status'] != 'warning') {
                        $summary['by_hosts'][$num_line]['status'] = 'success';
                    }
                }
            } catch (Exception $e) {
                $summary['by_hosts'][$num_line]['errors']['Database error'] = $e->getMessage();
                $summary['general']['statistics']['errors']++;
            }
        }
    }
    if ($summary['general']['statistics']['saved'] > 0) {
        if ($summary['general']['statistics']['errors'] == 0) {
            $summary['general']['status'] = 'success';
            $summary['general']['data'] = _('All assets have been successfully imported ');
        } else {
            $summary['general']['status'] = 'warning';
            $summary['general']['data'] = _('Some assets cannot be imported');
        }
        Util::disable_perm_triggers($conn, FALSE);
        try {
            Asset_host::report_changes($conn, 'hosts');
        } catch (Exception $e) {
            Av_exception::write_log(Av_exception::USER_ERROR, $e->getMessage());
        }
    } else {
        $summary['general']['statistics']['errors'] = count($data);
        //CSV file is not empty, but all lines are wrong
        if (empty($summary['general']['status'])) {
            $summary['general']['status'] = 'error';
            $summary['general']['data'] = _('Assets cannot be imported');
        }
    }
    @$conn->Execute("REPLACE INTO alienvault.host_net_reference SELECT host.id,net_id FROM alienvault.host, alienvault.host_ip, alienvault.net_cidrs WHERE host.id = host_ip.host_id AND host_ip.ip >= net_cidrs.begin AND host_ip.ip <= net_cidrs.end");
    $db->close();
    return $summary;
}
开发者ID:jackpf,项目名称:ossim-arc,代码行数:101,代码来源:import_all_hosts.php

示例2: array

            if (empty($hosts_in_db[$ip][$ctx]) && empty($ids)) {
                if ($mode == 'insert') {
                    try {
                        $id = Util::uuid();
                        $hostname = Asset_host::get_autodetected_name($ip);
                        $ips = array();
                        $ips[$ip] = array('ip' => $ip, 'mac' => NULL);
                        $sensors = array($rs->fields['sensor_id']);
                        $conn_aux = $db->connect();
                        $host = new Asset_host($conn_aux, $id);
                        Util::disable_perm_triggers($conn_aux, TRUE);
                        $host->set_name($hostname);
                        $host->set_ctx($ctx);
                        $host->set_ips($ips);
                        $host->set_sensors($sensors);
                        $host->save_in_db($conn_aux, FALSE);
                        $hosts_in_db[$ip][$ctx] = $ip;
                        ?>
                        <script type="text/javascript">                                          
                             parent.$("#ptext").html("<?php 
                        echo _('Inserting new host') . ' <strong>' . $hostname . '</strong>';
                        ?>
");
                        </script>                                  
                        <?php 
                    } catch (Exception $e) {
                        $errors[] = $e->getMessage();
                    }
                } else {
                    $hostname = Asset_host::get_autodetected_name($ip);
                    $h_key = $ip . ';' . $ctx;
开发者ID:AntBean,项目名称:alienvault-ossim,代码行数:31,代码来源:import_all_hosts_from_siem_ajax.php

示例3: key

     $hostid = key(Asset_host::get_id_by_ips($dbconn, $hostip, $ctx));
     if (!Asset_host::is_in_db($dbconn, $hostid)) {
         list($sensor_list, $total) = Av_sensor::get_list($dbconn, array('where' => "acl_sensors.entity_id=UNHEX('{$ctx}')"));
         $sensors = array_keys($sensor_list);
         try {
             $hostid = Util::uuid();
             Util::disable_perm_triggers($dbconn, TRUE);
             $host = new Asset_host($dbconn, $hostid);
             $host->set_name($hostname);
             $host->set_ctx($ctx);
             $host_ip = array();
             $ips[$hostip] = array('ip' => $hostip, 'mac' => NULL);
             $host->set_ips($ips);
             $host->set_sensors($sensors);
             $host->set_fqdns($aliases);
             $host->save_in_db($dbconn);
         } catch (Exception $e) {
             $result = 'Impossible to save the host';
         }
     } else {
         $result = 'The host already exists.';
     }
     break;
 case 'update_aliases':
     list($hostip, $ctx, $aliases) = explode('|', base64_decode($asset));
     $hostid = key(Asset_host::get_id_by_ips($dbconn, $hostip, $ctx));
     if (Asset_host::is_in_db($dbconn, $hostid)) {
         try {
             $asset = new Asset_host($dbconn, $hostid);
             $asset->load_from_db($dbconn);
             $asset->set_fqdns($aliases);
开发者ID:AntBean,项目名称:alienvault-ossim,代码行数:31,代码来源:util.php

示例4: insert_host

function insert_host($conn, $data)
{
    $ips = preg_replace('/\\s*/', '', $data['ip']);
    $name = utf8_decode($data['name']);
    list($os, $dtype) = explode("_", $data['type']);
    // Type
    ossim_valid($ips, OSS_IP_ADDR, 'illegal:' . _("IP"));
    ossim_valid($name, OSS_HOST_NAME, 'illegal:' . _("Name"));
    ossim_valid($os, OSS_NULLABLE, OSS_ALPHA, 'illegal:' . _("OS"));
    ossim_valid($dtype, OSS_NULLABLE, OSS_ALPHA, 'illegal:' . _("Device Type"));
    check_ossim_error();
    $ips = explode(',', $ips);
    foreach ($ips as $ip) {
        $h_ip[$ip] = array('ip' => $ip, 'mac' => NULL);
    }
    //Insert the New Host
    $uuid = Util::uuid();
    $sensor_ip = Util::get_default_admin_ip();
    $sensor = Av_sensor::get_id_by_ip($conn, $sensor_ip);
    $host = new Asset_host($conn, $uuid);
    $host->set_ips($h_ip);
    $host->set_name($name);
    $host->set_sensors(array($sensor));
    $host->save_in_db($conn);
    // Device Type
    if ($dtype == 'networkdevice') {
        Asset_host_devices::save_device_in_db($conn, $uuid, 4);
    }
    // OS
    if ($os == 'windows' || $os == 'linux') {
        Asset_host_properties::save_property_in_db($conn, $uuid, 3, ucfirst($os), 1, TRUE);
    }
    $response['error'] = FALSE;
    $response['data'] = array();
    return $response;
}
开发者ID:jackpf,项目名称:ossim-arc,代码行数:36,代码来源:wizard_actions_ajax.php

示例5: json_encode

}
$db = new ossim_db();
$conn = $db->connect();
try {
    $uuid = Util::uuid();
    $name = Asset_host::get_autodetected_name($ip);
    //Getting the sensors for the new host
    $f = array();
    $f['where'] = " sensor.id = acl_sensors.sensor_id AND acl_sensors.entity_id=UNHEX('{$ctx}') ";
    $s_list = Av_sensor::get_basic_list($conn, $tables, $filters);
    $sensors = array();
    foreach ($s_list as $s) {
        $sensors[] = $s['id'];
    }
    $h_ip[$ip] = array('ip' => $ip, 'mac' => NULL);
    $host = new Asset_host($conn, $uuid);
    $host->set_ips($h_ip);
    $host->set_name($name);
    $host->set_sensors($sensors);
    $host->save_in_db($conn);
    Util::memcacheFlush();
    $response['msg'] = _("Host ") . $name . _(" Successfully inserted into inventory with default values.");
    $response['error'] = FALSE;
    $response['id'] = strtoupper($uuid);
    $response['txt'] = $name . " (" . $ip . ")";
} catch (Exception $e) {
    $response['error'] = true;
    $response['msg'] = $e->getMessage();
}
$db->close();
echo json_encode($response);
开发者ID:jackpf,项目名称:ossim-arc,代码行数:31,代码来源:newhost_response.php

示例6: array

         }
         $data[POST("{$key}")] = array('hostname' => $hostname, 'fqdns' => $fqdns);
         if (ossim_error()) {
             $info_error[] = ossim_get_error();
             ossim_clean_error();
         } else {
             $id = Util::uuid();
             $host = new Asset_host($conn, $id);
             $host->set_name($hostname);
             $host->set_ctx($ctx);
             $host_ip = array();
             $host_ip[POST("{$key}")] = array('ip' => POST("{$key}"), 'mac' => NULL);
             $host->set_ips($host_ip);
             $host->set_sensors($sensors);
             $host->set_fqdns($fqdns);
             $host->save_in_db($conn, FALSE);
             $save++;
         }
     }
 }
 if ($save > 0) {
     Util::disable_perm_triggers($conn, FALSE);
     try {
         Asset_host::report_changes($conn, 'hosts');
     } catch (Exception $e) {
         Av_exception::write_log(Av_exception::USER_ERROR, $e->getMessage());
     }
 }
 if (count($info_error) == 0) {
     ?>
     <script type="text/javascript">
开发者ID:alienfault,项目名称:ossim,代码行数:31,代码来源:add_hosts.php

示例7: catch

            } catch (Exception $e) {
                $result = 'Impossible to save the host';
            }
        } else {
            $result = 'The host already exists. Host ID: ' . $hostid;
        }
        break;
    case 'update_aliases':
        list($hostip, $ctx, $aliases) = explode('|', base64_decode($data_1));
        $hostid = key(Asset_host::get_id_by_ips($dbconn, $hostip, $ctx));
        if (Asset_host::is_in_db($dbconn, $hostid)) {
            try {
                $h_object = new Asset_host($dbconn, $hostid);
                $h_object->load_from_db($dbconn);
                $h_object->set_fqdns($aliases);
                $h_object->save_in_db($dbconn);
                $result = 'Host aliases updated';
            } catch (Exception $e) {
                $result = 'Impossible to save the host aliases';
            }
        }
        break;
    case "get_host_id":
        list($hostip, $ctx) = explode('|', base64_decode($data_1));
        $result = key(Asset_host::get_id_by_ips($dbconn, $hostip, $ctx));
        break;
    default:
        $db->close();
        die("The option isn't correct\n");
}
$db->close();
开发者ID:jackpf,项目名称:ossim-arc,代码行数:31,代码来源:util.php


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