Exemple #1
0
	def writefile(self,filename,sha1v):
		file = self.getfile(filename)
		path = self.dir+filename
		if os.path.isfile(path):
			input = FileUtil.open(path,"r")
			oldfile = input.read()
			input.close()
		else:
			oldfile = None
		output = FileUtil.open(path,"wb")
		output.write(file)
		print 'Update	'+filename+'				OK!'
		output.close()
		input = FileUtil.open(path,"rb")
		sha1vv = FileUtil.get_file_sha1(input)
		#print sha1v.strip()
		#print sha1vv.strip()
		input.close()
		if sha1v.strip()==sha1vv.strip() :
			print 'Verify	'+filename+'				OK!'
		else:
			print 'Verify	'+filename+'				Fail!'
			if oldfile:
				output = FileUtil.open(path,"wb")
				output.write(oldfile)
				output.close()
			print 'Recover	'+filename+'				OK!'
		if filename.strip() == '/autoupdate.ini'.strip():
			newconfig = Config(__config__)
			newconfig.writeconfig('autoupdate', 'server',common.AUTOUPDATE_SERVER_STR)
			print 'ReWrite	/autoupdate.ini				OK!'
			common.reloadini()
			print 'ReLoad	/autoupdate.ini				OK!'
Exemple #2
0
 def writefile(self, filename, sha1v):
     file = self.getfile(filename)
     path = self.dir + filename
     if os.path.isfile(path):
         input = FileUtil.open(path, "r")
         oldfile = input.read()
         input.close()
     else:
         oldfile = None
     output = FileUtil.open(path, "wb")
     output.write(file)
     print 'Update	' + filename + '				OK!'
     output.close()
     input = FileUtil.open(path, "rb")
     sha1vv = FileUtil.get_file_sha1(input)
     #print sha1v.strip()
     #print sha1vv.strip()
     input.close()
     if sha1v.strip() == sha1vv.strip():
         print 'Verify	' + filename + '				OK!'
     else:
         print 'Verify	' + filename + '				Fail!'
         if oldfile:
             output = FileUtil.open(path, "wb")
             output.write(oldfile)
             output.close()
         print 'Recover	' + filename + '				OK!'
     if filename.strip() == '/autoupdate.ini'.strip():
         newconfig = Config(__config__)
         newconfig.writeconfig('autoupdate', 'server',
                               common.AUTOUPDATE_SERVER_STR)
         print 'ReWrite	/autoupdate.ini				OK!'
         common.reloadini()
         print 'ReLoad	/autoupdate.ini				OK!'
Exemple #3
0
def version():
	input = FileUtil.open(common.CONFIG_GIT,"r")
	gits = input.read().replace('\r\n','\n').split('\n')
	input.close()
	message  = "=============================="
	message += "\r\n"
	message += "Name:"+common.CONFIG_NAMES
	message += "\r\n"
	message += "Author:"+common.CONFIG_AUTHOR
	message += "\r\n"
	message += "Version:"+common.CONFIG_VERSION
	message += "\r\n"
	message += "Now Git Version:"
	message += str(len(gits))
	message += "\r\n"
	message += "Last Git Commit:"
	message += gits[len(gits)-2]
	message += "\r\n"
	message += "Update Time:"
	message += time.strftime("%Y-%m-%d %X",time.localtime())
	message += "\r\n"
	message += "=============================="
	message += "\r\n"
	out = FileUtil.open(common.CONFIG_VERSIONFILE,"w")
	out.write(message)
	out.close
	return message
