X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fadmin.pl;h=a08891a8f825897c05366bb65d8aeee57f8cc2fb;hb=fe73e0d261229f181e8133283b530509773d2151;hp=e478d6ba1f68e86c657c61b9711272ef8b7856c2;hpb=2d6988532a665bd7e42bb88a38a8b52cbb352646;p=kivitendo-erp.git diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl old mode 100644 new mode 100755 index e478d6ba1..a08891a8f --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -32,23 +32,41 @@ # #====================================================================== -$menufile = "menu.ini"; +my $menufile = "menu.ini"; use DBI; use CGI; - +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::Form; +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"; -our $cgi = new CGI(''); +use strict; -$form = new Form; -$form->{"root"} = "root login"; +our $cgi = new CGI(''); +our $form = new Form; +our $locale = new Locale $main::language, "admin"; +our $auth = SL::Auth->new(); -$locale = new Locale $language, "admin"; +if ($auth->session_tables_present()) { + $auth->expire_sessions(); + $auth->restore_session(); + $auth->set_session_value('rpw', $form->{rpw}); +} # customization if (-f "bin/mozilla/custom_$form->{script}") { @@ -60,39 +78,28 @@ $form->{stylesheet} = "lx-office-erp.css"; $form->{favicon} = "favicon.ico"; if ($form->{action}) { + if ($auth->authenticate_root($form->{rpw}, 0) != $auth->OK()) { + $form->{error_message} = $locale->text('Incorrect Password!'); + adminlogin(); + exit; + } + $auth->create_or_refresh_session() if ($auth->session_tables_present()); - $subroutine = $locale->findsub($form->{action}); + call_sub($locale->findsub($form->{action})); - if ($subroutine eq 'login') { - if ($form->{rpw}) { - $form->{rpw} = crypt $form->{rpw}, "ro"; - } - } +} elsif ($auth->authenticate_root($form->{rpw}, 0) == $auth->OK()) { - &check_password; + $auth->create_or_refresh_session() if ($auth->session_tables_present()); - call_sub($subroutine); + login(); } 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= - -|; - close FH; - } - - &adminlogin; + adminlogin(); } @@ -101,572 +108,390 @@ password= # 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; + exit 0; + } - $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; + exit 0; + } + + if (-f $main::memberfile) { + my $memberdir = ""; + + if ($main::memberfile =~ m|^.*/|) { + $memberdir = $&; } + + my $backupdir = "${memberdir}member-file-migration"; + + $form->{title} = $locale->text('User data migration'); + $form->header(); + print $form->parse_html_template('admin/user_migration', { 'memberfile' => $main::memberfile, + 'backupdir' => $backupdir }); + + exit 0 } +} - close(FH); +sub create_auth_db { + my $form = $main::form; - delete $members{"root login"}; - map { $_->{templates} =~ s|.*/||; } values %members; + $main::auth->create_database('superuser' => $form->{db_superuser}, + 'superuser_password' => $form->{db_superuser_password}, + 'template' => $form->{db_template}); + login(); +} - $form->{title} = "Lx-Office ERP " . $locale->text('Administration'); - $form->{LOCKED} = -e "$userspath/nologin"; - $form->{MEMBERS} = [ @members{sort { lc $a cmp lc $b } keys %members} ]; +sub create_auth_tables { + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->create_tables(); + $main::auth->set_session_value('rpw', $form->{rpw}); + $main::auth->create_or_refresh_session(); + + if (!-f $main::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); + } - $form->header(); - print $form->parse_html_template("admin/list_users"); + login(); } -sub add_user { +sub migrate_users { + $main::lxdebug->enter_sub(); - $form->{title} = - "Lx-Office ERP " - . $locale->text('Administration') . " / " - . $locale->text('Add User'); + my $form = $main::form; + my $locale = $main::locale; - $form->{Oracle_sid} = $sid; - $form->{Oracle_dbport} = '1521'; - $form->{Oracle_dbhost} = `hostname`; + my $memberdir = ""; - if (-f "css/lx-office-erp.css") { - $myconfig->{stylesheet} = "lx-office-erp.css"; + if ($main::memberfile =~ m|^.*/|) { + $memberdir = $&; } - $myconfig->{vclimit} = 200; - $myconfig->{countrycode} = "de"; - $myconfig->{numberformat} = "1000,00"; - $myconfig->{dateformat} = "dd.mm.yy"; + my $backupdir = "${memberdir}member-file-migration"; - &form_header; - &form_footer; + if (! -d $backupdir && !mkdir $backupdir, 0700) { + $form->error(sprintf($locale->text('The directory "%s" could not be created:\n%s'), $backupdir, $!)); + } -} + copy $main::memberfile, "users/member-file-migration/members"; -sub edit { + my $in = IO::File->new($main::memberfile, "r"); - $form->{title} = - "Lx-Office ERP " - . $locale->text('Administration') . " / " - . $locale->text('Edit User'); - $form->{edit} = 1; + $form->error($locale->text('Could not open the old memberfile.')) if (!$in); - &form_header; - &form_footer; + my (%members, $login); -} + while (<$in>) { + chomp; -sub form_footer { + next if (m/^\s*\#/); - if ($form->{edit}) { - $delete = - qq| -|; + if (m/^\[.*\]/) { + $login = $_; + $login =~ s/(\[|\])//g; + $login =~ s/^\s*//; + $login =~ s/\s*$//; + + $members{$login} = { "login" => $login }; + next; + } + + if ($login && m/=/) { + my ($key, $value) = split m/\s*=\s*/, $_, 2; + $key =~ s|^\s*||; + $value =~ s|\s*$||; + + $value =~ s|\\r||g; + $value =~ s|\\n|\n|g; + + $members{$login}->{$key} = $value; + } } - print qq| + $in->close(); + + delete $members{"root login"}; - -{rpw}> + map { $_->{dbpasswd} = unpack 'u', $_->{dbpasswd} } values %members; - -$delete + while (my ($login, $params) = each %members) { + $main::auth->save_user($login, %{ $params }); + $main::auth->change_password($login, $params->{password}, 1); - + my $conf_file = "${memberdir}${login}.conf"; + + if (-f $conf_file) { + copy $conf_file, "${backupdir}/${login}.conf"; + unlink $conf_file; + } + } - - -|; + unlink $main::memberfile; + my @member_list = sort { lc $a->{login} cmp lc $b->{login} } values %members; + + $form->{title} = $locale->text('User data migration'); + $form->header(); + print $form->parse_html_template('admin/user_migration_done', { 'MEMBERS' => \@member_list }); + + $main::lxdebug->leave_sub(); } -sub form_header { +sub create_standard_group_ask { + my $form = $main::form; + my $locale = $main::locale; - # if there is a login, get user - if ($form->{login}) { + $form->{title} = $locale->text('Create a standard group'); - # get user - $myconfig = new User "$memberfile", "$form->{login}"; + $form->header(); + print $form->parse_html_template("admin/create_standard_group_ask"); +} - $myconfig->{signature} =~ s/\\n/\r\n/g; - $myconfig->{address} =~ s/\\n/\r\n/g; +sub create_standard_group { + my $form = $main::form; + my $locale = $main::locale; - # strip basedir from templates directory - $myconfig->{templates} =~ s/^$templates\///; + my %members = $main::auth->read_all_users(); - # $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - } + my $groups = $main::auth->read_groups(); - 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}) - ? "