Exemple #1
0
    def action_snode(self, justselect):
        if self.get_address() is None:
            return
        view = self.get_object("servernodeview")
        _sel = view.get_selection().get_selected()
        if _sel[1] is None:
            return

        _security, _name, _hash = _sel[0][_sel[1]][1:4] #_entry.get_text().split("/",1)
        _check = self.do_requestdo("check", server=self.get_address(), name=_name, hash=_hash)
        if not logcheck(_check, logging.DEBUG):
            return
        # set new hash, when using a broken certhash otherwise everything stays the same
        _hash = _check[1].get("hash")
        # retrieve with the same/new hash
        _node = self.do_requestdo("get", server=self.get_address(), name=_name, hash=_hash)
        if not logcheck(_node, logging.ERROR):
            return
        # set new hash, when using a broken certhash
        #if _security != "valid":
        #    _hash = _node[1].get("hash")

        self.links["gtkclient"].set_curnode("{}-{}".format(_node[1]["address"], _node[1]["port"]), _name, _hash, self.get_address())
        if not justselect:
            _res = self.resdict.copy()
            _res["forcehash"] = _hash
            gtkclient_node(self.links, "{}-{}".format(_node[1]["address"], _node[1]["port"]), _name, **_res)
        self.close()
Exemple #2
0
 def update_info(self, *args):
     self.info = None
     _address = self.get_address()
     if _address is not None:
         infoob = self.do_requestdo("info", address=_address)
         if not logcheck(infoob, logging.ERROR) and infoob[2] is not None:
             travret = self.do_requestdo("getreferences", hash=self.resdict.get("forcehash"), filter="surl")
             if not logcheck(travret, logging.ERROR):
                 logging.error("fetching references failed")
                 return
             for _tsaddr, _type in travret[1]["items"]:
                 try:
                     # update info for local do_requestdo
                     self.resdict["traverseserveraddr"] = _tsaddr
                     infoob = self.do_requestdo("info", address=_address)
                     break
                 except Exception:
                     pass
         if infoob[0]:
             self.info = infoob
     if not self.info:
         _thash = self.resdict.get("forcehash")
         infoob = self.do_requestdo("getlocal", hash=_thash)
         if not infoob[0]:
             return
         name = (infoob[1]["name"], infoob[1]["security"])
         self.info = (True, {"type": infoob[1]["type"], "message": "", "name": name[0]}, name, _thash)
Exemple #3
0
 def update_name(self, *args):
     _name = self.get_object("rnamee").get_text()
     if not check_name(_name):
         logging.info("Invalid name: %s", _name)
         return
     # log errors
     logcheck(self.do_requestdo("changename", name=_name, permanent=self.get_object("changenamepermanent").get_active()), logging.ERROR)
Exemple #4
0
 def update_message(self, *args):
     messagebuf = self.get_object("messagebuffer")
     if not messagebuf.get_modified():
         return
     start, end = messagebuf.get_bounds()
     _text = messagebuf.get_text(start, end, True)
     # log errors
     logcheck(self.do_requestdo("changemsg", message=_text, permanent=self.get_object("changemsgpermanent").get_active()), logging.ERROR)
Exemple #5
0
 def register_ownnode(self, *args):
     if self.get_address() is None:
         return
     registerb = self.get_object("registerbutton")
     namestore = self.get_object("servernodelist")
     res = self.do_requestdo("register", server=self.get_address())
     if not logcheck(res, logging.ERROR):
         return
     if not self.isregistered:
         res_show = self.do_requestdo("show")
         if not logcheck(res_show, logging.ERROR):
             return
         self.isregistered = True
         namestore.prepend(("This Client", "valid", res_show[1]["name"], res_show[1]["hash"], res_show[1]["name"]))
         registerb.set_label("Update Address")
Exemple #6
0
 def update_friend(self):
     root = App.get_running_app().root
     text = root.requester.cur_server
     d2 = {"hash": self.entry[1], "reftype": "surl", "reference": text}
     ret = root.requester.requester.do_request("/client/addreference", d2,
                                               {})
     logcheck(ret)
     d3 = {
         "hash": self.entry[1],
         "reftype": "sname",
         "reference": self.entry[0]
     }
     ret = root.requester.requester.do_request("/client/addreference", d3,
                                               {})
     logcheck(ret)
