From 583400a0bb0ad064650abbcd13527b5dbebe0f65 Mon Sep 17 00:00:00 2001 From: Rod Wright Date: Wed, 24 Jun 2026 20:28:32 -0400 Subject: [PATCH] Incorporate common.php --- distfiles/common.php | 856 ++++++++++++++++++ distfiles/lognotes.php | 3 +- .../{functions.php => old-functions.php} | 0 3 files changed, 858 insertions(+), 1 deletion(-) create mode 100644 distfiles/common.php rename distfiles/{functions.php => old-functions.php} (100%) diff --git a/distfiles/common.php b/distfiles/common.php new file mode 100644 index 0000000..5246ada --- /dev/null +++ b/distfiles/common.php @@ -0,0 +1,856 @@ + + + + Installation error + + + Could not find the db.php file required for this installation. + + + "; + exit(); +} + +include("db.php"); +include("settings.php"); + +// assign variables from constants + + +// define some other constants +define("ADMIN",2); +define("USER",1); + +// build the basic color array +$basic_colors=array( +"White" => "#FFFFFF", +"Silver" => "#C0C0C0", +"Gray" => "#808080", +"Black" => "#000000", +"Red" => "#FF0000", +"Maroon" => "#800000", +"Orange" => "#FFA500", +"Yellow" => "#FFFF00", +"Olive" => "#808000", +"Lime" => "#00FF00", +"Green" => "#008000", +"Aqua" => "#00FFFF", +"Teal" => "#008080", +"Blue" => "#0000FF", +"Navy" => "#000080", +"Fuchsia" => "#FF00FF", +"Purple" => "#800080"); + +// Determine access mode, login status, and admin status +if ($access_mode == "trusted") $trusted=true; else $trusted=false; +$loggedin=$isadmin=false; +if (isset($_SESSION['userid'])) { + $uid=$_SESSION['userid']; + $loggedin=true; + if (mysqli_fetch_row(mysqli_query($db,"select role from users where id=\"$uid\""))[0] == ADMIN) { + $isadmin=true; + } +} + +// Generic functions + +function framework($option,$htmltitle,$pagetitle,$print) { + // generates html code for the beginning and end of all pages + if ($option=="begin") { + // generates everything down to the sidemenu/pagetable + // htmltitle is the page title that appears in the window titlebar + // pagetitle is what will appear as the title of the page itself + // print is whether to format for printing or not + if ($print) { + $bgcolor=P_BACKGROUND_COLOR; + $textcolor=P_TEXT_COLOR; + $linkcolor=P_LINK_COLOR; + $vlinkcolor=P_VLINK_COLOR; + $hdgcolor=P_HEADING_COLOR; + } else { + $bgcolor=BACKGROUND_COLOR; + $textcolor=TEXT_COLOR; + $linkcolor=LINK_COLOR; + $vlinkcolor=VLINK_COLOR; + $hdgcolor=HEADING_COLOR; + } + + echo " + + + + $htmltitle + + + + + + + + + + + + + + + + + + + + + + + "; + echo " + + "; + if ($htmltitle || $pagetitle) { + echo " $htmltitle - $pagetitle"; + if ($print) { + echo " +     +     + "; + } + echo "
"; + } + } else if ($option=="end") { + echo " + + + + + + + + "; + } else { + echo " +
Invalid option \"$option\" passed to framework(). Valid options are \"begin\" and \"end\".
+ "; + exit(1); + } +} +function pagetable($option) { + if ($option=="begin") { + echo " +
+ + + "; + } else if ($option=="end") { + echo " +
+ "; + } else { + echo " +
Invalid option \"$option\" passed to pagetable(). Valid options are \"begin\" and \"end\".
+ "; + exit(1); + } +} + +function pageblock($block,$option) { + if ($block=="left") { + if ($option=="begin") { + echo " + + "; + } else if ($option=="end") { + echo " + + "; + } else { + echo " +
Invalid option \"$option\" passed to pageblock(). Valid options are \"begin\" and \"end\".
+ "; + exit(1); + } + } else if ($block=="right") { + if ($option=="begin") { + echo " + + "; + } else if ($option=="end") { + if (defined("FOOTER_MESSAGE")) { + $footer_msg=FOOTER_MESSAGE; + echo " +

+
$footer_msg

