5 use Digest::MD5 qw(md5_hex);
7 use Time::HiRes qw(gettimeofday);
8 use List::MoreUtils qw(uniq);
11 use SL::Auth::Constants qw(:all);
22 $main::lxdebug->enter_sub();
29 $self->{SESSION} = { };
31 $self->_read_auth_config();
33 $main::lxdebug->leave_sub();
39 my ($self, $login) = @_;
40 my %user = $self->read_user($login);
41 my $dbh = DBI->connect(
46 pg_enable_utf8 => $::locale->is_utf8,
49 ) or $::form->dberror;
51 if ($user{dboptions}) {
52 $dbh->do($user{dboptions}) or $::form->dberror($user{dboptions});
61 $self->{dbh}->disconnect() if ($self->{dbh});
64 # form isn't loaded yet, so auth needs it's own error.
66 $::lxdebug->show_backtrace();
68 my ($self, @msg) = @_;
69 if ($ENV{HTTP_USER_AGENT}) {
70 print Form->create_http_response(content_type => 'text/html');
71 print "<pre>", join ('<br>', @msg), "</pre>";
73 print STDERR "Error: @msg\n";
78 sub _read_auth_config {
79 $main::lxdebug->enter_sub();
84 my $in = IO::File->new('config/authentication.pl', 'r');
87 my $locale = Locale->new('en');
88 $self->mini_error($locale->text('The config file "config/authentication.pl" was not found.'));
99 my $locale = Locale->new('en');
100 $self->mini_error($locale->text('The config file "config/authentication.pl" contained invalid Perl code:'), $@);
103 if ($self->{module} eq 'DB') {
104 $self->{authenticator} = SL::Auth::DB->new($self);
106 } elsif ($self->{module} eq 'LDAP') {
107 $self->{authenticator} = SL::Auth::LDAP->new($self);
110 if (!$self->{authenticator}) {
111 my $locale = Locale->new('en');
112 $self->mini_error($locale->text('No or an unknown authenticantion module specified in "config/authentication.pl".'));
115 my $cfg = $self->{DB_config};
118 my $locale = Locale->new('en');
119 $self->mini_error($locale->text('config/authentication.pl: Key "DB_config" is missing.'));
122 if (!$cfg->{host} || !$cfg->{db} || !$cfg->{user}) {
123 my $locale = Locale->new('en');
124 $self->mini_error($locale->text('config/authentication.pl: Missing parameters in "DB_config". Required parameters are "host", "db" and "user".'));
127 $self->{authenticator}->verify_config();
129 $self->{session_timeout} *= 1;
130 $self->{session_timeout} = 8 * 60 if (!$self->{session_timeout});
132 $main::lxdebug->leave_sub();
135 sub authenticate_root {
136 $main::lxdebug->enter_sub();
139 my $password = shift;
140 my $is_crypted = shift;
142 $password = crypt $password, 'ro' if (!$password || !$is_crypted);
143 my $admin_password = crypt "$self->{admin_password}", 'ro';
145 $main::lxdebug->leave_sub();
147 return OK if $password eq $admin_password;
153 $main::lxdebug->enter_sub();
157 $main::lxdebug->leave_sub();
159 my $result = $self->{authenticator}->authenticate(@_);
160 return OK if $result eq OK;
166 $main::lxdebug->enter_sub(2);
169 my $may_fail = shift;
172 $main::lxdebug->leave_sub(2);
176 my $cfg = $self->{DB_config};
177 my $dsn = 'dbi:Pg:dbname=' . $cfg->{db} . ';host=' . $cfg->{host};
180 $dsn .= ';port=' . $cfg->{port};
183 $main::lxdebug->message(LXDebug->DEBUG1, "Auth::dbconnect DSN: $dsn");
185 $self->{dbh} = DBI->connect($dsn, $cfg->{user}, $cfg->{password}, { pg_enable_utf8 => $::locale->is_utf8, AutoCommit => 0 });
187 if (!$may_fail && !$self->{dbh}) {
188 $main::form->error($main::locale->text('The connection to the authentication database failed:') . "\n" . $DBI::errstr);
191 $main::lxdebug->leave_sub(2);
197 $main::lxdebug->enter_sub();
202 $self->{dbh}->disconnect();
206 $main::lxdebug->leave_sub();
210 $main::lxdebug->enter_sub();
214 my $dbh = $self->dbconnect();
215 my $query = qq|SELECT COUNT(*) FROM pg_tables WHERE (schemaname = 'auth') AND (tablename = 'user')|;
217 my ($count) = $dbh->selectrow_array($query);
219 $main::lxdebug->leave_sub();
225 $main::lxdebug->enter_sub();
229 my $dbh = $self->dbconnect(1);
231 $main::lxdebug->leave_sub();
236 sub create_database {
237 $main::lxdebug->enter_sub();
242 my $cfg = $self->{DB_config};
244 if (!$params{superuser}) {
245 $params{superuser} = $cfg->{user};
246 $params{superuser_password} = $cfg->{password};
249 $params{template} ||= 'template0';
250 $params{template} =~ s|[^a-zA-Z0-9_\-]||g;
252 my $dsn = 'dbi:Pg:dbname=template1;host=' . $cfg->{host};
255 $dsn .= ';port=' . $cfg->{port};
258 $main::lxdebug->message(LXDebug->DEBUG1(), "Auth::create_database DSN: $dsn");
260 my $charset = $main::dbcharset;
261 $charset ||= Common::DEFAULT_CHARSET;
262 my $encoding = $Common::charset_to_db_encoding{$charset};
263 $encoding ||= 'UNICODE';
265 my $dbh = DBI->connect($dsn, $params{superuser}, $params{superuser_password}, { pg_enable_utf8 => $charset =~ m/^utf-?8$/i });
268 $main::form->error($main::locale->text('The connection to the template database failed:') . "\n" . $DBI::errstr);
271 my $query = qq|CREATE DATABASE "$cfg->{db}" OWNER "$cfg->{user}" TEMPLATE "$params{template}" ENCODING '$encoding'|;
273 $main::lxdebug->message(LXDebug->DEBUG1(), "Auth::create_database query: $query");
278 my $error = $dbh->errstr();
280 $query = qq|SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = 'template0'|;
281 my ($cluster_encoding) = $dbh->selectrow_array($query);
283 if ($cluster_encoding && ($cluster_encoding =~ m/^(?:UTF-?8|UNICODE)$/i) && ($encoding !~ m/^(?:UTF-?8|UNICODE)$/i)) {
284 $error = $main::locale->text('Your PostgreSQL installationen uses UTF-8 as its encoding. Therefore you have to configure Lx-Office to use UTF-8 as well.');
289 $main::form->error($main::locale->text('The creation of the authentication database failed:') . "\n" . $error);
294 $main::lxdebug->leave_sub();
298 $main::lxdebug->enter_sub();
301 my $dbh = $self->dbconnect();
303 my $charset = $main::dbcharset;
304 $charset ||= Common::DEFAULT_CHARSET;
307 SL::DBUpgrade2->new(form => $::form)->process_query($dbh, 'sql/auth_db.sql', undef, $charset);
309 $main::lxdebug->leave_sub();
313 $main::lxdebug->enter_sub();
319 my $form = $main::form;
321 my $dbh = $self->dbconnect();
323 my ($sth, $query, $user_id);
325 $query = qq|SELECT id FROM auth."user" WHERE login = ?|;
326 ($user_id) = selectrow_query($form, $dbh, $query, $login);
329 $query = qq|SELECT nextval('auth.user_id_seq')|;
330 ($user_id) = selectrow_query($form, $dbh, $query);
332 $query = qq|INSERT INTO auth."user" (id, login) VALUES (?, ?)|;
333 do_query($form, $dbh, $query, $user_id, $login);
336 $query = qq|DELETE FROM auth.user_config WHERE (user_id = ?)|;
337 do_query($form, $dbh, $query, $user_id);
339 $query = qq|INSERT INTO auth.user_config (user_id, cfg_key, cfg_value) VALUES (?, ?, ?)|;
340 $sth = prepare_query($form, $dbh, $query);
342 while (my ($cfg_key, $cfg_value) = each %params) {
343 next if ($cfg_key eq 'password');
345 do_statement($form, $sth, $query, $user_id, $cfg_key, $cfg_value);
350 $main::lxdebug->leave_sub();
353 sub can_change_password {
356 return $self->{authenticator}->can_change_password();
359 sub change_password {
360 $main::lxdebug->enter_sub();
363 my $result = $self->{authenticator}->change_password(@_);
365 $main::lxdebug->leave_sub();
371 $main::lxdebug->enter_sub();
375 my $dbh = $self->dbconnect();
376 my $query = qq|SELECT u.id, u.login, cfg.cfg_key, cfg.cfg_value
377 FROM auth.user_config cfg
378 LEFT JOIN auth."user" u ON (cfg.user_id = u.id)|;
379 my $sth = prepare_execute_query($main::form, $dbh, $query);
383 while (my $ref = $sth->fetchrow_hashref()) {
384 $users{$ref->{login}} ||= { 'login' => $ref->{login}, 'id' => $ref->{id} };
385 $users{$ref->{login}}->{$ref->{cfg_key}} = $ref->{cfg_value} if (($ref->{cfg_key} ne 'login') && ($ref->{cfg_key} ne 'id'));
390 $main::lxdebug->leave_sub();
396 $main::lxdebug->enter_sub();
401 my $dbh = $self->dbconnect();
402 my $query = qq|SELECT u.id, u.login, cfg.cfg_key, cfg.cfg_value
403 FROM auth.user_config cfg
404 LEFT JOIN auth."user" u ON (cfg.user_id = u.id)
405 WHERE (u.login = ?)|;
406 my $sth = prepare_execute_query($main::form, $dbh, $query, $login);
410 while (my $ref = $sth->fetchrow_hashref()) {
411 $user_data{$ref->{cfg_key}} = $ref->{cfg_value};
412 @user_data{qw(id login)} = @{$ref}{qw(id login)};
417 $main::lxdebug->leave_sub();
423 $main::lxdebug->enter_sub();
428 my $dbh = $self->dbconnect();
429 my ($id) = selectrow_query($main::form, $dbh, qq|SELECT id FROM auth."user" WHERE login = ?|, $login);
431 $main::lxdebug->leave_sub();
437 $main::lxdebug->enter_sub();
442 my $form = $main::form;
444 my $dbh = $self->dbconnect();
445 my $query = qq|SELECT id FROM auth."user" WHERE login = ?|;
447 my ($id) = selectrow_query($form, $dbh, $query, $login);
449 return $main::lxdebug->leave_sub() if (!$id);
451 do_query($form, $dbh, qq|DELETE FROM auth.user_group WHERE user_id = ?|, $id);
452 do_query($form, $dbh, qq|DELETE FROM auth.user_config WHERE user_id = ?|, $id);
456 $main::lxdebug->leave_sub();
459 # --------------------------------------
463 sub restore_session {
464 $main::lxdebug->enter_sub();
468 my $cgi = $main::cgi;
469 $cgi ||= CGI->new('');
471 $session_id = $cgi->cookie($self->get_session_cookie_name());
472 $session_id =~ s|[^0-9a-f]||g;
474 $self->{SESSION} = { };
477 $main::lxdebug->leave_sub();
481 my ($dbh, $query, $sth, $cookie, $ref, $form);
485 $dbh = $self->dbconnect();
486 $query = qq|SELECT *, (mtime < (now() - '$self->{session_timeout}m'::interval)) AS is_expired FROM auth.session WHERE id = ?|;
488 $cookie = selectfirst_hashref_query($form, $dbh, $query, $session_id);
490 if (!$cookie || $cookie->{is_expired} || ($cookie->{ip_address} ne $ENV{REMOTE_ADDR})) {
491 $self->destroy_session();
492 $main::lxdebug->leave_sub();
493 return $cookie ? SESSION_EXPIRED : SESSION_NONE;
496 $query = qq|SELECT sess_key, sess_value FROM auth.session_content WHERE session_id = ?|;
497 $sth = prepare_execute_query($form, $dbh, $query, $session_id);
499 while (my $ref = $sth->fetchrow_hashref()) {
500 $self->{SESSION}->{$ref->{sess_key}} = $ref->{sess_value};
501 $form->{$ref->{sess_key}} = $self->_load_value($ref->{sess_value}) if (!defined $form->{$ref->{sess_key}});
506 $main::lxdebug->leave_sub();
512 return $_[1] if $_[1] !~ m/^---/;
516 $value = YAML::Load($_[1]);
523 sub destroy_session {
524 $main::lxdebug->enter_sub();
529 my $dbh = $self->dbconnect();
531 do_query($main::form, $dbh, qq|DELETE FROM auth.session_content WHERE session_id = ?|, $session_id);
532 do_query($main::form, $dbh, qq|DELETE FROM auth.session WHERE id = ?|, $session_id);
537 $self->{SESSION} = { };
540 $main::lxdebug->leave_sub();
543 sub expire_sessions {
544 $main::lxdebug->enter_sub();
548 my $dbh = $self->dbconnect();
550 qq|DELETE FROM auth.session_content
554 WHERE (mtime < (now() - '$self->{session_timeout}m'::interval)))|;
556 do_query($main::form, $dbh, $query);
559 qq|DELETE FROM auth.session
560 WHERE (mtime < (now() - '$self->{session_timeout}m'::interval))|;
562 do_query($main::form, $dbh, $query);
566 $main::lxdebug->leave_sub();
569 sub _create_session_id {
570 $main::lxdebug->enter_sub();
573 map { push @data, int(rand() * 255); } (1..32);
575 my $id = md5_hex(pack 'C*', @data);
577 $main::lxdebug->leave_sub();
582 sub create_or_refresh_session {
583 $main::lxdebug->enter_sub();
587 $session_id ||= $self->_create_session_id();
589 my ($form, $dbh, $query, $sth, $id);
592 $dbh = $self->dbconnect();
594 $query = qq|SELECT id FROM auth.session WHERE id = ?|;
596 ($id) = selectrow_query($form, $dbh, $query, $session_id);
599 do_query($form, $dbh, qq|UPDATE auth.session SET mtime = now() WHERE id = ?|, $session_id);
602 do_query($form, $dbh, qq|INSERT INTO auth.session (id, ip_address, mtime) VALUES (?, ?, now())|, $session_id, $ENV{REMOTE_ADDR});
606 $self->save_session($dbh);
610 $main::lxdebug->leave_sub();
615 my $provided_dbh = shift;
617 my $dbh = $provided_dbh || $self->dbconnect();
619 do_query($::form, $dbh, qq|DELETE FROM auth.session_content WHERE session_id = ?|, $session_id);
621 if (%{ $self->{SESSION} }) {
622 my $query = qq|INSERT INTO auth.session_content (session_id, sess_key, sess_value) VALUES (?, ?, ?)|;
623 my $sth = prepare_query($::form, $dbh, $query);
625 foreach my $key (sort keys %{ $self->{SESSION} }) {
626 do_statement($::form, $sth, $query, $session_id, $key, $self->{SESSION}->{$key});
632 $dbh->commit() unless $provided_dbh;
635 sub set_session_value {
636 $main::lxdebug->enter_sub();
641 $self->{SESSION} ||= { };
643 while (my ($key, $value) = each %params) {
644 $self->{SESSION}->{ $key } = YAML::Dump($value);
647 $main::lxdebug->leave_sub();
652 sub delete_session_value {
653 $main::lxdebug->enter_sub();
657 $self->{SESSION} ||= { };
658 delete @{ $self->{SESSION} }{ @_ };
660 $main::lxdebug->leave_sub();
665 sub get_session_value {
666 $main::lxdebug->enter_sub();
669 my $value = $self->{SESSION} ? $self->_load_value($self->{SESSION}->{ $_[0] }) : undef;
671 $main::lxdebug->leave_sub();
676 sub set_cookie_environment_variable {
678 $ENV{HTTP_COOKIE} = $self->get_session_cookie_name() . "=${session_id}";
681 sub get_session_cookie_name {
684 return $self->{cookie_name} || 'lx_office_erp_session_id';
691 sub session_tables_present {
692 $main::lxdebug->enter_sub();
695 my $dbh = $self->dbconnect(1);
698 $main::lxdebug->leave_sub();
705 WHERE (schemaname = 'auth')
706 AND (tablename IN ('session', 'session_content'))|;
708 my ($count) = selectrow_query($main::form, $dbh, $query);
710 $main::lxdebug->leave_sub();
715 # --------------------------------------
717 sub all_rights_full {
718 my $locale = $main::locale;
721 ["--crm", $locale->text("CRM optional software")],
722 ["crm_search", $locale->text("CRM search")],
723 ["crm_new", $locale->text("CRM create customers, vendors and contacts")],
724 ["crm_service", $locale->text("CRM services")],
725 ["crm_admin", $locale->text("CRM admin")],
726 ["crm_adminuser", $locale->text("CRM user")],
727 ["crm_adminstatus", $locale->text("CRM status")],
728 ["crm_email", $locale->text("CRM send email")],
729 ["crm_termin", $locale->text("CRM termin")],
730 ["crm_opportunity", $locale->text("CRM opportunity")],
731 ["crm_knowhow", $locale->text("CRM know how")],
732 ["crm_follow", $locale->text("CRM follow up")],
733 ["crm_notices", $locale->text("CRM notices")],
734 ["crm_other", $locale->text("CRM other")],
735 ["--master_data", $locale->text("Master Data")],
736 ["customer_vendor_edit", $locale->text("Create and edit customers and vendors")],
737 ["part_service_assembly_edit", $locale->text("Create and edit parts, services, assemblies")],
738 ["project_edit", $locale->text("Create and edit projects")],
739 ["license_edit", $locale->text("Manage license keys")],
740 ["--ar", $locale->text("AR")],
741 ["sales_quotation_edit", $locale->text("Create and edit sales quotations")],
742 ["sales_order_edit", $locale->text("Create and edit sales orders")],
743 ["sales_delivery_order_edit", $locale->text("Create and edit sales delivery orders")],
744 ["invoice_edit", $locale->text("Create and edit invoices and credit notes")],
745 ["dunning_edit", $locale->text("Create and edit dunnings")],
746 ["sales_all_edit", $locale->text("View/edit all employees sales documents")],
747 ["--ap", $locale->text("AP")],
748 ["request_quotation_edit", $locale->text("Create and edit RFQs")],
749 ["purchase_order_edit", $locale->text("Create and edit purchase orders")],
750 ["purchase_delivery_order_edit", $locale->text("Create and edit purchase delivery orders")],
751 ["vendor_invoice_edit", $locale->text("Create and edit vendor invoices")],
752 ["--warehouse_management", $locale->text("Warehouse management")],
753 ["warehouse_contents", $locale->text("View warehouse content")],
754 ["warehouse_management", $locale->text("Warehouse management")],
755 ["--general_ledger_cash", $locale->text("General ledger and cash")],
756 ["general_ledger", $locale->text("Transactions, AR transactions, AP transactions")],
757 ["datev_export", $locale->text("DATEV Export")],
758 ["cash", $locale->text("Receipt, payment, reconciliation")],
759 ["--reports", $locale->text('Reports')],
760 ["report", $locale->text('All reports')],
761 ["advance_turnover_tax_return", $locale->text('Advance turnover tax return')],
762 ["--batch_printing", $locale->text("Batch Printing")],
763 ["batch_printing", $locale->text("Batch Printing")],
764 ["--others", $locale->text("Others")],
765 ["email_bcc", $locale->text("May set the BCC field when sending emails")],
766 ["config", $locale->text("Change Lx-Office installation settings (all menu entries beneath 'System')")],
773 return grep !/^--/, map { $_->[0] } all_rights_full();
777 $main::lxdebug->enter_sub();
781 my $form = $main::form;
783 my $dbh = $self->dbconnect();
785 my $query = 'SELECT * FROM auth."group"';
786 my $sth = prepare_execute_query($form, $dbh, $query);
790 while ($row = $sth->fetchrow_hashref()) {
791 $groups->{$row->{id}} = $row;
795 $query = 'SELECT * FROM auth.user_group WHERE group_id = ?';
796 $sth = prepare_query($form, $dbh, $query);
798 foreach $group (values %{$groups}) {
801 do_statement($form, $sth, $query, $group->{id});
803 while ($row = $sth->fetchrow_hashref()) {
804 push @members, $row->{user_id};
806 $group->{members} = [ uniq @members ];
810 $query = 'SELECT * FROM auth.group_rights WHERE group_id = ?';
811 $sth = prepare_query($form, $dbh, $query);
813 foreach $group (values %{$groups}) {
814 $group->{rights} = {};
816 do_statement($form, $sth, $query, $group->{id});
818 while ($row = $sth->fetchrow_hashref()) {
819 $group->{rights}->{$row->{right}} |= $row->{granted};
822 map { $group->{rights}->{$_} = 0 if (!defined $group->{rights}->{$_}); } all_rights();
826 $main::lxdebug->leave_sub();
832 $main::lxdebug->enter_sub();
837 my $form = $main::form;
838 my $dbh = $self->dbconnect();
840 my ($query, $sth, $row, $rights);
843 ($group->{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('auth.group_id_seq')|);
845 $query = qq|INSERT INTO auth."group" (id, name, description) VALUES (?, '', '')|;
846 do_query($form, $dbh, $query, $group->{id});
849 do_query($form, $dbh, qq|UPDATE auth."group" SET name = ?, description = ? WHERE id = ?|, map { $group->{$_} } qw(name description id));
851 do_query($form, $dbh, qq|DELETE FROM auth.user_group WHERE group_id = ?|, $group->{id});
853 $query = qq|INSERT INTO auth.user_group (user_id, group_id) VALUES (?, ?)|;
854 $sth = prepare_query($form, $dbh, $query);
856 foreach my $user_id (uniq @{ $group->{members} }) {
857 do_statement($form, $sth, $query, $user_id, $group->{id});
861 do_query($form, $dbh, qq|DELETE FROM auth.group_rights WHERE group_id = ?|, $group->{id});
863 $query = qq|INSERT INTO auth.group_rights (group_id, "right", granted) VALUES (?, ?, ?)|;
864 $sth = prepare_query($form, $dbh, $query);
866 foreach my $right (keys %{ $group->{rights} }) {
867 do_statement($form, $sth, $query, $group->{id}, $right, $group->{rights}->{$right} ? 't' : 'f');
873 $main::lxdebug->leave_sub();
877 $main::lxdebug->enter_sub();
882 my $form = $main::from;
884 my $dbh = $self->dbconnect();
886 do_query($form, $dbh, qq|DELETE FROM auth.user_group WHERE group_id = ?|, $id);
887 do_query($form, $dbh, qq|DELETE FROM auth.group_rights WHERE group_id = ?|, $id);
888 do_query($form, $dbh, qq|DELETE FROM auth."group" WHERE id = ?|, $id);
892 $main::lxdebug->leave_sub();
895 sub evaluate_rights_ary {
896 $main::lxdebug->enter_sub(2);
903 foreach my $el (@{$ary}) {
904 if (ref $el eq "ARRAY") {
905 if ($action eq '|') {
906 $value |= evaluate_rights_ary($el);
908 $value &= evaluate_rights_ary($el);
911 } elsif (($el eq '&') || ($el eq '|')) {
914 } elsif ($action eq '|') {
923 $main::lxdebug->leave_sub(2);
928 sub _parse_rights_string {
929 $main::lxdebug->enter_sub(2);
939 push @stack, $cur_ary;
941 while ($access =~ m/^([a-z_0-9]+|\||\&|\(|\)|\s+)/) {
943 substr($access, 0, length $1) = "";
945 next if ($token =~ /\s/);
948 my $new_cur_ary = [];
949 push @stack, $new_cur_ary;
950 push @{$cur_ary}, $new_cur_ary;
951 $cur_ary = $new_cur_ary;
953 } elsif ($token eq ")") {
957 $main::lxdebug->leave_sub(2);
961 $cur_ary = $stack[-1];
963 } elsif (($token eq "|") || ($token eq "&")) {
964 push @{$cur_ary}, $token;
967 push @{$cur_ary}, $self->{RIGHTS}->{$login}->{$token} * 1;
971 my $result = ($access || (1 < scalar @stack)) ? 0 : evaluate_rights_ary($stack[0]);
973 $main::lxdebug->leave_sub(2);
979 $main::lxdebug->enter_sub(2);
986 $self->{FULL_RIGHTS} ||= { };
987 $self->{FULL_RIGHTS}->{$login} ||= { };
989 if (!defined $self->{FULL_RIGHTS}->{$login}->{$right}) {
990 $self->{RIGHTS} ||= { };
991 $self->{RIGHTS}->{$login} ||= $self->load_rights_for_user($login);
993 $self->{FULL_RIGHTS}->{$login}->{$right} = $self->_parse_rights_string($login, $right);
996 my $granted = $self->{FULL_RIGHTS}->{$login}->{$right};
997 $granted = $default if (!defined $granted);
999 $main::lxdebug->leave_sub(2);
1005 $main::lxdebug->enter_sub(2);
1009 my $dont_abort = shift;
1011 my $form = $main::form;
1013 if ($self->check_right($form->{login}, $right)) {
1014 $main::lxdebug->leave_sub(2);
1019 delete $form->{title};
1020 $form->show_generic_error($main::locale->text("You do not have the permissions to access this function."));
1023 $main::lxdebug->leave_sub(2);
1028 sub load_rights_for_user {
1029 $main::lxdebug->enter_sub();
1034 my $form = $main::form;
1035 my $dbh = $self->dbconnect();
1037 my ($query, $sth, $row, $rights);
1042 qq|SELECT gr."right", gr.granted
1043 FROM auth.group_rights gr
1046 FROM auth.user_group ug
1047 LEFT JOIN auth."user" u ON (ug.user_id = u.id)
1048 WHERE u.login = ?)|;
1050 $sth = prepare_execute_query($form, $dbh, $query, $login);
1052 while ($row = $sth->fetchrow_hashref()) {
1053 $rights->{$row->{right}} |= $row->{granted};
1057 map({ $rights->{$_} = 0 unless (defined $rights->{$_}); } SL::Auth::all_rights());
1059 $main::lxdebug->leave_sub();