Exemple #7
0
    def update_storage(self):
        """ func: update local storage """
        _storage = self.do_requestdo("listnodenametypes")
        if not logcheck(_storage):
            return
        self.localstore.clear()
        self.serverit = self.localstore.insert_with_values(None, -1, [0], ["Server"])
        self.server_dic = []
        self.friendit = self.localstore.insert_with_values(None, -1, [0], ["Friend"])
        self.friend_dic = []
        self.unknownit = self.localstore.insert_with_values(None, -1, [0], ["Unknown"])
        self.unknown_dic = []
        self.emptyit = self.localstore.insert_with_values(None, -1, [0], ["Empty"])
        self.empty_dic = []

        #serverlist=self.builder.get_object("serverlist")
        #serverlist.clear()
        for elem in _storage[1]["items"]:
            if elem[0] is None:
                logging.critical("None element as name")
                return
            if elem[1] is None:
                self.empty_dic += [elem[0]]
            elif elem[1] == "server":
                self.update_serverlist(elem[0])
                self.server_dic += [elem[0]]
                self.localstore.insert_with_values(self.serverit, -1, [0], [elem[0]])
            elif elem[1] == "client":
                self.friend_dic += [elem[0]]
                self.localstore.insert_with_values(self.friendit, -1, [0], [elem[0]])
            else:
                self.unknown_dic += [elem[0]]
                self.localstore.insert_with_values(self.unknownit, -1, [0], [elem[0]])
        for elem in self.server_dic+self.friend_dic+self.unknown_dic:
            if elem in self.empty_dic:
                self.empty_dic.remove(elem)

        for elem in self.empty_dic:
            self.localstore.insert_with_values(self.emptyit, -1, [0], [elem])

        localnames = self.builder.get_object("localnames")
        localnames.clear()
        localnames.append(("",))
        _names = self.do_requestdo("listnodenames")
        if not logcheck(_names):
            return
        for elem in _names[1]["items"]:
            localnames.append((elem,))
Exemple #8
0
    def addnodehash_confirm(self, *args):
        addnodecombo = self.builder.get_object("addnodecombo")
        addnodehashentry = self.builder.get_object("addnodehashentry")
        addnodetypecombo = self.builder.get_object("addnodetypecombo")

        hashlist = self.builder.get_object("hashlist")
        hashview = self.builder.get_object("hashview")

        _name = addnodecombo.get_active_id()
        _hash = addnodehashentry.get_text().strip(" ").rstrip(" ")
        _type = addnodetypecombo.get_active_id()
        if _name is None:
            return
        if _type == "":
            _type = "unknown"
        if not check_hash(_hash):
            logging.debug("invalid hash")
            return
        res = self.do_requestdo("addhash", name=_name, hash=_hash, type=_type)
        if logcheck(res):
            self.update_storage()
            if self.curlocal is not None and _type == self.curlocal[0]:
                it = hashlist.prepend((_hash,))
                hashview.get_selection().select_iter(it)
            #self.update_hashes()
            # apply refs (saved in classvariable) from addnodehash
            for elem in self._intern_refstoadd:
                self.do_requestdo("addreference", hash=_hash, reference=elem[1], reftype=elem[0])
            self.close_addnodedia()
        else:
            logging.error(str(res[1]))
