~oem-solutions-releng/live-build/lb-sg-2.x-add-support-for-xz-and-bzip2-compression

« back to all changes in this revision

Viewing changes to cgi/cgi

  • Committer: Daniel Baumann
  • Date: 2011-03-09 18:17:04 UTC
  • Revision ID: daniel@debian.org-20110309181704-fuq28tc89dn0pggz
Merging live-webhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
# live-webhelper - web interface to live-helper
 
4
# Copyright (C) 2007-2010 Daniel Baumann <daniel@debian.org>
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program; if not, write to the Free Software
 
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
19
#
 
20
# On Debian systems, the complete text of the GNU General Public License
 
21
# can be found in /usr/share/common-licenses/GPL-2 file.
 
22
 
 
23
# Reading common
 
24
. /usr/share/live-webhelper/common
 
25
 
 
26
# Reading defaults
 
27
if [ -r /etc/default/live-webhelper ]
 
28
then
 
29
        . /etc/default/live-webhelper
 
30
else
 
31
        echo "E: /etc/default/live-webhelper missing"
 
32
        exit 1
 
33
fi
 
34
 
 
35
# Sending http header
 
36
echo "Content-type: text/html"
 
37
echo
 
38
 
 
39
# Sending html header
 
40
cat "${_TEMPLATES}"/header.html
 
41
 
 
42
# CGI
 
43
if [ -z "${QUERY_STRING}" ]
 
44
then
 
45
        # Sending html form
 
46
        sed -e "s#LH_MIRROR_BOOTSTRAP_SECURITY#${LH_MIRROR_BOOTSTRAP_SECURITY}#" \
 
47
            -e "s#LH_MIRROR_BOOTSTRAP#${LH_MIRROR_BOOTSTRAP}#" \
 
48
            -e "s#LH_MIRROR_BINARY_SECURITY#${LH_MIRROR_BINARY_SECURITY}#" \
 
49
            -e "s#LH_MIRROR_BINARY#${LH_MIRROR_BINARY}#" \
 
50
            -e "s/VERSION/${VERSION}/" \
 
51
            -e "s/DATE/`date +%Y%m%d-%H:%M`/" \
 
52
        "${_TEMPLATES}"/form.html
 
53
else
 
54
        # Converting spaces:    sed 's/+/ /g'
 
55
        # Converting '@':       sed 's/%40/@/g'
 
56
        # Converting ':':       sed 's/%3A/:/g'
 
57
        # Converting ';':       sed 's/%3B/\;/g'
 
58
        # Converting '/':       sed 's/%2F/\//g'
 
59
        # Converting '~':       sed 's/%7E/\~/g'
 
60
 
 
61
        # Translate parameters
 
62
        QUERY_STRING=$(echo "${QUERY_STRING}" | sed -e 's/%2F/\//g' -e 's/+/ /g' -e 's/%3B/;/g' -e 's/%7E/~/g' -e 's/%3A/:/g' -e 's/%40/@/g')
 
63
        # Debug the filtering string
 
64
        # echo ${QUERY_STRING}
 
65
 
 
66
        # Email
 
67
        _EMAIL=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])email=[0-9,a-z,A-Z,.,_,-,@]+' | cut -f 2 -d '=' | head -n1)
 
68
 
 
69
        # Standard options
 
70
        LH_BINARY_IMAGES=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])binary_images=[a-z,-]+' | cut -f 2 -d '=' | head -n1)
 
71
        LH_DISTRIBUTION=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])distribution=[a-z]+' | cut -f 2 -d '=' | head -n1)
 
72
        LH_PACKAGES_LISTS=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])packages_lists=[0-9,a-z,-]+' | cut -f 2 -d '=' | head -n1)
 
73
        LH_PACKAGES=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])packages=[0-9,a-z,A-Z,., ,_,-]+' | cut -f 2 -d '=' | head -n1)
 
74
 
 
75
        # Advanced bootstrap options
 
76
        LH_ARCHITECTURE=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])architecture=[0-9,a-z]+' | cut -f 2 -d '=' | head -n1)
 
