autodist-cgi: add available log files table for build target in SHOWLOG and implement security checks on passed urls

This commit is contained in:
Silvan Calarco 2012-07-29 10:56:54 +02:00
parent 00adf496ba
commit 2ee18817c4

View File

@ -7,11 +7,20 @@ AS_SECONDARY=`echo "$QUERY_STRING" | sed -n 's/^.*AS_SECONDARY=\([^&]*\).*$/\1/p
SHOWLOG=`echo "$QUERY_STRING" | sed -n 's/^.*SHOWLOG=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` SHOWLOG=`echo "$QUERY_STRING" | sed -n 's/^.*SHOWLOG=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
SHOWINDEX=`echo "$QUERY_STRING" | sed -n 's/^.*SHOWINDEX=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` SHOWINDEX=`echo "$QUERY_STRING" | sed -n 's/^.*SHOWINDEX=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
LINES=`echo "$QUERY_STRING" | sed -n 's/^.*LINES=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` LINES=`echo "$QUERY_STRING" | sed -n 's/^.*LINES=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
FORMAT=`echo "$QUERY_STRING" | sed -n 's/^.*FORMAT=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
[ ! "$FORMAT" ] && FORMAT=html
[ "$LINES" ] || LINES=5 [ "$LINES" ] || LINES=5
[ "$AS_SECONDARY" ] && SECONDARY_ADD="&SECONDARY=1" [ "$AS_SECONDARY" ] && SECONDARY_ADD="&SECONDARY=1"
echo -e "Content-type: text/html; charset=UTF-8\n\n" if [ ! "$AS_SECONDARY" -a "$FORMAT" = "xml" ]; then
echo -e "Content-type: text/xml\nPragma: no-cache\n"
echo -n "<autodist><output><![CDATA["
RELOADTIME=3600000
else
echo -e "Content-type: text/html; charset=UTF-8\n"
fi
[ ! "$AS_SECONDARY" ] && echo "Build environments: [<a href=\"?NUM=\">ALL</a>]<br>" [ ! "$AS_SECONDARY" ] && echo "Build environments: [<a href=\"?NUM=\">ALL</a>]<br>"
@ -75,20 +84,36 @@ for i in `seq 0 ${#AUTOPORT_ARCH[*]}`; do
_EOF _EOF
echo -n "<pre><code>" echo -n "<pre><code>"
if [ "$SHOWLOG" = "current" ]; then if [ "$SHOWLOG" = "current" ]; then
RELOADTIME=600000
cat $LOGFILE | sed "s|<|\&lt;|g" cat $LOGFILE | sed "s|<|\&lt;|g"
elif [ "$SHOWLOG" = "last" ]; then elif [ "$SHOWLOG" = "last" ]; then
cat $LASTLOGFILE | sed "s|<|\&lt;|g" cat $LASTLOGFILE | sed "s|<|\&lt;|g"
else else
# Security check
[ "${SHOWLOG/\/\.}" != "${SHOWLOG}" ] && continue
if [ "${AUTOPORT_CHROOT[$i]}" ]; then if [ "${AUTOPORT_CHROOT[$i]}" ]; then
BUILDLOGFILE="/var/autoport/${AUTOPORT_CHROOT[$i]}/home/${AUTOPORT_CHROOT_USER[$i]}/.autodist/log/$SHOWLOG" BUILDLOGDIR="/var/autoport/${AUTOPORT_CHROOT[$i]}/home/${AUTOPORT_CHROOT_USER[$i]}/.autodist/log/"
elif [ "${AUTOPORT_NATIVE[$i]}" -o "${AUTOPORT_UPDATE[$i]}" ]; then elif [ "${AUTOPORT_NATIVE[$i]}" -o "${AUTOPORT_UPDATE[$i]}" ]; then
BUILDLOGFILE="/var/autodist/log/$SHOWLOG" BUILDLOGDIR="/var/autodist/log/"
fi fi
[ -e $BUILDLOGFILE ] && cat $BUILDLOGFILE | sed "s|<|\&lt;|g" if [ "${SHOWLOG/\/ok\/}" != "${SHOWLOG}" -o "${SHOWLOG/\failed\/}" != "${SHOWLOG}" ]; then
SHOWLOGPKG=${SHOWLOG/*\/}
[ "${SHOWLOGPKG}" ] || continue
echo "<table><tr><td colspan=3>Last ${SHOWLOGPKG} logs:</td>"
for t in prepare update build install send; do
echo -n "<tr><td>$t:</td><td>"
[ -e ${BUILDLOGDIR}${t}/ok/${SHOWLOGPKG} ] && echo -n "<td><a href=\"?NUM=$i$SECONDARY_ADD&SHOWLOG=${t}/ok/${SHOWLOGPKG}\">OK</a></td>" || echo "<td></td>"
[ -e ${BUILDLOGDIR}${t}/failed/${SHOWLOGPKG} ] && echo -n "<td><a href=\"?NUM=$i$SECONDARY_ADD&SHOWLOG=${t}/failed/${SHOWLOGPKG}\">FAILED</a></td>" || echo "<td></td>"
echo "</tr>"
done
echo "</table>"
fi
[ -e ${BUILDLOGDIR}${SHOWLOG} ] && cat ${BUILDLOGDIR}${SHOWLOG} | sed "s|<|\&lt;|g"
fi fi
echo "</code></pre></div></div>" echo "</code></pre></div></div>"
fi fi
elif [ ! "$SHOWLOG" ]; then elif [ ! "$SHOWLOG" ]; then
RELOADTIME=60000
[[ "$NUM" && "$NUM" != "$i" ]] && continue [[ "$NUM" && "$NUM" != "$i" ]] && continue
[[ "$SECONDARY" = "$AS_SECONDARY" ]] || continue [[ "$SECONDARY" = "$AS_SECONDARY" ]] || continue
if [ "${AUTOPORT_UPDATE[$i]}" ]; then if [ "${AUTOPORT_UPDATE[$i]}" ]; then
@ -220,3 +245,9 @@ if [ "$AUTOPORT_CGI_SECONDARY" -a ! "$SHOWLOG" ]; then
fi fi
fi fi
[ ! "$AS_SECONDARY" ] && echo "<p><i>Generated by autodist CGI interface. Last update: `date`</i>" [ ! "$AS_SECONDARY" ] && echo "<p><i>Generated by autodist CGI interface. Last update: `date`</i>"
if [ ! "$AS_SECONDARY" -a "$FORMAT" = "xml" ]; then
echo -n "]]></output>"
[ "$RELOADTIME" ] && echo -n "<reloadtime>$RELOADTIME</reloadtime>"
echo "</autodist>"
fi