Exemple #9
0
 def client_confirm(self, *args):
     clurl = self.builder.get_object("clienturl")
     clhash = self.builder.get_object("clienthash")
     _hash = clhash.get_text().strip(" ").rstrip(" ")
     _url = clurl.get_text().strip().rstrip()
     if _url == "":
         self.close_clientdia()
         return
     if _hash == "":
         ret = self.do_requestdo("show", overwriteaddress=_url)
         if not logcheck(ret, logging.INFO):
             return
         clhash.set_text(ret[3])
         _hash = clhash.get_text().strip(" ").rstrip(" ")
         if not self.clientunix.get_active():
             return
     if _url == "":
         return
     if not check_hash(_hash):
         return
     # deactivate old
     if self.remoteclient_url != _url:
         self.links["trusted_certhash"] = ""
     self.remoteclient_url = clurl.get_text()
     self.remoteclient_hash = _hash
     # get local port
     _showret = self.do_requestdo("show", forcehash=_hash)
     if not _showret[0]:
         logging.error("Error: redirect not possible; servercomponent of client not active")
         self.close_clientdia()
         return
     self.links["trusted_certhash"] = _hash
     self.close_clientdia()
Exemple #10
0
 def add_entity_afterask(self, name):
     root = App.get_running_app().root
     ret = root.requester.requester.do_request("/client/addentity", {"name": name}, {})
     if not logcheck(ret):
         return True
     self.entries = self.load_entities()
     return True
Exemple #11
0
 def registerserver(self):
     serverurlw = self.ids["serveraddressinp"]
     serverurlt = serverurlw.text
     if serverurlt == "":
         return
     reg1 = self.requester.requester.do_request("/client/register",
                                                {"server": serverurlt}, {})
     if logcheck(reg1):
         self.load_servernames()
Exemple #12
0
 def load_friends(self):
     lnames1 = self.requester.requester.do_request("/client/listnodenames",
                                                   {"filter": "client"}, {})
     if not logcheck(lnames1):
         return
     wid = self.ids.get("friendlist")
     wid.clear_widgets()
     for entry in lnames1[2]["items"]:
         wid.add_widget(FriendTreeNode(entry))
Exemple #13
0
 def add_hash_afterask(self, _hash):
     root = App.get_running_app().root
     ret = root.requester.requester.do_request("/client/addhash", {
         "name": self.text,
         "hash": _hash,
         "type": "client"
     }, {})
     if logcheck(ret):
         self.reload_hashes(None)
 def loadplugins(self):
     pluginlist = self.builder.get_object("pluginlist")
     pluginlist.clear()
     _listplugins = self.do_requestdo("listplugins")
     if not logcheck(_listplugins, logging.ERROR):
         _listplugins = []
     else:
         _listplugins = _listplugins[1]["items"]
     for plugin in _listplugins:
         pluginlist.append((plugin[0],))
 def load_mainconfig(self, *args):
     cleanpluginsb = self.builder.get_object("cleanpluginsb")
     cleanpluginsb.hide()
     self.preflist.clear()
     _preflist = self.links["config"].list()
     if not logcheck(_preflist, logging.ERROR):
         return
     for _key, _val, _converter, _default, _doc, ispermanent in _preflist:
         if _key != "state":
             self.preflist.append((_key, _val, ispermanent, _default))
Exemple #16
0
 def rename_call(self, name):
     root = App.get_running_app().root
     ret = root.requester.requester.do_request("/client/renameentity", {
         "name": self.text,
         "newname": name,
         "merge": True
     }, {})
     if not logcheck(ret):
         return
     root.load_friends()
Exemple #17
0
 def open_dia(self):
     root = App.get_running_app().root
     ret = root.requester.requester.do_request("/client/listhashes",
                                               {"name": self.entry[0]}, {})
     if not logcheck(ret):
         return
     hashes = map(lambda x: (x[0], (0, 0, 0, 1)), ret[2].get("items"))
     buttons = [("Select", self.load_selected), ("Clear", self.clear_chats),
                ("Close", lambda sel: None)]
     dia = ListDialog(entries=hashes, buttons=buttons)
     PopupNew(title="Select hash", content=dia).open()
Exemple #18
0
 def reload_hashes(self, selection):
     root = App.get_running_app().root
     ret = root.requester.requester.do_request("/client/listhashes", {
         "name": self.text,
         "filter": "client"
     }, {})
     if not logcheck(ret):
         return False
     self.entries = map(
         lambda entry: (entry[0], (1, 0, 0, 1) if entry[4] == "valid" else
                        (1, 1, 1, 1)), ret[2]["items"])
     return True
