• 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

77.02
/includes/base_output_html.inc.php
1
<?php
2
// Basic Analysis and Security Engine (BASE)
3
// Copyright (C) 2019-2023 Nathan Gibbs
4
// Copyright (C) 2004 BASE Project Team
5
// Copyright (C) 2000 Carnegie Mellon University
6
//
7
//   For license info: See the file 'base_main.php'
8
//
9
//       Project Lead: Nathan Gibbs
10
// Built upon work by: Kevin Johnson & the BASE Project Team
11
//                     Roman Danyliw <rdd@cert.org>, <roman@danyliw.com>
12
//
13
//            Purpose: Prints or generates HTML to display
14
//
15
//          Author(s): Nathan Gibbs
16
//                     Kevin Johnson
17
// Ensure the conf file has been loaded.  Prevent direct access to this file.
18
defined( '_BASE_INC' ) or die( 'Accessing this file directly is not allowed.' );
19

20
include_once("$BASE_path/includes/base_state_common.inc.php");
21

22
function PageStart ( $refresh = 0, $page_title = '' ){
23
        GLOBAL $BASE_VERSION, $BASE_installID, $base_style, $BASE_urlpath,
70✔
24
        $html_no_cache, $refresh_stat_page, $stat_page_refresh_time, $UIL;
40✔
25
        $MHE = "<meta http-equiv='";
100✔
26
        $MNM = "<meta name='";
100✔
27
        $GT = 'BASE'; // Generator Meta Attribute.
100✔
28
        // Backport Shim
29
        $Charset = _CHARSET;
100✔
30
        $title = _TITLE;
100✔
31
        // Remove Info leaking suffix from title.
32
        // We can safely remove this shim once we merge the Issue11 branch.
33
        $title = preg_replace("/ ?\(BASE\) $BASE_installID/", '', $title);
100✔
34
        // End Backport Shim
35
        $title .= " ($GT)";
100✔
36
        $HT = $title; // Header Title
100✔
37
        if ( !AuthorizedPage('(base_denied|index)') ){
100✔
38
                // Additional app info allowed everywhere but landing pages.
39
                $GT .= " $BASE_VERSION";
100✔
40
                if ( isset($BASE_installID) && $BASE_installID != ''){
100✔
41
                        $title .= " $BASE_installID";
100✔
42
                        $HT = $title;
100✔
43
                }
30✔
44
                $title .= " $BASE_VERSION";
100✔
45
                if ($page_title != ''){
100✔
46
                        $title .= ': ' . XSSPrintSafe($page_title);
20✔
47
                }
6✔
48
                if ( ChkCookie ('archive', 1) ){
100✔
49
                        $SfxA = ' -- ARCHIVE';  // Need to add this to Translation Data.
20✔
50
                        $title .= $SfxA;
20✔
51
                        $HT .= $SfxA;
20✔
52
                }
6✔
53
        }
30✔
54
        print "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>";
100✔
55
        NLIO('<!-- '. $title . ' -->');
100✔
56
        NLIO('<html>');
100✔
57
        NLIO('<head>', 1);
100✔
58
        NLIO($MHE."Content-Type' content='text/html; charset=$Charset'>", 2);
100✔
59
        if ( $html_no_cache == 1 ) {
100✔
60
                NLIO($MHE."pragma' content='no-cache'>", 2);
20✔
61
        }
6✔
62
        if ( $refresh == 1 && $refresh_stat_page == 1 ){
100✔
63
                if (isset($_SERVER["REQUEST_URI"])){
20✔
64
                        $URI = $_SERVER["REQUEST_URI"];
×
65
                }else{
66
                        $URI = '/';
20✔
67
                }
68
                $tmp = CleanVariable(
20✔
69
                        $URI, VAR_FSLASH | VAR_PERIOD | VAR_DIGIT | VAR_PUNC | VAR_LETTER
20✔
70
                );
6✔
71
                $tmp = htmlspecialchars($tmp,ENT_QUOTES);
20✔
72
                NLIO(
20✔
73
                        $MHE."refresh' content='$stat_page_refresh_time; URL=$tmp'>",2
20✔
74
                );
6✔
75
        }
6✔
76
        NLIO($MNM."Author' content='Nathan Gibbs'>",2);
100✔
77
        NLIO($MNM."Generator' content='$GT'>",2);
100✔
78
        NLIO($MNM."viewport' content='width=device-width, initial-scale=1'>",2);
100✔
79
        NLIO("<title>$title</title>",2);
100✔
80
//        NLIO('<meta name="color-scheme" content="light dark"/>',2);
81
        NLIO('<link rel="stylesheet" type="text/css" HREF="'. $BASE_urlpath .'/styles/base_common.css'.'">', 2);
100✔
82
        NLIO('<link rel="stylesheet" type="text/css" HREF="'. $BASE_urlpath .'/styles/'. $base_style .'">', 2);
100✔
83
        NLIO('</head>', 1);
100✔
84
        NLIO('<body>', 1);
100✔
85
        NLIO('<div class="mainheadertitle">'.$HT.'</div>',2);
100✔
86
}
70✔
87
function PageEnd (){
88
        NLIO('</body>',1);
22✔
89
        NLIO('</html>');
22✔
90
}
16✔
91
function NLI ( $Item = '', $Count = 0 ){
92
        if ( !is_int($Count) ){
950✔
93
                $Count = 0;
44✔
94
        }
16✔
95
        return "\n".str_repeat ("\t", $Count).$Item;
950✔
96
}
97
function NLIO ( $Item = '', $Count = 0 ){
98
        print NLI ($Item, $Count);
290✔
99
}
206✔
100
function PrintBASESubHeader(
101
        $page_title = '', $page_name = '', $back_link = '', $refresh = 0, $page = ''
102
){
103
        GLOBAL $debug_mode, $BASE_installID, $BASE_path, $BASE_urlpath,
104
        $html_no_cache, $max_script_runtime, $Use_Auth_System, $base_style, $UIL;
105
        if ( ini_get("safe_mode") != true ){
×
106
                set_time_limit($max_script_runtime);
×
107
        }
108
        PageStart($refresh, $page_title);
×
109
        PrintBASEMenu( 'Header', $back_link);
×
110
        if ( $debug_mode > 0 ){
×
111
                PrintPageHeader();
×
112
        }
113
}
114
function PrintBASESubFooter(){
115
        GLOBAL $BASE_VERSION, $BASE_path, $BASE_urlpath, $Use_Auth_System,
116
        $base_custom_footer;
117
        NLIO ('<!-- BASE Footer -->',2);
×
118
        PrintBASEMenu( 'Footer' );
×
119
        NLIO ("<div class='mainfootertext'>",2);
×
120
        NLIO (
×
121
                "<a class='largemenuitem' href='https://github.com/NathanGibbs3/BASE' "
122
                ."target='_blank'>BASE</a>"
123
                ,3
124
        );
125
        $tmp = '';
×
126
        if ( !AuthorizedPage('(base_denied|index)') ){
×
127
                $tmp = "$BASE_VERSION ";
×
128
        }
129
        $tmp .= _FOOTER;
×
130
        NLIO ($tmp,3);
×
131
        NLIO ('</div>',2);
×
132
        if ( AuthorizedPage('base_main') ){
×
133
                // Custom footer allowed on main page only.
134
                if ( strlen($base_custom_footer) != 0 ){
×
135
                        NLIO ('<!-- BASE Custom Footer -->',2);
×
136
                        $tmp = base_include($base_custom_footer);
×
137
                        if ( $tmp == false ){
×
138
                                $tmp = XSSPrintSafe ( $base_custom_footer );
×
139
                                $tmp = returnErrorMessage (
×
140
                                        "ERROR: Include custom footer file: $tmp"
×
141
                                );
142
                                NLIO ($tmp,2);
×
143
                        }
144
                }
145
        }
146
        PageEnd();
×
147
}
148
function PrintBASEMenu( $type = '', $back_link = '' ){
149
        GLOBAL $BASE_urlpath, $Use_Auth_System, $et;
84✔
150
        if ( LoadedString( $type ) == true ){
120✔
151
                // Common
152
                $type = strtolower($type);
100✔
153
                $ReqRE = '';
100✔
154
                if ( $type == 'header' ){ // Header
100✔
155
                        $ReqRE = "(base_(denied|local_rules|main)|index)";
40✔
156
                }elseif ( $type == 'footer' ){ // Footer
72✔
157
                        $ReqRE = "(base_(denied|local_rules)|index)";
40✔
158
                }
12✔
159
                // Header Menu allowed everywhere but main & landing pages.
160
                // Footer Menu allowed everywhere but landing pages.
161
                if ( $ReqRE != '' && !AuthorizedPage($ReqRE) ){
100✔
162
                        // Html Template
163
                        $Hrst = "<a class='menuitem' href='$BASE_urlpath/";
80✔
164
                        // Href tag start.
165
                        $HrstTL = $Hrst . 'base_'; // Top Level Pages.
80✔
166
                        $Sep = ' | '; // Separator.
80✔
167
                        NLIO ("<div class='mainheadermenu'>",2);
80✔
168
                        NLIO ("<table border='0'>",3);
80✔
169
                        NLIO ('<tr>',4);
80✔
170
                        NLIO ("<td class='menuitem'>",5);
80✔
171
                        if ( $type == 'header' ){ // Header
80✔
172
                                NLIO ($HrstTL."main.php'>"._HOME.'</a>',6);
40✔
173
                                NLIO ($Sep.$HrstTL."qry_main.php?new=1'>"._SEARCH.'</a>',6);
40✔
174
                        }elseif ( $type == 'footer' ){ // Footer
52✔
175
                                NLIO ($HrstTL."ag_main.php?ag_action=list'>". _AGMAINT.'</a>',6);
40✔
176
                                NLIO ($Sep.$HrstTL."maintenance.php'>". _CACHE.'</a>',6);
40✔
177
                        }
12✔
178
                        if ($Use_Auth_System == 1){
80✔
179
                                NLIO ($Sep.$HrstTL."user.php'>". _USERPREF .'</a>',6);
80✔
180
                                NLIO ($Sep.$HrstTL."logout.php'>". _LOGOUT .'</a>',6);
80✔
181
                        }
24✔
182
                        if ( $type == 'header' && $back_link != '' ){ // Header
80✔
183
                                NLIO($Sep.$back_link,6);
20✔
184
                        }elseif ( $type == 'footer' ){ // Footer
66✔
185
                                if ( AuthorizedRole(1) ){ // Issue #144 fix
40✔
186
                                        NLIO ($Sep.$Hrst."admin/index.php'>". _ADMIN .'</a>',6);
40✔
187
                                }
12✔
188
                                if ( is_object($et) ){
40✔
189
                                        print $Sep;
20✔
190
                                        NLIO ('</td><td>',5);
20✔
191
                                        $et->PrintTiming();
20✔
192
                                }
6✔
193
                        }
12✔
194
                        PrintFramedBoxFooter(1);
80✔
195
                        NLIO ('</div>',2);
80✔
196
                }
24✔
197
        }
30✔
198
}
84✔
199
function PrintFramedBoxHeader(
200
        $title = '', $cc = 'black' , $td = 0, $tab = 3, $align = 'center',
201
        $wd = 100
202
){
203
        print FramedBoxHeader( $title, $cc, $td, $tab, $align, $wd);
88✔
204
}
64✔
205
function FramedBoxHeader(
206
        $title = '', $cc = 'black' , $td = 0, $tab = 3, $align = 'center',
207
        $wd = 100
208
){
209
        $Ret = '';
176✔
210
        // Input Validation
211
        $title = XSSPrintSafe($title);
176✔
212
        if ( HtmlColor($cc) == false ){
176✔
213
                $cc = 'black';
132✔
214
        }
48✔
215
        if ( !is_int($td) ){
176✔
216
                $td = 0;
44✔
217
        }
16✔
218
        if ( !is_int($tab) ){
176✔
219
                $tab = 3;
44✔
220
        }
16✔
221
        if ( !is_int($wd) ){
176✔
222
                $wd = 100;
44✔
223
        }
16✔
224
        $align = strtolower($align);
176✔
225
        $hal = array( 'left', 'center', 'right' );
176✔
226
        if ( !in_array($align, $hal) ){
176✔
227
                $align = 'center';
44✔
228
        }
16✔
229
        // Input Validation End
230
        $style = "'border: 2px solid $cc; border-collapse: collapse; width:$wd%;'";
176✔
231
        $tmp = "<table style = $style";
176✔
232
        if ( LoadedString($title) == true ){
176✔
233
                $tmp .= " summary='$title'";
88✔
234
        }
32✔
235
        $tmp .= '>';
176✔
236
        $Ret .= NLI($tmp, $tab) . NLI('<tr>',$tab + 1);
176✔
237
        if ( LoadedString($title) == true ){
176✔
238
                $Ret .= NLI(
88✔
239
                        "<td class='sectiontitle' style='text-align: $align;' colspan='20'>",
88✔
240
                        $tab + 2
40✔
241
                );
32✔
242
                $Ret .= NLI($title, $tab + 3);
88✔
243
                $Ret .= TblNewRow( $td, $align, $tab + 2 );
88✔
244
        }else{
32✔
245
                if ( $td != 0 ){
88✔
246
                        $Ret .= NLI('<td',$tab + 2);
44✔
247
                        if ( $align != '' ){
44✔
248
                                $Ret .= " style='text-align: $align;'";
44✔
249
                        }
16✔
250
                        $Ret .= '>';
44✔
251
                }
16✔
252
        }
253
        return $Ret;
176✔
254
}
255
function PrintFramedBoxFooter( $td = 0, $tab = 3 ){
256
        print FramedBoxFooter( $td, $tab);
146✔
257
}
104✔
258
function FramedBoxFooter( $td = 0, $tab = 3 ){
259
        $Ret = '';
212✔
260
        // Input Validation
261
        if ( !is_int($td) ){
212✔
262
                $td = 0;
44✔
263
        }
16✔
264
        if ( !is_int($tab) ){
212✔
265
                $tab = 3;
44✔
266
        }
16✔
267
        // Input Validation End
268
        if ( $td != 0 ){
212✔
269
                $Ret .= NLI('</td>',$tab + 2);
124✔
270
        }
40✔
271
        $Ret .= NLI('</tr>',$tab + 1);
212✔
272
        $Ret .= NLI('</table>',$tab);
212✔
273
        return $Ret;
212✔
274
}
275
function TblNewRow( $td = 0, $align = '', $tab = 3 ){
276
        $Ret = '';
264✔
277
        // Input Validation
278
        if ( !is_int($td) ){
264✔
279
                $td = 0;
44✔
280
        }
16✔
281
        if ( !is_int($tab) || $tab < 1 ){
264✔
282
                $tab = 3;
44✔
283
        }
16✔
284
        $align = strtolower($align);
264✔
285
        $hal = array( 'left', 'center', 'right' );
264✔
286
        if ( $align != '' && !in_array($align, $hal) ){
264✔
287
                $align = 'left';
44✔
288
        }
16✔
289
        // Input Validation End
290
        $Ret = NLI('</td>', $tab);
264✔
291
        $Ret .= NLI('</tr><tr>', $tab -1 );
264✔
292
        if ( $td != 0 ){
264✔
293
                $Ret .= NLI('<td',$tab);
88✔
294
                if ( $align != '' ){
88✔
295
                        $Ret .= " style='text-align: $align;'";
44✔
296
                }
16✔
297
                $Ret .= '>';
88✔
298
        }
32✔
299
        return $Ret;
264✔
300
}
301
function PrintTblNewRow( $td = 0, $align = '', $tab = 3 ){
302
        print TblNewRow( $td, $align, $tab );
88✔
303
}
64✔
304
function returnExportHTTPVar ( $var_name = '', $var_value = '', $tab = 3 ){
305
        $Ret = '';
110✔
306
        if ( LoadedString( $var_name ) == true ){ // Input Validation
110✔
307
                if ( !is_int($tab) ){
88✔
308
                        $tab = 3;
22✔
309
                }
8✔
310
                $Ret = NLI(
88✔
311
                        "<input type='hidden' name='$var_name' value='$var_value'/>", $tab
88✔
312
                );
32✔
313
        }
32✔
314
        return $Ret;
110✔
315
}
316

