Esempio n. 1
0
    def __init__(self, parent, uname, upass, dpool, epool):
        # begin wxGlade: MainPannel.__init__
        self.version = 1.0
        self.canlock = True
        self.listall = False
        self.last_copied_pass = None
        wx.Frame.__init__(self,
                          parent,
                          size=(1000, 1000),
                          style=wx.TAB_TRAVERSAL | wx.DEFAULT_FRAME_STYLE
                          | wx.WANTS_CHARS)
        self.DWorkerPool = dpool
        self.EWrokerPool = epool
        self.uname = uname
        self.upass = upass
        self.icon = wx.Icon(
            os.path.join(common.cur_file_dir(), "manpassc.ico"),
            wx.BITMAP_TYPE_ICO)
        self.SetIcon(self.icon)
        #self.chkupdate_thread=checkUpdate.ChkUpdateThread("http://192.168.1.1:8090/ver.txt",self.version,self)

        #username, password must be encoded into utf-8 string before they could be used by crypto functions
        self.lock_label = wx.HyperlinkCtrl(self,
                                           wx.ID_ANY,
                                           _("Unlock Me"),
                                           style=wx.HL_ALIGN_CENTRE)
        self.progress_bar = wx.Gauge(self, wx.ID_ANY)
        self.status_bar = wx.StatusBar(self, wx.ID_ANY)
        self.SetStatusBar(self.status_bar)

        defconflist = [
            (_("Basic Options"), [
                (("addr"), {
                    "desc": _("Listening address"),
                    "value": "127.0.0.1",
                    "type": "string"
                }),
                (("port"), {
                    "desc": _("Listening port"),
                    "value": 9000,
                    "type": "int"
                }),
                (("idle_timer"), {
                    "desc": _("Idle lock timer(seconds)"),
                    "value": 60,
                    "type": "int"
                }),
                (("startup_minimize"), {
                    "desc": _("Minimize the window upon startup"),
                    "value": False,
                    "type": "bool"
                }),
                (("close&lock"), {
                    "desc": _("Lock the window upon close(windows only)"),
                    "value": True,
                    "type": "bool"
                }),
            ]),
        ]
        self.OptionDiag = myoptions.OptionDiag(self, "manpass.conf",
                                               defconflist, self.uname)
        self.confDict = None
        self.confDict = self.OptionDiag.toDict()
        if not common.checkTCPPort(self.confDict['addr'],
                                   self.confDict['port']):
            waitbox = wx.BusyInfo(_("Starting Manpass server, please wait..."))
            cmd = common.getManpassdExeName()
            exename = cmd
            cmd += " -username={uname} -pipepass=true -svrip={ip} -svrport={port}".format(
                uname=self.uname,
                ip=self.confDict['addr'],
                port=self.confDict['port'])
            args = shlex.split(cmd)
            if platform.system() == "Windows":
                startupinfo = subprocess.STARTUPINFO()
                startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            else:
                startupinfo = None
            try:
                self.svrp = subprocess.Popen(args,
                                             executable=exename,
                                             stdin=subprocess.PIPE,
                                             stdout=subprocess.PIPE,
                                             stderr=subprocess.PIPE,
                                             shell=False,
                                             startupinfo=startupinfo)
            except Exception as Err:
                del waitbox
                wx.MessageBox(unicode(Err), _("Error"), 0 | wx.ICON_ERROR,
                              self)
                self.ExitMe()
                return

            def enqueue_output(out, queue):
                for line in iter(out.readline, b''):
                    queue.put(line)
                out.close()

            errq = Queue.Queue()
            t2 = newUserDiag.EnQThread(self.svrp.stderr, errq)
            t2.daemon = True
            t2.start()
            self.svrp.stdin.write(self.upass + "\n")
            self.svrp.stdin.close()
            ferror = False
            ferror_msg = ""

            def check_output(errq):
                t0 = time.time()
                ferror = False
                while True:
                    wx.GetApp().Yield()
                    try:
                        errline = errq.get_nowait()
                    except Queue.Empty:
                        if time.time() - t0 > 30.0:
                            ferror = True
                            ferror_msg = "Time out"
                            break
                        pass
                    else:
                        if errline.find("Server started") != -1:
                            break
                        if errline.find("Fatal Error") != -1:
                            ferror = True
                            ferror_msg = errline
                            break
                        if (time.time() - t0) > 30.0:
                            ferror = True
                            ferror_msg = "Time out"
                            break
                t2.stop()
                if ferror:
                    ##                    wx.MessageBox(_("Server failed to start!\n")+unicode(ferror_msg),_("Error"),0|wx.ICON_ERROR,self)
                    return _("Server failed to start!\n") + unicode(ferror_msg)
                else:
                    return True

            startresult = check_output(errq)
            if startresult != True:
                del waitbox
                wx.MessageBox(startresult, _("Error"), 0 | wx.ICON_ERROR, self)
                self.ExitMe()
                return
            del waitbox

        try:
            cadata = apiclient.loadCAFile(self.uname, self.upass,
                                          self.confDict['confDir'])
        except Exception as Err:
            wx.MessageBox(
                _("Authentication Failed!\n") + unicode(Err), _("Error"),
                0 | wx.ICON_ERROR, self)
            self.ExitMe()
            return
        try:
            self.apiclient = apiclient.APIClient(
                self.confDict['addr'], self.confDict['port'], cadata,
                os.path.join(self.confDict["confDir"], "ee.cert"),
                os.path.join(self.confDict["confDir"], "ee.key"), self.upass,
                self.DWorkerPool, self.EWrokerPool)
        except Exception as Err:
            ##            traceback.print_exc(Err)
            wx.MessageBox(_("Failed to connect to the server!"), _("Error"),
                          0 | wx.ICON_ERROR, self)
            self.ExitMe()
            return

        self.SetTitle("Manpass - " + self.uname.decode("utf-8"))

        if platform.system() == "Windows":
            self.taskicon = MyTaskbarIcon(self)
            self.taskicon.SetIcon(self.icon)
            wx.EVT_TASKBAR_LEFT_UP(self.taskicon, self.OnDClickTaskIcon)

        self.Bind(wx.EVT_CLOSE, self.HideMe)

        self.timer_lock = wx.Timer(self, wx.NewId())
        self.timer_clear = wx.Timer(self, wx.NewId())
        self.timer_statustxt = wx.Timer(self, wx.NewId())
        self.timer_lock.Start(self.confDict['idle_timer'] * 1000,
                              wx.TIMER_CONTINUOUS)
        self.text_ctrl_search_input = wx.SearchCtrl(self, wx.NewId(), "")
        self.list_ctrl_1 = PassListCtrl(self, self.text_ctrl_search_input)

        self.Bind(wx.EVT_TIMER, self.OnTimerLock, self.timer_lock)
        self.Bind(wx.EVT_TIMER, self.OnTimerClear, self.timer_clear)
        self.Bind(wx.EVT_TIMER, self.OnTimerStatusTxt, self.timer_statustxt)

        self.Bind(wx.EVT_TEXT, self.OnFilter, self.text_ctrl_search_input)
        self.text_ctrl_search_input.Bind(wx.EVT_SET_FOCUS, self.OnFilterAct)
        self.text_ctrl_search_input.Bind(wx.EVT_CHAR, self.OnChar)

        self.Bind(wx.EVT_CHAR, self.OnChar)
        self.list_ctrl_1.Bind(wx.EVT_CHAR, self.OnChar)
        self.lock_label.Bind(wx.EVT_CHAR, self.OnChar)
        ##        self.text_ctrl_search_input.Bind(wx.EVT_SET_FOCUS,self.OnFilterAct)

        self.__set_properties()
        self.__do_layout()
        self.CentreOnScreen()
        self.SetSize((400, 400))
        self.list_ctrl_1.reload()
        self.text_ctrl_search_input.SetFocus()
        self.text_ctrl_search_input.SetValue("")

        #self.Bind(wx.EVT_ICONIZE,self.HideMe)
        self.lock_label.Bind(wx.EVT_HYPERLINK, self.OnUnlock)

        #self.text_ctrl_search_input.Bind(wx.EVT_CHAR,self.resetTimer)

        self.list_ctrl_1.Bind(wx.dataview.EVT_DATAVIEW_SELECTION_CHANGED,
                              self.resetTimer)
        self.list_ctrl_1.Bind(wx.dataview.EVT_DATAVIEW_ITEM_ACTIVATED,
                              self.resetTimer)
        self.list_ctrl_1.Bind(wx.dataview.EVT_DATAVIEW_COLUMN_HEADER_CLICK,
                              self.resetTimer)
        self.list_ctrl_1.Bind(
            wx.dataview.EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK,
            self.resetTimer)
        self.list_ctrl_1.Bind(wx.dataview.EVT_DATAVIEW_ITEM_CONTEXT_MENU,
                              self.resetTimer)
        self.Bind(wx.EVT_ACTIVATE, self.resetTimer)
        self.Bind(common.EVT_MANPASS_FATALERR, self.OnFatal)
        self.Bind(common.EVT_MANPASS_PROGRESS, self.UpdateProgress)
        self.Bind(common.EVT_MANPASS_LOAD_DONE, self.LoadDone)
        self.Bind(wx.EVT_SET_FOCUS, self.OnFocus)
        #self.Bind(checkUpdate.EVT_CHK_UPDATE,self.CheckUpdateDone)

        if platform.system() == "Windows":
            import win32con
            self.RegisterHotKey(52445, win32con.MOD_CONTROL, ord("I"))
            self.Bind(wx.EVT_HOTKEY, self.OnDClickTaskIcon, id=52445)

        if self.confDict['startup_minimize']:
            self.HideMe(None)
        else:
            self.Show(True)
            self.Raise()
