-require "bin/mozilla/admin_groups.pl";
-
-our $cgi = new CGI('');
-
-$form = new Form;
-
-$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}"; };
- $form->error($@) if ($@);
-}
-
-$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());
-
- call_sub($locale->findsub($form->{action}));
-
-} elsif ($auth->authenticate_root($form->{rpw}, 0) == Auth::OK) {
-
- $auth->create_or_refresh_session() if ($auth->session_tables_present());
-
- login();
-
-} else {
- # if there are no drivers bail out
- $form->error($locale->text('No Database Drivers available!'))
- unless (User->dbdrivers);
-
- adminlogin();
-
-}
-
-1;
-
-# end
-
-sub adminlogin {
-
- $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 logout {
- $auth->destroy_session();
- adminlogin();
-}
-
-sub check_auth_db_and_tables {
- my %params;
-
- map { $params{"db_${_}"} = $auth->{DB_config}->{$_} } keys %{ $auth->{DB_config} };
-
- if (!$auth->check_database()) {
- $form->{title} = $locale->text('Authentification database creation');
- $form->header();
- print $form->parse_html_template('admin/check_auth_database', \%params);
-
- exit 0;
- }
-
- if (!$auth->check_tables()) {
- $form->{title} = $locale->text('Authentification tables creation');
- $form->header();
- print $form->parse_html_template('admin/check_auth_tables', \%params);
-
- exit 0;
- }
-
- if (-f $memberfile) {
- my $memberdir = "";
-
- 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
- }
-}
-
-sub create_auth_db {
- $auth->create_database('superuser' => $form->{db_superuser},
- 'superuser_password' => $form->{db_superuser_password},
- 'template' => $form->{db_template});
- login();
-}
-
-sub create_auth_tables {
- $auth->create_tables();
- $auth->set_session_value('rpw', $form->{rpw});
- $auth->create_or_refresh_session();
-
- 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);
- }
-
- login();
-}
-
-sub migrate_users {
- $lxdebug->enter_sub();
-
- my $memberdir = "";
-
- 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, $!));
- }
-
- copy $memberfile, "users/member-file-migration/members";
-
- 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;
-
- next if (m/^\s*\#/);
-
- 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;
- }
- }
-
- $in->close();
-
- delete $members{"root login"};
-
- 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;
- }
- }
-
- 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 });
-
- $lxdebug->leave_sub();
-}
-
-sub create_standard_group_ask {
- $form->{title} = $locale->text('Create a standard group');
-
- $form->header();
- print $form->parse_html_template("admin/create_standard_group_ask");
-}
-
-sub create_standard_group {
- my %members = $auth->read_all_users();
-
- my $groups = $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."));
- }
- }
-
- 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);
-
- user_migration_complete(1);
-}
-
-sub dont_create_standard_group {
- user_migration_complete(0);
-}
-
-sub user_migration_complete {
- my $standard_group_created = shift;
-
- $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 %members = $auth->read_all_users();
-
- 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} ];
-
- $form->header();
- print $form->parse_html_template("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_user {
-
- $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($form->{login});
-
- # 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;