This file is indexed.

/usr/lib/python2.7/dist-packages/gplugs/eventnet.py is in gozerbot 0.99.1-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# gozerplugs/eventnet.py
#
#

## gozerbot imports

from gozerbot.callbacks import callbacks, jcallbacks
from gozerbot.utils.url import posturl, getpostdata
from gozerbot.persist.persist import PlugPersist
from gozerbot.commands import cmnds
from gozerbot.irc.monitor import outmonitor
from gozerbot.persist.persistconfig import PersistConfig
from gozerbot.rest.server import RestServer, RestRequestHandler
from gozerbot.eventbase import EventBase
from gozerbot.utils.exception import handle_exception
from gozerbot.utils.log import rlog
from gozerbot.utils.textutils import html_unescape

## simplejson imports

from simplejson import dumps

## basic imports

import socket
import re

## VARS

outurl = "http://cmndtest.appspot.com/eventnet/"

state = PlugPersist('eventnet')

if not state.data:
    state.data = {}
if not state.data.has_key('relay'):
    state.data['relay'] = []

cfg = PersistConfig()
cfg.define('enable', 0)
cfg.define('host' , socket.gethostbyname(socket.getfqdn()))
cfg.define('name' , socket.getfqdn())
cfg.define('port' , 10102)
cfg.define('disable', [])

waitre = re.compile(' wait (\d+)', re.I)
hp = "%s:%s" % (cfg.get('host'), cfg.get('port'))
url = "http://%s" % hp

## callbacks

def preremote(bot, event):

    if event.channel in state.data['relay']:
        return True

def handle_doremote(bot, event):

    if event.isremote:
        return

    posturl(outurl, {}, {'event': event.tojson() })

callbacks.add('PRIVMSG', handle_doremote, preremote, threaded=True)
outmonitor.add('eventnet', handle_doremote, preremote, threaded=True)

def handle_jabberin(bot, event):

    if event.isremote or not event.txt:
        return

    try:
        if event.txt.startswith('{'):
            e = EventBase()
            e.fromjsonstring(event.txt)
            e.isremote = True
            rlog(10, bot.name, 'got event on jabberin: %s - %s ' % (e.userhost, str(e)))
            callbacks.check(bot, e)
    except Exception, ex:
        handle_exception()
        print event.txt
        return
    
jcallbacks.add('Message', handle_jabberin)

## server part

server = None

def eventnet_POST(server, request):

    try:
        input = getpostdata(request)
        eventin = input['event']
    except KeyError, AttributeError:
        rlog(10, 'eventnet', "can't determine eventin")
        return dumps(["can't determine eventin"])

    event = EventBase()
    event.fromjsonstring(eventin)
    callbacks.check(event)
    return dumps(['ok',])

def eventnet_GET(server, request):
    try:
        path, eventin = request.path.split('#', 1)
    except ValueError:
        rlog(10, 'eventnet', "can't determine eventin")
        return dumps(["can't determine eventin", ])

    try:
        event = EventBase()
        event.fromjsonstring(eventin)
        callbacks.check(event)
    except Exception, ex:
        handle_exception()
    return dumps(['ok', ])

def startserver():

    global server 

    try:
        rlog(10, 'eventnet', 'starting server at %s:%s' % (cfg.get('host'), cfg.get('port')))
        server = RestServer((cfg.get('host'), cfg.get('port')), RestRequestHandler)

        if server:
            server.start()
            rlog(10, 'eventnet', 'running at %s:%s' % (cfg.get('host'), cfg.get('port')))
            server.addhandler('/eventnet/', 'POST', eventnet_POST)
            server.addhandler('/eventnet/', 'GET', eventnet_GET)

            for mount in cfg.get('disable'):
                server.disable(mount)

        else:
            rlog(10, 'eventnet', 'failed to start server at %s:%s' % (cfg.get('host'), cfg.get('port')))

    except socket.error, ex:
        rlog(10, 'eventnet - server', str(ex))

    except Exception, ex:
        handle_exception()

def stopserver():

    try:
        if not server:
            rlog(10, 'eventnet', 'server is already stopped')
            return

        server.shutdown()

    except Exception, ex:
        handle_exception()
        pass

## plugin init

def init():

    if cfg['enable']:
        startserver()

def shutdown():

    if cfg['enable']:
        stopserver()

def handle_eventnet_on(bot, event):

    if not event.rest:
        target = event.channel
    else:
        target = event.rest

    if not target in state.data['relay']:
        state.data['relay'].append(target)
        state.save()

    event.done()

cmnds.add('eventnet-on', handle_eventnet_on, 'OPER')

def handle_eventnet_off(bot, event):

    if not event.rest:
        target = event.channel
    else:
        target = event.rest

    if target in state.data['relay']:
        state.data['relay'].remove(target)
        state.save()
    event.done()

cmnds.add('eventnet-off', handle_eventnet_off, 'OPER')

def handle_eventnet_startserver(bot, event):
    cfg['enable'] = 1
    cfg.save()
    startserver()
    event.done()

cmnds.add('eventnet-startserver', handle_eventnet_startserver, 'OPER')

def handle_eventnet_stopserver(bot, event):
    cfg['enable'] = 0
    cfg.save()
    stopserver()
    event.done()

cmnds.add('eventnet-stopserver', handle_eventnet_stopserver, 'OPER')