Exemplo n.º 1
0
         if ($num_agents == 1) {
             $agent = array_pop($hids_agents);
             $d_data['agent_id'] = $agent['agent_id'];
         } else {
             $e_msg = _('Unable to deploy HIDS agent. This asset already has an agent deployed. If you want to deploy a new agent, please review <a class="bold_red" href="https://www.alienvault.com/help/redirect/usm/connect_agent" target="_blank">how to manage agent connections</a> and try again');
             Av_exception::throw_error(Av_exception::USER_ERROR, $e_msg);
         }
     }
     $res = Ossec_agent::deploy_windows_agent($sensor_id, $d_data);
     $job_id = $res['job_id'];
     $attempts = 0;
     $max_attempts = 80;
     $data = Ossec_agent::check_deployment_status($job_id);
     while ($data['status'] == 'in_progress' && $attempts < $max_attempts) {
         sleep(3);
         $data = Ossec_agent::check_deployment_status($job_id);
         $attempts++;
     }
     if ($attempts >= $max_attempts) {
         $e_msg = _('Connection has timed out. Please deploy the HIDS agent again');
         Av_exception::throw_error(Av_exception::USER_ERROR, $e_msg);
     } else {
         if ($data['status'] != 'success') {
             $e_msg = $data['data'] . "<br/><br/>" . $data['help'];
             Av_exception::throw_error(Av_exception::USER_ERROR, $e_msg);
         }
     }
     break;
 case 3:
     //Deploy Agentless
     /************************************************
    $conn = $db->connect();
    $res = Av_center::get_system_info_by_ip($conn, $d_data['sensor_ip']);
    if ($res['status'] == 'success') {
        $sensor_id = $res['data']['sensor_id'];
        if (!Ossec_utilities::is_sensor_allowed($conn, $sensor_id)) {
            $data['status'] = 'error';
            $data['data'] = _('Error! Sensor not allowed');
        }
    } else {
        $data['status'] = 'error';
        $data['data'] = _('Error! Unable to validate sensor IP');
    }
    if ($data['status'] == 'error') {
        $db->close();
        echo json_encode($data);
        exit;
    }
    $db->close();
    try {
        if ($order == 'status') {
            $data = Ossec_agent::check_deployment_status($d_data, $os_type);
        } else {
            $data = Ossec_agent::execute_deployment_action($d_data, $order, $os_type);
        }
    } catch (Exception $e) {
        $data['status'] = 'warning';
        $data['data'] = $e->getMessage();
    }
    echo json_encode($data);
    exit;
}