%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/engines/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/engines/ircbot.pyc

�
���^c@@sdZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
mZddlZ
ddlZ
ddlZeje�ZddlZddlmZedd�Zedd	�Zd
efd��YZddddeed
eeed�
ZdS(u
IRC Bot engine

.. versionadded:: 2017.7.0

Example Configuration

.. code-block:: yaml

    engines:
      - ircbot:
          nick: <nick>
          username: <username>
          password: <password>
          host: chat.freenode.net
          port: 7000
          channels:
            - salt-test
            - '##something'
          use_ssl: True
          use_sasl: True
          disable_query: True
          allow_hosts:
            - salt/engineer/.*
          allow_nicks:
            - gtmanfred

Available commands on irc are:

ping
    return pong

echo <stuff>
    return <stuff> targeted at the user who sent the commands

event <tag> [<extra>, <data>]
    fire event on the master or minion event stream with the tag `salt/engines/ircbot/<tag>` and a data object with a
    list of everything else sent in the message

Example of usage

.. code-block:: text

    08:33:57 @gtmanfred > !ping
    08:33:57   gtmanbot > gtmanfred: pong
    08:34:02 @gtmanfred > !echo ping
    08:34:02   gtmanbot > ping
    08:34:17 @gtmanfred > !event test/tag/ircbot irc is useful
    08:34:17   gtmanbot > gtmanfred: TaDa!

.. code-block:: text

    [DEBUG   ] Sending event: tag = salt/engines/ircbot/test/tag/ircbot; data = {'_stamp': '2016-11-28T14:34:16.633623', 'data': ['irc', 'is', 'useful']}

i(tabsolute_importtprint_functiontunicode_literalsN(t
namedtuple(tsixuEventusource code lineu	PrivEventu/source nick user host code channel command linet	IRCClientcB@s�eZddddeedeeed�
Zd�Zd�Zed��Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�ZRS(iu!c

C@s�||_||_||_|p$||_||_|p<g|_||_||_|	|_|
|_	||_
||_tj
jdt�|_|jj�|j�dS(Ntmake_current(tnickthosttporttusernametpasswordtchannelstssltsasltchartallow_hoststallow_nickst
disable_queryttornadotiolooptIOLooptFalsetio_loopRt_connect(
tselfRRR	R
RRtuse_ssltuse_saslRRRR((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyt__init__Us										
cC@s�tjtjtjd�}|jtkrRtjj|ditjd6�|_	ntjj
|�|_	|j	j|j�|j	j
|j|jf|j�dS(Nitssl_optionsu	cert_reqs(tsockettAF_INETtSOCK_STREAMR
tTrueRtiostreamtSSLIOStreamt	CERT_NONEt_streamtIOStreamtset_close_callbackt	on_closedtconnectRR	t
on_connect(Rt_sock((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyRgs(cC@s|jjd|j�dS(Nu
(R%t
read_untilt_message(R((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyt
read_messagespscC@satjd|�tjd|�}|jd�|jd�|jd�}}}t|||�S(NuReceived: %su;^(?:(?P<source>:[^ ]+) )?(?P<code>[^ ]+)(?: (?P<line>.*))?$usourceucodeuline(tlogtdebugtretmatchtgrouptEvent(tlinetsearchtsourcetcode((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyt_eventss/cC@sIt|jt�r|jStg|jD]}tj||�^q&�SdS(N(t
isinstanceRtbooltanyR1R2(RRR2((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyt_allow_hostzscC@sIt|jt�r|jStg|jD]}tj||�^q&�SdS(N(R:RR;R<R1R2(RRR2((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyt_allow_nick�sc

C@sXtjd|j�}|jd�|jd�|jd�}}}tjdj|j�|j�}|rT|jd�|jd�|jd�}}}|jtkr�|j	d	�r�dS||j
kr�|}nt|j||||j|||�}	|j
|�s|j|�rTt|d
j|��rTt|d
j|��|	�qTndS(Nu/^:(?P<nick>[^!]+)!(?P<user>[^@]+)@(?P<host>.*)$unickuuseruhostuB^(?P<channel>[^ ]+) :(?:{0}(?P<command>[^ ]+)(?: (?P<line>.*))?)?$uchannelucommandulineu#u_command_{0}(R1R2R7R3tformatRR5RR!t
startswithRt	PrivEventR8R>R=thasattrtgetattr(
RteventR6RtuserRtchanneltcommandR5t	privevent((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyt_privmsg�s/!/	'6cC@s)dj|j|j�}|j|�dS(NuPRIVMSG {0} :{1}(R?RFR5tsend_message(RRDtmessage((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyt
_command_echo�scC@s)dj|j|j�}|j|�dS(NuPRIVMSG {0} :{1}: pong(R?RFRRJ(RRDRK((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyt
_command_ping�sc@s�tjd�dkr7tjjjttd�j�nd��fd�}|jj	d�}|d}t
|�dkr�i|dd6}n
igd6}|d	||�d
j|j|j
�}|j|�dS(Nu__roleumasterusock_dirc@s+�r�||�ntd||�dS(u/
            How to fire the event
            u
event.sendN(t__salt__(ttagtmsg(tfire_master(s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pytfire�su iiudatausalt/engines/ircbot/uPRIVMSG {0} :{1}: TaDa!(t__opts__tgettsalttutilsRDtget_master_eventt
fire_eventtNoneR5tsplittlenR?RFRRJ(RRDRRtargsROtpayloadRK((RQs7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyt_command_event�s"	

cC@s�|jd�jd�}|j|�}|jdkrdtjjj�j|j	dj
|j��n1|jdkr�tjjj�j|j|�n|j
�dS(Ns
uutf-8uPINGuPONG {0}uPRIVMSG(trstriptdecodeR9R8RRRtcurrenttspawn_callbackRJR?R5RIR.(RtrawRD((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyR-�s."cC@s6|jd�sd|}n|jdj|��dS(Nu#uJOIN {0}(R@RJR?(RRF((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pytjoin_channel�s
cC@stjd�|jtkr,|jd�n|jdj|j��|jd�|jr�|jtkr�tj	dj|j
|j�j��}|jd�|jdj|��|jd�q�|jd	j|j
|j��nx|jD]}|j
|�q�W|j�dS(
Nu
on_connectu
CAP REQ :sasluNICK {0}uUSER saltstack 0 * :saltstacku{0}{0}{1}uAUTHENTICATE PLAINuAUTHENTICATE {0}uCAP ENDu"PRIVMSG NickServ :IDENTIFY {0} {1}(tloggingtinfoRR!RJR?RRtbase64t	b64encodeR
tencodeRRdR.(Rt
authstringRF((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyR*�s

	'
"cC@stjd�dS(Nu	on_closed(ReRf(R((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyR(�scC@sLt|tj�r$|jd�}ntjd|�|jj|d�dS(Nuutf-8uSending:  %ss
(R:Rtstring_typesRiR/R0R%twrite(RR5((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyRJ�sN(t__name__t
__module__RYRR!RRR.tstaticmethodR9R=R>RIRLRMR^R-RdR*R(RJ(((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyRTs 										
			iu!c
C@sDt||||||pg||||	|
|�}|jj�dS(uo
    IRC Bot for interacting with salt.

    nick
        Nickname of the connected Bot.

    host
        irc server (example - chat.freenode.net).

    port
        irc port.  Default: 6667

    password
        password for authenticating.  If not provided, user will not authenticate on the irc server.

    channels
        channels to join.

    use_ssl
        connect to server using ssl. Default: False

    use_sasl
        authenticate using sasl, instead of messaging NickServ. Default: False

        .. note:: This will allow the bot user to be fully authenticated before joining any channels

    char
        command character to look for. Default: !

    allow_hosts
        hostmasks allowed to use commands on the bot.  Default: False
        True to allow all
        False to allow none
        List of regexes to allow matching

    allow_nicks
        Nicks that are allowed to use commands on the bot.  Default: False
        True to allow all
        False to allow none
        List of regexes to allow matching

    disable_query
        Disable commands from being sent through private queries.  Require they be sent to a channel, so that all
        communication can be controlled by access to the channel. Default: True

    .. warning:: Unauthenticated Access to event stream

        This engine sends events calls to the event stream without authenticating them in salt.  Authentication will
        need to be configured and enforced on the irc server or enforced in the irc channel.  The engine only accepts
        commands from channels, so non authenticated users could be banned or quieted in the channel.

        /mode +q $~a  # quiet all users who are not authenticated
        /mode +r      # do not allow unauthenticated users into the channel

        It would also be possible to add a password to the irc channel, or only allow invited users to join.
    N(RRtstart(
RRR	R
RRRRRRRRtclient((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyRp�s:$(t__doc__t
__future__RRRRgReR1RR
tcollectionsRttornado.ioloopRttornado.iostreamt	getLoggerRmR/tsalt.utils.eventRUtsalt.extRR4RAtobjectRRYRR!Rp(((s7/usr/lib/python2.7/site-packages/salt/engines/ircbot.pyt<module>8s$�

Zerion Mini Shell 1.0