a Jg&@sRdZdZdZddlZddlmZmZddlmZm Z m Z ee Z Gdd d Z dS) z!Cyril Jaquier, Yaroslav Halchenkoz:Copyright (c) 2004 Cyril Jaquier, 2013- Yaroslav HalchenkoZGPLN)UnknownJailExceptionDuplicateJailException) getLoggerlogging PREFER_ENCc@sheZdZeZejr&ejjdur&ejjZedkr6dndZ dddZ ddZ d d Z d d Z d dZdS) BeautifierNzutf-8rcCs ||_dSN_Beautifier__inputCmdselfcmdr>/usr/lib/python3.9/site-packages/fail2ban/client/beautifier.py__init__.szBeautifier.__init__cCs ||_dSr r r rrr setInputCmd1szBeautifier.setInputCmdcCs|jSr r )rrrr getInputCmd4szBeautifier.getInputCmdc sttddt|dt|j|j}|z|ddkrHd|n|ddkr\|n|ddkrpd n|dd krt|d kr|durd n |durd nz|ddkrd|nb|ddkrd|nJ|ddkrdn0|dd dgkrnddfdd }t|d krH|d dkrHd|d g||nd}t|d krn|d}|dd}dgt|D]n\}}|s|t|d krdnd}t|d trdt t |d n|d } d||d|fq||r` dd} | D]V\}} | d 7} | t|kr*dnd} d ||f|| | t|krVd!nd"qd#n|dd d$gks|dd d%gkrgd&gd'g} d(d)} |sWd*Sd#| || |j nLt|d+krn:|d d,krd-d.|7n|d d/kr*d0d.|7n|d d+d1gkrhd2tt|tr\t|n|7n|d d3kr|durd4nd5d.|7n|d d6kr|durd4nd7d8|7nTt|d9krސnB|d+d:vrkrZd?|7n|d+d@vrt|dkr|dAndBdCdDdE|D7n|d+dFkrdG|durˆdH7n,|ddurdI|d 7n dJ|7n.|d+dKvrPt|dkrdLn8dM|ddD]}d=|d#7q$d.|d7n|d+dNvrt|dkrrdOn\dPd}|ddD]*}dQt |dR|d#7|d 7}qdSt |dR|d7nN|d+dTkrt|dkrdU|d ndV|d dW|7n|d+dXkrpt|dkrLdY|d |d9fn"dZ|d |d9fdW|7n|d+d[krt|dkrd\|d |d9fn"d]|d |d9fdW|7nZ|d+d^kr |dd_kr t|tr t|d9krdn|d9}|d`krd#}||WnLtyntdatjdb||jttjkdctt|Yn0S)eNz Beautify z with rZpingzServer replied: versionstartz Jail startedstopr zShutdown successfulz Jail stoppedaddz Added jail Z flushlogszlogs: Zecho statusc st|D]\}}||t|dkr&dnd}d||df||t|dkrXdnd}t|dD]j\}}||t|ddkrdnd}t|dtrdtt|dn|d}d ||d|fqjqdS) Nr `-|-z%s %srz z| r %s %s: %s) enumeratelenappend isinstancelistjoinmapstr) responseZprefnres1prefix1mZres2Zprefix2valmsgrr jail_statQs *z&Beautifier.beautify..jail_statz--allzStatus for the jail: %sZStatusrrrz`- Status for the jails:z %s Jail: %sz z |  ZstatsZ statistics)|-r3xr5r4r3r4)u║u═u╟u╫u╬u╩u│u─c slgd}gd}gd}gd}dd|D}g}tt|dD].fdd |D}|t|t|qFg} g} tt|dD]8|rd nd } | | || | |q| d| d d | dd| dfd | dd| dfg} | d| d d | dd| dfd | dd| dfg} |d|d d|d|dd|d|dg} | d| d d | dfd | dfg} | dd}ddd| } ddd| } ddd| } ddd|}|t|ddddddddfdd| ddDd}g}|d| tddg|dd|d||d| t|d dd fdd| Dd }|d ||D]}|d| t|qd dd fdd| Dd }|d ||S)N)ZJailZBackendZFilterZActions)rrcurtotr6r7)r8r9r9r9)rrr r r r cSs,g|]$\}}||dg|d|dqS)rr rr).0r)rrrr {z._statstable..rc3s|]}tt|VqdSr )r!r')r:s)irr ~r=z;Beautifier.beautify.._statstable..z%%%dsz%%-%dsr z%s %s %srr9rrcsg|]}d|qS)rCrr:r)ctrrr<r=rcsg|]}d|qSr rrDrErrr<r=csg|]}d|qSrGrrDrErrr<r=)itemsranger!r"maxr%tuple)r(rFZtopheadZheadersZminlensZralignZrowsZlenscolZrfmtZhfmtfZtlensZtfmtZtsep separatorretrowr)rFr?r _statstablevsP@@4( &2&44z(Beautifier.beautify.._statstablezNo jails found.rZ syslogsocketzCurrent syslog socket is: z`- Z logtargetzCurrent logging target is: ZloglevelzCurrent logging level is ZdbfilezDatabase currently disabledzCurrent database file is: Z dbpurgeagezCurrent database purge age is: z `- %isecondsr9)ZlogpathZ addlogpathZ dellogpathzNo file is currently monitoredzCurrent monitored log file(s): z|- Z logencodingz Current log encoding is set to: )Z journalmatchZaddjournalmatchZdeljournalmatchzNo journal match filter setzCurrent match filter: z + css|]}d|VqdS)rN)r%)r:resrrrr@r=z&Beautifier.beautify..Z datepatternzCurrent date pattern set to: zNot set/requiredz%sz%s (%s))ZignoreipZ addignoreipZ delignoreipz No IP address/network is ignoredz)These IP addresses/networks are ignored: )Z failregexZ addfailregexZ delfailregexZ ignoreregexZaddignoreregexZdelignoreregexz No regular expression is definedz.The following regular expression are defined: z|- [z]: z`- [actionszNo actions for jail %sz'The jail %s has the following actions: z, Zactionpropertiesz#No properties for jail %s action %sz4The jail %s action %s has the following properties: Z actionmethodsz No methods for jail %s action %sz1The jail %s action %s has the following methods: Zbanipgetz --with-timez)Beautifier error. Please report the errorzBeautify %r with %r failed)exc_info)r)logSyslogreprr r!r%r r#r$r&r'r"rHencUtfintrZ getLevelName ExceptionZwarningerrorZgetEffectiveLevelDEBUG)rr(ZinCr0Zjstatr)r*r+r-r?jZchrTablerQpathipclseprr.rbeautify7s0               ,  (&&               zBeautifier.beautifycCsbtd||j|}t|tr2d|jdd}n,t|trBd}nt|tr^d|jdd}|S)NzBeautify (error) %r with %rzSorry but the jail 'rz' does not existz Sorry but the command is invalidz The jail 'z' already exists)rVdebugr r#rargs IndexErrorr)rr(r/rrr beautifyErrors   zBeautifier.beautifyError)N)__name__ __module__ __qualname__rZ stdoutEncsysstdoutencodinglowerrYrrrrdrhrrrrr's Qr) __author__Z __copyright__Z __license__rl exceptionsrrZhelpersrrrrirVrrrrrs