X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fadmin.pl;h=2472f6c6cd1319e16c7f00336ccbb908450814fc;hb=dfb76ebf04df9aed8ba63d7b51bc558d2928030e;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..2472f6c6c --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -32,641 +32,464 @@ # #====================================================================== -$menufile = "menu.ini"; - use DBI; -use CGI; - +use Encode; +use English qw(-no_match_vars); +use Fcntl; +use File::Copy; +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"; -our $cgi = new CGI(''); - -$form = new Form; -$form->{"root"} = "root login"; +use strict; -$locale = new Locale $language, "admin"; +our $cgi; +our $form; +our $locale; +our $auth; -# customization -if (-f "bin/mozilla/custom_$form->{script}") { - eval { require "bin/mozilla/custom_$form->{script}"; }; - $form->error($@) if ($@); -} +sub run { + $::lxdebug->enter_sub; + my $session_result = shift; -$form->{stylesheet} = "lx-office-erp.css"; -$form->{favicon} = "favicon.ico"; + $form = $::form; + $locale = $::locale; + $auth = $::auth; -if ($form->{action}) { + $::auth->store_root_credentials_in_session($form->{rpw}) if $session_result == SL::Auth->SESSION_OK; + $form->{stylesheet} = "lx-office-erp.css"; + $form->{favicon} = "favicon.ico"; - $subroutine = $locale->findsub($form->{action}); + if ($form->{action}) { + if ($auth->authenticate_root($form->{rpw}) != $auth->OK()) { + $form->{error_message} = $locale->text('Incorrect Password!'); + $auth->delete_session_value('rpw'); + adminlogin(); + } else { + if ($auth->session_tables_present()) { + $::auth->store_root_credentials_in_session($::form->{rpw}); + delete $::form->{rpw}; + _apply_dbupgrade_scripts(); + } - 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|Lx-Office ERP $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 { +sub logout { + $main::auth->destroy_session(); + adminlogin(); +} - $form->error($locale->text('File locked!')) if (-f "${memberfile}.LCK"); +sub check_auth_db_and_tables { + my $form = $main::form; + my $locale = $main::locale; - open(FH, "$memberfile") or $form->error("$memberfile : $!"); + my %params; - my %members; + map { $params{"db_${_}"} = $main::auth->{DB_config}->{$_} } keys %{ $auth->{DB_config} }; - while () { - chomp; + 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 (/^\[.*\]/) { - $login = $_; - $login =~ s/(\[|\])//g; + ::end_of_request(); + } - $members{$login} = { "login" => $login }; - } + if (!$main::auth->check_tables()) { + $form->{title} = $locale->text('Authentification tables creation'); + $form->header(); + print $form->parse_html_template('admin/check_auth_tables', \%params); - if (/^([a-z]+)=(.*)/) { - $members{$login}->{$1} = $2; - } + ::end_of_request(); } - close(FH); + my $memberfile = $::lx_office_conf{paths}->{memberfile}; + if (-f $memberfile) { + my $memberdir = ""; - delete $members{"root login"}; - map { $_->{templates} =~ s|.*/||; } values %members; + if ($memberfile =~ m|^.*/|) { + $memberdir = $&; + } - $form->{title} = "Lx-Office ERP " . $locale->text('Administration'); - $form->{LOCKED} = -e "$userspath/nologin"; - $form->{MEMBERS} = [ @members{sort { lc $a cmp lc $b } keys %members} ]; + my $backupdir = "${memberdir}member-file-migration"; - $form->header(); - print $form->parse_html_template("admin/list_users"); -} + $form->{title} = $locale->text('User data migration'); + $form->header(); + print $form->parse_html_template('admin/user_migration', { 'memberfile' => $memberfile, + 'backupdir' => $backupdir }); -sub add_user { + ::end_of_request(); + } +} - $form->{title} = - "Lx-Office ERP " - . $locale->text('Administration') . " / " - . $locale->text('Add User'); +sub create_auth_db { + my $form = $main::form; - $form->{Oracle_sid} = $sid; - $form->{Oracle_dbport} = '1521'; - $form->{Oracle_dbhost} = `hostname`; + $main::auth->create_database('superuser' => $form->{db_superuser}, + 'superuser_password' => $form->{db_superuser_password}, + 'template' => $form->{db_template}); + login(); +} - if (-f "css/lx-office-erp.css") { - $myconfig->{stylesheet} = "lx-office-erp.css"; - } +sub create_auth_tables { + my $form = $main::form; + my $locale = $main::locale; - $myconfig->{vclimit} = 200; - $myconfig->{countrycode} = "de"; - $myconfig->{numberformat} = "1000,00"; - $myconfig->{dateformat} = "dd.mm.yy"; + $main::auth->create_tables(); + $main::auth->set_session_value('rpw', $form->{rpw}); + $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 edit { +sub migrate_users { + $main::lxdebug->enter_sub(); - $form->{title} = - "Lx-Office ERP " - . $locale->text('Administration') . " / " - . $locale->text('Edit User'); - $form->{edit} = 1; + my $form = $main::form; + my $locale = $main::locale; - form_header(); - form_footer(); + my $memberdir = ""; -} + my $memberfile = $::lx_office_conf{paths}->{memberfile}; + if ($memberfile =~ m|^.*/|) { + $memberdir = $&; + } -sub form_footer { + my $backupdir = "${memberdir}member-file-migration"; - if ($form->{edit}) { - $delete = - qq| -|; + if (! -d $backupdir && !mkdir $backupdir, 0700) { + $form->error(sprintf($locale->text('The directory "%s" could not be created:\n%s'), $backupdir, $!)); } - print qq| + copy $memberfile, "users/member-file-migration/members"; - -{rpw}> + my $in = IO::File->new($memberfile, "r"); - -$delete + $form->error($locale->text('Could not open the old memberfile.')) if (!$in); - + my (%members, $login); - - -|; - -} + while (<$in>) { + chomp; -sub form_header { + next if (m/^\s*\#/); - # if there is a login, get user - if ($form->{login}) { + if (m/^\[.*\]/) { + $login = $_; + $login =~ s/(\[|\])//g; + $login =~ s/^\s*//; + $login =~ s/\s*$//; - # get user - $myconfig = new User "$memberfile", "$form->{login}"; + $members{$login} = { "login" => $login }; + next; + } - $myconfig->{signature} =~ s/\\n/\r\n/g; - $myconfig->{address} =~ s/\\n/\r\n/g; + if ($login && m/=/) { + my ($key, $value) = split m/\s*=\s*/, $_, 2; + $key =~ s|^\s*||; + $value =~ s|\s*$||; - # strip basedir from templates directory - $myconfig->{templates} =~ s/^$templates\///; + $value =~ s|\\r||g; + $value =~ s|\\n|\n|g; - # $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; + $members{$login}->{$key} = $value; + } } - 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}) - ? "