Beispiel #1
0
function loadRemoteURLContentWithRange($url, $range, $bypassProxy = true, $timeout = 30)
{
    if (!function_exists("curl_init")) {
        return false;
    }
    if (false && strpos($url, HEURIST_SERVER_URL) === 0) {
        return loadRemoteURLviaSocket($url);
    }
    $useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6';
    //'Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEFILE, '/dev/null');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //return the output as a string from curl_exec
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    curl_setopt($ch, CURLOPT_NOBODY, 0);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    //don't include header in output
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    // follow server header redirects
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    // don't verify peer cert
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    // timeout after ten seconds
    curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
    // no more than 5 redirections
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    //curl_setopt($ch, CURLOPT_REFERER, HEURIST_SERVER_URL);
    if ($range) {
        curl_setopt($ch, CURLOPT_RANGE, $range);
    }
    if (!$bypassProxy && defined("HEURIST_HTTP_PROXY")) {
        curl_setopt($ch, CURLOPT_PROXY, HEURIST_HTTP_PROXY);
        if (defined('HEURIST_HTTP_PROXY_AUTH')) {
            curl_setopt($ch, CURLOPT_PROXYUSERPWD, HEURIST_HTTP_PROXY_AUTH);
        }
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    $data = curl_exec($ch);
    $error = curl_error($ch);
    if ($error) {
        $code = intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
        //error_log('code = '.$code.'  '.$error);
        curl_close($ch);
        return false;
    } else {
        curl_close($ch);
        if (!$data) {
            $code = intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
            //error_log('code2 = '.$code);
        }
        return $data;
    }
}
Beispiel #2
0
if (@$_REQUEST['filename']) {
    $result = loadSearch($_REQUEST, false, true, $PUBONLY);
    //load IDS only
} else {
    // true || @$_REQUEST['rules']){ //search with h4 search engine
    $url = HEURIST_BASE_URL . "hserver/controller/record_search.php";
    $url = $url . '?' . $_SERVER["QUERY_STRING"] . "&detail=ids&vo=h3&needall=1";
    //call h4
    if ($PUBONLY) {
        $url = $url . "&publiconly=1";
    }
    /*
    $result = loadRemoteURLContent($url);
    $result = json_decode($result, true);
    */
    $result = loadRemoteURLviaSocket($url);
    //because of issue with curl/proxy on heurist server loadRemoteURLContent($url, false);
    $result = json_decode($result, true);
    /* it requires pecl http
       $r = new HttpRequest($url, HttpRequest::METH_GET);
       $r->addCookies($_COOKIE);
       $r->addQueryData($_REQUEST);
       try {
       $result = $r->getResponseBody(); //send()->getBody();
       $result = json_decode($result, true);
       } catch (HttpException $ex) {
       echo $ex;
       exit();
       }
       */
}
Beispiel #3
0
if ($islist || array_key_exists("id", $_REQUEST) && $_REQUEST["id"] != "") {
    // for wkt
    $squery = "select rec_ID, rec_URL, rec_Title, d0.dtl_DetailTypeID, d0.dtl_Value, if(d0.dtl_Geo is null, null, AsWKT(d0.dtl_Geo)) as dtl_Geo, " . "d1.dtl_Value as Date0, d2.dtl_Value as DateStart, d3.dtl_Value as DateEnd ";
    $ourwhere = " and (d0.dtl_RecID=rec_ID) and (d0.dtl_Geo is not null " . (defined('DT_KML') ? " or d0.dtl_DetailTypeID=" . DT_KML : "") . ")";
    $detTable = " left join recDetails d1 on d1.dtl_RecID=rec_ID and d1.dtl_DetailTypeID=" . (defined('DT_DATE') ? DT_DATE : "0") . " left join recDetails d2 on d2.dtl_RecID=rec_ID and d2.dtl_DetailTypeID=" . (defined('DT_START_DATE') ? DT_START_DATE : "0") . " left join recDetails d3 on d3.dtl_RecID=rec_ID and d3.dtl_DetailTypeID=" . (defined('DT_END_DATE') ? DT_END_DATE : "0") . ", recDetails d0";
    //for kml
    $squery2 = "select  rec_ID, rec_URL, rec_Title, ulf_ID, ulf_FilePath, ulf_FileName ";
    $ourwhere2 = " and (dtl_RecID=rec_ID) and (dtl_DetailTypeID=" . (defined('DT_KML_FILE') ? DT_KML_FILE : "0") . (defined('DT_FILE_RESOURCE') ? " or (dtl_DetailTypeID = " . DT_FILE_RESOURCE . " AND ulf_MimeExt='kml'))" : ")");
    $detTable2 = ", recDetails left join recUploadedFiles on ulf_ID = dtl_UploadedFileID";
    $isSearchKml = defined('DT_KML_FILE') || defined('DT_FILE_RESOURCE');
    if ($islist) {
        if (true || @$_REQUEST['rules']) {
            //search with h4 search engine
            $url = HEURIST_BASE_URL . "/hserver/controller/record_search.php?" . $_SERVER["QUERY_STRING"] . "&detail=ids&vo=h3";
            //call heurist
            $reclist = loadRemoteURLviaSocket($url);
            //because of issue with curl/proxy on heurist server loadRemoteURLContent($url, false);
            $reclist = json_decode($reclist, true);
            $reccount = @$reclist['resultCount'];
            if (@$reclist['error'] != null || !($reccount > 0)) {
                print '</Document></kml>';
                return;
            }
            $reclist = explode(",", $reclist['recIDs']);
            $reclist = array_slice($reclist, 0, 1000);
            $squery = $squery . " from Records " . $detTable . " where rec_ID in (" . implode(",", $reclist) . ") " . $ourwhere;
            $squery2 = $squery2 . " from Records " . $detTable2 . " where rec_ID in (" . implode(",", $reclist) . ") " . $ourwhere2;
        } else {
            if (array_key_exists('w', $_REQUEST) && ($_REQUEST['w'] == 'B' || $_REQUEST['w'] == 'bookmark')) {
                $search_type = BOOKMARK;
            } else {
Beispiel #4
0
/**
* Main function
*
* @param mixed $_REQUEST
*/
function executeSmartyTemplate($params)
{
    global $smarty, $outputfile, $isJSout, $rtStructs, $dtStructs, $dtTerms, $gparams, $max_allowed_depth, $publishmode, $execution_counter, $execution_total_counter, $session_id, $mysqli;
    set_time_limit(0);
    //no script execution time limit
    mysql_connection_overwrite(DATABASE);
    //AO: mysql_connection_select - does not work since there is no access to stored procedures(getTemporalDateString)
    //    which Steve used in some queries
    //TODO SAW  grant ROuser EXECUTE on getTemporalDate and any other readonly procs
    //load definitions (USE CACHE)
    //$rtStructs = getAllRectypeStructures(true);
    //$dtStructs = getAllDetailTypeStructures(true);
    //$dtTerms = getTerms(true);
    $params["f"] = 1;
    //always search (do not use cache)
    $isJSout = array_key_exists("mode", $params) && $params["mode"] == "js";
    //use javascript wrap
    $outputfile = array_key_exists("output", $params) ? $params["output"] : null;
    $publishmode = array_key_exists("publish", $params) ? intval($params['publish']) : 0;
    $emptysetmessage = array_key_exists("emptysetmessage", $params) ? $params['emptysetmessage'] : null;
    $gparams = $params;
    //keep to use in other functions
    if (!array_key_exists("limit", $params)) {
        //not defined
        if ($publishmode == 0) {
            $limit_for_interface = intval(@$_SESSION[HEURIST_SESSION_DB_PREFIX . 'heurist']["display-preferences"]['smarty-output-limit']);
            if (!$limit_for_interface || $limit_for_interface < 1) {
                $limit_for_interface = 50;
                //default limit in dispPreferences
            }
            $params["limit"] = $limit_for_interface;
            //force limit
        } else {
            $params["limit"] = PHP_INT_MAX;
        }
    }
    if (@$params['recordset']) {
        //we already have the list of record ids
        if (is_array($params['recordset'])) {
            $qresult = $params['recordset'];
        } else {
            $qresult = json_decode($params['recordset'], true);
        }
        //truncate recordset  - limit does not work for publish mode
        if ($publishmode == 0 && $qresult && array_key_exists('recIDs', $qresult)) {
            $recIDs = explode(',', $qresult['recIDs']);
            if ($params["limit"] < count($recIDs)) {
                $qresult['recIDs'] = implode(',', array_slice($recIDs, 0, $params["limit"]));
            }
        }
    } else {
        if (@$params['h4'] == 1) {
            //search with h4 search engine and got list of ids
            /*    for future use
                  $params['detail']='ids';
                  $params['vo']='h3';
                  $qresult = recordSearch($system, $params);
                  */
            $url = "";
            foreach ($params as $key => $value) {
                $url = $url . $key . "=" . urlencode($value) . "&";
            }
            $url = HEURIST_BASE_URL . "hserver/controller/record_search.php?" . $url . "&detail=ids&vo=h3";
            $result = loadRemoteURLviaSocket($url);
            // loadRemoteURLContent($url);
            $qresult = json_decode($result, true);
        } else {
            $qresult = loadSearch($params);
            //from search/getSearchResults.php - loads array of records based og GET request
        }
    }
    // EMPTY RESULT SET - EXIT
    if (!$qresult || !array_key_exists('recIDs', $qresult) && !array_key_exists('records', $qresult) || $qresult['resultCount'] == 0) {
        if ($emptysetmessage) {
            $error = $emptysetmessage;
            // allows publisher of URL to customise the message if no records retrieved
        } else {
            if ($publishmode > 0) {
                $error = "<b><font color='#ff0000'>Note: There are no records in this view. The URL will only show records to which the viewer has access. Unless you are logged in to the database, you can only see records which are marked as Public visibility</font></b>";
            } else {
                $error = "<b><font color='#ff0000'>Search or Select records to see template output</font></b>";
            }
        }
        if ($isJSout) {
            $error = add_javascript_wrap4($error, null);
        }
        if ($publishmode > 0 && $outputfile != null) {
            //save empty output into file
            save_report_output2($error . "<div style=\"padding:20px;font-size:110%\">Currently there are no results</div>");
        } else {
            echo $error;
        }
        exit;
    }
    //get name of template file
    $template_file = array_key_exists('template', $params) ? $params['template'] : null;
    //get template body from request (for execution from editor)
    $template_body = array_key_exists('template_body', $params) ? $params['template_body'] : null;
    if (null != $template_file) {
        if (substr($template_file, -4) != ".tpl") {
            $template_file = $template_file . ".tpl";
        }
        if (file_exists(HEURIST_SMARTY_TEMPLATES_DIR . $template_file)) {
            $content = file_get_contents(HEURIST_SMARTY_TEMPLATES_DIR . $template_file);
        } else {
            $error = "<b><font color='#ff0000'>Template file {$template_file} does not exist</font></b>";
            echo $error;
            if ($publishmode > 0 && $outputfile != null) {
                //save empty output into file
                save_report_output2($error);
            }
            exit;
        }
    } else {
        $content = $template_body;
    }
    //verify that template has new features
    //need to detect $heurist->getRecord - if it is not found this is old version - show error message
    if (strpos($content, '$heurist->getRecord(') === false) {
        $error = '<p>To improve performance we have made some small changes to the report template specifications (July 2016).</p>' . '<p>You will need to add  {$r = $heurist->getRecord($r)}  immediately after the start of the main record loop, like this:<p/>' . '{*------------------------------------------------------------*}' . '<br/>{foreach $results as $r}' . '<br/><b>{$r = $heurist->getRecord($r)}</b>' . '<br/>{*------------------------------------------------------------*}' . '<p>and similar expressions for record pointer loops - example: {$r.f103 = $heurist->getRecord($r.f103)}</p>' . '<p>Please generate a new report to obtain an example of the syntax, or simply send your report template to ' . '<br/>support at HeuristNetwork dot org and we will adjust the template for you.</p>';
        if ($publishmode > 0 && $outputfile != null) {
            save_report_output2($error);
        } else {
            echo $error;
        }
        exit;
    }
    $k = strpos($content, "{*depth");
    $kp = 8;
    if (is_bool($k) && !$k) {
        $k = strpos($content, "{* depth");
        $kp = 9;
    }
    if (is_numeric($k) && $k >= 0) {
        $nd = substr($content, $k + $kp, 1);
        //strpos($content,"*}",$k)-$k-8);
        if (is_numeric($nd) && $nd < 3) {
            $max_allowed_depth = $nd;
        }
    }
    //end pre-parsing of template
    $mysqli = mysqli_connection_overwrite(DATABASE);
    if ($publishmode == 0 && $session_id != null) {
        updateProgress($mysqli, $session_id, true, '0,0');
    }
    //convert to array that will assigned to smarty variable
    if (array_key_exists('recIDs', $qresult)) {
        $results = explode(",", $qresult["recIDs"]);
        $execution_total_counter = count($results);
        /* OLD WAY
                $records =  explode(",", $qresult["recIDs"]);
                $results = array();
                $k = 0;
                $execution_total_counter = count($records); //'tot_count'=>$tot_count,
        
                foreach ($records as $recordID){
        
                    if(smarty_function_progress(array('done'=>$k), $smarty)){
                        echo 'Execution was terminated';
                        return;
                    }
        
                    $rec = loadRecord($recordID, false, true); //from search/getSearchResults.php
        
                    $res1 = getRecordForSmarty($rec, 0, $k);
                    $res1["recOrder"]  = $k;
                    $k++;
                    array_push($results, $res1);
                }
        */
    } else {
        $records = $qresult["records"];
        $execution_total_counter = count($records);
        //'tot_count'=>$tot_count,
        //v5.5+ $results =  array_column($records, 'recID');
        $results = array_map(function ($value) {
            return @$value['recID'] ? $value['recID'] : array();
        }, $records);
        /*  OLD WAY        
                $records =  $qresult["records"];
                $execution_total_counter = count($records); //'tot_count'=>$tot_count,
                $results = array();
                $k = 0;
                foreach ($records as $rec){
        
                    if(smarty_function_progress(array('done'=>$k), $smarty)){
                        echo 'Execution was terminated';
                        return;
                    }
        
                    $res1 = getRecordForSmarty($rec, 0, $k);
                    $res1["recOrder"]  = $k;
                    $k++;
                    array_push($results, $res1);
                }
        */
    }
    //activate default template - generic list of records
    //we have access to 2 methods getRecord and getRelatedRecords
    $heuristRec = new ReportRecord();
    //$smarty->registerObject('heurist', $heuristRec, array('getRecord'), false);
    $smarty->assignByRef('heurist', $heuristRec);
    $smarty->assign('results', $results);
    //assign
    //$smarty->getvar()
    ini_set('display_errors', 'false');
    // 'stdout' );
    $smarty->error_reporting = 0;
    if ($template_body) {
        //execute template from string - modified template in editor
        //error report level: 1 notices, 2 all, 3 debug mode
        $replevel = array_key_exists('replevel', $params) ? $params['replevel'] : 0;
        if ($replevel == "1" || $replevel == "2") {
            ini_set('display_errors', 'true');
            // 'stdout' );
            $smarty->debugging = false;
            if ($replevel == "2") {
                $smarty->error_reporting = E_ALL & ~E_STRICT & ~E_NOTICE;
            } else {
                $smarty->error_reporting = E_NOTICE;
            }
        } else {
            $smarty->debugging = $replevel == "3";
        }
        $smarty->debug_tpl = dirname(__FILE__) . '/debug_html.tpl';
        //save temporary template
        //this is user name $template_file = "_temp.tpl";
        $template_file = "_" . get_user_username() . ".tpl";
        $file = fopen($smarty->template_dir . $template_file, "w");
        fwrite($file, $template_body);
        fclose($file);
        //$smarty->display('string:'.$template_body);
    } else {
        // usual way - from file
        if (!$template_file) {
            $template_file = 'test01.tpl';
        }
        $smarty->debugging = false;
        $smarty->error_reporting = 0;
        if ($outputfile != null) {
            $smarty->registerFilter('output', 'smarty_output_filter');
        } else {
            if ($isJSout) {
                $smarty->registerFilter('output', 'add_javascript_wrap5');
            }
        }
    }
    //DEBUG
    $smarty->registerFilter('post', 'smarty_post_filter');
    if ($publishmode == 0 && $session_id != null) {
        updateProgress($mysqli, $session_id, true, '0,' . count($results));
        /*session_start();
          $_SESSION[HEURIST_SESSION_DB_PREFIX.'heurist']['smarty_progress2'] = '0,'.count($results);
          session_write_close();*/
    }
    $execution_counter = -1;
    $execution_total_counter = count($results);
    try {
        $smarty->display($template_file);
    } catch (Exception $e) {
        echo 'Exception on execution: ', $e->getMessage(), "\n";
    }
    if ($publishmode == 0 && $session_id != null) {
        updateProgress($mysqli, $session_id, false, 'REMOVE');
    }
    $mysqli->close();
}