public function update()
 {
     $inTransaction = Database::inTransaction();
     if (!$inTransaction) {
         Database::beginTransaction();
     }
     $statement = Database::prepare("UPDATE user_power SET `uid`=:uid WHERE id=:id");
     $statement->bindValue(':uid', $this->uid, \PDO::PARAM_INT);
     $statement->bindValue(':id', $this->id, \PDO::PARAM_INT);
     $statement->execute();
     $this->uid = Database::lastInsertId();
     $statement->execute();
     if (!$inTransaction) {
         Database::commit();
     }
 }
Esempio n. 2
0
 /**
  * update User info
  *
  */
 public function updateUser()
 {
     $inTransaction = Database::inTransaction();
     if (!$inTransaction) {
         Database::beginTransaction();
     }
     $statement = Database::prepare("UPDATE member SET email=:email, `password`=:pwd, sspwd=:sspwd, `port`=:port, nickname=:nickname,\n            `flow_up`=:flow_up, `flow_down`=:flow_down, transfer=:transfer, plan=:plan, `enable`=:enable, invite=:invite, regDateLine=:regDateLine WHERE uid=:userId");
     $statement->bindValue(':email', $this->email, \PDO::PARAM_STR);
     $statement->bindValue(':pwd', $this->password, \PDO::PARAM_STR);
     $statement->bindValue(':sspwd', $this->sspwd, \PDO::PARAM_STR);
     $statement->bindValue(':port', $this->port, \PDO::PARAM_INT);
     $statement->bindValue(':nickname', $this->nickname, \PDO::PARAM_STR);
     $statement->bindValue(':flow_up', $this->flow_up, \PDO::PARAM_INT);
     $statement->bindValue(':flow_down', $this->flow_down, \PDO::PARAM_INT);
     $statement->bindValue(':transfer', $this->transfer, \PDO::PARAM_INT);
     $statement->bindValue(':plan', $this->plan, \PDO::PARAM_STR);
     $statement->bindValue(':enable', $this->enable, \PDO::PARAM_INT);
     $statement->bindValue(':invite', $this->invite, \PDO::PARAM_INT);
     $statement->bindValue(':regDateLine', $this->regDateLine, \PDO::PARAM_INT);
     $statement->bindValue(':userId', $this->uid, \PDO::PARAM_INT);
     $statement->execute();
     if (!$inTransaction) {
         Database::commit();
     }
 }
Esempio n. 3
0
 public function updateInvite()
 {
     $inTransaction = Database::inTransaction();
     if (!$inTransaction) {
         Database::beginTransaction();
     }
     $statement = Database::prepare("UPDATE invite SET expiration=:expiration,\n\t\t\t`reguid`=:reguid, `regDateLine`=:regDateLine, `status`=:status, `inviteIp`=:inviteIp WHERE invite=:invite");
     $statement->bindValue(':expiration', $this->expiration, \PDO::PARAM_INT);
     $statement->bindValue(':reguid', $this->reguid, \PDO::PARAM_INT);
     $statement->bindValue(':regDateLine', $this->regDateLine, \PDO::PARAM_INT);
     $statement->bindValue(':status', $this->status, \PDO::PARAM_INT);
     $statement->bindValue(':inviteIp', $this->inviteIp, \PDO::PARAM_STR);
     $statement->bindValue(':invite', $this->invite, \PDO::PARAM_STR);
     $statement->execute();
     if (!$inTransaction) {
         Database::commit();
     }
 }
Esempio n. 4
0
 /**
  * Save new password
  * @param string $password New password
  */
 public function savePassword($password)
 {
     $salt = substr(md5($this->id . $this->email . ENCRYPT_KEY), 8, 16);
     $this->password = substr(md5(md5($password) . $salt), 0, 30) . 'T' . self::ENCRYPT_TYPE_ENHANCE;
     $inTransaction = Database::inTransaction();
     if (!$inTransaction) {
         Database::beginTransaction();
     }
     $statement = Database::prepare("UPDATE member SET `password`=:pwd WHERE id=:userId");
     $statement->bindValue(':pwd', $this->password, \PDO::PARAM_STR);
     $statement->bindValue(':userId', $this->id, \PDO::PARAM_INT);
     $statement->execute();
     if (!$inTransaction) {
         Database::commit();
     }
 }
