Added pinhole to enhanced list
This commit is contained in:
parent
bbd85d2516
commit
7229d32e8b
7 changed files with 88 additions and 4 deletions
|
@ -64,6 +64,7 @@ class Item extends Model
|
|||
$view = $sap->configDetails();
|
||||
$output->view = $view;
|
||||
}
|
||||
if(!isset($output->dataonly)) $output->dataonly = 0;
|
||||
|
||||
}
|
||||
return (object)$output;
|
||||
|
@ -74,6 +75,7 @@ class Item extends Model
|
|||
$config = null;
|
||||
} else {
|
||||
$store = false;
|
||||
//die(print_r($config));
|
||||
foreach($config as $key => $check) {
|
||||
if($key == 'type') continue;
|
||||
if(!empty($check)) {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<?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()
|
||||
{
|
||||
return '#222';
|
||||
|
@ -9,4 +12,59 @@ class Pihole implements Contracts\Applications {
|
|||
{
|
||||
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
vendored
4
public/js/app.js
vendored
|
@ -20,6 +20,8 @@ $.when( $.ready ).then(function() {
|
|||
if($('.livestats-container').length) {
|
||||
$('.livestats-container').each(function(index){
|
||||
var id = $(this).data('id');
|
||||
var dataonly = $(this).data('dataonly');
|
||||
var increaseby = (dataonly == 1) ? 20000 : 1000;
|
||||
var container = $(this);
|
||||
var max_timer = 30000;
|
||||
var timer = 5000;
|
||||
|
@ -28,7 +30,7 @@ $.when( $.ready ).then(function() {
|
|||
url: '/get_stats/'+id,
|
||||
success: function(data) {
|
||||
container.html(data);
|
||||
if(data != '') timer = 1000;
|
||||
if(data != '') timer = increaseby;
|
||||
else {
|
||||
if(timer < max_timer) timer += 2000;
|
||||
}
|
||||
|
|
4
resources/assets/js/app.js
vendored
4
resources/assets/js/app.js
vendored
|
@ -11,6 +11,8 @@ $.when( $.ready ).then(function() {
|
|||
if($('.livestats-container').length) {
|
||||
$('.livestats-container').each(function(index){
|
||||
var id = $(this).data('id');
|
||||
var dataonly = $(this).data('dataonly');
|
||||
var increaseby = (dataonly == 1) ? 20000 : 1000;
|
||||
var container = $(this);
|
||||
var max_timer = 30000;
|
||||
var timer = 5000;
|
||||
|
@ -19,7 +21,7 @@ $.when( $.ready ).then(function() {
|
|||
url: '/get_stats/'+id,
|
||||
success: function(data) {
|
||||
container.html(data);
|
||||
if(data != '') timer = 1000;
|
||||
if(data != '') timer = increaseby;
|
||||
else {
|
||||
if(timer < max_timer) timer += 2000;
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ return [
|
|||
'apps.password' => 'Password',
|
||||
'apps.config' => 'Config',
|
||||
'apps.apikey' => 'Api Key',
|
||||
'apps.enable' => 'Enable',
|
||||
|
||||
'url' => 'Url',
|
||||
'title' => 'Title',
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<div class="details">
|
||||
<div class="title">{{ $app->title }}</div>
|
||||
@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
|
||||
</div>
|
||||
<a class="link" href="{{ $app->url }}"><i class="fas fa-arrow-alt-to-right"></i></a>
|
||||
|
|
19
resources/views/supportedapps/pihole.blade.php
Normal file
19
resources/views/supportedapps/pihole.blade.php
Normal file
|
@ -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…
Reference in a new issue