예제 #1
0
    def SaveConfig(self, simple=False, persistent=True):
        """Save the user settings to the configuration file."""
        config.SetParam('fetch_server', self.servertext.GetValue())
        if self.rememberchk.GetValue() and self.pwdtext.GetValue() != '':
            if not self.pwdfake:
                import pkcs5
                password = pkcs5.PBKDF1(self.pwdtext.GetValue(), config.GetParam('fetch_server').lower())
                config.SetParam('password', password)
                self.pwdfake = True
        else:
            config.DeleteParam('password')

        if not simple:
            config.SetParam('listen_port', self.porttext.GetValue())
            if self.httpschk.GetValue():
                config.SetParam('fetch_protocol', 'https')
            else:
                config.SetParam('fetch_protocol', 'http')
            
            config.SetParam('auto_redirect', True)

            if self.proxycheck.GetValue():
                if self.proxyauthcheck.GetValue():
                    config.SetParam('local_proxy',
                                    '%s:%s@%s:%d' % (self.proxyusertext.GetValue(),
                                                     self.proxypwdtext.GetValue(),
                                                     self.proxytext.GetValue(),
                                                     self.proxyporttext.GetValue() )
                                    )
                else:
                    config.SetParam('local_proxy',
                                    '%s:%d' % (self.proxytext.GetValue(),
                                               self.proxyporttext.GetValue() )
                                    )
            else:
                config.SetParam('local_proxy', '')

            
            if wx.Platform == '__WXMSW__' and common.we_are_frozen():
                if self.autostartchk.GetValue():
                    try:
                        import _winreg
                        hkey = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run")
                        _winreg.SetValueEx(hkey, "secure-gappproxy", 0, _winreg.REG_SZ, sys.executable)
                        _winreg.CloseKey(hkey)
                    except:
                        _winreg.CloseKey(hkey)
                else:
                    try:
                        import _winreg
                        hkey = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run")
                        _winreg.DeleteValue(hkey, "secure-gappproxy")
                        _winreg.CloseKey(hkey)
                    except:
                        _winreg.CloseKey(hkey)


        if persistent: 
            config.SaveConfig()
예제 #2
0
    def LoadConfig(self):
        """Load configuration to UI controls."""
        self.servertext.SetValue(config.GetParam('fetch_server'))
        self.porttext.SetValue(config.GetParam('listen_port'))
        self.httpschk.SetValue(config.GetParam('fetch_protocol') == 'https')
        self.hostchk.SetValue(config.GetParam('auto_redirect'))
        if config.GetParam('password') != None:
            #We cannot extract the original password from the stored hash
            #Therefore, we have to place a fake place holder in the password box to fool the user
            self.rememberchk.SetValue(True)
            self.pwdtext.SetValue('PigPigLaLaLa~~')
            self.pwdfake = True
        else:
            self.rememberchk.SetValue(False)

        localproxy = config.GetParam('local_proxy')
        self.proxycheck.SetValue(localproxy != "")
        self.proxyauthcheck.SetValue('@' in localproxy)
        #Proxy requires authentication
        if '@' in localproxy:
            userpwd, _, hostport = localproxy.partition('@')
            user, _, pwd = userpwd.partition(':')
            self.proxyusertext.SetValue(user)
            self.proxypwdtext.SetValue(pwd)
        else:
            hostport = localproxy
        host, _, port = hostport.partition(':')
        self.proxytext.SetValue(host)
        self.proxyporttext.SetValue(port)

        if wx.Platform == '__WXMSW__' and common.we_are_frozen():
            import _winreg
            try:
                hkey = _winreg.CreateKey(
                    _winreg.HKEY_CURRENT_USER,
                    "Software\\Microsoft\\Windows\\CurrentVersion\\Run")
                val, _ = _winreg.QueryValueEx(hkey, "secure-gappproxy")
                self.autostartchk.SetValue(val == sys.executable)
                _winreg.CloseKey(hkey)
            except:
                self.autostartchk.SetValue(False)
                _winreg.CloseKey(hkey)

        #Notify the change of checkbox states
        self.Notify()
