function updatejTipsFiles() { global $mosConfig_absolute_path; $release = str_replace('.', '', getFullVersion()); $curl = new jTipsCurl("http://www.jtips.com.au/update.php?action=update&release={$release}"); $result = $curl->exec(); if ($curl->hasError()) { jTipsLogger::_log("Error downloading update"); return 'DOWNLOAD ERROR'; } else { if (substr($result, 0, 3) == 'ERR') { jTipsLogger::_log('update response: ' . $result); return $result; } } $curl->close(); $update_dir = $mosConfig_absolute_path . '/administrator/components/com_jtips/updates'; /*if (!file_exists($update_dir)) { if (!mkdir($update_dir)) { return "FAILED TO MAKE UPLOAD DIRECTORY"; } }*/ $update_file = $update_dir . '/' . date("Y-m-d") . '.zip'; jTipsLogger::_log("writing update to file: " . $update_file); $decoded = unserialize(base64_decode(urldecode($result))); $buffer = base64_decode($decoded['update']); return jTipsWriteUpdateFile($update_file, $buffer); }
function revalidate($force = false) { global $database, $jTips, $mosConfig_absolute_path; $this_file = $mosConfig_absolute_path . '/administrator/components/com_jtips/licence.php'; $jTipsUser = new jTipsUser($database); $jSeason = new jSeason($database); $seasons = array('end_time' => array('type' => 'query', 'query' => ">= '" . gmdate('Y-m-d') . "'")); //BUG 127 - Optionally use an unsecure connection if ($jTips['SSLValidation'] == 0 or $jTips['SSLValidation'] == '0') { $this->host = preg_replace('/https/', 'http', $this->host); jTipsLogger::_log('validating license through unsecure connection'); } $params = array('total_users' => $this->getActiveUserCount(), 'total_seasons' => $jSeason->getCount($seasons), 'license_key' => $jTips['ActivationKey'], 'activation_email' => $jTips['ActivationEmail'], 'domain_name' => preg_replace('/(www\\.)|(www)/i', '', $_SERVER['SERVER_NAME']), 'current_version' => getFullVersion()); $encoded = serialize($params); jTipsLogger::_log('Preparing to revalidate license', 'INFO'); if ($this->hasError() or $this->licence['license_expiry'] <= gmdate('Y-m-d H:i:s', time() - 3600 * 24) or $force) { jTipsLogger::_log('connecting to ' . $this->host); $curl = new jTipsCurl($this->host); $licence_params = array('data' => $params, 'license' => base64_encode(serialize($this->licence))); $data['key'] = base64_encode(serialize($licence_params)); //$fields = $curl->asPostString($licence_params); $fields = $curl->asPostString($data); //jTipsDebug($fields); $curl->setopt(CURLOPT_POST, TRUE); $curl->setopt(CURLOPT_POSTFIELDS, $fields); $curl->setopt(CURLOPT_CONNECTTIMEOUT, 60); jTipsLogger::_log('Sending validation request', 'INFO'); $result = $curl->exec(); if ($curl->hasError()) { jTipsLogger::_log('curl error validation license: ' . $curl->hasError(), 'ERROR'); //Return the current license data if there was an error in the connection return $curl->hasError(); } jTipsLogger::_log('License validation request result:'); jTipsLogger::_log($result); //jTipsDebug($result); //die(); jTipsLogger::_log('Decoding license response', 'INFO'); $decoded = $result == '-1' ? -1 : @unserialize(base64_decode($result)); //jTipsDebug($result); //die(); if ($decoded == -1) { jTipsLogger::_log('error in response', 'ERROR'); return false; } else { jTipsLogger::_log('all is well with license ', 'INFO'); $this->licence = $decoded; $this->writeLicenceFile(); //jTipsDebug($this->licence); return $this->licence; } } else { jTipsLogger::_log('license still current', 'INFO'); return $this->licence; } }
function getLatestVersion() { jTipsLogger::_log('Checking for latest version', 'INFO'); if (!extension_loaded('curl')) { jTipsLogger::_log('curl not loaded in php', 'ERROR'); return 'N/A'; } $release = str_replace('.', '', getFullVersion()); $curl = new jTipsCurl("http://www.jtips.com.au/update.php?version=10&release={$release}"); $curl->setopt(CURLOPT_CONNECTTIMEOUT, 10); $result = $curl->exec(); if ($theError = $curl->hasError()) { return $theError; jTipsLogger::_log($result, 'ERROR'); } $curl->close(); $response = unserialize(base64_decode($result)); return !empty($response) ? $response : "N/A"; }
/** * Arrays are walked through using the key as a the name. Arrays * of Arrays are emitted as repeated fields consistent with such things * as checkboxes. * * @desc Return data as a post string. * @param mixed by reference data to be written. * @param string [optional] name of the datum. * @access public */ function &asPostString(&$theData, $theName = NULL) { $thePostString = ''; $thePrefix = $theName; if (is_array($theData)) { foreach ($theData as $theKey => $theValue) { if ($thePrefix === NULL) { $thePostString .= '&' . jTipsCurl::asPostString($theValue, $theKey); } else { $thePostString .= '&' . jTipsCurl::asPostString($theValue, $thePrefix . '[' . $theKey . ']'); } } } else { $thePostString .= '&' . urlencode((string) $thePrefix) . '=' . urlencode($theData); } $xxx =& substr($thePostString, 1); return $xxx; }