• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NathanGibbs3 / BASE / 584

pending completion
584

push

travis-ci-com

NathanGibbs3
20230412 Fix CI build breakage.
         Related Issue(s) #158

2 of 2 new or added lines in 1 file covered. (100.0%)

2594 of 16816 relevant lines covered (15.43%)

20.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.92
/includes/base_log_error.inc.php
1
<?php
2
/*******************************************************************************
3
** Basic Analysis and Security Engine (BASE)
4
** Copyright (C) 2004 BASE Project Team
5
** Copyright (C) 2000 Carnegie Mellon University
6
**
7
** (see the file 'base_main.php' for license details)
8
**
9
** Project Lead: Kevin Johnson <kjohnson@secureideas.net>
10
**                Sean Muller <samwise_diver@users.sourceforge.net>
11
** Built upon work by Roman Danyliw <rdd@cert.org>, <roman@danyliw.com>
12
**
13
** Purpose: debugging and logging routines   
14
********************************************************************************
15
** Authors:
16
********************************************************************************
17
** Kevin Johnson <kjohnson@secureideas.net
18
**
19
********************************************************************************
20
*/
21
/** The below check is to make sure that the conf file has been loaded before this one....
22
 **  This should prevent someone from accessing the page directly. -- Kevin
23
 **/
24
defined( '_BASE_INC' ) or die( 'Accessing this file directly is not allowed.' );
25

26
function DivErrorMessage ($message, $Count = 0 ){
27
        NLIO ("<div class='errorMsg' align='center'>$message</div>",$Count);
44✔
28
}
32✔
29

30
function ErrorMessage ($message, $color = "#ff0000", $br = 0 ){
31
        print returnErrorMessage($message, $color, $br);
220✔
32
}
160✔
33

34
function returnErrorMessage ($message, $color = "#ff0000", $br = 0 ){
35
        if ( HtmlColor($color) == false ){
330✔
36
                // Default to Red if we are passed something odd.
37
                $color = "#ff0000";
154✔
38
        }
56✔
39
        $error = "<font color='$color'>$message</font>";
330✔
40
        if ( is_numeric($br) && $br == 1 ){ // Issue #160
330✔
41
                $error .= '<br/>';
154✔
42
        }
56✔
43
        return $error;
330✔
44
}
45

46
function BuildError ($message = '', $fmessage = '' ){
47
        if ( LoadedString($message) == true ){
20✔
48
                ErrorMessage(_ERRPHPERROR.':',0,1);
20✔
49
                ErrorMessage($message, 'black', 1);
20✔
50
                print '<br/>';
20✔
51
        }
6✔
52
        // @codeCoverageIgnoreStart
53
        if ( LoadedString($fmessage) == true ){
54
                FatalError($fmessage);
55
        }
56
        // @codeCoverageIgnoreEnd
57
}
14✔
58

59
function LibIncError (
60
                $Desc, $Loc, $Lib, $message = '', $LibName = '', $URL = '', $Fatal = 0,
61
                $Pear = 0
62
        ){
63
        // Translation data this msg when we get to _ERRSQLDBALLOAD1 on Issue#11
64
        $msg = "<b>Error loading the $Desc library:</b> ".
110✔
65
        XSSPrintSafe('from "'.$Loc.'".');
110✔
66
        if ( LoadedString($LibName) == true ){
110✔
67
                $msg .= '<br/>';
66✔
68
                // Translation data this msg when we get to _ERRSQLDBALLOAD2 on Issue#11
69
                $msg .= "The underlying $Desc library currently used is $LibName";
66✔
70
                if ( LoadedString($URL) == true ){
66✔
71
                        $URL = XSSPrintSafe($URL);
22✔
72
                        $msg .= ', that can be downloaded at ';
22✔
73
                        $msg .= "<a href='$URL'>$URL</a>";
22✔
74
                }
8✔
75
                $msg .= '.';
66✔
76
        }
24✔
77
        ErrorMessage($msg,'black',1);
110✔
78
        if ( LoadedString($message) == true ){
110✔
79
                ErrorMessage($message,'black',1);
22✔
80
        }
8✔
81
        $FLib = $Lib;
110✔
82
        if ($Pear == 1){
110✔
83
                $EMsg = "Check your Pear::$LibName installation!<br/>";
22✔
84
                $EMsg .= 'Make sure PEAR libraries can be found by PHP.';
22✔
85
                $EMsg .= '<pre>';
22✔
86
                $EMsg .= XSSPrintSafe('pear config-show | grep "PEAR directory"'."\n");
22✔
87
                $EMsg .= XSSPrintSafe('PEAR directory      php_dir     /usr/share/pear');
22✔
88
                $EMsg .= '</pre>';
22✔
89
                $EMsg .= 'This path must be part of the include path of php (cf. /etc/php.ini).';
22✔
90
                $EMsg .= '<pre>';
22✔
91
                $EMsg .= XSSPrintSafe('php -i | grep "include_path"');
22✔
92
                $EMsg .= XSSPrintSafe(
22✔
93
                        'include_path => .:/usr/share/pear:/usr/share/php => .:/usr/share/pear:/usr/share/php'
8✔
94
                );
8✔
95
                $EMsg .= '</pre>';
22✔
96
                if ( ini_get('safe_mode') ){
22✔
97
                        $EMsg .= XSSPrintSafe(
×
98
                                'In "safe_mode" it must also be part of safe_mode_include_dir in /etc/php.ini'
99
                        );
100
                }
101
                ErrorMessage($EMsg,'black',1);
22✔
102
                $FLib = $LibName;
22✔
103
        }
8✔
104
        $tmp = "PHP setup incomplete: $FLib required.";
110✔
105
        if ($Fatal == 0){
110✔
106
                ErrorMessage($tmp, 0,1);
110✔
107
        }else{
40✔
108
                // @codeCoverageIgnoreStart
109
                FatalError($tmp);
110
                // @codeCoverageIgnoreEnd
111
        }
112
}
80✔
113

