-
Notifications
You must be signed in to change notification settings - Fork 7
/
safeloader.html
112 lines (104 loc) · 3.92 KB
/
safeloader.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TP-Link Stock Firmware Converter</title>
<style>
body {
font-family: arial;
margin: 0 auto;
max-width: 50em;
}
[type="file"] {
border: 0;
clip: rect(0, 0, 0, 0);
height: 1px;
overflow: hidden;
padding: 0;
position: absolute !important;
white-space: nowrap;
width: 1px;
}
[type="file"] + label {
background: #4accd5;
border: none;
border-radius: 5px;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: inherit;
font-weight: bold;
outline: none;
padding: 1rem 1rem;
position: relative;
transition: all 0.3s;
vertical-align: middle;
margin-left: 50%;
transform: translate(-50%, 0);
}
[type="file"]:focus + label,
[type="file"] + label:hover {
background-color: #00bcc4;
}
</style>
</head>
<body>
<p>Use this tool to convert a TP-Link stock firmware to an OpenWrt-compatible sysupgrade file.</p>
<p>This is useful in case you want to return to a stock firmware from OpenWrt.</p>
<p>This tool is based on the <a href="https://github.com/openwrt/openwrt/blob/master/tools/firmware-utils/src/tplink-safeloader.c">TP-Link Safeloader</a>. You may look through the source code to find a list of compatible devices.</p>
<p>You can find stock firmware images at <a href="https://www.tp-link.com/uk/support/download/">the TP-Link website</a>, typically as .bin files.</p>
<input id="file-input" type="file">
<label for="file-input">Browse for a stock firmware image</label>
<p><a href="https://github.com/argsnd/tp-link-stock-firmware-converter">View the source for this tool, build it yourself, and help improve it on GitHub.</a></p>
<script type="text/javascript">
var fileInput = document.getElementById('file-input');
fileInput.onchange = function(event) {
var reader = new FileReader();
var files = event.target.files;
reader.onloadend = function() {
var fileName = "file";
var base64result = reader.result.split(',')[1];
run_safeloader(fileName, base64result);
};
reader.readAsDataURL(files[0]);
};
var Module;
function run_safeloader(fileName, fileData) {
Module = {
print: function(text) { console.log('stdout: ' + text) },
printErr: function(text) { console.error('stderr: ' + text) },
preRun: function() {
FS.createDataFile(".", fileName, atob(fileData), true, true);
},
postRun: function () {
let mime = "application/octet-stream";
let filename = "sysupgrade.bin"
let content = Module.FS.readFile(filename);
console.log(`Offering download of "${filename}", with ${content.length} bytes...`);
var a = document.createElement('a');
a.download = filename;
a.href = URL.createObjectURL(new Blob([content], {type: mime}));
a.style.display = 'none';
document.body.appendChild(a);
a.click();
setTimeout(() => {
document.body.removeChild(a);
URL.revokeObjectURL(a.href);
}, 2000);
},
totalDependencies: 0,
arguments: ["-z", fileName, "-o", "sysupgrade.bin"]
};
var safeloader = document.getElementById('safeloader-runner');
if (safeloader) {
safeloader.remove();
}
safeloader = document.createElement('script');
safeloader.setAttribute('src', 'safeloader.js');
safeloader.setAttribute('id', 'safeloader-runner');
document.head.appendChild(safeloader);
}
</script>
</body>
</html>