Exemple #19
0
 def update_serverlist_refid(self, _refid):
     serverlist = self.builder.get_object("serverlist")
     _serverrefs = self.do_requestdo("getreferences", certreferenceid=_refid)
     if not logcheck(_serverrefs):
         return
     for elem in _serverrefs[1]["items"]:
         if elem[0] not in self.serverlist_dic:
             if elem[1] == "name":
                 serverlist.append((elem[0], True))
                 self.serverlist_dic.append(elem[0])
             elif elem[1] == "url":
                 serverlist.append((elem[0], False))
                 self.serverlist_dic.append(elem[0])
Exemple #20
0
 def enternode_confirm(self, *args):
     _address = self.builder.get_object("enternodeurl").get_text().strip(" ").rstrip(" ")
     _hasho = self.builder.get_object("enternodehash")
     _hash = _hasho.get_text().strip(" ").rstrip(" ")
     if _hash == "":
         ret = self.do_requestdo("gethash", address=_address)
         if not logcheck(ret, logging.INFO):
             return
         _hasho.set_text(ret[1]["hash"])
         return
     if not check_hash(_hash):
         logging.info("hash wrong")
         return
     if _address == "":
         logging.info("address wrong")
         return
     ret = self.do_requestdo("info", hash=_hash)
     if not logcheck(ret, logging.ERROR):
         return
     self.set_curnode(_address, ret[1]["name"], _hash, None)
     self.close_enternodedia()
     self.opennode()
Exemple #21
0
 def update_services(self, *args):
     if self.get_address() is None:
         return
     servicel = self.get_object("servicelist")
     if self.info[2] is isself:
         ret = self.do_requestdo("listservices")
     else:
         ret = self.do_requestdo("listservices", client=self.get_address())
     servicel.clear()
     if not logcheck(ret, logging.INFO):
         return
     for elem in ret[1]["items"]:
         servicel.append((elem[0], elem[1]))
Exemple #22
0
 def addentity_confirm(self, *args):
     addentity = self.builder.get_object("addentityentry")
     localnames = self.builder.get_object("localnames")
     addnodecombo = self.builder.get_object("addnodecombo")
     _entity = addentity.get_text()
     res = self.do_requestdo("addentity", name=_entity)
     if logcheck(res):
         self.addentitydia.hide()
         self.empty_dic += [_entity]
         # add to proposal list
         localit = localnames.append((_entity,))
         # select entry
         addnodecombo.set_active_iter(localit)
         self.localstore.insert_with_values(self.emptyit, -1, [0], [_entity])
Exemple #23
0
 def load_server(self):
     root = App.get_running_app().root
     ret = root.requester.requester.do_request("/client/listhashes", {
         "name": self.text,
         "filter": "client"
     }, {})
     if not logcheck(ret):
         return
     if len(ret[2]["items"]) <= 1:
         self.load_server_direct()
         return
     newlist = map(
         lambda entry: (entry[0], (1, 0, 0, 1) if entry[4] == "valid" else
                        (0, 0, 0, 1)), ret[2]["items"])
     buttons = [("Load", self.load_server_direct)]
     dia = ListDialog(entries=newlist, buttons=buttons)
     PopupNew(title="Hashes", content=dia).open()
Exemple #24
0
 def load_friend(self):
     self.closebubble()
     root = App.get_running_app().root
     ret = root.requester.requester.do_request("/client/listhashes", {
         "name": self.text,
         "filter": "client"
     }, {})
     if not logcheck(ret):
         return
     buttons = [("Load", self.load_hash), \
                 ("Add", self.add_hash), ("Reload", self.reload_hashes), \
                 ("Close", lambda x: None)]
     newlist = map(
         lambda entry: (entry[0], (1, 0, 0, 1) if entry[4] == "valid" else
                        (1, 1, 1, 1)), ret[2]["items"])
     dia = ListDialog(entries=newlist, buttons=buttons)
     PopupNew(title="Hashes", content=dia).open()
