@ -90,8 +90,9 @@ sub get_available_languages()
sub log_msg ()
{
my $ text = shift ;
# TODO: improve or remove!
system ( "echo $text >>$LOG_FILE" ) ;
open ( LOGFILE , ">> $LOG_FILE" ) ;
print LOGFILE "$text" ;
close ( LOGFILE ) ;
}
@ -153,29 +154,22 @@ sub mount_vol
my $ pw = shift ;
if ( & check_mounted ) {
$ pagedata - > setValue ( 'Data.Warning' , 'Das Dateisystem war bereits aktiv!' ) ;
return 0 ;
$ pagedata - > setValue ( 'Data.Warning' , 'IsMounted' ) ;
} else {
open ( PW_INPUT , "| $CB_SCRIPT crypto-up" ) ;
print PW_INPUT $ pw ;
close ( PW_INPUT ) ;
}
# TODO: the output is always empty?
my $ output = open ( PW_INPUT , "| $CB_SCRIPT crypto-mount" ) ;
print PW_INPUT $ pw ;
close ( PW_INPUT ) ;
$ pagedata - > setValue ( 'Data.ProgOutput' , "$output" ) if ( $ output ) ;
}
sub umount_vol
{
unless ( & check_mounted ) {
$ pagedata - > setValue ( 'Data.Warning' , 'Das Dateisystem war bereits inaktiv!' ) ;
return 0 ;
if ( & check_mounted ) {
system ( "$CB_SCRIPT" , "crypto-down" ) ;
} else {
$ pagedata - > setValue ( 'Data.Warning' , 'NotMounted' ) ;
}
# TODO: check if "system" returns output
my $ output = `$CB_SCRIPT crypto-umount` ;
$ pagedata - > setValue ( 'Data.ProgOutput' , "$output" ) if ( $ output ) ;
}
@ -195,14 +189,14 @@ sub box_init
sub system_poweroff ()
{
& umount_vol ( ) ;
& umount_vol ( ) if ( & check_mounted ( ) ) ;
system ( "$CB_SCRIPT" , "poweroff" ) ;
}
sub system_reboot ()
{
& umount_vol ( ) ;
& umount_vol ( ) if ( & check_mounted ( ) ) ;
system ( "$CB_SCRIPT" , "reboot" ) ;
}
@ -246,8 +240,6 @@ my $query = new CGI;
$ pagedata = load_hdf ( ) ;
#TODO: check result of actions and set Data.Error for failures
######### temporary language setting? ############
# the default language can be overriden by the language links in the
# upper right of the page
@ -292,9 +284,10 @@ if ( ! &check_ssl()) {
if ( & check_mounted ( ) ) {
$ pagedata - > setValue ( 'Data.Warning' , 'UmountFailed' ) ;
$ pagedata - > setValue ( 'Data.Action' , 'umount_form' ) ;
}
$ pagedata - > setValue ( 'Data.Success' , 'UmountDone' ) ;
$ pagedata - > setValue ( 'Data.Action' , 'mount_form' ) ;
} else {
$ pagedata - > setValue ( 'Data.Success' , 'UmountDone' ) ;
$ pagedata - > setValue ( 'Data.Action' , 'mount_form' ) ;
}
}
################ mount_do ########################
} elsif ( $ action eq 'mount_do' ) {
@ -423,15 +416,31 @@ if ( ! &check_ssl()) {
$ pagedata - > setValue ( 'Data.Warning' , 'IPAddressChanged' ) ;
}
# TODO: check for success by comparing with new config and report success
$ pagedata - > setValue ( 'Data.Success' , 'ConfigSaved' ) ;
# TODO: maybe the intro page does not fit here ...
# check for success
if ( `$CB_SCRIPT get_config timeout` ne $ query - > param ( 'timeout' ) ) {
$ pagedata - > setValue ( 'Data.Warning' , 'ConfigTimeOutFailed' ) ;
} elsif ( `$CB_SCRIPT get_config ip` ne $ query - > param ( 'ip' ) ) {
$ pagedata - > setValue ( 'Data.Warning' , 'ConfigIPFailed' ) ;
} elsif ( `$CB_SCRIPT get_config language` ne $ query - > param ( 'language' ) ) {
$ pagedata - > setValue ( 'Data.Warning' , 'ConfigLanguageFailed' ) ;
} else {
$ pagedata - > setValue ( 'Data.Success' , 'ConfigSaved' ) ;
}
$ pagedata - > setValue ( 'Data.Action' , 'intro' ) ;
}
}
#################### show_log #######################
} elsif ( $ action eq 'show_log' ) {
$ pagedata - > setValue ( 'Data.Action' , 'show_log' ) ;
##################### doc ############################
} elsif ( $ action eq 'doc' ) {
if ( $ query - > param ( 'page' ) ) {
$ pagedata - > setValue ( 'Data.Doc.Page' , $ query - > param ( 'page' ) ) ;
$ pagedata - > setValue ( 'Data.Action' , 'doc' ) ;
} else {
$ pagedata - > setValue ( 'Data.Doc.Page' , 'CryptoBox' ) ;
$ pagedata - > setValue ( 'Data.Action' , 'doc' ) ;
}
##################### poweroff ######################
} elsif ( $ action eq 'shutdown_ask' ) {
$ pagedata - > setValue ( 'Data.Action' , 'shutdown_form' ) ;
@ -461,7 +470,7 @@ $pagedata->setValue('Data.Status.Mounted', &check_mounted() ? 1 : 0);
my $ output = & get_current_ip ( ) ;
$ pagedata - > setValue ( 'Data.Status.IP' , "$output" ) ;
$ output = `$CB_SCRIPT diskinfo 2>&1 | sed 's/^/<br>/'` ;
( $ output = `$CB_SCRIPT diskinfo 2>&1 `) =~ s #\Z#<br/># ;
$ pagedata - > setValue ( 'Data.PartitionInfo' , "$output" ) ;
# preset config settings for clearsilver
@ -469,8 +478,13 @@ $pagedata->setValue('Data.Config.IP', `$CB_SCRIPT get_config ip`);
$ pagedata - > setValue ( 'Data.Config.TimeOut' , `$CB_SCRIPT get_config timeout` ) ;
$ pagedata - > setValue ( 'Data.Config.Language' , `$CB_SCRIPT get_config language` ) ;
# read log - TODO: use perl filtering
$ output = ( - e "$LOG_FILE" ) ? `cat '$LOG_FILE' | sed 's/^/<br>/'` : '' ;
# read log and add html linebreaks
$ output = '' ;
if ( - e "$LOG_FILE" ) {
open ( LOGFILE , "< $LOG_FILE" ) ;
while ( <LOGFILE> ) { $ output . = "$_<br/>" }
close ( LOGFILE ) ;
}
$ pagedata - > setValue ( 'Data.Log' , "$output" ) ;
$ pagedata - > setValue ( 'Data.Status.DevelopmentMode' , 1 ) if ( $ IS_DEV ) ;