示例#1
0
 def purple_handle_acct_connection(self, obj, proto):
     """This will handle account events coming from purple.."""
     evt = obj.evt
     log_info(evt)
     acct_id = evt.objid
     if evt.event in (yobotproto.YOBOT_EVENT_AUTH_FAIL,
                      yobotproto.YOBOT_EVENT_LOGIN_ERR,
                      yobotproto.YOBOT_EVENT_DISCONNECTED):
         #find account and trigger its errback:
         try:
             acct, _ = self.accounts.byId(acct_id)
         except TypeError:
             log_err("account does not exist (anymore)")
             return            
         try:
             acct.timeoutCb.cancel()
         except Exception, e:
             log_warn(e)
         
         #relay the segment now because the client/account lookup will be
         #broken after the account has been deleted:
         self._relay_segment(obj, acct_id)
         try:
             if not evt.event == yobotproto.YOBOT_EVENT_DISCONNECTED:
                 acct.connectedCb.errback(AccountRemoved("Login Failed"))
             else:
                 acct.connectedCb.errback(AccountRemoved("Disconnected"))
         except defer.AlreadyCalledError, e:
             log_err(e)
示例#2
0
 def fill_from(self, account_dict):
     w = self.widgets
     w.username.setText(account_dict.get("name", ""))
     w.password.setText(account_dict.get("password", ""))
     
     #get protocol constant
     improto_constant = getattr(yobotproto, str(account_dict.get("improto")))
     log_debug("improto_constant", improto_constant)
     #find it in the combobox
     i = w.improto.findData(QVariant(improto_constant))
     if i >= 0:
         w.improto.setCurrentIndex(i)
     else:
         log_warn("couldn't find improto_constant", improto_constant)
     if account_dict.get("use_proxy", False) and account_dict.get("proxy_params", False):
         w.use_proxy.setChecked(True)
         pp = account_dict["proxy_params"]
         
         proxy_type_index = w.improto.findText(pp.get("proxy_type", "").upper())
         if proxy_type_index >= 0:
             w.proxy_type.setCurrentIndex(proxy_type_index)
         w.proxy_address.setText(pp.get("proxy_address"))
         w.proxy_port.setText(pp.get("proxy_port"))
         w.proxy_username.setText(pp.get("proxy_username", ""))
         w.proxy_password.setText(pp.get("proxy_password", ""))
     else:
         w.use_proxy.setChecked(False)
示例#3
0
 def encode(self):
     if not self.user or not self.passw or not self.improto or not self.id:
         raise TypeError("missing parameters")
     info = yobot_mkacctinfo()
     info.user = self.user
     info.password = self.passw
     info.acctid = self.id
     info.improto = self.improto
     if self._proxy_host:
         proxy_info_xml = "<foo><proxy_info proxy_host='%s' " % (self._proxy_host)
         if self._proxy_port:
             proxy_info_xml += "proxy_port='%s' " % (str(self._proxy_port))
         if self._proxy_username:
             proxy_info_xml += "proxy_username='******' " % (self._proxy_username)
             if self._proxy_password:
                 proxy_info_xml += "proxy_password='******' " % (self._proxy_password)
         
         if self._proxy_type in ("socks4", "socks5", "http"):
             proxy_info_xml += "proxy_type='%d' " % (
                 getattr(yobotproto, "PURPLE_PROXY_" + self._proxy_type.upper()))
         else:
             log_warn("unknown proxy type", self._proxy_type)
             proxy_info_xml = ""
         
         if proxy_info_xml:
             proxy_info_xml += "/></foo>"
         info.attr_xml = proxy_info_xml
         log_debug(proxy_info_xml)
     else:
         log_debug("proxy info is null?")
     ptr = yobot_protoclient_mkacct_encode(info, None, YOBOT_PROTOCLIENT_TO_BUF)
     return ptr
示例#4
0
 def addAcct(self, acct):
     #add an account and request an ID..
     if acct in self._all_accounts:
         log_warn( "request already completed or pending.. not adding")
         return
     self.pending_accounts.put(acct)
     self.yobot_server.sendCommand(yobotproto.YOBOT_CMD_ACCT_ID_REQUEST,0)
     log_debug( "send account connect command for account %s" % (acct, ))
示例#5
0
文件: account.py 项目: mnunberg/yobot
 def delConnection(self, connection, id=None, userproto=(None,None)):
     """Removes a connection from the account's data list"""
     #FIXME: accept iterables for id and userproto
     ((acct, st), lookup_table) = self._getacct(id, userproto)
     try:
         st.remove(connection)
     except KeyError, e:
         log_warn( e)
         return
