X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fadmin.pl;h=daae59a23b0c81a5992f1de721c49c68a09fe849;hb=f373f98d676d433b7db20e3e74435a34029cac0f;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..daae59a23 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -36,20 +36,38 @@ $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(''); $form = new Form; -$form->{"root"} = "root login"; $locale = new Locale $language, "admin"; +our $auth = SL::Auth->new(); +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}") { eval { require "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(); } @@ -102,571 +109,351 @@ password= sub adminlogin { - $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 { + $auth->destroy_session(); + adminlogin(); +} - $form->error($locale->text('File locked!')) if (-f "${memberfile}.LCK"); +sub check_auth_db_and_tables { + my %params; - open(FH, "$memberfile") or $form->error("$memberfile : $!"); + map { $params{"db_${_}"} = $auth->{DB_config}->{$_} } keys %{ $auth->{DB_config} }; - my %members; + if (!$auth->check_database()) { + $form->{title} = $locale->text('Authentification database creation'); + $form->header(); + print $form->parse_html_template('admin/check_auth_database', \%params); - while () { - chomp; + exit 0; + } - if (/^\[.*\]/) { - $login = $_; - $login =~ s/(\[|\])//g; + if (!$auth->check_tables()) { + $form->{title} = $locale->text('Authentification tables creation'); + $form->header(); + print $form->parse_html_template('admin/check_auth_tables', \%params); - $members{$login} = { "login" => $login }; - } + exit 0; + } + + if (-f $memberfile) { + my $memberdir = ""; - if (/^([a-z]+)=(.*)/) { - $members{$login}->{$1} = $2; + if ($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' => $memberfile, + 'backupdir' => $backupdir }); + + exit 0 } +} - close(FH); +sub create_auth_db { + $auth->create_database('superuser' => $form->{db_superuser}, + 'superuser_password' => $form->{db_superuser_password}, + 'template' => $form->{db_template}); + login(); +} - delete $members{"root login"}; - map { $_->{templates} =~ s|.*/||; } values %members; +sub create_auth_tables { + $auth->create_tables(); + $auth->set_session_value('rpw', $form->{rpw}); + $auth->create_or_refresh_session(); - $form->{title} = "Lx-Office ERP " . $locale->text('Administration'); - $form->{LOCKED} = -e "$userspath/nologin"; - $form->{MEMBERS} = [ @members{sort { lc $a cmp lc $b } keys %members} ]; + if (!-f $memberfile) { + # New installation -- create a standard group with full access + 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 ], + }; + + $auth->save_group($group); + } - $form->header(); - print $form->parse_html_template("admin/list_users"); + login(); } -sub add_user { +sub migrate_users { + $lxdebug->enter_sub(); - $form->{title} = - "Lx-Office ERP " - . $locale->text('Administration') . " / " - . $locale->text('Add User'); + my $memberdir = ""; + + if ($memberfile =~ m|^.*/|) { + $memberdir = $&; + } - $form->{Oracle_sid} = $sid; - $form->{Oracle_dbport} = '1521'; - $form->{Oracle_dbhost} = `hostname`; + my $backupdir = "${memberdir}member-file-migration"; - if (-f "css/lx-office-erp.css") { - $myconfig->{stylesheet} = "lx-office-erp.css"; + if (! -d $backupdir && !mkdir $backupdir, 0700) { + $form->error(sprintf($locale->text('The directory "%s" could not be created:\n%s'), $backupdir, $!)); } - $myconfig->{vclimit} = 200; - $myconfig->{countrycode} = "de"; - $myconfig->{numberformat} = "1000,00"; - $myconfig->{dateformat} = "dd.mm.yy"; + copy $memberfile, "users/member-file-migration/members"; - &form_header; - &form_footer; + my $in = IO::File->new($memberfile, "r"); -} + $form->error($locale->text('Could not open the old memberfile.')) if (!$in); -sub edit { + my (%members, $login); - $form->{title} = - "Lx-Office ERP " - . $locale->text('Administration') . " / " - . $locale->text('Edit User'); - $form->{edit} = 1; + while (<$in>) { + chomp; - &form_header; - &form_footer; + next if (m/^\s*\#/); -} + if (m/^\[.*\]/) { + $login = $_; + $login =~ s/(\[|\])//g; + $login =~ s/^\s*//; + $login =~ s/\s*$//; -sub form_footer { + $members{$login} = { "login" => $login }; + next; + } - if ($form->{edit}) { - $delete = - qq| -|; + 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(); - -{rpw}> + delete $members{"root login"}; - -$delete + map { $_->{dbpasswd} = unpack 'u', $_->{dbpasswd} } values %members; - + while (my ($login, $params) = each %members) { + $auth->save_user($login, %{ $params }); + $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; + } + } -sub form_header { + unlink $memberfile; - # if there is a login, get user - if ($form->{login}) { + my @member_list = sort { lc $a->{login} cmp lc $b->{login} } values %members; - # get user - $myconfig = new User "$memberfile", "$form->{login}"; + $form->{title} = $locale->text('User data migration'); + $form->header(); + print $form->parse_html_template('admin/user_migration_done', { 'MEMBERS' => \@member_list }); - $myconfig->{signature} =~ s/\\n/\r\n/g; - $myconfig->{address} =~ s/\\n/\r\n/g; + $lxdebug->leave_sub(); +} - # strip basedir from templates directory - $myconfig->{templates} =~ s/^$templates\///; +sub create_standard_group_ask { + $form->{title} = $locale->text('Create a standard group'); - # $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - } + $form->header(); + print $form->parse_html_template("admin/create_standard_group_ask"); +} - 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}) - ? "