X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fadmin.pl;h=5f3e0b19d8f2e95406aa48c8c58a48ba1e65a30a;hb=16455a4f7a2e871d645485ffb5904d197b907217;hp=3fba37cc8ccbdb757f37399eeeeb17481c743080;hpb=82c41aacb54996848276f5cb00c6587bf20f03a7;p=kivitendo-erp.git diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl old mode 100644 new mode 100755 index 3fba37cc8..5f3e0b19d --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -32,573 +32,130 @@ # #====================================================================== -$menufile = "menu.ini"; - use DBI; -use CGI; -use POSIX qw(strftime); -use IO::File; -use Fcntl; +use Encode; use English qw(-no_match_vars); +use Fcntl; +use File::Copy; +use File::Find; +use File::Spec; +use Cwd; +use IO::Dir; +use IO::File; +use POSIX qw(strftime); use Sys::Hostname; +use SL::Auth; +use SL::Auth::PasswordPolicy; +use SL::DB::AuthClient; +use SL::DB::AuthUser; use SL::Form; +use SL::Iconv; use SL::Mailer; use SL::User; use SL::Common; use SL::Inifile; use SL::DBUpgrade2; use SL::DBUtils; +use SL::Template; require "bin/mozilla/common.pl"; -our $cgi = new CGI(''); - -$form = new Form; -$form->{"root"} = "root login"; - -$locale = new Locale $language, "admin"; - -# customization -if (-f "bin/mozilla/custom_$form->{script}") { - eval { require "bin/mozilla/custom_$form->{script}"; }; - $form->error($@) if ($@); -} - -$form->{stylesheet} = "lx-office-erp.css"; -$form->{favicon} = "favicon.ico"; - -if ($form->{action}) { - - - $subroutine = $locale->findsub($form->{action}); - - if ($subroutine eq 'login') { - if ($form->{rpw}) { - $form->{rpw} = crypt $form->{rpw}, "ro"; - } - } - - 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 : $ERRNO"); - print FH qq|# SQL-Ledger Accounting members - -[root login] -password= - -|; - close FH; - } - - adminlogin(); - -} - -1; - -# end - -sub adminlogin { - - $form->{title} = - qq|Lx-Office ERP $form->{version} | . $locale->text('Administration'); - - $form->header(); - print $form->parse_html_template2('admin/adminlogin'); -} - -sub login { - list_users(); -} - -sub list_users { - - $form->error($locale->text('File locked!')) if (-f "${memberfile}.LCK"); - - open(FH, "$memberfile") or $form->error("$memberfile : $ERRNO"); - - my %members; - - while () { - chomp; - - if (/^\[.*\]/) { - $login = $_; - $login =~ s/(\[|\])//g; - - $members{$login} = { "login" => $login }; - } - - if (/^([a-z]+)=(.*)/) { - $members{$login}->{$1} = $2; - } - } - - close(FH); - - delete $members{"root login"}; - map { $_->{templates} =~ s|.*/||; } values %members; - - $form->{title} = "Lx-Office ERP " . $locale->text('Administration'); - $form->{LOCKED} = -e "$userspath/nologin"; - $form->{MEMBERS} = [ @members{sort { lc $a cmp lc $b } keys %members} ]; +use strict; - $form->header(); - print $form->parse_html_template2("admin/list_users"); -} - -sub add_user { - - $form->{title} = - "Lx-Office ERP " - . $locale->text('Administration') . " / " - . $locale->text('Add User'); - - my $myconfig = { - "vclimit" => 200, - "countrycode" => "de", - "numberformat" => "1.000,00", - "dateformat" => "dd.mm.yy", - "stylesheet" => "lx-office-erp.css", - "menustyle" => "v3", - }; - - edit_user_form($myconfig); -} - -sub edit { - - $form->{title} = - "Lx-Office ERP " - . $locale->text('Administration') . " / " - . $locale->text('Edit User'); - $form->{edit} = 1; - - $form->isblank("login", $locale->text("The login is missing.")); - - # get user - my $myconfig = new User "$memberfile", "$form->{login}"; - - $myconfig->{signature} =~ s/\\n/\r\n/g; - $myconfig->{address} =~ s/\\n/\r\n/g; - - # strip basedir from templates directory - $myconfig->{templates} =~ s|.*/||; - - edit_user_form($myconfig); -} - -sub edit_user_form { - my ($myconfig) = @_; - - my @valid_dateformats = qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd); - $form->{ALL_DATEFORMATS} = [ map { { "format" => $_, "selected" => $_ eq $myconfig->{dateformat} } } @valid_dateformats ]; - - my @valid_numberformats = qw(1,000.00 1000.00 1.000,00 1000,00); - $form->{ALL_NUMBERFORMATS} = [ map { { "format" => $_, "selected" => $_ eq $myconfig->{numberformat} } } @valid_numberformats ]; - - %countrycodes = User->country_codes; - $form->{ALL_COUNTRYCODES} = []; - foreach $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) { - push @{ $form->{ALL_COUNTRYCODES} }, { "value" => $countrycode, - "name" => $countrycodes{$countrycode}, - "selected" => $countrycode eq $myconfig->{countrycode} }; - } - - # is there a templates basedir - if (!-d "$templates") { - $form->error(sprintf($locale->text("The directory %s does not exist."), $templates)); - } - - opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $ERRNO"); - my @all = readdir(TEMPLATEDIR); - my @alldir = sort grep { -d "$templates/$_" && !/^\.\.?$/ } @all; - my @allhtml = sort grep { -f "$templates/$_" && /\.html$/ } @all; - closedir TEMPLATEDIR; - - @alldir = grep !/\.(html|tex|sty|odt|xml|txb)$/, @alldir; - @alldir = grep !/^(webpages|\.svn)$/, @alldir; - - @allhtml = reverse grep !/Default/, @allhtml; - push @allhtml, 'Default'; - @allhtml = reverse @allhtml; - - $form->{ALL_TEMPLATES} = [ map { { "name", => $_, "selected" => $_ eq $myconfig->{templates} } } @alldir ]; - - $lastitem = $allhtml[0]; - $lastitem =~ s/-.*//g; - $form->{ALL_MASTER_TEMPLATES} = [ { "name" => $lastitem, "selected" => $lastitem eq "German" } ]; - foreach $item (@allhtml) { - $item =~ s/-.*//g; - next if ($item eq $lastitem); +# parserhappy(R): - push @{ $form->{ALL_MASTER_TEMPLATES} }, { "name" => $item, "selected" => $item eq "German" }; - $lastitem = $item; - } - - # css dir has styles that are not intended as general layouts. - # reverting to hardcoded list - $form->{ALL_STYLESHEETS} = [ map { { "name" => $_, "selected" => $_ eq $myconfig->{stylesheet} } } qw(lx-office-erp.css Win2000.css) ]; - - $form->{"menustyle_" . $myconfig->{menustyle} } = 1; - - map { $form->{"myc_${_}"} = $myconfig->{$_} } keys %{ $myconfig }; +# $locale->text('periodic') +# $locale->text('income') +# $locale->text('perpetual') +# $locale->text('balance') - # access control - my @acsorder = (); - my %acs = (); - my %excl = (); - open(FH, $menufile) or $form->error("$menufile : $ERRNO"); +our $cgi; +our $form; +our $locale; +our $auth; - while ($item = ) { - next unless $item =~ /\[/; - next if $item =~ /\#/; +sub run { + $::lxdebug->enter_sub; + my $session_result = shift; - $item =~ s/(\[|\])//g; - chomp $item; + $form = $::form; + $locale = $::locale; + $auth = $::auth; - my ($level, $menuitem); + $::request->{layout} = SL::Layout::Dispatcher->new(style => 'admin'); + $::request->{layout}->use_stylesheet("lx-office-erp.css"); + $form->{favicon} = "favicon.ico"; - if ($item =~ /--/) { - ($level, $menuitem) = split /--/, $item, 2; + if ($form->{action}) { + if ($auth->authenticate_root($form->{'{AUTH}admin_password'}) != $auth->OK()) { + $auth->punish_wrong_login; + $form->{error} = $locale->text('Incorrect password!'); + $auth->delete_session_value('admin_password'); + adminlogin(); } else { - $level = $item; - $menuitem = $item; - push @acsorder, $item; - } - - $acs{$level} ||= []; - push @{ $acs{$level} }, $menuitem; - - } - - foreach $item (split(/;/, $myconfig->{acs})) { - ($key, $value) = split /--/, $item, 2; - $excl{$key}{$value} = 1; - } - - $form->{ACLS} = []; - $form->{all_acs} = ""; - - foreach $key (@acsorder) { - my $acl = { "checked" => $form->{login} ? !$excl{$key}->{$key} : 1, - "name" => "${key}--${key}", - "title" => $key, - "SUBACLS" => [], }; - $form->{all_acs} .= "${key}--${key};"; - - foreach $item (@{ $acs{$key} }) { - next if ($key eq $item); - - my $subacl = { "checked" => $form->{login} ? !$excl{$key}->{$item} : 1, - "name" => "${key}--${item}", - "title" => $item }; - push @{ $acl->{SUBACLS} }, $subacl; - $form->{all_acs} .= "${key}--${item};"; - } - push @{ $form->{ACLS} }, $acl; - } - - chop $form->{all_acs}; - - $form->header(); - print $form->parse_html_template2("admin/edit_user"); -} - -sub save { - - $form->{dbdriver} = 'Pg'; - - # no spaces allowed in login name - ($form->{login}) = split / /, $form->{login}; - - $form->isblank("login", $locale->text('Login name missing!')); - - # check for duplicates - if (!$form->{edit}) { - $temp = new User "$memberfile", "$form->{login}"; - - if ($temp->{login}) { - $form->error("$form->{login} " . $locale->text('is already a member!')); - } - } - - # no spaces allowed in directories - ($form->{newtemplates}) = split / /, $form->{newtemplates}; - - if ($form->{newtemplates}) { - $form->{templates} = $form->{newtemplates}; - } else { - $form->{templates} = - ($form->{usetemplates}) ? $form->{usetemplates} : $form->{login}; - } - - # is there a basedir - if (!-d "$templates") { - $form->error(sprintf($locale->text("The directory %s does not exist."), $templates)); - } - - # add base directory to $form->{templates} - $form->{templates} =~ s|.*/||; - $form->{templates} = "$templates/$form->{templates}"; - - $myconfig = new User "$memberfile", "$form->{login}"; - - # redo acs variable and delete all the acs codes - my @acs; - foreach $item (split m|;|, $form->{all_acs}) { - my $name = "ACS_${item}"; - $name =~ s| |+|g; - push @acs, $item if !$form->{$name}; - delete $form->{$name}; - } - $form->{acs} = join ";", @acs; - - $form->isblank("dbname", $locale->text('Dataset missing!')); - $form->isblank("dbuser", $locale->text('Database User missing!')); - - foreach $item (keys %{$form}) { - $myconfig->{$item} = $form->{$item}; - } - - delete $myconfig->{stylesheet}; - if ($form->{userstylesheet}) { - $myconfig->{stylesheet} = $form->{userstylesheet}; - } - - $myconfig->save_member($memberfile, $userspath); - - if ($webdav) { - @webdavdirs = - qw(angebote bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen); - foreach $directory (@webdavdirs) { - $file = "webdav/" . $directory . "/webdav-user"; - if ($form->{$directory}) { - if (open(HTACCESS, "$file")) { - while () { - ($login, $password) = split(/:/, $_); - if ($login ne $form->{login}) { - $newfile .= $_; - } - } - close(HTACCESS); - } - open(HTACCESS, "> $file") or die "cannot open $file $ERRNO\n"; - $newfile .= $myconfig->{login} . ":" . $myconfig->{password} . "\n"; - print(HTACCESS $newfile); - close(HTACCESS); - } else { - $form->{$directory} = 0; - if (open(HTACCESS, "$file")) { - while () { - ($login, $password) = split(/:/, $_); - if ($login ne $form->{login}) { - $newfile .= $_; - } - } - close(HTACCESS); - } - open(HTACCESS, "> $file") or die "cannot open $file $ERRNO\n"; - print(HTACCESS $newfile); - close(HTACCESS); - } - } - } - - $form->{templates} =~ s|.*/||; - $form->{templates} = "${templates}/$form->{templates}"; - $form->{mastertemplates} =~ s|.*/||; - - # create user template directory and copy master files - if (!-d "$form->{templates}") { - umask(002); - - if (mkdir "$form->{templates}", oct("771")) { - - umask(007); - - # copy templates to the directory - opendir TEMPLATEDIR, "$templates/." or $form - error("$templates : $ERRNO"); - @templates = grep /$form->{mastertemplates}.*?\.(html|tex|sty|xml|txb)$/, - readdir TEMPLATEDIR; - closedir TEMPLATEDIR; - - foreach $file (@templates) { - open(TEMP, "$templates/$file") - or $form->error("$templates/$file : $ERRNO"); - - $file =~ s/$form->{mastertemplates}-//; - open(NEW, ">$form->{templates}/$file") - or $form->error("$form->{templates}/$file : $ERRNO"); - - while ($line = ) { - print NEW $line; - } - close(TEMP); - close(NEW); + if ($auth->session_tables_present()) { + delete $::form->{'{AUTH}admin_password'}; } - } else { - $form->error("$ERRNO: $form->{templates}"); - } - } - - $form->redirect($locale->text('User saved!')); - -} -sub delete { - $form->error($locale->text('File locked!')) if (-f ${memberfile} . LCK); - open(FH, ">${memberfile}.LCK") or $form->error("${memberfile}.LCK : $ERRNO"); - close(FH); - - my $members = Inifile->new($memberfile); - my $templates = $members->{$form->{login}}->{templates}; - delete $members->{$form->{login}}; - $members->write(); - unlink "${memberfile}.LCK"; - - if ($templates) { - my $templates_in_use = 0; - foreach $login (keys %{ $members }) { - next if $login =~ m/^[A-Z]+$/; - next if $members->{$login}->{templates} ne $templates; - $templates_in_use = 1; - last; - } - - if (!$templates_in_use && -d $templates) { - unlink <$templates/*>; - rmdir $templates; + call_sub($locale->findsub($form->{action})); } + } else { + adminlogin(); } - - # delete config file for user - unlink "$userspath/$form->{login}.conf"; - - $form->redirect($locale->text('User deleted!')); - -} - -sub login_name { - my $login = shift; - - $login =~ s/\[\]//g; - return ($login) ? $login : undef; - -} - -sub get_value { - my $line = shift; - - my ($null, $value) = split(/=/, $line, 2); - - # remove comments - $value =~ s/\s#.*//g; - - # remove any trailing whitespace - $value =~ s/^\s*(.*?)\s*$/$1/; - - $value; -} - -sub change_admin_password { - - $form->{title} = - qq|Lx-Office ERP | - . $locale->text('Administration') . " / " - . $locale->text('Change Admin Password'); - - $form->header(); - print $form->parse_html_template2("admin/change_admin_password"); -} - -sub change_password { - if ($form->{"password"} ne $form->{"password_again"}) { - $form->{title} = - qq|Lx-Office ERP | - . $locale->text('Administration') . " / " - . $locale->text('Change Admin Password'); - - $form->header(); - $form->error($locale->text("The passwords do not match.")); - } - - $root->{password} = $form->{password}; - - $root->{'root login'} = 1; - $root->save_member($memberfile); - - $form->{callback} = - "$form->{script}?action=list_users&rpw=$root->{password}"; - - $form->redirect($locale->text('Password changed!')); + $::lxdebug->leave_sub; } -sub check_password { - $root = new User "$memberfile", $form->{root}; - - if (!defined($root->{password}) || ($root->{password} ne $form->{rpw})) { - $form->error($locale->text('Incorrect Password!')); - } - +sub adminlogin { + print $::request->cgi->redirect('controller.pl?action=Admin/login'); } sub pg_database_administration { - - $form->{dbdriver} = 'Pg'; + my $form = $main::form; dbselect_source(); - } sub dbselect_source { - $form->{dbport} = '5432'; - $form->{dbuser} = 'postgres'; + my $form = $main::form; + my $locale = $main::locale; + + $form->{dbport} = $::auth->{DB_config}->{port} || 5432; + $form->{dbuser} = $::auth->{DB_config}->{user} || 'lxoffice'; $form->{dbdefault} = 'template1'; - $form->{dbhost} = 'localhost'; + $form->{dbhost} = $::auth->{DB_config}->{host} || 'localhost'; - $form->{title} = "Lx-Office ERP / " . $locale->text('Database Administration'); + $form->{title} = "kivitendo / " . $locale->text('Database Administration'); - $form->{ALLOW_DBBACKUP} = "$pg_dump_exe" ne "DISABLED"; + # Intentionnaly disabled unless fixed to work with the authentication DB. + $form->{ALLOW_DBBACKUP} = 0; # "$pg_dump_exe" ne "DISABLED"; $form->header(); - print $form->parse_html_template2("admin/dbadmin"); + print $form->parse_html_template("admin/dbadmin"); } sub continue { - call_sub($form->{"nextsub"}); -} - -sub back { - call_sub($form->{"back_nextsub"}); + call_sub($main::form->{"nextsub"}); } sub update_dataset { - $form->{title} = - "Lx-Office ERP " - . $locale->text('Database Administration') . " / " - . $locale->text('Update Dataset'); + my $form = $main::form; + my $locale = $main::locale; + + $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Update Dataset'); my @need_updates = User->dbneedsupdate($form); $form->{NEED_UPDATES} = \@need_updates; $form->{ALL_UPDATED} = !scalar @need_updates; $form->header(); - print $form->parse_html_template2("admin/update_dataset"); + print $form->parse_html_template("admin/update_dataset"); } sub dbupdate { - $form->{stylesheet} = "lx-office-erp.css"; + my $form = $main::form; + my $locale = $main::locale; + + $::request->{layout}->use_stylesheet("lx-office-erp.css"); $form->{title} = $locale->text("Dataset upgrade"); $form->header(); @@ -609,92 +166,97 @@ sub dbupdate { $| = 1; - print $form->parse_html_template2("admin/dbupgrade_all_header"); + print $form->parse_html_template("admin/dbupgrade_all_header"); foreach my $i (@update_rows) { restore_form($saved_form); - map { $form->{$_} = $form->{"${_}_${i}"} } qw(dbname dbdriver dbhost dbport dbuser dbpasswd); - - my $controls = parse_dbupdate_controls($form, $form->{dbdriver}); - - print $form->parse_html_template2("admin/dbupgrade_header"); + %::myconfig = (); + map { $form->{$_} = $::myconfig{$_} = $form->{"${_}_${i}"} } qw(dbname dbhost dbport dbuser dbpasswd); - $form->{dbupdate} = $form->{dbname}; - $form->{$form->{dbname}} = 1; + print $form->parse_html_template("admin/dbupgrade_header"); User->dbupdate($form); - User->dbupdate2($form, $controls); + User->dbupdate2(form => $form, updater => SL::DBUpgrade2->new(form => $form)->parse_dbupdate_controls, database => $form->{dbname}); - print $form->parse_html_template2("admin/dbupgrade_footer"); + print $form->parse_html_template("admin/dbupgrade_footer"); } - print $form->parse_html_template2("admin/dbupgrade_all_done"); + print $form->parse_html_template("admin/dbupgrade_all_done"); } sub create_dataset { - $form->{dbsources} = join " ", map { "[${_}]" } sort User->dbsources(\%$form); + my $form = $main::form; + my $locale = $main::locale; - $form->{CHARTS} = []; + $form->{dbsources} = join " ", map { "[${_}]" } sort User->dbsources($form); - opendir SQLDIR, "sql/." or $form - error($ERRNO); - foreach $item (sort grep /-chart\.sql\z/, readdir SQLDIR) { - next if ($item eq 'Default-chart.sql'); - $item =~ s/-chart\.sql//; - push @{ $form->{CHARTS} }, { "name" => $item, - "selected" => $item eq "Germany-DATEV-SKR03EU" }; + $form->{CHARTS} = []; + + tie my %dir_h, 'IO::Dir', 'sql/'; + foreach my $item (map { s/-chart\.sql$//; $_ } sort grep { /-chart\.sql\z/ && !/Default-chart.sql\z/ } keys %dir_h) { + push @{ $form->{CHARTS} }, { name => $item, + selected => $item eq "Germany-DATEV-SKR03EU" }; } - closedir SQLDIR; - my $default_charset = $dbcharset; - $default_charset ||= Common::DEFAULT_CHARSET; + $form->{ACCOUNTING_METHODS} = [ map { { name => $_, selected => $_ eq 'cash' } } qw(accrual cash) ]; + $form->{INVENTORY_SYSTEMS} = [ map { { name => $_, selected => $_ eq 'periodic' } } qw(perpetual periodic) ]; + $form->{PROFIT_DETERMINATIONS} = [ map { { name => $_, selected => $_ eq 'income' } } qw(balance income) ]; - $form->{DBENCODINGS} = []; + my $default_charset = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET; - foreach my $encoding (@Common::db_encodings) { - push @{ $form->{DBENCODINGS} }, { "dbencoding" => $encoding->{dbencoding}, - "label" => $encoding->{label}, - "selected" => $encoding->{charset} eq $default_charset }; + my $cluster_encoding = User->dbclusterencoding($form); + if ($cluster_encoding && ($cluster_encoding =~ m/^(?:UTF-?8|UNICODE)$/i)) { + if ($::lx_office_conf{system}->{dbcharset} !~ m/^UTF-?8$/i) { + $form->show_generic_error($locale->text('The selected PostgreSQL installation uses UTF-8 as its encoding. ' . + 'Therefore you have to configure kivitendo to use UTF-8 as well.'), + 'back_button' => 1); + } + + $form->{FORCE_DBENCODING} = 'UNICODE'; + + } else { + $form->{DBENCODINGS} = [ map { { %{$_}, selected => $_->{charset} eq $default_charset } } @Common::db_encodings ]; } - $form->{title} = - "Lx-Office ERP " - . $locale->text('Database Administration') . " / " - . $locale->text('Create Dataset'); + $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Create Dataset'); $form->header(); - print $form->parse_html_template2("admin/create_dataset"); + print $form->parse_html_template("admin/create_dataset"); } sub dbcreate { + my $form = $main::form; + my $locale = $main::locale; + $form->isblank("db", $locale->text('Dataset missing!')); + $form->isblank("defaultcurrency", $locale->text('Default currency missing!')); User->dbcreate(\%$form); - $form->{title} = - "Lx-Office ERP " - . $locale->text('Database Administration') . " / " - . $locale->text('Create Dataset'); + $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Create Dataset'); $form->header(); - print $form->parse_html_template2("admin/dbcreate"); + print $form->parse_html_template("admin/dbcreate"); } sub delete_dataset { - @dbsources = User->dbsources_unused(\%$form, $memberfile); + my $form = $main::form; + my $locale = $main::locale; + + my @dbsources = User->dbsources_unused($form); $form->error($locale->text('Nothing to delete!')) unless @dbsources; - $form->{title} = - "Lx-Office ERP " - . $locale->text('Database Administration') . " / " - . $locale->text('Delete Dataset'); + $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Delete Dataset'); $form->{DBSOURCES} = [ map { { "name", $_ } } sort @dbsources ]; $form->header(); - print $form->parse_html_template2("admin/delete_dataset"); + print $form->parse_html_template("admin/delete_dataset"); } sub dbdelete { + my $form = $main::form; + my $locale = $main::locale; if (!$form->{db}) { $form->error($locale->text('No Dataset selected!')); @@ -702,22 +264,19 @@ sub dbdelete { User->dbdelete(\%$form); - $form->{title} = - "Lx-Office ERP " - . $locale->text('Database Administration') . " / " - . $locale->text('Delete Dataset'); + $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Delete Dataset'); $form->header(); - print $form->parse_html_template2("admin/dbdelete"); + print $form->parse_html_template("admin/dbdelete"); } sub backup_dataset { - $form->{title} = - "Lx-Office ERP " - . $locale->text('Database Administration') . " / " - . $locale->text('Backup Dataset'); + my $form = $main::form; + my $locale = $main::locale; - if ("$pg_dump_exe" eq "DISABLED") { - $form->error($locale->text('Database backups and restorations are disabled in lx-erp.conf.')); + $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Backup Dataset'); + + if ($::lx_office_conf{applications}->{pg_dump} eq "DISABLED") { + $form->error($locale->text('Database backups and restorations are disabled in the configuration.')); } my @dbsources = sort User->dbsources($form); @@ -726,22 +285,22 @@ sub backup_dataset { my $username = getpwuid $UID || "unknown-user"; my $hostname = hostname() || "unknown-host"; - $form->{from} = "Lx-Office Admin <${username}\@${hostname}>"; + $form->{from} = "kivitendo Admin <${username}\@${hostname}>"; $form->header(); - print $form->parse_html_template2("admin/backup_dataset"); + print $form->parse_html_template("admin/backup_dataset"); } sub backup_dataset_start { - $form->{title} = - "Lx-Office ERP " - . $locale->text('Database Administration') . " / " - . $locale->text('Backup Dataset'); + my $form = $main::form; + my $locale = $main::locale; - $pg_dump_exe ||= "pg_dump"; + $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Backup Dataset'); + + my $pg_dump_exe = $::lx_office_conf{applications}->{pg_dump} || "pg_dump"; if ("$pg_dump_exe" eq "DISABLED") { - $form->error($locale->text('Database backups and restorations are disabled in lx-erp.conf.')); + $form->error($locale->text('Database backups and restorations are disabled in the configuration.')); } $form->isblank("dbname", $locale->text('The dataset name is missing.')); @@ -766,7 +325,7 @@ sub backup_dataset_start { push @args, ("-p", $form->{dbport}) if ($form->{dbport}); push @args, $form->{dbname}; - my $cmd = "${pg_dump_exe} " . join(" ", map { s/\\/\\\\/g; s/\"/\\\"/g; $_ } @args); + my $cmd = "$pg_dump_exe " . join(" ", map { s/\\/\\\\/g; s/\"/\\\"/g; $_ } @args); my $name = "dataset_backup_$form->{dbname}_" . strftime("%Y%m%d", localtime()) . ".tar"; if ($form->{destination} ne "email") { @@ -805,34 +364,31 @@ sub backup_dataset_start { map { $mail->{$_} = $form->{$_} } qw(from to cc subject message); - $mail->{charset} = $dbcharset ? $dbcharset : Common::DEFAULT_CHARSET; + $mail->{charset} = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET; $mail->{attachments} = [ { "filename" => $tmp, "name" => $name } ]; $mail->send(); unlink "${tmpdir}/.pgpass", $tmp; rmdir $tmpdir; - $form->{title} = - "Lx-Office ERP " - . $locale->text('Database Administration') . " / " - . $locale->text('Backup Dataset'); + $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Backup Dataset'); $form->header(); - print $form->parse_html_template2("admin/backup_dataset_email_done"); + print $form->parse_html_template("admin/backup_dataset_email_done"); } } sub restore_dataset { - $form->{title} = - "Lx-Office ERP " - . $locale->text('Database Administration') . " / " - . $locale->text('Restore Dataset'); + my $form = $main::form; + my $locale = $main::locale; - if ("$pg_restore_exe" eq "DISABLED") { - $form->error($locale->text('Database backups and restorations are disabled in lx-erp.conf.')); + $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Restore Dataset'); + + if ($::lx_office_conf{applications}->{pg_restore} eq "DISABLED") { + $form->error($locale->text('Database backups and restorations are disabled in the configuration.')); } - my $default_charset = $dbcharset; + my $default_charset = $::lx_office_conf{system}->{dbcharset}; $default_charset ||= Common::DEFAULT_CHARSET; $form->{DBENCODINGS} = []; @@ -844,19 +400,19 @@ sub restore_dataset { } $form->header(); - print $form->parse_html_template2("admin/restore_dataset"); + print $form->parse_html_template("admin/restore_dataset"); } sub restore_dataset_start { - $form->{title} = - "Lx-Office ERP " - . $locale->text('Database Administration') . " / " - . $locale->text('Restore Dataset'); + my $form = $main::form; + my $locale = $main::locale; - $pg_restore_exe ||= "pg_restore"; + $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Restore Dataset'); + + my $pg_restore_exe = $::lx_office_conf{applications}->{pg_restore} || "pg_restore"; if ("$pg_restore_exe" eq "DISABLED") { - $form->error($locale->text('Database backups and restorations are disabled in lx-erp.conf.')); + $form->error($locale->text('Database backups and restorations are disabled in the configuration.')); } $form->isblank("new_dbname", $locale->text('The dataset name is missing.')); @@ -942,7 +498,7 @@ sub restore_dataset_start { push @args, ("-p", $form->{dbport}) if ($form->{dbport}); push @args, $tmp; - my $cmd = "${pg_restore_exe} " . join(" ", map { s/\\/\\\\/g; s/\"/\\\"/g; $_ } @args); + my $cmd = "$pg_restore_exe " . join(" ", map { s/\\/\\\\/g; s/\"/\\\"/g; $_ } @args); my $in = IO::File->new("$cmd 2>&1 |"); @@ -953,10 +509,10 @@ sub restore_dataset_start { $form->error($locale->text('The pg_restore process could not be started.')); } - $AUTOFLUSH = 1; + $English::AUTOFLUSH = 1; $form->header(); - print $form->parse_html_template2("admin/restore_dataset_start_header"); + print $form->parse_html_template("admin/restore_dataset_start_header"); while (my $line = <$in>) { print $line; @@ -964,32 +520,10 @@ sub restore_dataset_start { $in->close(); $form->{retval} = $CHILD_ERROR >> 8; - print $form->parse_html_template2("admin/restore_dataset_start_footer"); + print $form->parse_html_template("admin/restore_dataset_start_footer"); unlink "${tmpdir}/.pgpass", $tmp; rmdir $tmpdir; } -sub unlock_system { - - unlink "$userspath/nologin"; - - $form->{callback} = - "$form->{script}?action=list_users&rpw=$root->{password}"; - - $form->redirect($locale->text('Lockfile removed!')); - -} - -sub lock_system { - - open(FH, ">$userspath/nologin") - or $form->error($locale->text('Cannot create Lock!')); - close(FH); - - $form->{callback} = - "$form->{script}?action=list_users&rpw=$root->{password}"; - - $form->redirect($locale->text('Lockfile created!')); - -} +1;