|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Apr 2009
Messaggi: 50
|
pagina dinamica[shell]
Ciao a tutti,
ho un problema con un CGI in bash, in pratica da questa CGI creo dinamicamente una pagina nella quale devo gestire dinamicamente dei campi textarea e select...la prima idea che mi è venuta è quella di fare la CGI in bash, creare la pagina web dinamicamente e gestirla attraverso javascript dato che non saprei come fare in bash. Il problema è che usando funzioni javascript visualizzo solo una pagina bianca, mentre senza funzioni mi visualizza la pagina ma ovviamente non posso operarci dinamicamente |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Puoi postare il codice ?
|
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Apr 2009
Messaggi: 50
|
Codice:
#!/bin/sh
#prova per CGI
#QUERY_STRING=?name=a&password=b
echo "Content-type: text/html"
echo ""
#NOME IN PASSWD
NAME_DB=$(cat ./postit.db | cut -d ":" -f 1)
#PASSWORD IN PASSWD
PASSWORD_DB=$(cat ./postit.db | cut -d ":" -f 2)
#NOME IN QUERY_STRING
NAME=$(printf "$QUERY_STRING" | tr "&" "\n" | head -n1 | cut -d "=" -f2 )
#PASSWORD IN QUERY_STRING
PASSWORD=$(printf "$QUERY_STRING"|cut -d "=" -f3 --output-delimiter=" ")
if [ $NAME_DB = $NAME ] && [ $PASSWORD_DB = $PASSWORD ]
then
echo "<html>
<head>
<title>Postit</title>
<script type="text/javascript">
<!--
function addOpt() {
var newitem=document.form.postit.value;
if(newitem!=""){
document.form.messaggi[document.form.messaggi.length] = new Option(newitem, newitem)
}
}
function delOpt() {
if(document.form.messaggi.selectedIndex >= 0) {
document.form.messaggi.options[document.form.messaggi.selectedIndex]=null
document.form.messaggi.selectedIndex=0
}
}
function viewPost(msg) {
document.forms['form'].elements['postit'].value=msg;
}
//-->
</script>
</head>
<body bgcolor="#EE4422">
<form name="form">
<textarea name="postit" cols='20' rows='10' ></textarea><br>
<input type="button" value="Aggiungi" onclick=""/>
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Salva e incolla la pagina generata con tutti il codice JavaScript. Imho c'è qualche problema di caratteri di escape.
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Aug 2006
Città: Udine
Messaggi: 3590
|
Hey... ma questo è ancora quel "postit" malefico?
|
|
|
|
|
|
#6 |
|
Member
Iscritto dal: Apr 2009
Messaggi: 50
|
Eccolo al completo
#!/bin/sh #prova per CGI #QUERY_STRING=?name=a&password=b echo "Content-type: text/html" echo "" #NOME IN PASSWD NAME_DB=$(cat ./postit.db | cut -d ":" -f 1) #PASSWORD IN PASSWD PASSWORD_DB=$(cat ./postit.db | cut -d ":" -f 2) #NOME IN QUERY_STRING NAME=$(printf "$QUERY_STRING" | tr "&" "\n" | head -n1 | cut -d "=" -f2 ) #PASSWORD IN QUERY_STRING PASSWORD=$(printf "$QUERY_STRING"|cut -d "=" -f3 --output-delimiter=" ") if [ $NAME_DB = $NAME ] && [ $PASSWORD_DB = $PASSWORD ] then echo "<html> <head> <title>Postit</title> <script type="text/javascript"> <!-- function addOpt() { var newitem=document.form.postit.value; if(newitem!=""){ document.form.messaggi[document.form.messaggi.length] = new Option(newitem, newitem) } } function delOpt() { if(document.form.messaggi.selectedIndex >= 0) { document.form.messaggi.options[document.form.messaggi.selectedIndex]=null document.form.messaggi.selectedIndex=0 } } function viewPost(msg) { document.forms['form'].elements['postit'].value=msg; } //--> </script> </head> <body bgcolor="#EE4422"> <form name="form"> <textarea name="postit" cols='20' rows='10' ></textarea><br> <input type="button" value="Aggiungi" onclick="addOpt()"/> <input type="reset" value="Cancella" /> <fieldset name="fieldset"> <legend>Postit</legend> <select name="messaggi" id="messaggi" onchange="viewPost()"> <option value="lavare i piatti">lavare i piatti</option> <option value="andare a prendere i bambini a scuola">andare a prendere i bambini a scuola</option> <option value="finale di champions">finale di champions</option> </select> </fieldset> <input type="button" value="Elimina" onclick="delOpt()"/> </form> </body> </html>" else echo "<html>" echo "<head>" echo "<title>Accesso negato</title>" echo "</head>" echo "<body bgcolor="#EE4422">" echo "<pre>Accesso negato</pre>" echo "<a href="http://localhost/postit/postit.html">Torna alla schermata di LogIn</a>" echo "</body>" echo "</html>" fi exit 0 |
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Devi fare l'escape di tutti i doppi apici nel codice HTML
Ad esempio questa linea: <script type="text/javascript"> deve diventare così: <script type=\"text/javascript\"> |
|
|
|
|
|
#8 |
|
Member
Iscritto dal: Apr 2009
Messaggi: 50
|
grazie mille cionci, ora funziona! Ti son debitore
|
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Aug 2006
Città: Udine
Messaggi: 3590
|
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 04:24.




















