mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Add first API call for the "systeminfo" class
This API call will return a list of external mounts
on the system
TYPE: UNKNOWN/USB/HDRIVE/DVD/SDCARD
REST Request:
-------------------------------
PUT /sysadm/systeminfo
{
"action" : "externalmounts"
}
REST Response:
-------------------------------
{
"args": {
"externalmounts": {
"/dev/fuse": {
"filesystem": "fusefs",
"path": "/usr/home/kris/.gvfs",
"type": "UNKNOWN"
}
}
}
}
WebSocket Request:
-------------------------------
{
"id" : "fooid",
"namespace" : "sysadm",
"name" : "systeminfo",
"args" : {
"action" : "externalmounts"
}
}
WebSocket Response:
-------------------------------
{
"args": {
"externalmounts": {
"/dev/fuse": {
"filesystem": "fusefs",
"path": "/usr/home/kris/.gvfs",
"type": "UNKNOWN"
}
}
},
"id": "fooid",
"name": "response",
"namespace": "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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
52
src/library/sysadm-systeminfo.cpp
Normal file
52
src/library/sysadm-systeminfo.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
//===========================================
|
||||
// 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
|
||||
|
||||
// ==== 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;
|
||||
}
|
||||
22
src/library/sysadm-systeminfo.h
Normal file
22
src/library/sysadm-systeminfo.h
Normal file
@@ -0,0 +1,22 @@
|
||||
//===========================================
|
||||
// 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 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,30 @@ 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());
|
||||
}
|
||||
|
||||
} //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