|
[求助]如何从进程获取文件路途
http://topic.csdn.net/u/20070309/10/e6010155-54fd-4d3c-96e4-129014838710.html?367425102 我在这里看到有一个,但怎么试就是成功不了。 |
|
[原创]简单inline hook ObReferenceObjectByHandle保护进程和屏蔽文件执行
好东东,很不错,双核退出,容易BSOD |
|
|
|
[求助] 外国人写的PHP 注册系统。源程序版
Os.class.php <?php /////////////////////////////////////////////////////////////////////////////// // // Copyright 2006 Point Clark Networks. // /////////////////////////////////////////////////////////////////////////////// // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // /////////////////////////////////////////////////////////////////////////////// /** * Operating system information. * * @author {@link http://www.pointclark.net/ Point Clark Networks} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @package Api * @copyright Copyright 2006, Point Clark Networks * @version 4.0, 1-14-2006 */ /////////////////////////////////////////////////////////////////////////////// // D E P E N D E N C I E S /////////////////////////////////////////////////////////////////////////////// require_once('Engine.class.php'); require_once('File.class.php'); /////////////////////////////////////////////////////////////////////////////// // C L A S S /////////////////////////////////////////////////////////////////////////////// /** * Software package class. * * @package Api */ class Os extends Engine { /////////////////////////////////////////////////////////////////////////////// // M E M B E R S /////////////////////////////////////////////////////////////////////////////// private $os = null; private $version = null; private $previous_os = null; private $previous_version = null; const FILE_RELEASE = '/etc/release'; const FILE_OLD_RELEASE = '/etc/system/release.previous'; const FILE_VENDOR = '/usr/share/system/settings/vendor'; /////////////////////////////////////////////////////////////////////////////// // M E T H O D S /////////////////////////////////////////////////////////////////////////////// /** * Os constructor. */ function __construct() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); parent::__construct(); require_once(GlobalGetLanguageTemplate(__FILE__)); } /** * Returns the name of the operating system/distribution. * * @return string OS name * @throws EngineException */ public function GetName() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); if (is_null($this->os)) $this->_LoadConfig(); return $this->os; } /** * Returns version from previous installed version (upgrade). * * @return string OS version, 0 if none exists * @throws EngineException */ public function GetPreviousVersion() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); try { $file = new File(self::FILE_OLD_RELEASE); if (! $file->Exists()) return 0; $contents = $file->GetContents(); } catch (Exception $e) { throw new EngineException($e->getMessage(), COMMON_ERROR); } $osinfo = explode(" release ", $contents); if (count($osinfo) != 2) throw new EngineException(OS_LANG_ERRMSG_NAME_UNKNOWN, COMMON_ERROR); return $osinfo[1]; } /** * Returns the vendor code for the operating system/distribution. * * @return string vendor code * @throws EngineException */ public function GetVendorCode() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $vendor = ""; try { $file = new File(self::FILE_VENDOR); $vendor = $file->LookupValue("/^vendor\s*=\s*/"); } catch (Exception $e) { throw new EngineException($e->getMessage(), COMMON_ERROR); } return $vendor; } /** * Returns the version of the operating system/distribution. * * @return string OS version * @throws EngineException */ public function GetVersion() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); if (is_null($this->version)) $this->_LoadConfig(); return $this->version; } /** * Populates version and name fields. * * @access private * @throws EngineException */ protected function _LoadConfig() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); try { $file = new File(self::FILE_RELEASE); $contents = $file->GetContents(); } catch (Exception $e) { throw new EngineException($e->getMessage(), COMMON_ERROR); } $osinfo = explode(" release ", $contents); if (count($osinfo) != 2) throw new EngineException(OS_LANG_ERRMSG_NAME_UNKNOWN, COMMON_ERROR); $this->os = $osinfo[0]; $this->version = $osinfo[1]; } /** * @access private */ public function __destruct() { if (COMMON_DEBUG_MODE) $this->Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); parent::__destruct(); } } // vim: syntax=php ts=4 ?> ========================================================== Register.class.php <?php /////////////////////////////////////////////////////////////////////////////// // // Copyright 2003-2006 Point Clark Networks. // /////////////////////////////////////////////////////////////////////////////// // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // /////////////////////////////////////////////////////////////////////////////// // // Eventually, this will get merged with the WebServices class. For now, this // class will handle its own request to the Service Delivery Network. // /////////////////////////////////////////////////////////////////////////////// /** * System registration class. * * @package Api * @subpackage WebServices * @author {@link http://www.pointclark.net/ Point Clark Networks} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @copyright Copyright 2003-2006, Point Clark Networks */ /////////////////////////////////////////////////////////////////////////////// // D E P E N D E N C I E S /////////////////////////////////////////////////////////////////////////////// require_once('ConfigurationFile.class.php'); require_once('Engine.class.php'); require_once('File.class.php'); require_once('Os.class.php'); require_once('Suva.class.php'); require_once('WebServices.class.php'); /////////////////////////////////////////////////////////////////////////////// // C L A S S /////////////////////////////////////////////////////////////////////////////// /** * System registration class. * * Registers your system to the Service Delivery Network (SDN). Instead of * going over the network to check the registration status *every* time, we * simply set a local file to indicate that the system has been registered. * * @package Api * @subpackage WebServices * @author {@link http://www.pointclark.net/ Point Clark Networks} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @copyright Copyright 2003-2006, Point Clark Networks */ class Register extends Engine { const URL_SERVICES = "webservice_services.jsp"; const URL_DEVICE = "webservice_device.jsp"; const URL_USER = "webservice_user.jsp"; const TYPE_ADD = "Add"; const TYPE_UPGRADE = "Upgrade"; const TYPE_REINSTALL = "Reinstall"; protected $hostkey = ""; protected $langcode = "en_US"; protected $vendor = ""; protected $config = array(); protected $is_loaded = false; /////////////////////////////////////////////////////////////////////////////// // M E T H O D S /////////////////////////////////////////////////////////////////////////////// /** * Register constructor. */ function __construct() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); parent::__construct(); require_once(GlobalGetLanguageTemplate(__FILE__)); } /** * Returns registration status. * * @return boolean registration status */ public function GetStatus() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); if (file_exists(WebServices::FILE_REGISTERED)) return true; else return false; } /** * Sets registration to true in local cache. * * @returns void * @throws EngineException */ public function SetStatus() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $file = new File(WebServices::FILE_REGISTERED); try { if ($file->Exists()) $file->Delete(); $file->Create("root", "root", "0644"); } catch (Exception $e) { throw new EngineException($e->GetMessage(), COMMON_ERROR); } } /** * Resets the registration status. * * @param boolean $newkey flag to indicate host key regeneration * @return void * @throws EngineException, ValidationException */ public function Reset($newkey) { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); if (! is_bool($newkey)) throw new ValidationException(LOCALE_LANG_ERRMSG_PARAMETER_IS_INVALID . " - newkey"); if ($newkey) { $suva = new Suva(); $this->hostkey = $suva->ResetHostkey(); } $file = new File(WebServices::FILE_REGISTERED); try { if ($file->Exists()) $file->Delete(); } catch (Exception $e) { throw new EngineException($e->GetMessage(), COMMON_ERROR); } } /** * Simple username/password check for an online account. * * @param string $username username * @param string $password password * @return array request response * @throws */ public function Authenticate($username, $password) { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $response = $this->Request( self::URL_USER, "Authenticate", "&username=$username&password=$password" ); if ($response['exitcode'] != 0) throw new WebServicesRemoteException($response['errormessage'], COMMON_WARNING); return $response; } /** * Returns a list of valid licenses for the given account. * * @param string $username username * @param string $password password * @return array license list */ public function GetLicenseList($username, $password) { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); try { $os = new Os(); $osname = $os->GetName(); $osversion = $os->GetVersion(); } catch (Exception $e) { throw new EngineException($e->GetMessage(), COMMON_WARNING); } $response = $this->Request( self::URL_DEVICE, "GetLicenses", "&username=$username&password=$password&osname=$osname&osversion=$osversion" ); if ($response['exitcode'] == 20) throw new WebServicesNotRegisteredException($response['errormessage'], COMMON_WARNING); if ($response['exitcode'] != 0) throw new WebServicesRemoteException($response['errormessage'], COMMON_WARNING); // Parse the payload //------------------ $payload = $response['payload']; $rawlicenses = preg_replace("/.*<licenses>/si", "", $payload); $rawlicenses = preg_replace("/<\/licenses>.*/si", "", $rawlicenses); if ($rawlicenses) { $licenses = explode("|", $rawlicenses); foreach ($licenses as $rawdetails) { $details = explode(",", $rawdetails); if (count($details) >= 4) { $licenseinfo["serial"] = $details[0]; $licenseinfo["description"] = $details[1]; $licenseinfo["name"] = $details[2]; $licenseinfo["status"] = $details[3]; $licenselist[] = $licenseinfo; } } } return $licenselist; } /** * Returns a list of devices in the given account. * * @param string $username username * @param string $password password * @return array device list */ public function GetDeviceList($username, $password) { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $response = $this->Request( self::URL_DEVICE, "GetDeviceList", "&username=$username&password=$password" ); if ($response['exitcode'] == 20) throw new WebServicesNotRegisteredException($response['errormessage'], COMMON_WARNING); if ($response['exitcode'] != 0) throw new WebServicesRemoteException($response['errormessage'], COMMON_WARNING); // Parse the payload //------------------ $deviceinfo = array(); $payload = $response['payload']; $rawdevices = preg_replace("/.*<devices>/si", "", $payload); $rawdevices = preg_replace("/<\/devices>.*/si", "", $rawdevices); if ($rawdevices) { $devices = explode("|", $rawdevices); foreach ($devices as $rawdetails) { $details = explode(",", $rawdetails); $deviceinfo['id'] = $details[0]; $deviceinfo['name'] = $details[1]; $deviceinfo['osname'] = $details[2]; $deviceinfo['osversion'] = $details[3]; $devicelist[] = $deviceinfo; } } return $devicelist; } /** * Returns product end of license. * * @return integer date */ public function GetEndOfLicense() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $response = $this->Request( self::URL_DEVICE, "GetEndOfLicense", "" ); if ($response['exitcode'] == 20) throw new WebServicesNotRegisteredException($response['errormessage'], COMMON_WARNING); if ($response['exitcode'] != 0) throw new WebServicesRemoteException($response['errormessage'], COMMON_WARNING); // TODO: date should be localized $rawdata = split("\|", $response['payload']); return $rawdata[1]; } /** * Returns product end of life. * * @return integer date */ public function GetEndOfLife() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $response = $this->Request( self::URL_DEVICE, "GetEndOfLife", "" ); if ($response['exitcode'] == 20) throw new WebServicesNotRegisteredException($response['errormessage'], COMMON_WARNING); if ($response['exitcode'] != 0) throw new WebServicesRemoteException($response['errormessage'], COMMON_WARNING); // TODO: date should be localized $rawdata = split("\|", $response['payload']); return $rawdata[1]; } /** * Returns services and subscription status. * * @return array service and subscription status */ function GetServiceList() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $response = $this->Request( self::URL_SERVICES, "GetList", "username=unused" ); if ($response['exitcode'] == 20) throw new WebServicesNotRegisteredException($response['errormessage'], COMMON_WARNING); if ($response['exitcode'] != 0) throw new WebServicesRemoteException($response['errormessage'], COMMON_WARNING); // Parse the payload //------------------ $servicelist = array(); $payload = $response['payload']; // TODO: add available/not available // TODO: help link should only be a URL (not a full href) if ($payload) { $services = explode("|", $payload); foreach($services as $rawdetails) { $details = explode(",", $rawdetails); $serviceinfo['name'] = $details[0]; $serviceinfo['help'] = $details[1]; if ($details[2] == "true") $serviceinfo['state'] = true; else $serviceinfo['state'] = false; $servicelist[] = $serviceinfo; } } return $servicelist; } /** * Returns the terms of service. * * @param string $username username * @param string $password password * @return string terms of service */ public function GetTermsOfService($username, $password) { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $response = $this->Request( self::URL_DEVICE, "GetTermsOfService", "&username=$username&password=$password" ); if ($response['exitcode'] == 20) throw new WebServicesNotRegisteredException($response['errormessage'], COMMON_WARNING); if ($response['exitcode'] != 0) throw new WebServicesRemoteException($response['errormessage'], COMMON_WARNING); $tos = preg_replace("/.*<tos>/si", "", $response['payload']); $tos = preg_replace("/<\/tos>.*/si", "", $tos); return $tos; } /** * Submits request to service delivery network. * * @param string $username username * @param string $password password * @param string $name system name * @param string $serial serial number * @param string $action type of registration * @return void */ public function SubmitRegistration($username, $password, $name, $serial, $action, $terms) { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); try { $os = new Os(); $osname = $os->GetName(); $osversion = $os->GetVersion(); } catch (Exception $e) { throw new EngineException($e->GetMessage(), COMMON_WARNING); } $response = $this->Request( self::URL_DEVICE, $action, "&username=$username&password=$password&name=$name" . "&serial=$serial&terms=$terms&osversion=$osversion" // "&serial=$serial&servicelevel=$servicelevel&terms=$terms&action=$action&osversion=$osversion" ); if ($response['exitcode'] == 20) throw new WebServicesNotRegisteredException($response['errormessage'], COMMON_WARNING); if ($response['exitcode'] != 0) throw new WebServicesRemoteException($response['errormessage'], COMMON_WARNING); } /** * @access private */ private function Request($resource, $action, $postfields) { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); if (! $this->isloaded) $this->_LoadConfig(); // We use the WebServices locale just for consistency. $ws_locale = new WebServices("Register"); // We always send the following information: // - hostkey // - vendor (reseller) // - language (error messages will be translated one of these days) if (!$this->hostkey || !$this->vendor || !$this->langcode) $this->LoadDefaultRequestFields(); $postfields .= "&hostkey=" . $this->hostkey . "&vendor=" . $this->vendor . "&lang=" . $this->langcode; // Registration can take some time set_time_limit(60); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->config['sdn_url'] . "/$resource"); curl_setopt($ch, CURLOPT_POSTFIELDS, "action=" . $action . $postfields); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $rawmessage = chop(curl_exec($ch)); $error = curl_error($ch); $errno = curl_errno($ch); curl_close($ch); // Return useful errno messages for the most common errnos //-------------------------------------------------------- if ($error || $errno) { $data["exitcode"] = 4; if ($errno == CURLE_COULDNT_RESOLVE_HOST) throw new EngineException(WEBSERVICES_LANG_ERRMSG_COULDNT_RESOLVE_HOST, COMMON_WARNING); else if ($errno == CURLE_OPERATION_TIMEOUTED) throw new EngineException(WEBSERVICES_LANG_ERRMSG_TIMEOUT, COMMON_WARNING); else throw new EngineException(WEBSERVICES_LANG_ERRMSG_CONNECTION_FAIL . " " . $error, COMMON_WARNING); } else { // Data is ok... return the payload and error message (if any) //------------------------------------------------------------ if (!preg_match("/exit_code|\d|/", $rawmessage)) { throw new EngineException("invalid page or data", COMMON_WARNING); } else { $rawmessage = trim($rawmessage); $exitcode = preg_replace("/.*<exitcode>/si", "", $rawmessage); $exitcode = preg_replace("/<\/exitcode>.*/si", "", $exitcode); $errormessage = preg_replace("/.*<errormessage>/si", "", $rawmessage); $errormessage = preg_replace("/<\/errormessage>.*/si", "", $errormessage); $payload = preg_replace("/.*<payload>/si", "", $rawmessage); $payload = preg_replace("/<\/payload>.*/si", "", $payload); $data["exitcode"] = $exitcode; $data["errormessage"] = $errormessage; $data["payload"] = $payload; } } return $data; } /** * Loads default remote request fields. * * @access private * @return void * @throws EngineException */ protected function LoadDefaultRequestFields() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); try { $suva = new Suva(); $this->hostkey = $suva->GetHostkey(); $os = new Os(); $vendor = $os->GetVendorCode(); $language= new Locale(); $this->langcode = $language->GetLanguageCode(); } catch (Exception $e) { throw new EngineException($e->GetMessage(), COMMON_ERROR); } } /** * Loads configuration. * * @access private * @return void * @throws EngineException */ protected function _LoadConfig() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $configfile = new ConfigurationFile(WebServices::FILE_CONFIG); try { $this->config = $configfile->Load(); } catch (Exception $e) { throw new EngineException($e->GetMessage(), COMMON_WARNING); } $this->is_loaded = true; } /** * @access private */ public function __destruct() { if (COMMON_DEBUG_MODE) $this->Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); parent::__destruct(); } } // vim: syntax=php ts=4 ?> ========================================================== Suva.class.php <?php /////////////////////////////////////////////////////////////////////////////// // // Copyright 2003-2006 Point Clark Networks. // /////////////////////////////////////////////////////////////////////////////// // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // /////////////////////////////////////////////////////////////////////////////// /** * Suva server. * * @package Api * @subpackage Daemon * @author {@link http://www.pointclark.net/ Point Clark Networks} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @copyright Copyright 2003-2006, Point Clark Networks */ /////////////////////////////////////////////////////////////////////////////// // D E P E N D E N C I E S /////////////////////////////////////////////////////////////////////////////// require_once("Daemon.class.php"); require_once("ShellExec.class.php"); /////////////////////////////////////////////////////////////////////////////// // C L A S S /////////////////////////////////////////////////////////////////////////////// /** * Suva utility class. * * The Suva class can be used to return the current host key. * * @package Api * @subpackage Daemon * @author {@link http://www.pointclark.net/ Point Clark Networks} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @copyright Copyright 2003-2006, Point Clark Networks */ class Suva extends Daemon { /////////////////////////////////////////////////////////////////////////////// // C O N S T A N T S /////////////////////////////////////////////////////////////////////////////// const CMD_SUVACTL = "/usr/local/suva/bin/suvactl"; const PARAM_GET_HOSTKEY = "--get-hostkey"; const PARAM_NEW_HOSTKEY = "--new-hostkey"; /////////////////////////////////////////////////////////////////////////////// // M E T H O D S /////////////////////////////////////////////////////////////////////////////// /** * Suva constructor. */ function __construct() { if (COMMON_DEBUG_MODE) $this->Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); parent::__construct("suvad"); require_once(GlobalGetLanguageTemplate(__FILE__)); } /** * Returns hostkey. * * @return string hostkey * @throws EngineException */ function GetHostkey() { if (COMMON_DEBUG_MODE) $this->Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $shell = new ShellExec(); try { $exitcode = $shell->Execute(Suva::CMD_SUVACTL, Suva::PARAM_GET_HOSTKEY, true); if ($exitcode != 0) throw new EngineException(SUVA_LANG_ERRMSG_HOSTKEY_NOT_FOUND, COMMON_WARNING); } catch (Exception $e) { throw new EngineException($e->getMessage(), COMMON_WARNING); } return implode(" ", $shell->GetOutput()); } /** * Resets a hostkey. * * @throws EngineException */ function ResetHostkey() { if (COMMON_DEBUG_MODE) $this->Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $shell = new ShellExec(); try { $exitcode = $shell->Execute(Suva::CMD_SUVACTL, Suva::PARAM_NEW_HOSTKEY, true); if ($exitcode != 0) throw new EngineException($shell->GetLastOutputLine(), COMMON_WARNING); } catch (Exception $e) { throw new EngineException($e->getMessage(), COMMON_WARNING); } } /** * @ignore */ function __destruct() { if (COMMON_DEBUG_MODE) $this->Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); parent::__destruct(); } } // vim: syntax=php ts=4 ?> ========================================================== WebServices.class.php <?php /////////////////////////////////////////////////////////////////////////////// // // Copyright 2003-2005 Point Clark Networks. // /////////////////////////////////////////////////////////////////////////////// // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // /////////////////////////////////////////////////////////////////////////////// /** * Web services class. * * @package Api * @subpackage WebServices * @author {@link http://www.pointclark.net/ Point Clark Networks} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @copyright Copyright 2003-2006, Point Clark Networks */ /////////////////////////////////////////////////////////////////////////////// // D E P E N D E N C I E S /////////////////////////////////////////////////////////////////////////////// require_once('ConfigurationFile.class.php'); require_once('Engine.class.php'); require_once('File.class.php'); require_once('Folder.class.php'); require_once('Locale.class.php'); require_once('Os.class.php'); require_once('Suva.class.php'); /////////////////////////////////////////////////////////////////////////////// // E X C E P T I O N C L A S S E S /////////////////////////////////////////////////////////////////////////////// /** * Remote web services exception. * * @package Api * @subpackage Exception * @author {@link http://www.pointclark.net/ Point Clark Networks} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @copyright Copyright 2007, Point Clark Networks */ class WebServicesNoCacheException extends EngineException { /** * Web Services no cache exception constructor. * * @param string $errmsg error message * @param int $code error code */ public function __construct() { parent::__construct(WEBSERVICES_LANG_SUBSCRIPTION_INFORMATION_UNAVAILABLE, COMMON_INFO); } } /** * Not registered exception. * * @package Api * @subpackage Exception * @author {@link http://www.pointclark.net/ Point Clark Networks} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @copyright Copyright 2006, Point Clark Networks */ class WebServicesNotRegisteredException extends EngineException { /** * Web Services not registered constructor. */ public function __construct() { parent::__construct(WEBSERVICES_LANG_SYSTEM_NOT_REGISTERED, COMMON_INFO); } } /** * Remote web services exception. * * @package Api * @subpackage Exception * @author {@link http://www.pointclark.net/ Point Clark Networks} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @copyright Copyright 2006, Point Clark Networks */ class WebServicesRemoteException extends EngineException { /** * Web Services Exception constructor. * * @param string $errmsg error message * @param int $code error code */ public function __construct($errmsg, $code) { parent::__construct($errmsg, $code); } } /////////////////////////////////////////////////////////////////////////////// // C L A S S /////////////////////////////////////////////////////////////////////////////// /** * Web services class. * * The Web Service class interacts with Point Clark Networks' backend * systems -- the Service Delivery Network. This network provides dynamic DNS, * Managed VPN, software updates, content filter updates, and much more. * This class will be replaced by direct SOAP calls in the future. * * @package Api * @subpackage WebServices * @author {@link http://www.pointclark.net/ Point Clark Networks} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @copyright Copyright 2003-2006, Point Clark Networks */ class WebServices extends Engine { /////////////////////////////////////////////////////////////////////////////// // M E M B E R S /////////////////////////////////////////////////////////////////////////////// protected $service; protected $cachefile; protected $config = array(); protected $is_loaded = false; protected $hostkey = ""; protected $langcode = "en_US"; protected $vendor = ""; const CONSTANT_UNKNOWN = 'unknown'; const CONSTANT_UNLIMITED = 'unlimited'; const CONSTANT_INCLUDED = 'included'; const CONSTANT_EXTRA = 'extra'; const CONSTANT_ASP = 'asp'; const CONSTANT_NOT_REGISTERED = 20; const PATH_SUBSCRIPTIONS = '/var/lib/system/services'; const FILE_REGISTERED = '/usr/share/system/modules/services/registered'; const FILE_CONFIG = '/usr/share/system/modules/services/environment'; /////////////////////////////////////////////////////////////////////////////// // M E T H O D S /////////////////////////////////////////////////////////////////////////////// /** * The WebServices constructor. * * The constructor requires the name of the remote service, for example: * * - DynamicDNS - Dynamic DNS service * - IpReferrer - IP Referrer service * - Ipsec - Managed VPN service * - Register - System registration service * - Snort - Intrusion detection rules updates service * - SoftwareUpdate - Software update service * - Sophos - Antivirus engine and virus definition service * - SpamAssassin - Antispam service * * @param string $service service name */ function __construct($service) { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); parent::__construct(); require_once(GlobalGetLanguageTemplate(__FILE__)); $this->service = $service; $this->cachefile = self::PATH_SUBSCRIPTIONS . "/$service/subscription"; } /** * A generic way to communicate with the Service Delivery Network (SDN). * * You can send IP updates, retrieve software update information, check * dynamic VPN status, etc. The method will immediately attempt a * connection with alternate servers in the SDN if a previous connection * attempt fails. * * @access private * @param string $action action * @param string $postfields post fields (eg ?ip=1.2.3.4) * @return string payload * @throws EngineException, ValidationException, WebServicesRemoteException */ public function Request($action, $postfields = "") { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); if (! $this->is_loaded) $this->_LoadConfig(); // The FILE_REGISTERED file is created when a box is successfully // registered. We check to see if this file exists to save the // backend from handling endless invalid requests. if ($this->service != "Apt") { if (! file_exists(self::FILE_REGISTERED)) throw new WebServicesNotRegisteredException(); } $sdnerror = ""; $resource = strtolower($this->service) . ".php?action=" . strtolower($action) . $postfields; // We always send the following information: // - hostkey // - vendor (reseller) // - language (error messages will be translated one of these days) if (!$this->hostkey || !$this->vendor || !$this->langcode) $this->LoadDefaultRequestFields(); $resource .= "&hostkey=" . $this->hostkey . "&vendor=" . $this->vendor . "&lang=" . $this->langcode; for ($inx = 1; $inx <= $this->config['sdn_servers']; $inx++) { $server = $this->config['sdn_prefix'] . "$inx" . "." . $this->config['sdn_domain']; // Logger::Syslog("webservices", "Sending request to SDN $server", "WebServices." . $action); if (isset($ch)) unset($ch); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://" . $server . "/" . $this->config['sdn_version'] . "/" . $resource); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 20); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $rawmessage = chop(curl_exec($ch)); $error = curl_error($ch); $errno = curl_errno($ch); curl_close($ch); // Return useful errno messages for the most common errnos //-------------------------------------------------------- if ($errno == 0) { //------------------------------------------------------------------ // // Data is ok... return the payload and error message (if any) // // payload format: // exit_code|<code>|<error message> // <payload> // // e.g., a request for dynamic DNS information looks like: // exit_code|0|ok // 123.12.12.32|1052023323|test.system.net // //------------------------------------------------------------------ // Make sure the return data is valid if (!preg_match("/exit_code|\d|/", $rawmessage)) { $sdnerror = "$server: invalid page or data"; } else { $message = explode("\n", $rawmessage, 2); $returned = explode("|", $message[0], 3); if (!isset($returned[1])) { $sdnerror = "$server: invalid return code"; $this->Log(COMMON_DEBUG, $sdnerror, "WebServices." . $action, __LINE__); } else if ($returned[1] == self::CONSTANT_NOT_REGISTERED) { throw new WebServicesNotRegisteredException(); } else if ($returned[1] != 0) { throw new WebServicesRemoteException($returned[2], COMMON_INFO); } else { // Not all replies have a payload (just true/false) if (isset($message[1])) return $message[1]; else return ""; } } } } // None of the SDN servers responded -- send the last error code. if ($sdnerror) throw new EngineException($sdnerror, COMMON_WARNING); else if ($errno == CURLE_COULDNT_RESOLVE_HOST) throw new EngineException(WEBSERVICES_LANG_ERRMSG_COULDNT_RESOLVE_HOST, COMMON_WARNING); else if ($errno == CURLE_OPERATION_TIMEOUTED) throw new EngineException(WEBSERVICES_LANG_ERRMSG_TIMEOUT, COMMON_WARNING); else throw new EngineException(WEBSERVICES_LANG_ERRMSG_CONNECTION_FAIL . " " . $error, COMMON_WARNING); } /** * Returns subscription status. * * Information in hash array includes: * - policy * - expiry * - license * - title * - state * - status * * @param boolean $realtime set realtime to true to fetch real-time data * @return array information about subscription * @throws EngineException, ValidationException, WebServicesRemoteException */ public function GetSubscriptionStatus($realtime) { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $file = new File($this->cachefile); $fileexists = false; try { $fileexists = $file->Exists(); } catch (Exception $e) { throw new EngineException($e->GetMessage(), COMMON_ERROR); } if (!$realtime && $fileexists) { try { $state = $file->LookupValue("/^state\s*=\s*/"); $isenabled = $file->LookupValue("/^isenabled\s*=\s*/"); $info["policy"] = $file->LookupValue("/^policy\s*=\s*/"); $info["expiry"] = $file->LookupValue("/^expiry\s*=\s*/"); $info["license"] = $file->LookupValue("/^license\s*=\s*/"); $info["title"] = $file->LookupValue("/^title\s*=\s*/"); $info["message"] = $file->LookupValue("/^message\s*=\s*/"); if ($state == "t") $info["state"] = true; else $info["state"] = false; if ($isenabled == "t") $info["isenabled"] = true; else $info["isenabled"] = false; return $info; } catch (Exception $e) { throw new EngineException($e->GetMessage(), COMMON_ERROR); } } else if (!$realtime && !$fileexists) { throw new WebServicesNoCacheException(); } // Catch the harmless exceptions -- we do not want them to // throw a COMMON_ERROR exception. try { $payload = $this->Request("GetSubscriptionInfo"); } catch (WebServicesNotRegisteredException $e) { throw new WebServicesNotRegisteredException(); } catch (WebServicesRemoteException $e) { throw new WebServicesRemoteException($e->GetMessage(), COMMON_INFO); } catch (Exception $e) { throw new EngineException($e->GetMessage(), COMMON_ERROR); } // payload format -- state|policy|expiry|license_type|title|message|state $result = explode("|", $payload); if ($result[0] == "t") $info["state"] = true; else $info["state"] = false; $info["policy"] = $result[1]; $info["expiry"] = $result[2]; $info["license"] = $result[3]; $info["title"] = $result[4]; $info["message"] = $result[5]; if ($result[6] == "t") $info["isenabled"] = true; else $info["isenabled"] = false; // Cache info //----------- $folder = new Folder(self::PATH_SUBSCRIPTIONS . "/$this->service"); try { if (! $folder->Exists()) $folder->Create("suvlet", "suvlet", "0755"); if ($fileexists) $file->Delete(); $file->Create("suvlet", "suvlet", "0644"); $file->AddLines( "state = $result[0]\n" . "policy = $result[1]\n" . "expiry = $result[2]\n" . "license = $result[3]\n" . "title = $result[4]\n" . "message = $result[5]\n" . "isenabled = $result[6]\n" ); } catch (Exception $e) { throw new EngineException($e->GetMessage(), COMMON_ERROR); } return $info; } /** * Loads default remote request fields. * * @access private * @return void * @throws EngineException */ protected function LoadDefaultRequestFields() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); try { $suva = new Suva(); $this->hostkey = $suva->GetHostkey(); $os = new Os(); $this->vendor = $os->GetVendorCode(); $language= new Locale(); $this->langcode = $language->GetLanguageCode(); } catch (Exception $e) { throw new EngineException($e->GetMessage(), COMMON_ERROR); } } /** * Loads configuration. * * @access private * @return void * @throws EngineException */ protected function _LoadConfig() { if (COMMON_DEBUG_MODE) self::Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); $configfile = new ConfigurationFile(self::FILE_CONFIG); try { $this->config = $configfile->Load(); } catch (Exception $e) { throw new EngineException($e->GetMessage(), COMMON_WARNING); } $this->is_loaded = true; } /** * @ignore */ public function __destruct() { if (COMMON_DEBUG_MODE) $this->Log(COMMON_DEBUG, "called", __METHOD__, __LINE__); parent::__destruct(); } } // vim: syntax=php ts=4 ?> 完!! |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值