The ipkg Web Frontend
Hi,
für die NSLU2 gibt es ein ipkg-Web-Managment Tool.
Es ist für die NSLU2 geschrieben auf denen das NSLU2-Debian läuft.
Also keine Oleg oder OpenWRT oder zu der Gruppe gehörende FirmeWare.
Leider kann ea auf der WL-HDD so nicht per ipkg installiert werden, weil es andere Pfade nutzt. Da es ja nicht für die Oleg-Firmware geschrieben wurde.
Daher möchte ich das von dem NSLU2-Debian auf die Oleg-FirmeWare portieren.
Im Grund müssten nur ein paar Pfade geändert werden, dachte ich.
Aber irgendwo scheint doch noch etwas tiefer der "Wurm" drin zu stecken.
Aber vielleicht sehr ihr ja den springenden Punkt warum es sich nicht o einfach portieren lässt oder das es sich einfach portieren lässt nur bis jetzt das noch nicht gefunden wurde was es ist das geändert werden muß.
Es besteht aus 2 Dateien:
package.cgi
und sluginfo:PHP Code:
#!/bin/sh
#
# $Id: package.cgi 6240 2007-06-17 22:29:05Z marceln $
#
if [ "${BASH_CHECK}" != 1 -a -f /opt/bin/bash ]
then
BASH_CHECK=1; export BASH_CHECK
/opt/bin/bash $0
exit $$
fi
PROG=${0##*/}
TMPFILE=/tmp/${PROG}.$$
#
# HTML Header
#
cat << EOF
Content-type: text/html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="CGI:shell" />
<meta name="version" content="\$Id: package.cgi 6240 2007-06-17 22:29:05Z marceln $" />
<title>ipkg web</title>
<style type="text/css">
h1, h2 {
font-family: Arial, Helvetica, sans-serif;
color: #004;
}
table {
border-top: 1px solid #eee;
border-right: 1px solid #eee;
width: 100%;
}
th, td {
padding: 2px 4px;
border-left: 1px solid #eee;
border-bottom: 1px solid #eee;
}
table a {
background: #ddd;
color: #004;
text-decoration: none;
margin: 1px;
padding: 2px 4px;
font-family: Arial, Helvetica, sans-serif;
font-size: 75%;
}
table a.ins {
background: #dfd;
border-left: 1px solid #cec;
border-bottom: 1px solid #cec;
}
table a.upd {
background: #ddf;
border-left: 1px solid #cce;
border-bottom: 1px solid #cce;
}
table a.del {
background: #fdd;
border-left: 1px solid #ecc;
border-bottom: 1px solid #ecc;
}
</style>
</head>
<body>
<h1>The ipkg web frontend</h1>
<form methode="GET">
<table>
<tr>
<td>Sync packages</td>
<td>
<input type="radio" name="updatedb" value="n" checked>no</input>
<input type="radio" name="updatedb" value="y">yes</input>
</td>
</tr>
<tr>
<td>Type:</td>
<td>
<select name="typefilter">
<option selected value="none">NONE</option>
<option value="update">Updates</option>
<option value="installed">Installed</option>
<option value="not">Not installed</option>
</select>
</td>
</tr>
<tr>
<td>Filter</td>
<td><input type="text" name="namefilter"></td>
</tr>
</table>
<input type="submit" name="submit"> <input type="reset">
</form>
EOF
NAMEFILTER=.
# QUERY_STRING=task=install&package=atk
IFS='&'
set -- ${QUERY_STRING}
for i in $@
do
case ${i%%=*} in
task)
TASK="${i#*=}"
;;
package)
PACKAGE="${i#*=}"
;;
updatedb)
UPDATEDB="${i#*=}"
;;
typefilter)
TYPEFILTER="${i#*=}"
;;
namefilter)
if [ "${i#*=}" ]
then
NAMEFILTER="${i#*=}"
fi
;;
submit)
SUBMIT="${i#*=}"
;;
*)
echo "<b>ERROR</b>: Unkown option '${i}'"
echo '</body>'
echo '</html>'
exit 1
;;
esac
done
if [ ! -f /opt/bin/bash ]
then
echo "<h2>Please install bash</h2>"
echo "<p>I recomend to install bash because this cgi script will"
echo "run more than two times faster with bash</p>"
fi
if [ "${UPDATEDB}" = y ]
then
echo "<h2>Upgrading package list</h2>"
echo '<pre>'
ipkg update </dev/null
echo '</pre>'
fi
if [ "${TASK}" = install ]
then
echo "<h2>Install ${PACKAGE}</h2>"
echo '<pre>'
ipkg -force-defaults install "${PACKAGE}" </dev/null
echo '</pre>'
fi
if [ "${TASK}" = update ]
then
echo "<h2>Update ${PACKAGE}</h2>"
echo '<pre>'
ipkg -force-defaults upgrade "${PACKAGE}" </dev/null
echo '</pre>'
fi
if [ "${TASK}" = delete ]
then
echo "<h2>Delete ${PACKAGE}</h2>"
echo '<pre>'
ipkg -force-defaults remove "${PACKAGE}" </dev/null
echo '</pre>'
fi
if [ "${SUBMIT}" != "" ]
then
echo '<h2>Package list</h2>'
ipkg list_installed >${TMPFILE}
trap "[ -f ${TMPFILE} ] && rm ${TMPFILE}" 0
echo '<table border="1" cellpadding="0" cellspacing="0">'
echo '<tr><th>task</th><th>Package</th><th>I-Ver</th><th>P-Ver</th><th>Comment</th><th>Delete</th></tr>'
ipkg list | grep -- "${NAMEFILTER}" | while read line
do
INSTALLED=""
NAME=${line%% - *}
line=${line#* - }
VERSION=${line%% - *}
VERSION=${VERSION% -}
COMMENT=${line#* - }
if [ "$COMMENT" = "$line" ]
then
COMMENT=' '
fi
instline=$(grep "^${NAME} - " ${TMPFILE})
if [ "${instline}" != "" ]
then
INSTALLED=Y
DEL="<a href='$PROG?task=delete&package=${NAME}' class='del'>delete</a>"
instline=${instline#* - }
IVER=${instline%% - *}
if [ "${IVER}" = "${VERSION}" ]
then
TASK=' '
else
TASK="<a href='$PROG?task=update&package=${NAME}' class='upd'>update</a>"
fi
else
DEL=' '
IVER=' '
TASK="<a href='$PROG?task=install&package=${NAME}' class='ins'>install</a>"
fi
SHOW=0
case "${TYPEFILTER}" in
none)
SHOW=1
;;
update)
[ "${INSTALLED}" ] && [ "${IVER}" != "${VERSION}" ] && SHOW=1
;;
installed)
[ "${INSTALLED}" ] && SHOW=1
;;
not)
[ -z "${INSTALLED}" ] && SHOW=1
;;
*)
echo "<b>ERROR</b>: Unkown typefilter '${TYPEFILTER}'"
echo '</body>'
echo '</html>'
exit 1
;;
esac
[ "${SHOW}" = 1 ] && echo "<tr><td>${TASK}</td><td>${NAME}</td><td>${IVER}</td><td>${VERSION}</td><td>${COMMENT}</td><td>${DEL}</td></tr>"
done
echo '</table>'
fi
echo '</body>'
echo '</html>'
Wobei sluginfo nur Informationen zum System ausgibt.PHP Code:
#!/bin/sh
#
# $Id: sluginfo.cgi 7479 2007-12-18 22:29:09Z marceln $
#
if [ "${BASH_CHECK}" != 1 -a -f /opt/bin/bash ]
then
BASH_CHECK=1; export BASH_CHECK
/opt/bin/bash $0
exit $$
fi
showcommand() {
NAME=$1
shift
PROG=$1
shift
if [ -f ${PROG} ]
then
echo "<h3>${NAME}</h3>"
echo "<pre>"
${PROG} "$@"
echo "</pre>"
fi
}
showfile() {
FILE=$1;
BASE=${FILE##*/}
shift
if [ -f "${FILE}" ]
then
showcommand "${BASE}" "/bin/cat" "${FILE}"
fi
}
runprog() {
PROG=$1;
BASE=${PROG##*/}
shift
showcommand "${BASE}" "${PROG}" "$@"
}
cd /tmp
cat << EOF
Content-type: text/html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="sh" />
<meta name="version" content="\$Id: sluginfo.cgi 7479 2007-12-18 22:29:09Z marceln $" />
<title>sluginfo</title>
</head>
<body>
<h1>Slug info</h1>
<ol>
<li><a href="#sys">System</a></li>
<li><a href="#soft">Installed software</a></li>
<li><a href="#disk">Disks</a></li>
<li><a href="#network">Network</a></li>
<li><a href="#samba">samba</a></li>
</ol>
EOF
echo '<a id="sys" /><h2>System</h2>'
showfile /etc/motd
runprog /opt/bin/uname -a
showfile /proc/cpuinfo
showfile /proc/meminfo
showfile /proc/bus/usb/devices
runprog /sbin/lsmod
runprog /bin/ps
runprog /bin/dmesg
echo '<a id="soft" /><h2>Installed software</h2>'
runprog /usr/bin/ipkg list_installed
echo '<a id="disk" /><h2>Disks</h2>'
showfile /proc/mounts
runprog /bin/df
showcommand "sda" /sbin/fdisk -l /dev/sda
showcommand "sdb" /sbin/fdisk -l /dev/sdb
showcommand "sdc" /sbin/fdisk -l /dev/sdc
showcommand "sdd" /sbin/fdisk -l /dev/sdd
echo '<a id="network" /><h2>Network</h2>'
runprog /sbin/ifconfig
runprog /sbin/route
showfile /etc/resolv.conf
runprog /opt/bin/host ipkg.nslu2-linux.org
runprog /bin/ping -c 2 ipkg.nslu2-linux.org
runprog /usr/bin/wget http://ipkg.nslu2-linux.org
echo '<a id="samba" /><h2>Samba</h2>'
showfile /opt/etc/samba/smb.conf
showfile /opt/etc/samba/user_smb.conf
showfile /var/log/samba/log.smbd
showfile /var/log/samba/log.nmbd
echo '</body>'
echo '</html>'
Dieses Script habe ich schon an die WL-HDD angepasst, kann sein das ich noch was übersehen.
Das script package.cgi muß noch bearbeitet werden.
Als erstes muß das hier angepasst werden:
Haben wir auf der WL-HDD eine bash? Oder wie heisst das Ding und wo liegt es, so das der Pfad geändert werden kann?PHP Code:
if [ "${BASH_CHECK}" != 1 -a -f /opt/bin/bash ]
then
BASH_CHECK=1; export BASH_CHECK
/opt/bin/bash $0
exit $$
fi
Würde nach anpassen das auch ohne die Installation von einem zusätzlichen thttpd WebServer mit dem Originalen WebServer funktionieren?
Ein:
hat das ergeben.PHP Code:
ipkg list | grep bash
bash - 3.2.17-1 - A bourne style shell
dash - 0.5.3-1 - dash (Debian Almquist Shell) is a POSIX compliant shell that is much smaller than bash.
which - 2.18-1 - which prints out the full path of the executablesthat bash(1) would execute when the passed program names would have been enter
Brauche ich die bash? Ich habe doch schon root Zugriff über Putty.
Gruß WLAN-Fan.