#!/usr/bin/perl my $KSDIR = "/home/KickStart/cfg"; my $KSCONFIG = "$KSDIR/ks.config"; my $CONFIGD = "$KSDIR/config.d"; my $ACTIVED = "$KSDIR/ks.d"; my @HDTYPES = ( "prompt", "sd", "hd", "hdc" ); my @FWTYPES = ( "disable", "medium", "high" ); my @SELINUX = ( "disabled", "permissive", "enforcing" ); my @SETYPES = ( "targeted", "strict" ); my @TZONES = ( "US/Arizona", "US/Eastern", "US/Hawaii", "US/Pacific", "US/Central", "US/East-Indiana", "US/Indiana-Starke", "US/Mountain" ); my $DISCOLS = 3; my $STAGES; $STAGES->{1}->{suffix} = "P"; $STAGES->{1}->{desc} = "Pre"; $STAGES->{2}->{suffix} = "S"; $STAGES->{2}->{desc} = "Post (chroot)"; $STAGES->{3}->{suffix} = "N"; $STAGES->{3}->{desc} = "Post (No chroot)"; my $ks; my $cnt; my $run; print "Content-type: text/html\n\n"; print "\n"; print "\n"; print " iGlass KickStart Config \n"; print "\n"; print "\n"; print "

iGlass KickStart Config

