HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //usr/lib/python2.7/site-packages/lap/weatherman.py
import json
import netifaces
import os
import psutil
import socket
import sys
import time
import xmpp

socket.setdefaulttimeout(10)

def check_log(message, logfile, logseek):
    f = file(logfile)
    f.seek(logseek)
    for line in f.readlines():
        if message in line:
            return True
    return False

def check_ha(iface):
    try:
        netifaces.ifaddresses(iface)
        return True
    except Exception, e:
        return False

def check_process():
    for name in psutil.get_pid_list():
        p = psutil.Process(name).cmdline
        if "weatherman" in p:
            return True
    return False

def __run__(params):
    iface = params.get("iface")
    if check_ha(iface):
        if check_process():
            jid_to = params.get("jid_to")
            logfile = params.get("logfile")

            start = time.time()
            jid = xmpp.protocol.JID(params.get("jid_from"))
            cl = xmpp.Client(jid.getDomain(),debug=[])
            logseek = os.stat(logfile).st_size

            if not cl.connect():
                return [2, "Could not connect to xmpp server"]

            if not cl.auth(jid.getNode(), params.get("jid_password"), resource=jid.getResource()):
                return [2, "Could not authenticate on xmpp server"]

            message = json.dumps({"timestamp": int(time.time()), "name": params.get("jid_data"), "value": 88.8})

            if not cl.send(xmpp.protocol.Message(jid_to, message)):
                return [2, "Could not send message to: %s" % jid_to]

            cl.disconnect()
            time.sleep(1.0)

            if not check_log(message, logfile, logseek=logseek):
                return [2, "Message not received on weatherman"]

            total = time.time() - start
            return[0, "OK - Total runtime: %.2f" % total]
        else:
            return[2, "Weatherman not running"]
    else:
        return[0, "OK"]