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

NathanGibbs3 / BASE / 590

pending completion
590

push

travis-ci-com

NathanGibbs3
20230420 Fix CI build breakage. 2

2755 of 16977 relevant lines covered (16.23%)

21.61 hits per line

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

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

326
function chk_select($stored_value, $current_value){
327
        $msg = ' ';
40✔
328
        if ( strnatcmp($stored_value,$current_value) == 0 ){
40✔
329
                $msg .= 'selected';
20✔
330
        }
6✔
331
        return $msg;
40✔
332
}
333

334
function chk_check($stored_value, $current_value){
335
        $msg = ' ';
40✔
336
        if ( $stored_value == $current_value ){
40✔
337
                $msg .= 'checked';
20✔
338
        }
6✔
339
        return $msg;
40✔
340
}
341

342
function dispYearOptions($stored_value)
343
{
344
  // Creates the years for drop down boxes
345
  $thisyear = date("Y");
×
346
  $options = "";
×
347
  $options = "<OPTION VALUE=' ' ".chk_select($stored_value, " ").">"._DISPYEAR."\n";
×
348
  for($i=1999; $i<=$thisyear; $i++) {
×
349
    $options = $options ."<OPTION VALUE='".$i."' ".chk_select($stored_value, $i).">".$i."\n";
×
350
  }
351
  $options = $options. "</SELECT>";
×
352
  
353
  return($options);
×
354
}
355

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

397
// Generate Horizontal Bar Graph <td> tag set.
398
function HBarGraph (
399
        $Value = 1, $Count = 1, $color = "ff0000", $bgcolor = "ffffff"
400
){
401
        $pfx = '<td bgcolor="#';
120✔
402
        // Input Validation.
403
        if ( HtmlColor($color) == false ){
120✔
404
                $color = 'ff0000';
20✔
405
        }
6✔
406
        if ( HtmlColor($bgcolor) == false ){
120✔
407
                $bgcolor = 'ffffff';
20✔
408
        }
6✔
409
        // Input End.
410
        $ent_pct = Percent( $Value, $Count );
120✔
411
        if ( $ent_pct > 0 ){
120✔
412
                $ent_clr = $color;
100✔
413
        }else{
30✔
414
                $ent_pct = 100;
20✔
415
                $ent_clr = $bgcolor;
20✔
416
        }
417
        $Ret = $pfx . $ent_clr . '" width="' . $ent_pct. '%">&nbsp;</td>';
120✔
418
        if ( $ent_pct > 0 && $ent_pct < 100 ){
120✔
419
                $Ret .= $pfx . $bgcolor.'"></td>';
20✔
420
        }
6✔
421
        return($Ret);
120✔
422
}
423
function HtmlPercent ( $Value = 1, $Count = 1 ){
424
        $ent_pct = Percent( $Value, $Count );
80✔
425
        if ( $ent_pct == 0 ){
80✔
426
                $tmp = "&lt; 1";
20✔
427
        }else{
6✔
428
                $tmp = $ent_pct;
60✔
429
        }
430
        $Ret = $tmp . '%';
80✔
431
        return($Ret);
80✔
432
}
433
?>
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