示例#6
0
 def fn(cls, obj, proto):
     tbl = getattr(cls, tbl_name)
     #get required attribute:
     target = obj
     try:
         for attr in attrs.split("."):
             target = getattr(target, attr)
     except AttributeError, e:
         log_warn( e)
         return None
示例#7
0
 def callback(self, ret):
     if not self.svc:
         log_warn("service was not specified")
         return
     cmd = YobotCommand()
     cmd.acctid = self.evt.objid
     cmd.cmd = yobotproto.YOBOT_CMD_PURPLE_REQUEST_GENERIC_RESPONSE
     cmd.data = str(ret)
     cmd.reference = self.evt.reference
     self.svc.sendSegment(cmd)
     log_info("send response - %s" % (cmd.reference,))
示例#8
0
 def _addItem(self, item, key):
     if item in self:
         log_warn( "item exists")
         return
     self.beginAdd(len(self._t))
     #log_debug("passing %d" % len(self._t))
     l = list(self._t)
     l.append(item)
     self._t = tuple(l)
     item.index = len(l)-1
     self._d[key] = item
     self.endAdd()
示例#9
0
 def __init__(self, account, txt, refid=0):
     if not txt:
         log_warn("no text")
         txt = ""
     log_debug(txt)
     self.refid = refid
     self._initvars()
     self.acct = account
     self.options.append(("Ok",
                          lambda: None,
                          yobotproto.YOBOT_ACTIONTYPE_OK))
     self._prettyformat(txt)
示例#10
0
文件: client.py 项目: mnunberg/yobot
def startup(args=sys.argv):
    import optparse
    options = optparse.OptionParser()
    options.add_option("-p", "--plugin", dest="selected_plugins", action="append",
                       help="include this plugin")
    options.add_option("-U", "--username", dest="username",
                       help="use this IM username")
    options.add_option("-P", "--password", dest="password",
                       help="use this password")
    options.add_option("-I", "--improto", dest="improto",
                       help="use this IM protocol [see documentation for a list]")
    options.add_option("-c", "--config-dir", dest="configdir",
                       help="client configuration directory",
                       default=yobot_interfaces.get_yobot_homedir())
    options.add_option("--use-proxy", dest="use_proxy", action="store_true",
                       help="use env proxy settings", default=False)
    options.add_option("--agent-address", dest="agent_addrinfo",
                       help="agent server:port")
    
    options, args = options.parse_args(args)
    
    #set our configuration directory
    yobot_interfaces.component_registry.register_component("yobot-config-dir", options.configdir)
    
    if options.selected_plugins:
        #generate dict:
        name_object = {}
        for plugin in yobot_interfaces.component_registry.get_plugins():
            name_object[plugin.plugin_name] = plugin
        for p in options.selected_plugins:
            plugin_object = name_object.get(p)
            if not plugin_object:
                log_warn("couldn't find plugin", p)
                continue
            yobot_interfaces.component_registry.activate_plugin(plugin_object)
    
    tmp = options.agent_addrinfo
    if tmp:
        tmp = tmp.rsplit(":", 1)
        address = tmp[0]
        if len(tmp) >= 2:
            port = int(tmp[1])
    else:
        #no address specified on the command line
        address, port = None, None
        
    debuglog.init("Client", title_color="green")
    yobotproto.yobot_proto_setlogger("Client")
    ui = UIClient()
    ui.run(address, port)
示例#11
0
 def buddyEvent(self, obj, proto):
     #find account...
     log_info( "id: ", obj.evt.objid)
     acct = self.accounts.getAccount(obj.evt.objid)
     if not acct:
         log_warn( "Couldn't find account!")
     log_debug(acct)
     
     name, data = getNameAndData(obj)
     
     if name == "*":
         name = None
     if obj.evt.event == yobotproto.YOBOT_EVENT_BUDDY_GOT_ICON:            
         acct.gotBuddyIcon(name, data)
     else:
         acct.gotBuddyStatus(name, obj.evt.event, data)
示例#12
0
 def unregisterClient(self, proto):
     """
     Hook for connectionLost(). Removes the CID (if any) and its associated
     protocol instance from the table of clients
     """
     log_debug( "UNREGISTERING: ", proto.cid)
     #first remove it from the accounts list:
     acct_refs = self.accounts.getConnectionData(proto)
     if acct_refs:
         acct_refs = acct_refs.copy()
         for acctid in acct_refs:
             self.accounts.delConnection(proto, id = acctid)
     #finally, remove the client.. need to find a better way for this
     try:
         self.accounts._connections.pop(proto)
     except KeyError, e:
         log_warn( e, "don't care")
