/** * * * @param mixed $filedata */ function downloadViaProxy($filename, $mimeType, $url, $bypassProxy = true) { if (!file_exists($filename)) { // || filemtime($filename)<time()-(86400*30)) $rawdata = loadRemoteURLContent($url, $bypassProxy); saveAsFile($rawdata, $filename); /* if ($raw) { if(file_exists($filename)){ unlink($filename); } $fp = fopen($filename, "w"); //$fp = fopen($filename, "x"); fwrite($fp, $raw); //fflush($fp); // need to insert this line for proper output when tile is first requestet fclose($fp); } */ } if (file_exists($filename)) { downloadFile($mimeType, $filename); } }
/** * request version on Heurist reference server and compare it with the local version * * @param mixed $version_in_session */ function checkVersionOnMainServer($version_in_session) { $version_last_check = getLastCheckedVersion($version_in_session); //check data of last check and last warning email $fname = HEURIST_UPLOAD_ROOT . "lastAdviceSent.ini"; if ($version_last_check == null && file_exists($fname)) { //version in session is outdated //last check and version $version_in_session = file_get_contents($fname); $version_last_check = getLastCheckedVersion($version_in_session); //get last version from file } if ($version_last_check) { //version is valid (not null) return $version_in_session; } //send request to main server at HEURIST_INDEX_BASE_URL // Heurist_Master_Index is the refernece standard for current database version // Maybe this should be changed to Heurist_Sandpit?. Note: sandpit no longer needed, or used, from late 2015 $url = HEURIST_INDEX_BASE_URL . "admin/setup/dbproperties/getCurrentVersion.php?db=Heurist_Master_Index&check=1"; $rawdata = loadRemoteURLContentSpecial($url); if ($rawdata) { //parse result if (checkVersionValid($rawdata)) { // $rawdata contains program version | database version $current_version = explode("|", $rawdata); // $curver is the current program version $curver = explode(".", $current_version[0]); if (count($curver) >= 2) { $major = intval($curver[0]); $subver = intval($curver[1]); //compare with local program version set in HEURIST_VERSION $locver = explode(".", HEURIST_VERSION); $major_local = intval($locver[0]); $subver_local = intval($locver[1]); // TODO: HEURIST_VERSION is not rendering the local version in the email below, yet HEURIST_SERVER_NAME works // and it seems to have set the $variables and to detect local version OK ??? $email_title = null; if ($major_local < $major) { $email_title = "Major new version of Heurist Vsn " . $current_version[0] . " available for " . HEURIST_SERVER_NAME . " (running Vsn " . HEURIST_VERSION . ")"; } else { if ($major_local == $major && $subver_local < $subver) { $email_title = "Heurist update Vsn " . $current_version[0] . " available for " . HEURIST_SERVER_NAME . " (running Vsn " . HEURIST_VERSION . ")"; } } if ($email_title) { //send email to administrator about new database registration $email_text = "Your server is running Heurist version " . HEURIST_VERSION . " The current stable version of Heurist (version " . $current_version[0] . ") is available from <a href='https://code.google.com/p/heurist/'>Google Code</a> or " . "<a href='http://HeuristNetwork.org'>HeuristNetwork.org</a>. We recommend updating your copy of the software if the sub-version has changed " . "(or better still with any change of version).\n\n" . "Heurist is copyright (C) 20075 - 2014 The University of Sydney and available as Open Source software under the GNU-GPL licence. " . "Beta versions of the software with new features may also be available at the Google Code repository or linked from the HeuristNetwork home page."; sendEmail(HEURIST_MAIL_TO_ADMIN, $email_title, $email_text, null); } //save current date of check $version_in_session = date("Y-m-d") . "|" . $current_version[0]; if (!saveAsFile($version_in_session, $fname)) { } return $version_in_session; } } } //cannot access server or it returns invalid data - check next 24 hr $version_in_session = date("Y-m-d") . "|unknown"; if (!saveAsFile($version_in_session, $fname)) { } return $version_in_session; }
function checkVersionOnMainServer($version_in_session) { $version_last_check = getLastCheckedVersion($version_in_session); //check data of last check and last warning email $fname = HEURIST_UPLOAD_ROOT . "lastAdviceSent.ini"; if ($version_last_check == null && file_exists($fname)) { //last check and version $version_in_session = file_get_contents($fname); $version_last_check = getLastCheckedVersion($version_in_session); } if ($version_last_check) { return $version_in_session; } //send request to main server HEURIST_INDEX_BASE_URL $url = HEURIST_INDEX_BASE_URL . "admin/setup/getCurrentVersion.php?db=H3MasterIndex&check=1"; $rawdata = loadRemoteURLContent($url); if ($rawdata) { //parse result $current_version = explode("|", $rawdata); if (count($current_version) > 0) { //debug $current_version[0] = "5.9.1 RC2"; $curver = explode(".", $current_version[0]); if (count($curver) > 2) { $major = intval($curver[0]); $subver = intval($curver[1]); //compare with local versions $locver = explode(".", HEURIST_VERSION); $major_local = intval($locver[0]); $subver_local = intval($locver[1]); $email_title = null; if ($major_local < $major) { $email_title = "Major new version of Heurist Vsn " . $current_version[0] . " available for " . HEURIST_SERVER_NAME . " (running Vsn " . HEURIST_VERSION . ")"; } else { if ($major_local == $major && $subver_local < $subver) { $email_title = "Heurist update Vsn " . $current_version[0] . " available for " . HEURIST_SERVER_NAME . " (running Vsn " . HEURIST_VERSION . ")"; } } if ($email_title) { //send email to administrator about new database registration $email_text = "Your server is running Heurist version " . HEURIST_VERSION . " The current stable version of Heurist (version " . $current_version[0] . ") is available from HeuristScholar.org We recommend updating your copy of the software if the sub-version has changed " . "(or better still with any change of version).\n\n" . "Heurist is copyright (C) The University of Sydney and available as Open Source software under the GNU-GPL licence. " . "Beta versions of the software with new features may also be available at the Google Code repository, linked from the Heurist home page."; // $rv = mail(HEURIST_MAIL_TO_ADMIN, $email_title, $email_text, "From: root"); if (!$rv) { //TODO SAW this should not fail silently error_log("mail send failed: " . HEURIST_MAIL_TO_ADMIN); //to delete check file ????? } else { } } //save current date of check $version_in_session = date("Y-m-d") . "|" . $current_version[0]; if (!saveAsFile($version_in_session, $fname)) { error_log("Can't write file " . $fname); } return $version_in_session; } } } return null; //version check fails }