Exemple #25
0
def init(srequester, handler):
    hserver = httpserver(("::1", 0), handler)
    body = {
        "port": hserver.server_port,
        "name": "chatscn",
        "post": True,
        "wrappedport": True
    }
    resp = srequester.requester.do_request("/client/registerservice", body, {})
    if not logcheck(resp, logging.ERROR):
        hserver.shutdown()
        return None
    handler.forcehash = resp[3][1]
    threading.Thread(target=hserver.serve_forever, daemon=True).start()
    srequester.requester.p.keywords["forcehash"] = resp[3][1]
    srequester.requester.p.keywords["ownhash"] = resp[3][1]
    return hserver
Exemple #26
0
 def add_service(self, *args):
     localservicelist = self.get_object("servicelist")
     servicee = self.get_object("newservicenameentry")
     porte = self.get_object("newserviceportentry")
     service = servicee.get_text().strip(" ").rstrip(" ")
     port = porte.get_text().strip(" ").rstrip(" ")
     if service == "":
         logging.debug("service invalid")
         return
     if port == "" or not port.isdecimal():
         logging.debug("port invalid")
         return
     ret = self.do_requestdo("registerservice", name=service, port=port)
     if not logcheck(ret, logging.DEBUG):
         return
     servicee.set_text("")
     porte.set_text("")
     localservicelist.append((service, int(port)))
    def load_pluginconfig(self, *args):
        self.preflist.clear()
        prefpluginscroll = self.builder.get_object("prefpluginscroll")
        prefpluginscroll.show()
        cleanpluginsb = self.builder.get_object("cleanpluginsb")
        cleanpluginsb.show()
        self.preflist.clear()
        #localview = self.builder.get_object("localview")
        _sel = self.pluginlistview.get_selection().get_selected()
        if _sel[1] is None:
            return
        _plugin = _sel[0][_sel[1]][0]
        _preflist = self.do_requestdo("list_pluginconfig", plugin=_plugin)
        if not logcheck(_preflist, logging.ERROR):
            return

        for _key, _val, _converter, _default, _doc, ispermanent in _preflist[1]["items"]:
            if _key == "state":
                self.preflist.prepend((_key, _val, ispermanent, _default))
            else:
                self.preflist.append((_key, _val, ispermanent, _default))
Exemple #28
0
 def load_servernames(self):
     serverurlw = self.ids["serveraddressinp"]
     serverurlw.background_color = (1., 1., 1., 1.)
     nameofserver = self.ids["nameofserver"]
     nameofserver.text = ""
     _reqserver = serverurlw.text
     lnames1 = self.requester.requester.do_request("/client/listnames",
                                                   {"server": _reqserver},
                                                   {})
     if not logcheck(lnames1):
         if _reqserver != "":
             serverurlw.background_color = (1., 0., 0., 1.)
         return
     self.requester.cur_server = _reqserver
     if not lnames1[3][0]:
         nameofserver.text = "unknown"
     elif lnames1[3][0] is isself:
         nameofserver.text = "Own client"
     else:
         nameofserver.text = "Identified as:\n{}".format(lnames1[3][0][0])
     wid = self.ids.get("serverlist")
     wid.clear_widgets()
     entryfriends = set()
     self.ids["registerserverb"].text = "Register"
     for entry in lnames1[2]["items"]:
         if entry[2] != "valid":
             continue
         if entry[3]:
             if entry[3] in entryfriends:
                 continue
             elif entry[3] == isself:
                 self.ids["registerserverb"].text = "Register again"
                 continue
             else:
                 entryfriends.add(entry[3])
         wid.add_widget(ServerTreeNode(entry))