示例#13
0
 def sendMsg(self):
     w = self.widgets
     if not w.input.toPlainText():
         log_debug("empty input")
         return
     if self._send_html:
         txt = unicode(w.input.toHtml().toUtf8(), "utf-8")
         txt = simplify_css(txt.encode("utf-8"))
     else:
         txt = unicode(w.input.toPlainText().toUtf8(), "utf-8")
         if not txt: return
     log_warn(txt)
     
     w.input.clear()
     
     chat = True if self.type == CHAT else False
     self.account.sendmsg(self.target, str(txt), chat=chat)
示例#14
0
 def chatUserEvent(self, obj, proto):
     evt = obj.evt
     joined = False if evt.event == yobotproto.YOBOT_EVENT_ROOM_USER_LEFT else True
         
     room, user = evt.txt.split(yobotproto.YOBOT_TEXT_DELIM, 1)
     log_info("room:", room, "user:"******"couldn't find account")
         return
     
     if joined:
         self.uihooks.chatUserJoined(acct, room, user)
     else:
         self.uihooks.chatUserLeft(acct, room, user)
         
     log_info( obj.evt)
示例#15
0
 def load_settings(self):
     w = self.widgets
     if not self.config:
         log_warn("config object not available! bailing")
         return
     #for font..
     appearance = self.config.globals.setdefault("appearance", {})
     family = appearance.get("font_family", None)
     size = appearance.get("font_size", None)
     color = appearance.get("font_color", None)
     
     if family: self.font.setFamily(family)
     if size: self.font.setPointSize(size)
     if color: self.color.setNamedColor(color)
     
     bold = appearance.get("font_bold", False)
     italic = appearance.get("font_italic", False)
     underline = appearance.get("font_underline", False)
     html_relsize = appearance.get("use_html_relsize", False)
     show_joinpart = appearance.get("show_joinpart", False)
     
     self.font.setBold(bold)
     self.font.setItalic(italic)
     self.font.setUnderline(underline)
     w.html_relsize.setChecked(html_relsize)
     w.show_joinpart.setChecked(show_joinpart)
     
     self.change_formatting()
     
     #for the agent...
     agent = self.config.globals.get("agent_address", None)
     if agent: w.agent_address.setText(agent)
     self.change_agent()
     #for accounts:
     for a in self.config.accounts:
         log_warn("got account", a)
         if a.get("name", None) and a.get("improto", None):
             #get name and icon
             name, icon = getProtoIconAndName(getattr(yobotproto, a["improto"], ""))
             log_debug(icon, name)
             i = QTreeWidgetItem((a["name"], name))
             i.setIcon(1, icon)
             i.setData(0, ITEM_PLACEHOLDER_ROLE, a)
             self.account_items[i] = a
             self.widgets.accounts.addTopLevelItem(i)
示例#16
0
 def getMsgs(self, account_name, protocol_name, other_user=None, timerange=None,type=None,count=50):
     """-> list of message, in order of time"""
     account_id_internal = self._get_account_id_internal(account_name, protocol_name)
     if not account_id_internal:
         return
     where_params = { "account_id_internal" : account_id_internal }
     if other_user:
         conv_id = self._getConvId(account_id_internal, other_user)
         if not conv_id:
             return
         where_params["conv_id"] = conv_id
     
     query_string = "SELECT timestamp, who, body, type, other_user FROM messages WHERE "
     value_l = []
     ands = []
     for k, v in where_params.items():
         ands.append(k + "=? ")
         value_l.append(v)
         
     query_string += " AND ".join(ands)
     
     if timerange:
         start, end = timerange
         query_string += " AND timestamp BETWEEN ? AND ? "
         value_l += [int(start), int(end)]
     
     query_string += "ORDER BY timestamp "
     if count:
         query_string += "LIMIT ? "
         value_l.append(count)
         
     log_warn(query_string, value_l)
     del ands
     for res in self._cursor.execute(query_string, value_l):
         msg = YobotMessage()
         msg.time = int(res["timestamp"])
         msg.name = res["other_user"]
         msg.who = res["who"]
         msg.txt = res["body"]
         type = res["type"]
         msg.yprotoflags |= yobotproto.YOBOT_MSG_TYPE_CHAT if type == CONV_TYPE_CHAT else yobotproto.YOBOT_MSG_TYPE_IM
         msg.prplmsgflags |= yobotproto.PURPLE_MESSAGE_SEND if msg.who == account_name else yobotproto.PURPLE_MESSAGE_RECV
         yield msg
