public function getBan(Board $board, Ban $ban)
 {
     if (!$ban->canView($this->user)) {
         return abort(403);
     }
     $seeing = false;
     if (!$ban->seen) {
         $ban->seen = true;
         $ban->save();
         $seeing = true;
     }
     $ban->setRelation('board', $board);
     return $this->view(static::VIEW_BAN, ['board' => $board, 'ban' => $ban, 'seeing' => $seeing]);
 }
Exemplo n.º 2
0
 /**
  *
  */
 public function putMod(Request $request, Board $board, $post)
 {
     // Validate the request parameters.
     if (!($post = $this->validatePost($board, $post)) instanceof Post) {
         // If the response isn't a Post, it's a redirect or error.
         // Return the message.
         return $post;
     }
     // Take trailing arguments,
     // compare them against a list of real actions,
     // intersect the liss to find the true commands.
     $actions = ["delete", "ban", "all", "global"];
     $argList = func_get_args();
     $modActions = array_intersect($actions, array_splice($argList, 2));
     sort($modActions);
     $ban = in_array("ban", $modActions);
     $delete = in_array("delete", $modActions);
     $all = in_array("all", $modActions);
     $global = in_array("global", $modActions);
     if (!$ban) {
         return abort(404);
     }
     $validator = Validator::make(Input::all(), ['ban_ip' => 'required|ip', 'justification' => 'max:255', 'expires_days' => 'required|integer|min:0|max:' . $this->option('banMaxLength'), 'expires_hours' => 'required|integer|min:0|max:23', 'expires_minutes' => 'required|integer|min:0|max:59']);
     if (!$validator->passes()) {
         return redirect()->back()->withInput(Input::all())->withErrors($validator->errors());
     }
     $banLengthStr = [];
     $expiresDays = Input::get('expires_days');
     $expiresHours = Input::get('expires_hours');
     $expiresMinutes = Input::get('expires_minutes');
     if ($expiresDays > 0) {
         $banLengthStr[] = "{$expiresDays}d";
     }
     if ($expiresHours > 0) {
         $banLengthStr[] = "{$expiresHours}h";
     }
     if ($expiresMinutes > 0) {
         $banLengthStr[] = "{$expiresMinutes}m";
     }
     if ($expiresDays == 0 && $expiresHours == 0 && $expiresMinutes == 0) {
         $banLengthStr[] = "Ø";
     }
     $banLengthStr = implode($banLengthStr, " ");
     $ban = new Ban();
     $ban->ban_ip = Input::get('ban_ip');
     $ban->seen = false;
     $ban->created_at = $ban->freshTimestamp();
     $ban->updated_at = clone $ban->created_at;
     $ban->expires_at = clone $ban->created_at;
     $ban->expires_at->addDays($expiresDays);
     $ban->expires_at->addHours($expiresHours);
     $ban->expires_at->addMinutes($expiresMinutes);
     $ban->mod_id = $this->user->user_id;
     $ban->post_id = $post->post_id;
     $ban->ban_reason_id = null;
     $ban->justification = Input::get('justification');
     if ($global) {
         if ($ban && !$this->user->canBanGlobally() || $delete && !$this->user->canDeleteGlobally()) {
             return abort(403);
         }
         if ($ban) {
             $ban->board_uri = null;
             $ban->save();
         }
         $this->log('log.post.ban.global', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "ip" => $post->author_ip, "justification" => $ban->justification, "time" => $banLengthStr]);
         if ($delete) {
             $posts = Post::where('author_ip', $post->author_ip);
             $this->log('log.post.ban.delete', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "posts" => $posts->count()]);
             $posts->delete();
             return redirect($board->board_uri);
         }
     } else {
         if ($ban && !$board->canBan($this->user) || $delete && !$board->canDelete($this->user)) {
             return abort(403);
         }
         if ($ban) {
             $ban->board_uri = $post->board_uri;
             $ban->save();
         }
         $this->log('log.post.ban.local', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "ip" => $post->author_ip, "justification" => $ban->justification, "time" => $banLengthStr]);
         if ($delete) {
             if ($all) {
                 $posts = Post::where('author_ip', $post->author_ip)->where('board_uri', $board->board_uri);
                 $this->log('log.post.ban.delete', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "posts" => $posts->count()]);
                 $posts->delete();
                 return redirect($board->board_uri);
             } else {
                 $this->log('log.post.ban.delete', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "posts" => 1]);
                 $post->delete();
                 if ($post->reply_to) {
                     return redirect("{$post->board_uri}/thread/{$post->op->board_id}");
                 } else {
                     return redirect($board->board_uri);
                 }
             }
         }
     }
     Event::fire(new PostWasBanned($post));
     if ($post->reply_to) {
         return redirect("{$post->board_uri}/thread/{$post->op->board_id}#{$post->board_id}");
     } else {
         return redirect("{$post->board_uri}/thread/{$post->board_id}");
     }
 }
