mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 02:20:17 +00:00
Merge branch 'master' of https://github.com/pcbsd/sysadm
This commit is contained in:
@@ -128,14 +128,14 @@ void AuthorizationManager::ListCertificates(QString token, QJsonObject *out){
|
||||
}
|
||||
|
||||
void AuthorizationManager::ListCertificateChecksums(QJsonObject *out){
|
||||
QStringList keys; //Format: "RegisteredCerts/<user>/<key>"
|
||||
QStringList keys; //Format: "RegisteredCerts/<user>/<key>" (value is full text)
|
||||
//Read all user's certs (since we only need checksums)
|
||||
keys = CONFIG->allKeys().filter("RegisteredCerts/");
|
||||
keys.sort();
|
||||
QJsonArray arr;
|
||||
QCryptographicHash chash(QCryptographicHash::Md5);
|
||||
for(int i=0; i<keys.length(); i++){
|
||||
chash.addData( CONFIG->value(keys[i]).toString().toLocal8Bit() );
|
||||
chash.addData( keys[i].section("/",2,-1).toLocal8Bit() );
|
||||
QByteArray res = chash.result();
|
||||
chash.reset();
|
||||
arr << QString(res);
|
||||
|
||||
@@ -131,7 +131,7 @@ void WebSocket::EvaluateREST(QString msg){
|
||||
}
|
||||
|
||||
void WebSocket::EvaluateRequest(const RestInputStruct &REQ){
|
||||
//qDebug() << "Evaluate Request:" << REQ.namesp << REQ.name << REQ.args;
|
||||
qDebug() << "Evaluate Request:" << REQ.namesp << REQ.name << REQ.args;
|
||||
RestOutputStruct out;
|
||||
out.in_struct = REQ;
|
||||
QHostAddress host;
|
||||
@@ -150,7 +150,7 @@ void WebSocket::EvaluateRequest(const RestInputStruct &REQ){
|
||||
AUTHSYSTEM->clearAuth(SockAuthToken); //new auth requested - clear any old token
|
||||
SockAuthToken = AUTHSYSTEM->LoginUP(host, out.in_struct.auth.section(":",0,0), out.in_struct.auth.section(":",1,1));
|
||||
}
|
||||
|
||||
//qDebug() << "Auth Token:" << SockAuthToken;
|
||||
//Now check the body of the message and do what it needs
|
||||
if(out.in_struct.namesp.toLower() == "rpc"){
|
||||
if(out.in_struct.name == "identify"){
|
||||
@@ -377,19 +377,23 @@ void WebSocket::ParseIncoming(){
|
||||
// Check if we have a complete JSON request waiting to be parsed
|
||||
QString JsonRequest;
|
||||
for ( int i = 0; i<incomingbuffer.size(); i++) {
|
||||
JsonRequest = incomingbuffer;
|
||||
JsonRequest.truncate(i);
|
||||
if ( !QJsonDocument::fromBinaryData(JsonRequest.toLocal8Bit()).isNull() )
|
||||
if(incomingbuffer[i]!='}'){ continue; } //only look for the end of a JSON block
|
||||
JsonRequest = incomingbuffer.left(i+1);
|
||||
//REST requests will have non-JSON at the top - trim that off
|
||||
JsonRequest = "{"+JsonRequest.section("{",1,-1);
|
||||
//JsonRequest.truncate(i);
|
||||
//qDebug() << "Check JSON:" << JsonRequest;
|
||||
if ( !QJsonDocument::fromJson(JsonRequest.toLocal8Bit()).isNull() )
|
||||
{
|
||||
// We have what looks like a valid JSON request, lets parse it now
|
||||
//qDebug() << "TCP Message" << JsonRequest;
|
||||
EvaluateREST(JsonRequest);
|
||||
EvaluateREST(incomingbuffer.left(i+1)); //send the full message
|
||||
incomingbuffer.remove(0, i);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//if(!found){ qDebug() << "Bad Message:" << incomingbuffer; }
|
||||
// If the buffer is larger than 128000 chars and no valid JSON somebody
|
||||
// is screwing with us, lets clear the buffer
|
||||
if ( ! found && incomingbuffer.size() > 128000 ) {
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
# Default values
|
||||
DEFUSER="root"
|
||||
DEFNAMESPACE="sysadm"
|
||||
DEFCLASS="logs"
|
||||
DEFACTION="{\"action\":\"read_logs\",\"time_format\":\"relative_second\",\"start_time\":\"-3600\"}"
|
||||
DEFCLASS="systemmanager"
|
||||
DEFACTION="{\"action\":\"procinfo\"}"
|
||||
|
||||
# Set variable to call jsawk utility
|
||||
JSAWK="./utils/jsawk -j js24"
|
||||
@@ -106,29 +106,31 @@ if [ -z "$APITESTPAYLOAD" ] ; then
|
||||
fi
|
||||
|
||||
# Source our resty functions
|
||||
#. ./utils/resty -W "https://45.32.222.81:12151" -H "Accept: application/json" -H "Content-Type: application/json" -u ${APITESTUSER}:${APITESTPASS}
|
||||
. ./utils/resty -W "https://127.0.0.1:12151" -H "Accept: application/json" -H "Content-Type: application/json" -u ${APITESTUSER}:${APITESTPASS}
|
||||
|
||||
# Save output to a file in addition to stdout
|
||||
#ofile="/tmp/api-response"
|
||||
#echo "" > /tmp/api-response
|
||||
ofile="/tmp/api-response"
|
||||
echo "" > /tmp/api-response
|
||||
|
||||
# Check the reply of this REST query
|
||||
#echo "" | tee -a $ofile
|
||||
#echo "REST Request:" | tee -a $ofile
|
||||
#echo "-------------------------------" | tee -a $ofile
|
||||
#echo "PUT /${namesp}/${name}" | tee -a $ofile
|
||||
#echo "${payload}" | perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"' | tee -a $ofile
|
||||
echo "" | tee -a $ofile
|
||||
echo "REST Request:" | tee -a $ofile
|
||||
echo "-------------------------------" | tee -a $ofile
|
||||
echo "PUT /${APITESTNAMESPACE}/${APITESTCLASS}" | tee -a $ofile
|
||||
echo "${APITESTPAYLOAD}" | perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"' | tee -a $ofile
|
||||
|
||||
echo "" | tee -a $ofile
|
||||
echo "REST Response:" | tee -a $ofile
|
||||
echo "-------------------------------" | tee -a $ofile
|
||||
PUT /${APITESTNAMESPACE}/${APITESTCLASS} "${APITESTPAYLOAD}" -v -k #2>/tmp/.rstErr | tee -a $ofile
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "Failed.. Error output:"
|
||||
cat /tmp/.rstErr
|
||||
fi
|
||||
rm $ofile
|
||||
rm /tmp/.rstErr
|
||||
exit 0;
|
||||
|
||||
#echo "" | tee -a $ofile
|
||||
#echo "REST Response:" | tee -a $ofile
|
||||
#echo "-------------------------------" | tee -a $ofile
|
||||
#PUT /${APITESTNAMESPACE}/${APITESTCLASS} "${APITESTPAYLOAD}" -v -k 2>/tmp/.rstErr | tee -a $ofile
|
||||
#if [ $? -ne 0 ] ; then
|
||||
# echo "Failed.. Error output:"
|
||||
# cat /tmp/.rstErr
|
||||
#fi
|
||||
#rm $ofile
|
||||
#rm /tmp/.rstErr
|
||||
|
||||
# Now check the response via WebSockets
|
||||
export NODE_TLS_REJECT_UNAUTHORIZED=0
|
||||
|
||||
Reference in New Issue
Block a user