示例#17
0
 def load_appearance_config(self):
     w = self.widgets
     if self.appearance_config:
         #navigate around.. this could be tricky
         c = self.appearance_config
         if c.get("font_family", None):
             f = QFont()
             f.setFamily(c["font_family"])
             w.font.setCurrentFont(f)
         if c.get("font_size", None):
             log_warn("setting font size to ", c["font_size"])
             w.fontsize.setValue(c["font_size"])
             w.input.setFontPointSize(c["font_size"])
         if c.get("font_color", None): self._choosecolor(set_color=QColor(c["font_color"]))
         if c.get("font_bold", False): w.bold.setChecked(True)
         if c.get("font_italic", False): w.italic.setChecked(True)
         if c.get("font_underline", False): w.underline.setChecked(True)
         if c.get("show_joinpart", False): w.actionShow_Join_Leave.setChecked(True)
         
         self.use_relsize = c.get("use_html_relsize", False)
示例#18
0
 def relayOfflines(self, obj, proto):
     acct, _ = self.accounts.byId(obj.cmd.acctid)
     if not acct:
         log_err("account is none")
         return
     if not acct.lastClientDisconnected:
         log_info("not relaying offlines while other clients are still connected")
         return
     for msg in self.logger.getMsgs(acct.name, yobotops.imprototostr(acct.improto),
                                  timerange = (acct.lastClientDisconnected, time.time()),
                                  count=0):
         msg.acctid = obj.cmd.acctid
         msg.yprotoflags |= (yobotproto.YOBOT_BACKLOG|yobotproto.YOBOT_OFFLINE_MSG)
         proto.sendSegment(msg)
         print msg
     self.logger.dump()
         
     log_warn("done")
     log_info(acct.lastClientDisconnected)
     acct.lastClientDisconnected = 0
示例#19
0
文件: account.py 项目: mnunberg/yobot
    def rm_account(self, cbresult):
        log_debug( "rm_account...")
        #tell the client we've timed out
        if self.timedOut:
            log_debug( "sending event..")

            self.proto.sendAccountEvent(yobotproto.YOBOT_EVENT_LOGIN_TIMEOUT,
                                    self.newacct.id,severity=yobotproto.YOBOT_WARN,
                                    txt="Yobot Server did not get a response from purple")
            log_debug( "Sent event")
        
        #tell purple to forget about our account
        log_debug( "telling purple to remove the account...")
        self.prpl.sendCommand(yobotproto.YOBOT_CMD_ACCT_REMOVE,self.newacct.id)
        log_debug( "done")
        
        try:
            log_debug( "deleting account from relay...")
            self.acct_mgr.delAcct(id=self.newacct.id)
            log_debug( "done")
        except Exception,e:
            log_warn( err)
示例#20
0
 def handle_request(self, obj, proto):
     """Mainly for buddy auth requests but can also possibly be used for
     other stuff"""
     evt = obj.evt
     acct = self.accounts.getAccount(obj.evt.objid)
     if evt.event == yobotproto.YOBOT_EVENT_USER_ADDREQ:
         req = BuddyAuthorize(self, evt.txt, acct)
         self.uihooks.gotRequest(req)
     elif evt.event == yobotproto.YOBOT_EVENT_PURPLE_REQUEST_GENERIC:
         req = YCRequest(self, obj.evt, acct)
         log_warn(req)
         self.uihooks.gotRequest(req)
     elif evt.event in (yobotproto.YOBOT_EVENT_PURPLE_NOTICE_GENERIC,
                        yobotproto.YOBOT_EVENT_AGENT_NOTICE_GENERIC):
         #get the text..
         req = SimpleNotice(acct, obj.evt.txt, obj.evt.reference)
         self.uihooks.gotRequest(req)
     elif evt.event == yobotproto.YOBOT_EVENT_PURPLE_REQUEST_GENERIC_CLOSED:
         log_debug("closed")
         #get request id..
         refid = obj.evt.reference
         self.uihooks.delRequest(acct, refid)
示例#21
0
 def model_dump(self):
     return
     for a in self.backend:
         log_warn(a)
         for b in a.blist:
             log_warn("\t", b)
     log_err("now recursing")
     rows = self.rowCount()
     log_err("rows: ", rows)
     if rows > 0:
         for r in xrange(0, rows):
             acct_index = self.index(r)
             log_warn("Account", acct_index.internalPointer().name)
             c_rows = self.rowCount(acct_index)
             if c_rows > 0:
                 for cr in xrange(0, c_rows):
                     c_index = self.index(cr, 0, acct_index)
                     log_warn("\tBuddy", c_index.internalPointer().name)