Esempio n. 5
0
 public static function handleException($e)
 {
     if (error_reporting() == 0) {
         return;
     }
     while (ob_get_level() > 0) {
         ob_end_clean();
     }
     $eS = $e->getMessage();
     $eN = $e->getCode();
     $eC = $e->getTrace();
     // Put current context into stack trace
     array_unshift($eC, array('file' => $e->getFile(), 'line' => $e->getLine()));
     if ($e instanceof ErrorException) {
         switch ($e->getSeverity()) {
             case E_ERROR:
             case E_PARSE:
             case E_CORE_ERROR:
             case E_USER_ERROR:
             default:
                 $logType = LogLevel::CRITICAL;
                 break;
             case E_WARNING:
             case E_CORE_WARNING:
             case E_USER_WARNING:
                 $logType = LogLevel::WARNING;
                 break;
             case E_DEPRECATED:
             case E_NOTICE:
             case E_USER_DEPRECATED:
             case E_USER_NOTICE:
                 $logType = LogLevel::NOTICE;
                 break;
             case E_STRICT:
                 $logType = LogLevel::INFO;
                 break;
         }
         $exceptionType = 'error';
     } else {
         $exceptionType = get_class($e);
         if (strpos($exceptionType, '\\') !== false) {
             $exceptionType = substr(strrchr($exceptionType, '\\'), 1);
         }
         $logType = LogLevel::ERROR;
     }
     $logString = sprintf('[Gateway] Uncaught %s#%d with message: "%s".', $exceptionType, $eN, $eS);
     unset($exceptionType);
     // Current request context
     $resolver = Resolver::getActiveInstance();
     if ($resolver) {
         if ($resolver->request()) {
             $client = $resolver->request()->client();
         }
         $response = $resolver->response();
     }
     unset($resolver);
     // Prevent recursive errors on logging when database fails to connect.
     if (Database::isConnected()) {
         // Release table locks of current session.
         @Database::unlockTables(false);
         if (Database::inTransaction()) {
             @Database::rollback();
         }
     }
     $logContext = array_filter(array('errorContext' => $eC, 'client' => @$client));
     // Log the error
     try {
         @Log::log($logType, $logString, $logContext);
     } catch (\Exception $e) {
     }
     unset($logContext);
     // Send the error to output
     $output = array('error' => $eS, 'code' => $eN);
     if (System::environment(false) != System::ENV_PRODUCTION) {
         $output['trace'] = $eC;
     }
     // Display error message
     if (isset($response) && @$client['type'] != 'cli') {
         // Do i18n when repsonse context is available
         if ($e instanceof GeneralException) {
             $errorMessage = $response->__($eS, $logType);
             if ($errorMessage) {
                 $output['error'] = $errorMessage;
             }
         }
         if ($e instanceof ErrorException) {
             $statusCode = 500;
         } else {
             $statusCode = 400;
         }
         if ($e instanceof ValidationException) {
             $output['errors'] = $e->getErrors();
         }
         $response->clearHeaders();
         $response->header('Content-Type', 'application/json; charset=utf-8');
         $response->send($output, $statusCode);
     } else {
         header('Content-Type: text/plain', true, 500);
         echo "{$logString}\n";
         // Debug stack trace
         if (System::environment(false) != System::ENV_PRODUCTION) {
             echo "Trace:\n";
             array_walk($eC, function ($stack, $index) {
                 $trace = $index + 1 . '.';
                 $function = implode('->', array_filter(array(@$stack['class'], @$stack['function'])));
                 if ($function) {
                     $trace .= " {$function}()";
                 }
                 unset($function);
                 if (@$stack['file']) {
                     $trace .= " {$stack['file']}";
                     if (@$stack['line']) {
                         $trace .= ":{$stack['line']}";
                     }
                 }
                 echo "{$trace}\n";
             });
         }
     }
     // CLI exit code on Exceptions and Errors
     if (in_array($logType, array(LogLevel::ERROR, LogLevel::CRITICAL, LogLevel::ALERT, LogLevel::EMERGENCY))) {
         $exitCode = $e->getCode();
         if ($exitCode <= 0) {
             $exitCode = 1;
         }
         die($exitCode);
     }
 }
Esempio n. 6
0
 /**
  * 删除 node
  * @param $nodeId  Int
  */
 public static function deleteNode($nodeId)
 {
     $inTransaction = Database::inTransaction();
     if (!$inTransaction) {
         Database::beginTransaction();
     }
     $statement = Database::prepare("DELETE * FROM node WHERE id=:id");
     $statement->bindValue(':id', $nodeId, \PDO::PARAM_INT);
     $statement->execute();
     if (!$inTransaction) {
         Database::commit();
     }
 }
Esempio n. 7
0
 /**
  * Update message
  */
 public function update()
 {
     $inTransaction = Database::inTransaction();
     if (!$inTransaction) {
         Database::beginTransaction();
     }
     $statement = Database::prepare("UPDATE message SET `content`=:content, `pushTime`=:pushTime,\n\t\t\t`addTime`=:addTime, `pushUsers`=:pushUsers, `type`=:type, `pushEndTime`:=pushEndTime,\n\t\t\t `order`=:order WHERE id=:id");
     $statement->bindValue(':content', $this->name, \PDO::PARAM_STR);
     $statement->bindValue(':pushTime', $this->type, \PDO::PARAM_INT);
     $statement->bindValue(':addTime', $this->server, \PDO::PARAM_INT);
     $statement->bindValue(':pushUsers', $this->method, \PDO::PARAM_STR);
     $statement->bindValue(':type', $this->info, \PDO::PARAM_INT);
     $statement->bindValue(':pushEndTime', $this->status, \PDO::PARAM_INT);
     $statement->bindValue(':order', $this->order, \PDO::PARAM_INT);
     $statement->bindValue(':id', $this->order, \PDO::PARAM_INT);
     $statement->execute();
     if (!$inTransaction) {
         Database::commit();
     }
 }