init
This commit is contained in:
commit
bf8958d006
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.idea
|
||||||
|
intercepts
|
||||||
|
venv
|
39
deduplication.py
Normal file
39
deduplication.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
BASE_PATH = 'intercepts'
|
||||||
|
|
||||||
|
|
||||||
|
# As cron record:
|
||||||
|
# zstd --rm -z intercepts/*/*.json 2>&1 | grep -v "No such file or directory -- ignored" && python3 deduplication.py
|
||||||
|
|
||||||
|
def take_hash_from_name(name: str) -> str:
|
||||||
|
return name.split('.')[2]
|
||||||
|
|
||||||
|
|
||||||
|
def remove_unique(files: dict[str, list[Path]]):
|
||||||
|
for file_hash in tuple(files.keys()):
|
||||||
|
files_list = files[file_hash]
|
||||||
|
if len(files_list) == 1:
|
||||||
|
del files[file_hash]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
for host_name in Path(BASE_PATH).iterdir():
|
||||||
|
if host_name.is_dir():
|
||||||
|
files: dict[str, list[Path]] = defaultdict(list)
|
||||||
|
for intercept_file in host_name.iterdir():
|
||||||
|
if intercept_file.is_file():
|
||||||
|
file_hash = take_hash_from_name(intercept_file.name)
|
||||||
|
files[file_hash].append(intercept_file)
|
||||||
|
|
||||||
|
remove_unique(files)
|
||||||
|
|
||||||
|
for duplicated_files in files.values():
|
||||||
|
for file in duplicated_files[1:]:
|
||||||
|
print(f'Removing {file.name}')
|
||||||
|
file.unlink()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
51
tm_intercept_script.js
Normal file
51
tm_intercept_script.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// ==UserScript==
|
||||||
|
// @name XHR Requests logger
|
||||||
|
// @namespace http://tampermonkey.net/
|
||||||
|
// @version 0.2
|
||||||
|
// @description None
|
||||||
|
// @author None
|
||||||
|
// @match https://myshows.me/*
|
||||||
|
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
|
||||||
|
// @grant none
|
||||||
|
// ==/UserScript==
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
(function(open) {
|
||||||
|
XMLHttpRequest.prototype.open = function() {
|
||||||
|
this.addEventListener("load", function() {
|
||||||
|
if (!this.responseURL.includes('/rpc/')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request body
|
||||||
|
// Response body
|
||||||
|
// Status code
|
||||||
|
// Endpoint
|
||||||
|
// Method
|
||||||
|
const request = {
|
||||||
|
"host": document.location.host,
|
||||||
|
"status_code": this.status,
|
||||||
|
"endpoint": this.responseURL,
|
||||||
|
"method": this.__sentry_xhr__.method,
|
||||||
|
"request_body": this.__sentry_xhr__.body,
|
||||||
|
"response_body": this.response
|
||||||
|
};
|
||||||
|
// console.log(this.responseURL, this.response, this.status);
|
||||||
|
// console.log(this)
|
||||||
|
// console.log(JSON.stringify(request))
|
||||||
|
let xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", "https://specify.domain/upload");
|
||||||
|
|
||||||
|
xhr.setRequestHeader("Accept", "application/json");
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
|
xhr.send(JSON.stringify(request));
|
||||||
|
|
||||||
|
}, false);
|
||||||
|
open.apply(this, arguments);
|
||||||
|
};
|
||||||
|
})(XMLHttpRequest.prototype.open);
|
||||||
|
|
||||||
|
})();
|
31
web_log_server.py
Normal file
31
web_log_server.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import falcon
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class Upload:
|
||||||
|
def on_post(self, req: falcon.request.Request, resp: falcon.response.Response):
|
||||||
|
resp.status = falcon.HTTP_OK
|
||||||
|
|
||||||
|
content = req.bounded_stream.read()
|
||||||
|
json_content = json.loads(content)
|
||||||
|
hostname = json_content['host']
|
||||||
|
|
||||||
|
content_hash = hashlib.md5(content).hexdigest()
|
||||||
|
|
||||||
|
file_path = Path('intercepts').joinpath(hostname)
|
||||||
|
file_path.mkdir(exist_ok=True, parents=True)
|
||||||
|
filename = file_path.joinpath(f'{datetime.now().isoformat().replace(":", "-")}.{content_hash}.json')
|
||||||
|
|
||||||
|
with open(filename, mode='bw') as file:
|
||||||
|
file.write(content)
|
||||||
|
|
||||||
|
|
||||||
|
application = falcon.App(cors_enable=True)
|
||||||
|
application.add_route('/upload', Upload())
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import waitress
|
||||||
|
waitress.serve(application, host='127.0.0.1', port=3241)
|
Loading…
x
Reference in New Issue
Block a user