@@ -2,7 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace PiFinder\Services; |
| 4 | 4 | |
| 5 | -use Carbon\Carbon; |
|
| 6 | 5 | use DB; |
| 7 | 6 | use PiFinder\DeviceArchive; |
| 8 | 7 | use PiFinder\Poke; |
@@ -9,60 +9,60 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Statistics |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Returns the count of all pokes. |
|
| 14 | - * |
|
| 15 | - * @return mixed |
|
| 16 | - */ |
|
| 17 | - public function totalPokes() |
|
| 18 | - { |
|
| 19 | - $base = 189771; |
|
| 12 | + /** |
|
| 13 | + * Returns the count of all pokes. |
|
| 14 | + * |
|
| 15 | + * @return mixed |
|
| 16 | + */ |
|
| 17 | + public function totalPokes() |
|
| 18 | + { |
|
| 19 | + $base = 189771; |
|
| 20 | 20 | |
| 21 | - return DB::table('network_distribution')->sum('pokes') + $base; |
|
| 22 | - } |
|
| 21 | + return DB::table('network_distribution')->sum('pokes') + $base; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Returns the the count of all devices. |
|
| 26 | - * |
|
| 27 | - * @return mixed |
|
| 28 | - */ |
|
| 29 | - public function totalDevices() |
|
| 30 | - { |
|
| 31 | - return DeviceArchive::count(); |
|
| 32 | - } |
|
| 24 | + /** |
|
| 25 | + * Returns the the count of all devices. |
|
| 26 | + * |
|
| 27 | + * @return mixed |
|
| 28 | + */ |
|
| 29 | + public function totalDevices() |
|
| 30 | + { |
|
| 31 | + return DeviceArchive::count(); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Returns all pokes. |
|
| 36 | - * |
|
| 37 | - * @return mixed |
|
| 38 | - */ |
|
| 39 | - public function allPokes() |
|
| 40 | - { |
|
| 41 | - return Poke::all(); |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * Returns all pokes. |
|
| 36 | + * |
|
| 37 | + * @return mixed |
|
| 38 | + */ |
|
| 39 | + public function allPokes() |
|
| 40 | + { |
|
| 41 | + return Poke::all(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Returns a collection of all networks and it's count. |
|
| 46 | - * |
|
| 47 | - * @return mixed |
|
| 48 | - */ |
|
| 49 | - public function networkDistribution() |
|
| 50 | - { |
|
| 51 | - $data = DB::table('network_distribution') |
|
| 52 | - ->select('network as label', 'pokes as value') |
|
| 53 | - ->get(); |
|
| 44 | + /** |
|
| 45 | + * Returns a collection of all networks and it's count. |
|
| 46 | + * |
|
| 47 | + * @return mixed |
|
| 48 | + */ |
|
| 49 | + public function networkDistribution() |
|
| 50 | + { |
|
| 51 | + $data = DB::table('network_distribution') |
|
| 52 | + ->select('network as label', 'pokes as value') |
|
| 53 | + ->get(); |
|
| 54 | 54 | |
| 55 | - return $this->addColors($data); |
|
| 56 | - } |
|
| 55 | + return $this->addColors($data); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - private function addColors($data) |
|
| 59 | - { |
|
| 60 | - $colors = ['rgb(23,103,153)', 'rgb(47,135,176)', 'rgb(66,164,187)', 'rgb(91,192,196)']; |
|
| 61 | - $highlight_colors = ['#8BB3CC', '#97C3D7', '#ADDFE1', '#BBEAE3']; |
|
| 58 | + private function addColors($data) |
|
| 59 | + { |
|
| 60 | + $colors = ['rgb(23,103,153)', 'rgb(47,135,176)', 'rgb(66,164,187)', 'rgb(91,192,196)']; |
|
| 61 | + $highlight_colors = ['#8BB3CC', '#97C3D7', '#ADDFE1', '#BBEAE3']; |
|
| 62 | 62 | |
| 63 | - return $data->each(function ($network, $i) use ($colors, $highlight_colors) { |
|
| 64 | - $network->color = $colors[$i]; |
|
| 65 | - $network->highlight = $highlight_colors[$i]; |
|
| 66 | - }); |
|
| 67 | - } |
|
| 63 | + return $data->each(function ($network, $i) use ($colors, $highlight_colors) { |
|
| 64 | + $network->color = $colors[$i]; |
|
| 65 | + $network->highlight = $highlight_colors[$i]; |
|
| 66 | + }); |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | $colors = ['rgb(23,103,153)', 'rgb(47,135,176)', 'rgb(66,164,187)', 'rgb(91,192,196)']; |
| 61 | 61 | $highlight_colors = ['#8BB3CC', '#97C3D7', '#ADDFE1', '#BBEAE3']; |
| 62 | 62 | |
| 63 | - return $data->each(function ($network, $i) use ($colors, $highlight_colors) { |
|
| 63 | + return $data->each(function($network, $i) use ($colors, $highlight_colors) { |
|
| 64 | 64 | $network->color = $colors[$i]; |
| 65 | 65 | $network->highlight = $highlight_colors[$i]; |
| 66 | 66 | }); |
@@ -4,27 +4,27 @@ |
||
| 4 | 4 | |
| 5 | 5 | class ExtractNetwork |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Extract the network from the ip address. |
|
| 9 | - * |
|
| 10 | - * @param string $ip |
|
| 11 | - * |
|
| 12 | - * @return string $network |
|
| 13 | - */ |
|
| 14 | - public static function fromIp($ip) |
|
| 15 | - { |
|
| 16 | - if(starts_with($ip, '192.168.')) { |
|
| 17 | - return '192.168.0.0/16'; |
|
| 18 | - } |
|
| 7 | + /** |
|
| 8 | + * Extract the network from the ip address. |
|
| 9 | + * |
|
| 10 | + * @param string $ip |
|
| 11 | + * |
|
| 12 | + * @return string $network |
|
| 13 | + */ |
|
| 14 | + public static function fromIp($ip) |
|
| 15 | + { |
|
| 16 | + if(starts_with($ip, '192.168.')) { |
|
| 17 | + return '192.168.0.0/16'; |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - if(starts_with($ip, '10.')) { |
|
| 21 | - return '10.0.0.0/8'; |
|
| 22 | - } |
|
| 20 | + if(starts_with($ip, '10.')) { |
|
| 21 | + return '10.0.0.0/8'; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - if(preg_match('/^172\.(1[6-9]|2[0-9]|3[01])\./', $ip)) { |
|
| 25 | - return '172.16.0.0/12'; |
|
| 26 | - } |
|
| 24 | + if(preg_match('/^172\.(1[6-9]|2[0-9]|3[01])\./', $ip)) { |
|
| 25 | + return '172.16.0.0/12'; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - return 'Internet'; |
|
| 29 | - } |
|
| 28 | + return 'Internet'; |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -13,15 +13,15 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public static function fromIp($ip) |
| 15 | 15 | { |
| 16 | - if(starts_with($ip, '192.168.')) { |
|
| 16 | + if (starts_with($ip, '192.168.')) { |
|
| 17 | 17 | return '192.168.0.0/16'; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - if(starts_with($ip, '10.')) { |
|
| 20 | + if (starts_with($ip, '10.')) { |
|
| 21 | 21 | return '10.0.0.0/8'; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - if(preg_match('/^172\.(1[6-9]|2[0-9]|3[01])\./', $ip)) { |
|
| 24 | + if (preg_match('/^172\.(1[6-9]|2[0-9]|3[01])\./', $ip)) { |
|
| 25 | 25 | return '172.16.0.0/12'; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | |
| 7 | 7 | class DeviceArchive extends Model |
| 8 | 8 | { |
| 9 | - protected $table = 'device_archive'; |
|
| 9 | + protected $table = 'device_archive'; |
|
| 10 | 10 | |
| 11 | - protected $guarded = []; |
|
| 11 | + protected $guarded = []; |
|
| 12 | 12 | } |
@@ -11,29 +11,29 @@ |
||
| 11 | 11 | |
| 12 | 12 | class UpdateStatistics |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Handle the event. |
|
| 16 | - * |
|
| 17 | - * @param ServerWasPoked $event |
|
| 18 | - * |
|
| 19 | - * @return void |
|
| 20 | - */ |
|
| 21 | - public function handle(ServerWasPoked $event) |
|
| 22 | - { |
|
| 23 | - $device = $event->getDevice()->toArray(); |
|
| 14 | + /** |
|
| 15 | + * Handle the event. |
|
| 16 | + * |
|
| 17 | + * @param ServerWasPoked $event |
|
| 18 | + * |
|
| 19 | + * @return void |
|
| 20 | + */ |
|
| 21 | + public function handle(ServerWasPoked $event) |
|
| 22 | + { |
|
| 23 | + $device = $event->getDevice()->toArray(); |
|
| 24 | 24 | |
| 25 | - // device count |
|
| 26 | - DeviceArchive::updateOrCreate( |
|
| 27 | - ['mac_hash' => md5($device['mac'])], |
|
| 28 | - ['updated_at' => Carbon::now()] |
|
| 29 | - ); |
|
| 25 | + // device count |
|
| 26 | + DeviceArchive::updateOrCreate( |
|
| 27 | + ['mac_hash' => md5($device['mac'])], |
|
| 28 | + ['updated_at' => Carbon::now()] |
|
| 29 | + ); |
|
| 30 | 30 | |
| 31 | - // network distribution |
|
| 32 | - $network = ExtractNetwork::fromIp($device['ip']); |
|
| 33 | - DB::table('network_distribution')->where('network', $network)->increment('pokes'); |
|
| 31 | + // network distribution |
|
| 32 | + $network = ExtractNetwork::fromIp($device['ip']); |
|
| 33 | + DB::table('network_distribution')->where('network', $network)->increment('pokes'); |
|
| 34 | 34 | |
| 35 | - // pokes |
|
| 36 | - $date = Carbon::now()->toDateString(); |
|
| 37 | - Poke::firstOrCreate(['date' => $date])->increment('pokes'); |
|
| 38 | - } |
|
| 35 | + // pokes |
|
| 36 | + $date = Carbon::now()->toDateString(); |
|
| 37 | + Poke::firstOrCreate(['date' => $date])->increment('pokes'); |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Poke extends Model |
| 8 | 8 | { |
| 9 | - protected $guarded = []; |
|
| 9 | + protected $guarded = []; |
|
| 10 | 10 | |
| 11 | - public $timestamps = false; |
|
| 11 | + public $timestamps = false; |
|
| 12 | 12 | } |