My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
<!--
2011-05-09
Online interface for Funcoes ZZ (http://funcoeszz.net)

by Aurelio Jargas
http://aurelio.net
@oreio

License: MIT

Note:
Make sure magic_quotes_gpc is turned OFF.
http://php.net/manual/en/security.magicquotes.disabling.php
-->

<html>
<head>
<title>Funções ZZ online</title>
<link rel="icon" type="image/png" href="../img/favicon.png">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
margin: 0 1em;
background: black;
color: #ccc;
}
body, label, #stdin, #stdout, #arguments {
font-family: monospace;
}
#stdin, #stdout, #arguments {
font-size: 100%;
background: white;
color: black;
}
.stderr {
color: red;
}
select, input, #history {
font-size: 100%;
}
#inout {
width: 100%;
border-spacing: 1em;
border-collapse: collapse;
position: fixed;
bottom: 0;
right: 0;
left: 0;
background: #555;
}
#inout td {
border-width: 2px 1em 1em 1em;
border-style: solid;
border-color: #555;
}
#inout label {
color: white;
cursor: help;
}
#stdin, #stdout {
width: 100%;
}
#arguments {
width: 40%;
}
#prompt {
padding-bottom: 10em;
}
#history {
margin-bottom: 0;
line-height: 1.5em;
}
h1 {
text-align: center;
color: lime;
line-height: 80px;
margin: 0;
font-family: Arial,sans-serif;
border-bottom: 1px solid lime;
}
h1 a {
color: lime;
text-decoration: none;
}
h1 a:hover {
text-decoration: underline;
}
.PS1 {
color: lime;
}
.cmdline {
color: white;
}
#help {
display: none; /* disabled */
color: lime;
float: right;
cursor: help;
font-family: Arial;
font-size: 85%;
}
#help-zz {
float: right;
}
#footer {
position: fixed;
right: 1.5em;
bottom: 0.2em;
font-family: Arial,sans-serif;
font-size: 75%;
font-weight: normal;
color: silver;
font-style: italic;
}
#footer a {
color: silver;
}
</style>
</head>
<body>

<h1><a href="..">Funções ZZ</a> online</h1>

<?php
$method = $_SERVER['REQUEST_METHOD'];

// Settings
$api_root = 'http://api.funcoeszz.net/0';
// $api_root = 'http://zzapi.dev/0'; // local
$stdin_max_chars = 10000;
$arguments_max_chars = 250;
$stderr = null;

// POST data
$zzfunc = (empty($_POST['zzfunc'] )) ? null : $_POST['zzfunc'];
$stdin = (empty($_POST['stdin'] )) ? null : $_POST['stdin'];
$stdout = (empty($_POST['stdout'] )) ? null : $_POST['stdout'];
$arguments = (empty($_POST['arguments'])) ? null : $_POST['arguments'];
$history = (empty($_POST['history'] )) ? null : $_POST['history'];
$showhelp = (empty($_POST['showhelp'] )) ? null : $_POST['showhelp'];

// Get from API the list of available functions
// $available = json_decode(file_get_contents("$api_root/list.json"));
$available = json_decode(file_get_contents("list.json")); // cached

// Defaults
if ($method == 'GET') {
// $zzfunc = 'zzcalcula';
// $arguments = '2+2';
$zzfunc = 'zzsenha';
$arguments = '25';
}

/////////////////////////////////////////////////////////////////////

// // Test file/dir access exploit
// foreach($available as $zz) {
// if (in_array($zz, $file_exploit)) continue;
// foreach(array('/etc/passwd', '/etc') as $arg) {
// $cmd = "ZZCOR=0 $funcoeszz $zz $arg";
// print "<h2 style='color:yellow;'>$cmd</h2>";
// passthru("$cmd");
// }
// }
// exit();

