Merge branch 'master' of git@lx-office.linet-services.de:lx-office-erp
[kivitendo-erp.git] / scripts / console
index d7679d0..8443321 100755 (executable)
@@ -9,16 +9,17 @@ BEGIN {
   push    @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
 }
 
-use Config::Std;
 use Data::Dumper;
 use Devel::REPL 1.002001;
 use Term::ReadLine::Perl::Bind;     # use sane key binding for rxvt users
 
-read_config 'config/console.conf' => my %config;# if -f 'config/console.conf';
+use SL::LxOfficeConf;
+SL::LxOfficeConf->read;
 
-my $login        = shift || $config{Console}{login}        || 'demo';
-my $history_file =          $config{Console}{history_file} || '/tmp/lxoffice_console_history.log'; # fallback if users is not writable
-my $autorun      =          $config{Console}{autorun};
+my $login        = shift || $::lx_office_conf{console}{login}        || 'demo';
+my $history_file =          $::lx_office_conf{console}{history_file} || '/tmp/lxoffice_console_history.log'; # fallback if users is not writable
+my $debug_file   =          $::lx_office_conf{console}{log_file}     || '/tmp/lxoffice_console_debug.log';
+my $autorun      =          $::lx_office_conf{console}{autorun};
 
 # will be configed eventually
 my @plugins      = qw(History LexEnv Colors MultiLine::PPI FancyPrompt PermanentHistory AutoloadModules);
@@ -29,11 +30,23 @@ $repl->load_history($history_file);
 $repl->eval('help');
 $repl->print("trying to auto login as '$login'...");
 $repl->print($repl->eval("lxinit '$login'"));
-$repl->print($repl->eval($autorun)) if $autorun;
+if ($autorun) {
+  my $result = $repl->eval($autorun);
+  $repl->print($result->message) if ref($result) eq 'Devel::REPL::Error';
+}
 $repl->run;
 
 package Devel::REPL;
 
+use utf8;
+use CGI qw( -no_xhtml);
+use DateTime;
+use SL::Auth;
+use SL::Form;
+use SL::Helper::DateTime;
+use SL::Locale;
+use SL::LXDebug;
+use Data::Dumper;
 
 # this is a cleaned up version of am.pl
 # it lacks redirection, some html setup and most of the authentication process.
@@ -46,28 +59,11 @@ sub lxinit {
 
   package main;
 
-  { no warnings 'once';
-    $::userspath  = "users";
-    $::templates  = "templates";
-    $::memberfile = "users/members";
-    $::sendmail   = "| /usr/sbin/sendmail -t";
-  }
-
-  use SL::LXDebug;
-  $::lxdebug = LXDebug->new;
-
-  use CGI qw( -no_xhtml);
-  use SL::Auth;
-  use SL::Form;
-  use SL::Locale;
-  use Data::Dumper;
-
-  eval { require "config/lx-erp.conf"; };
-  eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf";
-
-  $::cgi  = CGI->new qw();
-  $::form = Form->new;
-  $::auth = SL::Auth->new;
+  $::lxdebug = LXDebug->new(file => $debug_file);
+  $::locale = Locale->new($::lx_office_conf{system}->{language});
+  $::cgi    = CGI->new qw();
+  $::form   = Form->new;
+  $::auth   = SL::Auth->new;
 
   die 'cannot reach auth db'               unless $::auth->session_tables_present;
 
@@ -76,8 +72,12 @@ sub lxinit {
   require "bin/mozilla/common.pl";
 
   die "cannot find user $login"            unless %::myconfig = $::auth->read_user($login);
+
+  $::form->{login} = $login; # normaly implicit at login
+
   die "cannot find locale for user $login" unless $::locale   = Locale->new($::myconfig{countrycode});
 
+
   return "logged in as $login";
 }
 
@@ -90,7 +90,7 @@ sub load {
 }
 
 sub reload {
-  use Module::Reload;
+  require Module::Reload;
   Module::Reload->check();
 
   return "modules reloaded";
@@ -110,18 +110,19 @@ sub help {
 Spezielle Kommandos:
 
   help                - zeigt diese Hilfe an.
-  lxinit 'login'      - lädt das Lx-Office Environment für den User 'login'.
-  reload              - lädt modifizierte Module neu.
+  lxinit 'login'      - lädt das Lx-Office Environment für den User 'login'.
+  reload              - lädt modifizierte Module neu.
   pp DATA             - zeigt die Datenstruktur mit Data::Dumper an.
   quit                - beendet die Konsole
 
 EOL
-#  load   'module'     - läd das angegebene Modul, d.h. bin/mozilla/module.pl und SL/Module.pm.
+#  load   'module'     - läd das angegebene Modul, d.h. bin/mozilla/module.pl und SL/Module.pm.
 }
 
 sub pp {
-  $Data::Dumper::Indent   = 2;
-  $Data::Dumper::Maxdepth = 2;
+  local $Data::Dumper::Indent   = 2;
+  local $Data::Dumper::Maxdepth = 2;
+  local $Data::Dumper::Sortkeys = 1;
   Data::Dumper::Dumper(@_);
 }
 
@@ -131,7 +132,7 @@ __END__
 
 =head1 NAME
 
-scripts/console - Lx Office Console
+scripts/console - Lx-Office console
 
 =head1 SYNOPSIS
 
@@ -184,13 +185,13 @@ of the classes they were created with.
 
 Configuration of this script is located in:
 
- config/console.conf
- config/console.conf.default
+ config/lx_office.conf
+ config/lx_office.conf.default
 
 See there for interesting options.
 
 =head1 AUTHOR
 
-  Sven Schöling <s.schoeling@linet-services.de>
+  Sven Schöling <s.schoeling@linet-services.de>
 
 =cut