예제 #1
0
 def func_substr(self, *args):
     if len(args) != 3:
         log.warning("Warning: function substr takes exactly 3 arguments.")
         return
     start = args[0]
     end = args[1]
     var = args[2]
     return var[start:end]
예제 #2
0
    def func_diskspace(self, *args):
        """
        diskspace("/var") -> 125 (12.5% used)
        """
        if len(args) != 1:
            log.warning("Warning: function diskspace takes exactly 1 argument.")
            return
        mountpoint = args[0]

        fd = os.open(mountpoint, os.O_RDONLY)
        stats = os.fstatvfs(fd)
        os.close(fd)
        size = stats[1] * stats[2]
        free = stats[1] * stats[4]
        diskspace = 1000 * (size - free) / size
        return diskspace
예제 #3
0
파일: acl.py 프로젝트: OutOfOrder/sshproxy
    def load_rules(self):
        rulefile = get_config('acl_db.ini')['file']
        if not os.path.exists(rulefile):
            open(rulefile, 'w').close()
            os.chmod(rulefile, 0600)
            # no need to parse an empty file
            return None

        fd = open(rulefile)
        nline = []
        line = []
        for linepart in fd.readlines():
            if not linepart.strip() or linepart.strip()[0] == '#':
                continue

            if linepart[0] not in (' ', '\t'):
                nline = [ linepart.strip() ]
                if not line:
                    line = nline
                    continue
            else:
                line.append(linepart.strip())
                continue

            try:
                acl, rule = (' '.join(line)).split(':', 1)
                if rule is None or not rule.strip():
                    raise ValueError
            except ValueError:
                # drop rule, it won't parse anyway
                log.warning('Dropped unparseable rule %s' % acl)
                line = nline
                continue
            self.add_rule(acl=acl, rule=rule.lstrip())
            line = nline

        if line:
            try:
                acl, rule = (' '.join(line)).split(':', 1)
                if rule is None or not rule.strip():
                    raise ValueError
                self.add_rule(acl=acl, rule=rule.lstrip())
            except ValueError:
                # drop rule, it won't parse anyway
                log.warning('Dropped unparseable rule %s' % acl)
                pass
        fd.close()
예제 #4
0
    def load_rules(self):
        rulefile = get_config('acl_db.ini')['file']
        if not os.path.exists(rulefile):
            open(rulefile, 'w').close()
            os.chmod(rulefile, 0600)
            # no need to parse an empty file
            return None

        fd = open(rulefile)
        nline = []
        line = []
        for linepart in fd.readlines():
            if not linepart.strip() or linepart.strip()[0] == '#':
                continue

            if linepart[0] not in (' ', '\t'):
                nline = [linepart.strip()]
                if not line:
                    line = nline
                    continue
            else:
                line.append(linepart.strip())
                continue

            try:
                acl, rule = (' '.join(line)).split(':', 1)
                if rule is None or not rule.strip():
                    raise ValueError
            except ValueError:
                # drop rule, it won't parse anyway
                log.warning('Dropped unparseable rule %s' % acl)
                line = nline
                continue
            self.add_rule(acl=acl, rule=rule.lstrip())
            line = nline

        if line:
            try:
                acl, rule = (' '.join(line)).split(':', 1)
                if rule is None or not rule.strip():
                    raise ValueError
                self.add_rule(acl=acl, rule=rule.lstrip())
            except ValueError:
                # drop rule, it won't parse anyway
                log.warning('Dropped unparseable rule %s' % acl)
                pass
        fd.close()
예제 #5
0
 def func_len(self, *args):
     if len(args) != 1:
         log.warning("Warning: function len takes exactly 1 argument.")
         return
     return len(args[0])