/////////////////////////////////////////////////////////////////////
// Button pressed
if ($method == 'POST') {

// Sanity: Max size
if (strlen($arguments) > $arguments_max_chars) {
die("Ops, texto muito extenso nos argumentos da função. O máximo é $arguments_max_chars caracteres.");
}
if (strlen($stdin) > $stdin_max_chars) {
die("Ops, texto muito extenso na STDIN. O máximo é $stdin_max_chars caracteres.");
}

// Make sure we have a line break at the end of history
// Seems like Safari rstrip() the <PRE> contents
if (substr($history, -1) != "\n") {
$history .= "\n";
}

// Call API to show help
if ($showhelp) {
$help = file_get_contents("$api_root/help/${zzfunc}.txt?apikey=e0a7a294");
$stdout = "\n" . trim($help) . "\n\n";

// Call API to run the command
} else {
$results_json = json_decode(
file_get_contents(
"$api_root/run/${zzfunc}.json?" .
"apikey=e0a7a294" .
"&stdin=" . urlencode($stdin) .
"&arg=" . urlencode($arguments)
)
);

// Got results?
if (isset($results_json)) {

// Save STDOUT/STDERR
if (property_exists($results_json, 'stdout')) {
$stdout = $results_json->stdout;
$stderr = trim($results_json->stderr);
} else {
$stdout = $stderr = '';
}

// API errors raised?
if (property_exists($results_json, 'error')) {
$stderr .= $results_json->error;
}
}
}

// Add command to history
$hist_arg = ($showhelp) ? '-h' : $arguments;
$history .= '<span class="PS1">prompt$</span> ';
$history .= '<span class="cmdline">'.htmlspecialchars("$zzfunc $hist_arg", ENT_NOQUOTES).'</span>'."\n";

// Add stdout to history
$history .= htmlspecialchars($stdout, ENT_NOQUOTES);

// Maybe some errors to show?
if (!empty($stderr)) {
$history .=
'<span class="stderr">' .
htmlspecialchars($stderr, ENT_NOQUOTES) .
'</span>' . "\n";
}
}


/////////////////////////////////////////////////////////////////////
?>

<span id="help" title="Use -h na caixa de texto para obter a ajuda da função. Recarregue a página para limpar o histórico de comandos.">?</span>

<form method="post" action="#prompt">

<pre id="history"><?php echo $history; ?></pre> <!-- Leave as one line, do not indent. -->

<div id="prompt">
<span class="PS1">prompt$</span>
<select name="zzfunc" id="zzfunc" size="1">
<?php
foreach ($available as $zz) {
?>
<option value="<?php echo $zz; ?>"<?php if ($zz == $zzfunc) echo ' selected="selected"'; ?>><?php echo $zz; ?></option>
<?php
}
?>
</select>
<input type="text" id="arguments" name="arguments" value="<?php echo htmlspecialchars($arguments); ?>">
<input type="submit" id="submit" value="Enter">
<input type="submit" id="help-zz" value="Ajuda" name="showhelp">
</div><!-- prompt -->

<table id="inout">
<tr>
<td>
<label for="stdin" title="Cole aqui o texto a ser manipulado pela função.">STDIN:</label>
<textarea id="stdin" name="stdin" rows="5"><?php echo htmlspecialchars($stdin); ?></textarea>
</td>
<td>
<label for="stdout" title="Aqui aparece o resultado do último comando.">STDOUT:</label>
<textarea id="stdout" name="stdout" rows="5"><?php echo htmlspecialchars($stdout); ?></textarea>
</td>
</tr>
</table>

<input type="hidden" name="history" id="history" value="<?php echo str_replace('"', '&quot;', htmlspecialchars($history)); ?>">
</form>

<div id="footer">
<a
title="Veja o código-fonte deste webapp e me ajude a melhorá-lo!"
href="http://code.google.com/p/funcoeszz/source/browse/trunk/web/online/index.php">PHP-HTML-CSS</a>
por
<a
title="Quer ajuda? Tem uma sugestão? Achou uma brecha na segurança? Fale comigo no twitter."
href="http://twitter.com/oreio">@oreio</a>

<?php if ($method == 'GET'): ?>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-280222-4";
urchinTracker();
</script>
<?php endif ?>

</body>
</html>

<!--
TODO:
iphone: #inout not really fixed
copy stdout to stdin?
chain commands?
history clicable? (reload command)
timestamp pra cada cmd (tooltip)
JS: mostrar Uso: no onchange do select
-->

Change log

r716 by aureliojargas on Mar 29, 2012   Diff
online: a nova função padrão ao carregar a
página é a zsenha.
Go to: 
Sign in to write a code review

Older revisions

r661 by aureliojargas on Mar 23, 2012   Diff
online: agora usando o /help da API
pra mostrar o texto de ajuda, em vez
de rodar o comando com o -h. Além de
ser mais rápido e eficiente, continua
funcionando mesmo quando o /run da API
...
r653 by aureliojargas on Mar 23, 2012   Diff
online: agora mostra na tela mensagens
de erro enviados pela API.
r652 by aureliojargas on Mar 23, 2012   Diff
online: Testa $results_json antes de
tentar ler suas propriedades.
All revisions of this file

File info

Size: 7508 bytes, 308 lines
Powered by Google Project Hosting