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

NathanGibbs3 / BASE / 624

pending completion
624

push

travis-ci-com

NathanGibbs3
Merge branch 'devel'

562 of 562 new or added lines in 28 files covered. (100.0%)

3145 of 17504 relevant lines covered (17.97%)

23.22 hits per line

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

75.3
/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
function PageStart ( $refresh = 0, $page_title = '' ){
21
        GLOBAL $BASE_VERSION, $BASE_installID, $base_style, $BASE_urlpath,
70✔
22
        $html_no_cache, $refresh_stat_page, $stat_page_refresh_time, $UIL, $BCR,
40✔
23
        $Use_Auth_System;
40✔
24
        $AS = false;
100✔
25
        if( isset($BCR) && is_object($BCR) ){
100✔
26
                $BV = $BCR->GetCap('BASE_Ver');
×
27
                $AS = $BCR->GetCap('BASE_Auth');
×
28
        }else{
29
                $BV = $BASE_VERSION;
100✔
30
                if( $Use_Auth_System == 1 ){
100✔
31
                        $AS = true;
×
32
                }
33
        }
34
        $MHE = "<meta http-equiv='";
100✔
35
        $MNM = "<meta name='";
100✔
36
        $GT = 'BASE'; // Generator Meta Attribute.
100✔
37
        // Backport Shim
38
        $Charset = _CHARSET;
100✔
39
        $title = _TITLE;
100✔
40
        // Remove Info leaking suffix from title.
41
        // We can safely remove this shim once we merge the Issue11 branch.
42
        $title = preg_replace("/ ?\(BASE\) $BASE_installID/", '', $title);
100✔
43
        // End Backport Shim
44
        $title .= " ($GT)";
100✔
45
        $HT = $title; // Header Title
100✔
46
        if ( !AuthorizedPage('(base_denied|index)') ){
100✔
47
                // Additional app info allowed everywhere but landing pages.
48
                $GT .= " $BV";
100✔
49
                if ( isset($BASE_installID) && $BASE_installID != ''){
100✔
50
                        $title .= " $BASE_installID";
100✔
51
                        $HT = $title;
100✔
52
                }
30✔
53
                $title .= " $BV";
100✔
54
                if ($page_title != ''){
100✔
55
                        $title .= ': ' . XSSPrintSafe($page_title);
20✔
56
                }
6✔
57
                if ( ChkArchive() ){
100✔
58
                        $SfxA = ' -- ARCHIVE';  // Need to add this to Translation Data.
20✔
59
                        $title .= $SfxA;
20✔
60
                        $HT .= $SfxA;
20✔
61
                }
6✔
62
                // @codeCoverageIgnoreStart
63
                if( $AS ){ // Auth System in use, attempt cookie refresh.
64
                        if( AuthorizedRole(10000) ){// Authenticated & enabled user.
65
                                $cookievalue = $_COOKIE['BASERole'];
66
                                BCS('BASERole', $cookievalue); // Refresh cookie expiration.
67
                        }
68
                }
69
                // @codeCoverageIgnoreEnd
70
        }
30✔
71
        print "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>";
100✔
72
        NLIO('<!-- '. $title . ' -->');
100✔
73
        NLIO('<html>');
100✔
74
        NLIO('<head>', 1);
100✔
75
        NLIO($MHE."Content-Type' content='text/html; charset=$Charset'>", 2);
100✔
76
        if ( $html_no_cache == 1 ) {
100✔
77
                NLIO($MHE."pragma' content='no-cache'>", 2);
20✔
78
        }
6✔
79
        if ( $refresh == 1 && $refresh_stat_page == 1 ){
100✔
80
                if (isset($_SERVER["REQUEST_URI"])){
20✔
81
                        $URI = $_SERVER["REQUEST_URI"];
×
82
                }else{
83
                        $URI = '/';
20✔
84
                }
85
                $tmp = CleanVariable(
20✔
86
                        $URI, VAR_FSLASH | VAR_PERIOD | VAR_DIGIT | VAR_PUNC | VAR_LETTER
20✔
87
                );
6✔
88
                $tmp = htmlspecialchars($tmp,ENT_QUOTES);
20✔
89
                NLIO(
20✔
90
                        $MHE."refresh' content='$stat_page_refresh_time; URL=$tmp'>",2
20✔
91
                );
6✔
92
        }
6✔
93
        NLIO($MNM."Author' content='Nathan Gibbs'>",2);
100✔
94
        NLIO($MNM."Generator' content='$GT'>",2);
100✔
95
        NLIO($MNM."viewport' content='width=device-width, initial-scale=1'>",2);
100✔
96
        NLIO("<title>$title</title>",2);
100✔
97
//        NLIO('<meta name="color-scheme" content="light dark"/>',2);
98
        NLIO('<link rel="stylesheet" type="text/css" HREF="'. $BASE_urlpath .'/styles/base_common.css'.'">', 2);
100✔
99
        NLIO('<link rel="stylesheet" type="text/css" HREF="'. $BASE_urlpath .'/styles/'. $base_style .'">', 2);
100✔
100
        NLIO('</head>', 1);
100✔
101
        NLIO('<body>', 1);
100✔
102
        NLIO('<div class="mainheadertitle">'.$HT.'</div>',2);
100✔
103
}
70✔
104

