mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Merge branch 'master' of github.com:pcbsd/sysadm
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -12,6 +12,8 @@ src/library/sysadm-general.o
|
||||
src/library/sysadm-lifepreserver.o
|
||||
src/library/sysadm-network.o
|
||||
src/library/sysadm-firewall.o
|
||||
src/library/sysadm-servicemanager.o
|
||||
src/library/sysadm-systeminfo.o
|
||||
src/library/sysadm-update.o
|
||||
src/library/sysadm-usermanager.o
|
||||
src/server/AuthorizationManager.o
|
||||
|
||||
151
api/classes/systeminfo.rst
Normal file
151
api/classes/systeminfo.rst
Normal file
@@ -0,0 +1,151 @@
|
||||
.. _systeminfo:
|
||||
|
||||
systeminfo
|
||||
**********
|
||||
|
||||
The systeminfo class is used to retrieve information about the system. Every systeminfo class request contains the following parameters:
|
||||
|
||||
+---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+
|
||||
| **Parameter** | **Value** | **Description** |
|
||||
| | | |
|
||||
+=================================+===============+======================================================================================================================+
|
||||
| id | | any unique value for the request; examples include a hash, checksum, or uuid |
|
||||
| | | |
|
||||
+---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+
|
||||
| name | systeminfo | |
|
||||
| | | |
|
||||
+---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+
|
||||
| namespace | sysadm | |
|
||||
| | | |
|
||||
+---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+
|
||||
| action | | supported actions include "batteryinfo", "externalmounts" |
|
||||
| | | |
|
||||
+---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+
|
||||
|
||||
The rest of this section provides examples of the available *actions* for each type of request, along with their responses.
|
||||
|
||||
.. index:: batteryinfo, systeminfo
|
||||
|
||||
.. _Battery Information:
|
||||
|
||||
Battery Information
|
||||
===================
|
||||
|
||||
The "batteryinfo" action will indicate whether or not a battery exists. If it does, it will also report its current charge percentage level (1-99) and its
|
||||
status (offline, charging, on backup, or unknown).
|
||||
|
||||
**REST Request**
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
PUT /sysadm/systeminfo
|
||||
{
|
||||
"action" : "batteryinfo"
|
||||
}
|
||||
|
||||
**REST Response**
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"args": {
|
||||
"batteryinfo": {
|
||||
"battery": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
**WebSocket Request**
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"namespace" : "sysadm",
|
||||
"name" : "systeminfo",
|
||||
"id" : "fooid",
|
||||
"args" : {
|
||||
"action" : "batteryinfo"
|
||||
}
|
||||
}
|
||||
|
||||
**WebSocket Response**
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"args": {
|
||||
"batteryinfo": {
|
||||
"battery": "false"
|
||||
}
|
||||
},
|
||||
"id": "fooid",
|
||||
"name": "response",
|
||||
"namespace": "sysadm"
|
||||
}
|
||||
|
||||
.. index:: externalmounts, systeminfo
|
||||
|
||||
.. _List External Mounts:
|
||||
|
||||
List External Mounts
|
||||
====================
|
||||
|
||||
The "externalmounts" action returns a list of mounted external devices. Supported device types are UNKNOWN, USB, HDRIVE (external hard drive), DVD, and SDCARD.
|
||||
For each mounted device, the response will include the device name, filesystem, mount path, and device type.
|
||||
|
||||
**REST Request**
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
PUT /sysadm/systeminfo
|
||||
{
|
||||
"action" : "externalmounts"
|
||||
}
|
||||
|
||||
**REST Response**
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"args": {
|
||||
"externalmounts": {
|
||||
"/dev/fuse": {
|
||||
"filesystem": "fusefs",
|
||||
"path": "/usr/home/kris/.gvfs",
|
||||
"type": "UNKNOWN"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
**WebSocket Request**
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"id" : "fooid",
|
||||
"namespace" : "sysadm",
|
||||
"name" : "systeminfo",
|
||||
"args" : {
|
||||
"action" : "externalmounts"
|
||||
}
|
||||
}
|
||||
|
||||
**WebSocket Response**
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"args": {
|
||||
"externalmounts": {
|
||||
"/dev/fuse": {
|
||||
"filesystem": "fusefs",
|
||||
"path": "/usr/home/kris/.gvfs",
|
||||
"type": "UNKNOWN"
|
||||
}
|
||||
}
|
||||
},
|
||||
"id": "fooid",
|
||||
"name": "response",
|
||||
"namespace": "sysadm"
|
||||
}
|
||||
@@ -16,6 +16,7 @@ HEADERS += sysadm-global.h \
|
||||
sysadm-network.h \
|
||||
sysadm-firewall.h \
|
||||
sysadm-servicemanager.h\
|
||||
sysadm-systeminfo.h\
|
||||
sysadm-update.h \
|
||||
sysadm-usermanager.h
|
||||
|
||||
@@ -25,6 +26,7 @@ SOURCES += NetDevice.cpp \
|
||||
sysadm-network.cpp \
|
||||
sysadm-firewall.cpp \
|
||||
sysadm-servicemanager.cpp \
|
||||
sysadm-systeminfo.cpp \
|
||||
sysadm-update.cpp \
|
||||
sysadm-usermanager.cpp
|
||||
|
||||
|
||||
86
src/library/sysadm-systeminfo.cpp
Normal file
86
src/library/sysadm-systeminfo.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
//===========================================
|
||||
// PC-BSD source code
|
||||
// Copyright (c) 2015, PC-BSD Software/iXsystems
|
||||
// Available under the 3-clause BSD license
|
||||
// See the LICENSE file for full details
|
||||
//===========================================
|
||||
#include "sysadm-general.h"
|
||||
#include "sysadm-systeminfo.h"
|
||||
#include "sysadm-global.h"
|
||||
|
||||
using namespace sysadm;
|
||||
|
||||
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
|
||||
|
||||
|
||||
//Battery Availability
|
||||
QJsonObject SysInfo::batteryInfo(){
|
||||
QJsonObject retObject;
|
||||
bool ok;
|
||||
|
||||
int val = General::RunCommand("apm -l").toInt(&ok);
|
||||
if ( ok && (val >= 0 && val <= 100) ) {
|
||||
retObject.insert("battery", "true");
|
||||
} else {
|
||||
retObject.insert("battery", "false");
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// We have a battery, return info about it
|
||||
//Battery Charge Level
|
||||
QString tmp;
|
||||
tmp.setNum(val);
|
||||
retObject.insert("level", tmp);
|
||||
|
||||
//Battery Charging State
|
||||
int state = General::RunCommand("apm -a").toInt(&ok);
|
||||
if ( ok && state == 0 )
|
||||
retObject.insert("status", "offline");
|
||||
else if ( ok && state == 1 )
|
||||
retObject.insert("status", "charging");
|
||||
else if ( ok && state == 2 )
|
||||
retObject.insert("status", "backup");
|
||||
else
|
||||
retObject.insert("status", "unknown");
|
||||
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// ==== ExternalDevicePaths() ====
|
||||
QJsonObject SysInfo::externalDevicePaths() {
|
||||
QJsonObject retObject;
|
||||
|
||||
//Returns: QStringList[<type>::::<filesystem>::::<path>]
|
||||
//Note: <type> = [USB, HDRIVE, DVD, SDCARD, UNKNOWN]
|
||||
QStringList devs = General::RunCommand("mount").split("\n");
|
||||
|
||||
//Now check the output
|
||||
for(int i=0; i<devs.length(); i++){
|
||||
if(devs[i].startsWith("/dev/")){
|
||||
devs[i].replace("\t"," ");
|
||||
QString type = devs[i].section(" on ",0,0);
|
||||
type.remove("/dev/");
|
||||
//Determine the type of hardware device based on the dev node
|
||||
if(type.startsWith("da")){ type = "USB"; }
|
||||
else if(type.startsWith("ada")){ type = "HDRIVE"; }
|
||||
else if(type.startsWith("mmsd")){ type = "SDCARD"; }
|
||||
else if(type.startsWith("cd")||type.startsWith("acd")){ type="DVD"; }
|
||||
else{ type = "UNKNOWN"; }
|
||||
//Now put the device in the proper output format
|
||||
QString filesystem = devs[i].section("(",1,1).section(",",0,0);
|
||||
QString path = devs[i].section(" on ",1,50).section("(",0,0).simplified();
|
||||
QJsonObject vals;
|
||||
vals.insert("type",type);
|
||||
vals.insert("filesystem",filesystem);
|
||||
vals.insert("path",path);
|
||||
retObject.insert(devs[i].section(" ", 0, 0), vals);
|
||||
}else{
|
||||
//invalid device - remove it from the list
|
||||
devs.removeAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the devices / mounts
|
||||
return retObject;
|
||||
}
|
||||
23
src/library/sysadm-systeminfo.h
Normal file
23
src/library/sysadm-systeminfo.h
Normal file
@@ -0,0 +1,23 @@
|
||||
//===========================================
|
||||
// PC-BSD source code
|
||||
// Copyright (c) 2015, PC-BSD Software/iXsystems
|
||||
// Available under the 3-clause BSD license
|
||||
// See the LICENSE file for full details
|
||||
//===========================================
|
||||
#ifndef __PCBSD_LIB_UTILS_SYSINFO_H
|
||||
#define __PCBSD_LIB_UTILS_SYSINFO_H
|
||||
|
||||
#include <QJsonObject>
|
||||
#include "sysadm-global.h"
|
||||
|
||||
namespace sysadm{
|
||||
|
||||
class SysInfo{
|
||||
public:
|
||||
static QJsonObject batteryInfo();
|
||||
static QJsonObject externalDevicePaths();
|
||||
};
|
||||
|
||||
} //end of pcbsd namespace
|
||||
|
||||
#endif
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "sysadm-general.h"
|
||||
#include "sysadm-lifepreserver.h"
|
||||
#include "sysadm-network.h"
|
||||
#include "sysadm-systeminfo.h"
|
||||
#include "sysadm-update.h"
|
||||
|
||||
#include "syscache-client.h"
|
||||
@@ -67,6 +68,8 @@ RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(const RestInputStru
|
||||
return EvaluateSysadmNetworkRequest(IN.args, out);
|
||||
}else if(namesp=="sysadm" && name=="lifepreserver"){
|
||||
return EvaluateSysadmLifePreserverRequest(IN.args, out);
|
||||
}else if(namesp=="sysadm" && name=="systeminfo"){
|
||||
return EvaluateSysadmSystemInfoRequest(IN.args, out);
|
||||
}else if(namesp=="sysadm" && name=="update"){
|
||||
return EvaluateSysadmUpdateRequest(IN.args, out);
|
||||
}else{
|
||||
@@ -245,6 +248,34 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmLifePreserverRequest(const Q
|
||||
return RestOutputStruct::OK;
|
||||
}
|
||||
|
||||
//==== SYSADM -- SysInfo ====
|
||||
RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSystemInfoRequest(const QJsonValue in_args, QJsonObject *out){
|
||||
if(in_args.isObject()){
|
||||
QStringList keys = in_args.toObject().keys();
|
||||
bool ok = false;
|
||||
if(keys.contains("action")){
|
||||
QString act = JsonValueToString(in_args.toObject().value("action"));
|
||||
if(act=="externalmounts"){
|
||||
ok = true;
|
||||
out->insert("externalmounts", sysadm::SysInfo::externalDevicePaths());
|
||||
}
|
||||
if(act=="batteryinfo"){
|
||||
ok = true;
|
||||
out->insert("batteryinfo", sysadm::SysInfo::batteryInfo());
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
//If nothing done - return the proper code
|
||||
if(!ok){
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
}
|
||||
}else{ // if(in_args.isArray()){
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
}
|
||||
return RestOutputStruct::OK;
|
||||
}
|
||||
|
||||
//==== SYSADM -- Update ====
|
||||
RestOutputStruct::ExitCode WebSocket::EvaluateSysadmUpdateRequest(const QJsonValue in_args, QJsonObject *out){
|
||||
if(in_args.isObject()){
|
||||
|
||||
@@ -50,6 +50,8 @@ private:
|
||||
RestOutputStruct::ExitCode EvaluateSysadmNetworkRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
// -- sysadm LifePreserver API
|
||||
RestOutputStruct::ExitCode EvaluateSysadmLifePreserverRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
// -- sysadm info API
|
||||
RestOutputStruct::ExitCode EvaluateSysadmSystemInfoRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
// -- sysadm Update API
|
||||
RestOutputStruct::ExitCode EvaluateSysadmUpdateRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user