Exemplo n.º 3
0
 /**
  *
  */
 public function putMod(Request $request, Board $board, Post $post)
 {
     if (!$post->exists) {
         abort(404);
     }
     // Take trailing arguments,
     // compare them against a list of real actions,
     // intersect the liss to find the true commands.
     $actions = ["delete", "ban", "all", "global"];
     $argList = func_get_args();
     $modActions = array_intersect($actions, array_splice($argList, 2));
     sort($modActions);
     $ban = in_array("ban", $modActions);
     $delete = in_array("delete", $modActions);
     $all = in_array("all", $modActions);
     $global = in_array("global", $modActions);
     if (!$ban) {
         return abort(404);
     }
     $validator = Validator::make(Input::all(), ['raw_ip' => 'required|boolean', 'ban_ip' => 'required_if:raw_ip,true|ip', 'ban_ip_range' => 'required|between:0,128', 'justification' => 'max:255', 'expires_days' => 'required|integer|min:0|max:' . $this->option('banMaxLength'), 'expires_hours' => 'required|integer|min:0|max:23', 'expires_minutes' => 'required|integer|min:0|max:59']);
     if (!$validator->passes()) {
         return redirect()->back()->withInput(Input::all())->withErrors($validator->errors());
     }
     $banLengthStr = [];
     $expiresDays = Input::get('expires_days');
     $expiresHours = Input::get('expires_hours');
     $expiresMinutes = Input::get('expires_minutes');
     if ($expiresDays > 0) {
         $banLengthStr[] = "{$expiresDays}d";
     }
     if ($expiresHours > 0) {
         $banLengthStr[] = "{$expiresHours}h";
     }
     if ($expiresMinutes > 0) {
         $banLengthStr[] = "{$expiresMinutes}m";
     }
     if ($expiresDays == 0 && $expiresHours == 0 && $expiresMinutes == 0) {
         $banLengthStr[] = "Ø";
     }
     $banLengthStr = implode($banLengthStr, " ");
     // If we're banning without the ability to view IP addresses, we will get our address directly from the post in human-readable format.
     $banIpAddr = $this->user->canViewRawIP() ? Input::get('ban_ip') : $post->getAuthorIpAsString();
     // The CIDR is passed from our post parameters. By default, it is 32/128 for IPv4/IPv6 respectively.
     $banCidr = Input::get('ban_ip_range');
     // This generates a range from start to finish. I.E. 192.168.1.3/22 becomes [192.168.0.0, 192.168.3.255].
     // If we just pass the CDIR into the construct, we get 192.168.1.3-129.168.3.255 for some reason.
     $banCidrRange = IP::cidr_to_range("{$banIpAddr}/{$banCidr}");
     // We then pass this range into the construct method.
     $banIp = new IP($banCidrRange[0], $banCidrRange[1]);
     $ban = new Ban();
     $ban->ban_ip_start = $banIp->getStart();
     $ban->ban_ip_end = $banIp->getEnd();
     $ban->seen = false;
     $ban->created_at = $ban->freshTimestamp();
     $ban->updated_at = clone $ban->created_at;
     $ban->expires_at = clone $ban->created_at;
     $ban->expires_at = $ban->expires_at->addDays($expiresDays);
     $ban->expires_at = $ban->expires_at->addHours($expiresHours);
     $ban->expires_at = $ban->expires_at->addMinutes($expiresMinutes);
     $ban->mod_id = $this->user->user_id;
     $ban->post_id = $post->post_id;
     $ban->ban_reason_id = null;
     $ban->justification = Input::get('justification');
     if ($global) {
         if ($ban && !$this->user->canBanGlobally() || $delete && !$this->user->canDeleteGlobally()) {
             return abort(403);
         }
         if ($ban) {
             $ban->board_uri = null;
             $ban->save();
         }
         $this->log('log.post.ban.global', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "ip" => $post->getAuthorIpAsString(), "justification" => $ban->justification, "time" => $banLengthStr]);
         if ($delete) {
             $posts = Post::ipBinary($post->author_ip);
             $this->log('log.post.ban.delete', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "posts" => $posts->count()]);
             $posts->delete();
             return redirect($board->board_uri);
         }
     } else {
         if ($ban && !$board->canBan($this->user) || $delete && !$board->canDelete($this->user)) {
             return abort(403);
         }
         if ($ban) {
             $ban->board_uri = $post->board_uri;
             $ban->save();
         }
         $this->log('log.post.ban.local', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "ip" => $post->getAuthorIpAsString(), "justification" => $ban->justification, "time" => $banLengthStr]);
         if ($delete) {
             if ($all) {
                 $posts = Post::ipBinary($post->author_ip)->where('board_uri', $board->board_uri);
                 $this->log('log.post.ban.delete', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "posts" => $posts->count()]);
                 $posts->delete();
                 return redirect($board->board_uri);
             } else {
                 $this->log('log.post.ban.delete', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "posts" => 1]);
                 $post->delete();
             }
         }
     }
     Event::fire(new PostWasBanned($post));
     Event::fire(new PostWasModerated($post, $this->user));
     return back();
 }