$bonusShop = new BonusShop($db, $user); httpResponse($bonusShop->getShopItems()); break; case validateRoute('POST', 'bonus-shop/\\d+'): $mailbox = new Mailbox($db, $user); $bonusShop = new BonusShop($db, $user, $mailbox); $bonusShop->buy((int) $params[1], $postdata); httpResponse(); break; case validateRoute('GET', 'invites'): $invite = new Invite($db, $user); httpResponse($invite->query()); break; case validateRoute('POST', 'invites'): $invite = new Invite($db, $user); httpResponse($invite->create()); break; case validateRoute('DELETE', 'invites/\\d+'): $invite = new Invite($db, $user); httpResponse($invite->delete((int) $params[1])); break; case validateRoute('GET', 'friends'): $friends = new Friends($db, $user); httpResponse($friends->query()); break; case validateRoute('POST', 'friends'): $friends = new Friends($db, $user); httpResponse($friends->create($postdata)); break; case validateRoute('DELETE', 'friends/\\d+'): $friends = new Friends($db, $user);
public function postManage($group_id) { $input = Input::all(); $messages = array(); $email = NULL; /* For Lease Creation */ if ("ssh" == $input["rule_type"]) { $protocol = "tcp"; $port_from = "22"; $port_to = "22"; } elseif ("https" == $input["rule_type"]) { $protocol = "tcp"; $port_from = "443"; $port_to = "443"; } elseif ("custom" == $input["rule_type"]) { $protocol = $input['protocol']; $port_from = $input['port_from']; $port_to = $input['port_to']; //Validations if ($protocol != "tcp" && $protocol != "udp") { array_push($messages, "Invalid Protocol"); } if (!is_numeric($port_from) || $port_from > 65535 || $port_from <= 0) { array_push($messages, "Invalid From port"); } if (!is_numeric($port_to) || $port_to > 65535 || $port_to <= 0) { array_push($messages, "Invalid To port"); } if ($port_from > $port_to) { array_push($messages, "From port Must be less than equal to To Port"); } } else { App::abort(403, 'Unauthorized action.'); } //Other validations $expiry = $input['expiry']; if (!is_numeric($expiry) || $expiry <= 0 || $expiry > 86400) { array_push($messages, "Invalid Expiry Time"); } if (!in_array($input['access'], array(1, 2, 3, 4))) { array_push($messages, "Invalid invite Email"); } if (2 == $input['access']) { if (!isset($input['email']) || !filter_var($input['email'], FILTER_VALIDATE_EMAIL)) { array_push($messages, "Invalid invite Email"); } } //Validation fails if (!empty($messages)) { return Redirect::to("/manage/{$group_id}")->with('message', implode("<br/>", $messages)); } if (1 == $input['access']) { //Creating the lease $lease = array('user_id' => Auth::User()->id, 'group_id' => $group_id, 'lease_ip' => $this->getClientIp() . "/32", 'protocol' => $protocol, 'port_from' => $port_from, 'port_to' => $port_to, 'expiry' => $expiry); $existingLease = Lease::where('lease_ip', '=', $lease['lease_ip'])->where('group_id', '=', $lease['group_id'])->where('protocol', '=', $lease['protocol'])->where('port_from', '=', $lease['port_from'])->where('port_to', '=', $lease['port_to']); if ($existingLease->count() > 0) { $newLease = $existingLease->first(); $newLease->expiry = $lease['expiry']; $newLease->save(); } else { $result = $this->createLease($lease); if (!$result) { //Lease Creation Failed. AWS Reported an error. Generally in case if a lease with same ip, protocol, port already exists on AWS. return Redirect::to("/manage/{$group_id}")->with('message', "Lease Creation Failed! Does a similar lease already exist? Terminate that first."); } $lease = Lease::create($lease); } $this->NotificationMail($lease, TRUE); return Redirect::to("/manage/{$group_id}")->with('message', "Lease created successfully!"); } elseif (2 == $input['access']) { $email = $input['email']; } elseif (4 == $input['access']) { $email = 'DEPLOY'; } $token = md5(time() + rand()); $invite = array('user_id' => Auth::User()->id, 'group_id' => $group_id, 'protocol' => $protocol, 'port_from' => $port_from, 'port_to' => $port_to, 'expiry' => $expiry, 'email' => $email, 'token' => $token); $invite = Invite::create($invite); if ($email && $email != 'DEPLOY') { $data = array('invite' => $invite->toArray()); //Send Invite Mail Mail::queue('emails.invite', $data, function ($message) use($email) { $message->to($email, 'Invite')->subject('Access Lease Invite'); }); return Redirect::to("/manage/{$group_id}")->with('message', "Invite Sent successfully!"); } else { return View::make('pages.invited')->with('invite', $invite); } }