Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonscott committed May 15, 2014
2 parents aa03eb6 + ef15fbf commit 0bad0cf
Show file tree
Hide file tree
Showing 81 changed files with 12,042 additions and 448 deletions.
6 changes: 6 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
</IfModule>

RewriteEngine On
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Methods "GET,PUT, POST, DELETE, OPTIONS"
Header add Access-Control-Allow-Headers "Authorization"

RewriteRule ^vpu - [L,NC]

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
Expand All @@ -12,4 +17,5 @@
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
2 changes: 2 additions & 0 deletions app/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
'Illuminate\Validation\ValidationServiceProvider',
'Illuminate\View\ViewServiceProvider',
'Illuminate\Workbench\WorkbenchServiceProvider',
'Travisjryan\Twilio\TwilioServiceProvider'

),

Expand Down Expand Up @@ -169,6 +170,7 @@
'Session' => 'Illuminate\Support\Facades\Session',
'SSH' => 'Illuminate\Support\Facades\SSH',
'Str' => 'Illuminate\Support\Str',
'Twilio' => 'Travisjryan\Twilio\Facades\Twilio',
'URL' => 'Illuminate\Support\Facades\URL',
'Validator' => 'Illuminate\Support\Facades\Validator',
'View' => 'Illuminate\Support\Facades\View',
Expand Down
18 changes: 18 additions & 0 deletions app/config/packages/travisjryan/twilio/twilio.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

return array(
/**
* SID - Your Twilio Account SID #
*/
"sid" => "AC3b8cd1e12a5b6ff4e4ea25f431833a97",

/**
* token - Access token that can be found in your Twilio dashboard
*/
"token" => "22964db1d502e5069c2d44c9a49c8b6c",

/**
* from - The Phone number registered with Twilio that your SMS & Calls will come from
*/
"from" => "+441332402803"
);
4 changes: 1 addition & 3 deletions app/config/pubnub.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

return array(

'publish_key' => 'pub-c-18bc7bd1-2981-4cc4-9c4e-234d25519d36',
'subscribe_key' => 'sub-c-5782df52-d147-11e3-93dd-02ee2ddab7fe',

);
);
32 changes: 32 additions & 0 deletions app/controllers/AuthenticationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
class AuthenticationController extends BaseController{

public function getAll()
{


}

public function store()
{

}

public function auth()
{
if (!isset($_SERVER['HTTP_AUTHORIZATION']) || $_SERVER['HTTP_AUTHORIZATION'] == '')
{
return Response::json(array("success" => "test"));
}
else{
list($email, $password) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
}
if (Auth::attempt(array('email' => $email, 'password' => $password)))
{
return Response::json(Auth::user());
}

return Response::json(array("id" => 0));
}
}
?>
27 changes: 27 additions & 0 deletions app/controllers/PrivilegeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
class PrivilegeController extends BaseController {

public function getAll()
{
return Response::json(Privilege::all());
}

public function store()
{
$privilege = new Privilege;
$privilege->name = Input::get('name');

$privilege->save();

return Response::json($privilege);
}

public function deletePrivilege($id)
{
$privilege = Privilege::find($id);
$privilege->delete();

return Response::json(array("success" => true));
}
}
?>
11 changes: 9 additions & 2 deletions app/controllers/PulseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class PulseController extends BaseController{

public function getAll()
{

return Response::json(Pulse::all());
}

Expand All @@ -22,12 +21,20 @@ public function store()

$pubnub = App::make('pubnub');
$pubnub->publish(array(
'channel' => 'Cadence',
'channel' => 'pulses-' . $pulse->server_id,
'message' => json_decode($pulse)
));

return Response::json($pulse);
}