Esempio n. 2
0
    def OnOK(self,evt):
        pass1=self.text_ctrl_upass1.GetValue().strip()
        pass2=self.text_ctrl_upass2.GetValue().strip()
        self.uname=self.text_ctrl_uname.GetValue().strip()
        b=evt.GetEventObject()
        orig_label=b.GetLabel()
        b.SetLabel(_("Creating..."))
        self.disableMe()
        confdir=common.getConfDir(self.uname)
        if os.path.isdir(confdir):
            wx.MessageBox(_("User already exisits, choose a different username"),_("Error"),0|wx.ICON_ERROR,self)
            b.SetLabel(orig_label)
            self.enableMe()
            return
        try:
            goodName(self.uname)
        except Exception as Err:
            wx.MessageBox(_("Not a good username, choose a different username\n")+unicode(Err),_("Error"),0|wx.ICON_ERROR,self)
            b.SetLabel(orig_label)
            self.enableMe()
            return
        if pass1!=pass2:
            wx.MessageBox(_("Password of two typing doesn't match!"),_("Error"),0|wx.ICON_ERROR,self)
            b.SetLabel(orig_label)
            self.enableMe()
            return
        try:
            goodPass(pass1,self.uname)
        except Exception as Err:
            wx.MessageBox(_("Not a good password, choose a different password\n")+unicode(Err),_("Error"),0|wx.ICON_ERROR,self)
            b.SetLabel(orig_label)
            self.enableMe()
            return
        waitbox=wx.BusyInfo(_("Creating new user, please wait..."))
        uport=common.getNewPort()
        exename=common.getManpassdExeName()
        cmd=exename+" -username={uname} -create=true -pipepass=true -svrport={port}".format(uname=self.uname,port=uport)
        args=shlex.split(cmd)
        if platform.system()=="Windows":
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags|= subprocess.STARTF_USESHOWWINDOW
        else:
            startupinfo = None
        ON_POSIX = 'posix' in sys.builtin_module_names
        p=subprocess.Popen(args,executable=exename,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,startupinfo=startupinfo,close_fds=ON_POSIX)
        def enqueue_output(out, queue):
            for line in iter(out.readline, b''):
                queue.put(line)
            out.close()
        outq=Queue.Queue()
        errq=Queue.Queue()
        t1=EnQThread(p.stdout,outq)
        t2=EnQThread(p.stderr,errq)
        t1.daemon=True
        t2.daemon=True
        t1.start()
        t2.start()
        p.stdin.write(pass1+"\n")
        p.stdin.close()
        def check_output(outq,errq):
            while True:
                wx.GetApp().Yield()
                try:
                    outline=outq.get_nowait()
                except Queue.Empty:
                    pass
                else:
                    #print "stdout:",outline
                    if outline.find("new user created") !=-1:
                        break
                try:
                    errline=errq.get_nowait()
                except Queue.Empty:
                    pass
                else:
                    #print "some err:",errline
                    break
            t1.stop()
            t2.stop()
            fp=open(os.path.join(confdir,"manpass.conf"),"w")
            fp.write('{"port": '+str(uport)+" }")
            fp.close()


        check_output(outq,errq)
        del waitbox
        self.Close()
        evt.Skip()
