Skip to content

Commit e2ab87e

Browse files
committed
19 Jun 2023
1) Removed debug option from fetch calls in PAGE-cb.js. Will always console.error() by default. 2) Slight changes to installer - Will not start if mod_rewrite is not enabled.
1 parent 8a5965c commit e2ab87e

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

assets/PAGE-cb.js

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var cb = {
7676

7777
// (B4) CHANGE "LOCAL" PAGE
7878
// num : int, page number (1 to 5)
79-
page : num => { for (let i in cb.hPages) {
79+
page : num => { num--; for (let i in cb.hPages) {
8080
if (i==num) { cb.hPages[i].classList.remove("d-none"); }
8181
else { cb.hPages[i].classList.add("d-none"); }
8282
}},
@@ -88,15 +88,13 @@ var cb = {
8888
// url : string, target URL
8989
// data : optional object, data to send
9090
// loading : boolean, show "now loading" screen? default true.
91-
// debug : boolean, debug mode. default false.
9291
// onpass : function, run this function on server response
9392
// onerr : optional function, run this function on error
9493
ajax : opt => {
9594
// (C1) CHECKS & DEFAULTS
9695
if (opt.url === undefined) { cb.modal("AJAX ERROR", "Target URL is not set!"); return false; }
9796
if (opt.onpass === undefined) { cb.modal("AJAX ERROR", "Function to call on onpass is not set!"); return false; }
9897
if (opt.loading === undefined) { opt.loading = true; }
99-
if (opt.debug === undefined) { opt.debug = false; }
10098

10199
// (C2) DATA TO SEND
102100
var data = new FormData();
@@ -105,19 +103,16 @@ var cb = {
105103
// (C3) AJAX REQUEST
106104
if (opt.loading) { cb.loading(true); }
107105
fetch(opt.url, { method:"POST", credentials:"include", body:data })
108-
.then(res => {
109-
if (opt.debug) { console.log(res); }
106+
.then(async res => {
110107
if (res.status==200) { return res.text(); }
111108
else {
109+
console.error(await res.text());
112110
cb.modal("SERVER ERROR", "Bad server response - " + res.status);
113-
console.error(res.status, res);
114111
if (opt.onerr) { opt.onerr(); }
112+
throw new Error("Bad server response");
115113
}
116114
})
117-
.then(txt => {
118-
if (opt.debug) { console.log(txt); }
119-
opt.onpass(txt);
120-
})
115+
.then(txt => opt.onpass(txt))
121116
.catch(err => {
122117
cb.modal("AJAX ERROR", err.message);
123118
console.error(err);
@@ -130,10 +125,9 @@ var cb = {
130125

131126
// (D) AJAX API CALL
132127
// mod : string, module to call
133-
// req : string, request
128+
// act : string, action to perform
134129
// data : object, data to send
135130
// loading : boolean, show loading screen?
136-
// debug : boolean, optional debug mode. default false.
137131
// passmsg : boolean false to supress toast "success message".
138132
// boolean true to use server response message.
139133
// string to override "OK" message.
@@ -144,34 +138,33 @@ var cb = {
144138
api : opt => {
145139
// (D1) INIT OPTIONS
146140
var options = {};
147-
options.url = `${cbhost.api}${opt.mod}/${opt.req}/`;
141+
options.url = `${cbhost.api}${opt.mod}/${opt.act}/`;
148142
if (opt.data) { options.data = opt.data; }
149143
if (opt.loading!=undefined) { options.loading = opt.loading; }
150-
if (opt.debug!=undefined) { options.debug = opt.debug; }
151144
if (opt.onerr) { options.onerr = opt.onerr; }
152145
if (opt.passmsg === undefined) { opt.passmsg = "OK"; }
153146
if (opt.nofail === undefined) { opt.nofail = false; }
154147

155148
// (D2) ON AJAX LOAD
156149
options.onpass = res => {
157150
// (D2-1) PARSE RESULTS
158-
try { var res = JSON.parse(res); }
151+
try { var r = JSON.parse(res); }
159152
catch (err) {
160153
console.error(res);
161154
cb.modal("AJAX ERROR", "Failed to parse JSON data.");
162155
return false;
163156
}
164157

165158
// (D2-2) RESULTS FEEBACK
166-
if (res.status=="E") { location.href = cbhost.base + "login/"; }
167-
else if (res.status) {
159+
if (r.status=="E") { location.href = cbhost.base + "login/"; }
160+
else if (r.status) {
168161
if (opt.passmsg !== false) {
169-
cb.toast(1, "Success", opt.passmsg===true ? res.message : opt.passmsg);
162+
cb.toast(1, "Success", opt.passmsg===true ? r.message : opt.passmsg);
170163
}
171-
if (opt.onpass) { opt.onpass(res); }
164+
if (opt.onpass) { opt.onpass(r); }
172165
} else {
173-
if (!opt.nofail) { cb.modal("ERROR", res.message); }
174-
if (opt.onfail) { opt.onfail(res.message); }
166+
if (!opt.nofail) { cb.modal("ERROR", r.message); }
167+
if (opt.onfail) { opt.onfail(r.message); }
175168
}
176169
};
177170

@@ -184,23 +177,21 @@ var cb = {
184177
// target : string, ID of target HTML element
185178
// data : object, data to send
186179
// loading : boolean, show loading screen? Default false.
187-
// debug : boolean, optional debug mode. default false.
188180
// onload : optional function, do this on loaded
189181
// onerr : optional function, do this on ajax error
190182
load : opt => {
191183
// (E1) INIT OPTIONS
192184
var options = {};
193185
options.url = `${cbhost.base}${opt.page}/`;
194186
if (opt.loading!=undefined) { options.loading = opt.loading; }
195-
if (opt.debug!=undefined) { options.debug = opt.debug; }
196187
if (opt.onerr) { options.onerr = opt.onerr; }
197188
if (opt.data) {
198189
opt.data["ajax"] = 1;
199190
options.data = opt.data;
200191
} else { options.data = { "ajax" : 1 }; }
201192

202193
// (E2) ON AJAX LOAD
203-
options.onpass = (res) => {
194+
options.onpass = res => {
204195
if (res=="E") { location.href = cbhost.base + "login/"; }
205196
else {
206197
document.getElementById(opt.target).innerHTML = res;
@@ -214,7 +205,7 @@ var cb = {
214205

215206
// (F) SIGN OFF
216207
bye : () => cb.modal("Please Confirm", "Sign off?", () => cb.api({
217-
mod : "session", req : "logout", passmsg : false,
208+
mod : "session", act : "logout", passmsg : false,
218209
onpass : () => location.href = cbhost.base + "login/"
219210
})),
220211

lib/CORE-Install.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@ function import ($pdo, $from=0) {
7070
exit("At least PHP ".I_MIN_PHP." is required. You are using ".PHP_VERSION);
7171
}
7272

73-
// (B2-2) MYSQL PDO
73+
// (B2-2) MOD REWRITE
74+
if (I_APACHE && !I_REWRITE) { exit("Please enable Apache MOD_REWRITE"); }
75+
76+
// (B2-3) MYSQL PDO
7477
if (I_PDO===false) { exit("PDO MYSQL extension is not enabled."); }
7578

76-
// (B2-3) OPENSSL
79+
// (B2-4) OPENSSL
7780
if (I_PUSH && I_OPENSSL===false) { exit("OPENSSL extension is not enabled."); }
7881

79-
// (B2-4) FILES & FOLDERS - READ/WRITE PERMISSIONS
82+
// (B2-5) FILES & FOLDERS - READ/WRITE PERMISSIONS
8083
foreach (I_ALL as $p) {
8184
if (!file_exists($p)) { exit("$p does not exist!"); }
8285
if (!is_readable($p)) { exit("Please give PHP read permission to $p"); }
@@ -265,10 +268,11 @@ function import ($pdo, $from=0) {
265268
<?php if (I_APACHE === false || I_REWRITE === false) { ?>
266269
<!-- (DD8) WARNINGS -->
267270
<div class="danger">
268-
The installer cannot verify if you are running Apache Web Server, or if <code>MOD_REWRITE</code> is enabled.
269-
You can still try to proceed if you want.
270-
If you are not running Apache, you need to create your own "translated" <code>.htaccess</code> file.
271-
See <code>lib/LIB-Route.php &gt; function init()</code>.
271+
If you are running Apache Web Server - Please enable <code>MOD_REWRITE</code>.
272+
</div>
273+
<div class="danger">
274+
If you are not running Apache Web Server, you can still try to proceed.
275+
After the installation, "translate" your own <code>.htaccess</code> file.
272276
</div>
273277
<?php } ?>
274278

0 commit comments

Comments
 (0)