public function deletePulse($id)
{
$user = Pulse::find($id);
$user->delete();

return Response::json(array("success" => true));
}

}
?>
150 changes: 150 additions & 0 deletions app/controllers/ServerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php
class ServerController extends BaseController {

public function getAll()
{
return Response::json(Server::all());
}

public function getServer($id)
{
$server = Server::find($id);
//return Response::json(array('server' => json_decode($server), 'pulses' => json_decode($server->pulse)));
return Response::json($server);
}

public function store()
{
$server = new Server;

$server->servergroup_id = Input::get("servergroup_id");
$server->name = Input::get("name");
$server->available_disk = Input::get("available_disk");
$server->available_ram = Input::get("available_ram");
$server->cpu_speed = Input::get("cpu_speed");
$server->os_name = Input::get("os_name");
$server->os_version = Input::get("os_version");
$server->guid = Input::get("guid");

$server->save();

$pubnub = App::make('pubnub');
$pubnub->publish(array(
'channel' => 'Cadence',
'message' => json_decode($server)
));

return Response::json($server);
}

public function getPulses($id)
{
$server = Server::find($id);
return Response::json($server->pulse);
}

public function getPulsesForDays($id, $days)
{
$server = Server::find($id);
$pulses = Pulse::ofServerID($id)->ofDays($days)->get();
return Response::json($pulses);
}

public function getLatestPulse($id)
{
$pulse = Pulse::ofServerID($id)->orderby('timestamp', 'asc')->first();
return Response::json($pulse);
}

public function changeStatus($guid)
{
Server::where('guid', '=', $guid)->update(array('online' => Input::get("status")));
$server = Server::where('guid', '=', $guid)->get();

if($server->isEmpty())
{
return Response::make("Server with this GUID not found");
}

$subscriptionsForServer = Subscription::ofServerID($server->first()->servergroup_id)->get();
foreach ($subscriptionsForServer as $subscription)
{
if (Input::get("status") == 0)
{
if($subscription->text == 1)
{
Twilio::message($subscription->user->mobile_number, "CADENCE STATUS ALERT: Server '" . $server->first()->name . "' has gone offline. Urgent attention needed.");
}
if($subscription->phonecall == 1)
{
Twilio::call($subscription->user->mobile_number, 'http://cadence-bu.cloudapp.net/voicealert.xml');
}
}
else
{
if($subscription->text == 1)
{
Twilio::message($subscription->user->mobile_number, "CADENCE STATUS UPDATE: Server '" . $server->first()->name . "' has come back online. Have a great day.");
}
}
}

$pubnub = App::make('pubnub');
$pubnub->publish(array(
'channel' => 'pulses-' . $server->first()->id . '-online',
'message' => json_encode(array("online" => Input::get("status")))
));

return Response::json($server->first());
}

public function updateServerDetails($guid)
{
$server = Server::where('guid', '=', $guid)->first()->update(array(
"available_disk" => Input::get("available_disk"),
"available_ram" => Input::get("available_ram"),
"cpu_speed" => Input::get("cpu_speed"),
"os_name" => Input::get("os_name"),
"os_version" => Input::get("os_version")
));
return Response::json(Server::where('guid', '=', $guid)->get());
}

public function updateServerGroup($id)
{
$server = Server::find($id);

$server->servergroup_id = Input::get('servergroup_id');
$server->save();
}

public function getStatus($guid)
{
$server = Server::where('guid', '=', $guid)->get();
return Response::json($server);
}

public function deleteServer($id)
{
$server = Server::find($id);
$server->delete();

return Response::json(array("success" => true));
}

public function getUnassignedServers()
{
return Response::json(Server::ofUnassigned(0)->get());
}

public function getAssignedServers()
{
return Response::json(Server::ofAssigned(0)->get());
}

public function getServersForStatus($status)
{
return Response::json(Server::ofStatus($status)->get());
}
}
?>
72 changes: 72 additions & 0 deletions app/controllers/ServerGroupController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
class ServerGroupController extends BaseController {

public function getAll()
{
return Response::json(ServerGroup::all());
}

public function getServers($id)
{
$serverGroup = ServerGroup::find($id);
return Response::json($serverGroup->server);
}

public function store()
{
if (ServerGroup::where('name','=', Input::get("name"))->count() > 0) {
//$user = User::where('email','=', Input::get("email"))->get()->first();
return Response::json(array('success' => false , 'error' => 'Server Group already exists'));
}

$serverGroup = new ServerGroup;
$serverGroup->name = Input::get("name");
$serverGroup->save();

return Response::json($serverGroup);
}

public function deleteServerGroup($id)
{
$serverGroup = ServerGroup::find($id);
$serverGroup->delete();

$servers = Server::where("servergroup_id", "=", $id)->get();

foreach($servers as $server)
{
$server->servergroup_id = 0;
$server->save();
}

$subscriptions = Subscription::where("servergroup_id", "=", $id)->get();

foreach($subscriptions as $Subscription)
{
$Subscription->delete();
}

return Response::json(array("success" => true));
}

public function getServerGroup($id)
{
return Response::json(ServerGroup::find($id));
}

public function editServerGroup($id)
{
if (ServerGroup::find($id)->count() > 0) {
//$user = User::where('email','=', Input::get("email"))->get()->first();
return Response::json(array('success' => false , 'error' => 'Server Group already exists'));
}

$serverGroup = ServerGroup::find($id);
$serverGroup->name = Input::get("name");

$serverGroup->save();

return Response::json($serverGroup);
}
}
?>
Loading

0 comments on commit 0bad0cf

Please sign in to comment.