5 use 5.008; # too much magic in here to include perl 5.6
8 unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
9 push @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
14 use Devel::REPL 1.002001;
16 require Term::ReadLine::Perl::Bind; # use sane key binding for rxvt users
19 read_config 'config/console.conf' => my %config;# if -f 'config/console.conf';
21 my $login = shift || $config{Console}{login} || 'demo';
22 my $history_file = $config{Console}{history_file} || '/tmp/lxoffice_console_history.log'; # fallback if users is not writable
23 my $autorun = $config{Console}{autorun};
25 # will be configed eventually
26 my @plugins = qw(History LexEnv Colors MultiLine::PPI FancyPrompt PermanentHistory AutoloadModules);
28 my $repl = Devel::REPL->new;
29 $repl->load_plugin($_) for @plugins;
30 $repl->load_history($history_file);
32 $repl->print("trying to auto login as '$login'...");
33 $repl->print($repl->eval("lxinit '$login'"));
34 $repl->print($repl->eval($autorun)) if $autorun;
40 # this is a cleaned up version of am.pl
41 # it lacks redirection, some html setup and most of the authentication process.
42 # it is assumed that anyone with physical access and execution rights on this script
43 # won't be hindered by authentication anyway.
47 die 'need login' unless $login;
52 $::userspath = "users";
53 $::templates = "templates";
54 $::memberfile = "users/members";
55 $::sendmail = "| /usr/sbin/sendmail -t";
59 $::lxdebug = LXDebug->new;
61 use CGI qw( -no_xhtml);
67 eval { require "config/lx-erp.conf"; };
68 eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf";
70 $::cgi = CGI->new qw();
72 $::auth = SL::Auth->new;
74 die 'cannot reach auth db' unless $::auth->session_tables_present;
76 $::auth->restore_session;
78 require "bin/mozilla/common.pl";
80 die "cannot find user $login" unless %::myconfig = $::auth->read_user($login);
81 die "cannot find locale for user $login" unless $::locale = Locale->new($::myconfig{countrycode});
83 return "logged in as $login";
86 # these function provides a load command to slurp in a lx-office module
87 # since it's seldomly useful, it's not documented in help
90 $module =~ s/[^\w]//g;
91 require "bin/mozilla/$module.pl";
95 require Module::Reload;
96 Module::Reload->check();
98 return "modules reloaded";
110 ./scripts/console [login]
114 help - zeigt diese Hilfe an.
115 lxinit 'login' - lädt das Lx-Office Environment für den User 'login'.
116 reload - lädt modifizierte Module neu.
117 pp DATA - zeigt die Datenstruktur mit Data::Dumper an.
118 quit - beendet die Konsole
121 # load 'module' - läd das angegebene Modul, d.h. bin/mozilla/module.pl und SL/Module.pm.
125 $Data::Dumper::Indent = 2;
126 $Data::Dumper::Maxdepth = 2;
127 Data::Dumper::Dumper(@_);
136 scripts/console - Lx Office Console
141 > help # displays a brief documentation
145 Users of Ruby on Rails will recognize this as a perl reimplementation of the
146 rails scripts/console. It's intend is to provide a shell environment to the
147 lx-office internals. This will mostly not interest you if you just want to do
148 your ERP stuff with lx-office, but will be invaluable for those who wish to
149 make changes to lx-office itself.
153 You can do most things in the console that you could do in an actual perl
154 script. Certain helper functions will aid you in debugging the state of the
159 Named after the rails pretty print gem, this will call Data::Dumper on the
160 given C<DATA>. Use it to see what is going on.
162 Currently C<pp> will set the Data::Dumper depth to 2, so if you need a
163 different depth, you'll have to change that. A nice feature would be to
164 configure that, or at least to be able to change it at runtime.
166 =head2 lxinit C<login>
168 Login into lx-office using a specified login. No password will be required, and
169 security mechanisms will mostly be inactive. form, locale, myconfig will be
174 Attempts to reload modules that changed since last reload (or inital startup).
175 This will mostly work just fine, except for Moose classes that have been made
176 immutable. Keep in mind that existing objects will continue to have the methods
177 of the classes they were created with.
181 - Reload on immutable Moose classes is buggy.
182 - Logging in more than once is not supported by the program, and thus not by
183 the console. It seems to work, but strange things may happen.
187 Configuration of this script is located in:
190 config/console.conf.default
192 See there for interesting options.
196 Sven Schöling <s.schoeling@linet-services.de>