105
function PageEnd (){
106
        NLIO('</body>', 1);
22✔
107
        NLIO('</html>');
22✔
108
}
16✔
109

110
function PrintBASESubHeader (
111
        $page_title = '', $page_name = '', $back_link = '', $refresh = 0,
112
        $page = ''
113
){
114
        GLOBAL $debug_mode, $max_script_runtime, $UIL, $BCR;
115
        if ( ini_get("safe_mode") != true ){
×
116
                set_time_limit($max_script_runtime);
×
117
        }
118
        $BCR->AddCap('UIMode', 'Web');
×
119
        PageStart($refresh, $page_title);
×
120
        PrintBASEMenu( 'Header', $back_link);
×
121
        if ( $debug_mode > 0 ){
×
122
                PrintPageHeader();
×
123
        }
124
}
125

126
function PrintBASESubFooter (){
127
        GLOBAL $BASE_path, $BASE_urlpath, $base_custom_footer, $BCR;
128
        $BV = $BCR->GetCap('BASE_Ver');
×
129
        NLIO('<!-- BASE Footer -->', 2);
×
130
        PrintBASEMenu('Footer');
×
131
        NLIO("<div class='mainfootertext'>", 2);
×
132
        NLIO(
×
133
                "<a class='largemenuitem' href='https://github.com/NathanGibbs3/BASE' "
134
                . "target='_blank'>BASE</a>"
135
                ,3
136
        );
137
        $tmp = '';
×
138
        if( !AuthorizedPage('(base_denied|index)') ){
×
139
                $tmp = "$BV ";
×
140
        }
141
        $tmp .= _FOOTER;
×
142
        NLIO($tmp, 3);
×
143
        NLIO('</div>', 2);
×
144
        if( AuthorizedPage('base_main') ){
×
145
                // Custom footer allowed on main page only.
146
                if( strlen($base_custom_footer) != 0 ){
×
147
                        NLIO('<!-- BASE Custom Footer -->', 2);
×
148
                        $tmp = base_include($base_custom_footer);
×
149
                        if( $tmp == false ){
×
150
                                $tmp = XSSPrintSafe ( $base_custom_footer );
×
151
                                $tmp = returnErrorMessage (
×
152
                                        "ERROR: Include custom footer file: $tmp"
×
153
                                );
154
                                NLIO($tmp, 2);
×
155
                        }
156
                }
157
        }
158
        PageEnd();
×
159
}
160