예제 #3
0
    def LoadConfig(self):
        """Load configuration to UI controls."""
        self.servertext.SetValue( config.GetParam('fetch_server') )
        self.porttext.SetValue( config.GetParam('listen_port') )
        self.httpschk.SetValue( config.GetParam('fetch_protocol') == 'https' )
        self.hostchk.SetValue( config.GetParam('auto_redirect') )
        if config.GetParam('password') != None:
            #We cannot extract the original password from the stored hash
            #Therefore, we have to place a fake place holder in the password box to fool the user
            self.rememberchk.SetValue( True )
            self.pwdtext.SetValue('PigPigLaLaLa~~')
            self.pwdfake = True
        else:
            self.rememberchk.SetValue( False )

        localproxy = config.GetParam('local_proxy')
        self.proxycheck.SetValue(localproxy != "")
        self.proxyauthcheck.SetValue('@' in localproxy)
        #Proxy requires authentication
        if '@' in localproxy:
            userpwd, _, hostport = localproxy.partition('@')
            user, _, pwd = userpwd.partition(':')
            self.proxyusertext.SetValue(user)
            self.proxypwdtext.SetValue(pwd)
        else:
            hostport = localproxy
        host, _, port = hostport.partition(':')
        self.proxytext.SetValue(host)
        self.proxyporttext.SetValue(port)

        if wx.Platform == '__WXMSW__' and common.we_are_frozen():
            import _winreg
            try:
                hkey = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run")
                val, _ = _winreg.QueryValueEx(hkey, "secure-gappproxy")
                self.autostartchk.SetValue( val == sys.executable)
                _winreg.CloseKey(hkey)
            except:
                self.autostartchk.SetValue(False)
                _winreg.CloseKey(hkey)


        #Notify the change of checkbox states
        self.Notify()