Exemple #4
0
 def writefile(self, filename, sha1v):
     file = self.getfile(filename)
     path = self.dir + filename
     if os.path.isfile(path):
         input = FileUtil.open(path, "r")
         oldfile = input.read()
         input.close()
     else:
         oldfile = None
     output = FileUtil.open(path, "wb")
     output.write(file)
     print "Update	" + filename + "				OK!"
     output.close()
     input = FileUtil.open(path, "rb")
     sha1vv = FileUtil.get_file_sha1(input)
     # print sha1v.strip()
     # print sha1vv.strip()
     input.close()
     if sha1v.strip() == sha1vv.strip():
         print "Verify	" + filename + "				OK!"
     else:
         print "Verify	" + filename + "				Fail!"
         if oldfile:
             output = FileUtil.open(path, "wb")
             output.write(oldfile)
             output.close()
         print "Recover	" + filename + "				OK!"
     if filename.strip() == "/autoupdate.ini".strip():
         newconfig = Config(__config__)
         newconfig.writeconfig("autoupdate", "server", common.AUTOUPDATE_SERVER_STR)
         print "ReWrite	/autoupdate.ini				OK!"
         common.reloadini()
         print "ReLoad	/autoupdate.ini				OK!"
Exemple #5
0
def do(message,filename):
	FileUtil.if_has_file_remove(filename)
	output = FileUtil.open(filename,"w")
	output.write(sign(message))
	output.close()
	input = FileUtil.open(filename,"r")
	ok = verify(message,input.read())
	input.close()
	return ok
	def getnewsha1(self,path,oldsha1):
		output = FileUtil.open(path,"wb")
		output.write(self.netopen('/'+common.CONFIG_SHA1))
		output.close()
		input = FileUtil.open(path,"r")
		tmp2 = input.read()
		input.close()
		hash = self.netopen('/'+common.CONFIG_SIGN)
		print 'Verifing Hash Table.....'
		ok = verify(tmp2,hash)
		if not ok:
			print 'Verify Failed!'
			sys.exit()
		print 'Verify Successful1!'
Exemple #7
0
 def getnewsha1(self, path, oldsha1):
     output = FileUtil.open(path, "wb")
     output.write(self.getfile('/' + common.CONFIG_SHA1))
     output.close()
     input = FileUtil.open(path, "r")
     tmp2 = input.read()
     input.close()
     hash = self.getfile('/' + common.CONFIG_SIGN)
     print 'Verifing Hash Table.....'
     ok = verify(tmp2, hash)
     if not ok:
         print 'Verify Failed!'
         raise urllib2.HTTPError(filename, '500', 'Verify Failed!', '',
                                 None)
     print 'Verify Successful1!'
Exemple #8
0
def main():
    dir = FileUtil.cur_file_dir()
    os.chdir(dir)
    sys.stdout.write(common.info())
    sys.stdout.write(proxyconfig.info())
    thread.start_new_thread(server.serve_forever, tuple())
    sha1 = makehash(dir)
    while 1:
        try:
            updater = Updater(common.AUTOUPDATE_SERVER[0], sha1, dir)
            updater.update()
            return
        except urllib2.HTTPError:
            print '------------------------------------------------------\n'
            print 'Updata Server Error,Change another one\n'
            print '------------------------------------------------------\n'
            if len(common.AUTOUPDATE_SERVER) > 1:
                common.AUTOUPDATE_SERVER.pop(0)
                sys.stdout.write(common.info())
            else:
                print '------------------------------------------------------\n'
                print 'All Updata Server Is Down,Please Contact Author\n'
                print 'https://code.google.com/p/greatagent/issues/entry\n'
                print '------------------------------------------------------\n'
                return
Exemple #9
0
def sign(message):
	#message = base92.encode(message)
	privatefile = FileUtil.open(common.CONFIG_PRIKEY,'r')
	keydata = privatefile.read()
	prikey = rsa.PrivateKey.load_pkcs1(keydata)
	signature = rsa.sign(message, prikey, 'SHA-1')
	return base92.encode(signature)
Exemple #10
0
def main():
	dir = FileUtil.cur_file_dir()
	os.chdir(dir)
	sys.stdout.write(common.info())
	sys.stdout.write(proxyconfig.info())
	thread.start_new_thread(server.serve_forever, tuple())
	sha1 = makehash(dir)
	while 1:
		try:
			updater = Updater(common.AUTOUPDATE_SERVER[0],sha1,dir)
			updater.update()
			return
		except urllib2.HTTPError:
			print '------------------------------------------------------\n'
			print 'Updata Server Error,Change another one\n'
			print '------------------------------------------------------\n'
			if len(common.AUTOUPDATE_SERVER) > 1:
				common.AUTOUPDATE_SERVER.pop(0)
				sys.stdout.write(common.info())
			else :
				print '------------------------------------------------------\n'
				print 'All Updata Server Is Down,Please Contact Author\n'
				print 'https://code.google.com/p/greatagent/issues/entry\n'
				print '------------------------------------------------------\n'
				return
