ajout heimdall
This commit is contained in:
10
heimdall/config/www/SupportedApps/openmediavault/app.json
Executable file
10
heimdall/config/www/SupportedApps/openmediavault/app.json
Executable file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"appid": "68a90a2f21aad7a09a3533a2c6ab9a03dc94af49",
|
||||
"name": "openmediavault",
|
||||
"website": "https://www.openmediavault.org/",
|
||||
"license": "GNU General Public License v3.0 only",
|
||||
"description": "openmediavault is the next generation network attached storage (NAS) solution based on Debian Linux.",
|
||||
"enhanced": true,
|
||||
"tile_background": "dark",
|
||||
"icon": "openmediavault.png"
|
||||
}
|
||||
22
heimdall/config/www/SupportedApps/openmediavault/config.blade.php
Executable file
22
heimdall/config/www/SupportedApps/openmediavault/config.blade.php
Executable file
@@ -0,0 +1,22 @@
|
||||
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
|
||||
<div class="items">
|
||||
<div class="input">
|
||||
<label>{{ strtoupper(__('app.url')) }}</label>
|
||||
{!! Form::text('config[override_url]', null, array('placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control')) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.username') }}</label>
|
||||
{!! Form::text('config[username]', null, array('placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item')) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.password') }}</label>
|
||||
{!! Form::password('config[password]', array('placeholder' => __('app.apps.password'), 'data-config' => 'password', 'class' => 'form-control config-item')) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>Stats to show</label>
|
||||
{!! Form::select('config[availablestats][]', App\SupportedApps\openmediavault\openmediavault::getAvailableStats(), isset($item) ? ($item->getConfig()->availablestats ?? null) : null, array('multiple'=>'multiple')) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
8
heimdall/config/www/SupportedApps/openmediavault/livestats.blade.php
Executable file
8
heimdall/config/www/SupportedApps/openmediavault/livestats.blade.php
Executable file
@@ -0,0 +1,8 @@
|
||||
<ul class="livestats">
|
||||
@foreach ($visiblestats as $stat)
|
||||
<li>
|
||||
<span class="title">{!! $stat->title !!}</span>
|
||||
<strong>{!! $stat->value !!}</strong>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
100
heimdall/config/www/SupportedApps/openmediavault/openmediavault.php
Executable file
100
heimdall/config/www/SupportedApps/openmediavault/openmediavault.php
Executable file
@@ -0,0 +1,100 @@
|
||||
<?php namespace App\SupportedApps\openmediavault;
|
||||
use Exception;
|
||||
use GuzzleHttp\Cookie\CookieJar;
|
||||
|
||||
class openmediavault extends \App\SupportedApps implements \App\EnhancedApps {
|
||||
public $config;
|
||||
|
||||
private $cookie;
|
||||
|
||||
function __construct() {
|
||||
$this->cookie = new \GuzzleHttp\Cookie\CookieJar;
|
||||
}
|
||||
|
||||
public function url($endpoint) {
|
||||
$api_url = parent::normaliseurl($this->config->url) . 'rpc.php';
|
||||
return $api_url;
|
||||
}
|
||||
|
||||
private function request($service, $method, $params = []) {
|
||||
$attrs = [
|
||||
'json' => [
|
||||
'service' => $service,
|
||||
'method' => $method,
|
||||
'params' => $params,
|
||||
],
|
||||
'cookies' => $this->cookie,
|
||||
];
|
||||
|
||||
// @see \App\SupportedApps\execute($url, $attrs = [], $overridevars=false, $overridemethod=false)
|
||||
$result = parent::execute($this->url(false), $attrs, false, 'POST');
|
||||
if (null === $result) {
|
||||
throw new Exception("OMV error: Could not connect");
|
||||
}
|
||||
|
||||
$response = json_decode($result->getBody());
|
||||
|
||||
if (is_null($response->response) && isset($response->error->message)) {
|
||||
throw new Exception(sprintf('OMV error: %s', $response->error->message));
|
||||
}
|
||||
elseif (is_null($response->response)) {
|
||||
throw new Exception('OMV error: Empty response');
|
||||
}
|
||||
return $response->response;
|
||||
}
|
||||
|
||||
private function auth() {
|
||||
$result = $this->request('session', 'login', ['username' => $this->config->username, 'password' => $this->config->password]);
|
||||
return $result->authenticated;
|
||||
}
|
||||
|
||||
public function test() {
|
||||
try {
|
||||
$token = $this->auth();
|
||||
echo "Successfully communicated with the API";
|
||||
} catch (Exception $err) {
|
||||
echo $err->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private function symbol($bool) {
|
||||
return (true === $bool ? '✓' : '✗');
|
||||
}
|
||||
|
||||
public function livestats() {
|
||||
$status = 'inactive';
|
||||
$token = $this->auth();
|
||||
$data = ['visiblestats' => []];
|
||||
|
||||
$info = $this->request('system', 'getInformation');
|
||||
$data['CPU'] = sprintf('%.1f%%', $info->cpuUsage );
|
||||
$data['RAM'] = sprintf('%.1f%%', $info->memUsed / $info->memTotal * 100 );
|
||||
|
||||
$services = $this->request('services', 'getStatus');
|
||||
foreach ($services->data as $service) {
|
||||
$k = explode(' ', $service->title)[0];
|
||||
$data[$k] = sprintf('%s | %s', $this->symbol($service->enabled), $this->symbol($service->running));
|
||||
}
|
||||
|
||||
foreach ($this->config->availablestats as $stat) {
|
||||
$newstat = new \stdClass;
|
||||
$newstat->title = self::getAvailableStats()[$stat];
|
||||
$newstat->value = $data[$stat];
|
||||
$data['visiblestats'][] = $newstat;
|
||||
}
|
||||
$status = 'active';
|
||||
return parent::getLiveStats($status, $data);
|
||||
}
|
||||
|
||||
public static function getAvailableStats() {
|
||||
return [
|
||||
'CPU' => 'CPU',
|
||||
'RAM' => 'RAM',
|
||||
'NFS' => 'NFS',
|
||||
'FTP' => 'FTP',
|
||||
'RSync' => 'RSync',
|
||||
'SMB/CIFS' => 'SMB/CIFS',
|
||||
'SSH' => 'SSH',
|
||||
];
|
||||
}
|
||||
}
|
||||
BIN
heimdall/config/www/SupportedApps/openmediavault/openmediavault.png
Executable file
BIN
heimdall/config/www/SupportedApps/openmediavault/openmediavault.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
Reference in New Issue
Block a user