예제 #4
0
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, style=wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.FULL_REPAINT_ON_RESIZE)
        #Initialize proxy core
        self.core = proxycore.ProxyCore(Notifier(self))

        
        self.start_thread = None

        self.SetIcon(wx.Icon(WND_ICON, wx.BITMAP_TYPE_ICO))
        self.Bind(wx.EVT_CLOSE, self.on_close)

        self.out_panel = wx.Panel(self)
        
        simple_panel = wx.Panel(self.out_panel)
        self.simple_panel = simple_panel
        sizer_opts = wx.FlexGridSizer(rows=2,cols=2,vgap=10,hgap=5)
        sizer_opts.Add(wx.StaticText(simple_panel, label='Fetch Server:'), flag=wx.EXPAND | wx.TOP, border=3)
        self.servertext = wx.TextCtrl(simple_panel, value='your-appspot-id.appspot.com',size=(210,-1), style=wx.TE_PROCESS_ENTER)
        self.servertext.Bind(wx.EVT_TEXT_ENTER, self.OnEnterSubmit)
        sizer_opts.Add(self.servertext, flag=wx.EXPAND)
        sizer_opts.Add(wx.StaticText(simple_panel, label='Password:'******'', size=(210,-1), style=wx.TE_PASSWORD|wx.TE_PROCESS_ENTER)
        self.pwdtext.Bind(wx.EVT_SET_FOCUS, self.OnPwdFocus)
        self.pwdtext.Bind(wx.EVT_TEXT_ENTER, self.OnEnterSubmit)
        self.pwdfake = False
        sizer_pwd.Add(self.pwdtext, flag=wx.EXPAND | wx.BOTTOM, border=10)
        self.rememberchk = wx.CheckBox(simple_panel, label="Remember password.")
        sizer_pwd.Add(self.rememberchk, flag=wx.EXPAND)
        self.rememberchk.Bind(wx.EVT_CHECKBOX, self.OnCheckRememberPwd)
        sizer_pwd.Add(wx.StaticText(simple_panel, label="Do NOT check this if it's a public computer."), flag=wx.TOP, border=3)
        sizer_opts.Add(sizer_pwd, flag=wx.EXPAND)
        
        self.optbtn = bt.GenBitmapTextToggleButton(simple_panel, -1, bitmap=wx.Bitmap(OPT_ICON), style=wx.NO_BORDER, label='Options')
        self.optbtn.Bind(wx.EVT_BUTTON, self.OnToggleOptions)
        sizer_opts.Add(self.optbtn)
        
        sizer_start = wx.BoxSizer(wx.HORIZONTAL)
        sizer_start.Add(sizer_opts, flag=wx.EXPAND| wx.ALL, border=10)
        self.startbtn = bt.GenBitmapButton(simple_panel, -1, bitmap=wx.Bitmap(PLAY_ICON),size=(81,81), style=wx.NO_BORDER)
        if wx.Platform != '__WXMSW__':
            #Some hack
            self.startbtn.SetBackgroundColour(COLOUR_NORMAL)
            self.startbtn.faceDnClr = COLOUR_NORMAL
        else:
            self.startbtn.faceDnClr = self.startbtn.GetBackgroundColour()
        self.startbtn.Bind(wx.EVT_BUTTON, self.OnStart)
        sizer_start.Add(self.startbtn, flag=wx.ALIGN_TOP | wx.ALL, border=10)

        sizer_out = wx.BoxSizer(wx.VERTICAL)
        sizer_out.Add(sizer_start, flag=wx.EXPAND | wx.ALL, border=10)


        simple_panel.SetSizer(sizer_out)
        
        

        adv_panel = wx.Panel(self.out_panel)
        self.adv_panel = adv_panel
        sizer_adv = wx.FlexGridSizer(rows=5, cols=2, vgap=10, hgap=5)
        
        sizer_adv.Add(wx.StaticText(adv_panel, label='Local Proxy:'), flag=wx.EXPAND | wx.TOP, border=3)
        sizer_proxy_out = wx.BoxSizer(wx.VERTICAL)
        self.proxycheck = wx.CheckBox(adv_panel, label='Check this if you are behind a proxy.')
        self.proxycheck.Bind(wx.EVT_CHECKBOX, self.on_check_proxy)
        sizer_proxy_out.Add(self.proxycheck, flag=wx.EXPAND|wx.TOP, border=5)
        sizer_proxy = wx.BoxSizer(wx.HORIZONTAL)
        sizer_proxy.Add(wx.StaticText(adv_panel, label='Host:'), flag=wx.EXPAND | wx.TOP, border=3)
        self.proxytext = wx.TextCtrl(adv_panel, value='', size=(160,-1))
        MyTipWindow(self, self.proxytext, text='Your local proxy. e.g. proxy.company.com')
        sizer_proxy.Add(self.proxytext, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
        sizer_proxy.Add(wx.StaticText(adv_panel, label='Port:'), flag=wx.EXPAND | wx.TOP, border=3)
        self.proxyporttext = nc.NumCtrl( adv_panel, id = -1, value = None, integerWidth=5, allowNone=True, limited=True, limitOnFieldChange=True,selectOnEntry = True, groupDigits = False, min = 1, max = 65535 )
        MyTipWindow(self, self.proxyporttext, text='The port of the proxy. e.g. 8080')
        sizer_proxy.Add(self.proxyporttext, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
        
        sizer_proxy_out.Add(sizer_proxy, flag=wx.TOP, border=5)

        self.proxyauthcheck = wx.CheckBox(adv_panel, label='Check this if proxy requires authentication.')
        sizer_proxy_out.Add(self.proxyauthcheck, flag=wx.EXPAND|wx.TOP, border=5)
        self.proxyauthcheck.Bind(wx.EVT_CHECKBOX, self.on_check_proxy)
        sizer_auth = wx.BoxSizer(wx.HORIZONTAL)
        sizer_auth.Add(wx.StaticText(adv_panel, label='Username:'******'', size=(90,-1))
        sizer_auth.Add(self.proxyusertext, flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=5)
        sizer_auth.Add(wx.StaticText(adv_panel, label='Password:'******'', size=(90,-1), style=wx.TE_PASSWORD)
        sizer_auth.Add(self.proxypwdtext, flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=5)
        sizer_proxy_out.Add(sizer_auth, flag=wx.EXPAND|wx.TOP, border=5)
        
        
        sizer_adv.Add(sizer_proxy_out)

        

        sizer_adv.Add(wx.StaticText(adv_panel, label='Listen port:'), flag=wx.EXPAND | wx.TOP, border=3)
        self.porttext = nc.NumCtrl( adv_panel, id = -1, value = 8000, limited=True, limitOnFieldChange=True,selectOnEntry = True, groupDigits = False, min = 1, max = 65535 )
        MyTipWindow(self, self.porttext, text='The local port Secure GAppProxy listens on. There\'re very few reasons to change this.\nPort number should be from 1 to 65535.')
        sizer_adv.Add(self.porttext)
        
        sizer_adv.Add(wx.StaticText(adv_panel, label='Options:'), flag=wx.EXPAND | wx.TOP, border=3)
        sizer_advopts = wx.BoxSizer(wx.VERTICAL)
        self.httpschk = wx.CheckBox(adv_panel, label='Connect fetch server with HTTPS.')
        sizer_advopts.Add(self.httpschk, flag=wx.EXPAND | wx.BOTTOM, border=10)
        self.hostchk = wx.CheckBox(adv_panel, label='Try to detect and resolve connectivity issues on startup.')
        sizer_advopts.Add(self.hostchk, flag=wx.EXPAND | wx.BOTTOM, border=10)
        if wx.Platform == '__WXMSW__' and common.we_are_frozen():
            self.autostartchk = wx.CheckBox(adv_panel, label='Start proxy with Windows.')
            sizer_advopts.Add(self.autostartchk)
        sizer_adv.Add(sizer_advopts)
        
        ##sizer_adv.Add(wx.StaticText(adv_panel, label='Certificate:'), flag=wx.EXPAND | wx.TOP, border=3)
        ##sizer_certopts = wx.BoxSizer(wx.VERTICAL)
        ##self.clearcachebtn = wx.Button(adv_panel, label='Clear Certificate Cache')
        ##self.clearcachebtn.Bind(wx.EVT_BUTTON, self.on_clear_cert)
        ##sizer_certopts.Add(self.clearcachebtn)
        ##self.installcertbtn = wx.Button(adv_panel, label='Install Root Certificate')
        ##self.installcertbtn.Bind(wx.EVT_BUTTON, self.on_install_cert)
        ##sizer_certopts.Add(self.installcertbtn)
        ##sizer_adv.Add(sizer_certopts)

        sizer_adv_box = wx.BoxSizer(wx.VERTICAL)
        sizer_adv_box.Add(sizer_adv, flag=wx.EXPAND | wx.ALL, border=20)
        

        self.savebtn = wx.Button(adv_panel, size=(-1,35), label='Save and Apply')
        self.savebtn.Bind(wx.EVT_BUTTON, self.OnSaveApply)
        sizer_adv_box.Add((-1, 30))
        sizer_adv_box.Add(self.savebtn, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.RIGHT, border=20)
        
        adv_panel.SetSizer(sizer_adv_box)

        sizer_final = wx.BoxSizer(wx.VERTICAL)
        sizer_final.Add(simple_panel, flag=wx.EXPAND)
        sizer_final.Add(adv_panel, flag=wx.EXPAND)

        self.out_panel.SetSizer(sizer_final)
        
        MyTipWindow(self, self.servertext, text='Fetch server running on GAE. e.g. your-appspot-id.appspot.com')

        self.min_size = sizer_out.GetMinSize().Get()
        w1, h1 = sizer_out.GetMinSize().Get()
        w2, h2 = sizer_adv_box.GetMinSize().Get()
        self.expand_size = (max(w1,w2), h1+h2)
        self.Notify()

        self.Center()
        self.Show(True)
        self.startbtn.SetFocus()


        w,h = self.min_size
        self.statusbar = wx.Panel(simple_panel, style=wx.NO_BORDER, size=(300,25), pos=(w-300, h-35))
        self.statustext='SecureGAppProxy is not running.'
        self.statusicon = wx.Bitmap(RED_ICON)
        self.statusbar.Bind(wx.EVT_PAINT, self.on_paint_status)
        self.statusbar.Refresh()

        self.about_btn = bt.GenBitmapTextButton(adv_panel, -1, bitmap=wx.Bitmap(ABOUTBTN_ICON), style=wx.NO_BORDER, label='About')
        
        self.about_btn.Bind(wx.EVT_BUTTON, self.on_about)
        if wx.Platform != '__WXMSW__':
            self.about_btn.SetBackgroundColour(COLOUR_NORMAL)
            self.about_btn.faceDnClr = COLOUR_NORMAL
        self.about_btn.SetBestSize((-1,-1))
        p1, p2 = adv_panel.GetClientRect().GetBottomLeft().Get()
        q1, q2 = self.about_btn.GetSizeTuple()
        self.about_btn.SetPosition((0, p2-q2))

        if wx.Platform != '__WXMSW__':
            #Set background colour
            self.out_panel.SetBackgroundColour(COLOUR_NORMAL)
            simple_panel.SetBackgroundColour(COLOUR_NORMAL)
            adv_panel.SetBackgroundColour(COLOUR_NORMAL)
            self.statusbar.SetBackgroundColour(COLOUR_NORMAL)
        

        self.LoadConfig()

        #If we have the parameters needed, automatically connect
        if config.GetParam('password') != None and config.GetParam('fetch_server') != '':
            self.OnStart(None)
예제 #5
0
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self,
                          parent,
                          id,
                          title,
                          style=wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX
                          | wx.SYSTEM_MENU | wx.FULL_REPAINT_ON_RESIZE)
        #Initialize proxy core
        self.core = proxycore.ProxyCore(Notifier(self))

        self.start_thread = None

        self.SetIcon(wx.Icon(WND_ICON, wx.BITMAP_TYPE_ICO))
        self.Bind(wx.EVT_CLOSE, self.on_close)

        self.out_panel = wx.Panel(self)

        simple_panel = wx.Panel(self.out_panel)
        self.simple_panel = simple_panel
        sizer_opts = wx.FlexGridSizer(rows=2, cols=2, vgap=10, hgap=5)
        sizer_opts.Add(wx.StaticText(simple_panel, label='Fetch Server:'),
                       flag=wx.EXPAND | wx.TOP,
                       border=3)
        self.servertext = wx.TextCtrl(simple_panel,
                                      value='your-appspot-id.appspot.com',
                                      size=(210, -1),
                                      style=wx.TE_PROCESS_ENTER)
        self.servertext.Bind(wx.EVT_TEXT_ENTER, self.OnEnterSubmit)
        sizer_opts.Add(self.servertext, flag=wx.EXPAND)
        sizer_opts.Add(wx.StaticText(simple_panel, label='Password:'******'',
                                   size=(210, -1),
                                   style=wx.TE_PASSWORD | wx.TE_PROCESS_ENTER)
        self.pwdtext.Bind(wx.EVT_SET_FOCUS, self.OnPwdFocus)
        self.pwdtext.Bind(wx.EVT_TEXT_ENTER, self.OnEnterSubmit)
        self.pwdfake = False
        sizer_pwd.Add(self.pwdtext, flag=wx.EXPAND | wx.BOTTOM, border=10)
        self.rememberchk = wx.CheckBox(simple_panel,
                                       label="Remember password.")
        sizer_pwd.Add(self.rememberchk, flag=wx.EXPAND)
        self.rememberchk.Bind(wx.EVT_CHECKBOX, self.OnCheckRememberPwd)
        sizer_pwd.Add(wx.StaticText(
            simple_panel,
            label="Do NOT check this if it's a public computer."),
                      flag=wx.TOP,
                      border=3)
        sizer_opts.Add(sizer_pwd, flag=wx.EXPAND)

        self.optbtn = bt.GenBitmapTextToggleButton(simple_panel,
                                                   -1,
                                                   bitmap=wx.Bitmap(OPT_ICON),
                                                   style=wx.NO_BORDER,
                                                   label='Options')
        self.optbtn.Bind(wx.EVT_BUTTON, self.OnToggleOptions)
        sizer_opts.Add(self.optbtn)

        sizer_start = wx.BoxSizer(wx.HORIZONTAL)
        sizer_start.Add(sizer_opts, flag=wx.EXPAND | wx.ALL, border=10)
        self.startbtn = bt.GenBitmapButton(simple_panel,
                                           -1,
                                           bitmap=wx.Bitmap(PLAY_ICON),
                                           size=(81, 81),
                                           style=wx.NO_BORDER)
        if wx.Platform != '__WXMSW__':
            #Some hack
            self.startbtn.SetBackgroundColour(COLOUR_NORMAL)
            self.startbtn.faceDnClr = COLOUR_NORMAL
        else:
            self.startbtn.faceDnClr = self.startbtn.GetBackgroundColour()
        self.startbtn.Bind(wx.EVT_BUTTON, self.OnStart)
        sizer_start.Add(self.startbtn, flag=wx.ALIGN_TOP | wx.ALL, border=10)

        sizer_out = wx.BoxSizer(wx.VERTICAL)
        sizer_out.Add(sizer_start, flag=wx.EXPAND | wx.ALL, border=10)

        simple_panel.SetSizer(sizer_out)

        adv_panel = wx.Panel(self.out_panel)
        self.adv_panel = adv_panel
        sizer_adv = wx.FlexGridSizer(rows=5, cols=2, vgap=10, hgap=5)

        sizer_adv.Add(wx.StaticText(adv_panel, label='Local Proxy:'),
                      flag=wx.EXPAND | wx.TOP,
                      border=3)
        sizer_proxy_out = wx.BoxSizer(wx.VERTICAL)
        self.proxycheck = wx.CheckBox(
            adv_panel, label='Check this if you are behind a proxy.')
        self.proxycheck.Bind(wx.EVT_CHECKBOX, self.on_check_proxy)
        sizer_proxy_out.Add(self.proxycheck, flag=wx.EXPAND | wx.TOP, border=5)
        sizer_proxy = wx.BoxSizer(wx.HORIZONTAL)
        sizer_proxy.Add(wx.StaticText(adv_panel, label='Host:'),
                        flag=wx.EXPAND | wx.TOP,
                        border=3)
        self.proxytext = wx.TextCtrl(adv_panel, value='', size=(160, -1))
        MyTipWindow(self,
                    self.proxytext,
                    text='Your local proxy. e.g. proxy.company.com')
        sizer_proxy.Add(self.proxytext,
                        flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
                        border=5)
        sizer_proxy.Add(wx.StaticText(adv_panel, label='Port:'),
                        flag=wx.EXPAND | wx.TOP,
                        border=3)
        self.proxyporttext = nc.NumCtrl(adv_panel,
                                        id=-1,
                                        value=None,
                                        integerWidth=5,
                                        allowNone=True,
                                        limited=True,
                                        limitOnFieldChange=True,
                                        selectOnEntry=True,
                                        groupDigits=False,
                                        min=1,
                                        max=65535)
        MyTipWindow(self,
                    self.proxyporttext,
                    text='The port of the proxy. e.g. 8080')
        sizer_proxy.Add(self.proxyporttext,
                        flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
                        border=5)

        sizer_proxy_out.Add(sizer_proxy, flag=wx.TOP, border=5)

        self.proxyauthcheck = wx.CheckBox(
            adv_panel, label='Check this if proxy requires authentication.')
        sizer_proxy_out.Add(self.proxyauthcheck,
                            flag=wx.EXPAND | wx.TOP,
                            border=5)
        self.proxyauthcheck.Bind(wx.EVT_CHECKBOX, self.on_check_proxy)
        sizer_auth = wx.BoxSizer(wx.HORIZONTAL)
        sizer_auth.Add(wx.StaticText(adv_panel, label='Username:'******'', size=(90, -1))
        sizer_auth.Add(self.proxyusertext,
                       flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
                       border=5)
        sizer_auth.Add(wx.StaticText(adv_panel, label='Password:'******'',
                                        size=(90, -1),
                                        style=wx.TE_PASSWORD)
        sizer_auth.Add(self.proxypwdtext,
                       flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
                       border=5)
        sizer_proxy_out.Add(sizer_auth, flag=wx.EXPAND | wx.TOP, border=5)

        sizer_adv.Add(sizer_proxy_out)

        sizer_adv.Add(wx.StaticText(adv_panel, label='Listen port:'),
                      flag=wx.EXPAND | wx.TOP,
                      border=3)
        self.porttext = nc.NumCtrl(adv_panel,
                                   id=-1,
                                   value=8000,
                                   limited=True,
                                   limitOnFieldChange=True,
                                   selectOnEntry=True,
                                   groupDigits=False,
                                   min=1,
                                   max=65535)
        MyTipWindow(
            self,
            self.porttext,
            text=
            'The local port Secure GAppProxy listens on. There\'re very few reasons to change this.\nPort number should be from 1 to 65535.'
        )
        sizer_adv.Add(self.porttext)

        sizer_adv.Add(wx.StaticText(adv_panel, label='Options:'),
                      flag=wx.EXPAND | wx.TOP,
                      border=3)
        sizer_advopts = wx.BoxSizer(wx.VERTICAL)
        self.httpschk = wx.CheckBox(adv_panel,
                                    label='Connect fetch server with HTTPS.')
        sizer_advopts.Add(self.httpschk, flag=wx.EXPAND | wx.BOTTOM, border=10)
        self.hostchk = wx.CheckBox(
            adv_panel,
            label='Try to detect and resolve connectivity issues on startup.')
        sizer_advopts.Add(self.hostchk, flag=wx.EXPAND | wx.BOTTOM, border=10)
        if wx.Platform == '__WXMSW__' and common.we_are_frozen():
            self.autostartchk = wx.CheckBox(adv_panel,
                                            label='Start proxy with Windows.')
            sizer_advopts.Add(self.autostartchk)
        sizer_adv.Add(sizer_advopts)

        ##sizer_adv.Add(wx.StaticText(adv_panel, label='Certificate:'), flag=wx.EXPAND | wx.TOP, border=3)
        ##sizer_certopts = wx.BoxSizer(wx.VERTICAL)
        ##self.clearcachebtn = wx.Button(adv_panel, label='Clear Certificate Cache')
        ##self.clearcachebtn.Bind(wx.EVT_BUTTON, self.on_clear_cert)
        ##sizer_certopts.Add(self.clearcachebtn)
        ##self.installcertbtn = wx.Button(adv_panel, label='Install Root Certificate')
        ##self.installcertbtn.Bind(wx.EVT_BUTTON, self.on_install_cert)
        ##sizer_certopts.Add(self.installcertbtn)
        ##sizer_adv.Add(sizer_certopts)

        sizer_adv_box = wx.BoxSizer(wx.VERTICAL)
        sizer_adv_box.Add(sizer_adv, flag=wx.EXPAND | wx.ALL, border=20)

        self.savebtn = wx.Button(adv_panel,
                                 size=(-1, 35),
                                 label='Save and Apply')
        self.savebtn.Bind(wx.EVT_BUTTON, self.OnSaveApply)
        sizer_adv_box.Add((-1, 30))
        sizer_adv_box.Add(self.savebtn,
                          flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.RIGHT,
                          border=20)

        adv_panel.SetSizer(sizer_adv_box)

        sizer_final = wx.BoxSizer(wx.VERTICAL)
        sizer_final.Add(simple_panel, flag=wx.EXPAND)
        sizer_final.Add(adv_panel, flag=wx.EXPAND)

        self.out_panel.SetSizer(sizer_final)

        MyTipWindow(
            self,
            self.servertext,
            text='Fetch server running on GAE. e.g. your-appspot-id.appspot.com'
        )

        self.min_size = sizer_out.GetMinSize().Get()
        w1, h1 = sizer_out.GetMinSize().Get()
        w2, h2 = sizer_adv_box.GetMinSize().Get()
        self.expand_size = (max(w1, w2), h1 + h2)
        self.Notify()

        self.Center()
        self.Show(True)
        self.startbtn.SetFocus()

        w, h = self.min_size
        self.statusbar = wx.Panel(simple_panel,
                                  style=wx.NO_BORDER,
                                  size=(300, 25),
                                  pos=(w - 300, h - 35))
        self.statustext = 'SecureGAppProxy is not running.'
        self.statusicon = wx.Bitmap(RED_ICON)
        self.statusbar.Bind(wx.EVT_PAINT, self.on_paint_status)
        self.statusbar.Refresh()

        self.about_btn = bt.GenBitmapTextButton(
            adv_panel,
            -1,
            bitmap=wx.Bitmap(ABOUTBTN_ICON),
            style=wx.NO_BORDER,
            label='About')

        self.about_btn.Bind(wx.EVT_BUTTON, self.on_about)
        if wx.Platform != '__WXMSW__':
            self.about_btn.SetBackgroundColour(COLOUR_NORMAL)
            self.about_btn.faceDnClr = COLOUR_NORMAL
        self.about_btn.SetBestSize((-1, -1))
        p1, p2 = adv_panel.GetClientRect().GetBottomLeft().Get()
        q1, q2 = self.about_btn.GetSizeTuple()
        self.about_btn.SetPosition((0, p2 - q2))

        if wx.Platform != '__WXMSW__':
            #Set background colour
            self.out_panel.SetBackgroundColour(COLOUR_NORMAL)
            simple_panel.SetBackgroundColour(COLOUR_NORMAL)
            adv_panel.SetBackgroundColour(COLOUR_NORMAL)
            self.statusbar.SetBackgroundColour(COLOUR_NORMAL)

        self.LoadConfig()

        #If we have the parameters needed, automatically connect
        if config.GetParam('password') != None and config.GetParam(
                'fetch_server') != '':
            self.OnStart(None)
예제 #6
0
    def SaveConfig(self, simple=False, persistent=True):
        """Save the user settings to the configuration file."""
        config.SetParam('fetch_server', self.servertext.GetValue())
        if self.rememberchk.GetValue() and self.pwdtext.GetValue() != '':
            if not self.pwdfake:
                import pkcs5
                password = pkcs5.PBKDF1(
                    self.pwdtext.GetValue(),
                    config.GetParam('fetch_server').lower())
                config.SetParam('password', password)
                self.pwdfake = True
        else:
            config.DeleteParam('password')

        if not simple:
            config.SetParam('listen_port', self.porttext.GetValue())
            if self.httpschk.GetValue():
                config.SetParam('fetch_protocol', 'https')
            else:
                config.SetParam('fetch_protocol', 'http')

            config.SetParam('auto_redirect', True)

            if self.proxycheck.GetValue():
                if self.proxyauthcheck.GetValue():
                    config.SetParam(
                        'local_proxy',
                        '%s:%s@%s:%d' % (self.proxyusertext.GetValue(),
                                         self.proxypwdtext.GetValue(),
                                         self.proxytext.GetValue(),
                                         self.proxyporttext.GetValue()))
                else:
                    config.SetParam(
                        'local_proxy',
                        '%s:%d' % (self.proxytext.GetValue(),
                                   self.proxyporttext.GetValue()))
            else:
                config.SetParam('local_proxy', '')

            if wx.Platform == '__WXMSW__' and common.we_are_frozen():
                if self.autostartchk.GetValue():
                    try:
                        import _winreg
                        hkey = _winreg.CreateKey(
                            _winreg.HKEY_CURRENT_USER,
                            "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
                        )
                        _winreg.SetValueEx(hkey, "secure-gappproxy", 0,
                                           _winreg.REG_SZ, sys.executable)
                        _winreg.CloseKey(hkey)
                    except:
                        _winreg.CloseKey(hkey)
                else:
                    try:
                        import _winreg
                        hkey = _winreg.CreateKey(
                            _winreg.HKEY_CURRENT_USER,
                            "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
                        )
                        _winreg.DeleteValue(hkey, "secure-gappproxy")
                        _winreg.CloseKey(hkey)
                    except:
                        _winreg.CloseKey(hkey)

        if persistent:
            config.SaveConfig()