Пример #1
0
def getConfig(path=None, NS=None):
    if path == None:
        path = ProgramPath()
    cfname = os.path.abspath(os.path.join(path, "conf", "config.json"))
    # print __name__,cfname
    a = JsonConfig(cfname, NS=NS)
    return a
Пример #2
0
    def checkLicense(self):
        try:
            self.fromLicenseFile()
        except Exception as e:
            print("license file 1", e, ProgramPath(), sys.argv)
            self.registor = False
            return

        macs = [i for i in getAllMacAddress()]
        if self.mac not in [i[0] for i in macs]:
            self.registor = False
            self.ip = '0.0.0.0'
            return
        self.ip = [i[1] for i in macs if i[0] == self.mac][0]
        try:
            f = StringIO.StringIO(self.pubkey)
            key = pickle.load(f)
            f.close()
            s = str(self)
            verstr = rsa.verify(self.rc, key)
            if verstr == s:
                self.registor = True
            else:
                print("check failed 2")
                self.registor = False
        except Exception as e:
            print('4', e)
            print('exception 3', e)
            self.registor = False
            return
Пример #3
0
 def fromLicenseFile(self):
     p = os.path.join(ProgramPath(), 'license.json')
     print("license file name=", p)
     f = open(p, 'r')
     s = f.read()
     f.close()
     self.fromJson(s)
     print(self)
Пример #4
0
 def __init__(self):
     workdir = programPath = ProgramPath()
     if len(sys.argv) > 1:
         workdir = sys.argv[1]
     config = getConfig(workdir, {
         'ProgramPath': programPath,
         'workdir': workdir
     })
     if config.get('databases'):
         DBPools(config.databases)
     initEnv()
     paths = [os.path.abspath(p) for p in config.website.paths]
     resource = BaseResource(paths, indexes=config.website.indexes)
     setupTemplateEngine()
     resource.indexes = config.website.indexes
     resource.processors = config.website.processors
     self.app = MyApp(static=resource)
     resource.app = self.app
Пример #5
0
 def __init__(self, auth_klass=AuthAPI, workdir=None):
     super().__init__()
     if workdir is not None:
         pp = ProgramPath()
         config = getConfig(workdir, {
             'workdir': workdir,
             'ProgramPath': pp
         })
     else:
         config = getConfig()
     if config.databases:
         DBPools(config.databases)
     initEnv()
     setupTemplateEngine()
     self.app = web.Application()
     auth = auth_klass()
     auth.setupAuth(self.app)
     self.configPath(config)
Пример #6
0
def watch():
	workdir = ProgramPath()
	if len(sys.argv)>1:
		workdir = sys.argv[1]
	config = getConfig(workdir)
	observer = Observer()
	for m in config.monitors:
		handler = None
		if m.get('identify_by_ok'):
			print(curdt(),':','using OKFileHandler......')
			handler =OKFileHandler(m,config.peers)
		else:
			handler = FileEventHandler(m,config.peers)
		observer.schedule(handler,m.get('path'),True)
	observer.start()
	try:
		while True:
			yield from asyncio.sleep(1)

	except KeyboardInterrupt:
		observer.stop()
	observer.join()
Пример #7
0
            retdata.update(nodeinfo)
            retdata['cmd'] = 'getpeerinforesp'
        text = json.dumps(retdata)
        msg = self.cpd.setSendData(d.sender, text)
        self.send(msg, d.sender_addr)
        if nodeinfo is None:
            print(self.config.nodeid, 'getpeerinfo(),nodeinfo is none for',
                  d.peername)
            return
        forward = {
            "cmd": "forwardmsg",
            "forwardfrom": d.sender,
            "forwardto": d.peername,
            "forwarddata": self.nodeinfo.get(d.sender)
        }
        text = json.dumps(forward)
        msg = self.cpd.setSendData(d.peername, text)
        self.send(msg, tuple(nodeinfo.internetinfo))


if __name__ == '__main__':
    from appPublic.folderUtils import ProgramPath
    pp = ProgramPath()
    workdir = pp
    if len(sys.argv) > 1:
        workdir = sys.argv[1]
    config = getConfig(workdir, NS={'workdir': workdir, 'ProgramPath': pp})
    loop = asyncio.get_event_loop()
    server = serverFactory(CenterProtocol, '0.0.0.0', config.port)
    loop.run_forever()
Пример #8
0
#genKey.py
import os
from appPublic.printf import printf
import sys
import rsa
import pickle
from appPublic.folderUtils import _mkdir, ProgramPath

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print "Usage:\n%s software_name" % sys.argv[0]
        sys.exit(1)
    p = os.path.join(ProgramPath(), sys.argv[1])
    _mkdir(p)
    pub, pri = rsa.gen_pubpriv_keys(2048)
    printf(pub, pri)
    f = open(os.path.join(p, 'pri.key.dmp'), 'wb')
    pickle.dump(pri, f)
    f.close()
    f = open(os.path.join(p, 'pub.key.dmp'), 'wb')
    pickle.dump(pub, f)
    f.close()
Пример #9
0
                pconf['path1'], pconf['user'], pconf['host'], pconf['tpath1'])
        os.system(s)

    def on_created(self, event):
        print(self.__class__, 'on_create called')
        if event.is_directory:
            print("directory created:{0}".format(event.src_path))
            self.createdir(event.src_path)
        else:
            print('{0} created'.format(event.src_path))
            if endsWith(event.src_path.lower(), '.ok'):
                self.copyfile(event.src_path)


if __name__ == "__main__":
    workdir = ProgramPath()
    if len(sys.argv) > 1:
        workdir = sys.argv[1]
    config = getConfig(workdir)
    observer = Observer()
    for m in config.monitors:
        handler = None
        if m.get('identify_by_ok'):
            print('using OKFileHandler......')
            handler = OKFileHandler(m, config.peers)
        else:
            handler = FileEventHandler(m, config.peers)
        observer.schedule(handler, m.get('path'), True)
    observer.start()
    try:
        while True:
Пример #10
0
        hashes.SHA256()
    )

    # 返回签名数据
    return b''.join([ b'%02x' % i for i in signature ])


if __name__ == '__main__':
	if len(sys.argv)<5:
		print('usage\n%s appkey appname email mac' % sys.argv[0],len(sys.argv),sys.argv)
		sys.exit(1)
	appkey = sys.argv[1]
	appname = sys.argv[2]
	email = sys.argv[3]
	mac = sys.argv[4]
	path = os.path.join(ProgramPath(),appkey)
	if not os.path.exists(path):
		os.mkdir(path)
	pkf = os.path.join(path,'Key.pem')
	pubkf = os.path.join(path,'Key_pub.pem')
	pyf = os.path.join(path,'keybytes.py')
	if not os.path.exists(pkf):
		os.system('openssl genrsa -out ' + pkf + ' -f4 2048')
		os.system('openssl rsa -in ' + pkf + ' -pubout -out ' + pubkf)
	if not os.path.exists(pyf):
		f = open(pubkf,'r')
		kd = f.read()
		f.close()
		b = '''keydata=b"""%s"""
appkey="%s"
appname="%s"''' % (kd,appkey,appname)
Пример #11
0
def debug(s):
	fn = os.path.join(ProgramPath(),"worker_child.log")
	f = open(fn,"a")
	f.write("%s\n" % s)
	f.close()
	pass #print s
Пример #12
0
def getI18N(coding='utf8'):
    path = ProgramPath()
    i18n = MiniI18N(path, coding)
    return i18n