Esempio n. 3
0
    def __init__(self, parent,uname,upass,dpool,epool):
        # begin wxGlade: MainPannel.__init__
        self.version=1.0
        self.canlock=True
        self.listall=False
        self.last_copied_pass=None
        wx.Frame.__init__(self,parent,size=(1000,1000),style=wx.TAB_TRAVERSAL|wx.DEFAULT_FRAME_STYLE|wx.WANTS_CHARS)
        self.DWorkerPool=dpool
        self.EWrokerPool=epool
        self.uname=uname
        self.upass=upass
        self.icon=wx.Icon(os.path.join(common.cur_file_dir(),"manpassc.ico"),wx.BITMAP_TYPE_ICO)
        self.SetIcon(self.icon)

        #username, password must be encoded into utf-8 string before they could be used by crypto functions
        self.lock_label=wx.HyperlinkCtrl(self,wx.ID_ANY,_("Unlock Me"),style=wx.HL_ALIGN_CENTRE)
        self.progress_bar=wx.Gauge(self,wx.ID_ANY)
        self.status_bar=wx.StatusBar(self,wx.ID_ANY)
        self.SetStatusBar(self.status_bar)

        defconflist=[
        (_("Basic Options"),
                [(("addr"),{"desc":_("Listening address"),"value":"127.0.0.1","type":"string"}),
                 (("port"),{"desc":_("Listening port"),"value":9000,"type":"int"}),
                 (("idle_timer"),{"desc":_("Idle lock timer(seconds)"),"value":60,"type":"int"}),
                 (("startup_minimize"),{"desc":_("Minimize the window upon startup"),"value":False,"type":"bool"}),
                 (("close&lock"),{"desc":_("Lock the window upon close(windows only)"),"value":True,"type":"bool"}),
                    ]
            ),
        ]
        self.OptionDiag=myoptions.OptionDiag(self,"manpass.conf",defconflist,self.uname)
        self.confDict=None
        self.confDict=self.OptionDiag.toDict()
        if not common.checkTCPPort(self.confDict['addr'],self.confDict['port']):
            waitbox=wx.BusyInfo(_("Starting Manpass server, please wait..."))
            cmd=common.getManpassdExeName()
            exename=cmd
            cmd+=" -username={uname} -pipepass=true -svrip={ip} -svrport={port}".format(uname=self.uname,ip=self.confDict['addr'],port=self.confDict['port'])
            args=shlex.split(cmd)
            if platform.system()=="Windows":
                startupinfo = subprocess.STARTUPINFO()
                startupinfo.dwFlags|= subprocess.STARTF_USESHOWWINDOW
            else:
                startupinfo = None
            try:
                self.svrp=subprocess.Popen(args,executable=exename, stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=False,startupinfo=startupinfo)
            except Exception as Err:
                del waitbox
                wx.MessageBox(unicode(Err),_("Error"),0|wx.ICON_ERROR,self)
                self.ExitMe()
                return

            def enqueue_output(out, queue):
                for line in iter(out.readline, b''):
                    queue.put(line)
                out.close()
            errq=Queue.Queue()
            t2=newUserDiag.EnQThread(self.svrp.stderr,errq)
            t2.daemon=True
            t2.start()
            self.svrp.stdin.write(self.upass+"\n")
            self.svrp.stdin.close()
            ferror=False
            ferror_msg=""
            def check_output(errq):
                t0=time.time()
                ferror=False
                while True:
                    wx.GetApp().Yield()
                    try:
                        errline=errq.get_nowait()
                    except Queue.Empty:
                        if time.time()-t0>30.0:
                            ferror=True
                            ferror_msg="Time out"
                            break
                        pass
                    else:
                        if errline.find("Server started")!=-1:
                            break
                        if errline.find("Fatal Error")!=-1:
                            ferror=True
                            ferror_msg=errline
                            break
                        if (time.time()-t0)>30.0:
                            ferror=True
                            ferror_msg="Time out"
                            break
                t2.stop()
                if ferror:
