123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- from selenium import webdriver
- from selenium.webdriver.support.ui import WebDriverWait
- from sqlalchemy import Column,String,create_engine
- from sqlalchemy.orm import sessionmaker
- from sqlalchemy.ext.declarative import declarative_base
- import pyodbc
- import pandas as pd
- import traceback
- import csv
- import rsa
- import requests
- import binascii
- import json
- Base = declarative_base()
-
- class User(Base):
-
- __tablename__ = '客戶資料表'
-
- 客戶 = Column(String(20), primary_key=True)
- 資料庫 = Column(String(20))
- IP位置 = Column(String(20))
- 帳號 = Column(String(20))
- 密碼 = Column(String(20))
- class Someoneupdate(Base):
- __tablename__ = '自動導入判斷'
- 正在自動導入中= Column(String(20), primary_key=True)
- class CustomerDataVerify(Base):
- __tablename__ = '商客基本資料表'
- 網址= Column(String(20), primary_key=True)
- 帳號= Column(String(20), primary_key=True)
- 密碼= Column(String(20), primary_key=True)
- 驗證= Column(String(20))
-
- def LongFirstLogin(urlkey,adminkey,passkey):
- try:
- print(urlkey)
- pubkey="B0C1D0E12B47DA93A24C7422D433170A4D5B126A27CED6F3087652723562889803E2280041F02E6B24A251C928EBE5BA12501D466D63A43AD5D88A5809A09271F14FD220C0DAE272CAAF9F1CF09DAF52005272529071723C0CB87B5A6392860CA2E72B23A4652910DB87BAC31D89E4DD23B3C56AAE685D9A14C4CC89862AAA27"
- rsaPublickey = int(pubkey,16)
- key = rsa.PublicKey(rsaPublickey,65537)
- message='{\"Account\":\"'+adminkey+'\",\"Password\":\"'+passkey+'\"}'
- message=message.encode('utf8')
- #passwd = rsa.encrypt(message,key)
- passwd = binascii.b2a_hex(rsa.encrypt(message,key)).decode()
- Loginurl="http://"+urlkey+"/api/shared/login"
-
- headers1 = {
- 'Content-Length': '256',
- 'Content-Type': 'application/x-www-form-urlencoded'
- }
-
- response = requests.request("POST", Loginurl, headers=headers1, data=passwd)
-
- return response
- except:
- response="無法取得資料"
- print(response)
- return response
-
- def LongSecondLogin(LFLresponse):
- try:
-
- LFLresponseJson=json.loads(LFLresponse.text)
- print(LFLresponseJson)
- SecondLoginUrl=LFLresponseJson['Redirect']
- SecondLoginData=LFLresponseJson['Data']
-
- headers2 = {
- 'Content-Length': '514',
- 'Content-Type': 'application/x-www-form-urlencoded'
- }
- print(SecondLoginUrl)#debug
- GatewayUrl="http:"+SecondLoginUrl
- print(GatewayUrl)
- LoginGatewayPostData="+="+SecondLoginData
- response2 = requests.request("POST", GatewayUrl, headers=headers2, data=LoginGatewayPostData)
- return SecondLoginUrl,SecondLoginData,response2
- except:
- SecondLoginUrl=""
- SecondLoginData=""
- response2=""
- return SecondLoginUrl,SecondLoginData,response2
- def LongGetData(urlkey, adminkey, passkey):
-
- LFLresponse=LongFirstLogin(urlkey,adminkey,passkey)
- if LFLresponse=="無法取得資料":
- fordebugger="websiteerror"
-
- return fordebugger
- if LFLresponse.status_code==200:
- SecondLoginUrl,SecondLoginData,LSLresponse=LongSecondLogin(LFLresponse)
- if LSLresponse=="":
- fordebugger="ADPSERROR"
- return fordebugger
- else:
- fordebugger="OK"
- return fordebugger
-
- if LFLresponse.status_code!=200:
- fordebugger=ShortGetData(urlkey, adminkey, passkey)
-
- return fordebugger
-
-
-
- def ShortGetData(urlkey, adminkey, passkey):
-
- sloginUrl = "https://"+urlkey+"/pub/SuperGateway.php?c=900%2C"+adminkey+"%2C"+passkey
-
- response = requests.request("POST", sloginUrl)
- print(response.text)
- if response.status_code==200:
- if len(response.text)>3:
- SIDKey=response.text.split(',')[2]
- if len(SIDKey)<5:
- SIDKey=response.text.split(',')[3]
- print(SIDKey)
- AMKey=SIDKey.split('_')[0]
- print(AMKey)
- fordebugger="OK"
- return fordebugger
- else:
- fordebugger="ADPSERROR"
- return fordebugger
-
- if response.status_code!=200:
- fordebugger="ADPSERROR"
- return fordebugger
-
-
- def loadCSV():
- try:
- with open('000.csv', newline='') as csvfile:
-
- rows = csv.reader(csvfile)
- csvvrow=[]
- for row in rows:
- csvvrow.append(row)
- coustomtxt=(csvvrow[1][0])
- bdtxtcrypto=(csvvrow[2][0])
-
- #====================================解密==========================
- PRIVATTTTT=693199020841184529005187339596013597950466957598599888793608033530271219415853952414609432155441426597962873618644988823224505129033188472492232565627111731743840442387622658441932249274048207290194890312931801018119336565101207159089093817844379836520246765598761731093447853178093855957965143730121353938159096214435813116478583463281838568325696377260624492699103838269489173425735163766515881745838239102851526971498900537039965925229366981233886305256752613857576375123305107336285923247046744901857058559811348110224118414002814652550587381981742663420856507553321403129123387307759852585845583253705194423896104474967966535066409675943348475929657759428664521337873475544406762447015072876289975051669953965932555224693025757002523361150649200905802416556626834350633483715061798581642291839762255979334372982156774414505811030453728205541010293992016524698689810201483053731487961892768615175941360043106707261541518852778287823654935902238415934276399863697899069150965902889645358960710613979521286008786269668237598187906056491031301559442316212834296436205439154886053776090316790598915161638161668892006476380622662058436463540372859165165728327478177043147902958378365406901451035507793539047616182219516942468776336379
- #PrivateKey
- A1=435136098972877768874748645248339158125703956065257805897130489515873898645785064137580564100320503666838498219287367368030775233887671705599248600291953393231454780648861079171195672717473628632853618453449217420455794237632155291175461656351373149436294485404694429947256530385791280349340495413483412113186857182441596591220416636342090069157129915377951859333634936029548424638926391232291634636038258059603109206715187896810765799441703590963590776385210580000409455669280693512175818186066741512695081131148497030784289903926969375944559780083722346620544362180693184053719440253987062360057770451705216722616373945761278697477867656454308042535057052004210508850990364826097246310462235289453838547367442863138161099765610183693493835956264409463595891562624222255540841617618186384919177648960630843478742501992844305124096538648231123014949030890404247398161443680124720970242595119682693770042136274011065565273819531541118246115073819134261046370918950429149073365625538812772489582690787721407799409054150416184648077711942774002489730938839028835996373562349388498470086161265863994312489374464512279091382150353090705188164569282723516063722137626802108564462453248942121100848000690940344201632450119420978307322308945
- A2=9627714051932950193134188501742994592784042206914443459734438308841410040354738469881718445461422881776007294906803790685427277699734850787185938262102876531473114260174800542552232307443022494368143100728406826855674366796656059054215802558213346170105688323652674928367680251460924362233864869984871966783909100785712414620921144535418728448391075664442600744983428543175164409720230286595771434578391588137898216407341812591598354427012529961000712417819821596260309468611766323842906019082923549785615976305556417630687246871293866806059225782724368215141401076633953519395967986211659258251543120569378038365122086876706827618666557619122782700896147
- A3=72000374865933143340744306653169834428832683081115110740204100237805467875781399111076588189449270231784547205065314993551385284482420372845976820023615822918370850049018336485262561074750111640775157594829249815372287322731748252778906894672575675394415480712584447066603079224388770970172603768779881242086210954654794512868330782099170594476257989194451530266257956383540560124814995186866139904562390161487741092810396910518052928540664299189962055810713116703112503213279177866017925218355080344908808970420740591501342146164000394175136511345019472809580649061686926648057
- bdtxtcrypto=bdtxtcrypto.encode('utf8')
- print(bdtxtcrypto)
- print(type(bdtxtcrypto))
- bdtxtcrypto=binascii.a2b_hex(bdtxtcrypto)
- mmmmm=rsa.decrypt(bdtxtcrypto,rsa.PrivateKey(PRIVATTTTT,65537,A1,A2,A3))
- bdtxt=(mmmmm.decode('utf8'))
- #====================================解密==========================
-
- return coustomtxt,bdtxt
- except:
- traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
- traceback.print_exc(file=open('log.txt', 'a'))
-
- def connectEngine(coustomtxt):
- try:
-
- DB_session = sessionmaker(engine)
- db_session = DB_session()
- comDbUserData=db_session.query(User).filter(User.客戶.like(coustomtxt)).all()
-
- UserDbName=comDbUserData[0].資料庫
- UserIPName=comDbUserData[0].IP位置
- UserAdName=comDbUserData[0].帳號
- UserPdName=comDbUserData[0].密碼
-
- engine3 = create_engine('mssql+pyodbc://'+UserAdName+':'+UserPdName+'@'+UserIPName+'/'+UserDbName+'?driver=SQL+Server+Native+Client+11.0')
- return engine3
- except:
- traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
- traceback.print_exc(file=open('log.txt', 'a'))
-
- def LoadCustomData(engine3):
- try:
-
-
- text3="SELECT TOP(1000) 網址, 帳號, 密碼 FROM 商客基本資料表"
-
- loopper2=pd.read_sql(text3,engine3)
-
- contforloop=len(loopper2)
- loopper2=loopper2.values
- print(loopper2)
- return contforloop,loopper2
- except:
- traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
- traceback.print_exc(file=open('log.txt', 'a'))
-
- def UpdateVerify():
- Verifying=db_session2.query(CustomerDataVerify).filter_by(網址=urlkey,帳號=adminkey,密碼=passkey).first()
- Verifyingc=db_session2.query(CustomerDataVerify).filter_by(網址=urlkey,帳號=adminkey,密碼=passkey).count()
- print(Verifying)
- print("Have SQLData :"+str(Verifyingc))
- if (Verifyingc==1):
- Verifying.驗證=VerifyStr
- db_session2.commit()
-
- try:
- coustomtxt,bdtxt=loadCSV()
- engine = create_engine('mssql+pyodbc://'+bdtxt+'?driver=SQL+Server+Native+Client+11.0')
- engine3=connectEngine(coustomtxt)
- DB_session2 = sessionmaker(engine3)
- db_session2= DB_session2()
- def LoadingYesorNo():
- SUPDA=db_session2.query(Someoneupdate).filter_by(正在自動導入中='YES').first()
- SUPDAc=db_session2.query(Someoneupdate).filter_by(正在自動導入中='YES').count()
- print(SUPDAc)
- if (SUPDAc==1):
- SUPDA.正在自動導入中='NO'
- db_session2.commit()
- contforloop,loopper2=LoadCustomData(engine3)
-
- for z in range (contforloop):
-
- urlkey=loopper2[z][0]
- print(urlkey)
- adminkey=loopper2[z][1]
- passkey=loopper2[z][2]
- tttt2=LongGetData(urlkey, adminkey, passkey)
-
-
-
- if tttt2=="OK":
- VerifyStr="已驗證"
- UpdateVerify()
-
- elif tttt2=="websiteerror":
- VerifyStr="網址錯誤"
- UpdateVerify()
-
-
- elif tttt2=="ADPSERROR":
- VerifyStr="帳號密碼錯誤"
- UpdateVerify()
- LoadingYesorNo()
-
- except:
- traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
- traceback.print_exc(file=open('lorverrorlog.txt', 'a'))
- print("NNNNNNNNN2N")
- finally:
- LoadingYesorNo()
|