예제 #1
0
 public function returnError($errorMsg = '', $errorCode = -1, $httpStatus = 200)
 {
     if (preg_match("/too many connection/i", $errorMsg)) {
         $errorMsg = "流量爆表啦!小伙伴们请稍后重试吧~我们正在马不停蹄地解决!";
     }
     if (isset($_SERVER['HTTP_ORIGIN'])) {
         $origin = $_SERVER['HTTP_ORIGIN'];
         if (preg_match(self::DOMAIN_PATTERN, $origin) === 1) {
             header('Access-Control-Allow-Origin: ' . $origin);
             header('Access-Control-Allow-Credentials: true');
         }
     }
     header("Expires: 0");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Cache-Control: post-check=0, pre-check=0", false);
     header("Pragma: no-cache");
     header('Content-Type: application/json; charset=utf-8');
     if (!empty($errorMsg)) {
         echo json_encode(['ok' => 0, 'code' => $errorCode, 'msg' => $errorMsg], JSON_UNESCAPED_UNICODE);
     } else {
         echo json_encode(['ok' => 0, 'code' => $errorCode, 'msg' => TErrorConstants::getErrorMsg($errorCode)], JSON_UNESCAPED_UNICODE);
     }
     Wk::app()->stop();
 }
예제 #2
0
 public function beforeAction()
 {
     parent::beforeAction();
     Wk_Request::startSession(WAKA_DOMAIN);
     if (isset($_SESSION['user'])) {
         $this->curUser = $_SESSION['user'];
     }
     if (isset($this->curUser)) {
         Wk::app()->user = new Wk_WebUser();
         Wk::app()->user->userid = $this->curUser->id;
         Wk::app()->user->utoken = "";
     }
     if (isset($this->curUser)) {
         WkAdminUserService::getInstance()->setLoginCookie($this->curUser);
     } else {
         unset($_COOKIE['WAKAUID']);
         unset($_COOKIE['WAKAUMB']);
         setcookie('WAKAUID', '', time() - 3600, '/', WAKA_DOMAIN);
         setcookie('WAKAUMB', '', time() - 3600, '/', WAKA_DOMAIN);
     }
     $access = $this->access();
     if (!empty($access['?']) && in_array($this->actionName, $access['?'])) {
         if ($this->isLogin()) {
             throw new Wk_Exception('', TErrorConstants::E_LOGIN);
         }
     } elseif (!empty($access['*']) && in_array($this->actionName, $access['*'])) {
     } elseif ($this->isGuest()) {
         throw new Wk_Exception('', TErrorConstants::E_NOT_LOGIN);
     }
 }
예제 #3
0
 public function _templateAction()
 {
     $config = isset($_GET['__config__']) ? $_GET['__config__'] : null;
     if (!isset($config)) {
         throw new Wk_Exception("", -1);
     }
     if (!empty($config['redirect'])) {
         Wk_Request::redirect($config['redirect']);
     }
     $needLogin = isset($config['needLogin']) ? $config['needLogin'] : 0;
     if (isset($needLogin) && $needLogin == 1 && !$this->isLogin()) {
         $this->redirectLogin();
     }
     $needLogout = isset($config['needLogout']) ? $config['needLogout'] : 0;
     if (isset($needLogout) && $needLogout == 1 && $this->isLogin()) {
         // throw new K_Exception('', TErrorConstants::E_LOGIN);
         Wk_Request::redirect("/");
     }
     $path = $config['path'];
     if (!empty($path)) {
         unset($_GET['__config__']);
         $content = $this->renderReleaseTemplate($path, true);
         echo $content;
     }
     Wk::app()->stop();
 }
예제 #4
0
 public function renderAjax($obj = null)
 {
     $json = ['ok' => 1];
     if (isset($obj)) {
         $json['obj'] = $obj;
     }
     header('Content-Type: application/json; charset=utf-8');
     echo json_encode($json, JSON_UNESCAPED_UNICODE);
     Wk::app()->stop();
 }