77
        LH_BOOTSTRAP_FLAVOUR=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])bootstrap_flavour=[a-z]+' | cut -f 2 -d '=' | head -n1)
 
78
        LH_MIRROR_BOOTSTRAP=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])mirror_bootstrap=[0-9,a-z,A-Z,.,~,:,/,_,-]+' | cut -f 2 -d '=' | head -n1)
 
79
        LH_MIRROR_BOOTSTRAP_SECURITY=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])mirror_bootstrap=[0-9,a-z,A-Z,.,~,:,/,_,-]+' | cut -f 2 -d '=' | head -n1)
 
80
        LH_MIRROR_BINARY=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])mirror_binary=[0-9,a-z,A-Z,.,~,:,/,_,-]+' | cut -f 2 -d '=' | head -n1)
 
81
        LH_MIRROR_BINARY_SECURITY=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])mirror_binary_security=[0-9,a-z,A-Z,.,~,:,/,_,-]+' | cut -f 2 -d '=' | head -n1)
 
82
        LH_SECTIONS=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])sections=[a-z]+' | cut -f 2 -d '=' | head -n1)
 
83
 
 
84
        # Advanced chroot options
 
85
        LH_CHROOT_FILESYSTEM=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])chroot_filesystem=[0-9,a-z]+' | cut -f 2 -d '=' | head -n1)
 
86
        LH_LINUX_FLAVOURS=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])linux_flavours=[0-9,a-z,-]+' | cut -f 2 -d '=' | head -n1)
 
87
        LH_SECURITY=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])security=[a-z]+' | cut -f 2 -d '=' | head -n1)
 
88
        LH_SYMLINKS=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])symlinks=[a-z]+' | cut -f 2 -d '=' | head -n1)
 
89
        LH_SYSVINIT=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])sysvinit=[a-z]+' | cut -f 2 -d '=' | head -n1)
 
90
 
 
91
        # Advanced binary options
 
92
        LH_BINARY_INDICES=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])binary_indices=[a-z]+' | cut -f 2 -d '=' | head -n1)
 
93
        LH_BOOTAPPEND=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])bootappend=[0-9,a-z,A-Z,., ,_,+,-]+' | cut -f 2 -d '=' | head -n1)
 
94
        LH_BOOTLOADER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])bootloader=[a-z]+' | cut -f 2 -d '=' | head -n1)
 
95
        LH_DEBIAN_INSTALLER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])debian_installer=[a-z]+' | cut -f 2 -d '=' | head -n1)
 
96
        LH_ENCRYPTION=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])encryption=[0-9,a-z,A-Z]+' | cut -f 2 -d '=' | head -n1)
 
97
        LH_HOSTNAME=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])hostname=[0-9,a-z,A-Z,.,-]+' | cut -f 2 -d '=' | head -n1)
 
98
        LH_ISO_APPLICATION=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])iso_application=[0-9,a-z,A-Z,., ,~,;,:,/,_,-]+' | cut -f 2 -d '=' | head -n1)
 
99
        LH_ISO_PREPARER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])iso_preparer=[0-9,a-z,A-Z,., ,~,;,:,/,_,-]+' | cut -f 2 -d '=' | head -n1)
 
100
        LH_ISO_PUBLISHER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])iso_publisher=[0-9,a-z,A-Z,., ,~,;,:,/,_,/,-]+' | cut -f 2 -d '=' | head -n1)
 
101
        LH_ISO_VOLUME=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])iso_volume=[0-9,a-z,A-Z,., ,~,;,:,/,_,-]+' | cut -f 2 -d '=' | head -n1)
 
102
        LH_MEMTEST=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])memtest=[0-9,a-z,A-Z,.,_,-]+' | cut -f 2 -d '=' | head -n1)
 
103
        LH_NET_ROOT_PATH=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])net_path=[0-9,a-z,A-Z,.,_,/,-]+' | cut -f 2 -d '=' | head -n1)
 
104
        LH_NET_ROOT_SERVER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])net_server=[0-9,a-z,A-Z,.,_,-]+' | cut -f 2 -d '=' | head -n1)
 