161
function PrintBASEMenu ( $type = '', $back_link = '' ){
162
        GLOBAL $BASE_urlpath, $Use_Auth_System, $et;
84✔
163
        if( LoadedString($type) == true ){
120✔
164
                // Common
165
                $type = strtolower($type);
100✔
166
                $ReqRE = '';
100✔
167
                if( $type == 'header' ){ // Header
100✔
168
                        $ReqRE = "(base_(denied|local_rules|main)|index)";
40✔
169
                }elseif( $type == 'footer' ){ // Footer
72✔
170
                        $ReqRE = "(base_(denied|local_rules)|index)";
40✔
171
                }
12✔
172
                // Header Menu allowed everywhere but main & landing pages.
173
                // Footer Menu allowed everywhere but landing pages.
174
                if( $ReqRE != '' && !AuthorizedPage($ReqRE) ){
100✔
175
                        // Html Template
176
                        $Hrst = "<a class='menuitem' href='$BASE_urlpath/";
80✔
177
                        // Href tag start.
178
                        $HrstTL = $Hrst . 'base_'; // Top Level Pages.
80✔
179
                        $Sep = ' | '; // Separator.
80✔
180
                        NLIO("<div class='mainheadermenu'>", 2);
80✔
181
                        NLIO("<table border='0'>", 3);
80✔
182
                        NLIO('<tr>', 4);
80✔
183
                        NLIO("<td class='menuitem'>", 5);
80✔
184
                        if( $type == 'header' ){ // Header
80✔
185
                                NLIO($HrstTL . "main.php'>" . _HOME . '</a>', 6);
40✔
186
                                NLIO(
40✔
187
                                        $Sep . $HrstTL . "qry_main.php?new=1'>" . _SEARCH . '</a>',
32✔
188
                                        6
16✔
189
                                );
12✔
190
                        }elseif( $type == 'footer' ){ // Footer
52✔
191
                                NLIO(
40✔
192
                                        $HrstTL . "ag_main.php?ag_action=list'>" . _AGMAINT
32✔
193
                                        . '</a>',
28✔
194
                                        6
16✔
195
                                );
12✔
196
                                NLIO(
40✔
197
                                        $Sep . $HrstTL . "maintenance.php'>" . _CACHE . '</a>', 6
32✔
198
                                );
12✔
199
                        }
12✔
200
                        if( $Use_Auth_System == 1 ){
80✔
201
                                NLIO($Sep . $HrstTL . "user.php'>" . _USERPREF . '</a>', 6);
80✔
202
                                NLIO($Sep . $HrstTL . "logout.php'>" . _LOGOUT . '</a>', 6);
80✔
203
                        }
24✔
204
                        if( $type == 'header' && $back_link != '' ){ // Header
80✔
205
                                NLIO($Sep . $back_link, 6);
20✔
206
                        }elseif( $type == 'footer' ){ // Footer
66✔
207
                                if( AuthorizedRole(1) ){ // Issue #144 fix
40✔
208
                                        if( $Use_Auth_System == 1 ){
40✔
209
                                                $tmp = _ADMIN;
40✔
210
                                        }else{
12✔
211
                                                $tmp = _CREATEU;
×
212
                                        }
213
                                        NLIO("$Sep$Hrst" . "admin/index.php'>$tmp</a>", 6);
40✔
214
                                }
12✔
215
                                if( is_object($et) ){
40✔
216
                                        print $Sep;
20✔
217
                                        NLIO('</td><td>', 5);
20✔
218
                                        $et->PrintTiming();
20✔
219
                                }
6✔
220
                        }
12✔
221
                        PrintFramedBoxFooter(1);
80✔
222
                        NLIO('</div>', 2);
80✔
223
                }
24✔
224
        }
30✔
225
}
84✔
226

227
function PrintFramedBoxHeader (
228
        $title = '', $cc = 'black' , $td = 0, $tab = 3, $align = 'center',
229
        $wd = 100
230
){
231
        print FramedBoxHeader($title, $cc, $td, $tab, $align, $wd);
88✔
232
}
64✔
233

234
function FramedBoxHeader (
235
        $title = '', $cc = 'black' , $td = 0, $tab = 3, $align = 'center',
236
        $wd = 100
237
){
238
        $Ret = '';
176✔
239
        // Input Validation
240
        $title = XSSPrintSafe($title);
176✔
241
        if( HtmlColor($cc) == false ){
176✔
242
                $cc = 'black';
132✔
243
        }
48✔
244
        if( !is_int($td) ){
176✔
245
                $td = 0;
44✔
246
        }
16✔
247
        if( !is_int($tab) ){
176✔
248
                $tab = 3;
44✔
249
        }
16✔
250
        if( !is_int($wd) ){
176✔
251
                $wd = 100;
44✔
252
        }
16✔
253
        $align = strtolower($align);
176✔
254
        $hal = array('left', 'center', 'right');
176✔
255
        if( !in_array($align, $hal) ){
176✔
256
                $align = 'center';
44✔
257
        }
16✔
258
        // Input Validation End
259
        $style = "'border: 2px solid $cc; border-collapse: collapse; width:$wd%;'";
176✔
260
        $tmp = "<table style = $style";
176✔
261
        if( LoadedString($title) == true ){
176✔
262
                $tmp .= " summary='$title'";
88✔
263
        }
32✔
264
        $tmp .= '>';
176✔
265
        $Ret .= NLI($tmp, $tab) . NLI('<tr>', $tab + 1);
176✔
266
        if( LoadedString($title) == true ){
176✔
267
                $Ret .= NLI(
88✔
268
                        "<td class='sectiontitle' style='text-align: $align;' colspan='20'>",
88✔
269
                        $tab + 2
40✔
270
                );
32✔
271
                $Ret .= NLI($title, $tab + 3);
88✔
272
                $Ret .= TblNewRow( $td, $align, $tab + 2 );
88✔
273
        }else{
32✔
274
                if( $td != 0 ){
88✔
275
                        $Ret .= NLI('<td', $tab + 2);
44✔
276
                        if( $align != '' ){
44✔
277
                                $Ret .= " style='text-align: $align;'";
44✔
278
                        }
16✔
279
                        $Ret .= '>';
44✔
280
                }
16✔
281
        }
282
        return $Ret;
176✔
283
}
284

