예제 #1
0
 /**
  * Method will be called, when plugin is activated. e.g. create some tables required by plugin.
  *
  * @throws Gpf_Exception when plugin can not be activated
  */
 public function onActivate() {
     if (Gpf_Paths::getInstance()->isDevelopementVersion()) {
         return;
     }
     if(!Gpf_Php::isFunctionEnabled('iconv')) {
         throw new Gpf_Exception($this->_('Please enable "iconv" extension.'));
     }
     if(!Gpf_Php::isExtensionLoaded('ionCube Loader')) {
         throw new Gpf_Exception($this->_('Please enable "ionCube Loader" extension.'));
     }
 }
예제 #2
0
 /**
  * @param Gpf_Net_Http_Request $request
  * @return Gpf_Net_Http_Response
  */
 public function execute(Gpf_Net_Http_Request $request)
 {
     if (!$this->isNetworkingEnabled()) {
         throw new Gpf_Exception($this->_('Network connections are disabled'));
     }
     if (!strlen($request->getUrl())) {
         throw new Gpf_Exception('No URL defined.');
     }
     $this->setProxyServer($request);
     if (Gpf_Php::isFunctionEnabled('curl_init') && Gpf_Php::isFunctionEnabled('curl_exec')) {
         return $this->executeWithCurl($request);
     } else {
         return $this->executeWithSocketOpen($request);
     }
 }
예제 #3
0
 protected function isJsonDecodeEnabled()
 {
     return Gpf_Php::isFunctionEnabled('json_decode');
 }
예제 #4
0
 private function checkSSL()
 {
     $version = explode(".", Gpf_Php::isFunctionEnabled("phpversion") ? phpversion() : "3.0.7");
     $php_version = intval($version[0]) * 1000000 + intval($version[1]) * 1000 + intval($version[2]);
     if ($php_version < 4003000) {
         throw new Gpf_Exception("To establishing SSL connections requires at least PHP version 4.3.0");
     }
     if (!Gpf_Php::isFunctionEnabled("extension_loaded") || !extension_loaded("openssl")) {
         throw new Gpf_Exception("Establishing SSL/TLS connections requires the OpenSSL extension enabled");
     }
 }
예제 #5
0
 private function checkMysql()
 {
     $mysqlSupport = Gpf_Php::isFunctionEnabled('mysql_connect');
     $requirement = new Gpf_Install_Requirement();
     $requirement->setResult($mysqlSupport);
     $requirement->setPositiveName($this->_('MySQL extension is installed'));
     $requirement->setNegativeName($this->_('MySQL extension is not installed'));
     $requirement->setFixDescription($this->_('Please enable MySQL extension. More info http://php.net/mysql'));
     $this->addRequirement($requirement);
     if (!$mysqlSupport) {
         return;
     }
     $mysqlVersion = $this->getMysqlVersion();
     if ($mysqlVersion === false) {
         return;
     }
     $mysqlVersionTest = version_compare($mysqlVersion, self::MYSQL_MIN_VERSION) >= 0;
     $requirement = new Gpf_Install_Requirement();
     $requirement->setResult($mysqlVersionTest);
     $requirement->setPositiveName($this->_('MySQL version is %s or higher', self::MYSQL_MIN_VERSION));
     $requirement->setNegativeName($this->_('MySQL version is less then %s', self::MYSQL_MIN_VERSION));
     $requirement->setFixDescription($this->_('Please install MySQL version %s or higher. Your current version is %s. More info http://myqsl.net/', self::MYSQL_MIN_VERSION, $mysqlVersion));
     $this->addRequirement($requirement);
 }
