mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 02:20:17 +00:00
Merge branch 'master' of github.com:pcbsd/sysadm
This commit is contained in:
33
port-files/Makefile
Normal file
33
port-files/Makefile
Normal file
@@ -0,0 +1,33 @@
|
||||
# Created by: Kris Moore <kmoore@FreeBSD.org>
|
||||
# $FreeBSD$
|
||||
|
||||
PORTNAME= pcbsd-sysadm
|
||||
PORTVERSION= %%CHGVERSION%%
|
||||
CATEGORIES= sysutils
|
||||
|
||||
MAINTAINER= kmoore@FreeBSD.org
|
||||
COMMENT= PC-BSD SysAdm API server
|
||||
|
||||
LICENSE= BSD3CLAUSE
|
||||
|
||||
RUN_DEPENDS= sipcalc:${PORTSDIR}/net-mgmt/sipcalc \
|
||||
eject:${PORTSDIR}/sysutils/eject \
|
||||
unzip:${PORTSDIR}/archivers/unzip
|
||||
|
||||
WRKSRC_SUBDIR= src
|
||||
USE_QT5= core network buildtools qmake
|
||||
USES= pkgconfig tar:xz qmake
|
||||
MAKE_ARGS= PREFIX=${STAGEDIR}${PREFIX}
|
||||
|
||||
USE_GITHUB= yes
|
||||
GH_ACCOUNT= pcbsd
|
||||
GH_PROJECT= sysadm
|
||||
GH_TAGNAME= %%GHTAG%%
|
||||
|
||||
.include <bsd.port.pre.mk>
|
||||
|
||||
.if ${OSVERSION} < 1000000
|
||||
IGNORE= requires FreeBSD 10 or later
|
||||
.endif
|
||||
|
||||
.include <bsd.port.post.mk>
|
||||
2
port-files/distinfo
Normal file
2
port-files/distinfo
Normal file
@@ -0,0 +1,2 @@
|
||||
SHA256 (pcbsd-sysadm-20151217-5583f4d2c00d8326b44f7d39eefd0a90276d7a74_GH0.tar.xz) = 00972329b84a6a4bab0c9bde2ee3f513ce7bdf9a9ef1b3b496241cd4ddf20c54
|
||||
SIZE (pcbsd-sysadm-20151217-5583f4d2c00d8326b44f7d39eefd0a90276d7a74_GH0.tar.xz) = 37757
|
||||
3
port-files/pkg-descr
Normal file
3
port-files/pkg-descr
Normal file
@@ -0,0 +1,3 @@
|
||||
PC-BSD SysAdm utility and websocket server
|
||||
|
||||
WWW: https://github.com/pcbsd/sysadm
|
||||
11
port-files/pkg-plist
Normal file
11
port-files/pkg-plist
Normal file
@@ -0,0 +1,11 @@
|
||||
bin/sysadm
|
||||
bin/sysadm-server
|
||||
etc/rc.d/sysadm
|
||||
include/sysadm-general.h
|
||||
include/sysadm-global.h
|
||||
include/sysadm-lifepreserver.h
|
||||
include/sysadm-network.h
|
||||
%%QT_LIBDIR%%/%%QT_LIBDIR%%sysadm.so
|
||||
%%QT_LIBDIR%%/%%QT_LIBDIR%%sysadm.so.1
|
||||
%%QT_LIBDIR%%/%%QT_LIBDIR%%sysadm.so.1.0
|
||||
%%QT_LIBDIR%%/%%QT_LIBDIR%%sysadm.so.1.0.0
|
||||
41
src/rc.d/sysadm
Executable file
41
src/rc.d/sysadm
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
# $FreeBSD$
|
||||
|
||||
# PROVIDE: sysadm
|
||||
# REQUIRE: LOGIN cleanvar
|
||||
# KEYWORD: shutdown
|
||||
|
||||
#
|
||||
# Add the following lines to /etc/rc.conf to enable sysadm:
|
||||
# sysadm_enable (bool): Set to "NO" by default.
|
||||
# Set it to "YES" to enable sysadm
|
||||
|
||||
. /etc/rc.subr
|
||||
|
||||
name="sysadm"
|
||||
rcvar=sysadm_enable
|
||||
|
||||
command="/usr/local/bin/sysadm-server"
|
||||
start_cmd="sysadm_start"
|
||||
stop_cmd="sysadm_stop"
|
||||
|
||||
[ -z "$sysadm_enable" ] && sysadm_enable="NO"
|
||||
|
||||
load_rc_config $name
|
||||
|
||||
sysadm_stop()
|
||||
{
|
||||
if [ -e "/var/run/sysadm.pid" ] ; then
|
||||
pkill -9 -F /var/run/sysadm.pid
|
||||
fi
|
||||
}
|
||||
|
||||
sysadm_start()
|
||||
{
|
||||
export PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
|
||||
sysadm_stop
|
||||
echo "Starting sysadm..."
|
||||
daemon -p /var/run/sysadm.pid $command $flags >/dev/null 2>/dev/null
|
||||
}
|
||||
|
||||
run_rc_command "$1"
|
||||
@@ -6,8 +6,8 @@
|
||||
#include <WebSocket.h>
|
||||
|
||||
//sysadm library interface classes
|
||||
#include <sysadm-general.h>
|
||||
#include <sysadm-network.h>
|
||||
#include "sysadm-general.h"
|
||||
#include "sysadm-network.h"
|
||||
|
||||
#include "syscache-client.h"
|
||||
#include "dispatcher-client.h"
|
||||
@@ -16,53 +16,69 @@
|
||||
#define SCLISTDELIM QString("::::") //SysCache List Delimiter
|
||||
|
||||
void WebSocket::EvaluateBackendRequest(QString name, const QJsonValue args, QJsonObject *out){
|
||||
QJsonObject obj; //output object
|
||||
if(args.isObject()){
|
||||
//For the moment: all arguments are full syscache DB calls - no special ones
|
||||
QStringList reqs = args.toObject().keys();
|
||||
if(!reqs.isEmpty()){
|
||||
if(DEBUG){ qDebug() << "Parsing Inputs:" << reqs; }
|
||||
for(int r=0; r<reqs.length(); r++){
|
||||
QString req = JsonValueToString(args.toObject().value(reqs[r]));
|
||||
if(DEBUG){ qDebug() << " ["+reqs[r]+"]="+req; }
|
||||
QStringList values;
|
||||
if(name.toLower()=="syscache"){values = SysCacheClient::parseInputs( QStringList() << req ); }
|
||||
else if(name.toLower()=="dispatcher"){values = DispatcherClient::parseInputs( QStringList() << req, AUTHSYSTEM); }
|
||||
values.removeAll("");
|
||||
//Quick check if a list of outputs was returned
|
||||
if(values.length()==1 && name.toLower()=="syscache"){
|
||||
values = values[0].split(SCLISTDELIM); //split up the return list (if necessary)
|
||||
values.removeAll("");
|
||||
}
|
||||
if(DEBUG){ qDebug() << " - Returns:" << values; }
|
||||
if(values.length()<2){ out->insert(req, QJsonValue(values.join("")) ); }
|
||||
else{
|
||||
//This is an array of outputs
|
||||
QJsonArray arr;
|
||||
for(int i=0; i<values.length(); i++){ arr.append(values[i]); }
|
||||
out->insert(req,arr);
|
||||
}
|
||||
}
|
||||
} //end of special "request" objects
|
||||
}else if(args.isArray()){
|
||||
QStringList inputs = JsonArrayToStringList(args.toArray());
|
||||
if(DEBUG){ qDebug() << "Parsing Array inputs:" << inputs; }
|
||||
QStringList values;
|
||||
if(name.toLower()=="syscache"){values = SysCacheClient::parseInputs( inputs ); }
|
||||
else if(name.toLower()=="dispatcher"){values = DispatcherClient::parseInputs( inputs , AUTHSYSTEM); }
|
||||
if(DEBUG){ qDebug() << " - Returns:" << values; }
|
||||
for(int i=0; i<values.length(); i++){
|
||||
if(name.toLower()=="syscache" && values[i].contains(SCLISTDELIM)){
|
||||
//Go through and forward this request to the appropriate sub-system
|
||||
if(name.toLower()=="syscache"){
|
||||
return EvaluateSyscacheRequest(args, out);
|
||||
}else if(name.toLower()=="dispatcher"){
|
||||
return EvaluateSyscacheRequest(args, out);
|
||||
}else{
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RestOutputStruct::ExitCode WebSocket::EvaluateSyscacheRequest(const QJsonValue in_args, QJSonObject *out){
|
||||
//syscache only needs a list of sub-commands at the moment (might change later)
|
||||
QStringList in_req;
|
||||
|
||||
//Parse the input arguments structure
|
||||
if(args.isArray()){ in_req = JsonArrayToStringList(args.toArray()); }
|
||||
else if(args.isObject()){
|
||||
QStringList keys = arg.toObject().keys();
|
||||
for(int i=0; i<keys.length(); i++){ in_req << JsonValueToString(args.toObject().value(keys[i])); }
|
||||
}else if(args.isValue()){ in_req << JsonValueToString(args.toValue()); }
|
||||
}else{ return RestOutputStruct::BADREQUEST; }
|
||||
|
||||
//Run the Request (should be one value for each in_req)
|
||||
QStringList values = SysCacheClient::parseInputs(in_req);
|
||||
while(values.length() < in_req.length()){ values << "[ERROR]"; } //ensure lists are same length
|
||||
|
||||
//Format the result
|
||||
for(int i=0; i<values.length(); i++){
|
||||
if(values[i].contains(SCLISTDELIM)){
|
||||
//This is an array of values from syscache
|
||||
QStringList vals = values[i].split(SCLISTDELIM);
|
||||
vals.removeAll("");
|
||||
QJsonArray arr;
|
||||
for(int j=0; j<vals.length(); j++){ arr.append(vals[j]); }
|
||||
out->insert(inputs[i],arr);
|
||||
out->insert(in_req[i],arr);
|
||||
}else{
|
||||
out->insert(inputs[i],values[i]);
|
||||
out->insert(in_req[i],values[i]);
|
||||
}
|
||||
}
|
||||
} //end array of inputs
|
||||
|
||||
}
|
||||
//Return Success
|
||||
return RestOutputStruct::OK;
|
||||
}
|
||||
|
||||
RestOutputStruct::ExitCode WebSocket::EvaluateDispatcherRequest(const QJsonValue in_args, QJSonObject *out){
|
||||
//dispatcher only needs a list of sub-commands at the moment (might change later)
|
||||
QStringList in_req;
|
||||
|
||||
//Parse the input arguments structure
|
||||
if(args.isArray()){ in_req = JsonArrayToStringList(args.toArray()); }
|
||||
else if(args.isObject()){
|
||||
QStringList keys = arg.toObject().keys();
|
||||
for(int i=0; i<keys.length(); i++){ in_req << JsonValueToString(args.toObject().value(keys[i])); }
|
||||
}else if(args.isValue()){ in_req << JsonValueToString(args.toValue()); }
|
||||
}else{ return RestOutputStruct::BADREQUEST; }
|
||||
|
||||
//Run the Request (should be one value for each in_req)
|
||||
QStringList values = DispatcherClient::parseInputs(in_req, AUTHSYSTEM);;
|
||||
while(values.length() < in_req.length()){ values << "[ERROR]"; } //ensure lists are same length
|
||||
|
||||
//Format the result
|
||||
for(int i=0; i<values.length(); i++){ out->insert(in_req[i],values[i]); }
|
||||
//Return Success
|
||||
return RestOutputStruct::OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -192,4 +192,4 @@ void WebServer::WatcherUpdate(QString path){
|
||||
if(!watcher->files().contains(path) && !watcher->directories().contains(path)){
|
||||
watcher->addPath(path); //re-add it to the watcher. This happens when the file is removed/re-created instead of just overwritten
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,9 @@ private:
|
||||
void SetOutputError(QJsonObject *ret, QString id, int err, QString msg);
|
||||
|
||||
//Backend request/reply functions (contained in WebBackend.cpp)
|
||||
void EvaluateBackendRequest(QString name, const QJsonValue in_args, QJsonObject *out);
|
||||
RestOutputStruct::ExitCode EvaluateBackendRequest(QString name, const QJsonValue in_args, QJsonObject *out);
|
||||
RestOutputStruct::ExitCode EvaluateSyscacheRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
RestOutputStruct::ExitCode EvaluateDispatcherRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
|
||||
private slots:
|
||||
void checkIdle(); //see if the currently-connected client is idle
|
||||
|
||||
@@ -27,7 +27,6 @@ target.path=/usr/local/bin
|
||||
INSTALLS += target
|
||||
|
||||
|
||||
QMAKE_LIBDIR = /usr/local/lib/qt5 /usr/local/lib
|
||||
|
||||
INCLUDEPATH += /usr/local/include
|
||||
LIBS += -L../library -L/usr/local/lib -lpam -lutil -lsysadm
|
||||
QMAKE_LIBDIR = ../library /usr/local/lib/qt5 /usr/local/lib
|
||||
INCLUDEPATH += ../library /usr/local/include
|
||||
LIBS += -L../library -L/usr/local/lib -lpam -lutil -lsysadm
|
||||
|
||||
@@ -7,3 +7,7 @@ SUBDIRS+= library binary server
|
||||
binary.depends = library
|
||||
server.depends = library
|
||||
|
||||
rcd.path = /usr/local/etc/rc.d/
|
||||
rcd.extra = cp rc.d/* $(INSTALL_ROOT)/usr/local/etc/rc.d/
|
||||
|
||||
INSTALLS += rcd
|
||||
|
||||
Reference in New Issue
Block a user