Пример #1
0
function get_sql_from_avr($file)
{
    $sql = '';
    $category = '';
    $password = '';
    // Change password if needed
    $user = '******';
    if (preg_match("/#/", $file)) {
        list($category, $_name) = explode('#', basename($file), 2);
        $category = trim(str_replace(' ', '_', $category));
    }
    if (file_exists($file) && filesize($file) > 0) {
        $content = file_get_contents($file);
        $decrypted_content = decrypt($content, $password);
        $datareport = @unserialize($decrypted_content);
        $report_name = $datareport["name"];
        $report_data = @unserialize($datareport["report"]);
        $format_error = $report_data ? FALSE : TRUE;
        $validation_error = FALSE;
        $validation_error = !validate($report_name, 'A-Za-z0-9\\s\\.,:@_\\-\\/\\?&\\=_\\-\\;\\#\\|') ? TRUE : FALSE;
        if (!$validation_error) {
            $validation_error = !validate($category, 'A-Za-z0-9\\s\\.,:@_\\-\\/\\?&\\=_\\-\\;\\#\\|') ? TRUE : FALSE;
        }
        if (!$format_error && !$validation_error) {
            // Force some parameters
            $report_data["profile"] = 'Default';
            $report_data["user"] = 0;
            $report_data["entity"] = '-1';
            $report_data["category"] = !empty($category) ? str_replace('_', ' ', $category) : '';
            $category = !empty($category) ? '_' . $category : '';
            // check subreports ids
            $newds = array();
            $sub_reports = $datareport["sr"];
            foreach ($sub_reports as $idr => $info) {
                if ($idr < 3000) {
                    $newds[$idr] = $report_data["ds"][$idr];
                }
            }
            $report_data["ds"] = $newds;
            // insert
            $sql .= '    REPLACE INTO alienvault.user_config (login, category, name, value) VALUES (\'' . qstr($user) . '\', \'' . qstr('custom_report' . $category) . '\', \'' . qstr($report_name) . '\', from_base64(\'' . base64_encode(serialize($report_data)) . '\'));' . "\n";
        } else {
            print_err($validation_error ? "Invalid character in Report Name or Category" : "Invalid Password, file format or category");
        }
    } else {
        print_err(empty($file) ? "Use: php " . $argv[0] . " path/file_name.avr [category]" : "File {$file} doesn't exists");
    }
    return $sql;
}
Пример #2
0
function to_csv_row($adata)
{
    $r = '';
    foreach ($adata as $a) {
        $r .= ($r ? "," : "") . qstr($a);
    }
    return $r . "\n";
}
Пример #3
0
function to_csv_row($adata)
{
    global $D;
    $r = '';
    foreach ($adata as $a) {
        $r .= ($r ? "," : "") . qstr($a);
    }
    return $r . $D;
}
Пример #4
0
 /**
  * Удаление  узла
  *
  * @param mixed $rec Ксли  true  дочерние  узлы  удаляются  рекурсивно,
  *  иначе  удаляются  одним  запросом  к  БД
  */
 public function deleteChildren($rec = true)
 {
     $conn = DB::getConnect();
     $class = get_called_class();
     $meta = $class::getMetadata();
     if ($rec) {
         $children = $this->getChildren();
         foreach ($children as $child) {
             $b = $class::delete($child->getID());
             if ($b == false) {
                 return false;
             }
         }
     } else {
         $id = $this->fields[$meta['keyfield']];
         $conn->Execute("delete from {$meta['table']}  where " . $meta['pathfield'] . " like " . qstr('%' . sprintf('%08s', $id) . '%') . " and {$meta['keyfield']} != " . $id);
         return true;
     }
     return true;
 }