Example #1
0
 /**
  *  初始化Http请求参数...
  */
 protected static function _initRequestParam()
 {
     //定义详细请求路径及参数
     define('REQUEST_URI', Request::getFullPath());
     //定义客户端IP
     define('CLINET_IP', Request::getClientIP());
     //服务器名称
     define('SERVER_NAME', Request::getServerName());
     //前一跳转地址
     define('HTTP_REFERER', Request::getRefererUrl());
 }
Example #2
0
 /**
  * Send an email to feedback email address
  *
  * Expected fields:
  *  - client_id
  *  - client_secret
  *  - name
  *  - email
  *  - subject
  *  - comment
  *
  * @param  Request $request
  * @param  PDO $db
  *
  * @return void
  */
 public function contact($request, $db)
 {
     // only trusted clients can contact us to save on spam
     $clientId = $request->getParameter('client_id');
     $clientSecret = $request->getParameter('client_secret');
     $this->oauthModel = $request->getOauthModel($db);
     if (!$this->oauthModel->isClientPermittedPasswordGrant($clientId, $clientSecret)) {
         throw new Exception("This client cannot perform this action", 403);
     }
     $fields = ['name', 'email', 'subject', 'comment'];
     $error = [];
     foreach ($fields as $name) {
         $value = $request->getParameter($name);
         if (empty($value)) {
             $error[] = "'{$name}'";
         }
         $data[$name] = $value;
     }
     if (!empty($error)) {
         $message = 'The field';
         $message .= count($error) == 1 ? ' ' : 's ';
         $message .= implode(', ', $error);
         $message .= count($error) == 1 ? ' is ' : ' are ';
         $message .= 'required.';
         throw new Exception($message, 400);
     }
     // run it by akismet if we have it
     if (isset($this->config['akismet']['apiKey'], $this->config['akismet']['blog'])) {
         $spamCheckService = new SpamCheckService($this->config['akismet']['apiKey'], $this->config['akismet']['blog']);
         $isValid = $spamCheckService->isCommentAcceptable($data['comment'], $request->getClientIP(), $request->getClientUserAgent());
         if (!$isValid) {
             throw new Exception("Comment failed spam check", 400);
         }
     }
     $emailService = new ContactEmailService($this->config);
     $emailService->sendEmail($data);
     header("Content-Length: 0", null, 202);
     exit;
 }
Example #3
0
 /**
  * 写入日志
  * @param string $message 日志内容
  * @param int $level 日志级别
  * @param string $filename 日志文件名
  */
 public static function write($message, $level, $filename = '')
 {
     if (strtoupper($level) != 'DEBUG' || DEBUG) {
         $message = '[' . $level . ']' . $message;
         $message = '[' . Request::getClientIP() . ']' . $message;
         $message = '[' . date('Y-m-d H:i:s') . ']' . $message . "\n";
         file_exists(LOG_PATH) or mkdir(LOG_PATH);
         $filename = $filename ? $filename : date('Y-m-d') . '.log';
         file_put_contents(LOG_PATH . $filename, $message, FILE_APPEND);
     }
 }
Example #4
0
 /**
  * @descrpition 添加评论
  */
 public function addcomment()
 {
     $userLog = array('param' => array('request' => $_REQUEST, 'id' => Request::getClientIP()), 'method' => __METHOD__, 'create_time' => date('Y-m-d H:i:s'));
     UserLogBusiness::set($userLog);
     $jumpUrl = GAME_URL . 'article/main/aid-' . $this->param['aid'];
     //判断验证码
     $captcha = Request::getSession('captcha');
     if (empty($captcha) || $captcha !== strtolower($this->param['captcha'])) {
         View::showErrorMessage($jumpUrl, '验证码错误');
     }
     if (empty($this->param['aid']) || empty($this->param['mid']) || empty($this->param['nickname']) || empty($this->param['content'])) {
         View::showErrorMessage($jumpUrl, '必填项未填写全');
     }
     $fields = array();
     $fields['cid'] = Request::getRequest('cid', 'int');
     $fields['aid'] = Request::getRequest('aid', 'int');
     $fields['mid'] = Request::getRequest('mid', 'int');
     $fields['nickname'] = Request::getRequest('nickname', 'str');
     $fields['email'] = Request::getRequest('email', 'str');
     $fields['website'] = Request::getRequest('website', 'str');
     $fields['ctime'] = time();
     $fields['content'] = Request::getRequest('content', 'str');
     CommentBusiness::setComment($fields);
     //如果是回复别人的回复,则发送邮件提醒
     if (EMAIL_SENT_FOR_REPLY && $fields['cid'] > 0) {
         //根据CID查询评论的详细信息
         $comment = CommentBusiness::getComment($fields['cid']);
         if (!empty($comment['email'])) {
             $url = 'http://www.lanecn.com/article/main/aid-' . $comment['aid'];
             $title = '您的评论有了新回复【来自LaneBlog的系统邮件提醒】';
             $content = "\n";
             $content .= '<a href="' . $url . '">你的评论有了新的回复!请点击查看<a/>';
             $content .= "\n\n连接无效请复制到浏览器地址栏访问:" . $url;
             $content .= "\n\nPs:系统发送,请勿直接回复!";
             $config = array("from" => EMAIL_ADDRESS, "to" => $comment['email'], "subject" => $title, "body" => $content, "username" => EMAIL_ADDRESS, "password" => EMAIL_PASSWORD);
             $mail = new MailSocket();
             $mail->setServer(EMAIL_SMTP);
             $mail->setMailInfo($config);
             //                $result = Mail::quickSent($comment['email'], $title, $content, EMAIL_ADDRESS, EMAIL_PASSWORD);
         }
     }
     $userLog = array('param' => array('request' => $_REQUEST, 'id' => Request::getClientIP()), 'method' => __METHOD__, 'create_time' => date('Y-m-d H:i:s'), 'result' => $fields);
     $userLog['param'] = json_encode($userLog['param']);
     $userLog['result'] = json_encode($userLog['result']);
     UserLogBusiness::set($userLog);
     View::showMessage($jumpUrl, '成功!');
 }
Example #5
0
 /**
  * @dataProvider clientIpProvider
  */
 public function testGettingClientIp($header)
 {
     $_SERVER = array_merge($header, $_SERVER);
     $request = new \Request($this->config, []);
     $this->assertEquals('192.168.1.1', $request->getClientIP());
 }