HEX
Server: LiteSpeed
System: Linux pl-rocket-da1.hostsila.org 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: etorby24eu (1588)
PHP: 8.3.23
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //opt/node_api/node_api.py.copy
#!/usr/bin/python
import os
import re
import json
from flask import request, url_for, abort
from flask_api import FlaskAPI, status, exceptions

app = FlaskAPI(__name__)

@app.before_request
def limit_remote_addr():
        if request.remote_addr not in ( '77.222.144.118', '194.28.84.9', '91.223.223.89', '176.241.143.3', '79.143.42.245', '185.67.1.84', '91.223.223.7', '178.74.235.62'):
                    abort(403)  # Forbidden

notes = {
    "/zfs/zpool_get_health": 'Determining the Health Status of ZFS Storage Pools',
    "/zfs/zpool_status": 'Detailed Health Status',
    "/info/smart_tlw":   'Total_LBAs_Written',
    "/info/virsh_info":  'virsh info',
    "/metrics": 'Prometheus metrics',
    "/info/drive_info": 'wearout and errors info'
}

hostname = os.popen("hostname").read()
hostname = hostname.replace("\n", "") 

@app.route("/")
def default():
	return notes

@app.route("/zfs/zpool_get_health", methods=['GET'])
def zpool_get_health():
	output = os.popen("zpool get health").read()
	output = re.sub('[\n\t ]+', ' ', output)
	arr =  output.split(" ")
	i = 0 
	data={}
	for var in arr:
	    data[var] = arr[i+4]
	    i += 1
	    if i >= 4:
	       break
	data["hostname"] = hostname
	return json.dumps(data, ensure_ascii=False,sort_keys=True)

@app.route("/zfs/zpool_status", methods=['GET'])
def zpool_status():
        zpool_status = os.popen("zpool status").read()
	return {"hostname": ""+ hostname +"", "zpool_status": ""+ zpool_status +""}

@app.route("/info/smart_tlw", methods=['GET'])
def smart_tlw():
	return os.popen("/opt/node_api/drvinfo.hook").read()

@app.route("/info/virsh_info", methods=['GET'])
def virsh_info():
        return os.popen("/opt/node_api/virsh_info.hook").read()

@app.route("/metrics", methods=['GET'])
def metrics():
        return os.popen("/opt/node_api/metrics.hook").read()

@app.route("/info/drive_info", methods=['GET'])
def wearout():
        return os.popen("/opt/node_api/wearout.hook").read()

@app.route("/info/backup", methods=['GET'])
def backup():
    stream = os.popen("mount | grep /backup | awk {'print$1'}")
    output = stream.readlines()
    if output:
        stream = os.popen('df -h | grep ' + output[0].rstrip() + ' | awk {\'print$5\'}')
        output = stream.readlines()
        return output[0].rstrip().replace('%', '')

@app.route("/info/backup_local", methods=['GET'])
def backup_local():
            return os.popen("/opt/node_api/backup.hook_shared.v2").read()

if __name__ == "__main__":
    app.run(debug=True,host='0.0.0.0')