AnonSec Shell
Server IP : 92.204.138.22  /  Your IP : 18.227.102.127
Web Server : Apache
System : Linux ns1009439.ip-92-204-138.us 4.18.0-553.8.1.el8_10.x86_64 #1 SMP Tue Jul 2 07:26:33 EDT 2024 x86_64
User : internationaljou ( 1019)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/internationaljou/public_html/admin/js/BROKY_ADMIN/alfasymlink/root/lib/panopta-agent/plugins/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/internationaljou/public_html/admin/js/BROKY_ADMIN/alfasymlink/root/lib/panopta-agent/plugins/file_presence.py
import logging
import agent_util
import glob
import os
import datetime
import re
import time
import sys
from agent_util import float


class FilePresencePlugin(agent_util.Plugin):
    textkey = "files"
    label = "Filesystem"
    # this is here because it's used in 2 different places
    newer_than_regex = re.compile(r"(?P<op>(a|c|m)time)<(?P<delta>\d+)(?P<metric>d|h|m|s)")

    @classmethod
    def get_metadata(self, config):
        data = {
            "file.exists": {
                "label": "File exists",
                "options": None,
                "status": agent_util.SUPPORTED,
                "error_message": None,
                "unit": "boolean",
                "option_string": True
            },
            "file.count": {
                "label": "File count",
                "options": None,
                "status": agent_util.SUPPORTED,
                "error_message": None,
                "unit": "files",
                "option_string": True
            },
            "file.created": {
                "label": "Creation age",
                "options": None,
                "status": agent_util.SUPPORTED,
                "error_message": None,
                "unit": "minutes",
                "option_string": True
            },
            "file.modified": {
                "label": "Modification age",
                "options": None,
                "status": agent_util.SUPPORTED,
                "error_message": None,
                "unit": "minutes",
                "option_string": True
            },
            "directory.size": {
                "label": "Directory size (KB)",
                "options": None,
                "status": agent_util.SUPPORTED,
                "error_message": None,
                "unit": "kilobytes",
                "option_string": True
            },
            "file.size": {
                "label": "File size (KB)",
                "options": None,
                "status": agent_util.SUPPORTED,
                "error_message": None,
                "unit": "kilobytes",
                "option_string": True
            }
        }
        return data


    def check(self, textkey, path, config):
        path = path.strip()

        for date in re.findall("\$.[^$]+", path):
            date_format = date \
                            .replace("YYYY", "%Y") \
                            .replace("YY", "%y") \
                            .replace("MM", "%m") \
                            .replace("DD", "%d") \
                            .replace("D", "%w") \
                            .replace("ww", "%W") \
                            .replace("hh", "%H") \
                            .replace("mm", "%M") \
                            .replace("ss", "%S") \
                            .replace("Z", "%z") \
                            .replace("$", "") \
                            .strip()
            date_string = datetime.datetime.now().strftime(date_format)
            path = path.replace(date, date_string)

        self.log.debug("File path for file_presence plugin: %s" % path)

        if textkey == "file.exists":
            glob_results = glob.glob(path)
            has_results = len(glob_results) > 0
            return_val = has_results
            self.log.debug("Return value for file.exists textkey: %s" % str(return_val))
            return return_val
        elif textkey == "file.count":
            if os.path.isdir(path):
                glob_results = glob.glob(path+"/*")
                return_val = len(glob_results) 
                self.log.debug("Return value for file.count textkey: %s" % str(return_val))
            else:
                glob_results = glob.glob(path)
                return_val = len(glob_results) 
                self.log.debug("Return value for file.count textkey: %s" % str(return_val))
            return return_val
        elif textkey == "file.created":
            if not os.path.exists(path): return 0.0
            age = time.time() - os.path.getctime(path)
            return_val = float(age) / 60.0
            self.log.debug("Return value for file.created textkey: %s" % str(return_val))
            return return_val
        elif textkey == "file.modified":
            if not os.path.exists(path): return 0.0
            age = time.time() - os.path.getmtime(path)
            return_val = float(age) / 60.0
            self.log.debug("Return value for file.modified textkey: %s" % str(return_val))
            return return_val
        elif textkey == "file.size":
            if not os.path.exists(path): return 0.0
            return_val = float(os.path.getsize(path)) / 1024.0
            self.log.debug("Return value for file.size textkey: %s" % str(return_val))
            return return_val
        elif textkey == "directory.size":
            if not os.path.exists(path): return 0.0
            ret, output = agent_util.execute_command('du -sk ' + path)
            return_val =float(output.split()[0])
            self.log.debug("Return value for file.size textkey: %s" % str(return_val))
            return return_val

Anon7 - 2022
AnonSec Team