Esempio n. 1
0
def main():
	while True:

		for d in fscomm.devices():
			if d.type != "RemoteControlClient": continue
			if d.publicKeys.sign not in knownClientDevices:
				answer = gui.ask(
					"A new device was found:\n\n" +
					d.user_string() +
					"\nDo you want to allow full access on your computer?\n" +
					"(You can always disable the access again.)")
				devInfo = {}
				knownClientDevices[d.publicKeys.sign] = devInfo
				devInfo["devId"] = d.devId
				devInfo["publicKeys"] = d.publicKeys
				devInfo["allowAccess"] = answer

		for c in localDev.awaitingConnections():
			print "new conn:", c
			if c.srcDev.publicKeys.sign not in knownClientDevices:
				c.refuse("not accepted client " + c.srcDev.devId)
				continue
			if c.connData.intent == "PythonExec.1":
				c.accept()
			else:
				c.refuse("unknown intend '%s'" % c.intent)

		for c in localDev.connections():
			if c.hasCloseRequest():
				c.close()
				continue
			#if time.time() - c.firstTime > 60: # old enough to cleanup
			#	c.close("timeout")
			#	continue
			if not c.isAccepted(): continue
			if c.srcDev.publicKeys.sign not in knownClientDevices:
				print "unknown client issued connection"
				c.close("unknown client")
				continue
			if not knownClientDevices[c.srcDev.publicKeys.sign]["allowAccess"]:
				print "no access for", c.srcDev
				c.close("no access")
				continue
			for p in c.readPackages():
				print "got", repr(p), "from", c.srcDev
				response = {}
				response["seqnr"] = p.seqnr
				evalScope = evalScopes.setdefault(c.srcDev, {
					"srcDev":c.srcDev,
					"dstDev":c.dstDev})
				try:
					ret = eval(p.data, evalScope, evalScope)
					response["ret"] = ret
				except Exception as exc:
					response["exception"] = repr(exc)
				c.sendPackage(response)

		easycfg.save()
		fscomm.wait()
Esempio n. 2
0
	pubSignKey,privSignKey = binstruct.genkeypair()
	localDev.publicKeys = binstruct.Dict({"crypt": pubCryptKey, "sign": pubSignKey})
	localDev.privateKeys = binstruct.Dict({"crypt": privCryptKey, "sign": privSignKey})
	easycfg.save()
localDev.type = "RemoteControlClient"
localDev.appInfo = {"appId":appid, "version":version}

print "fscomm setup ..."
import fscomm
fscomm.setup(appid, localDev)

print "register local dev ..."
localDev = fscomm.registerDev(localDev)

serverDev = None
for d in fscomm.devices():
	if d.type != "RemoteControlServer": continue
	print "found server:", d
	serverDev = d

def pushDataFile(fn):
	# TODO check change-time if needed...
	serverDev.storeData(localDev, fn, open(mydir + "/../pydata/" + fn).read())
	
def execRemotePy(conn, pythonCmd, wait=False):
	conn.sendPackage(pythonCmd)
	print "sent %r ..." % pythonCmd

	while wait:
		for p in conn.readPackages():
			print "got", repr(p), "from", conn.dstDev