+ "; + } + echo " + + "; + } else { + echo " +
Invalid option \"$option\" passed to pageblock(). Valid options are \"begin\" and \"end\".
+ "; + exit(1); + } + } else { + echo " +
Invalid block \"$block\" passed to pageblock(). Valid blocks are \"left\" and \"right\".
+ "; + exit(1); + } +} + +function sidemenu($printable=true) { + // Displays sidebar menu + global $db,$mbgcolor,$trusted,$loggedin,$isadmin; + + if ($trusted || $loggedin) { + echo " +
+ + +
Create New Writeup
+
"; + } + echo " +
+ "; + if ($trusted || $loggedin) { + echo " +
+ + + + +
View Writeups
Writeup Groups
Search Writeups
+
+ "; + if ($isadmin) { + echo " +
+ + + + + +
Admin Functions
Global Settings
Manage Database
Manage Terminal
+
+ "; + } + } + + if (! $loggedin) { + echo " +
+ + + +
My Account
Log In
+
"; + } else { + $menuuser=$_SESSION['userid']; + $loggedinas=mysqli_fetch_row(mysqli_query($db,"select firstname,lastname from users where id=\"$menuuser\"")); + echo " +
+ + + + +
My Account
Logged in as $loggedinas[0] $loggedinas[1]
Log Out
My Profile
+
"; + } + if ($printable) { + $currentparams=arrayCopy($_REQUEST); + echo " +
+
+
+ +
+
+ "; + } + echo " +
+ + +
About
+
+ "; +} + +function banner($print) { + // displays a banner + global $db; + $bannerid=BANNER; + // get banner parameters from banner table + $banrow=mysqli_fetch_assoc(mysqli_query($db,"select * from banners where bannerid=\"$bannerid\"")); + if (!$banrow) { + $bannerid=1; + } else { + $bannertext=$banrow["bannername"]; + if ($print) { + $bannercolor="#FFFFFF"; + $bannertxtcolor="#000000"; + } else { + $bannercolor=$banrow["bannercolor"]; + $bannertxtcolor=$banrow["textcolor"]; + } + } + if ($bannerid != 1) { + echo " + +
$bannertext
+ "; + } +} + +function dblookup($db,$table,$in_field,$out_field,$in_data) { + // look up a single field in a database given a value for a single field + $lookup_result=(mysqli_query($db,"select $out_field from $table where $in_field=\"$in_data\"")); + if (mysqli_num_rows($lookup_result) > 0) { + $out_data=mysqli_fetch_row($lookup_result); + return($out_data[0]); + } else { + return NULL; + } +} + +function arrayCopy( array $array ) { + $result=[]; + foreach( $array as $key => $val ) { + if( is_array( $val ) ) { + $result[$key] = arrayCopy( $val ); + } elseif ( is_object( $val ) ) { + $result[$key] = clone $val; + } else { + $result[$key] = $val; + } + } + return $result; +} + +function validateDate($date, $format = 'Y-m-d') { + $d = DateTime::createFromFormat($format, $date); + return $d && $d->format($format) == $date; +} + +function validateTime($time, $format = 'H:i:s') { + $t = DateTime::createFromFormat($format, $time); + return $t && $t->format($format) == $time; +} + +function validate_password($pass,$passconf) { + // run some checks on supplied passwords + // returns a two element array + // first element is true if passwords match, false if not + // second element is true if passwords meet complexity requirements, false if not + + $results=[]; + + // check for match + if ($pass==$passconf) { + $results['match']=true; + } else { + $results['match']=false; + } + + // check for complexity + // length + if (strlen($pass) < 8) { + $passlength=false; + } else { + $passlength=true; + } + // upper case + if (preg_match('/[A-Z]/',$pass)) { + $hasupper=true; + } else { + $hasupper=false; + } + // lower case + if (preg_match('/[a-z]/',$pass)) { + $haslower=true; + } else { + $haslower=false; + } + // number + if (preg_match('/[0-9]/',$pass)) { + $hasnumber=true; + } else { + $hasnumber=false; + } + // special character + if (preg_match('/[[:punct:]]/',$pass)) { + $hasspecial=true; + } else { + $hasspecial=false; + } + if ($passlength && $hasupper && $haslower && $hasnumber && $hasspecial) { + $results['complex']=true; + } else { + $results['complex']=false; + } + return $results; +} + +function displaywriteup($id) { + // grab some important global variables + global $device_term; + global $discovered_term, $discovered_term_short, $disc_drop_data; + global $functional_term, $functional_term_short; + global $functional_yes, $functional_no; + global $functional_yes_short, $functional_no_short; + global $db; + + $writeupdata=mysqli_fetch_assoc(mysqli_query($db,"select * from writeups where id=\"$id\"")); + // determine status indicator + if ($writeupdata['status']==1) $statusind="
OPEN
"; + if ($writeupdata['status']==2) $statusind="
CLSD
"; + if ($writeupdata['status']==3) $statusind="
DFRD
"; + // determine functional indicator + if($writeupdata["functional"]==1) { + $funcind="$functional_yes_short"; + } else { + $funcind="$functional_no_short"; + } + // look up text data + $devicename=dblookup($db,"devices","id","name",$writeupdata["device"]); + $subsystemname=dblookup($db,"subsystems","id","name",$writeupdata["subsystem"]); + $subsystemdesc=dblookup($db,"subsystems","id","description",$writeupdata["subsystem"]); + $discrtxt=$writeupdata["discrepancy_text"]; + $rdate=$writeupdata["report_date"]; + $rtime=$writeupdata["report_time"]; + $repby=$writeupdata["reported_by"]; + $whendiscoveredname=dblookup($db,"discovered","id","whendiscoveredname",$writeupdata["discovered"]); + $whendiscovereddesc=dblookup($db,"discovered","id","whendiscovereddesc",$writeupdata["discovered"]); + $techfname=dblookup($db,"users","id","firstname",$writeupdata["action_by"]); + $techlname=dblookup($db,"users","id","lastname",$writeupdata["action_by"]); + $reasonname=dblookup($db,"reasons","id","text",$writeupdata["action_reason"]); + $actxt=$writeupdata["action_text"]; + $adate=$writeupdata["action_date"]; + if ($adate=="0000-00-00") $adate=""; + $atime=$writeupdata["action_time"]; + + // determine if this is a member of a group + $member_qry=mysqli_query($db,"select linkgroup from links where writeupid=\"{$writeupdata['id']}\""); + $is_member=mysqli_num_rows($member_qry); + if ($is_member) { + $group_count=$is_member; + $member_group=mysqli_fetch_row($member_qry)[0]; + $member_group_name=dblookup($db,"groups","id","name",$member_group); + if ($member_group_name) { + $imgtitle="Member of group: $member_group_name"; + } else { + $imgtitle="Member of group ID: $member_group"; + } + if ($group_count == 1) { + $group_ind="\"GRP\""; + } else { + $group_ind="\"GRP\""; + } + } else { + $group_ind=NULL; + } + echo " +
+ + + + + + + + +
ID: $id   $statusind   $device_term: $devicename   Subsystem: $subsystemname   $discovered_term: $whendiscoveredname   $funcind
+ + + + + +
Discrepancy:
$discrtxt
   $group_ind
