Skip to content

Commit

Permalink
NEW Add $dolibarr_main_db_readonly in conf.php for readonly access.
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 9, 2021
1 parent af8c973 commit 3fadd5c
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 7 deletions.
8 changes: 8 additions & 0 deletions htdocs/admin/system/dolibarr.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
'dolibarr_main_db_character_set' => $langs->trans("DBStoringCharset"),
'dolibarr_main_db_collation' => $langs->trans("DBSortingCollation"),
'?dolibarr_main_db_prefix' => $langs->trans("DatabasePrefix"),
'dolibarr_main_db_readonly' => $langs->trans("ReadOnlyMode"),
'separator2' => '',
'dolibarr_main_authentication' => $langs->trans("AuthenticationMode"),
'?multicompany_transverse_mode'=> $langs->trans("MultiCompanyMode"),
Expand Down Expand Up @@ -449,6 +450,13 @@
if (!empty($valuetoshow)) {
print img_warning($langs->trans('SwitchThisForABetterSecurity', 0));
}
} elseif ($newkey == 'dolibarr_main_db_readonly') {
print ${$newkey};

$valuetoshow = ${$newkey};
if (!empty($valuetoshow)) {
print img_warning($langs->trans('ReadOnlyMode', 1));
}
} else {
print (empty(${$newkey}) ? '' : ${$newkey});
}
Expand Down
9 changes: 9 additions & 0 deletions htdocs/conf/conf.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ $dolibarr_main_db_character_set='utf8';
$dolibarr_main_db_collation='utf8_unicode_ci';


// dolibarr_main_db_readonly
// Set this to 1 to have the application working in readonly mode. All sql access INSERT/UPDATE/DELETE/CREATE/ALTER/TRUNCATE/DROP will be disabled.
// Default value: 0
// Examples:
// $dolibarr_main_db_readonly='0';
//
$dolibarr_main_db_readonly=0;


// dolibarr_main_instance_unique_id
// An secret ID that is unique for each installation.
// This value is also visible and never propagated outside of Dolibarr, so it can be used as a salt / key for some encryption.
Expand Down
11 changes: 10 additions & 1 deletion htdocs/core/db/mysqli.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function close()
*/
public function query($query, $usesavepoint = 0, $type = 'auto')
{
global $conf;
global $conf, $dolibarr_main_db_readonly;

$query = trim($query);

Expand All @@ -278,6 +278,15 @@ public function query($query, $usesavepoint = 0, $type = 'auto')
return false; // Return false = error if empty request
}

if (!empty($dolibarr_main_db_readonly)) {
if (preg_match('/^(INSERT|UPDATE|DELETE|CREATE|ALTER|TRUNCATE|DROP)/i', $query)) {
$this->lasterror = 'Application in read-only mode';
$this->lasterrno = 'APPREADONLY';
$this->lastquery = $query;
return false;
}
}

if (!$this->database_name) {
// Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE)
$ret = $this->db->query($query);
Expand Down
14 changes: 13 additions & 1 deletion htdocs/core/db/pgsql.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public function close()
*/
public function query($query, $usesavepoint = 0, $type = 'auto')
{
global $conf;
global $conf, $dolibarr_main_db_readonly;

$query = trim($query);

Expand Down Expand Up @@ -527,6 +527,18 @@ public function query($query, $usesavepoint = 0, $type = 'auto')
$SYSLOG_SQL_LIMIT = 10000; // limit log to 10kb per line to limit DOS attacks
dol_syslog('sql='.substr($query, 0, $SYSLOG_SQL_LIMIT), LOG_DEBUG);
}
if (empty($query)) {
return false; // Return false = error if empty request
}

if (!empty($dolibarr_main_db_readonly)) {
if (preg_match('/^(INSERT|UPDATE|DELETE|CREATE|ALTER|TRUNCATE|DROP)/i', $query)) {
$this->lasterror = 'Application in read-only mode';
$this->lasterrno = 'APPREADONLY';
$this->lastquery = $query;
return false;
}
}

$ret = @pg_query($this->db, $query);

Expand Down
11 changes: 10 additions & 1 deletion htdocs/core/db/sqlite3.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public function close()
*/
public function query($query, $usesavepoint = 0, $type = 'auto')
{
global $conf;
global $conf, $dolibarr_main_db_readonly;

$ret = null;

Expand Down Expand Up @@ -455,6 +455,15 @@ public function query($query, $usesavepoint = 0, $type = 'auto')
return false; // Return false = error if empty request
}

if (!empty($dolibarr_main_db_readonly)) {
if (preg_match('/^(INSERT|UPDATE|DELETE|CREATE|ALTER|TRUNCATE|DROP)/i', $query)) {
$this->lasterror = 'Application in read-only mode';
$this->lasterrno = 'APPREADONLY';
$this->lastquery = $query;
return false;
}
}

// Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE)
try {
//$ret = $this->db->exec($query);
Expand Down
8 changes: 4 additions & 4 deletions scripts/accountancy/export-thirdpartyaccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@
$date_start = dol_get_first_day($year_start, 10, false);
$date_end = dol_get_last_day($year_start, 12, false);
}
} else {
}