105
        LH_USERNAME=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])username=[0-9,a-z,A-Z,.,-]+' | cut -f 2 -d '=' | head -n1)
 
106
 
 
107
        # Advanced source options
 
108
        LH_SOURCE=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])source=[a-z]+' | cut -f 2 -d '=' | head -n1)
 
109
        LH_SOURCE_IMAGES=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])source_images=[a-z]+' | cut -f 2 -d '=' | head -n1)
 
110
 
 
111
        # Unofficial options
 
112
        _CUSTOM_BOOTSTRAP=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])custom_bootstrap=[0-9,a-z,A-Z,., ,~,;,:,/,_,-]+' | cut -f 2 -d '=' | head -n1)
 
113
        _CUSTOM_BINARY=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])custom_binary=[0-9,a-z,A-Z,., ,~,;,:,/,_,-]+' | cut -f 2 -d '=' | head -n1)
 
114
 
 
115
        # FIXME: filter invalid options
 
116
        unset QUERY_STRING
 
117
 
 
118
        if [ -z "${_EMAIL}" ]
 
119
        then
 
120
                echo "<h2><div style='color: red;'>Error: No email address specified.</div></h2>"
 
121
 
 
122
                sed -e "s#LH_MIRROR_BOOTSTRAP_SECURITY#${LH_MIRROR_BOOTSTRAP_SECURITY}#" \
 
123
                    -e "s#LH_MIRROR_BOOTSTRAP#${LH_MIRROR_BOOTSTRAP}#" \
 
124
                    -e "s#LH_MIRROR_BINARY_SECURITY#${LH_MIRROR_BINARY_SECURITY}#" \
 
125
                    -e "s#LH_MIRROR_BINARY#${LH_MIRROR_BINARY}#" \
 
126
                    -e "s/VERSION/${VERSION}/" \
 
127
                    -e "s/DATE/`date +%Y%m%d-%H:%M`/" \
 
128
                "${_TEMPLATES}"/form.html
 
129
 
 
130
                exit
 
131
        fi
 
132
 
 
133
        # Getting build identifier
 
134
        _BUILD=$(date +%Y%m%d.%H%M%S.%N)
 
135
 
 
136
        #echo "${QUERY_STRING}"
 
137
        # Sending html confirmation
 
138
        # Note: On each string remember to use a delimeter that is not in the string.
 
139
        sed -e "s/BUILD/${_BUILD}/g" \
 
140
            -e "s/EMAIL/${_EMAIL}/" \
 
141
            -e "s/LH_BINARY_IMAGES/${LH_BINARY_IMAGES}/" \
 
142
            -e "s/LH_DISTRIBUTION/${LH_DISTRIBUTION}/" \
 
143
            -e "s/LH_PACKAGES_LISTS/${LH_PACKAGES_LISTS}/" \
 
144
            -e "s/LH_PACKAGES/${LH_PACKAGES}/" \
 
145
            -e "s/LH_ARCHITECTURE/${LH_ARCHITECTURE}/" \
 
146
            -e "s/LH_BOOTSTRAP_FLAVOUR/${LH_BOOTSTRAP_FLAVOUR}/" \
 
147
            -e "s#LH_MIRROR_BOOTSTRAP_SECURITY#${LH_MIRROR_BOOTSTRAP_SECURITY}#" \
 
148
            -e "s#LH_MIRROR_BOOTSTRAP#${LH_MIRROR_BOOTSTRAP}#" \
 
149
            -e "s#LH_MIRROR_BINARY_SECURITY#${LH_MIRROR_BINARY_SECURITY}#" \
 
150
            -e "s#LH_MIRROR_BINARY#${LH_MIRROR_BINARY}#" \
 
151
            -e "s/LH_SECTIONS/${LH_SECTIONS}/" \
 
152
            -e "s/LH_CHROOT_FILESYSTEM/${LH_CHROOT_FILESYSTEM}/" \
 
153
            -e "s/LH_LINUX_FLAVOURS/${LH_LINUX_FLAVOURS}/" \
 