+ + + + + + +
Report date: $rdate   Report time: $rtime   Reported by: $repby
+
+ + + + + +
Action taken by: $techfname $techlname   Status change reason: $reasonname
+ + + + +
Action taken:
$actxt
+ + + + + +
Action date: $adate   Action time: $atime
+
+ "; +} + +function format_message($msgtype,$msgtxt) { + // displays a formatted message + // $msgtype is 0 for success or anything else for failure + // $msgtxt is the string to display + if ($msgtype == 0) { + $state="ui-state-highlight"; + $icon="ui-icon-info"; + } else { + $state="ui-state-error"; + $icon="ui-icon-alert"; + } + if ($msgtxt == "") $msgtxt="PROGRAM ERROR: No message text was supplied."; + echo " +
+

+ $msgtxt

+


+ "; +} + +function getsetting($setting_name,$user_id) { + // get the value of a setting for a user + global $db; + $confqry=mysqli_query($db,"select id,value from config where name=\"$setting_name\""); + $confvalue=mysqli_fetch_assoc($confqry)['value']; + $userqry=mysqli_query($db,"select value from profile where name=\"$setting_name\" and user=\"$user_id\""); + if (mysqli_num_rows($userqry) > 0) { + $uservalue=mysqli_fetch_assoc($userqry)['value']; + if ($uservalue) { + return $uservalue; + } else { + return $confvalue; + } + } else { + return $confvalue; + } +} + +function putsetting($setting_name,$setting_value,$user_id) { + // set the value of a setting for a tech + global $db; + $confqry=mysqli_query($db,"select value from config where name=\"$setting_name\""); + $confvalue=mysqli_fetch_assoc($confqry)['value']; + $userqry=mysqli_query($db,"select value from profile where name=\"$setting_name\" and user=\"$user_id\""); + if (mysqli_num_rows($userqry) > 0) { + $uservalue=mysqli_fetch_assoc($userqry)['value']; + if ($setting_value==$confvalue) { + mysqli_query($db,"delete from profile where user=\"$user_id\" and name=\"$setting_name\""); + } else { + if ($uservalue) { + if ($uservalue != $setting_value) mysqli_query($db,"update profile set value=\"$setting_value\" where name=\"$setting_name\" and user=\"$user_id\""); + } else { + mysqli_query($db,"insert into profile(user,name,value) values(\"$user_id\",\"$setting_name\",\"$setting_value\")"); + } + } + } else { + mysqli_query($db,"insert into profile(user,name,value) values(\"$user_id\",\"$setting_name\",\"$setting_value\")"); + } +} + +function group_detail($groupid,$role=false,$mode="view",$selection="none") { + // display a table for a single group + + // groupid is the group for which detail is to be shown + // role is true if user is logged in, false if not. + // mode is "select" if selection boxes are to be displayed, "view" if not. + // selection is "all" or "none" + + // grab some important global variables + global $device_term; + global $discovered_term, $discovered_term_short, $disc_drop_data; + global $functional_term, $functional_term_short; + global $functional_yes, $functional_no; + global $functional_yes_short, $functional_no_short; + global $db; + + // print group id and name + if ($selection == "all") { + $sel_flag="checked"; + } elseif ($selection == "none") { + $sel_flag=""; + } + $groupname=dblookup($db,"groups","id","name",$groupid); + if ($groupname == "") { + echo "Group ID:  $groupid"; + } else { + echo "Group Name:  $groupname"; + } + echo "
"; + // print table headers + if ($role && $mode=="select") { + echo " + + + + + + + + + + + + + + "; + } else { + echo " +
SelectIDStatusDate$discovered_term_short$device_termSubsystemReported byDiscrepancy$functional_term_short
+ + + + + + + + + + + + "; + } + + $writeup_qry=mysqli_query($db,"select writeupid from links where linkgroup=$groupid order by writeupid asc"); + while ($writeup=mysqli_fetch_row($writeup_qry)) { + // get writeup data + $writeupdata=mysqli_fetch_assoc(mysqli_query($db,"select * from writeups where id={$writeup[0]}")); + + // convert device number to name + $tname=dblookup($db,"devices","id","name",$writeupdata["device"]); + // convert subsystem number to name + $ssname=dblookup($db,"subsystems","id","name",$writeupdata["subsystem"]); + // determine status indicator + if ($writeupdata['status']==1) $statusind="
OPEN
"; + if ($writeupdata['status']==2) $statusind="
CLSD
"; + if ($writeupdata['status']==3) $statusind="
DFRD
"; + // determine whendiscovered text for discovered id + $whendiscname=mysqli_fetch_row(mysqli_query($db,"select whendiscoveredname from discovered where id=\"{$writeupdata['discovered']}\""))[0]; + $whendiscdesc=mysqli_fetch_row(mysqli_query($db,"select whendiscovereddesc from discovered where id=\"{$writeupdata['discovered']}\""))[0]; + // determine functional icon + if($writeupdata["functional"]==1) { + $func_icon="\"$functional_yes_short\""; + } else { + $func_icon="\"$functional_no_short\""; + } + // print table row + if ($role && $mode=="select") { + printf( + " + + + + + + + + + + + \n", + $writeupdata["id"], + $writeupdata["id"],$writeupdata["id"], + $statusind, + $writeupdata["report_date"], + $whendiscdesc, $whendiscname, + $tname, + $ssname, + $writeupdata["reported_by"], + $writeupdata["discrepancy_text"], + $func_icon + ); + } else { + printf( + " + + + + + + + + + + \n", + $writeupdata["id"],$writeupdata["id"], + $statusind, + $writeupdata["report_date"], + $whendiscdesc, $whendiscname, + $tname, + $ssname, + $writeupdata["reported_by"], + $writeupdata["discrepancy_text"], + $func_icon + ); + } + } + echo "
IDStatusDate$discovered_term_short$device_termSubsystemReported byDiscrepancy$functional_term_short
%s%s%s%s%s%s%s%s%s
%s%s%s%s%s%s%s%s%s

"; + +} + + +?> diff --git a/distfiles/lognotes.php b/distfiles/lognotes.php index d1d80d6..f7f55d5 100644 --- a/distfiles/lognotes.php +++ b/distfiles/lognotes.php @@ -7,7 +7,8 @@ SPDX-License-Identifier: GPL-2.0 */ -include("functions.php"); +//---include("functions.php"); +include("common.php"); //$tgt_year=$_REQUEST['y']; //$tgt_month=$_REQUEST['m']; diff --git a/distfiles/functions.php b/distfiles/old-functions.php similarity index 100% rename from distfiles/functions.php rename to distfiles/old-functions.php