rev |
line source |
pankso@2
|
1 #!/bin/sh
|
pankso@2
|
2 #
|
al@419
|
3 # Main CGI interface for TazPanel. In on word: KISS. Use the main CSS form
|
paul@52
|
4 # command so we are faster and do not load unneeded functions. If necessary
|
pankso@14
|
5 # you can use the lib/ dir to handle external resources.
|
pankso@2
|
6 #
|
al@419
|
7 # Copyright (C) 2011-2015 SliTaz GNU/Linux - BSD License
|
pankso@42
|
8 #
|
pankso@2
|
9
|
al@419
|
10
|
pankso@14
|
11 # Common functions from libtazpanel
|
al@419
|
12
|
pankso@14
|
13 . lib/libtazpanel
|
pankso@14
|
14 get_config
|
pankso@2
|
15
|
al@292
|
16 TITLE="TazPanel"
|
al@292
|
17
|
al@419
|
18
|
al@419
|
19
|
paul@127
|
20 # Check whether a configuration file has been modified after installation
|
al@419
|
21
|
al@437
|
22 file_is_modified() {
|
pascal@91
|
23 grep -l " $1$" $INSTALLED/*/md5sum | while read file; do
|
al@292
|
24
|
al@419
|
25 # Found, but can we do diff?
|
pascal@91
|
26 [ "$(grep -h " $1$" $file)" != "$(md5sum $1)" ] || break
|
al@419
|
27 orig=$(dirname $file)/volatile.cpio.gz
|
al@419
|
28 zcat $orig 2>/dev/null | cpio -t 2>/dev/null | grep -q "^${1#/}$" || break
|
pascal@91
|
29
|
pascal@91
|
30 case "$2" in
|
al@419
|
31 diff)
|
al@419
|
32 tmp=$(mktemp -d)
|
al@419
|
33 ( cd $tmp; zcat $orig | cpio -id ${1#/} )
|
al@419
|
34 diff -abu $tmp$1 $1 | sed "s|$tmp||"
|
al@419
|
35 rm -rf $tmp;;
|
al@419
|
36 button)
|
al@437
|
37 echo -n '<button name="action" value="diff" data-icon="diff">'$(_ 'Differences')'</button>';;
|
pascal@91
|
38 esac
|
pascal@93
|
39 break
|
pascal@91
|
40 done
|
pascal@91
|
41 }
|
al@312
|
42
|
al@312
|
43
|
al@419
|
44
|
al@303
|
45 # OK status in table
|
al@419
|
46
|
al@303
|
47 ok_status_t() {
|
al@419
|
48 echo '<td><span class="diff-add" data-img="ok"></span></td></tr>'
|
al@303
|
49 }
|
al@303
|
50
|
al@303
|
51
|
al@419
|
52
|
al@437
|
53 # Terminal prompt
|
al@437
|
54
|
al@437
|
55 term_prompt() {
|
al@437
|
56 if [ "$user" == 'root' ]; then
|
al@437
|
57 local color1='color31' sign='#'
|
al@437
|
58 else
|
al@437
|
59 local color1='color32' sign='$'
|
al@437
|
60 fi
|
al@437
|
61 echo -n "<span class='$color1'>$user@$(hostname)</span>:<span class='color33'>"
|
al@437
|
62 pwd | sed "s|^$HOME|~|" | tr -d '\n'; echo -n "</span>$sign "
|
al@437
|
63 }
|
al@437
|
64
|
al@437
|
65
|
al@437
|
66
|
pankso@2
|
67 #
|
pankso@49
|
68 # Things to do before displaying the page
|
pankso@49
|
69 #
|
pankso@49
|
70
|
pascal@81
|
71 [ -n "$(GET panel_pass)" ] &&
|
pascal@81
|
72 sed -i s@/:root:.*@/:root:$(GET panel_pass)@ $HTTPD_CONF
|
pankso@49
|
73
|
al@419
|
74
|
al@419
|
75
|
al@419
|
76
|
al@419
|
77
|
pankso@49
|
78 #
|
pankso@2
|
79 # Commands
|
pankso@2
|
80 #
|
pankso@2
|
81
|
pascal@81
|
82 case " $(GET) " in
|
al@419
|
83
|
al@419
|
84
|
pascal@364
|
85 *\ exec\ *)
|
al@419
|
86 # Execute command and display its result in a terminal-like window
|
al@419
|
87
|
al@443
|
88 header; TITLE=$(_ 'TazPanel - exec'); xhtml_header
|
al@419
|
89
|
pascal@364
|
90 exec="$(GET exec)"
|
al@419
|
91 font="${TERM_FONT:-monospace}"
|
al@419
|
92 palette=$(echo $TERM_PALETTE | tr A-Z a-z)
|
al@419
|
93
|
al@419
|
94 cat <<EOT
|
al@419
|
95 <section>
|
al@419
|
96 <header>
|
al@419
|
97 $exec
|
al@419
|
98 $(back_button "$(GET back)" "$(GET back_caption)" "$(GET back_icon)")
|
al@419
|
99 </header>
|
al@419
|
100 <div class="term_">
|
al@419
|
101 <pre class="term $palette" style="font-family: '$font'">$($exec 2>&1 | htmlize | filter_taztools_msgs)</pre>
|
al@419
|
102 </div>
|
al@419
|
103 </section>
|
pascal@364
|
104 EOT
|
pascal@364
|
105 ;;
|
al@419
|
106
|
al@419
|
107
|
pascal@81
|
108 *\ file\ *)
|
pankso@56
|
109 #
|
pascal@91
|
110 # Handle files
|
pankso@56
|
111 #
|
al@419
|
112 header
|
pascal@81
|
113 file="$(GET file)"
|
al@419
|
114 action="$(POST action)"; [ -z "$action" ] && action="$(GET action)" # receive 'action' both on POST or GET
|
al@463
|
115 title="$(POST title)"; [ -z "$title" ] && title="$(GET title)" # (optional)
|
al@419
|
116
|
pankso@161
|
117 case $file in
|
pankso@161
|
118 *.html)
|
al@419
|
119 cat $file; exit 0 ;;
|
pankso@161
|
120 *)
|
al@443
|
121 TITLE=$(_ 'TazPanel - File'); xhtml_header ;;
|
pankso@161
|
122 esac
|
al@303
|
123
|
al@419
|
124 case "$action" in
|
al@419
|
125 edit)
|
al@419
|
126 cat <<EOT
|
al@419
|
127 <section>
|
al@419
|
128 <header>
|
al@463
|
129 <span data-icon="edit">${title:-$file}</span>
|
al@463
|
130 <form id="editform" method="post" action="?file=$file">
|
al@443
|
131 <button data-icon="save">$(_ 'Save')</button>
|
al@443
|
132 <button name="action" value="diff" data-icon="diff">$(_ 'Differences')</button>
|
al@419
|
133 </form>
|
al@419
|
134 </header>
|
al@419
|
135 <textarea form="editform" name="content" class="wide" rows="30" autofocus>$(cat $file | htmlize)</textarea>
|
al@419
|
136 </section>
|
pascal@90
|
137 EOT
|
naitsirhc@267
|
138 #The space before textarea gets muddled when the form is submitted.
|
naitsirhc@267
|
139 #It prevents anything else from getting messed up
|
al@419
|
140 ;;
|
al@419
|
141
|
al@419
|
142 setvar)
|
pascal@364
|
143 data="$(. $(GET file) ;eval echo \$$(GET var))"
|
pascal@364
|
144 cat <<EOT
|
al@419
|
145 <section>
|
al@419
|
146 <header>$(GET var)</header>
|
al@419
|
147 <form method="post" action="?file=$file" class="nogap">
|
al@419
|
148 <input type="hidden" name="var" value="$(GET var)">
|
al@419
|
149 <input type="text" name="content" value="${data:-$(GET default)}">
|
al@443
|
150 <button type="submit" data-icon="save">$(_ 'Save')</button>
|
al@419
|
151 </form>
|
al@419
|
152 </section>
|
pascal@364
|
153 EOT
|
al@419
|
154 ;;
|
al@419
|
155
|
al@419
|
156 diff)
|
al@419
|
157 cat <<EOT
|
al@419
|
158 <section>
|
al@419
|
159 <pre id="diff">$(file_is_modified $file diff | syntax_highlighter diff)</pre>
|
al@419
|
160 </section>
|
al@419
|
161 EOT
|
al@419
|
162 ;;
|
al@419
|
163
|
al@419
|
164 *)
|
al@340
|
165 R=$(echo -en '\r')
|
pascal@364
|
166 if [ -n "$(POST content)" ]; then
|
pascal@364
|
167 if [ -n "$(POST var)" ]; then
|
pascal@364
|
168 sed -i "s|^\\($(POST var)=\\).*|\1\"$(POST content)\"|" $file
|
pascal@364
|
169 else
|
pascal@364
|
170 sed "s/$R /\n/g;s/$R%0//g" > $file <<EOT
|
pascal@90
|
171 $(POST content)
|
pascal@90
|
172 EOT
|
pascal@364
|
173 fi
|
pascal@364
|
174 fi
|
al@419
|
175
|
pascal@90
|
176 cat <<EOT
|
al@463
|
177 <section class="bigNoScrollable">
|
al@439
|
178 <header>
|
al@463
|
179 <span data-icon="text">${title:-$file}</span>
|
pascal@433
|
180 EOT
|
pascal@444
|
181 if [ -w "$file" ]; then
|
pascal@444
|
182 cat <<EOT
|
al@463
|
183 <span class="float-right">
|
al@463
|
184 <button onclick='editFile()' id="edit_button" data-icon="edit">$(_ 'Edit')</button>
|
al@463
|
185 <button onclick='saveFile("$file", "$title")' id="save_button"
|
al@463
|
186 data-icon="save" style="display:none">$(_ 'Save')</button>
|
al@463
|
187 </span>
|
al@463
|
188 <!--form>
|
al@419
|
189 <input type="hidden" name="file" value="$file"/>
|
al@443
|
190 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button><!--
|
al@419
|
191 -->$(file_is_modified $file button)
|
al@463
|
192 </form-->
|
pascal@433
|
193 EOT
|
pascal@444
|
194 elif [ -r "$file" ]; then
|
pascal@444
|
195 cat <<EOT
|
pascal@444
|
196 <form>
|
pascal@444
|
197 <input type="hidden" name="file" value="$file"/>
|
pascal@444
|
198 $(file_is_modified $file button)
|
pascal@444
|
199 </form>
|
pascal@444
|
200 EOT
|
pascal@444
|
201 fi
|
pascal@433
|
202 cat <<EOT
|
al@439
|
203 </header>
|
al@439
|
204
|
al@419
|
205 <div>
|
al@463
|
206 <pre id="fileContent" class="bigScrollable">
|
al@303
|
207 EOT
|
al@463
|
208 end_code=''
|
pascal@90
|
209 # Handle file type by extension as a Web Server does it.
|
pascal@90
|
210 case "$file" in
|
al@463
|
211 *.sh|*.cgi|*/receipt|*.conf)
|
al@463
|
212 echo '<code class="language-bash">'; end_code='</code>'
|
al@463
|
213 cat | htmlize ;;
|
al@463
|
214 *.ini)
|
al@463
|
215 echo '<code class="language-ini">'; end_code='</code>'
|
al@463
|
216 cat | htmlize ;;
|
pascal@90
|
217 *.conf|*.lst)
|
pascal@90
|
218 syntax_highlighter conf ;;
|
al@419
|
219 *Xorg.0.log)
|
al@419
|
220 syntax_highlighter xlog ;;
|
al@419
|
221 *dmesg.log)
|
al@419
|
222 syntax_highlighter kernel ;;
|
pascal@90
|
223 *)
|
al@303
|
224 cat | htmlize ;;
|
pascal@90
|
225 esac < $file
|
al@419
|
226 cat <<EOT
|
al@463
|
227 $end_code</pre>
|
al@419
|
228 </div>
|
al@419
|
229 </section>
|
al@419
|
230 EOT
|
al@419
|
231 esac
|
al@419
|
232 ;;
|
al@419
|
233
|
al@303
|
234
|
al@312
|
235
|
pankso@191
|
236 *\ terminal\ *|*\ cmd\ *)
|
al@419
|
237 # Cmdline terminal
|
al@419
|
238
|
al@443
|
239 header; TITLE=$(_ 'TazPanel - Terminal'); xhtml_header
|
al@419
|
240
|
al@437
|
241 user="$REMOTE_USER"
|
al@437
|
242 HOME="$(awk -F: -vu=$user '$1==u{print $6}' /etc/passwd)"
|
al@437
|
243 historyfile="$HOME/.ash_history"
|
al@437
|
244
|
pankso@191
|
245 cmd=$(GET cmd)
|
al@437
|
246 path="$(GET path)"; path="${path:-/tmp}"; cd "$path"
|
al@419
|
247
|
al@419
|
248 font="${TERM_FONT:-monospace}"
|
al@419
|
249 palette=$(echo $TERM_PALETTE | tr A-Z a-z)
|
al@419
|
250
|
al@419
|
251 [ -n "$cmd" -a "$cmd" != "$(tail -n1 $historyfile)" ] && echo "$cmd" >> $historyfile
|
al@419
|
252
|
al@419
|
253
|
al@419
|
254 # Terminal history
|
al@419
|
255
|
al@419
|
256 if [ "$cmd" == 'history' ]; then
|
al@419
|
257 cat <<EOT
|
al@312
|
258 <section>
|
al@419
|
259 <header>
|
al@443
|
260 $(_ 'History')
|
al@443
|
261 <form><button name="terminal" data-icon="terminal">$(_ 'Back')</button></form>
|
al@419
|
262 </header>
|
al@419
|
263 <form>
|
al@419
|
264 <input type="hidden" name="path" value="$path"/>
|
al@419
|
265 <pre class="term $palette" style="font-family: '$font'">
|
pankso@191
|
266 EOT
|
al@443
|
267 htmlize < $historyfile | awk -vrun="$(_ 'run')" -vpath="$path" '
|
al@419
|
268 BEGIN { num=1 }
|
al@419
|
269 {
|
al@419
|
270 printf("%3d ", num);
|
al@419
|
271 cmd = $0
|
al@419
|
272 gsub("%", "%25", cmd); gsub("+", "%2B", cmd); gsub(" ", "+", cmd);
|
al@419
|
273 gsub("\"", "%22", cmd); gsub("!", "%21", cmd); gsub("'\''", "%27", cmd);
|
al@419
|
274 printf("<a data-icon=\"run\" href=\"?cmd=%s&path=%s\">%s</a> ", cmd, path, run);
|
al@419
|
275 printf("<input type=\"checkbox\" name=\"rm\" value=\"%d\" id=\"hist%d\">", num, num);
|
al@419
|
276 printf("<label for=\"hist%d\">%s</label>\n", num, $0);
|
al@419
|
277 num++
|
al@419
|
278 }'
|
al@419
|
279 cat <<EOT
|
al@419
|
280 </pre>
|
al@419
|
281 <footer>
|
al@443
|
282 <button name="rmhistory" data-icon="remove">$(_ 'Clear')</button>
|
al@419
|
283 </footer>
|
al@419
|
284 </form>
|
al@419
|
285 </section>
|
al@419
|
286 EOT
|
al@419
|
287 xhtml_footer
|
al@419
|
288 exit 0
|
al@419
|
289 fi
|
al@419
|
290
|
al@419
|
291
|
al@419
|
292 # Terminal window
|
al@419
|
293
|
al@419
|
294 cat <<EOT
|
al@419
|
295 <span id="num_hist"></span>
|
al@419
|
296 <section>
|
al@419
|
297 <pre class="term $palette" style="font-family: '$font'" onclick="document.getElementById('typeField').focus()">
|
al@419
|
298 EOT
|
al@419
|
299 if [ -n "$cmd" ]; then
|
al@437
|
300 term_prompt
|
al@419
|
301 echo "$cmd" | htmlize
|
al@419
|
302 fi
|
al@419
|
303
|
al@419
|
304 case "$cmd" in
|
pankso@191
|
305 usage|help)
|
al@443
|
306 _ 'Small non-interactive terminal emulator.'; echo
|
al@463
|
307 _ 'Run any command at your own risk, avoid interactive commands (%s)' 'nano, mc, ...'; echo
|
al@419
|
308 ;;
|
pankso@191
|
309 wget*)
|
pankso@191
|
310 dl=/var/cache/downloads
|
pankso@191
|
311 [ ! -d "$dl" ] && mkdir -p $dl
|
al@443
|
312 _ 'Downloading to: %s' $dl; echo
|
al@419
|
313 cd $dl; $cmd 2>&1 ;;
|
al@419
|
314 cd|cd\ *)
|
al@437
|
315 path="${cmd#cd}"; path="${path:-$HOME}";
|
al@437
|
316 path="$(realpath $path)"; cd "$path" ;;
|
al@419
|
317 ls|ls\ *)
|
al@419
|
318 $cmd -w80 --color=always 2>&1 | filter_taztools_msgs ;;
|
al@419
|
319 cat)
|
pankso@194
|
320 # Cmd must be used with an arg.
|
al@443
|
321 _ '%s needs an argument' "$cmd" ;;
|
al@443
|
322 mc|nano|su)
|
al@419
|
323 # List of restricted (interactive) commands
|
al@443
|
324 _ "Please, don't run interactive command \"%s\"" "$cmd"; echo; echo ;;
|
pankso@191
|
325 *)
|
al@419
|
326 unset HTTP_REFERER # for fooling /lib/libtaz.sh formatting utils (<hr> in the terminal is so-so)
|
al@419
|
327 export DISPLAY=:0.0 # for run X applications
|
al@419
|
328 /bin/sh -c "$cmd" 2>&1 | htmlize | filter_taztools_msgs
|
al@419
|
329 ;;
|
pankso@191
|
330 esac
|
al@419
|
331
|
al@419
|
332 cat <<EOT
|
al@419
|
333 <form id="term">
|
al@437
|
334 <div class="cmdline" id="cmdline"><span id="prompt">$(term_prompt)</span><span id="typeField"> </span></div>
|
al@437
|
335 <input type="hidden" name="path" value="$(pwd)"/>
|
al@419
|
336 <input type="hidden" name="cmd" id="cmd"/>
|
al@419
|
337 </form>
|
al@419
|
338 </pre>
|
al@419
|
339 </section>
|
al@419
|
340
|
al@419
|
341 <form>
|
al@443
|
342 <button name="termsettings" data-icon="settings">$(_ 'Settings')</button>
|
al@443
|
343 <button name="cmd" value="history" data-icon="history">$(_ 'History')</button>
|
al@419
|
344 </form>
|
al@419
|
345
|
al@419
|
346 <script type="text/javascript">
|
al@419
|
347 with (document.getElementById('typeField')) {
|
al@419
|
348 contentEditable=true;
|
al@419
|
349 focus();
|
al@419
|
350 }
|
al@419
|
351 document.onkeydown=keydownHandler;
|
al@419
|
352 EOT
|
al@419
|
353
|
al@419
|
354 # Export history as array.
|
al@419
|
355 # Escape "all \"quotes\" in quotes", and all '\'
|
al@419
|
356 # (because \u, \x, \c has special meaning and can produce syntax error and stop js)
|
al@419
|
357 sed 's|\\|\\\\|g; s|"|\\"|g' $historyfile | awk '
|
al@419
|
358 BEGIN{ i=1; printf("ash_history=[") }
|
al@419
|
359 { printf("\"%s\",", $0); i++ }
|
al@419
|
360 END{
|
al@419
|
361 printf("\"\"];")
|
al@419
|
362 i--; printf("cur_hist=\"%d\";max_hist=\"%d\";", i, i)
|
al@419
|
363 }'
|
al@419
|
364 cat <<EOT
|
al@419
|
365 </script>
|
al@419
|
366 EOT
|
al@312
|
367 ;;
|
al@312
|
368
|
al@312
|
369
|
al@419
|
370 *\ rmhistory\ *)
|
al@419
|
371 # Manage shell commandline history
|
al@437
|
372 user="$REMOTE_USER"
|
al@437
|
373 [ -z "$HOME" ] && HOME="$(awk -F: -vu=$user '$1==u{print $6}' /etc/passwd)"
|
al@437
|
374 historyfile="$HOME/.ash_history"
|
al@419
|
375
|
al@419
|
376 # Return sed command for removing history lines ('8d12d' to remove 8 and 12 lines)
|
al@419
|
377 rms=$(echo $QUERY_STRING | awk 'BEGIN{RS="&";FS="="}{if($1=="rm")printf "%dd", $2}')
|
al@419
|
378
|
al@419
|
379 if [ -n "$rms" ]; then
|
al@419
|
380 # Actually remove lines
|
al@419
|
381 sed -i $rms $historyfile
|
al@419
|
382 # Redirects back to the history table
|
al@419
|
383 header "HTTP/1.1 301 Moved Permanently" "Location: ?terminal&cmd=history&path=$(GET path)"
|
al@419
|
384 exit 0
|
al@419
|
385 fi
|
al@419
|
386 ;;
|
al@419
|
387
|
al@419
|
388
|
al@419
|
389 *\ termsettings\ *)
|
al@419
|
390 # Terminal settings
|
al@443
|
391 TITLE=$(_ 'TazPanel - Terminal'); header; xhtml_header;
|
al@419
|
392 user="$REMOTE_USER"
|
al@419
|
393 font="$(GET font)"; font="${font:-$TERM_FONT}"
|
al@419
|
394 palette="$(GET palette)"; palette="${palette:-$TERM_PALETTE}"
|
al@419
|
395 pal=$(echo $palette | tr A-Z a-z)
|
al@419
|
396
|
al@419
|
397 # Add or change settings in TazPanel config
|
al@419
|
398 if [ -z "$TERM_FONT" ]; then
|
al@419
|
399 echo -e "\n# Terminal font family\nTERM_FONT=\"$font\"" >> $CONFIG
|
al@419
|
400 else
|
al@419
|
401 sed -i "s|TERM_FONT=.*|TERM_FONT=\"$font\"|" $CONFIG
|
al@419
|
402 fi
|
al@419
|
403 if [ -z "$TERM_PALETTE" ]; then
|
al@419
|
404 echo -e "\n# Terminal color palette\nTERM_PALETTE=\"$palette\"" >> $CONFIG
|
al@419
|
405 else
|
al@419
|
406 sed -i "s|TERM_PALETTE=.*|TERM_PALETTE=\"$palette\"|" $CONFIG
|
al@419
|
407 fi
|
al@419
|
408
|
al@419
|
409 cat <<EOT
|
al@463
|
410 <section style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: 0.5rem;">
|
al@419
|
411 <header>
|
al@443
|
412 $(_ 'Terminal settings')
|
al@419
|
413 <form>
|
al@443
|
414 <button name="terminal" data-icon="terminal">$(_ 'Terminal')</button>
|
al@419
|
415 </form>
|
al@419
|
416 </header>
|
al@419
|
417 <pre class="term $pal" style="height: auto; font-family: '$font'">
|
al@419
|
418 <span class='color31'>$user@$(hostname)</span>:<span class='color33'>~</span># palette
|
al@419
|
419
|
al@419
|
420 $(
|
al@419
|
421 for i in $(seq 30 37); do
|
al@419
|
422 for b in 0 1; do
|
al@419
|
423 for j in $(seq 40 47); do
|
al@419
|
424 echo -n "<span class=\"color$b color$i color$j\">$i:$j</span>"
|
al@419
|
425 done
|
al@419
|
426 done
|
al@419
|
427 echo
|
al@419
|
428 done
|
al@419
|
429 )
|
al@419
|
430 </pre>
|
al@419
|
431 <footer>
|
al@419
|
432 <form class="wide">
|
al@443
|
433 $(_ 'Font:')
|
al@419
|
434 <select name="font">
|
al@443
|
435 <option value="">$(_ 'Default')</option>
|
al@419
|
436 $(fc-list :spacing=mono:lang=en family | sed '/\.pcf/d;/,/d;s|\\-|-|g' | sort -u | \
|
al@419
|
437 awk -vfont="$font" '{
|
al@419
|
438 printf("<option value=\"%s\"%s>%s</option>\n", $0, ($0 == font)?" selected":"", $0)
|
al@419
|
439 }')
|
al@419
|
440 </select>
|
al@443
|
441 $(_ 'Palette:')
|
al@419
|
442 <select name="palette">
|
al@419
|
443 $(echo -e 'Tango\nLinux\nXterm\nRxvt\nEcho' | awk -vpal="$palette" '{
|
al@419
|
444 printf("<option value=\"%s\"%s>%s</option>\n", $0, ($0 == pal)?" selected":"", $0)
|
al@419
|
445 }')
|
al@419
|
446 </select>
|
al@443
|
447 <button name="termsettings" data-icon="ok">$(_ 'Apply')</button>
|
al@419
|
448 </form>
|
al@419
|
449 </footer>
|
al@419
|
450 </section>
|
al@419
|
451 EOT
|
al@419
|
452
|
al@419
|
453 ;;
|
al@419
|
454
|
al@419
|
455
|
pascal@144
|
456 *\ top\ *)
|
al@443
|
457 header; TITLE=$(_ 'TazPanel - Process activity'); xhtml_header
|
al@419
|
458
|
al@419
|
459 r=$(GET refresh)
|
al@419
|
460 cat <<EOT
|
al@419
|
461 <form>
|
al@443
|
462 <p>$(_ 'Refresh:')
|
naitsirhc@268
|
463 <input type="hidden" name="top"/>
|
al@419
|
464 <input type="radio" name="refresh" value="1" id="r1" $([ "$r" == 1 ] && echo checked) onchange="this.form.submit()"/>
|
al@443
|
465 <label for="r1">$(_ '1s' )</label>
|
al@419
|
466 <input type="radio" name="refresh" value="5" id="r2" $([ "$r" == 5 ] && echo checked) onchange="this.form.submit()"/>
|
al@443
|
467 <label for="r2">$(_ '5s' )</label>
|
al@419
|
468 <input type="radio" name="refresh" value="10" id="r3" $([ "$r" == 10 ] && echo checked) onchange="this.form.submit()"/>
|
al@443
|
469 <label for="r3">$(_ '10s' )</label>
|
al@419
|
470 <input type="radio" name="refresh" value="" id="r4" $([ -z "$r" ] && echo checked) onchange="this.form.submit()"/>
|
al@443
|
471 <label for="r4">$(_ 'none')</label>
|
al@419
|
472 </p>
|
al@303
|
473 </form>
|
al@303
|
474 EOT
|
al@419
|
475 [ -n "$r" ] && echo "<meta http-equiv=\"refresh\" content=\"$r\">"
|
naitsirhc@268
|
476
|
al@419
|
477 echo '<section><div><pre class="term log">'
|
al@303
|
478 top -n1 -b | htmlize | sed \
|
al@419
|
479 -e 's|^[A-Z].*:|<span class="color1 color31">\0</span>|g' \
|
al@419
|
480 -e 's|^\ *PID|<span class="color1 color32">\0</span>|g'
|
al@419
|
481 echo '</pre></div></section>' ;;
|
al@303
|
482
|
al@312
|
483
|
pascal@81
|
484 *\ debug\ *)
|
al@443
|
485 header; TITLE=$(_ 'TazPanel - Debug'); xhtml_header
|
al@419
|
486
|
al@419
|
487 cat <<EOT
|
al@443
|
488 <h2>$(_ 'HTTP Environment')</h2>
|
al@303
|
489
|
al@419
|
490 <section>
|
al@419
|
491 <div>
|
al@419
|
492 <pre>$(httpinfo | syntax_highlighter conf)</pre>
|
al@419
|
493 </div>
|
al@419
|
494 </section>
|
al@303
|
495 EOT
|
al@303
|
496 ;;
|
al@303
|
497
|
al@312
|
498
|
pankso@161
|
499 *\ report\ *)
|
al@443
|
500 header; TITLE=$(_ 'TazPanel - System report'); xhtml_header
|
al@419
|
501
|
pascal@163
|
502 [ -d /var/cache/slitaz ] || mkdir -p /var/cache/slitaz
|
pankso@161
|
503 output=/var/cache/slitaz/sys-report.html
|
al@419
|
504
|
al@419
|
505 cat <<EOT
|
al@419
|
506
|
al@419
|
507 <section>
|
al@443
|
508 <header>$(_ 'Reporting to: %s' "$output")</header>
|
al@419
|
509 <table class="wide zebra">
|
al@419
|
510 <tbody>
|
al@443
|
511 <tr><td>$(_ 'Creating report header...')</td>
|
al@303
|
512 EOT
|
al@419
|
513 cat > $output <<EOT
|
pankso@161
|
514 <!DOCTYPE html>
|
pankso@161
|
515 <html xmlns="http://www.w3.org/1999/xhtml">
|
pankso@161
|
516 <head>
|
al@419
|
517 <meta charset="utf-8"/>
|
al@443
|
518 <title>$(_ 'SliTaz system report')</title>
|
pankso@161
|
519 <style type="text/css">
|
al@303
|
520 body { padding: 20px 60px; font-size: 13px; }
|
al@303
|
521 h1, h2 { color: #444; }
|
pankso@161
|
522 pre { background: #f1f1f1; border: 1px solid #ddd;
|
pankso@161
|
523 padding: 10px; border-radius: 4px; }
|
pascal@166
|
524 span.diff-rm { color: red; }
|
pascal@166
|
525 span.diff-add { color: green; }
|
pankso@161
|
526 </style>
|
pankso@161
|
527 </head>
|
pankso@161
|
528 <body>
|
pankso@161
|
529 EOT
|
al@419
|
530 cat <<EOT
|
al@303
|
531 $(ok_status_t)
|
al@443
|
532 <tr><td>$(_ 'Creating system summary...')</td>
|
al@303
|
533 EOT
|
al@419
|
534 cat >> $output <<EOT
|
al@443
|
535 <h1>$(_ 'SliTaz system report')</h1>
|
al@443
|
536 $(_ 'Date:') $(date)
|
pankso@161
|
537 <pre>
|
pascal@163
|
538 uptime : $(uptime)
|
pankso@161
|
539 cmdline : $(cat /proc/cmdline)
|
pankso@161
|
540 version : $(cat /etc/slitaz-release)
|
pankso@161
|
541 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
|
pankso@161
|
542 kernel : $(uname -r)
|
pankso@161
|
543 </pre>
|
pankso@161
|
544 EOT
|
al@419
|
545 cat <<EOT
|
al@303
|
546 $(ok_status_t)
|
al@443
|
547 <tr><td>$(_ 'Getting hardware info...')</td>
|
al@303
|
548 EOT
|
al@419
|
549 cat >> $output <<EOT
|
pankso@161
|
550 <h2>free</h2>
|
al@303
|
551 <pre>$(free)</pre>
|
pankso@161
|
552
|
pankso@161
|
553 <h2>lspci -k</h2>
|
al@303
|
554 <pre>$(lspci -k)</pre>
|
pankso@161
|
555
|
pankso@161
|
556 <h2>lsusb</h2>
|
al@303
|
557 <pre>$(lsusb)</pre>
|
pankso@161
|
558
|
pankso@161
|
559 <h2>lsmod</h2>
|
al@303
|
560 <pre>$(lsmod)</pre>
|
pankso@161
|
561
|
pankso@161
|
562 EOT
|
al@419
|
563 cat <<EOT
|
al@303
|
564 $(ok_status_t)
|
al@443
|
565 <tr><td>$(_ 'Getting networking info...')</td>
|
al@303
|
566 EOT
|
al@419
|
567 cat >> $output <<EOT
|
pankso@161
|
568 <h2>ifconfig -a</h2>
|
al@303
|
569 <pre>$(ifconfig -a)</pre>
|
al@303
|
570
|
pascal@163
|
571 <h2>route -n</h2>
|
al@303
|
572 <pre>$(route -n)</pre>
|
al@303
|
573
|
pascal@163
|
574 <h2>/etc/resolv.conf</h2>
|
al@303
|
575 <pre>$(cat /etc/resolv.conf)</pre>
|
pascal@163
|
576 EOT
|
al@419
|
577 cat <<EOT
|
al@303
|
578 $(ok_status_t)
|
al@443
|
579 <tr><td>$(_ 'Getting filesystems info...')</td>
|
al@303
|
580 EOT
|
al@419
|
581 cat >> $output <<EOT
|
pascal@163
|
582 <h2>blkid</h2>
|
al@303
|
583 <pre>$(blkid)</pre>
|
al@303
|
584
|
pascal@163
|
585 <h2>fdisk -l</h2>
|
al@303
|
586 <pre>$(fdisk -l)</pre>
|
al@303
|
587
|
pascal@163
|
588 <h2>mount</h2>
|
al@303
|
589 <pre>$(mount)</pre>
|
al@303
|
590
|
pascal@163
|
591 <h2>df -h</h2>
|
al@303
|
592 <pre>$(df -h)</pre>
|
al@303
|
593
|
pascal@163
|
594 <h2>df -i</h2>
|
al@303
|
595 <pre>$(df -i)</pre>
|
pascal@163
|
596 EOT
|
al@419
|
597 cat <<EOT
|
al@303
|
598 $(ok_status_t)
|
al@443
|
599 <tr><td>$(_ 'Getting boot logs...')</td>
|
al@303
|
600 EOT
|
al@419
|
601 cat >> $output <<EOT
|
al@443
|
602 <h2>$(_ 'Kernel messages')</h2>
|
al@303
|
603 <pre>$(cat /var/log/dmesg.log)</pre>
|
al@303
|
604
|
al@443
|
605 <h2>$(_ 'Boot scripts')</h2>
|
al@303
|
606 <pre>$(cat /var/log/boot.log | filter_taztools_msgs)</pre>
|
pankso@161
|
607 EOT
|
al@419
|
608 cat <<EOT
|
al@303
|
609 $(ok_status_t)
|
al@443
|
610 <tr><td>$(_ 'Creating report footer...')</td>
|
al@303
|
611 EOT
|
al@419
|
612 cat cat >> $output <<EOT
|
pankso@161
|
613 </body>
|
pankso@161
|
614 </html>
|
pankso@161
|
615 EOT
|
al@419
|
616 cat <<EOT
|
al@303
|
617 $(ok_status_t)
|
al@419
|
618 </tbody>
|
al@419
|
619 </table>
|
al@419
|
620 <footer>
|
al@443
|
621 <form><button name="file" value="$output" data-icon="view">$(_ 'View')</button></form>
|
al@419
|
622 </footer>
|
al@419
|
623 </section>
|
al@419
|
624
|
al@419
|
625
|
al@443
|
626 $(msg tip "$(_ 'This report can be attached with a bug report on:')
|
al@419
|
627 <a href="http://bugs.slitaz.org/" target="_blank">bugs.slitaz.org</a></p>")
|
al@303
|
628 EOT
|
al@303
|
629 ;;
|
al@312
|
630
|
al@312
|
631
|
pankso@2
|
632 *)
|
pankso@14
|
633 #
|
pankso@2
|
634 # Default xHTML content
|
pankso@14
|
635 #
|
al@419
|
636 header; xhtml_header
|
pascal@81
|
637 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
|
pascal@81
|
638 [ -n "$(GET rdate)" ] && echo ""
|
al@303
|
639 hostname=$(hostname)
|
al@419
|
640
|
al@419
|
641 cat <<EOT
|
al@443
|
642 <h2>$(_ 'Host: %s' $hostname)</h2>
|
al@443
|
643 <p>$(_ 'SliTaz administration and configuration Panel')<p>
|
al@419
|
644
|
al@419
|
645 <form class="nogap"><!--
|
al@443
|
646 --><button name="terminal" data-icon="terminal">$(_ 'Terminal')</button><!--
|
al@443
|
647 --><button name="top" data-icon="proc" >$(_ 'Process activity')</button><!--
|
al@443
|
648 --><button name="report" data-icon="report" data-root>$(_ 'Create a report')</button><!--
|
al@437
|
649 --></form>
|
pankso@14
|
650
|
al@312
|
651 <section>
|
al@443
|
652 <header>$(_ 'Summary')</header>
|
al@419
|
653 <table>
|
al@443
|
654 <tr><td>$(_ 'Uptime:')</td>
|
al@419
|
655 <td id="uptime">$(uptime | sed 's|\([0-9.:][0-9.:]*\)|<b>\1</b>|g')</td>
|
al@419
|
656 </tr>
|
al@443
|
657 <tr><td>$(_ 'Memory in Mb:')</td>
|
al@419
|
658 <td>$(free -m | grep Mem: | \
|
al@419
|
659 awk -vline="$(gettext 'Total: %d, Used: %d, Free: %d')" \
|
al@419
|
660 '{ printf(line, $2, $3, $4) }' | \
|
al@419
|
661 sed 's|\([0-9][0-9]*\)|<b>\1</b>|g')</td>
|
al@419
|
662 </tr>
|
al@443
|
663 <tr><td>$(_ 'Linux kernel:')</td>
|
al@419
|
664 <td>$(uname -r)</td>
|
al@419
|
665 </tr>
|
al@419
|
666 </table>
|
al@419
|
667 </section>
|
al@419
|
668
|
al@419
|
669
|
al@419
|
670 <section>
|
al@419
|
671 <header>
|
al@443
|
672 $(_ 'Network status')
|
al@419
|
673 <form action="network.cgi">
|
al@443
|
674 <button data-icon="wifi">$(_ 'Network')</button>
|
al@419
|
675 </form>
|
al@419
|
676 </header>
|
al@419
|
677 $(list_network_interfaces)
|
al@419
|
678 </section>
|
al@419
|
679
|
al@419
|
680
|
al@419
|
681 <section>
|
al@419
|
682 <header>
|
al@443
|
683 $(_ 'Filesystem usage statistics')
|
al@419
|
684 <form action="hardware.cgi">
|
al@443
|
685 <button data-icon="hdd">$(_ 'Disks')</button>
|
al@419
|
686 </form>
|
al@419
|
687 </header>
|
al@419
|
688 <table class="wide zebra center">
|
al@303
|
689 EOT
|
al@419
|
690 # Disk stats (management is done as hardware.cgi)
|
al@419
|
691 df_thead
|
al@419
|
692 echo '<tbody>'
|
al@419
|
693 df -h | grep ^/dev | while read fs size used av pct mp; do
|
al@419
|
694 cat <<EOT
|
al@419
|
695 <tr>
|
al@419
|
696 <td><span data-icon="hdd">${fs#/dev/}</span></td>
|
al@419
|
697 <td>$(blkid $fs | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/\1/')</td>
|
al@419
|
698 <td>$(blkid $fs | sed '/TYPE=/!d;s/.*TYPE="\([^"]*\).*/\1/')</td>
|
al@419
|
699 <td>$size</td>
|
al@419
|
700 <td>$av</td>
|
al@419
|
701 <td class="meter"><meter min="0" max="100" value="$(echo $pct | cut -d% -f1)"
|
al@419
|
702 low="$DU_WARN" high="$DU_CRIT" optimum="10"></meter>
|
al@419
|
703 <span>$used - $pct</span>
|
al@419
|
704 </td>
|
al@419
|
705 <td>$mp</td>
|
al@419
|
706 <td>$(blkid $fs | sed '/UUID=/!d;s/.*UUID="\([^"]*\).*/\1/')</td>
|
al@419
|
707 </tr>
|
al@303
|
708 EOT
|
al@303
|
709 done
|
al@419
|
710 cat <<EOT
|
al@419
|
711 </tbody>
|
al@419
|
712 </table>
|
al@312
|
713 </section>
|
pankso@14
|
714
|
al@312
|
715 <section>
|
al@419
|
716 <header>
|
al@443
|
717 $(_ 'Panel Activity')
|
al@419
|
718 <form>
|
al@443
|
719 <button name="file" value="$LOG_FILE" data-icon="view">$(_ 'View')</button>
|
al@419
|
720 </form>
|
al@419
|
721 </header>
|
al@419
|
722 <div>
|
al@419
|
723 <pre id="panel-activity">
|
al@419
|
724 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)</pre>
|
al@419
|
725 </div>
|
al@312
|
726 </section>
|
pankso@2
|
727 EOT
|
pankso@2
|
728 ;;
|
pankso@2
|
729 esac
|
pankso@2
|
730
|
pankso@14
|
731 xhtml_footer
|
pankso@14
|
732 exit 0
|