/*
* Main
*/

llxHeader();

$form = new Form($db);
Expand Down Expand Up @@ -186,9 +189,6 @@ function launch_export()
$i++;
}

/*
* View
*/

$thirdpartystatic = new Societe($db);

Expand Down
5 changes: 5 additions & 0 deletions scripts/company/sync_contacts_dolibarr2ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@

$now = $argv[1];

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-onyl mode\n";
exit(-1);
}

print "Mails sending disabled (useless in batch mode)\n";
$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails
print "\n";
Expand Down
5 changes: 5 additions & 0 deletions scripts/cron/cron_run_jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
exit(-1);
}

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-only mode\n";
exit(-1);
}

// If param userlogin is reserved word 'firstadmin'
if ($userlogin == 'firstadmin') {
$sql = 'SELECT login, entity from '.MAIN_DB_PREFIX.'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1';
Expand Down
5 changes: 5 additions & 0 deletions scripts/emailings/mailing-send.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
if ($conf->global->MAILING_LIMIT_SENDBYCLI == '-1') {
}

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-only mode\n";
exit(-1);
}

$user = new User($db);
// for signature, we use user send as parameter
if (!empty($login)) {
Expand Down
6 changes: 6 additions & 0 deletions scripts/emailings/reset-invalid-emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
$version = DOL_VERSION;
$error = 0;


/*
* Main
*/
Expand All @@ -71,6 +72,11 @@
exit(-1);
}

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-onyl mode\n";
exit(-1);
}

$db->begin();


Expand Down
5 changes: 5 additions & 0 deletions scripts/invoices/email_unpaid_invoices_to_customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
}

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-onyl mode\n";
exit(-1);
}

$sql = "SELECT f.ref, f.total_ttc, f.date_lim_reglement as due_date,";
$sql .= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
if ($targettype == 'contacts') {
Expand Down
5 changes: 5 additions & 0 deletions scripts/invoices/email_unpaid_invoices_to_representatives.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
}

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-onyl mode\n";
exit(-1);
}

$sql = "SELECT f.ref, f.total_ttc, f.date_lim_reglement as due_date, s.nom as name, s.email, s.default_lang,";
$sql .= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
Expand Down
6 changes: 6 additions & 0 deletions scripts/invoices/rebuild_merge_pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
$version = DOL_VERSION;
$error = 0;


/*
* Main
*/
Expand All @@ -66,6 +67,11 @@
exit(-1);
}

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-onyl mode\n";
exit(-1);
}

$diroutputpdf = $conf->facture->dir_output.'/temp';
$newlangid = 'en_EN'; // To force a new lang id
$filter = array();
Expand Down
5 changes: 5 additions & 0 deletions scripts/members/sync_members_dolibarr2ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
}
}

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-onyl mode\n";
exit(-1);
}

$now = $argv[1];

print "Mails sending disabled (useless in batch mode)\n";
Expand Down
5 changes: 5 additions & 0 deletions scripts/members/sync_members_ldap2dolibarr.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
exit(-2);
}

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-onyl mode\n";
exit(-1);
}

if (!$confirmed) {
print "Hit Enter to continue or CTRL+C to stop...\n";
$input = trim(fgets(STDIN));
Expand Down
6 changes: 6 additions & 0 deletions scripts/members/sync_members_types_dolibarr2ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
* }
*/

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-onyl mode\n";
exit(-1);
}


$sql = "SELECT rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."adherent_type";

Expand Down
5 changes: 5 additions & 0 deletions scripts/members/sync_members_types_ldap2dolibarr.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
}
}

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-onyl mode\n";
exit(-1);
}

print "Mails sending disabled (useless in batch mode)\n";
$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails
print "\n";
Expand Down
10 changes: 10 additions & 0 deletions scripts/website/migrate-news-joomla2dolibarr.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,18 @@
include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';


/*
* Main
*/

$langs->load('main');

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-onyl mode\n";
exit(-1);
}

$joomlaserverinfoarray = preg_split('/(:|@|\/)/', $joomlaserverinfo);
$joomlalogin = $joomlaserverinfoarray[0];
$joomlapass = $joomlaserverinfoarray[1];
Expand Down
10 changes: 10 additions & 0 deletions scripts/website/regenerate-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@
include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';


/*
* Main
*/

$langs->load('main');

if (!empty($dolibarr_main_db_readonly)) {
print "Error: instance in read-onyl mode\n";
exit(-1);
}

$website = new Website($db);
$result = $website->fetch(0, $websiteref);
if ($result <= 0) {
Expand Down

0 comments on commit 3fadd5c

Please sign in to comment.