-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
364 lines (329 loc) · 8.58 KB
/
index.php
File metadata and controls
364 lines (329 loc) · 8.58 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<?php
/*
MIT License
Copyright (c) 2022- Arno Richter
https://arnorichter.de
*/
//check for PHP version requirements
if(version_compare(phpversion(), '5.3.0', '<')) die('This requires at least PHP 5.3 to run.');
date_default_timezone_set('Europe/Berlin');
$conversions = array(
array(
'text' => 'UTF-8 Decode',
'function' => function($input) {
return utf8_decode($input);
}
),
array(
'text' => 'UTF-8 Encode',
'function' => function($input) {
return utf8_encode($input);
}
),
array(
'text' => 'Base64 Decode',
'function' => function($input) {
return base64_decode($input);
}
),
array(
'text' => 'Base64 Encode',
'function' => function($input) {
return base64_encode($input);
}
),
array(
'text' => 'JSON Decode',
'function' => function($input) {
return json_decode($input);
}
),
array(
'text' => 'JSON Encode',
'function' => function($input) {
return json_encode($input);
}
),
array(
'text' => 'URL Decode',
'function' => function($input) {
return rawurldecode($input);
}
),
array(
'text' => 'URL Encode',
'function' => function($input) {
return rawurlencode($input);
}
),
array(
'text' => 'Quoted-Printable Decode',
'function' => function($input) {
return quoted_printable_decode($input);
}
),
array(
'text' => 'Quoted-Printable Encode',
'function' => function($input) {
return quoted_printable_encode($input);
}
),
array(
'text' => 'HTMLEntities Decode',
'function' => function($input) {
return html_entity_decode($input);
}
),
array(
'text' => 'HTMLEntities Encode',
'function' => function($input) {
return htmlentities($input);
}
),
array(
'text' => 'HTMLSpecialchars Decode',
'function' => function($input) {
return htmlspecialchars_decode($input);
}
),
array(
'text' => 'HTMLSpecialchars Encode',
'function' => function($input) {
return htmlspecialchars($input);
}
),
array(
'text' => 'wpa_passphrase (ssid,pass)',
'function' => function($input) {
$input = preg_replace('#\s+#', ',', trim($input));
list($ssid, $passphrase) = explode(',', $input, 2);
$psk = hash_pbkdf2('sha1', trim($passphrase), trim($ssid), 4096, 32, true);
return bin2hex($psk);
}
),
array(
'text' => 'Unix Timestamp to String',
'function' => function($input) {
return date('Y-m-d H:i:s', $input);
}
),
array(
'text' => 'String to UNIX Timestamp',
'function' => function($input) {
return strtotime($input);
}
),
array(
'text' => 'Detect Encoding',
'function' => function($input) {
return mb_detect_encoding($input, 'auto');
}
),
array(
'text' => 'Hex to RGB',
'function' => function($input) {
$input = ltrim(trim($input), '#');
if(strlen($input) != 3 && strlen($input) != 6 ) return 'You need to enter either 6-digit or 3-digit hex colors';
$input = (strlen($input) == 3) ? $input[0].$input[0].$input[1].$input[1].$input[2].$input[2] : $input;
//thanks: http://stackoverflow.com/a/15202130/3625228
list($r, $g, $b) = sscanf($input, "%02x%02x%02x");
return $r.','.$g.','.$b.' <span style="display: inline-block; width: 1em; background: #'.$input.';"> </span>';
}
),
array(
'text' => 'String length (UTF-8)',
'function' => function($input) {
return mb_strlen($input, 'UTF-8');
}
),
array(
'text' => 'Clean up white space',
'function' => function($input) {
return preg_replace('/\s+/S', ' ', $input);
}
),
array(
'text' => 'Clean up spaces, preserve newlines',
'function' => function($input) {
$input = preg_replace('/[ \t]+/', ' ', $input);
return preg_replace('/[\r\n]+/', "\n", $input);
}
),
array(
'text' => 'Remove zero-width spaces',
'function' => function($input) {
$input = str_replace("​", "", $input); // remove html entities
$input = str_replace("​", "", $input);
$input = preg_replace("/&[zZ]ero[wW]idth[sS]pace;/", "", $input);
$input = str_replace("\xE2\x80\x8B", "", $input); // remove unencoded
return $input;
}
),
array(
'text' => 'SHA1',
'function' => function($input) {
return hash('sha1', $input);
}
),
array(
'text' => 'SHA256',
'function' => function($input) {
return hash('sha256', $input);
}
),
array(
'text' => 'SHA512',
'function' => function($input) {
return hash('sha512', $input);
}
),
array(
'text' => 'MD5',
'function' => function($input) {
return hash('md5', $input);
}
),
array(
'text' => 'Random string generator',
'function' => function($input) {
$lower = base_convert(mt_rand().microtime(true)/2, 10, 36);
$upper = strtoupper(base_convert(mt_rand().microtime(true)/2, 10, 36));
return str_shuffle($lower.$upper)."\n\n".'123456789 123456789 123456789';
}
)
);
header('Content-Type: text/html; charset=utf-8');
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Converter</title>
<link rel="license" href="./LICENCE" />
<meta name="author" content="Arno Richter" />
<meta name="description" content="Convert between various string encodings (UTF-8, Base64, JSON or Quoted-Printable) and clean up text." />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
* { box-sizing: border-box; }
html {
font: 100%/1.45 Helvetica, Arial, sans-serif;
}
#container {
margin: 0 auto;
width: 98%;
}
#output, form {
margin-bottom: 2em;
word-wrap: break-word;
}
textarea,
#output pre {
font-family: Consolas, Menlo, Andale Mono, monospace;
white-space: pre-wrap;
}
a { color: black; }
h1 {
margin: 0;
}
select, input {
font-size: 1.4em;
}
textarea {
width: 100%;
padding: 0.5em;
min-height: 20em;
font-size: 1em;
resize: vertical;
border: 0;
background: #eee;
}
textarea:focus {
outline: 1px solid #007aff;
}
#tosource, #toclipboard {
color: #007aff;
text-decoration: underline;
display: inline-block;
margin: 0 1em 1em 0;
cursor: pointer;
}
#message {
color: #4cd964;
opacity: 0;
transition: opacity 0.25s ease;
}
#message.show {
opacity: 1;
}
@media all and (min-width: 60em) {
#container {
margin-top: 2em;
width: 60%;
}
}
</style>
</head>
<body>
<div id="container">
<form action="" method="post">
<p>Host this on your own site or extend it: get <a href="https://gist.github.com/oelna/624b1f5376f0b3b9bff593fd1f9b1f24">the Gist</a></p>
<h1>Input</h1>
<textarea name="input" id="input" placeholder="Eingabe"><?php if(isset($_POST['input'])) echo($_POST['input']); ?></textarea>
<select name="conversion">
<?php foreach($conversions as $key => $conversion): ?>
<option value="<?= $key ?>"<?php if(isset($_POST['conversion']) && $key == $_POST['conversion']) echo('selected') ?>><?= $conversion['text'] ?></option>
<?php endforeach; ?>
</select>
<input type="submit" value="Convert" />
</form>
<div id="output">
<h1>Output</h1>
<a id="tosource">Copy to input field</a> <a id="toclipboard">Copy to clipboard</a> <span id="message">Copied!</span>
<code><pre id="output-content"><?php
if(isset($_POST['input']) && isset($_POST['conversion'])) {
$result = call_user_func($conversions[$_POST['conversion']]['function'], $_POST['input']);
echo($result);
}
?></pre></code>
</div>
</div>
<script>
var copyToSource = document.querySelector('#tosource');
var copyToClipboard = document.querySelector('#toclipboard');
var input = document.querySelector('#input');
var output = document.querySelector('#output-content');
var message = document.querySelector('#message');
copyToSource.addEventListener('click', function(e) {
e.preventDefault();
var val = output.innerHTML;
input.value = val;
});
copyToClipboard.addEventListener('click', function(e) {
e.preventDefault();
//as per http://stackoverflow.com/a/987376/3625228
if(document.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(output);
range.select();
} else if(window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(output);
selection.removeAllRanges();
selection.addRange(range);
}
try {
if(!document.execCommand('copy')) {
alert('Could not copy to clipboard');
} else {
message.classList.add('show');
setTimeout(function() {
message.classList.remove('show');
}, 2500);
}
} catch(err) {
alert('Could not copy to clipboard');
}
});
</script>
</body>
</html>