Compare commits

...

4 Commits

7 changed files with 233 additions and 427 deletions

View File

@ -1,11 +1,19 @@
# Generated file from class.acl.php # Generated file from class.acl.php
# For detection of htaccess functionality
SetEnv OPENXE_HTACCESS on
# Disable directory browsing # Disable directory browsing
Options -Indexes Options -Indexes
# Set default page to index.php
DirectoryIndex "index.php"
# Deny general access
Order deny,allow Order deny,allow
<FilesMatch ".">
Order Allow,Deny
Deny from all Deny from all
</FilesMatch>
# Allow index.php
<Files "index.php"> <Files "index.php">
Order Allow,Deny Order Allow,Deny
Allow from all Allow from all
</Files> </Files>
# end

View File

@ -571,6 +571,9 @@ class Acl
public function Login() public function Login()
{ {
include dirname(__DIR__).'/../version.php';
$this->app->Tpl->Set('XENTRALVERSION',"V.".$version_revision);
$result = $this->CheckHtaccess(); $result = $this->CheckHtaccess();
if ($result !== true) { if ($result !== true) {
$this->app->Tpl->Set('LOGINWARNING_TEXT', "Achtung: Zugriffskonfiguration (htaccess) fehlerhaft. Bitte wenden Sie sich an Ihren an Ihren Administrator. <br>($result)"); $this->app->Tpl->Set('LOGINWARNING_TEXT', "Achtung: Zugriffskonfiguration (htaccess) fehlerhaft. Bitte wenden Sie sich an Ihren an Ihren Administrator. <br>($result)");
@ -1217,37 +1220,47 @@ class Acl
// HTACCESS SECURITY // HTACCESS SECURITY
// Check for correct .htaccess settings // Check for correct .htaccess settings
// true if ok, else error text // true if ok, else error text
protected function CheckHtaccess() : mixed { protected function CheckHtaccess() {
$nominal = array( '# Generated file from class.acl.php $nominal = array('
# Generated file from class.acl.php
# For detection of htaccess functionality
SetEnv OPENXE_HTACCESS on
# Disable directory browsing # Disable directory browsing
Options -Indexes Options -Indexes
# Set default page to index.php
DirectoryIndex "index.php"
# Deny general access
Order deny,allow Order deny,allow
<FilesMatch ".">
Order Allow,Deny
Deny from all Deny from all
</FilesMatch>
# Allow index.php
<Files "index.php"> <Files "index.php">
Order Allow,Deny Order Allow,Deny
Allow from all Allow from all
</Files>', </Files>
'# Generated file from class.acl.php # end
SetEnv OPENXE_HTACCESS on ',
'
# Generated file from class.acl.php
# Disable directory browsing # Disable directory browsing
Options -Indexes Options -Indexes
# Deny access to all *.php
Order deny,allow Order deny,allow
Allow from all Allow from all
<FilesMatch "\.(css|jpg|jpeg|gif|png|svg|js)$">
<Files *.php>
Order Allow,Deny Order Allow,Deny
Deny from all Allow from all
</Files> </FilesMatch>
# Allow access to index.php
<Files index.php> <Files index.php>
Order Allow,Deny Order Allow,Deny
Allow from all Allow from all
</Files>'); </Files>
# end
');
$script_file_name = $_SERVER['SCRIPT_FILENAME']; $script_file_name = $_SERVER['SCRIPT_FILENAME'];
$htaccess_path = array( $htaccess_path = array(
@ -1255,22 +1268,23 @@ class Acl
dirname($script_file_name)."/.htaccess"); // www dirname($script_file_name)."/.htaccess"); // www
for ($count = 0;$count < 2;$count++) { for ($count = 0;$count < 2;$count++) {
$htaccess = file_get_contents($htaccess_path[$count]); $htaccess = trim(file_get_contents($htaccess_path[$count]));
if ($htacess === false) { $htaccess_nominal = trim($nominal[$count]);
return("FATAL: ".$htaccess_path[$count]." nicht gefunden");
$result = strcmp($htaccess,$htaccess_nominal);
if ($result !== 0) {
return("FATAL: ".$htaccess_path[$count]." fehlerhaft.");
}
if ($htaccess === false) {
return("FATAL: ".$htaccess_path[$count]." nicht vorhanden.");
}
} }
$result = strcmp(trim($htaccess[$count]),trim($nominal[$count]));
if ($result !== 0) {
$result = file_put_contents($htaccess_path[$count],$nominal[$count]);
if ($result === false) {
return("FATAL: ".$htaccess_path[$count]." fehlerhaft");
}
}
}
if (!isset($_SERVER['OPENXE_HTACCESS'])) { if (!isset($_SERVER['OPENXE_HTACCESS'])) {
return("FATAL: htaccess nicht aktiv."); return("FATAL: htaccess nicht aktiv.");
} }
return(true); return(true);
// HTACCESS SECURITY END // HTACCESS SECURITY END
} }

View File

@ -24308,328 +24308,6 @@
} }
] ]
}, },
{
"name": "belege",
"type": "VIEW",
"columns": [
{
"Field": "id",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": "0",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "adresse",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": "0",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "datum",
"Type": "date",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": "0000-00-00",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "belegnr",
"Type": "varchar(255)",
"Collation": "utf8mb3_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "status",
"Type": "varchar(64)",
"Collation": "utf8mb3_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "land",
"Type": "varchar(255)",
"Collation": "utf8mb3_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "typ",
"Type": "varchar(10)",
"Collation": "utf8mb4_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "umsatz_netto",
"Type": "decimal(19,2)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": "0.00",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "erloes_netto",
"Type": "decimal(19,2)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": "0.00",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "deckungsbeitrag",
"Type": "decimal(11,2)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": "0.00",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "provision_summe",
"Type": "decimal(11,2)",
"Collation": null,
"Null": "YES",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "vertriebid",
"Type": "int(11)",
"Collation": null,
"Null": "YES",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "gruppe",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": "0",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
}
],
"keys": []
},
{
"name": "belegegesamt",
"type": "VIEW",
"columns": [
{
"Field": "id",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": "0",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "adresse",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": "0",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "datum",
"Type": "date",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": "0000-00-00",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "belegnr",
"Type": "varchar(255)",
"Collation": "utf8mb3_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "status",
"Type": "varchar(64)",
"Collation": "utf8mb3_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "land",
"Type": "varchar(255)",
"Collation": "utf8mb3_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "typ",
"Type": "varchar(12)",
"Collation": "utf8mb4_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "umsatz_netto",
"Type": "varchar(21)",
"Collation": "utf8mb4_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "umsatz_brutto",
"Type": "varchar(21)",
"Collation": "utf8mb4_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "erloes_netto",
"Type": "varchar(21)",
"Collation": "utf8mb4_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "deckungsbeitrag",
"Type": "varchar(13)",
"Collation": "utf8mb4_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "provision_summe",
"Type": "varchar(13)",
"Collation": "utf8mb4_general_ci",
"Null": "YES",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "vertriebid",
"Type": "varchar(11)",
"Collation": "utf8mb4_general_ci",
"Null": "YES",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "gruppe",
"Type": "varchar(11)",
"Collation": "utf8mb4_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "projekt",
"Type": "varchar(222)",
"Collation": "utf8mb3_general_ci",
"Null": "NO",
"Key": "",
"Default": "",
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
}
],
"keys": []
},
{ {
"name": "belegeimport", "name": "belegeimport",
"type": "BASE TABLE", "type": "BASE TABLE",
@ -114560,5 +114238,22 @@
} }
] ]
} }
],
"views": [
{
"name": "belege",
"type": "VIEW",
"Create": "CREATE ALGORITHM=UNDEFINED DEFINER=`openxe`@`localhost` SQL SECURITY DEFINER VIEW `belege` AS select `rechnung`.`id` AS `id`,`rechnung`.`adresse` AS `adresse`,`rechnung`.`datum` AS `datum`,`rechnung`.`belegnr` AS `belegnr`,`rechnung`.`status` AS `status`,`rechnung`.`land` AS `land`,'rechnung' AS `typ`,`rechnung`.`umsatz_netto` AS `umsatz_netto`,`rechnung`.`erloes_netto` AS `erloes_netto`,`rechnung`.`deckungsbeitrag` AS `deckungsbeitrag`,`rechnung`.`provision_summe` AS `provision_summe`,`rechnung`.`vertriebid` AS `vertriebid`,`rechnung`.`gruppe` AS `gruppe` from `rechnung` where `rechnung`.`status` <> 'angelegt' union all select `gutschrift`.`id` AS `id`,`gutschrift`.`adresse` AS `adresse`,`gutschrift`.`datum` AS `datum`,`gutschrift`.`belegnr` AS `belegnr`,`gutschrift`.`status` AS `status`,`gutschrift`.`land` AS `land`,'gutschrift' AS `typ`,`gutschrift`.`umsatz_netto` * -1 AS `umsatz_netto*-1`,`gutschrift`.`erloes_netto` * -1 AS `erloes_netto*-1`,`gutschrift`.`deckungsbeitrag` * -1 AS `deckungsbeitrag*-1`,`gutschrift`.`provision_summe` * -1 AS `provision_summe*-1`,`gutschrift`.`vertriebid` AS `vertriebid`,`gutschrift`.`gruppe` AS `gruppe` from `gutschrift` where `gutschrift`.`status` <> 'angelegt'"
},
{
"name": "belegegesamt",
"type": "VIEW",
"Create": "CREATE ALGORITHM=UNDEFINED DEFINER=`openxe`@`localhost` SQL SECURITY DEFINER VIEW `belegegesamt` AS select `rechnung`.`id` AS `id`,`rechnung`.`adresse` AS `adresse`,`rechnung`.`datum` AS `datum`,`rechnung`.`belegnr` AS `belegnr`,`rechnung`.`status` AS `status`,`rechnung`.`land` AS `land`,'rechnung' AS `typ`,`rechnung`.`umsatz_netto` AS `umsatz_netto`,`rechnung`.`soll` AS `umsatz_brutto`,`rechnung`.`erloes_netto` AS `erloes_netto`,`rechnung`.`deckungsbeitrag` AS `deckungsbeitrag`,`rechnung`.`provision_summe` AS `provision_summe`,`rechnung`.`vertriebid` AS `vertriebid`,`rechnung`.`gruppe` AS `gruppe`,`rechnung`.`projekt` AS `projekt` from `rechnung` union all select `gutschrift`.`id` AS `id`,`gutschrift`.`adresse` AS `adresse`,`gutschrift`.`datum` AS `datum`,`gutschrift`.`belegnr` AS `belegnr`,`gutschrift`.`status` AS `status`,`gutschrift`.`land` AS `land`,'gutschrift' AS `typ`,`gutschrift`.`umsatz_netto` * -1 AS `umsatz_netto*-1`,`gutschrift`.`soll` * -1 AS `umsatz_brutto*-1`,`gutschrift`.`erloes_netto` * -1 AS `erloes_netto*-1`,`gutschrift`.`deckungsbeitrag` * -1 AS `deckungsbeitrag*-1`,`gutschrift`.`provision_summe` * -1 AS `provision_summe*-1`,`gutschrift`.`vertriebid` AS `vertriebid`,`gutschrift`.`gruppe` AS `gruppe`,`gutschrift`.`projekt` AS `projekt` from `gutschrift` union all select `auftrag`.`id` AS `id`,`auftrag`.`adresse` AS `adresse`,`auftrag`.`datum` AS `datum`,`auftrag`.`belegnr` AS `belegnr`,`auftrag`.`status` AS `status`,`auftrag`.`land` AS `land`,'auftrag' AS `typ`,`auftrag`.`umsatz_netto` AS `umsatz_netto`,`auftrag`.`gesamtsumme` AS `umsatz_brutto`,`auftrag`.`erloes_netto` AS `erloes_netto`,`auftrag`.`deckungsbeitrag` AS `deckungsbeitrag`,`auftrag`.`provision_summe` AS `provision_summe`,`auftrag`.`vertriebid` AS `vertriebid`,`auftrag`.`gruppe` AS `gruppe`,`auftrag`.`projekt` AS `projekt` from `auftrag` union all select `bestellung`.`id` AS `id`,`bestellung`.`adresse` AS `adresse`,`bestellung`.`datum` AS `datum`,`bestellung`.`belegnr` AS `belegnr`,`bestellung`.`status` AS `status`,`bestellung`.`land` AS `land`,'bestellung' AS `typ`,`bestellung`.`gesamtsumme` AS `umsatz_netto`,`bestellung`.`gesamtsumme` AS `umsatz_brutto`,'0' AS `erloes_netto`,'0' AS `deckungsbeitrag`,'0' AS `provision_summe`,'0' AS `vertriebid`,'0' AS `gruppe`,`bestellung`.`projekt` AS `projekt` from `bestellung` union all select `lieferschein`.`id` AS `id`,`lieferschein`.`adresse` AS `adresse`,`lieferschein`.`datum` AS `datum`,`lieferschein`.`belegnr` AS `belegnr`,`lieferschein`.`status` AS `status`,`lieferschein`.`land` AS `land`,'lieferschein' AS `typ`,'0' AS `umsatz_netto`,'0' AS `umsatz_brutto`,'0' AS `erloes_netto`,'0' AS `deckungsbeitrag`,'0' AS `provision_summe`,'0' AS `vertriebid`,'0' AS `gruppe`,`lieferschein`.`projekt` AS `projekt` from `lieferschein` union all select `angebot`.`id` AS `id`,`angebot`.`adresse` AS `adresse`,`angebot`.`datum` AS `datum`,`angebot`.`belegnr` AS `belegnr`,`angebot`.`status` AS `status`,`angebot`.`land` AS `land`,'angebot' AS `typ`,`angebot`.`umsatz_netto` AS `umsatz_netto`,`angebot`.`gesamtsumme` AS `umsatz_brutto`,'0' AS `erloes_netto`,`angebot`.`deckungsbeitrag` AS `deckungsbeitrag`,'0' AS `provision_summe`,`angebot`.`vertriebid` AS `vertriebid`,'0' AS `gruppe`,`angebot`.`projekt` AS `projekt` from `angebot`"
},
{
"name": "belegeregs",
"type": "VIEW",
"Create": "CREATE ALGORITHM=UNDEFINED DEFINER=`openxe`@`localhost` SQL SECURITY DEFINER VIEW `belegeregs` AS select `rechnung`.`id` AS `id`,`rechnung`.`adresse` AS `adresse`,`rechnung`.`datum` AS `datum`,`rechnung`.`belegnr` AS `belegnr`,`rechnung`.`status` AS `status`,`rechnung`.`land` AS `land`,'rechnung' AS `typ`,`rechnung`.`umsatz_netto` AS `umsatz_netto`,`rechnung`.`erloes_netto` AS `erloes_netto`,`rechnung`.`deckungsbeitrag` AS `deckungsbeitrag`,`rechnung`.`provision_summe` AS `provision_summe`,`rechnung`.`vertriebid` AS `vertriebid`,`rechnung`.`gruppe` AS `gruppe`,`rechnung`.`projekt` AS `projekt` from `rechnung` union all select `gutschrift`.`id` AS `id`,`gutschrift`.`adresse` AS `adresse`,`gutschrift`.`datum` AS `datum`,`gutschrift`.`belegnr` AS `belegnr`,`gutschrift`.`status` AS `status`,`gutschrift`.`land` AS `land`,'gutschrift' AS `typ`,`gutschrift`.`umsatz_netto` * -1 AS `umsatz_netto*-1`,`gutschrift`.`erloes_netto` * -1 AS `erloes_netto*-1`,`gutschrift`.`deckungsbeitrag` * -1 AS `deckungsbeitrag*-1`,`gutschrift`.`provision_summe` * -1 AS `provision_summe*-1`,`gutschrift`.`vertriebid` AS `vertriebid`,`gutschrift`.`gruppe` AS `gruppe`,`gutschrift`.`projekt` AS `projekt` from `gutschrift`"
}
] ]
} }