285
function PrintFramedBoxFooter ( $td = 0, $tab = 3 ){
286
        print FramedBoxFooter($td, $tab);
146✔
287
}
104✔
288

289
function FramedBoxFooter ( $td = 0, $tab = 3 ){
290
        $Ret = '';
212✔
291
        // Input Validation
292
        if( !is_int($td) ){
212✔
293
                $td = 0;
44✔
294
        }
16✔
295
        if( !is_int($tab) ){
212✔
296
                $tab = 3;
44✔
297
        }
16✔
298
        // Input Validation End
299
        if( $td != 0 ){
212✔
300
                $Ret .= NLI('</td>', $tab + 2);
124✔
301
        }
40✔
302
        $Ret .= NLI('</tr>', $tab + 1);
212✔
303
        $Ret .= NLI('</table>', $tab);
212✔
304
        return $Ret;
212✔
305
}
306

307
function TblNewRow ( $td = 0, $align = '', $tab = 3 ){
308
        $Ret = '';
264✔
309
        // Input Validation
310
        if( !is_int($td) ){
264✔
311
                $td = 0;
44✔
312
        }
16✔
313
        if( !is_int($tab) || $tab < 1 ){
264✔
314
                $tab = 3;
44✔
315
        }
16✔
316
        $align = strtolower($align);
264✔
317
        $hal = array( 'left', 'center', 'right' );
264✔
318
        if( $align != '' && !in_array($align, $hal) ){
264✔
319
                $align = 'left';
44✔
320
        }
16✔
321
        // Input Validation End
322
        $Ret = NLI('</td>', $tab);
264✔
323
        $Ret .= NLI('</tr><tr>', $tab -1 );
264✔
324
        if( $td != 0 ){
264✔
325
                $Ret .= NLI('<td', $tab);
88✔
326
                if( $align != '' ){
88✔
327
                        $Ret .= " style='text-align: $align;'";
44✔
328
                }
16✔
329
                $Ret .= '>';
88✔
330
        }
32✔
331
        return $Ret;
264✔
332
}
333

334
function PrintTblNewRow ( $td = 0, $align = '', $tab = 3 ){
335
        print TblNewRow($td, $align, $tab);
88✔
336
}
64✔
337

338
function LINext ( $tab = 3 ){
339
        $Ret = '';
88✔
340
        if( !is_int($tab) || $tab < 1 ){ // Input Validation
88✔
341
                $tab = 3;
44✔
342
        }
16✔
343
        $Ret = NLI('</li><li>', $tab);
88✔
344
        return $Ret;
88✔
345
}
346

347
function PrintLINext ( $tab = 3 ){
348
        print LINext($tab);
44✔
349
}
32✔
350

351
function returnExportHTTPVar ( $var_name = '', $var_value = '', $tab = 3 ){
352
        $Ret = '';
110✔
353
        if( LoadedString( $var_name ) == true ){ // Input Validation
110✔
354
                if( !is_int($tab) ){
88✔
355
                        $tab = 3;
22✔
356
                }
8✔
357
                $Ret = NLI(
88✔
358
                        "<input type='hidden' name='$var_name' value='$var_value'/>", $tab
88✔
359
                );
32✔
360
        }
32✔
361
        return $Ret;
110✔
362
}
363

364
function chk_select ( $stored_value, $current_value ){
365
        $msg = ' ';
44✔
366
        if( strnatcmp($stored_value,$current_value) == 0 ){
44✔
367
                $msg .= 'selected';
22✔
368
        }
8✔
369
        return $msg;
44✔
370
}
371

372
function chk_check ( $stored_value, $current_value ){
373
        $msg = ' ';
44✔
374
        if( $stored_value == $current_value ){
44✔
375
                $msg .= 'checked';
22✔
376
        }
8✔
377
        return $msg;
44✔
378
}
379