154
            -e "s/LH_SECURITY/${LH_SECURITY}/" \
 
155
            -e "s/LH_SYMLINKS/${LH_SYMLINKS}/" \
 
156
            -e "s/LH_SYSVINIT/${LH_SYSVINIT}/" \
 
157
            -e "s/LH_BINARY_INDICES/${LH_BINARY_INDICES}/" \
 
158
            -e "s/LH_BOOTAPPEND/${LH_BOOTAPPEND}/" \
 
159
            -e "s/LH_BOOTLOADER/${LH_BOOTLOADER}/" \
 
160
            -e "s/LH_DEBIAN_INSTALLER/${LH_DEBIAN_INSTALLER}/" \
 
161
            -e "s/LH_ENCRYPTION/${LH_ENCRYPTION}/" \
 
162
            -e "s/LH_HOSTNAME/${LH_HOSTNAME}/" \
 
163
            -e "s#LH_ISO_APPLICATION#${LH_ISO_APPLICATION}#" \
 
164
            -e "s#LH_ISO_PREPARER#${LH_ISO_PREPARER}#" \
 
165
            -e "s#LH_ISO_PUBLISHER#${LH_ISO_PUBLISHER}#" \
 
166
            -e "s#LH_ISO_VOLUME#${LH_ISO_VOLUME}#" \
 
167
            -e "s/LH_MEMTEST/${LH_MEMTEST}/" \
 
168
            -e "s#LH_NET_ROOT_PATH#${LH_NET_ROOT_PATH}#" \
 
169
            -e "s/LH_NET_ROOT_SERVER/${LH_NET_ROOT_SERVER}/" \
 
170
            -e "s#SERVER#${_SERVER}#g" \
 
171
            -e "s/LH_USERNAME/${LH_USERNAME}/" \
 
172
            -e "s/LH_SOURCE_IMAGES/${LH_SOURCE_IMAGES}/" \
 
173
            -e "s/LH_SOURCE/${LH_SOURCE}/" \
 
174
            -e "s#CUSTOM_BOOTSTRAP#${_CUSTOM_BOOTSTRAP}#" \
 
175
            -e "s#CUSTOM_BINARY#${_CUSTOM_BINARY}#" \
 
176
        "${_TEMPLATES}"/build.html
 
177
 
 
178
        # Creating temporary directory
 
179
        mkdir -p "${_TEMPDIR}"
 
180
 
 
181
# Writing build file
 
182
cat > "${_TEMPDIR}"/"${_BUILD}".build << EOF
 
183
# live-webhelper "${VERSION}" build file
 
184
# `date -R`
 
185
 
 
186
_BUILD="${_BUILD}"
 
187
_EMAIL="${_EMAIL}"
 
188
 
 
189
# Standard options
 
190
LH_BINARY_IMAGES="${LH_BINARY_IMAGES}"
 
191
LH_DISTRIBUTION="${LH_DISTRIBUTION}"
 
192
LH_PACKAGES_LISTS="${LH_PACKAGES_LISTS}"
 
193
LH_PACKAGES="${LH_PACKAGES}"
 
194
 
 
195
# Advanced bootstrap options
 
196
LH_ARCHITECTURE="${LH_ARCHITECTURE}"
 
197
LH_MIRROR_BOOTSTRAP_SECURITY="${LH_MIRROR_BOOTSTRAP}"
 
198
LH_MIRROR_BOOTSTRAP="${LH_MIRROR_BOOTSTRAP}"
 
199
LH_MIRROR_BINARY_SECURITY="${LH_MIRROR_BINARY_SECURITY}"
 
200
LH_MIRROR_BINARY="${LH_MIRROR_BINARY}"
 
201
LH_SECTIONS="${LH_SECTIONS}"
 
202
 
 
203
# Advanced chroot options
 
204
LH_CHROOT_FILESYSTEM="${LH_CHROOT_FILESYSTEM}"
 
205
LH_LINUX_FLAVOURS="${LH_LINUX_FLAVOURS}"
 
206
LH_SECURITY="${LH_SECURITY}"
 
