mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
'iocage get all <jail>' properties in json
REST Request:
-------------------------------
PUT /sysadm/iocage
{
"jail" : "testjail",
"action" : "getjailsettings"
}
REST Response:
-------------------------------
{
"args": {
"getjailsettings": {
"testjail": {
"allow_chflags": "0",
"allow_mount": "0",
"allow_mount_devfs": "0",
"allow_mount_nullfs": "0",
"allow_mount_procfs": "0",
"allow_mount_tmpfs": "0",
"allow_mount_zfs": "0",
"allow_quotas": "0",
"allow_raw_sockets": "0",
"allow_set_hostname": "1",
"allow_socket_af": "0",
"allow_sysvipc": "0",
"boot": "off",
"bpf": "off",
"branch": "-",
"children_max": "0",
"coredumpsize": "off",
"count": "1",
"cpuset": "off",
"cputime": "off",
"datasize": "off",
"defaultrouter": "none",
"defaultrouter6": "none",
"devfs_ruleset": "4",
"dhcp": "off",
"enforce_statfs": "2",
"exec_clean": "1",
"exec_fib": "0",
"exec_jail_user": "root",
"exec_poststart": "/usr/bin/true",
"exec_poststop": "/usr/bin/true",
"exec_prestart": "/usr/bin/true",
"exec_prestop": "/usr/bin/true",
"exec_start": "/bin/sh /etc/rc",
"exec_stop": "/bin/sh /etc/rc.shutdown",
"exec_system_jail_user": "0",
"exec_system_user": "root",
"exec_timeout": "60",
"ftpdir": "-",
"ftpfiles": "-",
"ftphost": "-",
"ftplocaldir": "-",
"gitlocation": "https",
"hack88": "0",
"host_domainname": "none",
"host_hostname": "4bb3f929-c6bf-11e5-bbe9-fcaa14deb15d",
"host_hostuuid": "4bb3f929-c6bf-11e5-bbe9-fcaa14deb15d",
"hostid": "4145fbb8-c5b6-11e5-9f2f-fcaa14deb15d",
"interfaces": "vnet0",
"ip4": "new",
"ip4_addr": "none",
"ip4_autoend": "none",
"ip4_autostart": "none",
"ip4_autosubnet": "none",
"ip4_saddrsel": "1",
"ip6": "new",
"ip6_addr": "none",
"ip6_saddrsel": "1",
"istemplate": "no",
"jail_zfs": "off",
"jail_zfs_dataset": "iocage/jails/4ba5d76b-c6bf-11e5-bbe9-fcaa14deb15d/data",
"jail_zfs_mountpoint": "none",
"last_started": "none",
"login_flags": "-f root",
"maxproc": "off",
"memorylocked": "off",
"memoryuse": "8G",
"mount_devfs": "1",
"mount_fdescfs": "1",
"mount_linprocfs": "0",
"mount_procfs": "0",
"msgqqueued": "off",
"msgqsize": "off",
"nmsgq": "off",
"notes": "none",
"nsemop": "off",
"nshm": "off",
"nthr": "off",
"openfiles": "off",
"owner": "root",
"pcpu": "off",
"pkglist": "none",
"priority": "99",
"pseudoterminals": "off",
"release": "10.2-RELEASE",
"resolver": "none",
"rlimits": "off",
"securelevel": "2",
"shmsize": "off",
"stacksize": "off",
"start": "-",
"stop_timeout": "30",
"swapuse": "off",
"sync_stat": "-",
"sync_target": "none",
"sync_tgt_zpool": "none",
"tag": "testjail",
"template": "-",
"type": "basejail",
"vmemoryuse": "off",
"vnet": "off",
"vnet0_mac": "none",
"vnet1_mac": "none",
"vnet2_mac": "none",
"vnet3_mac": "none",
"wallclock": "off"
}
}
}
}
WebSocket Request:
-------------------------------
{
"args" : {
"jail" : "testjail",
"action" : "getjailsettings"
},
"id" : "fooid",
"name" : "iocage",
"namespace" : "sysadm"
}
WebSocket Response:
-------------------------------
{
"args": {
"getjailsettings": {
"testjail": {
"allow_chflags": "0",
"allow_mount": "0",
"allow_mount_devfs": "0",
"allow_mount_nullfs": "0",
"allow_mount_procfs": "0",
"allow_mount_tmpfs": "0",
"allow_mount_zfs": "0",
"allow_quotas": "0",
"allow_raw_sockets": "0",
"allow_set_hostname": "1",
"allow_socket_af": "0",
"allow_sysvipc": "0",
"boot": "off",
"bpf": "off",
"branch": "-",
"children_max": "0",
"coredumpsize": "off",
"count": "1",
"cpuset": "off",
"cputime": "off",
"datasize": "off",
"defaultrouter": "none",
"defaultrouter6": "none",
"devfs_ruleset": "4",
"dhcp": "off",
"enforce_statfs": "2",
"exec_clean": "1",
"exec_fib": "0",
"exec_jail_user": "root",
"exec_poststart": "/usr/bin/true",
"exec_poststop": "/usr/bin/true",
"exec_prestart": "/usr/bin/true",
"exec_prestop": "/usr/bin/true",
"exec_start": "/bin/sh /etc/rc",
"exec_stop": "/bin/sh /etc/rc.shutdown",
"exec_system_jail_user": "0",
"exec_system_user": "root",
"exec_timeout": "60",
"ftpdir": "-",
"ftpfiles": "-",
"ftphost": "-",
"ftplocaldir": "-",
"gitlocation": "https",
"hack88": "0",
"host_domainname": "none",
"host_hostname": "4bb3f929-c6bf-11e5-bbe9-fcaa14deb15d",
"host_hostuuid": "4bb3f929-c6bf-11e5-bbe9-fcaa14deb15d",
"hostid": "4145fbb8-c5b6-11e5-9f2f-fcaa14deb15d",
"interfaces": "vnet0",
"ip4": "new",
"ip4_addr": "none",
"ip4_autoend": "none",
"ip4_autostart": "none",
"ip4_autosubnet": "none",
"ip4_saddrsel": "1",
"ip6": "new",
"ip6_addr": "none",
"ip6_saddrsel": "1",
"istemplate": "no",
"jail_zfs": "off",
"jail_zfs_dataset": "iocage/jails/4ba5d76b-c6bf-11e5-bbe9-fcaa14deb15d/data",
"jail_zfs_mountpoint": "none",
"last_started": "none",
"login_flags": "-f root",
"maxproc": "off",
"memorylocked": "off",
"memoryuse": "8G",
"mount_devfs": "1",
"mount_fdescfs": "1",
"mount_linprocfs": "0",
"mount_procfs": "0",
"msgqqueued": "off",
"msgqsize": "off",
"nmsgq": "off",
"notes": "none",
"nsemop": "off",
"nshm": "off",
"nthr": "off",
"openfiles": "off",
"owner": "root",
"pcpu": "off",
"pkglist": "none",
"priority": "99",
"pseudoterminals": "off",
"release": "10.2-RELEASE",
"resolver": "none",
"rlimits": "off",
"securelevel": "2",
"shmsize": "off",
"stacksize": "off",
"start": "-",
"stop_timeout": "30",
"swapuse": "off",
"sync_stat": "-",
"sync_target": "none",
"sync_tgt_zpool": "none",
"tag": "testjail",
"template": "-",
"type": "basejail",
"vmemoryuse": "off",
"vnet": "off",
"vnet0_mac": "none",
"vnet1_mac": "none",
"vnet2_mac": "none",
"vnet3_mac": "none",
"wallclock": "off"
}
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
112 lines
2.8 KiB
Bash
Executable File
112 lines
2.8 KiB
Bash
Executable File
#!/usr/local/bin/bash
|
|
# (Yes, yes, this is a bash script)
|
|
# Both resty/jsawk use bash'isms
|
|
|
|
# Set variable to call jsawk utility
|
|
JSAWK="./utils/jsawk -j js24"
|
|
|
|
which npm >/dev/null 2>/dev/null
|
|
if [ $? -ne 0 ] ; then
|
|
pkg install -y npm
|
|
if [ $? -ne 0 ] ; then
|
|
echo "Requires npm!"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
pkg info p5-JSON >/dev/null 2>/dev/null
|
|
if [ $? -ne 0 ] ; then
|
|
pkg install -y p5-JSON
|
|
if [ $? -ne 0 ] ; then
|
|
echo "Requires p5-JSON!"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if [ ! -d "${HOME}/.npm/ws" ] ; then
|
|
npm install ws
|
|
if [ $? -ne 0 ] ; then
|
|
echo "Failed installing ws node module"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if [ ! -d "${HOME}/.npm/wss" ] ; then
|
|
npm install wss
|
|
if [ $? -ne 0 ] ; then
|
|
echo "Failed installing wss node module"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo "Enter your username:"
|
|
echo -e ">\c"
|
|
read fuser
|
|
echo ""
|
|
|
|
echo "Enter your password:"
|
|
echo -e ">\c"
|
|
read -s fpass
|
|
echo ""
|
|
|
|
echo "Enter the namespace:"
|
|
echo -e "(sysadm)>\c"
|
|
read namesp
|
|
if [ -z "$namesp" ] ; then
|
|
namesp="sysadm"
|
|
fi
|
|
echo ""
|
|
|
|
echo "Enter the class name:"
|
|
echo -e "(lifepreserver)>\c"
|
|
read name
|
|
if [ -z "$name" ] ; then
|
|
name="lifepreserver"
|
|
fi
|
|
echo ""
|
|
|
|
echo "Enter the payload json:"
|
|
echo -e "{ \"action\":\"listcron\" }>\c"
|
|
read payload
|
|
if [ -z "$payload" ] ; then
|
|
payload="{ \"action\":\"listcron\" }"
|
|
fi
|
|
echo ""
|
|
|
|
# Source our resty functions
|
|
. ./utils/resty -W "https://127.0.0.1:12151" -H "Accept: application/json" -H "Content-Type: application/json" -u ${fuser}:${fpass}
|
|
|
|
# Save output to a file in addition to stdout
|
|
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 Response:" | tee -a $ofile
|
|
echo "-------------------------------" | tee -a $ofile
|
|
PUT /${namesp}/${name} "${payload}" -v -k 2>/tmp/.rstErr | tee -a $ofile
|
|
if [ $? -ne 0 ] ; then
|
|
echo "Failed.. Error output:"
|
|
cat /tmp/.rstErr
|
|
fi
|
|
|
|
|
|
# Now check the response via WebSockets
|
|
export NODE_TLS_REJECT_UNAUTHORIZED=0
|
|
|
|
echo "" | tee -a $ofile
|
|
echo "WebSocket Request:" | tee -a $ofile
|
|
echo "-------------------------------" | tee -a $ofile
|
|
echo "{ \"namespace\":\"${namesp}\", \"name\":\"${name}\", \"id\":\"fooid\", \"args\":${payload} }" | perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"' | tee -a $ofile
|
|
|
|
echo "" | tee -a $ofile
|
|
echo "WebSocket Response:" | tee -a $ofile
|
|
echo "-------------------------------" | tee -a $ofile
|
|
echo "{ \"namespace\":\"${namesp}\", \"name\":\"${name}\", \"id\":\"fooid\", \"args\":${payload} }" | node sendwebsocket.js "$fuser" "$fpass" | tee -a $ofile
|