def main():
	dir = FileUtil.cur_file_dir()
	os.chdir(dir)
	print 'Starting FirefoxPortable...'
	if FileUtil.has_file('FirefoxPortable/FirefoxPortable.exe'):
		os.system('start ./FirefoxPortable/FirefoxPortable.exe  -no-remote "http://www.secretchina.com/fq"')
		return
	else:
		print "Don't Have FirefoxPortable"
		#FileUtil.delete_dir("FirefoxPortable")
	print 'Starting GoogleChromePortable...'
	if  FileUtil.has_file('GoogleChromePortable/GoogleChromePortable.exe'):
		os.system('start ./GoogleChromePortable/GoogleChromePortable.exe   --ignore-certificate-errors  "http://www.secretchina.com/fq"')
		return
	else:
		print "Don't Have GoogleChromePortable"
	print "Don't Have Any Portable Broswer!"
Exemple #12
0
def main():
	dir = FileUtil.cur_file_dir()
	os.chdir(dir)
	print 'Starting FirefoxPortable...'
	if FileUtil.has_file('FirefoxPortable/FirefoxPortable.exe'):
		os.system('start ./FirefoxPortable/FirefoxPortable.exe  -no-remote "http://greatagent-ifanqiang.github.io/greatagent2-wp/ifanqiang.htm"')
		return
	else:
		print "Don't Have FirefoxPortable"
		FileUtil.delete_dir("FirefoxPortable")
	print 'Starting GoogleChromePortable...'
	if  FileUtil.has_file('GoogleChromePortable/GoogleChromePortable.exe'):
		os.system('start ./GoogleChromePortable/GoogleChromePortable.exe   --ignore-certificate-errors  "http://greatagent-ifanqiang.github.io/greatagent2-wp/ifanqiang.htm"')
		return
	else:
		print "Don't Have GoogleChromePortable"
	print 'Starting OperaPortable...'
	if  FileUtil.has_file('OperaPortable/OperaPortable.exe'):
		os.system('start ./OperaPortable/OperaPortable.exe "http://greatagent-ifanqiang.github.io/greatagent2-wp/ifanqiang.htm"')
		return
	else:
		print "Don't Have OperaPortable"
		print 'Starting MaxthonPortable...'
	if  FileUtil.has_file('MaxthonPortable/MaxthonPortable.exe'):
		os.system('start ./MaxthonPortable/MaxthonPortable.exe "http://greatagent-ifanqiang.github.io/greatagent2-wp/ifanqiang.htm"')
		return
	else:
		print "Don't Have MaxthonPortable"
	print "Don't Have Any Portable Broswer!"
def main():
	dir = FileUtil.cur_file_dir()
	os.chdir(dir)
	sys.stdout.write(common.info())
	sys.stdout.write(proxyconfig.info())
	thread.start_new_thread(server.serve_forever, tuple())
	sha1 = makehash(dir)
	updater = Updater(common.AUTOUPDATE_SERVER[0],sha1,dir)
	updater.update()
Exemple #14
0
def verify(message,signature):
	#message = base92.encode(message)
	signature = base92.decode(signature)
	publicfile = FileUtil.open(common.CONFIG_PUBKEY,'r')
	keydata = publicfile.read()
	pubkey = rsa.PublicKey.load_pkcs1(keydata)
	try:
		rsa.verify(message,signature, pubkey)
		return True
	except rsa.pkcs1.VerificationError:
		return False