예제 #5
0
 public function renderAjax($obj = null)
 {
     $json = ['ok' => 1];
     if (isset($obj)) {
         $json['obj'] = $obj;
     }
     $jsonStr = json_encode($json, JSON_UNESCAPED_UNICODE);
     if (isset($_SERVER['HTTP_ORIGIN'])) {
         $origin = $_SERVER['HTTP_ORIGIN'];
         if (preg_match(self::DOMAIN_PATTERN, $origin) === 1) {
             header('Access-Control-Allow-Origin: ' . $origin);
             header('Access-Control-Allow-Credentials: true');
         }
     }
     header('Content-Type: application/json; charset=utf-8');
     echo $jsonStr;
     Wk::app()->stop();
 }
예제 #6
0
 public function _templateAction()
 {
     if ($this->isGuest() && strpos($_SERVER['REQUEST_URI'], '/admin/login') !== 0) {
         Wk_Request::redirect('/admin/login');
     }
     if ($this->isLogin() && strpos($_SERVER['REQUEST_URI'], '/admin/login') === 0) {
         Wk_Request::redirect('/admin');
     }
     $config = isset($_GET['__config__']) ? $_GET['__config__'] : null;
     if (!isset($config)) {
         throw new Wk_Exception("", -1);
     }
     $path = $config['path'];
     if (!empty($path)) {
         unset($_GET['__config__']);
         $content = $this->renderReleaseTemplate($path, true);
         echo $content;
     }
     Wk::app()->stop();
 }
예제 #7
0
파일: Wk_Log.php 프로젝트: telander/waka
 private static function formatSMessage()
 {
     $prefix = date('Y-m-d H:i:s ', Wk_Request::getTime());
     $user = Wk::app()->user;
     if (isset($user) && !empty($user->userid) && !empty($user->utoken)) {
         $prefix .= '[userid:' . $user->userid . ']';
         $prefix .= '[usertoken:' . $user->utoken . ']';
     }
     if (session_status() == PHP_SESSION_ACTIVE) {
         $prefix .= '[SESSION_ID:' . session_id() . ']';
     }
     if (!empty($_COOKIE['SERVERID'])) {
         $prefix .= '[SERVERID:' . $_COOKIE['SERVERID'] . ']';
     }
     $prefix .= $_SERVER['REQUEST_URI'];
     $referStr = '[REFER:';
     $hasRefer = false;
     $locStr = '[LOC:';
     $hasLoc = false;
     if (!empty($_SERVER['REQUEST_URI'])) {
         $urlArr = parse_url($_SERVER['REQUEST_URI']);
         //$prefix .= "[PATH:{$urlArr['path']}]";
         $getParams = [];
         parse_str($urlArr['query'], $getParams);
         if (!empty($getParams)) {
             //$prefix .= '[GET:';
             foreach ($getParams as $key => $value) {
                 //                    if (!in_array($key, ['v','vc','vd','token','timestr','sign','lang'])) {
                 //                        $prefix .= "$key=$value&";
                 //                    }
             }
             //$prefix .= ']';
         }
     }
     $prefix .= " ";
     //        if (isset(K::app()->getController()) && !empty(K::app()->getController()->appParam)) {
     //            $prefix .= '[APP_PARAM:';
     //            foreach (K::app()->getController()->appParam as $key => $value) {
     //                $prefix .= "$key=$value&";
     //            }
     //            $prefix .= ']';
     //        }
     //$prefix .= self::getServerVariable('SERVER_SIGNATURE');
     //$prefix .= self::getServerVariable('REQUEST_URI');
     //$prefix .= self::getServerVariable('QUERY_STRING');
     if (!empty($_POST)) {
         $prefix .= '[POST:';
         foreach ($_POST as $key => $value) {
             if (in_array($key, ['refer', 'id1', 'id2'])) {
                 $hasRefer = true;
                 $referStr .= "{$key}={$value}&";
                 continue;
             }
             $prefix .= $key . '=' . urlencode($value) . '&';
         }
         $prefix .= ']';
     }
     $referStr .= ']';
     $locStr .= ']';
     if ($hasRefer) {
         $prefix .= $referStr;
     }
     if ($hasLoc) {
         $prefix .= $locStr;
     }
     $prefix .= $_SERVER['HTTP_USER_AGENT'];
     $prefix .= $_SERVER['REMOTE_ADDR'];
     $prefix .= $_SERVER['HTTP_REFERER'];
     //        $prefix .= '[NETCOUNT:db('.Wk::db()->getExecuteCnt().'),mc('.K::mcd()->getUseCnt().'),redis('.K::redis()->getUseCnt().'),tbapi('.TB_BaseSrv::getUseCnt().'),trapi('.TRoad_BaseSrv::getUseCnt().'),solr('.K::solr()->getUseCnt().')]';
     if (isset($_SERVER["REQUEST_TIME_FLOAT"])) {
         $prefix .= '[WAITING:' . round(Wk::app()->startTime - $_SERVER["REQUEST_TIME_FLOAT"], 8) * 1000 . 'ms]';
         $prefix .= '[DURATION:' . round(microtime(true) - Wk::app()->startTime, 8) * 1000 . 'ms]';
     }
     return $prefix . "\n";
 }