114
// Debug Data Table
115
function DDT (
116
        $Items, $Desc = array(), $title = NULL, $tab = 3, $wd = 75, $vf = 0
117
){
118
        if ( is_array($Items) ){ // Input Validation
176✔
119
                if ( !is_array($Desc) ){
176✔
120
                        $Desc = array($Desc);
22✔
121
                }
8✔
122
                if ( !is_int($tab) ){
176✔
123
                        $tab = 3;
66✔
124
                }
24✔
125
                if ( !is_int($wd) ){
176✔
126
                        $wd = 75;
44✔
127
                }
16✔
128
                if ( !is_int($vf) ){
176✔
129
                        $vf = 0;
×
130
                }
131
                if ( !LoadedString($title) ){
176✔
132
                        $title = 'Debug Data Table';
154✔
133
                }
56✔
134
                $title = XSSPrintSafe($title);
176✔
135
                $Desc = XSSPrintSafe($Desc);
176✔
136
                $Items = XSSPrintSafe($Items);
176✔
137
                PrintFramedBoxHeader($title, 'red', 0, $tab, '', $wd);
176✔
138
                $icnt = count($Items);
176✔
139
                $DF = false;
176✔
140
                if ( $icnt <= count($Desc) ){ // Do we have Descriptions?
176✔
141
                        $DF = true;
132✔
142
                }
48✔
143
                if ( $icnt > 0 ){
176✔
144
                        $style = '';
88✔
145
                        if ( $vf == 1 && $DF ){ // Vertical Dsiplay
88✔
146
                                $style = " class='sectiontitle' style='text-align: right;".
4✔
147
                                " padding-right: 10px; width: 10%'";
16✔
148
                        }
8✔
149
                        NLIO("<td$style>", $tab + 2);
88✔
150
                        if ( $vf == 0 ){
88✔
151
                                if ( $DF ){
44✔
152
                                        for ( $i = 0; $i < $icnt; $i++){
22✔
153
                                                NLIO($Desc[$i], $tab + 3);
22✔
154
                                                if ( $i != $icnt - 1 ){
22✔
155
                                                        NLIO('</td><td>', $tab + 2);
22✔
156
                                                }
8✔
157
                                        }
8✔
158
                                        PrintTblNewRow( 1, '', $tab + 2 );
22✔
159
                                }
8✔
160
                        }
16✔
161
                        for ( $i = 0; $i < $icnt; $i++){
88✔
162
                                if ( $vf == 0 ){
88✔
163
                                        NLIO($Items[$i], $tab + 3);
44✔
164
                                        if ( $i != $icnt - 1 ){
44✔
165
                                                NLIO('</td><td>', $tab + 2);
44✔
166
                                        }
16✔
167
                                }else{
16✔
168
                                        if ( $DF ){
44✔
169
                                                NLIO($Desc[$i].': ', $tab + 3);
22✔
170
                                                NLIO("</td><td style='padding-left:10px;'>", $tab + 2);
22✔
171
                                        }
8✔
172
                                        NLIO($Items[$i], $tab + 3);
44✔
173
                                        if ( $i != $icnt -1 ){
44✔
174
                                                PrintTblNewRow( 0, '', $tab + 2 );
44✔
175
                                                NLIO("<td$style>", $tab + 2);
44✔
176
                                        }
16✔
177
                                }
178
                        }
32✔
179
                        NLIO('</td>', $tab + 2);
88✔
180
                }
32✔
181
                PrintFramedBoxFooter(0, $tab);
176✔
182
        }
64✔
183
}
128✔
184

