Repository navigation
Expand file tree
/
Copy pathphpbb_settings.php
More file actions
202 lines (159 loc) · 8.03 KB
/
Copy pathphpbb_settings.php
File metadata and controls
202 lines (159 loc) · 8.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
//
// phpbb_integration, its page in the control panel: ?cp=phpbb_settings
//
// not for directly open
if (!defined('IN_ADMIN')) {
exit();
}
include_once __DIR__ . '/phpbb_test.php';
//current template
$stylee = 'admin_phpbb_settings';
$styleePath = __DIR__;
// the integration decides who signs in and who is a founder, so only a founder changes it, like the plugins
if ((int) ($userinfo['founder'] ?? 0) !== 1) {
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS'], basename(ADMIN_PATH));
}
// template variables
$action = basename(ADMIN_PATH) . '?cp=phpbb_settings';
$phpbb_bridge_url = $action . '&case=bridge';
$phpbb_test_url = $action . '&case=test';
$H_FORM_KEYS = kleeja_add_form_key('adm_phpbb_settings');
$phpbb_settings = phpbb_settings();
$phpbb_on = (int) $phpbb_settings['phpbb_intr_enabled'] === 1;
$phpbb_tab = in_array(g('case'), ['bridge', 'test'], true) ? g('case') : 'settings';
$phpbb_test_steps = $phpbb_errors = [];
$phpbb_alert = '';
$phpbb_alert_type = 'danger';
/**
* save settings, they are kept as they were typed, update_config() encodes them once.
* The settings are cached in a PHP file, and OPcache would run the old one for a while,
* or until PHP restarts on a server that doesn't check the files. OPcache finds a relative path only while it exists
*/
$phpbb_save = function (array $values): void {
$cached = PATH . 'cache/data_config.php';
if (function_exists('opcache_invalidate') && file_exists($cached)) {
@opcache_invalidate($cached, true);
}
foreach ($values as $name => $value) {
update_config($name, (string) $value);
}
};
$phpbb_passed = fn(array $steps): bool => !in_array('error', array_column($steps, 'status'), true);
if (ip('phpbb_action')) {
if (!kleeja_check_form_key('adm_phpbb_settings', 3600)) {
kleeja_admin_err($lang['INVALID_FORM_KEY'], $action);
}
switch (p('phpbb_action')) {
// the test of the saved settings
case 'test':
$phpbb_tab = 'test';
$phpbb_test_steps = phpbb_integration_test($phpbb_settings);
break;
// it is turned on only when kjauth.php answers with the key.
// The account of the admin is a Kleeja one, the next page signs it out
case 'enable':
// the members would be sent to the example address to register and to get a new password
if (phpbb_forum_address_is_example($phpbb_settings)) {
$phpbb_tab = 'settings';
$phpbb_alert = phpbb_integration_word('PHPBB_INTR_ERR_LINK_DEFAULT');
break;
}
$phpbb_tab = 'test';
$phpbb_test_steps = phpbb_integration_test($phpbb_settings);
if ($phpbb_passed($phpbb_test_steps)) {
$phpbb_save(['phpbb_intr_enabled' => '1', 'phpbb_intr_notice' => '']);
kleeja_admin_info(phpbb_integration_word('PHPBB_INTR_TURNED_ON'), $action);
}
$phpbb_alert = phpbb_integration_word('PHPBB_INTR_NOT_TURNED_ON');
break;
case 'disable':
$phpbb_save(['phpbb_intr_enabled' => '0']);
kleeja_admin_info(phpbb_integration_word('PHPBB_INTR_TURNED_OFF'), $action);
break;
case 'save':
$posted = $phpbb_settings;
// p() encodes what it reads
foreach (['phpbb_intr_link', 'phpbb_intr_path'] as $name) {
$posted[$name] = ip($name) ? htmlspecialchars_decode(p($name), ENT_QUOTES) : $phpbb_settings[$name];
}
if (phpbb_forum_address($posted) === '') {
$phpbb_errors[] = 'PHPBB_INTR_ERR_LINK';
}
// while it is on, the members sign in through this address: a new one is saved only if kjauth.php answers there,
// or nobody could sign in, the admin neither
$changed = phpbb_forum_address($posted) !== phpbb_forum_address($phpbb_settings);
if (!$phpbb_errors && $phpbb_on && $changed) {
$phpbb_test_steps = phpbb_integration_test($posted);
if (!$phpbb_passed($phpbb_test_steps)) {
$phpbb_alert = phpbb_integration_word('PHPBB_INTR_NOT_SAVED');
}
}
if (!$phpbb_errors && $phpbb_alert === '') {
$phpbb_save([
'phpbb_intr_link' => trim($posted['phpbb_intr_link']),
'phpbb_intr_path' => trim($posted['phpbb_intr_path']),
]);
kleeja_admin_info($lang['CONFIGS_UPDATED'], $action);
}
// the form keeps what was typed, to be fixed
$phpbb_settings = $posted;
break;
// a new key, kjauth.php of the forum has to have it
case 'regenerate':
$phpbb_tab = 'bridge';
$posted = ['phpbb_intr_api_key' => phpbb_new_api_key()] + $phpbb_settings;
if (!$phpbb_on) {
$phpbb_save(['phpbb_intr_api_key' => $posted['phpbb_intr_api_key']]);
$written = phpbb_write_bridge($posted)['status'] === 'written';
kleeja_admin_info(
phpbb_integration_word($written ? 'PHPBB_INTR_KEY_CHANGED_WRITTEN' : 'PHPBB_INTR_KEY_CHANGED_COPY'),
$action . '&case=bridge',
);
}
// while it is on, the members sign in with the key: Kleeja replaces kjauth.php itself,
// and keeps the new key only when kjauth.php answers with it
if (phpbb_write_bridge($posted)['status'] !== 'written') {
$phpbb_alert = phpbb_integration_word('PHPBB_INTR_KEY_NOT_CHANGED_FOLDER');
break;
}
$phpbb_test_steps = phpbb_integration_test($posted);
// the login cookie of the admin has a token of the old key, the next page signs it out
if ($phpbb_passed($phpbb_test_steps)) {
$phpbb_save(['phpbb_intr_api_key' => $posted['phpbb_intr_api_key']]);
kleeja_admin_info(phpbb_integration_word('PHPBB_INTR_KEY_CHANGED_ON'), $action . '&case=bridge');
}
// the file of the old key, the members sign in with it again, and the test says what failed
phpbb_write_bridge($phpbb_settings);
$phpbb_tab = 'test';
$phpbb_alert = phpbb_integration_word('PHPBB_INTR_KEY_NOT_CHANGED_TEST');
break;
}
}
// the form, its values are encoded once for HTML
$phpbb_form = array_map('kleeja_html_encode', $phpbb_settings);
$phpbb_tab_bridge = $phpbb_tab === 'bridge';
$phpbb_tab_test = $phpbb_tab === 'test';
$phpbb_tab_settings = !$phpbb_tab_bridge && !$phpbb_tab_test;
$phpbb_paused = $phpbb_on && defined('DISABLE_INTR');
$phpbb_notice = !$phpbb_on && $phpbb_settings['phpbb_intr_notice'] === 'bridge';
$phpbb_error_list = array_map(fn(string $word): array => ['text' => phpbb_integration_word($word)], $phpbb_errors);
// kjauth.php with the saved key, and where it goes
$phpbb_bridge_code = kleeja_html_encode(phpbb_bridge_code(phpbb_settings()));
$phpbb_bridge_folder = phpbb_forum_folder(phpbb_settings());
$phpbb_bridge_folder = $phpbb_bridge_folder === '' ? '' : kleeja_html_encode($phpbb_bridge_folder);
$phpbb_bridge_address = phpbb_forum_address(phpbb_settings());
$phpbb_bridge_address = $phpbb_bridge_address === '' ? '' : kleeja_html_encode($phpbb_bridge_address . '/kjauth.php');
$phpbb_key_confirm = phpbb_integration_word($phpbb_on ? 'PHPBB_INTR_KEY_NEW_CONFIRM_ON' : 'PHPBB_INTR_KEY_NEW_CONFIRM');
// the steps of the test, with the icon and the color of their status
$phpbb_test_passed = $phpbb_passed($phpbb_test_steps);
$phpbb_test_summary = phpbb_integration_word($phpbb_test_passed ? 'PHPBB_INTR_TEST_OK' : 'PHPBB_INTR_TEST_FAILED');
$phpbb_test_styles = [
'ok' => ['circle-check', 'success'],
'warning' => ['triangle-exclamation', 'warning'],
'error' => ['circle-xmark', 'danger'],
'skipped' => ['circle-minus', 'secondary'],
];
foreach ($phpbb_test_steps as $i => $step) {
[$phpbb_test_steps[$i]['icon'], $phpbb_test_steps[$i]['color']] = $phpbb_test_styles[$step['status']];
}