##                    wx.MessageBox(_("Server failed to start!\n")+unicode(ferror_msg),_("Error"),0|wx.ICON_ERROR,self)
                    return _("Server failed to start!\n")+unicode(ferror_msg)
                else:
                    return True
            startresult=check_output(errq)
            if startresult!=True:
                del waitbox
                wx.MessageBox(startresult,_("Error"),0|wx.ICON_ERROR,self)
                self.ExitMe()
                return
            del waitbox

        try:
            cadata=apiclient.loadCAFile(self.uname,self.upass,self.confDict['confDir'])
        except Exception as Err:
            wx.MessageBox(_("Authentication Failed!\n")+unicode(Err),_("Error"),0|wx.ICON_ERROR,self)
            self.ExitMe()
            return
        try:
            self.apiclient=apiclient.APIClient(self.confDict['addr'],self.confDict['port'],cadata,
            os.path.join(self.confDict["confDir"],"ee.cert"),
            os.path.join(self.confDict["confDir"],"ee.key"),self.upass,
            self.DWorkerPool,self.EWrokerPool)
        except Exception as Err:
##            traceback.print_exc(Err)
            wx.MessageBox(_("Failed to connect to the server!"),_("Error"),0|wx.ICON_ERROR,self)
            self.ExitMe()
            return

        self.SetTitle("Manpass - "+self.uname.decode("utf-8"))

        if platform.system()=="Windows":
            self.taskicon=MyTaskbarIcon(self)
            self.taskicon.SetIcon(self.icon)
            wx.EVT_TASKBAR_LEFT_UP(self.taskicon,self.OnDClickTaskIcon)

        self.Bind(wx.EVT_CLOSE,self.HideMe)


        self.timer_lock=wx.Timer(self,wx.NewId())
        self.timer_clear=wx.Timer(self,wx.NewId())
        self.timer_statustxt=wx.Timer(self,wx.NewId())
        self.timer_lock.Start(self.confDict['idle_timer']*1000,wx.TIMER_CONTINUOUS)
        self.text_ctrl_search_input = wx.SearchCtrl(self, wx.NewId(),"")
        self.list_ctrl_1 = PassListCtrl(self,self.text_ctrl_search_input)


        self.Bind(wx.EVT_TIMER,self.OnTimerLock,self.timer_lock)
        self.Bind(wx.EVT_TIMER,self.OnTimerClear,self.timer_clear)
        self.Bind(wx.EVT_TIMER,self.OnTimerStatusTxt,self.timer_statustxt)

        self.Bind(wx.EVT_TEXT,self.OnFilter,self.text_ctrl_search_input)
        self.text_ctrl_search_input.Bind(wx.EVT_SET_FOCUS,self.OnFilterAct)
        self.text_ctrl_search_input.Bind(wx.EVT_CHAR,self.OnChar)

        self.Bind(wx.EVT_CHAR,self.OnChar)
        self.list_ctrl_1.Bind(wx.EVT_CHAR,self.OnChar)
        self.lock_label.Bind(wx.EVT_CHAR,self.OnChar)