380
function dispYearOptions ( $stored_value, $Start = 1999 ){
381
        // Creates the years for drop down boxes
382
        if( !is_int($Start) || $Start < 1999 ){ // Input Validation
×
383
                $Start = 1999;
×
384
        }
385
        $thisyear = date("Y");
×
386
        $options = '';
×
387
  $options = "<OPTION VALUE=' ' ".chk_select($stored_value, " ").">"._DISPYEAR."\n";
×
388
        for( $i = $Start; $i<=$thisyear; $i++ ){
×
389
    $options = $options ."<OPTION VALUE='".$i."' ".chk_select($stored_value, $i).">".$i."\n";
×
390
        }
391
        $options .= '</select>';
×
392
        return $options;
×
393
}
394

395
function PrintBASEAdminMenuHeader (){
396
        GLOBAL $Use_Auth_System;
397
        $menu = NLI('<div>', 2);
×
398
        $menu .= NLI(
×
399
                "<div class='mainheadermenu' style='float: left; width: 15%;'>", 3
400
        );
401
        $menu .= NLI(_USERMAN . '<hr/>', 4);
×
402
        // Html Templates
403
        $Umca = "base_useradmin.php?action="; // User Managemnt Common Action.
×
404
        $Hrst = "<a href='$Umca"; // Href tag start.
×
405
        $Hrsp = " class='menuitem'>"; // Href tag end.
×
406
        if( $Use_Auth_System == 1 ){ // Issue #144 Fix
×
407
                $menu .= NLI($Hrst . "list'" . $Hrsp . _LISTU . '</a><br>', 4);
×
408
        }
409
        $menu .= NLI($Hrst . "create'" . $Hrsp . _CREATEU. '</a><br>', 4);
×
410
        $Umca = "base_roleadmin.php?action="; // Role Managemnt Common Action.
×
411
        $Hrst = "<a href='$Umca"; // Href tag start.
×
412
        if( $Use_Auth_System == 1 ){ // Issue #144 Fix
×
413
                $menu .= NLI('<br>' . _ROLEMAN . '<hr>', 4);
×
414
                $menu .= NLI($Hrst . "list'" . $Hrsp . _LISTR . '</a><br>', 4);
×
415
                $menu .= NLI($Hrst . "create'" . $Hrsp ._CREATER . '</a><br>', 4);
×
416
        }
417
        $menu .= NLI('</div>', 3);
×
418
        $menu .= NLI(
×
419
                "<div style='padding-left: 10px; width: auto;'>", 3
420
        );
421
        print $menu;
×
422
}
423

424
function PrintBASEAdminMenuFooter (){
425
        NLIO('</div>',3);
×
426
        NLIO('</div>',2);
×
427
}
428

429
function PrintBASEHelpLink ( $target ){
430
  /*
431
    This function will accept a target variable which will point to
432
    an anchor in the base_help.php file.  It will output a help icon
433
    that will link to that target in a new window.
434
  */
435
}
436

437
// Generate Horizontal Bar Graph <td> tag set.
438
function HBarGraph (
439
        $Value = 1, $Count = 1, $color = 'ff0000', $bgcolor = 'ffffff'
440
){
441
        $pfx = '<td bgcolor="#';
132✔
442
        // Input Validation.
443
        if( !HtmlColor($color) ){
132✔
444
                $color = 'ff0000';
22✔
445
        }
8✔
446
        if( !HtmlColor($bgcolor) ){
132✔
447
                $bgcolor = 'ffffff';
22✔
448
        }
8✔
449
        // Input End.
450
        $ent_pct = Percent($Value, $Count);
132✔
451
        if( $ent_pct > 0 ){
132✔
452
                $ent_clr = $color;
110✔
453
        }else{
40✔
454
                $ent_pct = 100;
22✔
455
                $ent_clr = $bgcolor;
22✔
456
        }
457
        $Ret = $pfx . $ent_clr . '" width="' . $ent_pct. '%">&nbsp;</td>';
132✔
458
        if ( $ent_pct > 0 && $ent_pct < 100 ){
132✔
459
                $Ret .= $pfx . $bgcolor.'"></td>';
22✔
460
        }
8✔
461
        return $Ret;
132✔
462
}
463

464
function HtmlPercent ( $Value = 1, $Count = 1 ){
465
        $ent_pct = Percent($Value, $Count);
88✔
466
        if( $ent_pct == 0 ){
88✔
467
                $tmp = "&lt; 1";
22✔
468
        }else{
8✔
469
                $tmp = $ent_pct;
66✔
470
        }
471
        $Ret = $tmp . '%';
88✔
472
        return $Ret;
88✔
473
}
474

475
?>
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