예제 #8
0
 /**
  * @throws Wk_Exception
  */
 public final function save()
 {
     //$now = date('Y-m-d H:i:s');
     if (!empty(Wk::app()->user) && property_exists($this, 'updateUser')) {
         $this->updateUser = Wk::app()->user->userid;
     }
     if (property_exists($this, 'updateTime')) {
         $this->updateTime = date('Y-m-d H:i:s');
     }
     if (isset($this->id)) {
         $this->update();
     } else {
         if (!empty(Wk::app()->user) && property_exists($this, 'createUser')) {
             $this->createUser = Wk::app()->user->userid;
         }
         if (property_exists($this, 'createTime')) {
             $this->createTime = date('Y-m-d H:i:s');
         }
         $this->insert();
     }
 }
예제 #9
0
 /**
  * @return int
  */
 public static function getTime()
 {
     if (!Wk::app() instanceof WebApp) {
         return time();
     }
     return $_SERVER['REQUEST_TIME'];
 }
예제 #10
0
 /**
  * 返回错误信息
  *
  * @param  string $errorMsg
  * @param  int $errorCode
  * @param  int $httpStatus
  */
 public function returnError($errorMsg = '', $errorCode = -1, $httpStatus = 200)
 {
     if ($httpStatus !== 200) {
         switch ($httpStatus) {
             case 404:
                 header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
                 echo '404 Not Found';
                 break;
             case 403:
                 header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
                 echo '403 Forbidden';
                 break;
             case 500:
                 header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
                 echo '500 Internal Server Error';
                 break;
             default:
                 header($_SERVER['SERVER_PROTOCOL'] . ' ' . $httpStatus . ' Http Error');
                 echo $httpStatus . ' Http Error';
                 break;
         }
     } elseif (Wk_Request::isAjax()) {
         header('Content-Type: application/json; charset=utf-8');
         if (!empty($errorMsg)) {
             echo json_encode(['ok' => 0, 'msg' => $errorMsg, 'code' => $errorCode], JSON_UNESCAPED_UNICODE);
         } else {
             echo json_encode(['ok' => 0, 'msg' => TErrorConstants::getErrorMsg($errorCode), 'code' => $errorCode], JSON_UNESCAPED_UNICODE);
         }
     } else {
         if (empty($errorMsg)) {
             $errorMsg = TErrorConstants::getErrorMsg($errorCode);
         }
         Wk::logger()->err('page error:' . $errorCode . (empty($errorMsg) ? '' : '(' . $errorMsg . ')'));
         // $this->renderView('/layouts/404');
         echo 'error: ' . $errorCode . (empty($errorMsg) ? '' : '(' . $errorMsg . ')');
     }
     Wk::app()->stop();
 }