Browse Source

Added pinhole to enhanced list

pull/21/head
KodeStar 7 years ago
parent
commit
7229d32e8b
  1. 2
      app/Item.php
  2. 60
      app/SupportedApps/Pihole.php
  3. 4
      public/js/app.js
  4. 4
      resources/assets/js/app.js
  5. 1
      resources/lang/en/app.php
  6. 2
      resources/views/item.blade.php
  7. 19
      resources/views/supportedapps/pihole.blade.php

2
app/Item.php

@ -64,6 +64,7 @@ class Item extends Model
$view = $sap->configDetails(); $view = $sap->configDetails();
$output->view = $view; $output->view = $view;
} }
if(!isset($output->dataonly)) $output->dataonly = 0;
} }
return (object)$output; return (object)$output;
@ -74,6 +75,7 @@ class Item extends Model
$config = null; $config = null;
} else { } else {
$store = false; $store = false;
//die(print_r($config));
foreach($config as $key => $check) { foreach($config as $key => $check) {
if($key == 'type') continue; if($key == 'type') continue;
if(!empty($check)) { if(!empty($check)) {

60
app/SupportedApps/Pihole.php

@ -1,6 +1,9 @@
<?php namespace App\SupportedApps; <?php namespace App\SupportedApps;
class Pihole implements Contracts\Applications { use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
class Pihole implements Contracts\Applications, Contracts\Livestats {
public function defaultColour() public function defaultColour()
{ {
return '#222'; return '#222';
@ -9,4 +12,59 @@ class Pihole implements Contracts\Applications {
{ {
return 'supportedapps/pihole.png'; return 'supportedapps/pihole.png';
} }
public function configDetails()
{
return 'pihole';
}
public function testConfig()
{
$res = $this->buildRequest();
switch($res->getStatusCode()) {
case 200:
echo 'Successfully connected to the API';
break;
case 401:
echo 'Failed: Invalid credentials';
break;
case 404:
echo 'Failed: Please make sure your URL is correct and that there is a trailing slash';
break;
default:
echo 'Something went wrong... Code: '.$res->getStatusCode();
break;
}
}
public function executeConfig()
{
$output = '';
$res = $this->buildRequest();
$data = json_decode($res->getBody());
$output = '
<ul class="livestats">
<li><span class="title">Domains<br />Blocked</span><strong>'.$data->domains_being_blocked.'</strong></li>
<li><span class="title">Blocked<br />Today</span><strong>'.$data->ads_blocked_today.'</span></strong></li>
</ul>
';
return $output;
}
public function buildRequest()
{
$config = $this->config;
$url = $config->url;
$api_url = $url.'admin/api.php';
//die( $api_url.' --- ');
$client = new Client(['http_errors' => false]);
$res = $client->request('GET', $api_url);
return $res;
}
} }

4
public/js/app.js

@ -20,6 +20,8 @@ $.when( $.ready ).then(function() {
if($('.livestats-container').length) { if($('.livestats-container').length) {
$('.livestats-container').each(function(index){ $('.livestats-container').each(function(index){
var id = $(this).data('id'); var id = $(this).data('id');
var dataonly = $(this).data('dataonly');
var increaseby = (dataonly == 1) ? 20000 : 1000;
var container = $(this); var container = $(this);
var max_timer = 30000; var max_timer = 30000;
var timer = 5000; var timer = 5000;
@ -28,7 +30,7 @@ $.when( $.ready ).then(function() {
url: '/get_stats/'+id, url: '/get_stats/'+id,
success: function(data) { success: function(data) {
container.html(data); container.html(data);
if(data != '') timer = 1000; if(data != '') timer = increaseby;
else { else {
if(timer < max_timer) timer += 2000; if(timer < max_timer) timer += 2000;
} }

4
resources/assets/js/app.js

@ -11,6 +11,8 @@ $.when( $.ready ).then(function() {
if($('.livestats-container').length) { if($('.livestats-container').length) {
$('.livestats-container').each(function(index){ $('.livestats-container').each(function(index){
var id = $(this).data('id'); var id = $(this).data('id');
var dataonly = $(this).data('dataonly');
var increaseby = (dataonly == 1) ? 20000 : 1000;
var container = $(this); var container = $(this);
var max_timer = 30000; var max_timer = 30000;
var timer = 5000; var timer = 5000;
@ -19,7 +21,7 @@ $.when( $.ready ).then(function() {
url: '/get_stats/'+id, url: '/get_stats/'+id,
success: function(data) { success: function(data) {
container.html(data); container.html(data);
if(data != '') timer = 1000; if(data != '') timer = increaseby;
else { else {
if(timer < max_timer) timer += 2000; if(timer < max_timer) timer += 2000;
} }

1
resources/lang/en/app.php

@ -60,6 +60,7 @@ return [
'apps.password' => 'Password', 'apps.password' => 'Password',
'apps.config' => 'Config', 'apps.config' => 'Config',
'apps.apikey' => 'Api Key', 'apps.apikey' => 'Api Key',
'apps.enable' => 'Enable',
'url' => 'Url', 'url' => 'Url',
'title' => 'Title', 'title' => 'Title',

2
resources/views/item.blade.php

@ -8,7 +8,7 @@
<div class="details"> <div class="details">
<div class="title">{{ $app->title }}</div> <div class="title">{{ $app->title }}</div>
@if(isset($app->config->enabled) && ((bool)$app->config->enabled === true)) @if(isset($app->config->enabled) && ((bool)$app->config->enabled === true))
<div data-id="{{ $app->id }}" class="livestats-container"></div> <div data-id="{{ $app->id }}" data-dataonly="{{ $app->config->dataonly or '0' }}" class="livestats-container"></div>
@endif @endif
</div> </div>
<a class="link" href="{{ $app->url }}"><i class="fas fa-arrow-alt-to-right"></i></a> <a class="link" href="{{ $app->url }}"><i class="fas fa-arrow-alt-to-right"></i></a>

19
resources/views/supportedapps/pihole.blade.php

@ -0,0 +1,19 @@
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }})</h2>
<div class="items">
<input type="hidden" data-config="type" class="config-item" name="config[type]" value="\App\SupportedApps\Pihole" />
<input type="hidden" data-config="dataonly" class="config-item" name="config[dataonly]" value="1" />
<div class="input">
<label>{{ __('app.apps.enable') }}</label>
<label class="switch">
<?php
$checked = false;
if(isset($item->config->enabled) && (bool)$item->config->enabled === true) $checked = true;
$set_checked = ($checked) ? ' checked="checked"' : '';
?>
{!! Form::hidden('config[enabled]', '0') !!}
<input type="checkbox" name="config[enabled]" value="1"<?php echo $set_checked;?> />
<span class="slider round"></span>
</label>
</div>
<button id="test_config">Test</button>
</div>
Loading…
Cancel
Save