##        self.text_ctrl_search_input.Bind(wx.EVT_SET_FOCUS,self.OnFilterAct)

        self.__set_properties()
        self.__do_layout()
        self.CentreOnScreen()
        self.SetSize((400,400))
        self.list_ctrl_1.reload()
        self.text_ctrl_search_input.SetFocus()
        self.text_ctrl_search_input.SetValue("")


        #self.Bind(wx.EVT_ICONIZE,self.HideMe)
        self.lock_label.Bind(wx.EVT_HYPERLINK,self.OnUnlock)

        #self.text_ctrl_search_input.Bind(wx.EVT_CHAR,self.resetTimer)

        self.list_ctrl_1.Bind(wx.dataview.EVT_DATAVIEW_SELECTION_CHANGED,self.resetTimer)
        self.list_ctrl_1.Bind(wx.dataview.EVT_DATAVIEW_ITEM_ACTIVATED,self.resetTimer)
        self.list_ctrl_1.Bind(wx.dataview.EVT_DATAVIEW_COLUMN_HEADER_CLICK,self.resetTimer)
        self.list_ctrl_1.Bind(wx.dataview.EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK,self.resetTimer)
        self.list_ctrl_1.Bind(wx.dataview.EVT_DATAVIEW_ITEM_CONTEXT_MENU,self.resetTimer)
        self.Bind(wx.EVT_ACTIVATE,self.resetTimer)
        self.Bind(common.EVT_MANPASS_FATALERR,self.OnFatal)
        self.Bind(common.EVT_MANPASS_PROGRESS,self.UpdateProgress)
        self.Bind(common.EVT_MANPASS_LOAD_DONE,self.LoadDone)
        self.Bind(wx.EVT_SET_FOCUS,self.OnFocus)

        if platform.system()=="Windows":
            import win32con
            self.RegisterHotKey(52445,win32con.MOD_CONTROL,ord("I"))
            self.Bind(wx.EVT_HOTKEY, self.OnDClickTaskIcon, id=52445)


        if self.confDict['startup_minimize']:
            self.HideMe(None)
        else:
            self.Show(True)
            self.Raise()