View File

@ -68,7 +68,6 @@ if (php_sapi_name() == "cli") {
if ($cli) { if ($cli) {
$check_git = false; $check_git = false;
$do_git = false; $do_git = false;
$check_db = false; $check_db = false;
@ -83,6 +82,12 @@ if ($cli) {
$verbose = false; $verbose = false;
} }
if (in_array('-e', $argv)) {
$export_db = true;
} else {
$export_db = false;
}
if (in_array('-f', $argv)) { if (in_array('-f', $argv)) {
$force = true; $force = true;
} else { } else {
@ -112,14 +117,8 @@ if ($cli) {
} }
} }
if (in_array('-utf8fix', $argv)) {
$utf8fix = true;
} else {
$utf8fix = false;
}
if ($check_git || $check_db || $do_git || $do_db) { if ($check_git || $check_db || $do_git || $do_db) {
upgrade_main($directory,$verbose,$check_git,$do_git,$check_db,$do_db,$force); upgrade_main($directory,$verbose,$check_git,$do_git,$export_db,$check_db,$do_db,$force);
} else { } else {
info(); info();
} }
@ -131,7 +130,7 @@ if ($cli) {
} }
// -------------------------------- END // -------------------------------- END
function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do_git, bool $check_db, bool $do_db, bool $force) { function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do_git, bool $export_db, bool $check_db, bool $do_db, bool $force) {
class DatabaseConnectionInfo { class DatabaseConnectionInfo {
function __construct($dir) { function __construct($dir) {
@ -279,14 +278,25 @@ function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do
} // Dry run } // Dry run
} // $check_git } // $check_git
if ($check_db || $do_db) { if ($check_db || $do_db || $export_db) {
echo_out("--------------- Loading from database '$schema@$host'... ---------------\n"); echo_out("--------------- Loading from database '$schema@$host'... ---------------\n");
$db_def = mustal_load_tables_from_db($host, $schema, $user, $passwd, $mustal_replacers); $db_def = mustal_load_tables_from_db($host, $schema, $user, $passwd, $mustal_replacers);
if (empty($db_def)) { if (empty($db_def)) {
echo ("Could not load from $schema@$host\n"); echo_out("Could not load from $schema@$host\n");
exit; exit;
} }
if ($export_db) {
$export_file_name = "exported_db_schema.json";
if (mustal_save_tables_to_json($db_def, $datafolder, $export_file_name, true) == 0) {
echo_out("Database exported to $datafolder/$export_file_name\n");
}
else {
echo_out("Could not export database to $datafolder/$export_file_name\n");
}
}
$compare_differences = array(); $compare_differences = array();
echo_out("--------------- Loading from JSON... ---------------\n"); echo_out("--------------- Loading from JSON... ---------------\n");
@ -296,10 +306,9 @@ function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do
abort("Could not load from JSON $schema_file_name\n"); abort("Could not load from JSON $schema_file_name\n");
return(-1); return(-1);
} }
echo_out("--------------- Comparing database '$schema@$host' vs. JSON '".$compare_def['database']."@".$compare_def['host']."' ---------------\n"); echo_out("Table count database ".count($db_def['tables'])." vs. JSON ".count($compare_def['tables'])."\n");
echo_out("--------------- Comparing JSON '".$compare_def['database']."@".$compare_def['host']."' vs. database '$schema@$host' ---------------\n");
$compare_differences = mustal_compare_table_array($compare_def,"in JSON",$db_def,"in DB",true,true); $compare_differences = mustal_compare_table_array($db_def,"in DB",$compare_def,"in JSON",false,true);
if ($verbose) { if ($verbose) {
foreach ($compare_differences as $compare_difference) { foreach ($compare_differences as $compare_difference) {
$comma = ""; $comma = "";
@ -310,7 +319,20 @@ function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do
echo_out("\n"); echo_out("\n");
} }
} }
echo_out((empty($compare_differences)?0:count($compare_differences))." differences.\n");
echo_out("--------------- Comparing database '$schema@$host' vs. JSON '".$compare_def['database']."@".$compare_def['host']."' ---------------\n");
$compare_differences = mustal_compare_table_array($compare_def,"in JSON",$db_def,"in DB",true,true);
if ($verbose) {
foreach ($compare_differences as $compare_difference) {
$comma = "";
foreach ($compare_difference as $key => $value) {
echo_out($comma."$key => [$value]");
$comma = ", ";
}
echo_out("\n");
}
}
echo_out((empty($compare_differences)?0:count($compare_differences))." differences.\n"); echo_out((empty($compare_differences)?0:count($compare_differences))." differences.\n");
echo_out("--------------- Calculating database upgrade for '$schema@$host'... ---------------\n"); echo_out("--------------- Calculating database upgrade for '$schema@$host'... ---------------\n");
@ -322,7 +344,7 @@ function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do
abort(count($result)." errors.\n"); abort(count($result)." errors.\n");
if ($verbose) { if ($verbose) {
foreach($result as $error) { foreach($result as $error) {
echo_out("Code: ".$error[0]." '".$error[1]."'."); echo_out("Code: ".$error[0]." '".$error[1]."'\n");
} }
} }
return(-1); return(-1);
@ -409,10 +431,10 @@ function info() {
echo_out("Options:\n"); echo_out("Options:\n");
echo_out("\t-s: check/do system upgrades\n"); echo_out("\t-s: check/do system upgrades\n");
echo_out("\t-db: check/do database upgrades\n"); echo_out("\t-db: check/do database upgrades\n");
echo_out("\t-e: export database schema\n");
echo_out("\t-do: execute all upgrades\n"); echo_out("\t-do: execute all upgrades\n");
echo_out("\t-v: verbose output\n"); echo_out("\t-v: verbose output\n");
echo_out("\t-f: force override of existing files\n"); echo_out("\t-f: force override of existing files\n");
echo_out("\t-utf8fix: apply fix for 'utf8' != 'utf8mb3'\n");
echo_out("\t-clean: (not yet implemented) create the needed SQL to remove items from the database not in the JSON\n"); echo_out("\t-clean: (not yet implemented) create the needed SQL to remove items from the database not in the JSON\n");
echo_out("\n"); echo_out("\n");
} }

View File

@ -79,8 +79,7 @@ function mustal_load_tables_from_db(string $host, string $schema, string $user,
} }
// Get db_def and views // Get db_def and views
$sql = "SHOW FULL tables WHERE Table_type = 'BASE TABLE'";
$sql = "SHOW FULL tables";
$query_result = mysqli_query($mysqli, $sql); $query_result = mysqli_query($mysqli, $sql);
if (!$query_result) { if (!$query_result) {
return(array()); return(array());
@ -149,11 +148,34 @@ function mustal_load_tables_from_db(string $host, string $schema, string $user,
} }
unset($table); unset($table);
$sql = "SHOW FULL tables WHERE Table_type = 'VIEW'";
$query_result = mysqli_query($mysqli, $sql);
if (!$query_result) {
return(array());
}
while ($row = mysqli_fetch_assoc($query_result)) {
$view = array();
$view['name'] = $row['Tables_in_'.$schema];
$view['type'] = $row['Table_type'];
$views[] = $view; // Add view to list of views
}
foreach ($views as &$view) {
$sql = "SHOW CREATE VIEW ".$view['name'];
$query_result = mysqli_query($mysqli, $sql);
if (!$query_result) {
return(array());
}
$viewdef = mysqli_fetch_assoc($query_result);
$view['Create'] = $viewdef['Create View'];
}
$result = array(); $result = array();
$result['host'] = $host; $result['host'] = $host;
$result['database'] = $schema; $result['database'] = $schema;
$result['user'] = $user; $result['user'] = $user;
$result['tables'] = $tables; $result['tables'] = $tables;
$result['views'] = $views;
return($result); return($result);
} }
@ -217,15 +239,6 @@ function mustal_compare_table_array(array $nominal, string $nominal_name, array
$column_collation_aliases = array(); $column_collation_aliases = array();
} }
if (count($nominal['tables']) != count($actual['tables'])) {
$compare_difference = array();
$compare_difference['type'] = "Table count";
$compare_difference[$nominal_name] = count($nominal['tables']);
$compare_difference[$actual_name] = count($actual['tables']);
$compare_differences[] = $compare_difference;
}
foreach ($nominal['tables'] as $database_table) { foreach ($nominal['tables'] as $database_table) {
$found_table = array(); $found_table = array();
@ -353,6 +366,33 @@ function mustal_compare_table_array(array $nominal, string $nominal_name, array
} }
unset($database_table); unset($database_table);
foreach ($nominal['views'] as $database_view) {
$found_view = array();
foreach ($actual['views'] as $compare_view) {
if ($database_view['name'] == $compare_view['name']) {
$found_view = $compare_view;
break;
}
}
unset($compare_view);
if ($found_view) {
if ($database_view['Create'] != $found_view['Create']) {
$compare_difference = array();
$compare_difference['type'] = "View definition";
$compare_difference[$nominal_name] = $database_view['name'];
$compare_differences[] = $compare_difference;
}
} else {
$compare_difference = array();
$compare_difference['type'] = "View existence";
$compare_difference[$nominal_name] = $database_view['name'];
$compare_differences[] = $compare_difference;
}
}
return($compare_differences); return($compare_differences);
} }
@ -486,6 +526,9 @@ function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$
$compare_differences = mustal_compare_table_array($compare_def,"in JSON",$db_def,"in DB",true,true); $compare_differences = mustal_compare_table_array($compare_def,"in JSON",$db_def,"in DB",true,true);
foreach ($compare_differences as $compare_difference) { foreach ($compare_differences as $compare_difference) {
$drop_view = false;
switch ($compare_difference['type']) { switch ($compare_difference['type']) {
case 'Table existence': case 'Table existence':
@ -657,6 +700,35 @@ function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$
case 'Table type': case 'Table type':
$result[] = array(11,"Upgrade type '".$compare_difference['type']."' on table '".$compare_difference['table']."' not supported."); $result[] = array(11,"Upgrade type '".$compare_difference['type']."' on table '".$compare_difference['table']."' not supported.");
break; break;
case 'View definition':
$drop_view = true;
// intentionally omitted break;
case 'View existence':
$view_name = $compare_difference['in JSON'];
$view_key = array_search($view_name,array_column($compare_def['views'],'name'));
if ($view_key !== false) {
$view = $compare_def['views'][$view_key];
switch ($view['type']) {
case 'VIEW':
if ($drop_view === true) {
$sql = "DROP VIEW ".$view['name'];
$upgrade_sql[] = $sql;
}
// Create view in DB
$upgrade_sql[] = $view['Create'];
break;
default:
$result[] = array(1,"Upgrade type '".$view['type']."' on view '".$view['name']."' not supported.");
break;
}
} else {
$result[] = array(2,"Error view_key while creating upgrade for view existence `$view_name`.");
}
break;
default: default:
$result[] = array(12,"Upgrade type '".$compare_difference['type']."' not supported."); $result[] = array(12,"Upgrade type '".$compare_difference['type']."' not supported.");
break; break;

View File

@ -1,18 +1,16 @@
# Generated file from class.acl.php # Generated file from class.acl.php
SetEnv OPENXE_HTACCESS on
# Disable directory browsing # Disable directory browsing
Options -Indexes Options -Indexes
# Deny access to all *.php
Order deny,allow Order deny,allow
Allow from all Allow from all
<FilesMatch "\.(css|jpg|jpeg|gif|png|svg|js)$">
<Files *.php>
Order Allow,Deny Order Allow,Deny
Deny from all Allow from all
</Files> </FilesMatch>
# Allow access to index.php
<Files index.php> <Files index.php>
Order Allow,Deny Order Allow,Deny
Allow from all Allow from all
</Files> </Files>
# end

View File

@ -37,12 +37,9 @@
[PAGE] [PAGE]
<div id="login-footer"> <div id="login-footer">
<div class="copyright"> <div class="copyright">
&copy; [YEAR] by OpenXE-org & Xentral&nbsp;ERP&nbsp;Software&nbsp;GmbH. &copy; [YEAR] by OpenXE-org & Xentral&nbsp;ERP&nbsp;Software&nbsp;GmbH.<br>
<br> OpenXE is free open source software under AGPL-3.0 license, based on <a href="https://xentral.com" target="_blank">Xentral®</a>.<br>
[WAWIVERSION] [XENTRALVERSION]
</br>
OpenXE is free open source software under AGPL-3.0 license, based on <a href="https://xentral.com" target="_blank">Xentral®</a>.
<!-- dead link [LIZENZHINWEIS] -->
</div> </div>
</div> </div>