Revision 722fee3c
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/User.pm | ||
---|---|---|
92 | 92 |
} |
93 | 93 |
|
94 | 94 |
sub login { |
95 |
$main::lxdebug->enter_sub(); |
|
96 |
|
|
97 | 95 |
my ($self, $form) = @_; |
98 | 96 |
our $sid; |
99 | 97 |
|
100 |
local *FH; |
|
101 |
|
|
102 |
my $rc = -3; |
|
98 |
return -3 if !$self->{login} || !$::auth->client; |
|
103 | 99 |
|
104 |
if ($self->{login}) { |
|
105 |
my %myconfig = $main::auth->read_user(login => $self->{login}); |
|
100 |
my %myconfig = $main::auth->read_user(login => $self->{login}); |
|
106 | 101 |
|
107 |
# check if database is down |
|
108 |
my $dbh = SL::DBConnect->connect($myconfig{dbconnect}, $myconfig{dbuser}, $myconfig{dbpasswd}, SL::DBConnect->get_options) |
|
109 |
or $self->error($DBI::errstr); |
|
110 |
|
|
111 |
# we got a connection, check the version |
|
112 |
my $query = qq|SELECT version FROM defaults|; |
|
113 |
my $sth = $dbh->prepare($query); |
|
114 |
$sth->execute || $form->dberror($query); |
|
102 |
# check if database is down |
|
103 |
my $dbh = $form->dbconnect_noauto; |
|
115 | 104 |
|
116 |
my ($dbversion) = $sth->fetchrow_array; |
|
117 |
$sth->finish; |
|
105 |
# we got a connection, check the version |
|
106 |
my $query = qq|SELECT version FROM defaults|; |
|
107 |
my $sth = $dbh->prepare($query); |
|
108 |
$sth->execute || $form->dberror($query); |
|
118 | 109 |
|
119 |
$self->create_employee_entry($form, $dbh, \%myconfig); |
|
110 |
my ($dbversion) = $sth->fetchrow_array; |
|
111 |
$sth->finish; |
|
120 | 112 |
|
121 |
$self->create_schema_info_table($form, $dbh);
|
|
113 |
$self->create_employee_entry($form, $dbh, \%myconfig);
|
|
122 | 114 |
|
123 |
my $dbupdater_auth = SL::DBUpgrade2->new(form => $form, dbdriver => 'Pg', auth => 1)->parse_dbupdate_controls; |
|
124 |
if ($dbupdater_auth->unapplied_upgrade_scripts($::auth->dbconnect)) { |
|
125 |
$::lxdebug->leave_sub; |
|
126 |
return -3; |
|
127 |
} |
|
115 |
$self->create_schema_info_table($form, $dbh); |
|
128 | 116 |
|
129 |
$rc = 0; |
|
117 |
# Auth DB upgrades available? |
|
118 |
my $dbupdater_auth = SL::DBUpgrade2->new(form => $form, dbdriver => 'Pg', auth => 1)->parse_dbupdate_controls; |
|
119 |
return -3 if $dbupdater_auth->unapplied_upgrade_scripts($::auth->dbconnect); |
|
130 | 120 |
|
131 |
my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $myconfig{dbdriver})->parse_dbupdate_controls;
|
|
121 |
my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $myconfig{dbdriver})->parse_dbupdate_controls; |
|
132 | 122 |
|
133 |
map({ $form->{$_} = $myconfig{$_} } qw(dbname dbhost dbport dbdriver dbuser dbpasswd dbconnect dateformat)); |
|
134 |
dbconnect_vars($form, $form->{dbname}); |
|
135 |
my $update_available = $dbupdater->update_available($dbversion) || $dbupdater->update2_available($dbh); |
|
136 |
$dbh->disconnect; |
|
123 |
$form->{$_} = $::auth->client->{$_} for qw(dbname dbhost dbport dbuser dbpasswd); |
|
124 |
$form->{$_} = $myconfig{$_} for qw(dateformat); |
|
137 | 125 |
|
138 |
if ($update_available) { |
|
139 |
$form->{"title"} = $main::locale->text("Dataset upgrade"); |
|
140 |
$form->header(no_layout => $form->{no_layout}); |
|
141 |
print $form->parse_html_template("dbupgrade/header"); |
|
126 |
dbconnect_vars($form, $form->{dbname}); |
|
142 | 127 |
|
143 |
$form->{dbupdate} = "db$myconfig{dbname}";
|
|
144 |
$form->{ $form->{dbupdate} } = 1;
|
|
128 |
my $update_available = $dbupdater->update_available($dbversion) || $dbupdater->update2_available($dbh);
|
|
129 |
$dbh->disconnect;
|
|
145 | 130 |
|
146 |
if ($form->{"show_dbupdate_warning"}) {
|
|
147 |
print $form->parse_html_template("dbupgrade/warning");
|
|
148 |
::end_of_request();
|
|
149 |
}
|
|
131 |
return 0 if !$update_available;
|
|
132 |
$form->{"title"} = $main::locale->text("Dataset upgrade");
|
|
133 |
$form->header(no_layout => $form->{no_layout});
|
|
134 |
print $form->parse_html_template("dbupgrade/header");
|
|
150 | 135 |
|
151 |
# update the tables |
|
152 |
if (!$::lx_office_conf{debug}->{keep_installation_unlocked} && !open(FH, ">", $::lx_office_conf{paths}->{userspath} . "/nologin")) { |
|
153 |
$form->show_generic_error($main::locale->text('A temporary file could not be created. ' . |
|
154 |
'Please verify that the directory "#1" is writeable by the webserver.', |
|
155 |
$::lx_office_conf{paths}->{userspath}), |
|
156 |
'back_button' => 1); |
|
157 |
} |
|
136 |
$form->{dbupdate} = "db" . $form->{dbname}; |
|
158 | 137 |
|
159 |
# required for Oracle |
|
160 |
$form->{dbdefault} = $sid; |
|
138 |
if ($form->{"show_dbupdate_warning"}) { |
|
139 |
print $form->parse_html_template("dbupgrade/warning"); |
|
140 |
::end_of_request(); |
|
141 |
} |
|
161 | 142 |
|
162 |
# ignore HUP, QUIT in case the webserver times out |
|
163 |
$SIG{HUP} = 'IGNORE'; |
|
164 |
$SIG{QUIT} = 'IGNORE'; |
|
143 |
# update the tables |
|
144 |
my $fh; |
|
145 |
if (!$::lx_office_conf{debug}->{keep_installation_unlocked} && !open($fh, ">", $::lx_office_conf{paths}->{userspath} . "/nologin")) { |
|
146 |
$form->show_generic_error($main::locale->text('A temporary file could not be created. ' . |
|
147 |
'Please verify that the directory "#1" is writeable by the webserver.', |
|
148 |
$::lx_office_conf{paths}->{userspath}), |
|
149 |
'back_button' => 1); |
|
150 |
} |
|
165 | 151 |
|
166 |
$self->dbupdate($form);
|
|
167 |
$self->dbupdate2($form, $dbupdater);
|
|
168 |
SL::DBUpgrade2->new(form => $::form, dbdriver => 'Pg', auth => 1)->apply_admin_dbupgrade_scripts(0);
|
|
152 |
# ignore HUP, QUIT in case the webserver times out
|
|
153 |
$SIG{HUP} = 'IGNORE';
|
|
154 |
$SIG{QUIT} = 'IGNORE';
|
|
169 | 155 |
|
170 |
close(FH); |
|
156 |
$self->dbupdate($form); |
|
157 |
$self->dbupdate2($form, $dbupdater); |
|
158 |
SL::DBUpgrade2->new(form => $::form, dbdriver => 'Pg', auth => 1)->apply_admin_dbupgrade_scripts(0); |
|
171 | 159 |
|
172 |
# remove lock file |
|
173 |
unlink($::lx_office_conf{paths}->{userspath} . "/nologin"); |
|
160 |
close($fh); |
|
174 | 161 |
|
175 |
print $form->parse_html_template("dbupgrade/footer"); |
|
162 |
# remove lock file |
|
163 |
unlink($::lx_office_conf{paths}->{userspath} . "/nologin"); |
|
176 | 164 |
|
177 |
$rc = -2; |
|
178 |
} |
|
179 |
} |
|
165 |
print $form->parse_html_template("dbupgrade/footer"); |
|
180 | 166 |
|
181 |
$main::lxdebug->leave_sub(); |
|
182 |
|
|
183 |
return $rc; |
|
167 |
return -2; |
|
184 | 168 |
} |
185 | 169 |
|
186 | 170 |
sub dbconnect_vars { |
... | ... | |
749 | 733 |
return @conf; |
750 | 734 |
} |
751 | 735 |
|
752 |
sub error { |
|
753 |
$main::lxdebug->enter_sub(); |
|
754 |
|
|
755 |
my ($self, $msg) = @_; |
|
756 |
|
|
757 |
$main::lxdebug->show_backtrace(); |
|
758 |
|
|
759 |
if ($ENV{HTTP_USER_AGENT}) { |
|
760 |
print qq|Content-Type: text/html |
|
761 |
|
|
762 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> |
|
763 |
|
|
764 |
<body bgcolor=ffffff> |
|
765 |
|
|
766 |
<h2><font color=red>Error!</font></h2> |
|
767 |
<p><b>$msg</b>|; |
|
768 |
|
|
769 |
} |
|
770 |
|
|
771 |
die "Error: $msg\n"; |
|
772 |
|
|
773 |
$main::lxdebug->leave_sub(); |
|
774 |
} |
|
775 |
|
|
776 | 736 |
sub data { |
777 | 737 |
+{ %{ $_[0] } } |
778 | 738 |
} |
Auch abrufbar als: Unified diff
Userlogin mit Mandanten gefixt (erster Schritt)