X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fadmin.pl;h=3258a317c268bf0236bd7e67601ed87834a37045;hb=c9902d7658d0cacdf665971b32de0e054637efd0;hp=9856c29550de158ee6ae7626107498ea81e35101;hpb=4dbb09950c9f5596646537c12d991c99086fe7c1;p=kivitendo-erp.git diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl old mode 100644 new mode 100755 index 9856c2955..3258a317c --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -32,840 +32,480 @@ # #====================================================================== -$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::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"; -$form = new Form; +use strict; -$locale = new Locale $language, "admin"; - -eval { require DBI; }; -$form->error($locale->text('DBI not installed!')) if ($@); +our $cgi; +our $form; +our $locale; +our $auth; +sub run { + $::lxdebug->enter_sub; + my $session_result = shift; -# customization -if (-f "$form->{path}/custom_$form->{script}") { - eval { require "$form->{path}/custom_$form->{script}"; }; - $form->error($@) if ($@); -} + $cgi = $::cgi; + $form = $::form; + $locale = $::locale; + $auth = $::auth; + $::auth->set_session_value('rpw', $::form->{rpw}) if $session_result == SL::Auth->SESSION_OK; -$form->{stylesheet} = "lx-office-erp.css"; -$form->{favicon} = "favicon.ico"; + $form->{stylesheet} = "lx-office-erp.css"; + $form->{favicon} = "favicon.ico"; -if ($form->{action}) { + if ($form->{action}) { + if ($auth->authenticate_root($form->{rpw}, 0) != $auth->OK()) { + $form->{error_message} = $locale->text('Incorrect Password!'); + adminlogin(); + } else { + if ($auth->session_tables_present()) { + $::auth->set_session_value('rpw', $::form->{rpw}); + $::auth->create_or_refresh_session(); + _apply_dbupgrade_scripts(); + } - $subroutine = $locale->findsub($form->{action}); - - if ($subroutine eq 'login') { - if ($form->{rpw}) { - $form->{rpw} = crypt $form->{rpw}, "ro"; + call_sub($locale->findsub($form->{action})); } + } else { + # if there are no drivers bail out + $form->error($locale->text('No Database Drivers available!')) + unless (User->dbdrivers); + + adminlogin(); } - - &check_password; - - &$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= - -|; - close FH; - } + $::lxdebug->leave_sub; +} + +sub adminlogin { + my $form = $main::form; + my $locale = $main::locale; - &adminlogin; + $form->{title} = qq|Lx-Office ERP $form->{version} | . $locale->text('Administration'); + $form->header(); + print $form->parse_html_template('admin/adminlogin'); } -1; -# end +sub login { + check_auth_db_and_tables(); + list_users(); +} +sub logout { + $main::auth->destroy_session(); + adminlogin(); +} -sub adminlogin { +sub check_auth_db_and_tables { + my $form = $main::form; + my $locale = $main::locale; - $form->{title} = qq|Lx-Office ERP $form->{version} |.$locale->text('Administration'); + my %params; - $form->header; - - print qq| - + map { $params{"db_${_}"} = $main::auth->{DB_config}->{$_} } keys %{ $auth->{DB_config} }; + if (!$main::auth->check_database()) { + $form->{title} = $locale->text('Authentification database creation'); + $form->header(); + print $form->parse_html_template('admin/check_auth_database', \%params); -
+ ::end_of_request(); + } - -

|.$locale->text('Version').qq| $form->{version}

|.$locale->text('Administration').qq|