def makehash(dir,topdown=True):
	try : 
		print 'Generating '+common.CONFIG_SHA1+' table...'
		FileUtil.if_has_file_remove(common.CONFIG_SHA1)
		sha1 = Config(common.CONFIG_SHA1)
		for root, dirs, files in os.walk(dir, topdown):
			for name in files:
				path = os.path.join(root,name)
				newpath = path.replace(dir,'$path$')
				regexpath = path.replace(dir,'.')
				if regexpath.startswith(common.REGEX_START) or regexpath.endswith(common.REGEX_END):
					continue
				else:
					sha1v = FileUtil.sumfile(path)
					sha1.writeconfig('FILE_SHA1',newpath,sha1v)
		print 'DONE generate '+common.CONFIG_SHA1+' table!'
		return sha1
	except Exception as e:
		print 'FAIL to generate '+common.CONFIG_SHA1+' table!'
		print e
		sys.exit()
def main():
    dir = FileUtil.cur_file_dir()
    os.chdir(dir)
    print 'Starting FirefoxPortable...'
    if FileUtil.has_file('FirefoxPortable/FirefoxPortable.exe'):
        os.system(
            'start ./FirefoxPortable/FirefoxPortable.exe  -no-remote "http://www.secretchina.com/fq"'
        )
        return
    else:
        print "Don't Have FirefoxPortable"
        #FileUtil.delete_dir("FirefoxPortable")
    print 'Starting GoogleChromePortable...'
    if FileUtil.has_file('GoogleChromePortable/GoogleChromePortable.exe'):
        os.system(
            'start ./GoogleChromePortable/GoogleChromePortable.exe   --ignore-certificate-errors  "http://www.secretchina.com/fq"'
        )
        return
    else:
        print "Don't Have GoogleChromePortable"
    print "Don't Have Any Portable Broswer!"
Exemple #17
0
 def update(self):
     print "Checking for new update..."
     versionfile = self.netopen("/" + common.CONFIG_VERSIONFILE)
     print "Show Server Version Message:"
     print versionfile
     oldsha1 = self.old_file_sha1_ini
     path = common.CONFIG_SHA1 + ".tmp"
     FileUtil.if_has_file_remove(path)
     self.getnewsha1(path, oldsha1)
     newsha1 = Config(path)
     for path, sha1v in newsha1.getsection("FILE_SHA1"):
         if not (sha1v == oldsha1.getconfig("FILE_SHA1", path)):
             oldpath = path
             path = path.replace("$path$", "")
             path = path.replace("\\", "/")
             self.writefile(path, sha1v)
     FileUtil.if_has_file_remove(path)
     print "Finished Update"
     print "Cleaning DIR"
     self.cleandir()
     print "Finished Clean"
	def update(self):
		print 'Checking for new update...'
		versionfile = self.netopen('/'+common.CONFIG_VERSIONFILE)
		print "Show Server Version Message:"
		print versionfile
		oldsha1 = self.old_file_sha1_ini
		path = common.CONFIG_SHA1+'.tmp'
		FileUtil.if_has_file_remove(path)
		self.getnewsha1(path,oldsha1)
		newsha1 = Config(path)
		for path, sha1v in newsha1.getsection('FILE_SHA1'):
			if not (sha1v == oldsha1.getconfig('FILE_SHA1',path)):
				oldpath = path
				path = path.replace('$path$','')
				path = path.replace('\\','/')
				self.writefile(path,sha1v)
		FileUtil.if_has_file_remove(path)
		print 'Finished Update'
		print 'Cleaning DIR'
		self.cleandir()
		print 'Finished Clean'
Exemple #19
0
def makehash(dir, topdown=True):
    try:
        print 'Generating ' + common.CONFIG_SHA1 + ' table...'
        FileUtil.if_has_file_remove(common.CONFIG_SHA1)
        sha1 = Config(common.CONFIG_SHA1)
        for root, dirs, files in os.walk(dir, topdown):
            for name in files:
                path = os.path.join(root, name)
                newpath = path.replace(dir, '$path$')
                regexpath = path.replace(dir, '.')
                if regexpath.startswith(
                        common.REGEX_START) or regexpath.endswith(
                            common.REGEX_END):
                    continue
                else:
                    sha1v = FileUtil.sumfile(path)
                    sha1.writeconfig('FILE_SHA1', newpath, sha1v)
        print 'DONE generate ' + common.CONFIG_SHA1 + ' table!'
        return sha1
    except Exception as e:
        print 'FAIL to generate ' + common.CONFIG_SHA1 + ' table!'
        print e
        sys.exit()