예제 #6
0
 function Login($user, $password, $apop = 0)
 {
     if ($this->pop3_state != "AUTHORIZATION") {
         return $this->SetError("connection is not in AUTHORIZATION state");
     }
     if ($apop) {
         if (!strcmp($this->greeting, "")) {
             return $this->SetError("Server does not seem to support APOP authentication");
         }
         if ($this->PutLine("APOP {$user} " . md5("<" . $this->greeting . ">" . $password)) == 0) {
             return $this->SetError("Could not send the APOP command");
         }
         $response = $this->GetLine();
         if (GetType($response) != "string") {
             return $this->SetError("Could not get APOP login command response");
         }
         if ($this->Tokenize($response, " ") != "+OK") {
             return $this->SetError("APOP login failed: " . $this->Tokenize("\r\n"));
         }
     } else {
         $authenticated = 0;
         if (strcmp($this->authentication_mechanism, "USER") && Gpf_Php::isFunctionEnabled("class_exists") && class_exists("sasl_client_class")) {
             if (strlen($this->authentication_mechanism)) {
                 $mechanisms = array($this->authentication_mechanism);
             } else {
                 $mechanisms = array();
                 if ($this->PutLine("CAPA") == 0) {
                     return $this->SetError("Could not send the CAPA command");
                 }
                 $response = $this->GetLine();
                 if (GetType($response) != "string") {
                     return $this->SetError("Could not get CAPA command response");
                 }
                 if (!strcmp($this->Tokenize($response, " "), "+OK")) {
                     for (;;) {
                         $response = $this->GetLine();
                         if (GetType($response) != "string") {
                             return $this->SetError("Could not retrieve the supported authentication methods");
                         }
                         switch ($this->Tokenize($response, " ")) {
                             case ".":
                                 break 2;
                             case "SASL":
                                 for ($method = 1; strlen($mechanism = $this->Tokenize(" ")); $method++) {
                                     $mechanisms[] = $mechanism;
                                 }
                                 break;
                         }
                     }
                 }
             }
             $sasl = new sasl_client_class();
             $sasl->SetCredential("user", $user);
             $sasl->SetCredential("password", $password);
             if (strlen($this->realm)) {
                 $sasl->SetCredential("realm", $this->realm);
             }
             if (strlen($this->workstation)) {
                 $sasl->SetCredential("workstation", $this->workstation);
             }
             do {
                 $status = $sasl->Start($mechanisms, $message, $interactions);
             } while ($status == SASL_INTERACT);
             switch ($status) {
                 case SASL_CONTINUE:
                     break;
                 case SASL_NOMECH:
                     if (strlen($this->authentication_mechanism)) {
                         return $this->SetError("authenticated mechanism " . $this->authentication_mechanism . " may not be used: " . $sasl->error);
                     }
                     break;
                 default:
                     return $this->SetError("Could not start the SASL authentication client: " . $sasl->error);
             }
             if (strlen($sasl->mechanism)) {
                 if ($this->PutLine("AUTH " . $sasl->mechanism . (isset($message) ? " " . base64_encode($message) : "")) == 0) {
                     return "Could not send the AUTH command";
                 }
                 $response = $this->GetLine();
                 if (GetType($response) != "string") {
                     return "Could not get AUTH command response";
                 }
                 switch ($this->Tokenize($response, " ")) {
                     case "+OK":
                         $response = "";
                         break;
                     case "+":
                         $response = base64_decode($this->Tokenize("\r\n"));
                         break;
                     default:
                         return $this->SetError("Authentication error: " . $this->Tokenize("\r\n"));
                 }
                 for (; !$authenticated;) {
                     do {
                         $status = $sasl->Step($response, $message, $interactions);
                     } while ($status == SASL_INTERACT);
                     switch ($status) {
                         case SASL_CONTINUE:
                             if ($this->PutLine(base64_encode($message)) == 0) {
                                 return "Could not send message authentication step message";
                             }
                             $response = $this->GetLine();
                             if (GetType($response) != "string") {
                                 return "Could not get authentication step message response";
                             }
                             switch ($this->Tokenize($response, " ")) {
                                 case "+OK":
                                     $authenticated = 1;
                                     break;
                                 case "+":
                                     $response = base64_decode($this->Tokenize("\r\n"));
                                     break;
                                 default:
                                     return $this->SetError("Authentication error: " . $this->Tokenize("\r\n"));
                             }
                             break;
                         default:
                             return $this->SetError("Could not process the SASL authentication step: " . $sasl->error);
                     }
                 }
             }
         }
         if (!$authenticated) {
             if ($this->PutLine("USER {$user}") == 0) {
                 return $this->SetError("Could not send the USER command");
             }
             $response = $this->GetLine();
             if (GetType($response) != "string") {
                 return $this->SetError("Could not get user login entry response");
             }
             if ($this->Tokenize($response, " ") != "+OK") {
                 return $this->SetError("User error: " . $this->Tokenize("\r\n"));
             }
             if ($this->PutLine("PASS {$password}") == 0) {
                 return $this->SetError("Could not send the PASS command");
             }
             $response = $this->GetLine();
             if (GetType($response) != "string") {
                 return $this->SetError("Could not get login password entry response");
             }
             if ($this->Tokenize($response, " ") != "+OK") {
                 return $this->SetError("Password error: " . $this->Tokenize("\r\n"));
             }
         }
     }
     $this->pop3_state = "TRANSACTION";
     return "";
 }
 private function createImage()
 {
     if (Gpf_Php::isFunctionEnabled('imagecreatetruecolor')) {
         return imagecreatetruecolor($this->width, $this->height);
     }
     if (Gpf_Php::isFunctionEnabled('imagecreate')) {
         return imagecreate($this->width, $this->height);
     }
     throw new Gpf_Exception("No GD installed");
 }