\n"; # Make changes if any my @stdin = ; if ( @stdin ) { my $rlst; my $clst; print "
\n" if $DEBUG;
   foreach my $line ( @stdin ) {
      foreach my $pair ( split(/\&/,$line) ) {
         $pair = URLDecode($pair);
         if ( $pair =~ /^CF\+(\S+)=(.+)$/ ) {
            print "file $1 = $2\n" if $DEBUG;
            $rlst->{$1} = $2;
         } elsif ( $pair =~ /^(\S+)=(.+)$/ ) {
            print "config $1=$2\n" if $DEBUG;
            $clst->{$1} = $2;
         }
      }
   }

   if ( open(RC, "$KSCONFIG") ) {
      my @configs = ;
      close RC;
      system("cp", "-a", "$KSCONFIG.2", "$KSCONFIG.3");
      system("cp", "-a", "$KSCONFIG.1", "$KSCONFIG.2");
      system("cp", "-a", "$KSCONFIG",   "$KSCONFIG.1");
      if ( open(WC, ">$KSCONFIG") ) {
         foreach ( @configs ) {
            if ( /^(\w+)\=(.+)$/ ) {
               if ( exists $clst->{$1} ) {
                  print WC "$1=$clst->{$1}\n";
                  delete $clst->{$1};
               } else {
                  print WC "$1=$2\n";
               }
            } else {
               print WC "$_";
            }
         }
         foreach $new ( keys %{$clst} ) {
            print WC "$new=$clst->{$new}\n";
         }
      } else {
         print "Erorr: Could not open $KSCONFIG for read\n";
      }
      close WC;
   } else {
      print "Erorr: Could not open $KSCONFIG for write\n";
   }

   if ( opendir(CD, "$CONFIGD") ) {
      my @fileList = grep(!/^\./, readdir(CD));
      close CD;
      foreach my $file ( @fileList ) {
         if ( $file =~ /^(\w)(\d+.+)$/ ) {
            print "$file: " if $DEBUG;
            if ( -e "$ACTIVED/$file" ) {
               if ( exists $rlst->{$file} ) {
                  print " Is turned on and should be turned on\n" if $DEBUG;
               } else {
                  print " Is turned on and should be turned off\n" if $DEBUG;
                  unlink("$ACTIVED/$file");
               }
            } else {
               if ( exists $rlst->{$file} ) {
                  print " Is turned off and should be turned on\n" if $DEBUG;
                  symlink("$CONFIGD/$file", "$ACTIVED/$file");
               } else {
                  print " Is turned off and should be turned off\n" if $DEBUG;
               }
            }
   
         } elsif ( $file =! /^HEADER/ ) {

         } else {
            print "

Warning: What is this file $CONFIGD/$file

\n"; } } } else { print "

Erorr: Could not open directory $CONFIGD

\n"; } print "
\n" if $DEBUG; } # Get current setup if ( open(C, "$KSCONFIG") ) { print "
\n" if $DEBUG;
   while (  ) {
      if ( (/^\s*$/) || (/^\s*#/) ) {
         next;
      } elsif ( /^(\w+)\=(.+)$/ ) {
         $ks->{$1} = $2;
         print "$1 == $ks->{$1}\n" if $DEBUG;
      }
   }
   print "
\n" if $DEBUG; close C; } else { print "Erorr: Could not open $KSCONFIG\n"; } if ( opendir(CD, "$CONFIGD") ) { foreach my $file ( grep(!/^\./, readdir(CD)) ) { if ( $file =~ /^([PSN])(\d+)(.+)$/ ) { my $act = $1; $run->{$act}->{$file}->{num} = $2; $run->{$act}->{$file}->{name} = $3; $run->{$act}->{$file}->{run} = ''; if (exists $cnt->{$act}) { ++$cnt->{$act}; } else { $cnt->{$act} = 1; } if ( open(F, "$CONFIGD/$file") ) { while ( ) { if ( /^#\s+description:\s*(.+)/ ) { $run->{$act}->{$file}->{desc} = $1; last; } } close F; } else { print "

Warning: Could not read file $CONFIGD/$file

\n"; } } elsif ( $file =! /^HEADER/ ) { } else { print "

Warning: What is this file $CONFIGD/$file

\n"; } } close CD; } else { print "

Erorr: Could not open directory $CONFIGD

\n"; } if ( opendir(AD, "$ACTIVED") ) { foreach my $file ( grep(!/^\./, readdir(AD)) ) { if ( ($file =~ /^([PSN])\d+.+$/) && (exists $run->{$1}->{$file}) ) { $run->{$1}->{$file}->{run} = 'checked'; } elsif ( $file =! /^HEADER/ ) { } else { print "

Warning: What is this file $ACTIVED/$file

\n"; } } close AD; } else { print "

Erorr: Could not open directory $ACTIVED

\n"; } # Start the form print "
\n"; print "
\n"; print "Disk device type: "; foreach my $type ( @HDTYPES ) { my $checked; if ( $type eq $ks->{DISKTYPE} ) { $checked = "checked"; } print " $type \n"; } print "

\n"; print "Time Zone: \n"; print "

\n"; print "Firewall setting: "; foreach my $type ( @FWTYPES ) { my $checked; if ( $type eq $ks->{FIREWALL} ) { $checked = "checked"; } print " $type \n"; } print "

\n"; print "SELinux setting: "; foreach my $type ( @SELINUX ) { my $checked; if ( $type eq $ks->{SELINUX} ) { $checked = "checked"; } print " $type \n"; } print "

\n"; { # password print "Grub and root MD5 password hash: {MD5PASS}\">\n"; } print "

\n"; { # interactive print "Prompt for settings? "; if ( $ks->{INTERACTIVE} =~ /^y/ ) { print " Yes\n"; print " No\n"; } else { print " Yes\n"; print " No\n"; } } print "

\n"; { # reboot print "Reboot when done? "; if ( $ks->{REBOOT} =~ /^y/ ) { print " Yes"; print " No\n"; } else { print " Yes"; print " No\n"; } } print "

\n"; { # pre-scripts print "Run Pre-scripts? "; if ( $ks->{PRE} =~ /^y/ ) { print " Yes"; print " No\n"; } else { print " Yes"; print " No\n"; } } print "

\n"; { # post-scripts print "Run Post-scripts? "; if ( $ks->{POST} =~ /^y/ ) { print " Yes"; print " No\n"; } else { print " Yes"; print " No\n"; } } print "

\n"; { # post-nochroot-scripts print "Run Post-nochroot-scripts? "; if ( $ks->{POSTNR} =~ /^y/ ) { print " Yes"; print " No\n"; } else { print " Yes"; print " No\n"; } } print "

\n"; print ""; print "
"; print "

Add/Del Probe Config

\n"; print "
\n"; print "


\n"; foreach $stage ( sort keys %{$STAGES} ) { print "\n"; print "\n"; print ""; print "
$STAGES->{$stage}->{desc}
"; my $i; foreach my $file ( sort keys %{$run->{$STAGES->{$stage}->{suffix}}} ) { if ( defined $i ) { if ( $i > ($cnt->{$STAGES->{$stage}->{suffix}}/$DISCOLS) ) { print "
"; $i = 1; } else { ++$i; } } else { $i = 1; } my $pdesc; if ( defined $run->{$STAGES->{$stage}->{suffix}}->{$file}->{desc} ) { $pdesc = $run->{$STAGES->{$stage}->{suffix}}->{$file}->{desc}; } else { $pdesc = $run->{$STAGES->{$stage}->{suffix}}->{$file}->{name}; } print "\n"; } print "
{$STAGES->{$stage}->{suffix}}->{$file}->{run} /> $run->{$STAGES->{$stage}->{suffix}}->{$file}->{num} - $pdesc
\n"; print "


\n"; } print "
\n"; print "

View ks.cfg

\n"; print "\n"; sub URLDecode { my $url = shift; $url =~ tr/+/ /; $url =~ s/%([a-fA-F0-9]{2,2})/chr(hex($1))/eg; $url =~ s///g; return $url; } sub URLEncode { my $url = shift; my $MetaChars = quotemeta( ';,/?\|=+)(*&^%$#@!~`:'); $url =~ s/([$MetaChars\"\'\x80-\xFF])/"%" . uc(sprintf("%2.2x",ord($1)))/eg; $url =~ s/ /\+/g; return $theURL; }