Exemple #20
0
def main():
	dir = FileUtil.cur_file_dir()
	#print 'now dir : '+dir
	os.chdir(dir)
	input = open(common.CONFIG_SHA1,"r")
	sha1 = input.read()
	input.close()
	print 'Now Signing sha1.ini ...'
	if do(sha1,common.CONFIG_SIGN):
		print 'Sign OK!'
		print version()
	else:
		print 'Sign Fail!'
		sys.exit()
Exemple #21
0
def main():
    dir = FileUtil.cur_file_dir()
    os.chdir(dir)
    print 'Starting FirefoxPortable...'
    if FileUtil.has_file('FirefoxPortable/FirefoxPortable.exe'):
        os.system(
            'start ./FirefoxPortable/FirefoxPortable.exe  -no-remote "http://greatagent-ifanqiang.github.io/greatagent2-wp/ifanqiang.htm"'
        )
        return
    else:
        print "Don't Have FirefoxPortable"
        FileUtil.delete_dir("FirefoxPortable")
    print 'Starting GoogleChromePortable...'
    if FileUtil.has_file('GoogleChromePortable/GoogleChromePortable.exe'):
        os.system(
            'start ./GoogleChromePortable/GoogleChromePortable.exe   --ignore-certificate-errors  "http://greatagent-ifanqiang.github.io/greatagent2-wp/ifanqiang.htm"'
        )
        return
    else:
        print "Don't Have GoogleChromePortable"
    print 'Starting OperaPortable...'
    if FileUtil.has_file('OperaPortable/OperaPortable.exe'):
        os.system(
            'start ./OperaPortable/OperaPortable.exe "http://greatagent-ifanqiang.github.io/greatagent2-wp/ifanqiang.htm"'
        )
        return
    else:
        print "Don't Have OperaPortable"
        print 'Starting MaxthonPortable...'
    if FileUtil.has_file('MaxthonPortable/MaxthonPortable.exe'):
        os.system(
            'start ./MaxthonPortable/MaxthonPortable.exe "http://greatagent-ifanqiang.github.io/greatagent2-wp/ifanqiang.htm"'
        )
        return
    else:
        print "Don't Have MaxthonPortable"
    print "Don't Have Any Portable Broswer!"
	def cleandir(self):
		needclean = Config(common.CONFIG_NEEDCLEAN)
		for path, sha1v in needclean.getsection('NEEDCLEAN'):
			path = path.replace('\\','/')
			path = path.replace('$path$/','')
			FileUtil.if_has_file_remove(path,showinfo = True)
Exemple #23
0
def main():
    dir = FileUtil.cur_file_dir()
    os.chdir(dir)
    #sys.stdout.write(common.info())
    makehash(dir)
Exemple #24
0
import json
from common import FileUtil
import requests
from requests.models import Response
if __name__ == '__main__':
    ruhnnFile = FileUtil.FileUtil()
    url = 'https://movie.douban.com/j/search_subjects'
    header = {
        'User-Agent':
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
    }
    param = {
        'type': 'movie',
        'sort': 'recommend',
        'tag': '%E7%83%AD%E9%97%A8',
        'page_start': '0',
        'page_limit': '20',
    }
    responses = requests.get(url=url, params=param, headers=header)
    list_data = responses.json()
    ruhnnFile.saveJsonToFile('./douban.json', list_data)
Exemple #25
0
 def cleandir(self):
     needclean = Config(common.CONFIG_NEEDCLEAN)
     for path, sha1v in needclean.getsection("NEEDCLEAN"):
         path = path.replace("\\", "/")
         path = path.replace("$path$/", "")
         FileUtil.if_has_file_remove(path, showinfo=True)
def main():
	dir = FileUtil.cur_file_dir()
	os.chdir(dir)
	#sys.stdout.write(common.info())
	makehash(dir)