def __init__(self, app, host, port, onClose): super(AccountSettingsScreen, self).__init__(app) self.onClose = onClose self.host = host self.port = port area = ScaledArea(50, 140, 924, 570) alpha = 192 if app.displaySettings.alphaOverlays else 255 font = app.screenManager.fonts.bigMenuFont self.tabContainer = TabContainer(self.app, area, font, app.theme.colours.playTabBorder) self.background = elements.SolidRect( self.app, app.theme.colours.playMenu, alpha, Area(AttachedPoint((0, 0), self.tabContainer._getTabRect), TabSize(self.tabContainer))) self.passwordTab = ChangePasswordTab(app, host, onClose=self.close, onSave=self.save) self.tabContainer.addTab(self.passwordTab) self.passwordGetter = self.passwordGUIFactory(self.app) self.elements = [self.background, self.tabContainer] self.protocol = None d = ClientCreator(reactor, amp.AMP).connectTCP(host, port) d.addCallbacks(self.connectionEstablished, self.connectionFailed)
def update_cfg(self, resp): if resp.__class__.__name__ != "query_cfg_response": logger.error('table: %s, query_cfg_response is error', self.name) return None self.query_cfg_response = resp self.app_id = self.query_cfg_response.app_id ds = [] connected_rpc_addrs = {} for partition in self.query_cfg_response.partitions: rpc_addr = partition.primary self.partition_dict[partition.pid.get_pidx()] = rpc_addr if rpc_addr in connected_rpc_addrs or rpc_addr.address == 0: continue host, port = rpc_addr.to_host_port() if rpc_addr in self.session_dict: self.session_dict[rpc_addr].close() d = ClientCreator(reactor, TPegasusThriftClientProtocol, ReplicaSession, TBinaryProtocol.TBinaryProtocolFactory(), None, self.container, self.timeout).connectTCP(host, port, self.timeout) connected_rpc_addrs[rpc_addr] = 1 d.addCallbacks(self.got_conn, self.got_err) ds.append(d) dlist = defer.DeferredList(ds, consumeErrors=True) dlist.addCallback(self.got_results) return dlist
def main(argv): d = ClientCreator(reactor, pbrpc.Protocol).connectTCP(FLAGS.host, FLAGS.port) d.addCallbacks(MakeProxy, ErrorMakingProxy) d.addCallbacks(MakeRequests) d.addCallbacks(PrintResult) d.addCallbacks(lambda x: reactor.stop()) reactor.run() return
def _makeNewProtocol(self, tosend): import twisted.internet.reactor as reactor deferred = Deferred() def makeProtocol(): return SoapProtocol(con=self.con) def sendPacket(protocol): if protocol is None: return # silently fail - log this? TODO protocol.sendPacket(tosend).addCallback(deferred.callback) return protocol conn_d = ClientCreator(reactor, makeProtocol).connectTCP( host=self.con._message_maker._host, port=self.con._message_maker._port) conn_d.addCallback(sendPacket) conn_d.addCallbacks(self._newProtocolConnected, self._onConnectionError) return deferred
def update_cfg(self, resp): if resp.__class__.__name__ != "query_cfg_response": logger.error('table: %s, query_cfg_response is error', self.name) return None self.query_cfg_response = resp self.app_id = self.query_cfg_response.app_id self.partition_count = self.query_cfg_response.partition_count ds = [] connected_rpc_addrs = {} for partition in self.query_cfg_response.partitions: rpc_addr = partition.primary self.partition_dict[partition.pid.get_pidx()] = rpc_addr self.partition_ballot[partition.pid.get_pidx()] = partition.ballot # table is partition split, and child partition is not ready # child requests should be redirected to its parent partition # this will be happened when query meta is called during partition split if partition.ballot < 0: continue if rpc_addr in connected_rpc_addrs or rpc_addr.address == 0: continue host, port = rpc_addr.to_host_port() if rpc_addr in self.session_dict: self.session_dict[rpc_addr].close() d = ClientCreator(reactor, TPegasusThriftClientProtocol, ReplicaSession, TBinaryProtocol.TBinaryProtocolFactory(), None, self.container, self.timeout).connectTCP(host, port, self.timeout) connected_rpc_addrs[rpc_addr] = 1 d.addCallbacks(self.got_conn, self.got_err) ds.append(d) dlist = defer.DeferredList(ds, consumeErrors=True) dlist.addCallback(self.got_results) return dlist
def query(self): ds = [] for (host, port) in self.addr_list: rpc_addr = rpc_address() rpc_addr.from_string(host + ':' + str(port)) if rpc_addr in self.session_dict: self.session_dict[rpc_addr].close() d = ClientCreator(reactor, TPegasusThriftClientProtocol, MetaSession, TBinaryProtocol.TBinaryProtocolFactory(), None, self, self.timeout).connectTCP(host, port, self.timeout) d.addCallbacks(self.got_conn, self.got_err) d.addCallbacks(self.query_one, self.got_err) ds.append(d) dlist = defer.DeferredList(ds, consumeErrors=True) dlist.addCallback(self.got_results) return dlist
def main(args=None): if args is None: args = sys.argv if len(args) == 1: usage(args) return 1 try: opts, extraArgs = getopt.getopt(args[1:], 's:t:u:d:', ['sessionId=', 'target=', 'user='******'domain=', 'targetId=', 'keys=', 'no-mouse', 'no-keyboard', 'no-input', 'title=', 'message='] ) except getopt.GetoptError as err: sys.stderr.write('error parsing args: {0}'.format(err)); return 1 sessionId = int(os.environ.get('OGON_SID', '0')) targetServer = ('127.0.0.1', 9091) targetId = None authUser = None authDomain = '' authPassword = None keySeq = wtsapi.VK_F10 keyModifiers = wtsapi.REMOTECONTROL_KBDALT_HOTKEY shadowFlags = 0 userTitle = None userMessage = None userWait = True for option, value in opts: if option in ('-s', '--sessionId',): sessionId = int(value) elif option in ('-t', '--target',): tokens = value.split(':', 2) targetServer = (tokens[0], int(tokens[1])) elif option in ('--targetId',): targetId = int(value) elif option in ('-u', '--user',): tokens = value.split('@', 2) authUser = tokens[0] if len(tokens) > 1: authDomain = tokens[1] elif option in ('-d', '--domain',): authDomain = value elif option in ('--keys',): tokens = value.split('+') keyModifiers = 0 keySeq = 0 for k in tokens: if k in modifiersNames: keyModifiers |= modifiersNames[k] elif k in wtsapi.VK: keySeq = wtsapi.VK[k] if keySeq == 0: print('missing key in key sequence') sys.exit(1) elif option in ('--no-mouse',): shadowFlags |= wtsapi.REMOTECONTROL_FLAG_DISABLE_MOUSE elif option in ('--no-keyboard',): shadowFlags |= wtsapi.REMOTECONTROL_FLAG_DISABLE_KEYBOARD elif option in ('--no-input',): shadowFlags |= wtsapi.REMOTECONTROL_FLAG_DISABLE_INPUT elif option in ('--title',): userTitle = value elif option in ('--message',): userMessage = value elif option in ('--nowait',): userWait = False else: print('unknown option {0}'.format(option)) sys.exit(1) if not len(extraArgs): usage(args) sys.exit(1) authPassword = authUser command = extraArgs[0] @inlineCallbacks def executeCommand(conn): try: # ping the topka to see if it is running client = conn.client ret = yield client.ping(0xff) if ret != 0xff: raise Exception('topka sessionManager not running') doKillToken = False authToken = '' if command in ('listSessions', 'logoffSession', 'sessionDetails', 'startShadowing', 'stopShadowing', 'sendMessage',): # commands that need the authentication token (doKillToken, authToken) = yield getAuthToken(client, authUser, authDomain, authPassword) if command == 'getVersion': v = TVersion(1, 1) ret = yield client.getVersionInfo(v) print("remote version is {0}.{1}".format(ret.VersionMajor, ret.VersionMinor)) elif command == 'listSessions': print("listing sessions:") ret = yield client.enumerateSessions(authToken, 1) if not ret.returnValue: print('error listing sessions') else: print('id\tstate\thostname') for s in ret.sessionInfoList: state = sessionStateNames.get(s.connectState, "<unknown {0}>".format(s.connectState)) print("{0}\t{1}\t{2}".format(s.sessionId, state, s.winStationName)) print('{0} sessions'.format(len(ret.sessionInfoList))) elif command == 'logoffSession': # bool logoffSession(1:TSTRING authToken, 2:TDWORD sessionId, 3:TBOOL wait); ret = yield client.logoffSession(authToken, sessionId, True) print("loggingOff session {0}: {1}".format(sessionId, ret and 'success' or 'failure')) elif command == 'sessionDetails': ret = yield client.querySessionInformation(authToken, sessionId, wtsapi.WTSSessionInfo) if not ret.returnValue: print("an error occured when querying session informations") else: wtsinfo = ret.infoValue.WTSINFO print ("session details for {0}:".format(wtsinfo.SessionId)) if wtsinfo.UserName: fullUser = wtsinfo.UserName + "@" + wtsinfo.Domain else: fullUser = "******" currentTime = wtsinfo.CurrentTime print(" * state: {0}".format( sessionStateNames.get(wtsinfo.State, "<unknown {0}>".format(wtsinfo.State))) ) print(" * user/domain: {0}".format(fullUser)) print(" * stationName: {0}".format(wtsinfo.WinStationName)) connectTime = utils.fromFileTime(wtsinfo.ConnectTime) print(" * connect time: {0}".format(time.strftime("%H:%M:%S-%d %b %Y", connectTime))) print(" * traffic stats: in={0}({1}) out={2}({3})" .format(wtsinfo.IncomingBytes, wtsinfo.IncomingFrames, wtsinfo.OutgoingBytes, wtsinfo.OutgoingFrames)) elif command == 'startShadowing': ret = yield client.startRemoteControlSession(authToken, sessionId, targetId, keySeq, keyModifiers, shadowFlags) if not ret: print ('error enabling shadowing') elif command == 'stopShadowing': ret = yield client.stopRemoteControlSession(authToken, sessionId, targetId) if not ret: print ('error stopping shadowing') elif command == 'sendMessage': ret = yield client.sendMessage(authToken, sessionId, userTitle, userMessage, wtsapi.MB_OK, 10, userWait); if doKillToken: ret = yield client.logoffConnection(authToken) if not ret: print("unable to kill authenticated connection") except: traceback.print_exc() reactor.stop() def connectError(e): print('error={0}'.format(e)) reactor.stop() client = ClientCreator(reactor, TTwisted.ThriftClientProtocol, otsapi.Client, TBinaryProtocol.TBinaryProtocolFactory(), ).connectSSL(targetServer[0], targetServer[1], ssl.ClientContextFactory()) client.addCallbacks(executeCommand, connectError) reactor.run() return 0