-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfloppy.cgi
executable file
·302 lines (284 loc) · 8.73 KB
/
floppy.cgi
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
#!/bin/sh
#
# Floppy set CGI interface
#
# Copyright (C) 2015 SliTaz GNU/Linux - BSD License
#
# Common functions from libtazpanel
. ./lib/libtazpanel
get_config
TITLE=$(_ 'Boot')
case "$1" in
menu)
TEXTDOMAIN_original=$TEXTDOMAIN
export TEXTDOMAIN='floppy'
#which bootloader > /dev/null &&
cat <<EOT
<li><a data-icon="@floppy@" href="floppy.cgi">$(_ 'Boot floppy')</a></li>
EOT
export TEXTDOMAIN=$TEXTDOMAIN_original
exit
esac
#
# Commands
#
error=
case " $(POST) " in
*\ doformat\ *)
fdformat $(POST fd)
which mkfs.$(POST fstype) > /dev/null 2>&1 &&
mkfs.$(POST fstype) $(POST fd)
;;
*\ write\ *)
if [ "$(FILE fromimage tmpname)" ]; then
dd if=$(FILE fromimage tmpname) of=$(POST tofd)
rm -f $(FILE fromimage tmpname)
else
error="$(msg err 'Broken FILE support')"
fi ;;
*\ read\ *)
dd if=$(POST fromfd) of=$(POST toimage)
;;
*\ build\ *)
cmd=""
toremove=""
while read key file ; do
[ "$(FILE $file size)" ] || continue
for i in $(seq 1 $(FILE $file count)); do
cmd="$cmd $key $(FILE $file tmpname $i)"
toremove="$toremove $(FILE $file tmpname $i)"
done
done <<EOT
bootloader kernel
--initrd initrd
--initrd initrd2
--info info
EOT
error="$(msg err 'Broken FILE support !')
<pre>$(httpinfo)</pre>"
if [ "$cmd" ]; then
for key in cmdline rdev video format mem ; do
[ "$(POST $key)" ] || continue
cmd="$cmd --$key '$(POST $key)'"
done
[ "$(POST edit)" ] || cmd="$cmd --dont-edit-cmdline"
TITLE="$(_ 'TazPanel - floppy')"
header
xhtml_header
cd $(POST workdir)
echo "<pre>"
eval $cmd 2>&1
echo "</pre>"
[ "$toremove" ] && rm -f $toremove && rmdir $(dirname $toremove)
xhtml_footer
exit 0
fi
;;
esac
listfd()
{
echo "<select name=\"$1\">"
ls /dev/fd[0-9]* | sed 's|.*|<option>&</option>|'
echo "</select>"
}
header
xhtml_header "$(_ 'Floppy disk utilities')"
echo "$error"
cat <<EOT
<form method="post" enctype="multipart/form-data" class="wide">
EOT
[ -w /dev/fd0 ] && cat <<EOT
<section>
<header>
$(_ 'Floppy disk format')
</header>
<div>
<button type="submit" name="doformat" data-icon="@start@" >$(_ 'Format disk')</button>
$(listfd fd) filesystem:
<select name "fstype">
<option>$(_ 'none')</option>
$(ls /sbin/mkfs.* | sed '/dev/d;s|.*/mkfs.\(.*\)|<option>\1</option>|')
</select>
</div>
</section>
<section>
<header>
$(_ 'Floppy disk transfer')
</header>
<table>
<tr>
<td>
<button type="submit" name="write" data-icon="@start@" >$(_ 'Write image')</button>
$(listfd tofd) <<< <input name="fromimage" type="file">
</td>
</tr>
<tr>
<td>
<button type="submit" name="read" data-icon="@start@" >$(_ 'Read image' )</button>
$(listfd fromfd) >>> <input name="toimage" type="text" value="/tmp/floppy.img">
<td>
</tr>
</table>
</section>
EOT
case "$HOME" in
/home/*) OUTPUTDIR=$HOME ;;
*) OUTPUTDIR=/tmp ;;
esac
cat <<EOT
<section>
<header>
$(_ 'Boot floppy set builder')
</header>
<table>
<tr>
<td>$(_ 'Linux kernel:')</td>
<td><input name="kernel" size="37" type="file"> <i>$(_ 'required')</i></td>
</tr>
<tr>
<td>$(_ 'Initramfs / Initrd:')</td>
<td><input name="initrd[]" size="37" type="file" multiple> <i>$(_ 'optional')</i></td>
</tr>
<tr>
<td>$(_ 'Extra initramfs:')</td>
<td><input name="initrd2[]" size="37" type="file" multiple> <i>$(_ 'optional')</i></td>
</tr>
<tr>
<td>$(_ 'Boot message:')</td>
<td><input name="info" size="37" type="file"> <i>$(_ 'optional')</i></td>
</tr>
<tr>
<td>$(_ 'Default cmdline:')</td>
<td id="cmdline"><input name="cmdline" size="36" type="text" value="$(sed 's/^BOOT_IMAGE[^ ]* //;s/initrd=[^ ]* //' /proc/cmdline)" > <input name="edit" checked="checked" type="checkbox">$(_ 'edit')
<i>$(_ 'optional')</i></td>
</tr>
<tr>
<td>$(_ 'Root device:')</td>
<td><input name="rdev" size="8" value="/dev/ram0" type="text">
$(_ 'Flags:')
<select name="flags">
<option selected="selected" value="1">R/O</option>
<option value="0">R/W</option>
</select>
VESA:
<select name="video">
<option value="-3">Ask</option>
<option value="-2">Extended</option>
<option value="-1" selected="selected">Standard</option>
EOT
echo "0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 8:8 9:9 10:10 11:11 12:12 13:13 14:14 15:15 \
3840:80x25 3843:80x28 3845:80x30 3846:80x34 3842:80x43 3841:80x50 3847:80x60 777:132x25 778:132x43 \
824:320x200x8 781:320x200x15 782:320x200x16 783:320x200x24 800:320x200x32 \
915:320x240x15 821:320x240x16 917:320x240x24 918:320x240x32 \
931:400x300x15 822:400x300x16 933:400x300x24 934:400x300x32 \
820:512x384x8 947:512x384x15 823:512x384x16 949:512x384x24 950:512x384x32 \
962:640x350x8 963:640x350x15 964:640x350x16 965:640x350x24 966:640x350x32 \
768:640x400x8 899:640x400x15 825:640x400x16 901:640x400x24 902:640x400x32 \
769:640x480x8 784:640x480x15 785:640x480x16 786:640x480x24 826:640x480x32 \
879:800x500x8 880:800x500x15 881:800x500x16 882:800x500x24 883:800x500x32 \
771:800x600x8 787:800x600x15 788:800x600x16 789:800x600x24 827:800x600x32 \
815:896x672x8 818:896x672x24 819:896x672x32 \
874:1024x640x8 875:1024x640x15 876:1024x640x16 877:1024x640x24 878:1024x640x32 \
773:1024x768x8 790:1024x768x15 791:1024x768x16 792:1024x768x24 828:1024x768x32 \
869:1152x720x8 870:1152x720x15 871:1152x720x16 872:1152x720x24 873:1152x720x32 \
775:1280x1024x8 793:1280x1024x15 794:1280x1024x16 795:1280x1024x24 829:1280x1024x32 \
835:1400x1050x8 837:1400x1050x16 838:1400x1040x24 \
864:1440x900x15 866:1440x900x16 867:1440x900x24 868:1440x900x32 \
816:1600x1200x8 817:1600x1200x16 \
893:1920x1200x8" | sed 's| *| |g' |\
awk 'BEGIN{RS=" "; FS=":"} {
printf "<option value=\"%s\">%s</option>\n", $1, $2;
}'
cat <<EOT
</select>
</td>
</tr>
<tr>
<td>$(_ 'Output directory:')</td>
<td>$(dir_chooser "workdir" "$OUTPUTDIR")</td>
</tr>
<tr>
<td>$(_ 'Floppy size:')</td>
<td><select name="format">
<optgroup label="5¼ SD">
<option value="360">360 KB</option>
</optgroup>
<optgroup label="3½ SD">
<option value="720">720 KB</option>
</optgroup>
<optgroup label="5¼ HD">
<option value="1200">1.20 MB</option>
</optgroup>
<optgroup label="3½ HD">
<option value="1440" selected="selected">1.44 MB</option>
<option value="1600">1.60 MB</option>
<option value="1680">1.68 MB</option>
<option value="1722">1.72 MB</option>
<option value="1743">1.74 MB</option>
<option value="1760">1.76 MB</option>
<option value="1840">1.84 MB</option>
<option value="1920">1.92 MB</option>
<option value="1968">1.96 MB</option>
</optgroup>
<optgroup label="3½ ED">
<option value="2880">2.88 MB</option>
<option value="3360">3.36 MB</option>
<option value="3444">3.44 MB</option>
<option value="3840">3.84 MB</option>
<option value="3936">3.92 MB</option>
</optgroup>
<option value="0">$(_ 'no limit')</option>
</select>
$(_ 'RAM used') <select name="mem">
<option selected="selected" value="16">16 MB</option>
<option value="15">15 MB</option>
<option value="14">14 MB</option>
<option value="13">13 MB</option>
<option value="12">12 MB</option>
<option value="11">11 MB</option>
<option value="10">10 MB</option>
<option value="9">9 MB</option>
<option value="8">8 MB</option>
<option value="7">7 MB</option>
<option value="6">6 MB</option>
<option value="5">5 MB</option>
<option value="4">4 MB</option>
</select>
<button type="submit" name="build" data-icon="@start@" >$(_ 'Build floppy set' )</button>
</td>
</tr>
</table>
<footer>
<p>
$(_ 'Note') 1: $(_ 'the extra initramfs may be useful to add your own configuration files.')
</p>
<p>
$(_ 'Note') 2: $(_ 'the keyboard is read for ESC or ENTER on every form feed (ASCII 12) in the boot message.')
</p>
</footer>
</section>
</form>
<section>
<header>
$(_ 'Floppy set from an ISO image')
</header>
<footer>
<form method="post" action="/user/boot.cgi" class="wide">
<input type="hidden" name="iso" />
<input type="hidden" name="action" value="floppyset" />
<table>
<tr>
<td>$(_ 'ISO image file full path')
<span data-img="@info@" title="$(_ 'set /dev/cdrom for a physical CD-ROM')"></span>
</td>
<td>$(file_chooser "iso" "$iso")</td>
<td><button type="submit" name="build" data-icon="@start@" >
$(_ 'Build floppy set' )</button></td>
</tr>
</table>
</form>
</footer>
</section>
EOT
xhtml_footer
exit 0