Skip to content

Commit

Permalink
20230612 Work on #95 #96 #103 #203 #212
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanGibbs3 committed Jun 12, 2023
1 parent 1385fb7 commit d05d340
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 59 deletions.
7 changes: 5 additions & 2 deletions base_maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
}
NLIO();
NLIO(_DATABASE);
NLIO(_MNTDBALV." $ADODB_vers");
NLIO(_MNTDBALV . ' ' . implode('.', GetDALSV());
NLIO(_MNTDBTYPE." $DBtype");
NLIO(_MNTDBALERTNAME." $alert_dbname");
if( $BADB ){
Expand Down Expand Up @@ -364,7 +364,10 @@
PrintFramedBoxFooter(1, 3);
NLIO('<br/>', 3);
PrintFramedBoxHeader(_DATABASE, '#669999', 1, 3, 'left');
NLIO( '<b>' . _MNTDBALV . ": </b>$ADODB_vers" . '<br/>', 6);
NLIO(
'<b>' . _MNTDBALV . ': </b>' . implode('.', GetDALSV()) . '<br/>',
6
);
echo "<B>"._MNTDBTYPE."</B> $DBtype <BR>
<B>"._MNTDBALERTNAME."</B> $alert_dbname <BR>
";
Expand Down
69 changes: 45 additions & 24 deletions includes/base_action.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1396,39 +1396,60 @@ function Action_archive_alert2_post(
// deletion.
$num_alert -= $action_cnt;
}

// This function accepts a (sid,cid) and purges it from the DB.
// - (sid,cid) : sensor, event id pair to delete
// - db : database handle
// RETURNS: 0 or 1 depending on whether the alert was deleted
function PurgeAlert( $sid, $cid, $db ){
$del_table_list = array(
"event", "iphdr", "tcphdr", "udphdr", "icmphdr", "opt", "data",
"acid_ag_alert", "acid_event"
);
$del_cnt = 0;
// Opened Issue #103 on this if block.
// https://github.com/NathanGibbs3/BASE/issues/103
// As this assumes that Oracle DB supports referentail Integrity.
if ( ($GLOBALS['use_referential_integrity'] == 1) &&
($GLOBALS['DBtype'] != "mysql") ){
$del_table_list = array ("event");
function PurgeAlert( $sid, $cid, $db = NULL ){
GLOBAL $use_referential_integrity, $BCR;
$Ret = 0;
$RIF = false; // Referential Integrity Flag.
// @codeCoverageIgnoreStart
if( isset($BCR) && is_object($BCR) ){
$RIF = $BCR->GetCap('BASE_SSRI');
}else{
if( intval($use_referential_integrity) == 1 ){
$RIF = true;
}
}
for ( $k = 0; $k < count($del_table_list); $k++ ){
// If trying to add to an BASE table append ag_ to the fields.
if ( strstr($del_table_list[$k], "acid_ag") == '' ){
$sql2 = "DELETE FROM ".$del_table_list[$k]." WHERE sid='".$sid."' AND cid='".$cid."'";
}else{
$sql2 = "DELETE FROM ".$del_table_list[$k]." WHERE ag_sid='".$sid."' AND ag_cid='".$cid."'";
// @codeCoverageIgnoreEnd
if ( is_object($db) ){
$EF = false; // Error Flag
$del_table_list = array ('event');
// Opened Issue #103 on this if block.
// https://github.com/NathanGibbs3/BASE/issues/103
// As this assumes that Oracle DB supports RI.
if( !$RIF || $db->DB_class == 0 ){
// No RI or DB does not support RI, add other tables.
array_push(
$del_table_list,
'iphdr', 'tcphdr', 'udphdr', 'icmphdr', 'opt', 'data',
'acid_ag_alert', 'acid_event'
);
}
$db->baseExecute($sql2);
if ( $db->baseErrorMessage() != '' ){
ErrorMessage(_ERRDELALERT." ".$del_table_list[$k]);
}elseif ( $k == 0 ){
$del_cnt = 1;
$Pfx = 'DELETE FROM ';
foreach( $del_table_list as $val ){
$tmp = '';
if( $val == 'acid_ag_alert' ){
$tmp = 'ag_';
}
$sql = "$Pfx$val WHERE " . $tmp . "sid='" . $sid
. "' AND " . $tmp . "cid='" . $cid . "'";
DumpSQL($sql, 1);
$db->baseExecute($sql);
if( $db->baseErrorMessage() != '' ){
$EF = true;
ErrorMessage(_ERRDELALERT . " $val");
}
}
if( !$EF ){
$Ret = 1;
}
}
return $del_cnt;
return $Ret;
}

// Returns true on success of sending message, false on failure.
function send_email (
$smtp_host, $smtp_auth, $smtp_user, $smtp_pw, $to, $hdrs, $body,
Expand Down
8 changes: 6 additions & 2 deletions includes/base_capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ function __construct(){ // PHP 5+ constructor Shim.
function BaseCapsRegistry(){ // PHP 4x constructor.
GLOBAL $Use_Auth_System, $BASE_Language, $event_cache_auto_update,
$colored_alerts, $archive_exists, $BASE_VERSION, $BASE_installID,
$debug_time_mode, $debug_mode, $BASE_urlpath, $domain, $BASE_IconSet;
$debug_time_mode, $debug_mode, $BASE_urlpath, $domain, $BASE_IconSet,
$use_referential_integrity;
if( $debug_mode > 1 ){
KML('Init: Caps Registry', 2);
}
Expand Down Expand Up @@ -111,9 +112,12 @@ function BaseCapsRegistry(){ // PHP 4x constructor.
if( LoadedString($domain) ){ // BASE Cookie Domain
$this->AddCap('BASE_SSDomain', $domain);
}
if( $event_cache_auto_update != 0 ){ // Event Cache Update.
if( intval($event_cache_auto_update) != 0 ){ // Event Cache Update.
$this->AddCap('BASE_SSECU');
}
if( intval($use_referential_integrity) != 0 ){
$this->AddCap('BASE_SSRI'); // DB Referential Integrity.
}
// BASE UI Settings
if( intval($colored_alerts) != 0 ){ // Colored Alerts
$this->AddCap('BASE_UICA');
Expand Down
62 changes: 44 additions & 18 deletions includes/base_db.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
defined('_BASE_INC') or die('Accessing this file directly is not allowed.');

class baseCon {
var $DB = NULL; // ADOdb DB dirver specific object when set.
var $DB = NULL; // ADOdb DB driver specific object when set.
var $DB_class = NULL; // DB Class.
var $DB_type = NULL; // ADOdb DB Driver.
var $DB_name = NULL; // DB.
var $DB_host = NULL; // DB Server.
var $DB_port = NULL; // DB Server Port.
var $DB_username = NULL; // DB User.
var $DBF_RI = false; // DB Feature Flag - Referential Integrity.
var $DBF_TS = false; // DB Feature Flag - Transaction Support.
var $lastSQL = ''; // Last SQL statement execution request.
var $version = 0; // Default to Schema v0 on Init.
var $sql_trace = NULL; // SQL Trace file handle.
var $DB_class = NULL; // DB Class.
var $Role = NULL; // Object Role Flag.
var $FLOP = NULL; // FLoP Extended DB Flag.

Expand Down Expand Up @@ -65,8 +67,8 @@ function baseCon($type) { // PHP 4x constructor.
function baseDBConnect(
$method, $database, $host, $port, $username, $password, $force = 0
){
GLOBAL $archive_dbname, $archive_host, $archive_port, $archive_user,
$archive_password, $debug_mode, $et;
GLOBAL $use_referential_integrity, $debug_mode, $et, $archive_dbname,
$archive_host, $archive_port, $archive_user, $archive_password;
$EMPfx = __FUNCTION__ . ': ';
// Check archive cookie to see if we need to use the archive tables.
// Only honnor cookie if not forced to use specified database.
Expand All @@ -89,7 +91,8 @@ function baseDBConnect(
$this->basePConnect($database, $host, $port, $username, $password);

}
if( $this->baseGetDBversion() > 105 ){ // FLoPS released after Schema v106
if( $this->baseGetDBversion() > 105 ){
// FLoPS released after Schema v106
$this->baseSetFLOP(); // Detect FLoP Extended DB.
}
// Need to TD these in Issue #11 branch.
Expand Down Expand Up @@ -193,14 +196,17 @@ function basePConnect ( $database, $host, $port, $username, $password ){

function baseClose (){
$this->DB->Close();
$this->DB_host = NULL; // Issue #204
$this->DB_name = NULL;
$this->DB_port = NULL;
$this->DB_username = NULL;
$this->FLOP = NULL;
$this->Role = NULL;
$this->version = 0;
$this->lastSQL = '';
// Issue #204
$this->DB_name = NULL; // DB.
$this->DB_host = NULL; // DB Server.
$this->DB_port = NULL; // DB Server Port.
$this->DB_username = NULL; // DB User.
$this->DBF_RI = false; // DB Feature Flag - Referential Integrity.
$this->DBF_TS = false; // DB Feature Flag - Transaction Support.
$this->lastSQL = ''; // Last SQL statement execution request.
$this->version = 0; // Default to Schema v0 on Init.
$this->Role = NULL; // Object Role Flag.
$this->FLOP = NULL; // FLoP Extended DB Flag.
}

function baseExecute(
Expand Down Expand Up @@ -464,12 +470,32 @@ function baseInsertID( $table = '', $field = '' ){
$DALV = GetDALSV(); // ADOdb Version
if( $DALV[0] > 5 || ($DALV[0] == 5 && $DALV[1] > 20) ){
// Use Insert_ID everywhere on ADOdb 5.21+
$Ret = $this->DB->Insert_ID($table, $field);
if(
$this->DB_type == 'postgres'
&& (
($DALV[0] == 5 && $DALV[1] == 22 && $DALV[2] < 6)
|| ($DALV[0] == 5 && $DALV[1] == 21 && $DALV[2] < 5)
)
){ // Catch ADOdb #978 - ADOdb 5.21x < 5.21.5 & 5.22x < 5.22.6
$Ret = @$this->DB->Insert_ID($table, $field);
}else{
$Ret = $this->DB->Insert_ID($table, $field);
}
}else{ // ADOdb < 5.21x
if( $DALV[0] > 3 || ($DALV[0] == 3 && $DALV[1] > 93) ){
if ($this->DB_type != 'oci8' ){
// Everywhere but Oracle on ADOdb 3.94+
$Ret = $this->DB->Insert_ID($table, $field);
if(
$this->DB_type == 'postgres'
&& (
($DALV[0] == 5 && $DALV[1] == 20 && $DALV[2] < 22)
|| ($DALV[0] == 5 && $DALV[1] > 17)
)
){ // Catch ADOdb #978 - ADOdb 5.18 - 5.20.21
$Ret = @$this->DB->Insert_ID($table, $field);
}else{
$Ret = $this->DB->Insert_ID($table, $field);
}
}
}else{ // Only MySQL && MsSQL on ADOdb < 3.94x
// @codeCoverageIgnoreStart
Expand Down Expand Up @@ -937,14 +963,14 @@ function ClearDataTables( $db ){
}
// @codeCoverageIgnoreEnd
// Get Max Length of field in table.
function GetFieldLength($db,$table,$field){
function GetFieldLength( $db, $table, $field ){
$EMPfx = __FUNCTION__ . ': Invalid ';
$Emsg = '';
$Ret = 0;
if ( !(is_object($db)) ){
if( !(is_object($db)) ){
$Emsg = 'DB Object';
}else{
if ( !(LoadedString($table) && $db->baseTableExists($table)) ){
if( !(LoadedString($table) && $db->baseTableExists($table)) ){
$Emsg = 'Table';
}elseif (
!(LoadedString($field) && $db->baseFieldExists($table,$field))
Expand Down
16 changes: 10 additions & 6 deletions includes/base_log_error.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function PrintServerInformation()
}

function PrintPageHeader(){
GLOBAL $DBtype, $ADODB_vers, $Use_Auth_System, $BCR;
GLOBAL $DBtype, $Use_Auth_System, $BCR;
if( !AuthorizedPage('(base_denied|index)') ){
// Additional app info allowed everywhere but landing pages.
if( ARC(10000) ){ // Auth check
Expand Down Expand Up @@ -304,11 +304,15 @@ function PrintPageHeader(){
$DD = array('BASE VERSION');
$DI = array($BV);
if( $Use_Auth_System == 1 && $AdminAuth ){
array_push($DD, 'OS', 'HTTP SW', 'HTTP PHP API', _MNTPHPVER);
array_push($DD, _MNTDBALV, _MNTDBTYPE, 'Executed Script');
array_push($DI, php_uname(), $SW_Svr, php_sapi_name());
array_push($DI, phpversion(), $ADODB_vers, $DBtype);
array_push($DI, XSSPrintSafe($_SERVER['SCRIPT_NAME']));
array_push(
$DD, 'OS', 'HTTP SW', 'HTTP PHP API', _MNTPHPVER,
_MNTDBALV, _MNTDBTYPE, 'Executed Script'
);
array_push(
$DI, php_uname(), $SW_Svr, php_sapi_name(), phpversion(),
implode('.', GetDALSV()) , $DBtype,
XSSPrintSafe($_SERVER['SCRIPT_NAME'])
);
}
DDT($DI, $DD, 'Server Information', '', '', 1, 0);
}
Expand Down
4 changes: 2 additions & 2 deletions sql/create_base_tbls_mssql_extra.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

-- Copyright (C) 2004 Kevin Johnson
-- Portions Copyright (C) 2002 Carnegie Mellon University
--
-- Author: Kevin Johnson <[email protected]
-- Based upon work by Roman Danyliw <[email protected]>
--

-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
Expand Down Expand Up @@ -68,4 +68,4 @@ ALTER TABLE data
ADD CONSTRAINT data_fkey_sid_cid
FOREIGN KEY (sid,cid) REFERENCES event (sid,cid)
ON DELETE CASCADE
ON UPDATE CASCADE;
ON UPDATE CASCADE;
2 changes: 2 additions & 0 deletions tests/php/idbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public function testClassbaseConConstruct(){
$this->assertEquals($Ec, $tc->DB_class, $URV);
$this->assertEquals(0, $tc->version, $URV);
$this->assertEmpty($tc->lastSQL, $URV);
$this->assertFalse($tc->DBF_RI, $URV);
$this->assertFalse($tc->DBF_TS, $URV);
$this->assertNull($tc->DB_name, $URV);
$this->assertNull($tc->DB_host, $URV);
$this->assertNull($tc->DB_port, $URV);
Expand Down
7 changes: 2 additions & 5 deletions tests/setupenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,17 @@ GHMode=release
#GHMode=branch
#GHBranch="NathanGibbs3-Issue#978"
if [ "$pvM" \> "7" ]; then # PHP 8x
ADODBVer=5.22.5
GHMode=branch
GHBranch="hotfix/5.22"
ADODBVer=5.22.6
if [ "$1" == "" ] && [ "$TRAVIS" == "true" ]; then
ADODBPATH="ADOdb-$ADODBVer"
fi
elif [ "$pvM" \> "5" ]; then # PHP 7x
GHMode=branch
GHBranch="hotfix/5.22"
if [ "$pvm" \> "1" ]; then # PHP 7.2+
ADODBVer=5.20.12
else
ADODBVer=5.20.0
fi
ADODBVer=5.22.6 # Test this.
if [ "$1" == "" ] && [ "$TRAVIS" == "true" ]; then
ADODBPATH="ADOdb-$ADODBVer"
fi
Expand Down

0 comments on commit d05d340

Please sign in to comment.