webbuild: also manage user for authentication

This commit is contained in:
Silvan Calarco 2013-05-21 01:18:05 +02:00
parent b84e90b7db
commit 61710ad694
2 changed files with 47 additions and 26 deletions

View File

@ -37,8 +37,8 @@ window.onbeforeunload = function (e) {
<script src="/scripts/webbuild.js"></script>
<script type="text/javascript">
<!--
var user = "silvan";
var user_email = "silvan.calarco@mambasoft.it";
var user = "";
var user_email = "";
var secret = "";
var lastupdate = 0;
var reloadtime = 15000;
@ -91,8 +91,12 @@ function editorChanged() {
function ajax_getvalues(request,confirm) {
var url = "/cgi-bin/webbuild"
if (!user) {
user=getCookie("webbuild-user");
}
if (!secret) {
secret=getCookie("webbuild");
secret=getCookie("webbuild-secret");
}
if (confirm) {
document.getElementById("status").innerHTML =
@ -136,8 +140,10 @@ function ajax_getvalues(request,confirm) {
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeName == "title") {
document.title = nodes[i].childNodes[0].nodeValue;
} else if (nodes[i].nodeName == "cookie") {
setCookie("webbuild", nodes[i].childNodes[0].nodeValue, 1);
} else if (nodes[i].nodeName == "cookie-user") {
setCookie("webbuild-user", nodes[i].childNodes[0].nodeValue, 1);
} else if (nodes[i].nodeName == "cookie-secret") {
setCookie("webbuild-secret", nodes[i].childNodes[0].nodeValue, 1);
} else if (document.getElementById(nodes[i].nodeName) != undefined) {
$("#"+nodes[i].nodeName).html(nodes[i].childNodes[0].nodeValue);
spectext = document.getElementById("spectext");

View File

@ -37,33 +37,25 @@ if [ "$USER" ]; then
USER_ENABLED=
if [ "$SECRET" = "$USER_SECRET" ]; then
USER_ENABLED=1
elif [ ! "$SECRET" ]; then
USER_ENABLED=
elif [ "$USER_SECRET" ]; then
echo -n "<environments> </environments>"
echo -n "<speccreate> </speccreate>"
echo -n "<specedit> </specedit>"
echo -n "<repositories> </repositories>"
echo -n "<packages> </packages>"
echo -n "<editcontrols> </editcontrols>"
echo -n "<editor> </editor>"
echo -n "<output>Unauthorized! If this happened after you changed your password in openmamba website please ask the maintainer to be re-enabled to use this service. Thank you."
echo -n "</output>"
echo -n "<operationpanel> </operationpanel>"
echo -n "</webbuild>"
exit
elif [ "$REQUEST" = "password" ]; then
/usr/libexec/webbuild-checkpassword "$PASSWORD" "$SECRET" 2>/dev/null
if [ "$USER_SECRET" ]; then
/usr/libexec/webbuild-checkpassword "$PASSWORD" "$USER_SECRET" 2>/dev/null
else
/usr/libexec/webbuild-checkpassword "$PASSWORD" "$SECRET" 2>/dev/null
fi
if [ $? -eq 0 ]; then
tmpfile=`mktemp --suffix=webbuildtmp`
cat $WEBBUILD_STATEDIR/users/$USER.conf > $tmpfile
echo "USER_SECRET='$SECRET'" >> $tmpfile
if [ ! "$USER_SECRET" ]; then
tmpfile=`mktemp --suffix=webbuildtmp`
cat $WEBBUILD_STATEDIR/users/$USER.conf > $tmpfile
echo "USER_SECRET='$SECRET'" >> $tmpfile
$SUDO_WRAPPER 0 local "$USER" "" "mv $tmpfile $WEBBUILD_STATEDIR/users/$USER.conf"
fi
SECRET="$USER_SECRET"
USER_ENABLED=1
$SUDO_WRAPPER 0 local "$USER" "" "mv $tmpfile $WEBBUILD_STATEDIR/users/$USER.conf"
else
USER_ENABLED=
fi
else
elif [ "$REQUEST" != "refresh" ]; then
# no "$USER_SECRET" set; require password
echo -n "<output><![CDATA[Please enter your password: <input type=password id=password>"
echo -n " <input type=button value=\"Submit\" onClick="
@ -82,7 +74,25 @@ if [ "$USER" ]; then
exit
fi
fi
elif [ "$REQUEST" != "refresh" ]; then
echo -n "<output><![CDATA[Please enter your username: <input type=text id=username>"
echo -n " <input type=button value=\"Submit\" onClick="
echo -n "user=encodeURIComponent(getElementById('username').value);"
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&"
echo -n "USER=\"+encodeURIComponent(getElementById('username').value));>"
echo -n "]]></output>"
echo -n "<environments> </environments>"
echo -n "<speccreate> </speccreate>"
echo -n "<specedit> </specedit>"
echo -n "<repositories> </repositories>"
echo -n "<packages> </packages>"
echo -n "<editcontrols> </editcontrols>"
echo -n "<editor> </editor>"
echo -n "<operationpanel> </operationpanel>"
echo -n "</webbuild>"
exit
fi
if [ "$USER_ENABLED" != "1" ]; then
echo -n "<environments> </environments>"
echo -n "<speccreate> </speccreate>"
@ -264,6 +274,11 @@ _EOF
exit
fi
# send data for cookie
if [ "$REQUEST" = "password" ]; then
echo -n "<cookie-user>$USER</cookie-user><cookie-secret>$USER_SECRET</cookie-secret>"
fi
# kill processes or clean log
if [ "$REQUEST" = "killtree" ]; then
killline=`grep "^$KILLPID " $WEBBUILD_STATEDIR/processes`