def InitGUI(self): self._managers = {} self._managers['services'] = CC.ServicesManager() self._managers[ 'hydrus_sessions'] = HydrusSessions.HydrusSessionManagerClient() self._managers['local_booru'] = CC.LocalBooruCache() self._managers['tag_censorship'] = HydrusTags.TagCensorshipManager() self._managers['tag_siblings'] = HydrusTags.TagSiblingsManager() self._managers['tag_parents'] = HydrusTags.TagParentsManager() self._managers['undo'] = CC.UndoManager() self._managers[ 'web_sessions'] = HydrusSessions.WebSessionManagerClient() self._fullscreen_image_cache = CC.RenderedImageCache('fullscreen') self._preview_image_cache = CC.RenderedImageCache('preview') self._thumbnail_cache = CC.ThumbnailCache() CC.GlobalBMPs.STATICInitialise() self._gui = ClientGUI.FrameGUI() HC.pubsub.sub(self, 'Clipboard', 'clipboard') HC.pubsub.sub(self, 'RestartServer', 'restart_server') HC.pubsub.sub(self, 'RestartBooru', 'restart_booru') self.Bind(wx.EVT_TIMER, self.TIMEREventMaintenance, id=ID_MAINTENANCE_EVENT_TIMER) self._maintenance_event_timer = wx.Timer(self, ID_MAINTENANCE_EVENT_TIMER) self._maintenance_event_timer.Start(MAINTENANCE_PERIOD * 1000, wx.TIMER_CONTINUOUS) # this is because of some bug in wx C++ that doesn't add these by default wx.richtext.RichTextBuffer.AddHandler( wx.richtext.RichTextHTMLHandler()) wx.richtext.RichTextBuffer.AddHandler(wx.richtext.RichTextXMLHandler()) if HC.is_first_start: wx.CallAfter(self._gui.DoFirstStart) if HC.is_db_updated: wx.CallLater( 1, HC.ShowText, 'The client has updated to version ' + HC.u(HC.SOFTWARE_VERSION) + '!') self.RestartServer() self.RestartBooru() self._db.StartDaemons()
def InitModel( self ): HydrusController.HydrusController.InitModel( self ) self._server_session_manager = HydrusSessions.HydrusSessionManagerServer() self._service_keys_to_connected_ports = {}
def InitModel( self ): HydrusController.HydrusController.InitModel( self ) self._server_session_manager = HydrusSessions.HydrusSessionManagerServer() self._services = {} self.sub( self, 'ActionService', 'action_service' )
def OnInit(self): HC.app = self try: self.Bind(HC.EVT_PUBSUB, self.EventPubSub) self._db = ServerDB.DB() threading.Thread(target=self._db.MainLoop, name='Database Main Loop').start() self.Bind(wx.EVT_MENU, self.EventExit, id=wx.ID_EXIT) self._managers = {} self._managers[ 'restricted_services_sessions'] = HydrusSessions.HydrusSessionManagerServer( ) self._managers[ 'messaging_sessions'] = HydrusSessions.HydrusMessagingSessionManagerServer( ) HC.pubsub.sub(self, 'ActionService', 'action_service') self._services = {} # self.Bind(wx.EVT_TIMER, self.TIMEREventMaintenance, id=ID_MAINTENANCE_EVENT_TIMER) self._maintenance_event_timer = wx.Timer( self, ID_MAINTENANCE_EVENT_TIMER) self._maintenance_event_timer.Start(MAINTENANCE_PERIOD * 1000, wx.TIMER_CONTINUOUS) # (service_type, options) = self.Read('service_info', HC.SERVER_ADMIN_KEY) port = options['port'] connection = httplib.HTTPConnection('127.0.0.1', port, timeout=10) try: connection.connect() connection.close() message = 'Something was already bound to port ' + HC.u(port) wx.MessageBox(message) return False except: pass # service_keys = self.Read('service_keys') for service_key in service_keys: self.ActionService(service_key, 'start') self.StartDaemons() if HC.PLATFORM_WINDOWS: self._tbicon = TaskBarIcon() else: stay_open_frame = wx.Frame(None, title='Hydrus Server') stay_open_frame.SetBackgroundColour( wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE)) stay_open_frame.SetIcon( wx.Icon(HC.STATIC_DIR + os.path.sep + 'hydrus.ico', wx.BITMAP_TYPE_ICO)) wx.StaticText(stay_open_frame, label='The hydrus server is now running.' + os.linesep * 2 + 'Close this window to stop it.') (x, y) = stay_open_frame.GetEffectiveMinSize() stay_open_frame.SetInitialSize((x, y)) stay_open_frame.Show() return True except Exception as e: print(traceback.format_exc()) return False
def test_server( self ): discard = HG.test_controller.GetWrite( 'session' ) # just to discard gumph from testserver session_key_1 = HydrusData.GenerateKey() service_key = HydrusData.GenerateKey() permissions = [ HC.GET_DATA, HC.POST_DATA, HC.POST_PETITIONS, HC.RESOLVE_PETITIONS, HC.MANAGE_USERS, HC.GENERAL_ADMIN, HC.EDIT_SERVICES ] access_key = HydrusData.GenerateKey() account_key = HydrusData.GenerateKey() account_type = HydrusNetwork.AccountType.GenerateAdminAccountType( HC.SERVER_ADMIN ) created = HydrusData.GetNow() - 100000 expires = HydrusData.GetNow() + 300 account = HydrusNetwork.Account( account_key, account_type, created, expires ) expires = HydrusData.GetNow() - 10 HG.test_controller.SetRead( 'sessions', [ ( session_key_1, service_key, account, expires ) ] ) session_manager = HydrusSessions.HydrusSessionManagerServer() with self.assertRaises( HydrusExceptions.SessionException ): session_manager.GetAccount( service_key, session_key_1 ) # test fetching a session already in db, after bootup expires = HydrusData.GetNow() + 300 HG.test_controller.SetRead( 'sessions', [ ( session_key_1, service_key, account, expires ) ] ) session_manager = HydrusSessions.HydrusSessionManagerServer() read_account = session_manager.GetAccount( service_key, session_key_1 ) self.assertIs( read_account, account ) # test adding a session expires = HydrusData.GetNow() + 300 account_key_2 = HydrusData.GenerateKey() account_2 = HydrusNetwork.Account( account_key_2, account_type, created, expires ) HG.test_controller.SetRead( 'account_key_from_access_key', account_key_2 ) HG.test_controller.SetRead( 'account', account_2 ) ( session_key_2, expires_2 ) = session_manager.AddSession( service_key, access_key ) [ ( args, kwargs ) ] = HG.test_controller.GetWrite( 'session' ) ( written_session_key, written_service_key, written_account_key, written_expires ) = args self.assertEqual( ( session_key_2, service_key, account_key_2, expires_2 ), ( written_session_key, written_service_key, written_account_key, written_expires ) ) read_account = session_manager.GetAccount( service_key, session_key_2 ) self.assertIs( read_account, account_2 ) # test adding a new session for an account already in the manager HG.test_controller.SetRead( 'account_key_from_access_key', account_key ) HG.test_controller.SetRead( 'account', account ) ( session_key_3, expires_3 ) = session_manager.AddSession( service_key, access_key ) [ ( args, kwargs ) ] = HG.test_controller.GetWrite( 'session' ) ( written_session_key, written_service_key, written_account_key, written_expires ) = args self.assertEqual( ( session_key_3, service_key, account_key, expires_3 ), ( written_session_key, written_service_key, written_account_key, written_expires ) ) read_account = session_manager.GetAccount( service_key, session_key_3 ) self.assertIs( read_account, account ) read_account_original = session_manager.GetAccount( service_key, session_key_1 ) self.assertIs( read_account, read_account_original ) # test individual account refresh expires = HydrusData.GetNow() + 300 updated_account = HydrusNetwork.Account( account_key, account_type, created, expires ) HG.test_controller.SetRead( 'account', updated_account ) session_manager.RefreshAccounts( service_key, [ account_key ] ) read_account = session_manager.GetAccount( service_key, session_key_1 ) self.assertIs( read_account, updated_account ) read_account = session_manager.GetAccount( service_key, session_key_3 ) self.assertIs( read_account, updated_account ) # test all account refresh expires = HydrusData.GetNow() + 300 updated_account_2 = HydrusNetwork.Account( account_key, account_type, created, expires ) HG.test_controller.SetRead( 'sessions', [ ( session_key_1, service_key, updated_account_2, expires ), ( session_key_2, service_key, account_2, expires ), ( session_key_3, service_key, updated_account_2, expires ) ] ) session_manager.RefreshAllAccounts() read_account = session_manager.GetAccount( service_key, session_key_1 ) self.assertIs( read_account, updated_account_2 ) read_account = session_manager.GetAccount( service_key, session_key_2 ) self.assertIs( read_account, account_2 ) read_account = session_manager.GetAccount( service_key, session_key_3 ) self.assertIs( read_account, updated_account_2 )