PNG  IHDR  8] PLTE S =tRNS   PNG  IHDR  8] PLTE S =tRNS   REDROOM
PHP 7.4.33
Preview: postomaat_conf Size: 7.84 KB
/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)

Directory Contents

Dirs: 0 × Files: 16

Name Size Perms Modified Actions
242 B lrwxr-xr-x 2024-10-10 13:18:22
Edit Download
242 B lrwxr-xr-x 2024-10-10 13:18:22
Edit Download
233 B lrwxr-xr-x 2024-10-10 13:18:22
Edit Download
233 B lrwxr-xr-x 2024-10-10 13:18:22
Edit Download
233 B lrwxr-xr-x 2024-10-10 13:18:22
Edit Download
233 B lrwxr-xr-x 2024-10-10 13:18:22
Edit Download
233 B lrwxr-xr-x 2024-10-10 13:18:22
Edit Download
404 B lrwxr-xr-x 2026-08-17 08:39:38
Edit Download
7.84 KB lrwxr-xr-x 2026-08-17 08:39:38
Edit Download
91 B lrwxr-xr-x 2025-01-08 10:53:47
Edit Download
15.27 KB lrwxr-xr-x 2025-01-08 10:54:13
Edit Download
1.82 KB lrwxr-xr-x 2025-01-08 10:53:47
Edit Download
15.27 KB lrwxr-xr-x 2025-01-08 10:54:13
Edit Download
1.82 KB lrwxr-xr-x 2025-01-08 10:53:47
Edit Download
15.27 KB lrwxr-xr-x 2025-01-08 10:54:13
Edit Download
1.82 KB lrwxr-xr-x 2025-01-08 10:53:47
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).
 !"#$%&'(()*+,-./00123456789 t\ wIDATx ]ys  47Y ƒ -  "  Rv  < f{Ɛ $k l L > L  ~h^ 1  [  r G t& h  l F z3O Y ! p A(_g̷ E8 )S 8 c  Kb"z ~ 5 J xAL WU <  *  5 m;W a pB h ~P J 2 3 6 ҙ .Ƹ P i  4g F R L P ΪK/D  M v (a3 k J Œ4N5* SH ` SdJ z  O J Xՠ V>u ߱ BE&L b2 ?2` tX+  c CB A$ i b C ĀMB E : /  # Dx &l =q Ty  0 \p I ( L Ǎ { e 4k ;`u^ヲ eP!( d {  )T A 8 O;Ě n >;s6 !  :Nx `[S D HU ~ q›J F} a g*D 49 / pn k h (t 8NxƐF _!r չ7 ZR R׷ q/5") Ӎ NY 0 x sZ!   o  fu  ,  K"$ ? pg  㕣=  1» {h " fh7    y  } € +7  $ y " X —ą - G P u 4 m >J 5 L =V ' ^@I p ?MS xЌ XV P ! h "C NS9B8̢ ]!K  e   zA , ӏkbY  !< XQ ٿyS| *" f { w  4@[S <  # 0 ! js [m  =,~ o "ݎ DHf Wo $ g ! Vԅ t mB /y Wf V4񺍸 c+@x?  B ~u " xUN e 0 BĂ) ~J pz! 7y6]l Ԥ@ P a< O /DHC `≻  N m"$  0ObB }{ x AO FCG D R ^ "B  { WDH  UR l@ T #  +"d T ; 0 i  D}. 7 ` ' ] w rE &S i ƕiTD EL P _ u h $ Ա FG wVD G L R Zf ' .!] J /ZR oGЍs Mr Ĥ ʬ 3 Q [3 cL ` ^ p + ( F;# B 5 '  2Y f [  ϶R0e }  E 7 6M aۮ H <& n % L] E}Up x紉, Uw' Q  Ǯշo k ވۙ 0N94 VX5 xEDE l D #֤ } C o )W :  ^ s 9  bRf iX5u ཱི 4 :[  T 1. | [E 2ؽ Iy\ : o x K G 5 ylP ' uK E ftb/i[3 .g _  [3M n G, #NwQ5~  ؚ) | n =Ц"x qg gB ` 듘 ~ x w ? ? R~  _ u. &VQ K˻   H C ( TN˄+ `C dA nB׭ D 3"Z G ê ^k H_ /- ~ " R_  .8 Z_ 6@ o  xg  uP ? 3լ @7AM!  E7^ - =V L  x  g-D0  CtmW 7  O  G _ WD0 g C  w1 r d w : a | \  *" f nֳ ^ H# f L ` Z ۽hV  }S F r0Ù Bć5r] @! NL iQ]{s^=4 d  WD  "  "   M; t" 8 5 e dL| "-*st" ) SWD ?R[S e ooF  20.D ? bo =) A i o d ģ ZҰaO @E =) i D a &ܟa CϞ y6 ,<%{^x%{f8? `iw^ ?/ M * IEND B`