#! /usr/bin/perl -w # *** Copyright (c)2002 Jim Massey. All rights reserved *********** # *** massey@stlouis-shopper.com ************** # *** No Warranty - certified to work with nothing *** # Program for user management use Tk; use Tk::Balloon; use DBD::Pg; use DBI; $bgcolor = "yellow"; $Label1_text = "Label 1"; $postgres_user = "postgres"; # User interface ********* # ********* MainWindow stuff ************* my $mainwindow = MainWindow->new; $mainwindow->title("System User management systemperl"); #$mainwindow->geometry("+150+50"); $mainwindow->configure(-background => "skyblue", -relief => 'sunken', -borderwidth => '5'); $mainwindow->geometry("500x400+150+50"); #$mainwindow->packPropagate(1); #$mainwindow->Button(-text => "NETWORK WORLD VIEW", -command => sub {arp_report()}) ->pack(-side => 'top'); $balloon_help = $mainwindow->Balloon( -initwait => 1750); # ********* Call GUI Elements in packing order ************** #about_window(); Main_menubar(); #Frame1(); #users_frame(); Frame2(); #about_window(); #$Frame2_Label1->packForget; #$Frame2->packForget; #users_report(); #arp_report(); read_wm_sessions(); MainLoop; # ******** Start sub routines ***************** sub arp_report { #$i++; my $arp_table = `/sbin/arp -a`; my $users_table = `who -H -l`; #print $arp_table; $Label1_text = `rwho -a`; $insert = "- Active terminals -".`date`."\n".$arp_table."\n"; if (Exists($Frame2_arp_Tbox)) { $Frame2_arp_Tbox->configure(-state => 'normal'); $Frame2_arp_Tbox->delete('1.0', 'end'); $Frame2_arp_Tbox->insert ( '1.0', $insert ); $Frame2_arp_Tbox->configure(-state => 'disabled'); } if (Exists($users_Tbox)) { $users_Tbox->configure(-state => 'normal'); $users_Tbox->delete("1.0", "end"); $users_Tbox->insert('1.0', $users_table); $users_Tbox->configure(-state => 'disabled'); $users_Tbox1->configure(-state => 'normal'); $users_Tbox1->delete("1.0", "end"); $users_Tbox1->insert('1.0', $arp_table); $users_Tbox1->configure(-state => 'disabled'); } #$Label1->configure(-textvariable => \$Label1_text); $Users_Frame_text = "Displaying System ARP and WHO"; #$mainwindow->geometry(""); } sub users_report { my $users_table = `who -H -l -i`; my $arp_table = `last -n 40`; $Label1_text = $users_table; if (Exists($users_Tbox1)) { $users_Tbox1->configure(-state => 'normal'); $users_Tbox1->delete("1.0", "end"); $users_Tbox1->insert('1.0', $users_table); $users_Tbox1->configure(-state => 'disabled'); } if (Exists($users_Tbox)) { $users_Tbox->configure(-state => 'normal'); $users_Tbox->delete("1.0", "end"); $users_Tbox->insert('1.0', $arp_table); #$users_Tbox->configure(-state => 'disabled'); } $Users_Frame_text = "Displaying System USERS and LAST"; #$mainwindow->geometry(""); } sub toggle_frame2 { if ($worldview eq "on"){ $Frame2->packForget(); $Frame1_toggle_btn->configure(-text => "User Proc View ON"); $worldview = "off"; } else { #$Frame2 ->pack(-side => 'bottom', -before => $arp_Tbox); $Frame2 ->pack(-side => 'bottom', -before => $Label1); $Frame1_toggle_btn->configure(-text => "turn Proc View OFF"); $worldview = "on"; } read_wm_sessions(); } # ***** Read gdm-kiosk accounting directory for managed clients ******* sub gdm_managed_clients { my $client = ""; my $gdm_client = ""; my $client_pid = ""; my $client_pid_file = ""; my $gdmAccounting = "/var/log/gdm/accounting"; $Frame2_gdm_Lbox->delete(0, "end"); print "\nhello FROM $gdm_client\n"; opendir (GDMACCOUNTING, "$gdmAccounting"); while ($client = readdir(GDMACCOUNTING)) { $gdm_client = "$gdmAccounting/" . "$client"; print "**hello FROM $gdm_client\n"; open(SESSION, $gdm_client); while () { chomp; $client_pid = $_; $client_pid_file = "/proc/" . $client_pid; if ( -e $client_pid_file) { print "hello FROM $gdm_client\n"; $Frame2_gdm_Lbox->insert('end', "$client : pid -:$client_pid"); } } } close (SESSION); closedir (GDMACCOUNTING); } # ***** Gdm-kiosk accounting Listbox dbl click to kill pid ****** sub gdm_managed_lbox_dblclick { my $index = ""; my $name = ""; my $value = ""; $index = $Frame2_gdm_Lbox->curselection; $Frame2_Entry1_value = $index; $Frame2_toolbar_text = "Process selected = ".$Frame2_gdm_Lbox ->get($index); ($name, $value) = split(/-:/, $Frame2_toolbar_text); $Frame2_Entry1_value = $value; } # ***** Read /proc directory and parse status file ************ sub read_wm_sessions { my $dirroot = "/proc"; my $i = "0"; $proc_name = ""; my $proc_id = ""; my $proc_state = ""; $Frame2_toolbar_text = "0 User processes"; $Frame2_users_Tbox->configure(-state => 'normal'); $Frame2_users_Tbox->delete("1.0", "end"); $Frame2_users_Tbox->configure(-state => 'disabled'); $Frame2_users_lbox->delete('0', 'end'); opendir (Proccesses, "/proc"); while ($proc_id = readdir(Proccesses)) { #$i++; #print $i."-".$proc_id."\n"; $status_file = $dirroot."/".$proc_id."/status"; if (-e $status_file) { $i++; #$status_file = $dirroot."/".proc_id."/status"; open (ProcStatus, $status_file); while () { $status = $_; ($field, $value) = split(/:/, $status); if ($field eq "Name") { #print STDOUT $status; $proc_name = $status; } if ($field eq "State") { $proc_state = $status; #print STDOUT $status; } if ($field eq "Uid") { if ($value = m/[5-9][0-9][0-9]/) { print STDOUT ("Process ID = $proc_id \n"); print STDOUT $proc_name; print STDOUT $status."\n"; parse_proc_file($proc_name); $Frame2_users_Tbox->configure(-state => 'normal'); #$Frame2_users_Tbox->delete("1.0", "end"); $Frame2_users_Tbox-> insert('1.0', "$user_id - $status ******** \n"); $Frame2_users_Tbox->insert('1.0', $proc_name); $Frame2_users_Tbox ->insert('1.0', "Pid: \t$proc_id \n$proc_state"); $Frame2_users_Tbox->configure(-state => 'disabled'); $Frame2_users_lbox ->insert('1.0', "$user_id - $user_proc-:$proc_id"); } } } #close (ProcStatus); # print STDOUT $status_file."\n"; # print STDOUT $i."-".$status."\n"; } } print "There are $i processes"; gdm_managed_clients(); #arp_report(); #$mainwindow->geometry(""); } sub kill_proccess { $Frame2_toolbar_text = $Frame2_Entry1_value; `kill $Frame2_Entry1_value`; $Frame2_Entry1_value = ""; read_wm_sessions(); } # ****** Parse directories under /proc - UID >= 500 *********** # ****** also updates $Frame2_toolbar_text - 0 base *********** sub parse_proc_file { my $name =""; my $value =""; ($name, $value) = split(/:/, $status); @fields = split(/\t/, $value); @proc_names = split(/\t/, $proc_name); $user_proc = $proc_names[1]; chomp $user_proc; $user_id = getpwuid $fields[1]; $Frame2_toolbar_text = $Frame2_users_lbox->size." - User Proccesses"; } # ******* Users Processes listbox dblckick to kill proc ************* sub frame2_users_lbox_dblclick { my $index = ""; my $name = ""; my $value = ""; $index = $Frame2_users_lbox->curselection; $Frame2_Entry1_value = $index; $Frame2_toolbar_text = "Process selected = ".$Frame2_users_lbox ->get($index); ($name, $value) = split(/-:/, $Frame2_toolbar_text); $Frame2_Entry1_value = $value; } # ************* DHCP WINDOW ROUTINES ******************************* # ******* dhcp_popup_window menu options toggle *********** sub dhcp_toggle { $dhcp_save_conf->destroy if Tk::Exists($dhcp_save_conf); # $dhcp_Tbox->destroy(); dhcp_display_Tbox(); if (Exists($dhcp_Tbox)) { $dhcp_Tbox->configure(-state => 'normal'); $dhcp_Tbox->delete('1.0', 'end'); if ($_[0] eq "CONFIG") { open (DHCP, "/etc/dhcpd.conf"); while () { $dhcp_Tbox->insert('end', $_); $dhcp_Frame1_text = "viewing DHCP.CONF"; } close (DHCP); } elsif ($_[0] eq "LEASES") { open (DHCP, "/var/state/dhcp/dhcpd.leases"); while () { $dhcp_Tbox->insert('end', $_); $dhcp_Frame1_text = "viewing DHCP.LEASES"; } close (DHCP); } elsif ($_[0] eq "HOSTS") { open (HOSTS, "/etc/hosts"); while () { $dhcp_Tbox->insert('end', $_); $dhcp_Frame1_text = "viewing HOSTS file"; } close (HOSTS); } $dhcp_Tbox->configure(-state => 'disabled'); # close (DHCP); } } sub dhcp_conf_build { $dhcp_save_conf->destroy() if Tk::Exists($dhcp_save_conf); dhcp_display_Tbox(); if (Exists($dhcp_Tbox)) { $dhcp_Tbox->configure(-state => 'normal'); $dhcp_Tbox->configure(-background => 'white'); $dhcp_Tbox->delete('1.0', 'end'); $dhcp_Frame1_text = "BUILD DHCP.CONF"; $dhcp_save_conf = $Frame1->Button(-text => 'Save DHCP.CONF', -command => sub {dhcp_save_conf()}) ->pack(-side => 'right'); $dbh = DBI->connect("DBI:Pg:dbname = net_clients", "$postgres_user"); $sth = $dbh->prepare("select * from dhcp_global"); $sth->execute; $sth->bind_columns(undef, \$option_name, \$option_value); while ($sth->fetch) { $dhcp_Tbox->insert('end', $option_name." ". $option_value.";\n"); } $sth->finish; $sth = $dbh->prepare("select * from dhcp_subnet"); $sth->execute; $sth->bind_columns(undef, \$subnet, \$netmask, \$rangestart, \$rangeend,\$option1, \$option2, \$option3, \$option4); while ($sth->fetch){ $dhcp_Tbox->insert('end', "\n\nsubnet ".$subnet. " netmask ".$netmask." {\n\t range ". $rangestart." ".$rangeend.";\n}\n\n"); } $sth->finish; $sth = $dbh->prepare("select * from dhcp_groups"); $sth->execute; $sth->bind_columns(undef, \$group_name, \$group_option, \$group_optionval); $count = 0; $i = 0; while ($sth->fetch){ $count++; $temp_group[$count] = $group_name.":". $group_option.":".$group_optionval; } $sth->finish; print STDOUT $count."###******###\n"; for ($i=1; $i <= $count; $i++) { ($group_name, $group_option, $group_optionval) = split(/:/, $temp_group[$i]); # $dhcp_Tbox->insert('end', "group {\n ".$group_option." ". # $group_optionval.";\n"); $sth = $dbh->prepare("select * from dhcp_host where '$group_name' = dhcp_host.host_group"); $num_rows = $sth->execute; $sth->bind_columns(undef, \$host_name, \$host_ipaddress, \$host_filename, \$host_group, \$host_option1, \$host_option2, \$host_option3, \$host_option4, \$host_macaddress,\$host_fixedaddress); if ($num_rows > 0) { if ($group_optionval) { $dhcp_Tbox->insert('end', "\n# **** Group is ".$group_name. "*****\ngroup {\n ". $group_option." ".$group_optionval.";\n"); } else { $dhcp_Tbox->insert('end', "\n# **** Group is ".$group_name. "*****\ngroup {\n"); } while ($sth->fetch) { $temp_record = ""; $temp_record = $temp_record."\n\thost ".$host_name." {\n\t". " hardware ethernet ".$host_macaddress.";\n\t"; if ($host_fixedaddress) { $temp_record = $temp_record." fixed-address ". $host_fixedaddress.";\n\t "; } else { $temp_record = $temp_record." fixed-address ". $host_name.";\n\t"; } if ($host_filename) { $temp_record = $temp_record." filename \"". $host_filename."\";\n\t"; } if ($host_option1) { $temp_record = $temp_record." ".$host_option1."\n\t"; } $temp_record = $temp_record."}\n"; $dhcp_Tbox->insert('end', $temp_record); } $dhcp_Tbox->insert('end', "}\n"); $sth->finish; } } } } sub dhcp_conf_edit { $dhcp_save_conf->destroy() if Tk::Exists($dhcp_save_conf); dhcp_display_Tbox(); if (Exists($dhcp_Tbox)) { $dhcp_Tbox->configure(-state => 'normal'); $dhcp_Tbox->configure(-background => 'white'); $dhcp_Tbox->delete('1.0', 'end'); $dhcp_Frame1_text = "EDITING DHCP.CONF"; $dhcp_save_conf = $Frame1->Button(-text => 'Save DHCP.CONF', -command => sub {dhcp_save_conf()}) ->pack(-side => 'right'); open (DHCP, "/etc/dhcpd.conf"); while () { $dhcp_Tbox->insert('end', $_); } } } sub dhcp_save_conf { open (DHCPD, ">/etc/dhcpd.conf"); print DHCPD $dhcp_Tbox->get('1.0', 'end'); close (DHCPD); dhcp_toggle("CONFIG"); } sub dhcp_hosts_edit { $dhcp_save_conf->destroy() if Tk::Exists($dhcp_save_conf); dhcp_display_Tbox(); if (Exists($dhcp_Tbox)) { $dhcp_Tbox->configure(-state => 'normal'); $dhcp_Tbox->configure(-background => 'white'); $dhcp_Tbox->delete('1.0', 'end'); $dhcp_Frame1_text = "EDITING ETC/HOSTS"; $dhcp_save_conf = $Frame1->Button(-text => 'Save ETC/HOSTS', -command => sub {dhcp_save_hosts()}) ->pack(-side => 'right'); open (DHCP, "/etc/hosts"); while () { $dhcp_Tbox->insert('end', $_); } } } sub dhcp_save_hosts { open (DHCPD, ">/etc/hosts"); print DHCPD $dhcp_Tbox->get('1.0', 'end'); close (DHCPD); dhcp_toggle("CONFIG"); } sub dhcp_group_form { dhcp_clear_hash(); $dhcp_save_conf->destroy if Tk::Exists($dhcp_save_conf); if (dhcp_clear_Tbox()) { dhcp_Tbox_newclient(); $dhcp_Frame1_text = "DHCP GROUP DEFINITION FORM"; $dhcp_Tbox->packPropagate(1); foreach (qw/GroupName Option Value/) { $element = $dhcp_Tbox->Label(-justify => 'left', -text => "$_:", -width => 20, -relief => 'groove', -borderwidth => 3); $dhcp_Tbox->windowCreate('end', -window => $element); $element = $dhcp_Tbox->Entry(-width => 20, -relief => 'sunken', -borderwidth => 3, -textvariable => \$dhcp_new_client{$_}); $dhcp_Tbox->windowCreate('end', -window => $element); $dhcp_Tbox->insert('end', "\n"); } $element = $dhcp_Tbox->Button(-text => "Add This DEFINITION", -background => 'skyblue', -relief => 'raised', -borderwidth => 5, -command => sub {dhcp_group_add()}); $dhcp_Tbox->windowCreate('end', -window => $element); $dhcp_Tbox->configure(-state => 'disabled'); # $dhcp_Frame1_text = $info{Second}; } else { $dhcp_Frame1_text = "UNABLE TO COMPLETE TASK"; } } sub dhcp_global_form { dhcp_clear_hash(); $dhcp_save_conf->destroy if Tk::Exists($dhcp_save_conf); if (dhcp_clear_Tbox()) { dhcp_Tbox_newclient(); $dhcp_Frame1_text = "DHCP GLOBAL PARAMETERS FORM"; foreach (qw/Parameter Value/) { $element = $dhcp_Tbox->Label(-justify => 'left', -text => "$_:", -width => 20, -relief => 'groove', -borderwidth => 3); $dhcp_Tbox->windowCreate('end', -window => $element); $element = $dhcp_Tbox->Entry(-width => 20, -relief => 'sunken', -borderwidth => 3, -textvariable => \$dhcp_new_client{$_}); $dhcp_Tbox->windowCreate('end', -window => $element); $dhcp_Tbox->insert('end', "\n"); } $element = $dhcp_Tbox->Button(-text => "Add This DEFINITION", -background => 'skyblue', -relief => 'raised', -borderwidth => 5, -command => sub {dhcp_global_add()}); $dhcp_Tbox->windowCreate('end', -window => $element); $dhcp_Tbox->configure(-state => 'disabled'); # $dhcp_Frame1_text = $info{Second}; } else { $dhcp_Frame1_text = "UNABLE TO COMPLETE TASK"; } } sub dhcp_network_form { dhcp_clear_hash(); $dhcp_save_conf->destroy if Tk::Exists($dhcp_save_conf); if (dhcp_clear_Tbox()) { dhcp_Tbox_newclient(); $dhcp_Frame1_text = "DHCP SUBNET description FORM"; foreach (qw/Subnet NetMask RangeStart RangeEnd Option1 Option2 Option3 Option4/) { $element = $dhcp_Tbox->Label(-justify => 'left', -text => "$_:", -width => 20, -relief => 'groove', -borderwidth => 3); $dhcp_Tbox->windowCreate('end', -window => $element); $element = $dhcp_Tbox->Entry(-width => 20, -relief => 'sunken', -borderwidth => 3, -textvariable => \$dhcp_new_client{$_}); $dhcp_Tbox->windowCreate('end', -window => $element); $dhcp_Tbox->insert('end', "\n"); } $element = $dhcp_Tbox->Button(-text => "Add This DEFINITION", -background => 'skyblue', -relief => 'raised', -borderwidth => 5, -command => sub {dhcp_network_add()}); $dhcp_Tbox->windowCreate('end', -window => $element); $dhcp_Tbox->configure(-state => 'disabled'); # $dhcp_Frame1_text = $info{Second}; } else { $dhcp_Frame1_text = "UNABLE TO COMPLETE TASK"; } } sub dhcp_entery_form { my $parameter = $_[0]; dhcp_clear_hash(); $dhcp_save_conf->destroy if Tk::Exists($dhcp_save_conf); if (dhcp_clear_Tbox()) { dhcp_Tbox_newclient(); $dhcp_Frame1_text = "DHCP CLIENT ENRTY FORM"; foreach (qw/Hostname Hardware-ethernet IP-Address fixed-address Kernel-Image Group-Name Option1 Option2 Option3 Option4/) { $element = $dhcp_Tbox->Label(-justify => 'left', -text => "$_:", -width => 20, -relief => 'groove', -borderwidth => 3); $dhcp_Tbox->windowCreate('end', -window => $element); $element = $dhcp_Tbox->Entry(-width => 20, -relief => 'sunken', -borderwidth => 3, -textvariable => \$dhcp_new_client{$_}); $dhcp_Tbox->windowCreate('end', -window => $element); $dhcp_Tbox->insert('end', "\n"); } $element = $dhcp_Tbox->Button(-text => "Add This CLIENT", -background => 'skyblue', -relief => 'raised', -borderwidth => 5, -command => sub {dhcp_new_client($parameter)}); $dhcp_Tbox->windowCreate('end', -window => $element); $dhcp_Tbox->configure(-state => 'disabled'); # $dhcp_Frame1_text = $info{Second}; } else { $dhcp_Frame1_text = "UNABLE TO COMPLETE TASK"; } #$dhcp->configure(-height => 0 -width => 0); #$dhcp->goemetry(""); } sub dhcp_new_client { my $parameter = $_[0]; my $output_string = ""; open (DHCP, "+>>/etc/dhcpd.conf"); if ($dhcp_new_client{Hostname} eq "") { $dhcp_Frame1_text = "Must have Hostname"; return; } if ($dhcp_new_client{'Hardware-ethernet'} eq "") { $dhcp_Frame1_text = "Need The Hardware-ethernet (MAC) address"; return (); } if ($dhcp_new_client{'Group-Name'} eq "") { $dhcp_Frame1_text = "Need Group-Name"; return(); } if ($dhcp_new_client{'IP-Address'} eq "") { $dhcp_Frame1_text = "Need IP-Address - for /etc/hosts"; return; } if ($parameter eq "file") { open (DHCP, "+>>/etc/dhcpd.conf"); $output_string = "\ngroup {\n"; $output_string = $output_string."\thost $dhcp_new_client{Hostname} {\n"; $output_string = $output_string. "\t hardware ethernet $dhcp_new_client{'Hardware-ethernet'};\n"; if ($dhcp_new_client{'fixed-address'} eq "") { $output_string = $output_string. "\t fixed-address $dhcp_new_client{'Hostname'};\n"; } else { $output_string = $output_string. "\t fixed-address $dhcp_new_client{'fixed-address'};\n"; } if ($dhcp_new_client{'Kernel-Image'}) { $output_string = $output_string. "\t filename \"$dhcp_new_client{'Kernel-Image'}\";\n"; } $output_string = $output_string."\t}\n}\n"; print DHCP $output_string; close (DHCP); dhcp_clear_hash(); } elsif ($parameter eq "db") { dhcp_host_add(); dhcp_clear_hash(); } } sub dhcp_client_concat { $output_string = "\ngroup {\n"; $output_string = $output_string."\thost $dhcp_new_client{Hostname} {\n"; $output_string = $output_string. "\t hardware ethernet $dhcp_new_client{'Hardware-ethernet'};\n"; if ($dhcp_new_client{'fixed-address'} eq "") { $output_string = $output_string. "\t fixed-address $dhcp_new_client{'Hostname'};\n"; } else { $output_string = $output_string. "\t fixed-address $dhcp_new_client{'fixed-address'};\n"; } if ($dhcp_new_client{'Kernel-Image'}) { $output_string = $output_string."\t filename \"$dhcp_new_client{'Kernel-Image'}\";\n"; } $output_string = $output_string."\t}\n}\n"; } # ******** dhcp window cleanup stuff **************** sub dhcp_clear_hash { foreach $key (keys(%dhcp_new_client)) { $dhcp_new_client{$key} = ""; } } sub dhcp_clear_Tbox { if (Exists($dhcp_Tbox)) { $dhcp_Tbox->configure(-state => 'normal'); $dhcp_Tbox->delete('1.0', 'end'); return "1"; } } sub dhcp_display_Tbox { # $dhcp_Tbox_entry1->destroy if Tk::Exists($dhcp_Tbox_entry1); if (Exists($dhcp_Tbox)) { #$dhcp_Tbox->delete('1.0','end'); $dhcp_Tbox->destroy(); dhcp_Tbox(); } } sub dhcp_Tbox_newclient { if (Exists($dhcp_Tbox)) { $dhcp_Tbox->destroy(); dhcp_Tbox_entry1(); } } # *********** END DHCP WINOW STUFF ******************************* # *********** DataBase routines below **************************** # ********** Add host def to net_clients database - pg - ********* sub dhcp_host_add { my $host_name = $dhcp_new_client{Hostname}; my $host_ipaddress = $dhcp_new_client{'IP-Address'}; my $host_filename = $dhcp_new_client{'Kernel-Image'}; my $host_group = $dhcp_new_client{'Group-Name'}; my $host_option1 = $dhcp_new_client{Option1}; my $host_option2 = $dhcp_new_client{Option2}; my $host_option3 = $dhcp_new_client{Option3}; my $host_option4 = $dhcp_new_client{Option4}; my $host_macaddress = $dhcp_new_client{'Hardware-ethernet'}; my $host_fixedaddress = $dhcp_new_client{'fixed-address'}; $dbh = DBI->connect("DBI:Pg:dbname = net_clients", "$postgres_user"); $sth = $dbh->prepare("insert into dhcp_host values('$host_name', '$host_ipaddress', '$host_filename', '$host_group', '$host_option1', '$host_option2', '$host_option3', '$host_option4', '$host_macaddress', '$host_fixedaddress')"); $sth->execute || die $dhcp_Frame1_text = $dbh->errstr."\n Duplicate Host"; #$dbh->commit || die print STDOUT $dbh->errstr; $dbh->disconnect; } # ********* Dhcp subnet Defs to net_clients DB - pg - ********* sub dhcp_network_add { if ($dhcp_new_client{Subnet} eq "" || $dhcp_new_client{NetMask} eq "") { $dhcp_Frame1_text = "Empty Field"; return(); } $dbh = DBI->connect("DBI:Pg:dbname = net_clients", "$postgres_user"); $sth = $dbh->prepare("insert into dhcp_subnet values( '$dhcp_new_client{Subnet}', '$dhcp_new_client{NetMask}', '$dhcp_new_client{RangeStart}', '$dhcp_new_client{RangeEnd}', 'dhcp_new_client{Option1}', 'dhcp_new_client{Option2}', 'dhcp_new_client{Option3}', 'dhcp_new_client{Option4}')"); $sth->execute || die $dhcp_Frame1_text = $dbh->errstr."\n Duplicate SUBNET"; $dbh->disconnect; dhcp_clear_hash(); $dhcp_Frame1_text = "DHCP SUBNET Description FORM \n SUBNET ADDED TO DataBase"; } # ********* Dhcp Global Defs to net_clients DB - pg - ********* sub dhcp_global_add { if ($dhcp_new_client{Parameter} eq "" || $dhcp_new_client{Value} eq "") { $dhcp_Frame1_text = "ALL FIELDS MUST BE COMPLETED"; return(); } $dbh = DBI->connect("DBI:Pg:dbname = net_clients", "$postgres_user"); $sth = $dbh->prepare("insert into dhcp_global values( '$dhcp_new_client{Parameter}', '$dhcp_new_client{Value}')"); $sth->execute || die $dhcp_Frame1_text = $dbh->errstr."\n Duplicate PARAMETER"; #$dbh->commit || die print STDOUT $dbh->errstr; $dbh->disconnect; dhcp_clear_hash(); } # ********* Dhcp Group Defs to net_clients DB - pg - ********* sub dhcp_group_add { if ($dhcp_new_client{GroupName} eq "") { $dhcp_Frame1_text = "GroupName field must be completed"; return(); } $dbh = DBI->connect("DBI:Pg:dbname = net_clients", "$postgres_user"); $sth = $dbh->prepare("insert into dhcp_groups values( '$dhcp_new_client{GroupName}', '$dhcp_new_client{Option}', '$dhcp_new_client{Value}')"); $sth->execute || die $dhcp_Frame1_text = $dbh->errstr."\n Duplicate GROUP NAME"; #$dbh->commit || die print STDOUT $dbh->errstr; $dbh->disconnect; dhcp_clear_hash(); } # ******** Main_menubar_toggle **************** sub main_menubar_option_toggle { #$mainwindow->geometry(""); my $value = $_[0]; $Label1_text = "From Option toggle - $value"; cleanup_window(); if ($value eq "Users_Frame") { #cleanup_window(); users_frame(); #Frame1(); arp_report(); users_report(); #$mainwindow->geometry(""); } elsif ($value eq "Frame2") { #cleanup_window(); Frame2(); read_wm_sessions(); #gdm_managed_clients(); #$mainwindow->geometry(""); } elsif ($value eq "All Views") { #cleanup_window(); users_frame(); Frame2(); #Frame1(); arp_report(); read_wm_sessions(); #$mainwindow->geometry(""); } #$mainwindow->packPropagate(); #$mainwindow->geometry(""); #$mainwindow->raise(); $mainwindow->geometry("600x510+150+50"); #$mainwindow->packPropagate(); } sub cleanup_window { $Users_Frame->packForget() if Tk::Exists($Users_Frame); $Frame1->packForget() if Tk::Exists($Frame1); $Frame2->destroy() if Tk::Exists($Frame2); } # ************* Define all GUI elements *********************** # ************************************************************* sub about_window { # ************ Modal adout dialog *************** $about_dialog = $mainwindow->Toplevel(-background => "green"); $about_dialog->title("ABOUT SYSTEMPERL"); #$about_dialog-> grabGlobal(); $dismiss_btn = $about_dialog->Button(-text => "Dismiss", -command => sub {kill_about_dialog()}) ->pack(-side => 'bottom', -anchor => 's'); $about_text = $about_dialog->Text(-width => 40, -height => 15) ->pack(-side => 'top'); $about_text->insert('end', "July 2001 - Version 0.40\n\n"); $about_text->insert('end', "Program Written by Jim Massey\n\n"); $about_text->insert('end', "e-mail massey\@stlouis-shopper.com\n"); $about_text->insert('end', "http://stlouis-shopper.com/~jtjsoftware\n\n"); $about_text->insert('end', "Released under the GNU GPL\n"); $about_text->insert('end', "Use at your own risk\nI am not responsible for anything!\n"); $about_text->insert('end',"UCITA WARNING - do not use this program!"); $about_text->insert('end',"DMCA WARNING - do not use - this program has no use!"); $about_dialog->bell(); $about_dialog-> grab(); } sub kill_about_dialog { $about_dialog ->destroy() if Tk::Exists($about_dialog); } sub users_frame { # ********* Users_Frame stuff ************** $Users_Frame_text = "System User and Last output"; $Users_Frame = $mainwindow->Frame(-labelVariable => \$Users_Frame_text, -relief => 'groove', -borderwidth => 5, -background => 'yellow') ->pack(-side => 'bottom'); $Frame1 = $Users_Frame->Frame(-borderwidth => '5', -relief => 'groove', -background => "blue") ->pack(-side => "top", -fill => "x"); $Frame1_Update_btn = $Frame1->Button(-text => "SYSTEM Arp - Who", -command => sub {arp_report()}) ->pack(-side => "right"); $Frame1_users_btn = $Frame1->Button(-text => "SYSTEM- Users - Last", -command => sub {users_report()}) ->pack(-side => "left"); $users_Tbox = $Users_Frame->Scrolled("Text", -height => 12, -width => 80, -state => 'disabled') ->pack(-side => 'top'); $users_Tbox1 = $Users_Frame->Scrolled("Text", -height => 12, -width => 80, -state => 'disabled') ->pack(-side => 'bottom'); #$arp_Tbox = $mainwindow->Scrolled("Text", -height => 6, -state => 'disabled')->pack(-side => 'bottom', -anchor => 'center', -before => $Label1); $mainwindow->geometry(""); } sub Main_menubar { # ************** mainwindow Main_menubar ******************* $Main_menubar_frame = $mainwindow->Frame(-relief => 'ridge', -borderwidth => 5, -background => 'skyblue') ->pack(-side => 'top', -anchor => 'n', -expand => 1, -fill => 'x'); $Main_menubar_filebtn = $Main_menubar_frame->Menubutton(-text => "File", -tearoff => 0, -background => 'skyblue', -menuitems => ([ ['command' => "Exit", -command => sub {exit}] ]) ) ->pack(-side => 'left', -anchor => 'w'); $Main_menubar_optionbtn = $Main_menubar_frame->Menubutton(-text => "Options", -tearoff => 0, -background =>'skyblue', -menuitems => ([ ['command' => "View Users Frame", -command => sub {main_menubar_option_toggle("Users_Frame")}], ['command' => "Manage User Proccesses", -command => sub {main_menubar_option_toggle("Frame2")}], ['command' => "DHCP Window", -command => sub {dhcp_data()}], ['command' => "update Gdm Managed list", -command => sub {gdm_managed_clients()}] ]) ) ->pack(-side => 'left', -anchor => 'w'); $Main_menubar_helpbtn = $Main_menubar_frame->Menubutton(-text => "Help", -tearoff => 0, -background => 'skyblue', -menuitems => ([ ['command' => "Help Exists", -command => sub {arp_report()}], ['command' => "Exit", -command => sub {exit}], ['command' => "About", -command => sub {about_window()}] ]) ) ->pack(-side => 'right', -anchor => 'e'); } sub Frame2 { # ******* FRAME2 stuff ******* $Frame2 = $mainwindow->Frame(-label => "View Users Processes", -width =>20, -height =>50, -relief => 'ridge', -borderwidth => 5, -background => "yellow") ->pack(-side => 'bottom'); $Frame2_toolbar = $Frame2->Frame(-labelVariable => \$Frame2_toolbar_text, -relief => 'groove', -borderwidth => 5, -background => 'blue') ->pack(-side => 'top', -fill => 'both'); $Frame2_Entry1 = $Frame2_toolbar->Entry(-borderwidth =>5, -width => 18, -textvariable => \$Frame2_Entry1_value) ->pack(-side => 'left', -anchor => 'nw'); $Frame2_kill_btn = $Frame2_toolbar->Button(-text => "Kill Proccess", -command => sub {kill_proccess()}) ->pack(-side => 'left', -anchor => 'nw', -before => $Frame2_Entry1); $Frame2_refresh_view = $Frame2_toolbar->Button(-text => "Update Proccess View", -command => sub {read_wm_sessions()}) ->pack(-side => 'left', -expand => 1, -anchor => 'ne'); $Frame2_users_Tbox = $Frame2->Scrolled("Text", -height => 13, -width => 45, -relief => 'groove', -borderwidth => 5, -state => 'disabled') ->pack(-side => 'right', -anchor => 'se'); $Frame2_users_lbox = $Frame2->Scrolled("Listbox", -width => 30, -borderwidth => 5, -relief => 'groove', -selectmode => "single") ->pack(-side => 'left', -anchor => 'nw'); $Frame2_users_lbox->bind("", \&frame2_users_lbox_dblclick); $Frame2_gdm_Lbox = $Frame2->Scrolled("Listbox", -borderwidth => 1, -selectmode => "single", -width => 50) ->pack(-side => 'bottom', -before => $Frame2_users_lbox, -before => $Frame2_users_Tbox); $Frame2_gdm_Lbox->bind("", \&gdm_managed_lbox_dblclick); $balloon_help->attach($Frame2_gdm_Lbox, -balloonmsg => "Gdm Managed Clients\nDouble click to \nselect item for killing" ); #$Frame2_arp_Tbox = $Frame2->Scrolled("Text", # -height => 10, # -state => 'disabled') # ->pack(-side => 'bottom', # -before => $Frame2_users_lbox, # -before => $Frame2_users_Tbox); #$balloon_help->attach($Frame2_arp_Tbox, -balloonmsg => # "Gdm Managed Clients\nDouble click to \nselect item for killing" ); $balloon_help->attach($Frame2_users_lbox, -balloonmsg => "Double click to \nselect item for killing" ); $balloon_help->attach($Frame2_users_Tbox, -balloonmsg => "Users >= 500 proccess detail"); $mainwindow->geometry(""); } sub dhcp_data { # *********** DHCP Popupwindow **************** $dhcp_Frame1_text = "DHPC VIEWER "; $dhcp = $mainwindow->Toplevel(-background => 'skyblue'); $dhcp->title("Systemperl DHCP VIEWER"); $dhcp->geometry("650x350+150+50"); #$dhcp->configure(-minsize => 350,250); #$dhcp->packPropagate(1); $Frame1 = $dhcp->Frame(-background => 'skyblue', -labelVariable => \$dhcp_Frame1_text) ->pack(-side => 'top', -expand => 1, -fill => 'both'); $dhcp_menu_filebtn = $Frame1->Menubutton(-text => 'File', -background => 'skyblue', -tearoff => 0, -menuitems => [ ['command' => "Exit window", -command => sub{$dhcp->destroy()}] ]) ->pack(-side => 'left'); $dhcp_menu_optionbtn = $Frame1->Menubutton(-text => 'View', -background => 'skyblue', -tearoff => 0, -menuitems => [ ['command' => 'DHCP.CONF', -command => sub {dhcp_toggle("CONFIG")}], ['command' => 'DHCP.LEASES', -command => sub {dhcp_toggle("LEASES")}], ['command' => 'HOSTS File', -command => sub {dhcp_toggle(HOSTS)}] ]) ->pack(-side => 'left'); $dhcp_menu_Editbtn = $Frame1->Menubutton(-text => 'Edit', -background => 'skyblue', -tearoff => 0, -menuitems => [ ['command' => 'DHCP.CONF', -command => sub {dhcp_conf_edit()}], ['command' => 'EDIT HOSTS file', -command => sub {dhcp_hosts_edit()}], ['command' => 'ADD CLIENT DIRECTLY', -command => sub {dhcp_entery_form("file")}], ['command' => 'Build DHCP.CONF', -command => sub {dhcp_conf_build()}] ]) ->pack(-side => 'left'); $dhcp_menu_Formsbtn =$Frame1->Menubutton(-text => 'Entry Forms', -background => 'skyblue', -tearoff => 0, -menuitems => [ ['command' => 'Add New Client DB', -command => sub {dhcp_entery_form("db")}], ['command' => 'Subnet Defs', -command => sub {dhcp_network_form()}], ['command' => 'Global Defs', -command => sub {dhcp_global_form()}], ['command' => 'Group Defs', -command => sub {dhcp_group_form()}] ]) ->pack(-side => 'left'); $dhcp_Tbox = $dhcp->Scrolled('Text', -height => 20, -width => 80, -state => 'disabled') ->pack(-side => 'bottom'); $dhcp->grab(); dhcp_toggle("LEASES"); } sub dhcp_Tbox_entry1 { $dhcp_Tbox = $dhcp->Scrolled('Text', -background => 'yellow', -height => 25, -width => 55, -state => 'disabled') ->pack(-side => 'bottom'); $dhcp->geometry(""); } sub dhcp_Tbox { $dhcp_Tbox = $dhcp->Scrolled('Text', -height => 20, -width => 80, -state => 'disabled') ->pack(-side => 'bottom'); #$dhcp_Tbox->packPropagate(0); $dhcp->geometry(""); }