Beispiel #1
0
class App(wx.App):
    def __init__(self, logfile,notadmin,cfg,redirect=False, filename=None):
        self.logfile=logfile
        self.notadmin = notadmin
        self.hdnscfg = cfg
        wx.App.__init__(self, redirect, filename)

    def OnInit(self):
        if False:
            wx.MessageDialog(None,u'请以管理员权限运行本程序',u'错误',wx.OK).ShowModal()
            self.ExitMainLoop()
            return True
        self.htcpdns = TCPDNS(self.hdnscfg)
        if self.hdnscfg.notadmin:
            wx.MessageDialog(None,u'请以管理员权限运行本程序',u'错误',wx.OK).ShowModal()
            self.htcpdns.force_close()
            self.ExitMainLoop()
            return True
        self.frame = Frame(None)
        #.Bind(wx.EVT_CLOSE,self.OnExit)
        #self.Bind(wx.EVT_END_SESSION,self.OnExit)
        return True
    def OnExit(self):
        self.hdnscfg.restore()
        self.htcpdns.force_close()
        print '>> OnExit()'
        logfile.flush()
        self.ExitMainLoop()
Beispiel #2
0
class App(wx.App):
    def __init__(self, logfile,notadmin,cfg,redirect=False, filename=None):
        self.logfile=logfile
        self.notadmin = notadmin
        self.hdnscfg = cfg
        wx.App.__init__(self, redirect, filename)

    def OnInit(self):
        if False:
            wx.MessageDialog(None,u'请以管理员权限运行本程序',u'错误',wx.OK).ShowModal()
            self.ExitMainLoop()
            return True
        self.htcpdns = TCPDNS(self.hdnscfg)
        if self.hdnscfg.notadmin:
            wx.MessageDialog(None,u'请以管理员权限运行本程序',u'错误',wx.OK).ShowModal()
            self.htcpdns.force_close()
            self.ExitMainLoop()
            return True
        self.frame = Frame(None)
        #.Bind(wx.EVT_CLOSE,self.OnExit)
        #self.Bind(wx.EVT_END_SESSION,self.OnExit)
        return True
    def OnExit(self):
        self.hdnscfg.restore()
        self.htcpdns.force_close()
        print '>> OnExit()'
        logfile.flush()
        self.ExitMainLoop()
Beispiel #3
0
 def OnInit(self):
     if False:
         wx.MessageDialog(None,u'请以管理员权限运行本程序',u'错误',wx.OK).ShowModal()
         self.ExitMainLoop()
         return True
     self.htcpdns = TCPDNS(self.hdnscfg)
     if self.hdnscfg.notadmin:
         wx.MessageDialog(None,u'请以管理员权限运行本程序',u'错误',wx.OK).ShowModal()
         self.htcpdns.force_close()
         self.ExitMainLoop()
         return True
     self.frame = Frame(None)
     #.Bind(wx.EVT_CLOSE,self.OnExit)
     #self.Bind(wx.EVT_END_SESSION,self.OnExit)
     return True
Beispiel #4
0
 def OnInit(self):
     if False:
         wx.MessageDialog(None,u'请以管理员权限运行本程序',u'错误',wx.OK).ShowModal()
         self.ExitMainLoop()
         return True
     self.htcpdns = TCPDNS(self.hdnscfg)
     if self.hdnscfg.notadmin:
         wx.MessageDialog(None,u'请以管理员权限运行本程序',u'错误',wx.OK).ShowModal()
         self.htcpdns.force_close()
         self.ExitMainLoop()
         return True
     self.frame = Frame(None)
     #.Bind(wx.EVT_CLOSE,self.OnExit)
     #self.Bind(wx.EVT_END_SESSION,self.OnExit)
     return True
Beispiel #5
0
def load(cfg):
    if os.geteuid() !=0:
        print '>> Please run this service as root.'
        os._exit(1)
    if len(sys.argv) == 2:
        if 'start' == sys.argv[1]:
            dns = TCPDNS(cfg) 
            dns.start()
        elif 'stop' == sys.argv[1]:
            dns = Daemon()
            dns.stop()
        elif 'restart' == sys.argv[1]:
            dns = TCPDNS(cfg) 
            dns.restart()
        elif 'censor' == sys.argv[1]:
            dns = UDPDNS(cfg)
            dns.start()
        else:
            print "Unknown command"
            sys.exit(2)
        sys.exit(0)
    else:
        dns = Daemon()
        tmp = dns.getstate()
        print "usage: %s start|stop|restart" % sys.argv[0]
        print "special usage: %s double-recv" % sys.argv[0]
        print '-------------------------------------'
        if tmp:
            print 'The daemon is running'
        else:
            print 'The daemon is stopped'
        sys.exit(2)