185
// @codeCoverageIgnoreStart
186
function FatalError ($message){
187
        print returnErrorMessage('<b>'._ERRBASEFATAL.'</b>',0,1)."\n".$message;
188
        $message = preg_replace("/\//", '', $message);
189
        $message = preg_replace("/<br>/i", ' ', $message);
190
        $message = strip_tags($message)."\n";
191
        error_log($message);
192
        trigger_error($message, E_USER_ERROR);
193
}
194
// @codeCoverageIgnoreEnd
195

196
function PrintServerInformation()
197
{
198
   echo '';
×
199
}
200

201
function PrintPageHeader(){
202
        GLOBAL $DBtype, $ADODB_vers, $Use_Auth_System, $BASE_VERSION;
203
        if ( !AuthorizedPage('(base_denied|index)') ){
×
204
                // Additional app info allowed everywhere but landing pages.
205
                $AdminAuth = AuthorizedRole(1); // Issue #146 Fix
×
206
                if ( $AdminAuth ){ // Issue #146 Fix
×
207
                        if ( base_array_key_exists('SERVER_SOFTWARE',$_SERVER) ){
×
208
                                $SW_Svr = $_SERVER['SERVER_SOFTWARE'];
×
209
                        }else{
210
                                $SW_Svr = 'unknown';
×
211
                        }
212
                        $tmp = session_encode();
×
213
                        $SW_Svr = XSSPrintSafe($SW_Svr);
×
214
                }
215
                $request_uri = XSSPrintSafe($_SERVER['REQUEST_URI']);
×
216
                if ( base_array_key_exists('HTTP_USER_AGENT',$_SERVER) ){
×
217
                        $SW_Cli = $_SERVER['HTTP_USER_AGENT'];
×
218
                }else{
219
                        $SW_Cli = 'unknown';
×
220
                }
221
                if ( base_array_key_exists('HTTP_REFERER', $_SERVER) ){
×
222
                        $http_referer = XSSPrintSafe($_SERVER['HTTP_REFERER']);
×
223
                }else{
224
                        $http_referer = '';
×
225
                }
226
                $SW_Cli = XSSPrintSafe($SW_Cli);
×
227
                $query_string = XSSPrintSafe($_SERVER['QUERY_STRING']);
×
228
                // TD these labels from Issue #11 at some point.
229
   echo "<PRE>
230
         <B>URL:</B> '".$request_uri."'
231
         (<B>referred by:</B> '".$http_referer."')
232
         <B>PARAMETERS:</B> '".$query_string."'
233
         <B>CLIENT:</B> ".$SW_Cli;
234
if ( $Use_Auth_System == 1 && AuthorizedRole(1) ){ // Issue #146 Fix
×
235
print "\n         <B>SERVER:</B> ".$SW_Svr."
×
236
         <B>SERVER HW:</B> ".php_uname();
×
237
print "\n         <B>PHP VERSION:</B> ".phpversion();
×
238
print "\n         <B>PHP API:</B> ".php_sapi_name();
×
239
print "\n         <B>DB TYPE:</B> ".$DBtype;
×
240
print "\n         <B>DB ABSTRACTION VERSION:</B> ".$ADODB_vers;
×
241
}
242
print "\n         <B>BASE VERSION:</B> ".$BASE_VERSION."
×
243
         <B>SESSION ID:</B> ".session_id()."( ".strlen($tmp)." bytes )
×
244
         <B>SCRIPT :</B> ".XSSPrintSafe($_SERVER['SCRIPT_NAME'])."
×
245
         </PRE>"; 
246
        }
247
}
248

249
function PrintHTTPPost()
250
{
251
   echo "<BR><B>HTTP POST Variables</B><PRE>";
×
252
   XSSPrintSafe($_POST);
×
253
   echo "</PRE>";
×
254
}
255

256

257
function SQLTraceLog($message)
258
{
259
  GLOBAL $sql_trace_mode, $sql_trace_file;
260

261

262
  if ($sql_trace_mode < 1)
×
263
  // then fallback to http server's error log:
264
  {
265
    error_log($message);
×
266
  }
267
  else
268
  // preferred
269
  {
270
    if (($sql_trace_file != "") && file_exists($sql_trace_file))
×
271
    {
272
      $fd = fopen($sql_trace_file, "a");
×
273
      if ($fd)
274
      {
275
        fputs($fd, $message);
×
276
        fputs($fd, "\n");
×
277
        fflush($fd);
×
278
        fclose($fd);
×
279
      }
280
      else
281
      {
282
        ErrorMessage("ERROR: Could not open " . $sql_trace_file);
×
283
      }
284
    }
285
    else
286
    {
287
      error_log($message);
×
288
    }
289
  }
290
}
291
?>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc