dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
dbxLogin.class.php
Go to the documentation of this file.
1<?php
2namespace dbx\dbxLogin;
3
4Class dbxLogin {
5
6
7 private function logout_response($uid) {
8 dbx()->debug("dbxLogin run logout");
9 dbx()->sys_msg('security', 'login', $uid, 'lock out', $_SERVER['REMOTE_ADDR'] ?? '');
10 $this->send_logout_mail($uid);
11 dbx()->logout($uid);
12 dbx()->set_modul_var('logout', 1);
13 dbx()->debug("dbxLogin logout redirect to fresh login form");
14 return dbx()->redirect('?dbx_modul=dbxLogin&dbx_run1=login&logout=1', 0);
15 }
16
17 private function mail_enabled($key) {
18 $value = dbx()->get_config('dbxLogin', $key);
19 $value = strtolower(trim((string)$value));
20 return !in_array($value, array('', '0', 'false', 'off', 'no'), true);
21 }
22
23 private function send_logout_mail($uid) {
24 if (!$uid || !$this->mail_enabled('logout_mail')) {
25 return;
26 }
27
28 try {
29 $db = dbx()->get_system_obj('dbxDB');
30 $rec = $db->select1('dbxUser', (int)$uid, '*', 0);
31 if (!is_array($rec)) {
32 $rec = array('id' => $uid);
33 }
34
35 $browser = dbx()->get_system_obj('dbxBrowser');
36 $username = (string)($rec['uname'] ?? ('uid-' . (int)$uid));
37 $tpl = dbx()->get_system_obj('dbxTPL');
38 $rows = array(
39 'Zeit' => date('Y-m-d H:i:s'),
40 'Benutzername' => $username,
41 'User-ID' => (string)($rec['id'] ?? $uid),
42 'Name' => trim((string)($rec['name'] ?? '') . ' ' . (string)($rec['name2'] ?? '')),
43 'E-Mail' => (string)($rec['email'] ?? ''),
44 'Rollen' => (string)($rec['roles'] ?? ''),
45 'Request' => (string)($_SERVER['REQUEST_URI'] ?? ''),
46 'Referer' => (string)($_SERVER['HTTP_REFERER'] ?? ''),
47 );
48
49 $browserRows = array(
50 'IP' => (string)($browser->_ip ?? ''),
51 'Host' => (string)($browser->_host ?? ''),
52 'Browser' => (string)($browser->_name ?? ''),
53 'Version' => (string)($browser->_version ?? ''),
54 'Plattform' => (string)($browser->_platform ?? ''),
55 'Geraet' => (string)($browser->_device ?? ''),
56 'Sprache' => (string)($browser->_language ?? ''),
57 'Mobile' => !empty($browser->_mobile) ? 'Ja' : 'Nein',
58 'Tablet/iPad' => !empty($browser->_ipad) ? 'Ja' : 'Nein',
59 'Robot' => !empty($browser->_robot) ? 'Ja' : 'Nein',
60 'Fenster' => (string)($browser->_width ?? 0) . ' x ' . (string)($browser->_height ?? 0),
61 'Cookies' => !empty($browser->_cookie) ? 'Ja' : 'Nein',
62 'JavaScript' => !empty($browser->_js) ? 'Ja' : 'Nein',
63 'User-Agent' => (string)($browser->_agent ?? ($_SERVER['HTTP_USER_AGENT'] ?? '')),
64 );
65
66 $html = $tpl->get_tpl('dbxLogin|mail-logout', array(
67 'username' => $this->h($username),
68 'logout_table' => $this->html_info_table($rows),
69 'browser_table' => $this->html_info_table($browserRows),
70 ));
71 $text = $this->logout_mail_text($rows, $browserRows);
72
73 dbx()->send_mail('logout@dbxapp.de', 'leo4u@gmx.de', 'dbxApp Logout: ' . $username, $html, 'html', array(), array('text' => $text));
74 } catch (\Throwable $e) {
75 dbx()->sys_msg('error', 'login', (int)$uid, 'logout mail failed', $e->getMessage());
76 }
77 }
78
79 private function logout_mail_text($rows, $browserRows) {
80 $lines = array('dbxApp Logout');
81 foreach ($rows as $key => $value) {
82 $lines[] = $key . ': ' . $value;
83 }
84 $lines[] = '';
85 $lines[] = 'Browser und Client:';
86 foreach ($browserRows as $key => $value) {
87 $lines[] = $key . ': ' . $value;
88 }
89 return implode("\n", $lines);
90 }
91
92 private function html_info_table($rows) {
93 $tpl = dbx()->get_system_obj('dbxTPL');
94 $rowHtml = '';
95 foreach ($rows as $key => $value) {
96 $rowHtml .= $tpl->get_tpl('dbxLogin|mail-info-row', array(
97 'label' => $this->h($key),
98 'value' => $this->h($value),
99 ));
100 }
101 return $tpl->get_tpl('dbxLogin|mail-info-table', array('rows' => $rowHtml));
102 }
103
104 private function h($value) {
105 return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
106 }
107
108
109 public function run(): mixed {
110 $uid =dbx()->user();
111 $modul =dbx()->get_system_var('dbx_modul');
112 $run =dbx()->get_system_var('dbx_run1');
113
114 dbx()->set_system_var('dbx_title','dbxApp Login');
115 dbx()->load_content_cache_classes();
116 \dbx\dbxContent\dbxContentRenderer::resetSeoMeta();
117
118 $content='';
119
120 if ($run == 'run') {
121 if (!$uid) $run='login';
122 if ( $uid) $run='logout';
123 }
124 dbx()->debug("dbxLogin switch-action=($run)");
125
126 switch ($run) {
127
128
129 case 'logout':
130 $content=$this->logout_response($uid);
131 break;
132
133 case 'login':
134 dbx()->debug("dbxLogin run login ($run)");
135 $obj=dbx()->get_include_obj('login');
136 $content=$obj->run();
137 break;
138
139 case 'register':
140 $run2 = dbx()->get_modul_var('dbx_run2', '', 'parameter');
141 if ((string)dbx()->get_config('dbxLogin', 'register') === '1' || in_array($run2, array('confirm', 'resend_confirm'), true)) {
142 $obj=dbx()->get_include_obj('register');
143 $content=$obj->run();
144 } else {
145 $obj=dbx()->get_include_obj('login');
146 $content = $this->alert('warning', 'Registrierung ist deaktiviert.') . $obj->run();
147 }
148 break;
149
150 case 'verify':
151 $content = $this->alert('info', 'Verifizierung ist noch nicht aktiv.');
152 break;
153
154
155 default:
156 $content = $this->alert('danger', 'Modul ' . $modul . ' run=(' . $run . ') is undef.');
157
158 }
159
160 return $content;
161 }
162
163 private function alert($type, $msg) {
164 $type = in_array($type, array('success', 'warning', 'info', 'danger'), true) ? $type : 'info';
165 $tpl = dbx()->get_system_obj('dbxTPL');
166
167 return $tpl->get_tpl('dbx|alert-' . $type, array('msg' => $msg));
168 }
169}
DBX schema administration.
$_SERVER['REQUEST_URI']