Al-HUWAITI Shell
Al-huwaiti


Server : LiteSpeed
System : Linux in-mum-web1112.main-hosting.eu 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User : u451330669 ( 451330669)
PHP Version : 8.2.27
Disable Function : NONE
Directory :  /opt/alt/python27/bin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/alt/python27/bin/postomaat_conf
#!/opt/alt/python27/bin/python
# -*- coding: utf-8 -*-
#   Copyright 2012-2018 Oli Schacher
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This tool is used to analyze/export the current configuration



# postomaat_conf -a
# print out a table
# section option default value , your value , flags (deprecated, confidential, ...), description


# postomaat_conf -n
# show all non-default values, auto-strip confidential stuff

from optparse import OptionParser
import sys
import os
try:
    import ConfigParser
except ImportError:
    import configparser as ConfigParser
from io import StringIO
import logging

def stderr(msg):
    sys.stderr.write(msg)


def print_config(config):
    for sec in config.sections():
        print("")
        print("[%s]"%sec)
        for op,val in config.items(sec):
            print("%s=%s"%(op,val))

def cloneConfig(config):
    tmpfile=StringIO()
    config.write(tmpfile)
    theClone=ConfigParser.ConfigParser()
    tmpfile.seek(0)
    theClone.readfp(tmpfile)
    return theClone


def config_equals(default,actual):
    """return true if default and actual mean the same thing, eg. """
    default=default.strip().lower()
    actual=actual.strip().lower()
    #we use '1' because 1 could be a numeric config as well which would be 
    #destroyed
    if default in ['yes','1','true','on']:
        default='1'
        
    if actual in ['yes','1','true','on']:
        actual='1'
    
    #path names, strip trailing slashes
    if len(default)>1 and default.endswith('/'):
        default=default[:-1]
    if len(actual)>1 and actual.endswith('/'):
        actual=actual[:-1]
    
    
    if default==actual:
        return True
    
    return False
    
    
def print_overrides(defaultconfig,userconfig,controller):
    for sec in defaultconfig.sections():
        have_printed_section=False
        for opt,defaultval in defaultconfig.items(sec):
            if userconfig.has_option(sec,opt):
                userval=userconfig.get(sec,opt)
                if not config_equals(defaultval,userval):
                    if not have_printed_section:
                        print("")
                        print("[%s]"%sec)
                        have_printed_section=True
                    
                    pdef=defaultval
                    if defaultval.strip()=='':
                        pdef='empty'
                    MAXCHARS=15
                    if len(pdef)>MAXCHARS:
                        pdef=pdef[:MAXCHARS-3]+"..."    
                    
                    pval=userval
                    #check if confidential
                    meta=get_config_meta(controller,sec,opt)
                    if pval.strip()!='' and meta!=None and 'confidential' in meta and meta['confidential']:
                        pval="***REDACTED***"
                    
                    print("%s=%s (def: %s)"%(opt,pval,pdef))


def make_config(controller,onlysection=None):
    config=controller.config
    for sec in config.sections():
        if onlysection!=None and sec!=onlysection:
            continue
        print("\n[%s]"%sec)
        for opt,val in config.items(sec):
            #print sec,opt
            meta=get_config_meta(controller,sec,opt)
            #print meta

            if meta!=None and 'description' in meta:
                desc='\n#'.join(meta['description'].split('\n'))
                print('\n#%s'%desc)
            
            print("%s=%s"%(opt,val))
    


def get_config_meta(controller,section,option):
    """retrieve config metadata from loaded controller/plugin instances"""
    allobjects=[]
    #core config
    allobjects.append(controller)
    #plugins
    allobjects.extend(controller.plugins)
    
    for obj in allobjects:
        if hasattr(obj,'requiredvars'):
            reqvars=getattr(obj,'requiredvars')
            if type(reqvars)==dict:
                if option in reqvars:
                    infodic=reqvars[option]            
                    clone=infodic.copy()
                    if 'section' not in clone and hasattr(obj,'section'):
                        clone['section']=getattr(obj,'section')
                    return clone


if __name__=='__main__':
    logging.basicConfig(level=logging.ERROR)
    optionparser=OptionParser()
    optionparser.add_option("-n",dest="notdefaults",action="store_true",default=False,help="print out values that differ from the default (use this for questions on the mailing lists)")
    optionparser.add_option("-m",dest="make",help="make default config (args: plugin or 'all')")
    optionparser.add_option("-b",dest="basedir",help="try importing the postomaat codebase from this directory instead of the system default")
    optionparser.add_option("-c",dest="configdir",default="/etc/postomaat",help="directory that contains postomaat.conf and optionally the conf.d subdirectory")
    (options,pargs) = optionparser.parse_args()
    
    if options.basedir:
        if os.path.exists(options.basedir+"/postomaat/core.py"):
            sys.path.insert(0, options.basedir)
        else:
            stderr("%s doesn't contain postomaat source"%options.basedir)
            sys.exit(1)

    confdir=options.configdir
    if confdir.endswith('/'):
        confidir=confdir[:-1]
    dconfdir=confdir+"/conf.d"
    
    postomaatconfigfile=confdir+"/postomaat.conf"
    userconfig=ConfigParser.ConfigParser()
    if not os.path.exists(postomaatconfigfile):
        stderr("""Configfile (%s) not found. """%postomaatconfigfile)
        sys.exit(1)
    readconfig=userconfig.readfp(open(postomaatconfigfile))
    #load conf.d
    if os.path.isdir(dconfdir):
        filelist=os.listdir(dconfdir)
        configfiles=[dconfdir+'/'+c for c in filelist if c.endswith('.conf')]
        readfiles=userconfig.read(configfiles)
        
    from postomaat.core import MainController
    defaultconfig=ConfigParser.ConfigParser()
    
    #copy plugindir, pluginalias and active plugins from current config
    defaultconfig.add_section("main")
    for sec,op in [('main','plugindir'),('main','plugins'),('main','prependers'),('main','appenders')]:
        if not defaultconfig.has_section(sec):
            defaultconfig.add_section(sec)
        if userconfig.has_option(sec, op):
            defaultconfig.set(sec,op, userconfig.get(sec,op))
    
    if userconfig.has_section('PluginAlias'):
        if not defaultconfig.has_section('PluginAlias'):
            defaultconfig.add_section('PluginAlias')
            
        for op,val in userconfig.items('PluginAlias'):
            defaultconfig.set('PluginAlias',op,val)
    
    if options.make and options.make.lower()!='all':
        defaultconfig.set('main', 'plugins', options.make)
    
    #load default values from plugins
    defcontroller=MainController(defaultconfig)
    defcontroller.propagate_core_defaults()
    defcontroller.load_plugins()
    
    #load active values
    activeconfig=cloneConfig(userconfig)
    activecontroller=MainController(activeconfig)
    activecontroller.propagate_core_defaults()
    activecontroller.load_plugins()
    
    
    if options.notdefaults:
        print_overrides(defaultconfig,userconfig,activecontroller)
    elif options.make:
        sec=None
        if options.make.lower()!='all':
            if len(defcontroller.plugins)==0:
                stderr("could not load plugin '%s'\n"%options.make)
                sys.exit(1)
            sec=defcontroller.plugins[0].section
        make_config(defcontroller,sec)
    else:
        print_config(activeconfig)

Al-HUWAITI Shell