X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fadmin.pl;h=4409505c1f86f184ed69332aaafc5e3a52c5bb92;hb=4a01a26b54aa6a5b97617a8d3fb2dc9b86ceb4c3;hp=a9769a06b6f82b7635f4a73e62b5b64e0766c474;hpb=bd23cc3e64900f14317c147aa52a8b1a7633e2a4;p=kivitendo-erp.git diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl old mode 100644 new mode 100755 index a9769a06b..4409505c1 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -32,885 +32,582 @@ # #====================================================================== -$menufile = "menu.ini"; - use DBI; -use CGI; - +use Encode; +use English qw(-no_match_vars); +use Fcntl; +use File::Copy; +use File::Find; +use File::Spec; +use Cwd; +use IO::File; +use POSIX qw(strftime); +use Sys::Hostname; + +use SL::Auth; +use SL::Auth::PasswordPolicy; use SL::Form; +use SL::Iconv; +use SL::Mailer; use SL::User; use SL::Common; +use SL::Inifile; +use SL::DBUpgrade2; +use SL::DBUtils; require "bin/mozilla/common.pl"; +require "bin/mozilla/admin_groups.pl"; +require "bin/mozilla/admin_printer.pl"; + +use strict; + +# parserhappy(R): + +# $locale->text('periodic') +# $locale->text('income') +# $locale->text('perpetual') +# $locale->text('balance') + +our $cgi; +our $form; +our $locale; +our $auth; + +my @valid_dateformats = qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd); +my @valid_numberformats = ('1,000.00', '1000.00', '1.000,00', '1000,00'); +my @all_stylesheets = qw(lx-office-erp.css Win2000.css Mobile.css kivitendo.css); +my @all_menustyles = ( + { id => 'old', title => $::locale->text('Old (on the side)') }, + { id => 'v3', title => $::locale->text('Top (CSS)') }, + { id => 'v4', title => $::locale->text('Top (CSS) new') }, + { id => 'neu', title => $::locale->text('Top (Javascript)') }, +); + +sub run { + $::lxdebug->enter_sub; + my $session_result = shift; + + $form = $::form; + $locale = $::locale; + $auth = $::auth; + + $form->{stylesheet} = "lx-office-erp.css"; + $form->{favicon} = "favicon.ico"; + + if ($form->{action}) { + if ($auth->authenticate_root($form->{'{AUTH}admin_password'}) != $auth->OK()) { + $auth->punish_wrong_login; + $form->{error_message} = $locale->text('Incorrect Password!'); + $auth->delete_session_value('admin_password'); + adminlogin(); + } else { + if ($auth->session_tables_present()) { + delete $::form->{'{AUTH}admin_password'}; + _apply_dbupgrade_scripts(); + } -our $cgi = new CGI(''); - -$form = new Form; -$form->{"root"} = "root login"; - -$locale = new Locale $language, "admin"; - -# customization -if (-f "bin/mozilla/custom_$form->{script}") { - eval { require "bin/mozilla/custom_$form->{script}"; }; - $form->error($@) if ($@); -} - -$form->{stylesheet} = "lx-office-erp.css"; -$form->{favicon} = "favicon.ico"; - -if ($form->{action}) { - - - $subroutine = $locale->findsub($form->{action}); - - if ($subroutine eq 'login') { - if ($form->{rpw}) { - $form->{rpw} = crypt $form->{rpw}, "ro"; + call_sub($locale->findsub($form->{action})); } - } - - check_password(); - - call_sub($subroutine); - -} else { - - # if there are no drivers bail out - $form->error($locale->text('No Database Drivers available!')) - unless (User->dbdrivers); - - # create memberfile - if (!-f $memberfile) { - open(FH, ">$memberfile") or $form->error("$memberfile : $!"); - print FH qq|# SQL-Ledger Accounting members - -[root login] -password= + } else { + # if there are no drivers bail out + $form->error($locale->text('No Database Drivers available!')) + unless (User->dbdrivers); -|; - close FH; + adminlogin(); } - - adminlogin(); - + $::lxdebug->leave_sub; } -1; - -# end - sub adminlogin { + my $form = $main::form; + my $locale = $main::locale; - $form->{title} = - qq|Lx-Office ERP $form->{version} | . $locale->text('Administration'); + $form->{title} = qq|kivitendo $form->{version} | . $locale->text('Administration'); $form->header(); print $form->parse_html_template('admin/adminlogin'); } sub login { + check_auth_db_and_tables(); list_users(); } -sub list_users { - - $form->error($locale->text('File locked!')) if (-f "${memberfile}.LCK"); +sub logout { + $main::auth->destroy_session(); + adminlogin(); +} - open(FH, "$memberfile") or $form->error("$memberfile : $!"); +sub check_auth_db_and_tables { + my $form = $main::form; + my $locale = $main::locale; - my %members; + my %params; - while () { - chomp; + map { $params{"db_${_}"} = $main::auth->{DB_config}->{$_} } keys %{ $auth->{DB_config} }; - if (/^\[.*\]/) { - $login = $_; - $login =~ s/(\[|\])//g; - - $members{$login} = { "login" => $login }; - } + if (!$main::auth->check_database()) { + $form->{title} = $locale->text('Authentification database creation'); + $form->header(); + print $form->parse_html_template('admin/check_auth_database', \%params); - if (/^([a-z]+)=(.*)/) { - $members{$login}->{$1} = $2; - } + ::end_of_request(); } - close(FH); - - delete $members{"root login"}; - map { $_->{templates} =~ s|.*/||; } values %members; + if (!$main::auth->check_tables()) { + $form->{title} = $locale->text('Authentification tables creation'); + $form->header(); + print $form->parse_html_template('admin/check_auth_tables', \%params); - $form->{title} = "Lx-Office ERP " . $locale->text('Administration'); - $form->{LOCKED} = -e "$userspath/nologin"; - $form->{MEMBERS} = [ @members{sort { lc $a cmp lc $b } keys %members} ]; + ::end_of_request(); + } - $form->header(); - print $form->parse_html_template("admin/list_users"); -} + my $memberfile = $::lx_office_conf{paths}->{memberfile}; + if (-f $memberfile) { + my $memberdir = ""; -sub add_user { + if ($memberfile =~ m|^.*/|) { + $memberdir = $&; + } - $form->{title} = - "Lx-Office ERP " - . $locale->text('Administration') . " / " - . $locale->text('Add User'); + my $backupdir = "${memberdir}member-file-migration"; - $form->{Oracle_sid} = $sid; - $form->{Oracle_dbport} = '1521'; - $form->{Oracle_dbhost} = `hostname`; + $form->{title} = $locale->text('User data migration'); + $form->header(); + print $form->parse_html_template('admin/user_migration', { 'memberfile' => $memberfile, + 'backupdir' => $backupdir }); - if (-f "css/lx-office-erp.css") { - $myconfig->{stylesheet} = "lx-office-erp.css"; + ::end_of_request(); } +} - $myconfig->{vclimit} = 200; - $myconfig->{countrycode} = "de"; - $myconfig->{numberformat} = "1000,00"; - $myconfig->{dateformat} = "dd.mm.yy"; - - form_header(); - form_footer(); +sub create_auth_db { + my $form = $main::form; + $main::auth->create_database('superuser' => $form->{db_superuser}, + 'superuser_password' => $form->{db_superuser_password}, + 'template' => $form->{db_template}); + login(); } -sub edit { +sub create_auth_tables { + my $form = $main::form; + my $locale = $main::locale; - $form->{title} = - "Lx-Office ERP " - . $locale->text('Administration') . " / " - . $locale->text('Edit User'); - $form->{edit} = 1; + $main::auth->create_tables(); + $main::auth->set_session_value('admin_password', $form->{'{AUTH}admin_password'}); + $main::auth->create_or_refresh_session(); - form_header(); - form_footer(); + my $memberfile = $::lx_office_conf{paths}->{memberfile}; + if (!-f $memberfile) { + # New installation -- create a standard group with full access + my %members; + my $group = { + 'name' => $locale->text('Full Access'), + 'description' => $locale->text('Full access to all functions'), + 'rights' => { map { $_ => 1 } SL::Auth::all_rights() }, + 'members' => [ map { $_->{id} } values %members ], + }; + + $main::auth->save_group($group); + } + _apply_dbupgrade_scripts(); + login(); } -sub form_footer { +sub migrate_users { + $main::lxdebug->enter_sub(); - if ($form->{edit}) { - $delete = - qq| -|; - } + my $form = $main::form; + my $locale = $main::locale; - print qq| + my $memberdir = ""; - -{rpw}> + my $memberfile = $::lx_office_conf{paths}->{memberfile}; + if ($memberfile =~ m|^.*/|) { + $memberdir = $&; + } - -$delete + my $backupdir = "${memberdir}member-file-migration"; - + if (! -d $backupdir && !mkdir $backupdir, 0700) { + $form->error(sprintf($locale->text('The directory "%s" could not be created:\n%s'), $backupdir, $!)); + } - - -|; + copy $memberfile, "users/member-file-migration/members"; -} + my $in = IO::File->new($memberfile, "r"); -sub form_header { + $form->error($locale->text('Could not open the old memberfile.')) if (!$in); - # if there is a login, get user - if ($form->{login}) { + my (%members, $login); - # get user - $myconfig = new User "$memberfile", "$form->{login}"; + while (<$in>) { + chomp; - $myconfig->{signature} =~ s/\\n/\r\n/g; - $myconfig->{address} =~ s/\\n/\r\n/g; + next if (m/^\s*\#/); - # strip basedir from templates directory - $myconfig->{templates} =~ s/^$templates\///; + if (m/^\[.*\]/) { + $login = $_; + $login =~ s/(\[|\])//g; + $login =~ s/^\s*//; + $login =~ s/\s*$//; - # $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - } + $members{$login} = { "login" => $login }; + next; + } - foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) { - $dateformat .= - ($item eq $myconfig->{dateformat}) - ? "