+ if (!$main::auth->check_tables()) { + $form->{title} = $locale->text('Authentification tables creation'); + $form->header(); + print $form->parse_html_template('admin/check_auth_tables', \%params); -
+ ::end_of_request(); + } - - - - - - - - -{path}> -
|.$locale->text('Password').qq|
+ if (-f $main::memberfile) { + my $memberdir = ""; + if ($main::memberfile =~ m|^.*/|) { + $memberdir = $&; + } -
+ my $backupdir = "${memberdir}member-file-migration"; -Lx-Office |.$locale->text('website').qq| + $form->{title} = $locale->text('User data migration'); + $form->header(); + print $form->parse_html_template('admin/user_migration', { 'memberfile' => $main::memberfile, + 'backupdir' => $backupdir }); -
+ ::end_of_request(); + } +} - - -|; +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 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); + } + login(); +} +sub migrate_users { + $main::lxdebug->enter_sub(); -sub login { + my $form = $main::form; + my $locale = $main::locale; - &list_users; + my $memberdir = ""; -} + if ($main::memberfile =~ m|^.*/|) { + $memberdir = $&; + } + 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, $!)); + } -sub add_user { - - $form->{title} = "Lx-Office ERP ".$locale->text('Administration')." / ".$locale->text('Add User'); + copy $main::memberfile, "users/member-file-migration/members"; - $form->{Oracle_sid} = $sid; - $form->{Oracle_dbport} = '1521'; - $form->{Oracle_dbhost} = `hostname`; + my $in = IO::File->new($main::memberfile, "r"); - if (-f "css/lx-office-erp.css") { - $myconfig->{stylesheet} = "lx-office-erp.css"; - } - $myconfig->{vclimit} = 200; - - &form_header; - &form_footer; - -} + $form->error($locale->text('Could not open the old memberfile.')) if (!$in); + my (%members, $login); + while (<$in>) { + chomp; -sub edit { - - $form->{title} = "Lx-Office ERP ".$locale->text('Administration')." / ".$locale->text('Edit User'); - $form->{edit} = 1; + next if (m/^\s*\#/); - &form_header; - &form_footer; + 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*$||; -sub form_footer { + $value =~ s|\\r||g; + $value =~ s|\\n|\n|g; - if ($form->{edit}) { - $delete = qq| -|; + $members{$login}->{$key} = $value; + } } - print qq| + $in->close(); - - -{path}> -{rpw}> + delete $members{"root login"}; - -$delete + map { $_->{dbpasswd} = unpack 'u', $_->{dbpasswd} } values %members; - + 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; -sub list_users { + my @member_list = sort { lc $a->{login} cmp lc $b->{login} } values %members; - $form->error($locale->text('File locked!')) if (-f "${memberfile}.LCK"); + $form->{title} = $locale->text('User data migration'); + $form->header(); + print $form->parse_html_template('admin/user_migration_done', { 'MEMBERS' => \@member_list }); - open(FH, "$memberfile") or $form->error("$memberfile : $!"); + $main::lxdebug->leave_sub(); +} - $nologin = qq| -|; +sub create_standard_group_ask { + my $form = $main::form; + my $locale = $main::locale; - if (-e "$userspath/nologin") { - $nologin = qq| -|; - } + $form->{title} = $locale->text('Create a standard group'); + $form->header(); + print $form->parse_html_template("admin/create_standard_group_ask"); +} - while () { - chop; - - if (/^\[.*\]/) { - $login = $_; - $login =~ s/(\[|\])//g; - } +sub create_standard_group { + my $form = $main::form; + my $locale = $main::locale; + + my %members = $main::auth->read_all_users(); - if (/^(name=|company=|templates=|dbuser=|dbdriver=|dbname=|dbhost=)/) { - chop ($var = $&); - ($null, $member{$login}{$var}) = split /=/, $_, 2; + my $groups = $main::auth->read_groups(); + + foreach my $group (values %{$groups}) { + if (($form->{group_id} != $group->{id}) + && ($form->{name} eq $group->{name})) { + $form->show_generic_error($locale->text("A group with that name does already exist.")); } } - - close(FH); -# type=submit $locale->text('Pg Database Administration') -# type=submit $locale->text('Oracle Database Administration') + 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 ], + }; - foreach $item (User->dbdrivers) { - $dbdrivers .= qq||; - } + $main::auth->save_group($group); + user_migration_complete(1); +} - $column_header{login} = qq||.$locale->text('Login').qq||; - $column_header{name} = qq||.$locale->text('Name').qq||; - $column_header{company} = qq||.$locale->text('Company').qq||; - $column_header{dbdriver} = qq||.$locale->text('Driver').qq||; - $column_header{dbhost} = qq||.$locale->text('Host').qq||; - $column_header{dataset} = qq||.$locale->text('Dataset').qq||; - $column_header{templates} = qq||.$locale->text('Templates').qq||; - - @column_index = qw(login name company dbdriver dbhost dataset templates); - - $form->{title} = "Lx-Office ERP ".$locale->text('Administration'); - - $form->header; - - print qq| - - -
{script}> - - - - - - - - - - - - - -
$form->{title}
- - |; - - map { print "$column_header{$_}\n" } @column_index; - - print qq| - -|; - -foreach $key (sort keys %member) { - $href = "$script?action=edit&login=$key&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}"; - $href =~ s/ /%20/g; - - $member{$key}{templates} =~ s/^$templates\///; - $member{$key}{dbhost} = $locale->text('localhost') unless $member{$key}{dbhost}; - $member{$key}{dbname} = $member{$key}{dbuser} if ($member{$key}{dbdriver} eq 'Oracle'); - - $column_data{login} = qq||; - $column_data{name} = qq||; - $column_data{company} = qq||; - $column_data{dbdriver} = qq||; - $column_data{dbhost} = qq||; - $column_data{dataset} = qq||; - $column_data{templates} = qq||; - - $i++; $i %= 2; - print qq| - |; - - map { print "$column_data{$_}\n" } @column_index; - - print qq| - |; +sub dont_create_standard_group { + user_migration_complete(0); } +sub user_migration_complete { + my $standard_group_created = shift; + + my $form = $main::form; + my $locale = $main::locale; -print qq| -
$key$member{$key}{name}$member{$key}{company}$member{$key}{dbdriver}$member{$key}{dbhost}$member{$key}{dbname}$member{$key}{templates}
-

- -{path}> -{rpw}> - - -
- - -$dbdrivers -$nologin - -
- -|.$locale->text('Click on login name to edit!').qq| -
-|.$locale->text('To add a user to a group edit a name, change the login name and save. A new user with the same variables will then be saved under the new login name.').qq| - -

- -

- - - - - - - - -
Lx-Office ERP |.$locale->text('Login').qq|
- - - - - - - - - - - -{path}> -
|.$locale->text('Name').qq| 
|.$locale->text('Password').qq|
-
- -
- -
- - - -|; + $form->{title} = $locale->text('User migration complete'); + $form->header(); + print $form->parse_html_template('admin/user_migration_complete', { 'standard_group_created' => $standard_group_created }); } +sub list_users { + my $form = $main::form; + my $locale = $main::locale; + my %members = $main::auth->read_all_users(); -sub form_header { + delete $members{"root login"}; - # if there is a login, get user - if ($form->{login}) { - # get user - $myconfig = new User "$memberfile", "$form->{login}"; + map { $_->{templates} =~ s|.*/||; } values %members; - $myconfig->{signature} =~ s/\\n/\r\n/g; - $myconfig->{address} =~ s/\\n/\r\n/g; + $form->{title} = "Lx-Office ERP " . $locale->text('Administration'); + $form->{LOCKED} = -e "$main::userspath/nologin"; + $form->{MEMBERS} = [ @members{sort { lc $a cmp lc $b } keys %members} ]; - # strip basedir from templates directory - $myconfig->{templates} =~ s/^$templates\///; + $form->header(); + print $form->parse_html_template("admin/list_users"); +} - # $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - } +sub add_user { + my $form = $main::form; + my $locale = $main::locale; + + $form->{title} = "Lx-Office ERP " . $locale->text('Administration') . " / " . $locale->text('Add User'); + +# Note: Menu Style 'v3' is not compatible to all browsers! +# "menustyle" => "old" sets the HTML Menu to default. + my $myconfig = { + "vclimit" => 200, + "countrycode" => "de", + "numberformat" => "1.000,00", + "dateformat" => "dd.mm.yy", + "stylesheet" => "lx-office-erp.css", + "menustyle" => "old", + }; + + edit_user_form($myconfig); +} +sub edit_user { + my $form = $main::form; + my $locale = $main::locale; - 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}) ? "