317
function chk_select($stored_value, $current_value){
318
        $msg = ' ';
44✔
319
        if ( strnatcmp($stored_value,$current_value) == 0 ){
44✔
320
                $msg .= 'selected';
22✔
321
        }
8✔
322
        return $msg;
44✔
323
}
324

325
function chk_check($stored_value, $current_value){
326
        $msg = ' ';
44✔
327
        if ( $stored_value == $current_value ){
44✔
328
                $msg .= 'checked';
22✔
329
        }
8✔
330
        return $msg;
44✔
331
}
332

333
function dispYearOptions($stored_value)
334
{
335
  // Creates the years for drop down boxes
336
  $thisyear = date("Y");
×
337
  $options = "";
×
338
  $options = "<OPTION VALUE=' ' ".chk_select($stored_value, " ").">"._DISPYEAR."\n";
×
339
  for($i=1999; $i<=$thisyear; $i++) {
×
340
    $options = $options ."<OPTION VALUE='".$i."' ".chk_select($stored_value, $i).">".$i."\n";
×
341
  }
342
  $options = $options. "</SELECT>";
×
343
  
344
  return($options);
×
345
}
346

347
function PrintBASEAdminMenuHeader(){
348
        GLOBAL $Use_Auth_System;
349
        $menu = NLI("<div>",2);
×
350
        $menu .= NLI(
×
351
                "<div class='mainheadermenu' style='float: left; width: 15%;'>",3
352
        );
353
        $menu .= NLI(_USERMAN ."<hr/>",4);
×
354
        // Html Templates
355
        $Umca = "base_useradmin.php?action="; // User Managemnt Common Action.
×
356
        $Hrst = "<a href='$Umca"; // Href tag start.
×
357
        $Hrsp = " class='menuitem'>"; // Href tag end.
×
358
        if ( $Use_Auth_System == 1 ){ // Issue #144 Fix
×
359
                $menu .= NLI($Hrst . "list'" . $Hrsp . _LISTU . "</a><br>",4);
×
360
        }
361
        $menu .= NLI($Hrst . "create'" . $Hrsp . _CREATEU."</a><br>",4);
×
362
        $Umca = "base_roleadmin.php?action="; // Role Managemnt Common Action.
×
363
        $Hrst = "<a href='$Umca"; // Href tag start.
×
364
        if ( $Use_Auth_System == 1 ){ // Issue #144 Fix
×
365
                $menu .= NLI("<br>". _ROLEMAN ."<hr>",4);
×
366
                $menu .= NLI($Hrst . "list'" . $Hrsp . _LISTR."</a><br>",4);
×
367
                $menu .= NLI($Hrst . "create'" . $Hrsp ._CREATER."</a><br>",4);
×
368
        }
369
        $menu .= NLI("</div>",3);
×
370
        $menu .= NLI(
×
371
                "<div style='padding-left: 10px; width: auto;'>",3
372
        );
373
        print $menu;
×
374
}
375
function PrintBASEAdminMenuFooter(){
376
        NLIO("</div>",3);
×
377
        NLIO("</div>",2);
×
378
}
379
function PrintBASEHelpLink($target)
380
{
381
  /*
382
    This function will accept a target variable which will point to
383
    an anchor in the base_help.php file.  It will output a help icon
384
    that will link to that target in a new window.
385
  */
386
}
387

