Пример #1
0
function items()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql();
    $tSource = $_GET["t"];
    $search = '%';
    $table = "xapian_folders";
    $database = 'artica_backup';
    $page = 1;
    $FORCE_FILTER = "";
    if (!$q->TABLE_EXISTS($table, $database)) {
        $q->BuildTables();
    }
    if (!$q->TABLE_EXISTS($table, $database)) {
        json_error_show("{$table}, No such table...", 0);
    }
    if ($q->COUNT_ROWS($table, $database) == 0) {
        json_error_show("No data...", 0);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = "*" . $_POST["query"] . "*";
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        $total = $ligne["TCOUNT"];
        if (!$q->ok) {
            json_error_show($q->mysql_error, 1);
        }
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        if (!$q->ok) {
            json_error_show($q->mysql_error, 1);
        }
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    //id 	domain_id 	name 	type 	content 	ttl 	prio 	change_date 	ordername 	auth
    $sql = "SELECT *  FROM `{$table}` WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    if (!$q->ok) {
        json_error_show($q->mysql_error, 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $sock = new sockets();
    $autofs = new autofs();
    $autofs->automounts_Browse();
    while ($ligne = mysql_fetch_assoc($results)) {
        $id = $ligne["ID"];
        $articasrv = null;
        $address = null;
        $delete = imgsimple("delete-24.png", null, "XapianRecordDelete{$tSource}('{$id}')");
        if ($ligne["depth"] == 0) {
            $ligne["depth"] = $tpl->_ENGINE_parse_body("{unlimited}");
        }
        $autmountdn = $ligne["autmountdn"];
        $lastscan = strtotime($ligne["ScannedTime"]);
        $t = time();
        $took = distanceOfTimeInWords($lastscan, $t, true);
        if ($ligne["WebCopyID"] > 0) {
            $address = "<div style='font-size:14px;font-weight:bold'>" . WebCopyIDAddresses($ligne["WebCopyID"]) . "</div>";
            $ligne["directory"] = WebCopyIDDirectory($ligne["WebCopyID"]);
        }
        if ($autmountdn != null) {
            $autmountdn_array = $autofs->hash_by_dn[$autmountdn];
            $ligne["directory"] = "/automounts/{$autmountdn_array["FOLDER"]}";
            $autmountdn_infos = $autmountdn_array["INFOS"];
            $BaseUrl = $autmountdn_infos["BROWSER_URI"];
            $address = "<div style='font-size:14px;font-weight:bold'>{$BaseUrl}</div>";
        }
        $size = FormatBytes($ligne["DatabaseSize"] / 1024);
        $data['rows'][] = array('id' => $id, 'cell' => array("<a href=\"javascript:blur();\" OnClick=\"javascript:XapianDir{$tSource}({$id});\" \n\t\tstyle='font-size:16px;text-decoration:underline'>{$ligne["directory"]}</a>{$address}<div>Scanned:{$took} indexed:{$ligne["indexed"]}</div>", "<span style='font-size:16px;'>{$size}</span>", "<span style='font-size:16px;'>{$ligne["depth"]}</span>", "<span style='font-size:16px;'>{$ligne["lang"]}</span>", $delete));
    }
    echo json_encode($data);
}
Пример #2
-1
function Scan_mysql_dirs()
{
    $GLOBALS["INDEXED"] = 0;
    $GLOBALS["SKIPPED"] = 0;
    $GLOBALS["DIRS"] = array();
    $unix = new unix();
    $GLOBALS["omindex"] = $unix->find_program("omindex");
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid)) {
        system_admin_events("Already instance executed pid:{$olpid}", __FUNCTION__, __FILE__, __LINE__, "xapian");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $q = new mysql();
    $q->check_storage_table(true);
    $localdatabase = "/usr/share/artica-postfix/LocalDatabases";
    $nice = EXEC_NICE();
    $sql = "SELECT * FROM xapian_folders";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        system_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "xapian");
        return;
    }
    $t1 = time();
    if (!is_file($GLOBALS["omindex"])) {
        system_admin_events("omindex no such binary, aborting", __FUNCTION__, __FILE__, __LINE__, "xapian");
        return;
    }
    $autofs = new autofs();
    $autofs->automounts_Browse();
    $count = 0;
    while ($ligne = mysql_fetch_assoc($results)) {
        $directory = $ligne["directory"];
        $database = "{$localdatabase}/samba." . md5($directory) . ".db";
        $depth = $ligne["depth"];
        $maxsize = $ligne["maxsize"];
        $samplsize = $ligne["sample-size"];
        $lang = $ligne["lang"];
        $WebCopyID = $ligne["WebCopyID"];
        $autmountdn = $ligne["autmountdn"];
        if ($lang == null) {
            $lang = "english";
        }
        $indexed = $ligne["indexed"];
        if (!is_numeric($samplsize)) {
            $samplsize = 512;
        }
        if (!is_numeric($maxsize)) {
            $maxsize = 60;
        }
        if (!is_numeric($depth)) {
            $depth = 0;
        }
        $BaseUrl = $directory;
        if ($WebCopyID > 0) {
            $directory = WebCopyIDDirectory($WebCopyID);
            $BaseUrl = WebCopyIDAddresses($WebCopyID) . "/";
        }
        if ($autmountdn != null) {
            if (!isset($autofs->hash_by_dn[$autmountdn])) {
                system_admin_events("Fatal.. {$autmountdn} no such connection", __FUNCTION__, __FILE__, __LINE__, "xapian");
                continue;
            }
            $autmountdn_array = $autofs->hash_by_dn[$autmountdn];
            $directory = "/automounts/{$autmountdn_array["FOLDER"]}";
            $autmountdn_infos = $autmountdn_array["INFOS"];
            if (!isset($autmountdn_infos["BROWSER_URI"])) {
                system_admin_events("Fatal.. {$autmountdn} external protocol error", __FUNCTION__, __FILE__, __LINE__, "xapian");
                continue;
            }
            $BaseUrl = $autmountdn_infos["BROWSER_URI"];
        }
        if (!is_dir($database)) {
            @mkdir($database, 0755, true);
        }
        if (!is_dir($directory)) {
            system_admin_events("{$directory}, no such directory", __FUNCTION__, __FILE__, __LINE__, "xapian");
            continue;
        }
        $t = time();
        $cmd = "{$nice}{$GLOBALS["omindex"]} -l {$depth} -s {$lang} -E {$samplsize} -m {$maxsize}M --follow -D \"{$database}\" -U \"{$BaseUrl}\" \"{$directory}\" 2>&1";
        if ($GLOBALS["VERBOSE"]) {
            echo "{$cmd}\n";
        }
        $GLOBALS["DIRS"]["{$directory}"] = true;
        $results_scan = array();
        exec($cmd, $results_scan);
        $dirRes = ParseLogs($results_scan);
        $took = $unix->distanceOfTimeInWords($t, time(), true);
        $DatabaseSize = $unix->DIRSIZE_BYTES($database);
        $count++;
        $indexed = $indexed + $dirRes[0];
        system_admin_events("scanned {$directory} took {$took} indexed:{$indexed} skipped:{$dirRes[1]}", __FUNCTION__, __FILE__, __LINE__, "xapian");
        $q->QUERY_SQL("UPDATE xapian_folders SET ScannedTime=NOW(),indexed={$indexed},DatabasePath='{$database}',DatabaseSize='{$DatabaseSize}'\n\t\n\t\tWHERE ID={$ligne["ID"]}", "artica_backup");
        if (!$q->ok) {
            system_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "xapian");
        }
    }
    $took = $unix->distanceOfTimeInWords($t1, time(), true);
    system_admin_events("scanned {$count} directorie(s) took {$took}", __FUNCTION__, __FILE__, __LINE__, "xapian");
}