#!/usr/bin/btcl
# File di libreria:
source file_variabili.var
source lib_mail_osp
# Variabili necessarie per controlli:
set login ""
set pass ""
set linea ""
set msg ""
set dest ""
set tmp [exec /bin/ls $m(lib_dir)]
set n_a [array_str $tmp "\n" dast]
for {set tmp 0} {$tmp<[expr $n_a+2]} {incr tmp} {set dast($tmp) 0}
# Studio le variabili post passate e le rendo utilizzabili:
cgi_post
# Studio le variabili get se ci sono e le rendo utilizzabili:
if {[cgi_get]!=-1} {
#Se ci sono, vado a leggere gli header:
set puntb 0
set ok 0
set fl [open "$m(lib_dir)/$login"]
while {[gets $fl linea]!=-1} {
if {$linea=="%%"} {
incr puntb
if {$puntb==$punto} {
gets $fl dest
gets $fl header
set tutto ""
while {[gets $fl line]!=-1} {
if {$line=="%%"} {break}
set tutto "$tutto\n$line"
}
incr ok
break
}
}
}
# Se ci sono gli header li mostro:
if {$header!=""} {
regexp {([^-]+)-([^-]+)-(.*)$} $header b ip_client ip_server data
puts "Content-type: text/html"
puts ""
header_1
exit
# Altrimenti no:
} else {
puts "Content-type: text/html"
puts ""
header_2
exit
}
}
# Controllo l'esistenza di login e password:
if {[string length $login]==0} {puts "Content-type: text/html";puts "";login; exit; }
if {[string length $pass]==0} {puts "Content-type: text/html";puts "";login; exit; }
# Gestisco il comando ESCI:
if {$cmd=="ESCI"} {
puts "Content-type: text/html"
puts ""
esci_1
exit
}
# Controllo login e password:
set fl [open $m(lib_prog) r]
set pass_crypt [crypt_des $pass $login]
set flag 0
while {[gets $fl linea]!=-1} {
regexp {([^:]+):([^:]+):(.*)$} $linea tutto l p graphic
if {($l==$login) && ($p==$pass_crypt)} {set flag 1;break}
}
# Se non sono corrette:
if {$flag==0} {
puts "Content-type: text/html"
puts ""
pass_errore_1
# Comando ENTRA:
} elseif {$cmd=="ENTRA"} {
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_entra_1
} elseif {$graphic==3} {
c_entra_1
} else {
a_entra_1
}
# Comando SCRIVI:
} elseif {$cmd=="SCRIVI"} {
set rispo 0
set msg ""
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_scrivi_1
} elseif {$graphic==3} {
c_scrivi_1
} else {
a_scrivi_1
}
# Mostro la lista utenti:
set tmp [exec /bin/ls $m(lib_dir)]
set n_a [array_str $tmp "\n" dat]
for {set tmp 0} {$tmp<$n_a} {incr tmp} {
if {$dat($tmp)!="tmp.tmp"} {puts ""}
}
if {$graphic==2} {
b_scrivi_2
} elseif {$graphic==3} {
c_scrivi_2
} else {
a_scrivi_2
}
# Comando LEGGI:
} elseif {$cmd=="LEGGI"} {
set dest ""
set punto 1
set fl [open $m(lib_dir)/$login]
while {[gets $fl line]!=-1} {
if {$line=="%%"} {
gets $fl dest
gets $fl line
set tutto ""
while {[gets $fl line]!=-1} {
if {$line=="%%"} {
break
}
append tutto "\n" $line
}
break
}
}
close $fl
set tutto [string range $tutto 1 end]
# Se non ci sono messaggi:
if {[string length $dest]==0} {
set frase "Non ci sono messaggi."
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_frase_1
} elseif {$graphic==3} {
c_frase_1
} else {
a_frase_1
}
# Se ci sono:
} else {
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_leggi_1
} elseif {$graphic==3} {
c_leggi_1
} else {
a_leggi_1
}
}
# Comando IMPOSTA:
} elseif {$cmd=="IMPOSTA"} {
set frase ""
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_imposta_1
} elseif {$graphic==3} {
c_imposta_1
} else {
a_imposta_1
}
# Comando Modifica (ovvero dopo che vengono impostati della pass e roba simile)
} elseif {$cmd=="Modifica"} {
if {$g!=$graphic} {set graphic $g}
if {[string length $pass1]==0} {
set pass1 $pass
set pass2 $pass
}
# Se mettono password nuove diverse:
if {$pass1!=$pass2} {
set frase "Le due password sono diverse. Riprovare "
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_imposta_1
} elseif {$graphic==3} {
c_imposta_1
} else {
a_imposta_1
}
# Effettuo l'operazione:
} else {
set file_c [open $m(lib_prog) r]
set file_d [open $m(lib_dir)/tmp.tmp w]
set pass_crypt [crypt_des $pass $login]
while {[gets $file_c r_file]!=-1} {
regexp {([^:]+):([^:]+):(.*)$} $r_file tutto l p c
if {($l==$login) && ($p==$pass_crypt)} {
puts $file_d "$login:[crypt_des $pass1 $login]:$graphic"
puts "$login:[crypt_des $pass1 $login]:$graphic"
# Scrivi righe normali
} else {
puts $file_d $r_file
}
}
close $file_c
close $file_d
set file_c [open $m(lib_dir)/tmp.tmp r]
set file_d [open $m(lib_prog) w]
while {[gets $file_c linea]!=-1} {
puts $file_d $linea
}
close $file_c
close $file_d
set pass $pass1
}
set frase "Operazione effettuata con successo!"
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_frase_1
} elseif {$graphic==3} {
c_frase_1
} else {
a_frase_1
}
# Comando INVIA:
} elseif {$cmd=="INVIA"} {
set fl [open "$m(lib_dir)/$dest" a]
set date [exec date]
set tutto ""
for {set n_msg 0} {$n_msg < [array_str $msg "\n" a_msg]} {incr n_msg} {
append tutto "\n"
while {([string length $a_msg($n_msg)] > 70) && ([string match "* *" [string range $a_msg($n_msg) 70 90] ])} {
append tutto [string range $a_msg($n_msg) 0 69]
set a_msg($n_msg) "a[string range $a_msg($n_msg) 70 end]"
regexp {([^ ]+) (.*)$} $a_msg($n_msg) a pre a_msg($n_msg)
append tutto [string range $pre 1 end] "\n"
}
append tutto $a_msg($n_msg)
}
set tutto [string range $tutto 1 end]
set tutto [code_hex $tutto]
puts $fl "%%\n$login\n$env(REMOTE_ADDR)-$env(SERVER_ADDR) $env(SERVER_NAME)-$date\n$tutto"
close $fl
set frase "Operazione effettuata con successo!"
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_frase_1
} elseif {$graphic==3} {
c_frase_1
} else {
a_frase_1
}
# Comando Rispondi:
} elseif {$cmd=="Rispondi"} {
set puntb 0
set ok 0
set rispo 1
set fl [open $m(lib_dir)/$login]
while {[gets $fl linea]!=-1} {
if {$linea=="%%"} {
incr puntb
if {$puntb==$punto} {
gets $fl dest
gets $fl linea
set tutto ""
while {[gets $fl line]!=-1} {
if {$line=="%%"} {break}
set tutto "$tutto\n$line"
}
incr ok
break
}
}
}
set tutto [string range $tutto 1 end]
set lista [array_str $tutto "\n" new_msg]
set post $tutto
set msg "\>"
while {[string match "*\&\#010;*" $post]} {
set tmp [string first "\&\#010;" $post]
append msg [string range $post 0 [expr $tmp-1]] "\>\&\#010;"
set post [string range $post [expr $tmp+6] end]
}
append msg $post
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_scrivi_1
} elseif {$graphic==3} {
c_scrivi_1
} else {
a_scrivi_1
}
# Lista utenti:
set tmp [exec /bin/ls $m(lib_dir)]
array_str $tmp "\n" dat
for {set tmp 0} {$tmp<[array size dat]} {incr tmp} {
if {$dat($tmp)==$dest} {
puts ""
} elseif {$dat($tmp)!="tmp.tmp"} {
puts ""
}
}
if {$graphic==2} {
b_scrivi_2
} elseif {$graphic==3} {
c_scrivi_2
} else {
a_scrivi_2
}
# Comando Successivo:
} elseif {$cmd=="Successivo"} {
set puntb 0
incr punto
set ok 0
set fl [open $m(lib_dir)/$login]
while {[gets $fl linea]!=-1} {
if {$linea=="%%"} {
incr puntb
if {$puntb==$punto} {
gets $fl dest
gets $fl linea
set tutto ""
while {[gets $fl line]!=-1} {
if {$line=="%%"} {break}
set tutto "$tutto\n$line"
}
incr ok
break
}
}
}
set tutto [string range $tutto 1 end]
# Se non ci sono altri messaggi successivi:
if {$ok==0} {
incr punto -1
set frase "Non ci sono messaggi successivi."
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_frase_2
} elseif {$graphic==3} {
c_frase_2
} else {
a_frase_2
}
# Se ci sono:
} else {
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_leggi_1
} elseif {$graphic==3} {
c_leggi_1
} else {
a_leggi_1
}
}
# Comando Cancella:
} elseif {$cmd=="Cancella"} {
set fl [open $m(lib_dir)/$login r]
set f_t [open $m(lib_dir)/tmp.tmp w]
set conta 1
while {[gets $fl line]!=-1} {
if {$line!="%%"} {
puts $f_t $line
} elseif {$conta!=$punto} {
incr conta
puts $f_t $line
} else {
incr conta
while {[gets $fl line]!=-1} {
if {$line=="%%"} {
puts $f_t $line
break
}
}
}
}
close $fl
close $f_t
set f_c [open "$m(lib_dir)/tmp.tmp" r]
set f_d [open "$m(lib_dir)/$login" w]
while {[gets $f_c line]!=-1} {
puts $f_d $line
}
close $f_c
close $f_d
set frase "Operazione effettuata con successo!"
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_frase_2
} elseif {$graphic==3} {
c_frase_2
} else {
a_frase_2
}
# Comando Precedente:
} elseif {$cmd=="Precedente"} {
set puntb 0
set ok 0
if {$punto>1} {
set fl [open $m(lib_dir)/$login]
while {[gets $fl linea]!=-1} {
if {$linea=="%%"} {
incr puntb
if {$puntb==[expr $punto-1]} {
gets $fl dest
gets $fl linea
set tutto ""
while {[gets $fl line]!=-1} {
if {$line=="%%"} {break}
set tutto "$tutto\n$line"
}
incr ok
break
}
}
}
incr punto -1
}
set tutto [string range $tutto 1 end]
# Se non ci sono messaggi precedenti:
if {$ok==0} {
set frase "Non ci sono messaggi precedenti."
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_frase_2
} elseif {$graphic==3} {
c_frase_2
} else {
a_frase_2
}
# Se ci sono:
} else {
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_leggi_1
} elseif {$graphic==3} {
c_leggi_1
} else {
a_leggi_1
}
}
# Comando Invia a + persone:
} elseif {$cmd=="Invia"} {
set date [exec date]
set tutto ""
for {set n_msg 0} {$n_msg < [array_str $msg "\n" a_msg]} {incr n_msg} {
append tutto "\n"
while {([string length $a_msg($n_msg)] > 70) && ([string match "* *" [string range $a_msg($n_msg) 70 90] ])} {
append tutto [string range $a_msg($n_msg) 0 69]
set a_msg($n_msg) "a[string range $a_msg($n_msg) 70 end]"
regexp {([^ ]+) (.*)$} $a_msg($n_msg) a pre a_msg($n_msg)
append tutto [string range $pre 1 end] "\n"
}
append tutto $a_msg($n_msg)
}
set tutto [code_hex $tutto]
set tmp [exec /bin/ls $m(lib_dir)]
set n_a [array_str $tmp "\n" tmp_array]
if {$dast([expr $n_a+1])==1} {
for {set tmp 0} {$tmp<$n_a} {incr tmp} {
if {$tmp_array($tmp)!="tmp.tmp"} {
set fl [open "$m(lib_dir)/$tmp_array($tmp)" a]
puts $fl "%%\n$login\n$env(REMOTE_ADDR)-$env(SERVER_ADDR) $env(SERVER_NAME)-$date\n$tutto"
close $fl
}
}
} else {
for {set tmp 0} {$tmp<$n_a} {incr tmp} {
if {$dast($tmp)==1} {
set fl [open "$m(lib_dir)/$tmp_array($tmp)" a]
puts $fl "%%\n$login\n$env(REMOTE_ADDR)-$env(SERVER_ADDR) $env(SERVER_NAME)-$date\n$tutto"
close $fl
}
}
}
set frase "Operazione effettuata con successo!"
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_frase_1
} elseif {$graphic==3} {
c_frase_1
} else {
a_frase_1
}
# Imposto il numero dei destinatari
} elseif {$cmd=="Avanzato"} {
set msg ""
puts "Content-type: text/html"
puts ""
# Mostro la lista utenti:
set tmp [exec /bin/ls $m(lib_dir)]
set n_a [array_str $tmp "\n" dat_user]
if {$graphic==2} {
b_adv_scrivi
} elseif {$graphic==3} {
c_adv_scrivi
} else {
a_adv_scrivi
}
# Altri comandi di sola visualizzazione:
} elseif {($cmd=="Header") || ($cmd=="Ritorna")} {
set puntb 0
set ok 0
set fl [open "$m(lib_dir)/$login"]
while {[gets $fl linea]!=-1} {
if {$linea=="%%"} {
incr puntb
if {$puntb==$punto} {
gets $fl dest
gets $fl linea
set tutto ""
incr ok
while {[gets $fl line]!=-1} {
if {$line=="%%"} {break}
set tutto "$tutto\n$line"
}
break
}
}
}
if {($ok==0) && ($punto>1)} {
incr punto -1
set puntb 0
set ok 0
set fl [open "$m(lib_dir)/$login"]
while {[gets $fl linea]!=-1} {
if {$linea=="%%"} {
incr puntb
if {$puntb==$punto} {
gets $fl dest
gets $fl linea
set tutto ""
incr ok
while {[gets $fl line]!=-1} {
if {$line=="%%"} {break}
set tutto "$tutto\n$line"
}
break
}
}
}
}
set tutto [string range $tutto 1 end]
# Se ci sono, mostrali:
if {$ok!=0} {
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_leggi_1
} elseif {$graphic==3} {
c_leggi_1
} else {
a_leggi_1
}
# Se no, no:
} else {
set frase "Non ci sono altri messaggi"
puts "Content-type: text/html"
puts ""
if {$graphic==2} {
b_frase_1
} elseif {$graphic==3} {
c_frase_1
} else {
a_frase_1
}
}
}