示例#22
0
 def unhandled(self, obj, proto):
     log_warn("UNHANDLED", obj)
     return NotImplemented
示例#23
0
文件: account.py 项目: mnunberg/yobot
         return
     
     try:
         if connection in acct.authenticated_clients and len(acct.authenticated_clients) == 1:
             #we're removing the last connection
             acct.lastClientDisconnected = time()
         acct.authenticated_clients.remove(connection)
     except KeyError:
         log_info("seems connection %s was not authenticated" % (str(connection),))
         
     self._update_both(acct, st, lookup_table)
     
     try:
         self._connections[connection].remove(acct.id)
     except KeyError, e:
         log_warn( e)
         return
 
 def getConnectionData(self, connection):
     return self._connections.get(connection, None)
 
 def reserveId(self,bits):
     if bits > 31:
         return None
     for _ in range(1,10):
         tmp = random.getrandbits(bits)
         tmp = abs(tmp)
         if not self._ids.has_key(tmp):
             self._ids[tmp] = RESERVED_ID
             return tmp
     return None
示例#24
0
 def wrap(*args, **kwargs):
     log_warn("Function ", in_fn.func_name, "is not implemented.")
     in_fn(*args, **kwargs)
示例#25
0
 def _tabRemoved(index):
     if self.tabwidget.count() == 0:
         log_warn("last tab removed..")
         self.close()
示例#26
0
    sys.path.append("../")
    from debuglog import log_debug, log_err, log_warn, log_crit, log_info
    from gui_util import adjust_stylesheet_palette
    if __name__ == "__main__":
        import debuglog
        debuglog.init("Tabbed Windows", title_color="red")
except ImportError, e:
    def log_generic(*args):
        print " ".join([str(a) for a in args])
    log_debug = log_err = log_warn = log_crit = log_info = log_generic
    adjust_stylesheet_palette = lambda x: x
    log_err(e)

import os
if os.environ.get("USE_PYSIDE"):
    log_warn("Using PySide")
    from PySide.QtCore import *
    from PySide.QtGui import *
else:
    from PyQt4.Qt import (QHBoxLayout, QTabBar, QWidget, QMainWindow, QFrame,
                          QCursor, QVBoxLayout, QMenu, QPixmap, QApplication,
                          QPoint, QPushButton, QSizePolicy, QTabWidget, QMenuBar,
                          QLabel, QDrag, QTabBar, QAction, QPainter, QStyleOptionTab,
                          QImage, QDesktopWidget, QRect)
    from PyQt4.QtCore import (QMimeData, QObject, SIGNAL, QPoint, Qt, QTimer, QSize,
                              pyqtSignal)

               

#make a few classes here
示例#27
0
文件: client.py 项目: mnunberg/yobot
 def connectToAgent(self, address=None, port=None, disconnect_from_server=True):
     try:
         self.disconnectAll(disconnect_from_server)
     except Exception, e:
         log_warn(e)
示例#28
0
     acct_refs = self.accounts.getConnectionData(proto)
     if acct_refs:
         acct_refs = acct_refs.copy()
         for acctid in acct_refs:
             self.accounts.delConnection(proto, id = acctid)
     #finally, remove the client.. need to find a better way for this
     try:
         self.accounts._connections.pop(proto)
     except KeyError, e:
         log_warn( e, "don't care")
     log_info( "Unregistered connection from all accounts")
     
     try:
         self.clients.pop(proto.cid)
     except KeyError, e:
         log_warn( e, "(don't care)")
     
     log_debug( "CURRENT CONNECTIONS: ", self.clients)
     log_debug( "Connections: ", self.accounts._connections, "Accounts ", self.accounts._ids)
 
 
 #########################   HANDLERS    ####################################
 #event handlers for the YobotServer relay agent/bouncer
 
 def verifyObj(self, obj, proto):
     """Verify that the acct ID referenced in the incoming client message
     indeed belongs to the client"""
     acctid = 0
     if obj.cmd: acctid = obj.cmd.acctid
     elif obj.evt: acctid = obj.evt.objid
     
示例#29
0
文件: client.py 项目: mnunberg/yobot
 def accountConnectionRemoved(self, acct):
     acct._logged_in = False
     self._plugin_hook_invoke("accountConnectionRemoved", (acct,))
     log_warn( "ACCOUNT REMOVED!")