388
// Generate Horizontal Bar Graph <td> tag set.
389
function HBarGraph (
390
        $Value = 1, $Count = 1, $color = "ff0000", $bgcolor = "ffffff"
391
){
392
        $pfx = '<td bgcolor="#';
132✔
393
        // Input Validation.
394
        if ( HtmlColor($color) == false ){
132✔
395
                $color = 'ff0000';
22✔
396
        }
8✔
397
        if ( HtmlColor($bgcolor) == false ){
132✔
398
                $bgcolor = 'ffffff';
22✔
399
        }
8✔
400
        // Input End.
401
        $ent_pct = Percent( $Value, $Count );
132✔
402
        if ( $ent_pct > 0 ){
132✔
403
                $ent_clr = $color;
110✔
404
        }else{
40✔
405
                $ent_pct = 100;
22✔
406
                $ent_clr = $bgcolor;
22✔
407
        }
408
        $Ret = $pfx . $ent_clr . '" width="' . $ent_pct. '%">&nbsp;</td>';
132✔
409
        if ( $ent_pct > 0 && $ent_pct < 100 ){
132✔
410
                $Ret .= $pfx . $bgcolor.'"></td>';
22✔
411
        }
8✔
412
        return($Ret);
132✔
413
}
414
function HtmlPercent ( $Value = 1, $Count = 1 ){
415
        $ent_pct = Percent( $Value, $Count );
88✔
416
        if ( $ent_pct == 0 ){
88✔
417
                $tmp = "&lt; 1";
22✔
418
        }else{
8✔
419
                $tmp = $ent_pct;
66✔
420
        }
421
        $Ret = $tmp . '%';
88✔
422
        return($Ret);
88✔
423
}
424
?>
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