X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fadmin.pl;h=c704174c8f66ec2fac026e3e217c8f708b91c369;hb=6881b4bd6a669dd991b227ecf41c3e8662806595;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..c704174c8 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -32,1609 +32,1190 @@ # #====================================================================== -$menufile = "menu.ini"; - +use DBI; +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 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(); + } + 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); -$form = new Form; + adminlogin(); + } + $::lxdebug->leave_sub; +} -$locale = new Locale $language, "admin"; - -eval { require DBI; }; -$form->error($locale->text('DBI not installed!')) if ($@); +sub adminlogin { + my $form = $main::form; + my $locale = $main::locale; + $form->{title} = qq|kivitendo $form->{version} | . $locale->text('Administration'); -# customization -if (-f "$form->{path}/custom_$form->{script}") { - eval { require "$form->{path}/custom_$form->{script}"; }; - $form->error($@) if ($@); + $form->header(); + print $form->parse_html_template('admin/adminlogin'); } +sub login { + check_auth_db_and_tables(); + list_users(); +} -$form->{stylesheet} = "lx-office-erp.css"; -$form->{favicon} = "favicon.ico"; +sub logout { + $main::auth->destroy_session(); + adminlogin(); +} -if ($form->{action}) { +sub check_auth_db_and_tables { + my $form = $main::form; + my $locale = $main::locale; - $subroutine = $locale->findsub($form->{action}); - - if ($subroutine eq 'login') { - if ($form->{rpw}) { - $form->{rpw} = crypt $form->{rpw}, "ro"; - } - } - - &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; - } + my %params; - &adminlogin; + map { $params{"db_${_}"} = $main::auth->{DB_config}->{$_} } keys %{ $auth->{DB_config} }; -} + $params{admin_password} = $::lx_office_conf{authentication}->{admin_password}; -1; -# end + 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(); + } -sub adminlogin { + 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} = qq|Lx-Office ERP $form->{version} |.$locale->text('Administration'); + ::end_of_request(); + } - $form->header; - - print qq| - + my $memberfile = $::lx_office_conf{paths}->{memberfile}; + if (-f $memberfile) { + my $memberdir = ""; + if ($memberfile =~ m|^.*/|) { + $memberdir = $&; + } -
+ my $backupdir = "${memberdir}member-file-migration"; - -

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

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

+ $form->{title} = $locale->text('User data migration'); + $form->header(); + print $form->parse_html_template('admin/user_migration', { 'memberfile' => $memberfile, + 'backupdir' => $backupdir }); -
+ ::end_of_request(); + } +} - - - - - - - - -{path}> -
|.$locale->text('Password').qq|
+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('admin_password', $form->{'{AUTH}admin_password'}); + $main::auth->create_or_refresh_session(); + + 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); + } -Lx-Office |.$locale->text('website').qq| + _apply_dbupgrade_scripts(); + login(); +} -
+sub migrate_users { + $main::lxdebug->enter_sub(); - - -|; + my $form = $main::form; + my $locale = $main::locale; -} + my $memberdir = ""; + my $memberfile = $::lx_office_conf{paths}->{memberfile}; + if ($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 login { + copy $memberfile, "users/member-file-migration/members"; - &list_users; + my $in = IO::File->new($memberfile, "r"); -} + $form->error($locale->text('Could not open the old memberfile.')) if (!$in); + my (%members, $login); + while (<$in>) { + chomp; -sub add_user { - - $form->{title} = "Lx-Office ERP ".$locale->text('Administration')." / ".$locale->text('Add User'); + next if (m/^\s*\#/); - $form->{Oracle_sid} = $sid; - $form->{Oracle_dbport} = '1521'; - $form->{Oracle_dbhost} = `hostname`; + if (m/^\[.*\]/) { + $login = $_; + $login =~ s/(\[|\])//g; + $login =~ s/^\s*//; + $login =~ s/\s*$//; - if (-f "css/lx-office-erp.css") { - $myconfig->{stylesheet} = "lx-office-erp.css"; - } - $myconfig->{vclimit} = 200; - - &form_header; - &form_footer; - -} + $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; -sub edit { + $members{$login}->{$key} = $value; + } + } - $form->{title} = "Lx-Office ERP ".$locale->text('Administration')." / ".$locale->text('Edit User'); - $form->{edit} = 1; + $in->close(); - &form_header; - &form_footer; + delete $members{"root login"}; -} + 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); -sub form_footer { + my $conf_file = "${memberdir}${login}.conf"; - if ($form->{edit}) { - $delete = qq| -|; + if (-f $conf_file) { + copy $conf_file, "${backupdir}/${login}.conf"; + unlink $conf_file; + } } - print qq| - - - -{path}> -{rpw}> - - -$delete + unlink $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 create_standard_group_ask { + my $form = $main::form; + my $locale = $main::locale; -sub list_users { + $form->{title} = $locale->text('Create a standard group'); - $form->error($locale->text('File locked!')) if (-f "${memberfile}.LCK"); + $form->header(); + print $form->parse_html_template("admin/create_standard_group_ask"); +} - open(FH, "$memberfile") or $form->error("$memberfile : $!"); +sub create_standard_group { + my $form = $main::form; + my $locale = $main::locale; - $nologin = qq| -|; + my %members = $main::auth->read_all_users(); - if (-e "$userspath/nologin") { - $nologin = qq| -|; - } + my $groups = $main::auth->read_groups(); - - while () { - chop; - - if (/^\[.*\]/) { - $login = $_; - $login =~ s/(\[|\])//g; - } - - if (/^(name=|company=|templates=|dbuser=|dbdriver=|dbname=|dbhost=)/) { - chop ($var = $&); - ($null, $member{$login}{$var}) = split /=/, $_, 2; + 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); - - $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| - |; + user_migration_complete(1); } - -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|
-
- -
- -
- - - -|; - +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; -sub form_header { - - # if there is a login, get user - if ($form->{login}) { - # get user - $myconfig = new User "$memberfile", "$form->{login}"; + $form->{title} = $locale->text('User migration complete'); + $form->header(); - $myconfig->{signature} =~ s/\\n/\r\n/g; - $myconfig->{address} =~ s/\\n/\r\n/g; + print $form->parse_html_template('admin/user_migration_complete', { 'standard_group_created' => $standard_group_created }); +} - # strip basedir from templates directory - $myconfig->{templates} =~ s/^$templates\///; +sub list_users { + my $form = $main::form; + my $locale = $main::locale; - # $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - } + my %members = $main::auth->read_all_users(); + delete $members{"root login"}; - 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}) ? "