mirror of
https://github.com/mbirth/tcl_ota_check.git
synced 2024-11-09 22:06:47 +00:00
Converted ChecksumRequest to new style.
This commit is contained in:
parent
c824d9c46b
commit
0d1e50abab
21
tclcheck.py
21
tclcheck.py
@ -12,7 +12,7 @@ import sys
|
|||||||
import tcllib
|
import tcllib
|
||||||
import tcllib.argparser
|
import tcllib.argparser
|
||||||
from tcllib.devices import Device
|
from tcllib.devices import Device
|
||||||
from tcllib.requests import RequestRunner, CheckRequest, DownloadRequest, ServerSelector, write_info_if_dumps_found
|
from tcllib.requests import RequestRunner, CheckRequest, DownloadRequest, ChecksumRequest, ServerSelector, write_info_if_dumps_found
|
||||||
from tcllib.xmltools import pretty_xml
|
from tcllib.xmltools import pretty_xml
|
||||||
|
|
||||||
|
|
||||||
@ -88,15 +88,20 @@ dlrres = dlr.get_result()
|
|||||||
print(dlrres.pretty_xml())
|
print(dlrres.pretty_xml())
|
||||||
|
|
||||||
if dlrres.encslaves:
|
if dlrres.encslaves:
|
||||||
chksum_xml = fc.do_checksum(random.choice(encslaves), fileurl, fileurl)
|
cksrunner = RequestRunner(ServerSelector(dlrres.encslaves), https=False)
|
||||||
print(pretty_xml(chksum_xml))
|
cks = ChecksumRequest(dlrres.fileurl, dlrres.fileurl)
|
||||||
file_addr, sha1_body, sha1_enc_footer, sha1_footer = fc.parse_checksum(chksum_xml)
|
cksrunner.run(cks)
|
||||||
|
if not cks.success:
|
||||||
|
print("{}".format(cks.error))
|
||||||
|
sys.exit(4)
|
||||||
|
cksres = cks.get_result()
|
||||||
|
print(cksres.pretty_xml())
|
||||||
|
|
||||||
for s in slaves:
|
for s in dlrres.slaves:
|
||||||
print("http://{}{}".format(s, fileurl))
|
print("http://{}{}".format(s, dlrres.fileurl))
|
||||||
|
|
||||||
for s in s3_slaves:
|
for s in dlrres.s3_slaves:
|
||||||
print("http://{}{}".format(s, s3_fileurl))
|
print("http://{}{}".format(s, dlrres.s3_fileurl))
|
||||||
|
|
||||||
if dev.mode == dev.MODE_STATES["FULL"]:
|
if dev.mode == dev.MODE_STATES["FULL"]:
|
||||||
header = fc.do_encrypt_header(random.choice(encslaves), fileurl)
|
header = fc.do_encrypt_header(random.choice(encslaves), fileurl)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from .checkrequest import CheckRequest
|
from .checkrequest import CheckRequest
|
||||||
from .downloadrequest import DownloadRequest
|
from .downloadrequest import DownloadRequest
|
||||||
|
from .checksumrequest import ChecksumRequest
|
||||||
from .runner import *
|
from .runner import *
|
||||||
from .serverselector import *
|
from .serverselector import *
|
||||||
from .dumpmgr import write_info_if_dumps_found
|
from .dumpmgr import write_info_if_dumps_found
|
||||||
|
42
tcllib/requests/checksumrequest.py
Normal file
42
tcllib/requests/checksumrequest.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
|
import json
|
||||||
|
from .. import credentials, devices
|
||||||
|
from .tclrequest import TclRequest
|
||||||
|
from .tclresult import ChecksumResult
|
||||||
|
|
||||||
|
class ChecksumRequest(TclRequest):
|
||||||
|
def __init__(self, address, file_uri):
|
||||||
|
super().__init__()
|
||||||
|
# NOTE: THIS HAS TO BE RUN ON AN ENCSLAVE
|
||||||
|
self.uri = "/checksum.php"
|
||||||
|
self.method = "POST"
|
||||||
|
self.address = address
|
||||||
|
self.file_uri = file_uri
|
||||||
|
|
||||||
|
def get_headers(self):
|
||||||
|
return {"User-Agent": "tcl"}
|
||||||
|
|
||||||
|
def get_params(self):
|
||||||
|
params = OrderedDict()
|
||||||
|
params.update(credentials.get_creds2())
|
||||||
|
payload = {self.address: self.file_uri}
|
||||||
|
payload_json = json.dumps(payload)
|
||||||
|
params["address"] = bytes(payload_json, "utf-8")
|
||||||
|
return params
|
||||||
|
|
||||||
|
def is_done(self, http_status: int, contents: str) -> bool:
|
||||||
|
if http_status == 200:
|
||||||
|
# <ENCRYPT_FOOTER>2abfa6f6507044fec995efede5d818e62a0b19b5</ENCRYPT_FOOTER> means ERROR (invalid ADDRESS!)
|
||||||
|
if "<ENCRYPT_FOOTER>2abfa6f6507044fec995efede5d818e62a0b19b5</ENCRYPT_FOOTER>" in contents:
|
||||||
|
self.error = "INVALID URI: {}".format(self.file_uri)
|
||||||
|
self.success = False
|
||||||
|
return True
|
||||||
|
self.response = contents
|
||||||
|
self.result = ChecksumResult(contents)
|
||||||
|
self.success = True
|
||||||
|
return True
|
||||||
|
self.error = "HTTP {}".format(http_status)
|
||||||
|
self.success = False
|
||||||
|
return True
|
@ -52,3 +52,13 @@ class DownloadResult(TclResult):
|
|||||||
self.slaves = [s.text for s in slave_list]
|
self.slaves = [s.text for s in slave_list]
|
||||||
self.encslaves = [s.text for s in enc_list]
|
self.encslaves = [s.text for s in enc_list]
|
||||||
self.s3_slaves = [s.text for s in s3_slave_list]
|
self.s3_slaves = [s.text for s in s3_slave_list]
|
||||||
|
|
||||||
|
class ChecksumResult(TclResult):
|
||||||
|
def __init__(self, xml: str):
|
||||||
|
super().__init__(xml)
|
||||||
|
root = ElementTree.fromstring(xml)
|
||||||
|
file = root.find("FILE_CHECKSUM_LIST").find("FILE")
|
||||||
|
self.file_addr = file.find("ADDRESS").text
|
||||||
|
self.sha1_enc_footer = file.find("ENCRYPT_FOOTER").text
|
||||||
|
self.sha1_footer = file.find("FOOTER").text
|
||||||
|
self.sha1_body = file.find("BODY").text
|
||||||
|
Loading…
Reference in New Issue
Block a user