예제 #8
0
 public static function getNowSeconds()
 {
     if (!Gpf_Php::isFunctionEnabled('microtime')) {
         return time();
     }
     $microtime = microtime(true);
     return time() + $microtime - floor($microtime);
 }
예제 #9
0
 protected function checkRequiredExtensions()
 {
     parent::checkRequiredExtensions();
     if (!Gpf_Php::isFunctionEnabled('pcntl_fork')) {
         throw new Gpf_Exception('Needs pcntl extension to fork processes.');
     }
 }
예제 #10
0
 function checkdnsrr($hostName, $recType = 'MX')
 {
     if (!empty($hostName)) {
         if (!Gpf_Php::isFunctionEnabled('exec') || !Gpf_Php::isFunctionEnabled('escapeshellarg')) {
             //It is not possible to validate domain, because exec or escapeshellarg command is not allowed
             return true;
         }
         exec("nslookup.exe -type={$recType} " . escapeshellarg($hostName), $result);
         // check each line to find the one that starts with the host
         // name. If it exists then the function succeeded.
         foreach ($result as $line) {
             if (preg_match("/^{$hostName}/i", $line)) {
                 return true;
             }
         }
     }
     return false;
 }
예제 #11
0
 protected static function strlen($word)
 {
     if (Gpf_Php::isFunctionEnabled('mb_strlen')) {
         return mb_strlen($word, 'UTF-8');
     } else {
         return strlen($word);
     }
 }
예제 #12
0
 private static function getBaseSysTempDir()
 {
     if (Gpf_Php::isFunctionEnabled('sys_get_temp_dir')) {
         return rtrim(rtrim(sys_get_temp_dir(), '/'), '\\') . '/';
     }
     if (!empty($_ENV['TMP'])) {
         return realpath($_ENV['TMP']);
     } else {
         if (!empty($_ENV['TMPDIR'])) {
             return realpath($_ENV['TMPDIR']);
         } else {
             if (!empty($_ENV['TEMP'])) {
                 return realpath($_ENV['TEMP']);
             } else {
                 $temp_file = tempnam(md5(uniqid(rand(), TRUE)), '');
                 if ($temp_file) {
                     $temp_dir = realpath(dirname($temp_file));
                     unlink($temp_file);
                     return $temp_dir;
                 } else {
                     return FALSE;
                 }
             }
         }
     }
 }
예제 #13
0
 protected function checkRequiredExtensions()
 {
     if (!Gpf_Php::isFunctionEnabled('socket_create')) {
         $this->dieExit('Sockets extension not available.');
     }
 }
예제 #14
0
 /**
  * Outputs file to the output buffer
  */
 public function output()
 {
     if (@readfile($this->fileName) == null) {
         if (!Gpf_Php::isFunctionEnabled('fpassthru')) {
             echo file_get_contents($this->fileName);
         } else {
             $fp = fopen($this->fileName, 'r');
             fpassthru($fp);
             fclose($fp);
         }
     }
 }