Exemple #29
0
    def update_server(self, *args):
        if self.get_address() is None:
            return
        namestore = self.get_object("servernodelist")
        registerb = self.get_object("registerbutton")
        self.isregistered = False
        namestore.clear()
        _names = self.do_requestdo("listnames", server=self.get_address())
        if not logcheck(_names, logging.ERROR):
            return

        for name, _hash, _security, _localname in _names[1]["items"]:
            if _localname is None:
                namestore.append(("remote", _security, name, _hash, name))
            # isself is here a name not an instance so use ==
            elif _localname == isself:
                self.isregistered = True
                namestore.append(("This Client", _security, name, _hash, name))
            else:
                namestore.append(("local", "{} ({})".format(name, _localname,), _security, _hash, name))
        if not self.isregistered:
            registerb.set_label("Register")
        else:
            registerb.set_label("Update Address")
    def action_node(self, justselect):
        servercombo = self.builder.get_object("servercomboentry")
        rview = self.builder.get_object("refview")
        _selr = rview.get_selection().get_selected()
        if _selr[1] is None:
            return
        _ref, _type = _selr[0][_selr[1]]
        hview = self.builder.get_object("hashview")
        _selh = hview.get_selection().get_selected()
        if _selh[1] is None:
            return
        _hash = _selh[0][_selh[1]][0]
        serverurl = None

        if _type == "name":
            serverurl = servercombo.get_text().strip(" ").rstrip(" ")
            if serverurl == "":
                logging.info("no server selected")
                return

            turl = self.do_requestdo("get", server=serverurl, reference=_ref, hash=_hash)
            if not logcheck(turl, logging.INFO):
                return
            _url = "{address}-{port}".format(**turl[1])
        elif _type == "surl":
            serverurl = _ref
            namesret = self.do_requestdo("getreferences", hash=_hash, type="name")
            if not logcheck(namesret, logging.INFO):
                return
            tempret = None
            for elem in namesret[1]["items"]: #try all names
                if elem[0] in ["", None]:
                    logging.warning("references type name contain invalid element: %s", elem[0])
                else:
                    tempret = self.do_requestdo("get", server=serverurl, name=elem[0], hash=_hash)
                    if tempret[0]:
                        break
            if tempret is None or not logcheck(tempret, logging.INFO):
                return
            _url = "{address}-{port}".format(**tempret[1])
        elif _type == "url":
            _url = _ref
        elif _type == "None":
            _url = None
        elif _type in implementedrefs:
            return
        else:
            logging.info("invalid type")
            return
        if _url is not None and "-"  not in _url:
            logging.info("invalid url: %s", _url)
            return

        if _url is None:
            ret = [True]
        else:
            ret = self.do_requestdo("check_direct", address=_url, name=self.curlocal[1], hash=_hash, forcehash=_hash)

        if logcheck(ret, logging.ERROR):
            self.managehashdia.hide()
            if _url:
                if self.curlocal[0] == "server":
                    servercombo.set_text(_url)
                    self.veristate_server()
                else:
                    self.set_curnode(_url, self.curlocal[1], _hash, serverurl)
            if justselect:
                pass
            elif _url is None:
                gtkclient_node(self.links, None, forcehash=_hash, page=1)
            else:
                gtkclient_node(self.links, "{}-{}".format(*scnparse_url(_url)), forcehash=_hash, page=1)
Exemple #31
0
 def delete_friend_afterask(self):
     root = App.get_running_app().root
     ret = root.requester.requester.do_request("/client/delentity",
                                               {"name": self.text})
     if logcheck(ret):
         root.load_friends()
Exemple #32
0
 def load_entities():
     root = App.get_running_app().root
     ret = root.requester.requester.do_request("/client/listnodenames", {}, {})
     if not logcheck(ret):
         return None
     return map(lambda entry: (entry, (1, 1, 1, 1)), ret[2].get("items"))
Exemple #33
0
 def update_serverlist(self, _localname):
     _serverhashes = self.do_requestdo("listhashes", name=_localname)
     if logcheck(_serverhashes):
         for _hash in _serverhashes[1]["items"]:
             if _hash[0] != "default":
                 self.update_serverlist_refid(_hash[4])
 def set_loglevel(self, *args):
     _levelname = self.builder.get_object("filterlevel-entry").get_text()
     _levelno = logging._nameToLevel[_levelname]
     if self.remoteclient_url != "":
         logcheck(self.do_requestdo("changeloglevel", loglevel=_levelno))
 def clean_plugins(self, *args):
     logcheck(self.do_requestdo("clean_pluginconfig"), logging.ERROR) #plugin=_plugin needed?