207
LH_SYMLINKS="${LH_SYMLINKS}"
 
208
LH_SYSVINIT="${LH_SYSVINIT}"
 
209
 
 
210
# Advanced binary options
 
211
LH_BINARY_INDICES="${LH_BINARY_INDICES}"
 
212
LH_BOOTAPPEND="${LH_BOOTAPPEND}"
 
213
LH_BOOTLOADER="${LH_BOOTLOADER}"
 
214
LH_DEBIAN_INSTALLER="${LH_DEBIAN_INSTALLER}"
 
215
LH_ENCRYPTION="${LH_ENCRYPTION}"
 
216
LH_HOSTNAME="${LH_HOSTNAME}"
 
217
LH_ISO_APPLICATION="${LH_ISO_APPLICATION}"
 
218
LH_ISO_PREPARER="${LH_ISO_PREPARER}"
 
219
LH_ISO_PUBLISHER="${LH_ISO_PUBLISHER}"
 
220
LH_ISO_VOLUME="${LH_ISO_VOLUME}"
 
221
LH_MEMTEST="${LH_MEMTEST}"
 
222
LH_NET_ROOT_PATH="${LH_NET_ROOT_PATH}"
 
223
LH_NET_ROOT_SERVER="${LH_NET_ROOT_SERVER}"
 
224
LH_USERNAME="${LH_USERNAME}"
 
225
 
 
226
# Advanced source options
 
227
LH_SOURCE_IMAGES="${LH_SOURCE_IMAGES}"
 
228
LH_SOURCE="${LH_SOURCE}"
 
229
 
 
230
# Unofficial options
 
231
_CUSTOM_BOOTSTRAP="${_CUSTOM_BOOTSTRAP}"
 
232
_CUSTOM_BINARY="${_CUSTOM_BINARY}"
 
233
EOF
 
234
 
 
235
        echo "$(date +%b\ %d\ %H:%M:%S) ${HOSTNAME} live-webhelper: add web build (${_BUILD})." >> /var/log/live
 
236
        echo "$(date +%b\ %d\ %H:%M:%S) ${HOSTNAME} live-webhelper: options ${_BUILD} |email ${_EMAIL}|binary_images ${LH_BINARY_IMAGES}|distribution ${LH_DISTRIBUTION}|packages_lists ${LH_PACKAGES_LISTS}|packages ${LH_PACKAGES}|architecture ${LH_ARCHITECTURE}|mirror_bootstrap_security ${LH_MIRROR_BOOTSTRAP}|mirror_bootstrap ${LH_MIRROR_BOOTSTRAP}|mirror_binary_security ${LH_MIRROR_BINARY_SECURITY}|mirror_binary ${LH_MIRROR_BINARY}|sections ${LH_SECTIONS}|chroot_filesystem ${LH_CHROOT_FILESYSTEM}|linux_flavours ${LH_LINUX_FLAVOURS}|security ${LH_SECURITY}|symlinks ${LH_SYMLINKS}|sysvinit ${LH_SYSVINIT}|binary_indices ${LH_BINARY_INDICES}|bootappend ${LH_BOOTAPPEND}|bootloader ${LH_BOOTLOADER}|debian_installer ${LH_DEBIAN_INSTALLER}|encryption ${LH_ENCRYPTION}|hostname ${LH_HOSTNAME}|iso_application ${LH_ISO_APPLICATION}|iso_preparer ${LH_ISO_PREPARER}|iso_publisher ${LH_ISO_PUBLISHER}|iso_volume ${LH_ISO_VOLUME}|memtest ${LH_MEMTEST}|net_path ${LH_NET_ROOT_PATH}|net_server ${LH_NET_ROOT_SERVER}|username ${LH_USERNAME}|source_images ${LH_SOURCE_IMAGES}|source ${LH_SOURCE}|custom_bootstrap ${_CUSTOM_BOOTSTRAP}|custom_binary ${_CUSTOM_BINARY}\n" >> /var/log/live
 
237
fi
 
238
 
 
239
sed -e "s/VERSION/${VERSION}/" "${_TEMPLATES}"/footer.html