CfgTie

 view release on metacpan or  search on metacpan

bin/DNS-find-free  view on Meta::CPAN

 else
  {print "Sorry, none of the address spaces work\n";}

if (exists $MyArgs{'swip-output'})
{
    SWIP_Gen(\%SReq, $MyArgs{'swip-input'}, $MyArgs{'swip-output'});
}


#Find the first free rang in the address block
sub find_first_free($$)
{
   my ($A,$Num)=@_;
   for(my $I=1; $I<255-$Num+1;$I++)
    {
       #Check to see if the first item is already used
       if (exists $A->{$I}) {next;}

       #Okay, the first item is not already used.. check the next few
       my $T=0;
       for(my $J=$I+1; $J<$I+$Num; $J++)
        {
	    if (exists $A->{$J}) {$T=1;}
        }
       if (!$T) {return $I;}
    }

   undef;
}

sub ARIN_scan($$)
{
   #Scans an ARIN file, placing the relevant information in S
   #Example: ARIN_Scan(\%MyHash,'file');
   my ($S,$Name)=@_;

   if (!-e $Name) {Fatal(FILE_NEXIST, $Name);}

   my $ARIN=$FNum++;
   open ARIN, "<$Name";

cgi/sys.cgi  view on Meta::CPAN

use 5.004;
use strict;
use CfgTie::TieGeneric;
my %Gen;
tie %Gen, 'CfgTie::TieGeneric';
my $pathinfo;
my $Base0="http://xiotech.com/~randym";
my $CSS="$Base0/CfgTie.css";
my $Base="$Base0/sys.cgi/";

sub redirect($) {exec ("cat ".shift);}
sub Untaint_path($) {$_[0]=~ s/^(.*)$/$1/;}

sub Prefixes_To_Avoid($)
{
   my $self=shift;
   #Avoid anything that starts with act-
   if ($self->{'name'} =~ /^act-/i) {return 0;}
   return 1;
}

sub Gen_print($$)
{
   my ($Space,$Name)= @_;

   #If the user does not exists, gripe
   if ( (defined $Space && $Space && length $Space &&  !exists $Gen{$Space}) ||
	(defined $Name && $Name && !exists $Gen{$Space}->{$Name}))
     {
	#Carlington miniscule
	my $Thingy=$Space;
        if ($Space=~/^(\w)(\w+)/) {my $a=$1;$a=~tr/a-z/A-Z/;$Thingy=$a.$2;}

lib/CfgTie/CfgArgs.pm  view on Meta::CPAN

#       elsif (!exists $N->{VALUE}
#       else {save this for later...}
    }
}

#while <F>
#  Args_parse(split /(?:\\)\s/);
#}


sub Help()
{
   #This returns a text string describing the flags.  It is meant to help
   #put together a command line tool help message
   my $L="\t    ";
   "Main operation mode:\n".
   "$L--op=set|unset|remove|delete|exists|fetch|get|copy|rename\n".
   "$L--copy   name1=name2 name3=name4 ...\n".
   "$L--delete name1 name2 ...\n".
   "$L--exists name1 name2 name3 ...\n".
   "$L--fetch  name1 name2 name3 ...\n".

lib/CfgTie/Cfgfile.pm  view on Meta::CPAN

       #Check to see if we need an initial description.
       if (!defined $Obj->comments) {@Args=(@Args, '-t-');}
#       print "Checkin' in\n";
       $Obj->ci(@Args);
    }
   %Files2CheckIn=();
}

__END__

sub RCS_Handshake($)
{
   my $self=shift;
   if (!exists $self->{RCS}) {return;}

   my $RObj = $self->{RCS};
   if (defined $RObj->comments)
     {
        my $locker = $RObj->lock;

        #Do we need to check it out?

lib/CfgTie/Cfgfile.pm  view on Meta::CPAN

   my ($self,$key) = @_;
   return exists $self->{Contents}->{$key};
}

sub FETCH
{
   my ($self,$key)=@_;
   return $self->{Contents}->{$key};
}

sub Queue_Delete($$)
{
   my ($self,$key) = @_;

#   print "Queuing a delete for $key\n";

   #If there is a value it is supposed to be associated with, remove it, and
   #queue it for later
   $self->{Queue}->{$key} ='';
}

sub Queue_Store($$$)
{
   my ($self,$key,$val) = @_;

   #If there is a value it is supposed to be associated with, override it, and
   #queue it for later
   $self->{Queue}->{$key} = $val;
}

sub DELETE
{
   my ($self,$key)=@_;
   #Queue this for later.

   #Remove it from our current set of values
   if (exists $self->{Contents}->{$key}) {delete $self->{Contents}->{$key};}

   Queue_Delete($self, $key);
}

sub STORE_cheap($$)
{
   my ($self,$val) = @_;
   #if we add something, and it is not in the DB, we have it easy...
   #we just append it to the end of the file and run newaliases
   #It is not completely cheap since we run new aliases...

   #Do the append
   eval '$self->cfg_begin();';

   #Check with the revision control system

lib/CfgTie/Cfgfile.pm  view on Meta::CPAN

               }
          }\n";
#Could be faster with an 'else'..
    }

   $Sub.="   }\n";
   eval "$Sub";
#die "$Sub\n $@\n";
}

sub Comment_Add($$)
{
   #This appends the comments to the set of comments for this revision
   my ($self,$Cmt) = @_;
   if (exists $self->{Comments})
     {$self->{Comments} .= "$Cmt\n";}
    else
     {$self->{Comments} = "$Cmt\n";}
}

#Some HTML helpers

lib/CfgTie/TieAliases.pm  view on Meta::CPAN

}

sub cfg_end
{
   my $self = shift;
   if (exists $self->{Path} && $self->{Path} eq '/etc/aliases')
     {CfgTie::filever::system("/usr/bin/newaliases");}
#    else {print "Not a path for newaliases\n";}
}

sub format($$)
{
   my ($self,$key,$value)=@_;
   "$key: ".join(',',@{$value})."\n";
}

#sub is_tainted {not eval {join('',@_),kill 0; 1;};}

sub makerewrites
{
   my ($self) = @_;

lib/CfgTie/TieAliases.pm  view on Meta::CPAN

   $Rules .="\n   \$_;\n};\n";
   $@='';
#   if (&is_tainted($Rules))
#       {die "Rules for updating aliases file are tainted\n";}
#    else
     {eval $Rules;}
   if (defined $@ && length $@) {die "rewrite rules compilation failed: $@";}
   return $Sub;
}

sub ImpGroups(&$)
{
   my ($CodeRef,$Ref)=@_;
   #Create a list of group names that pass the selection criteria
   #The code ref is passed a reference to the group information
   my %groups;
   use CfgTie::TieGroup;
   tie %groups, 'CfgTie::TieGroup';

   if (!defined $CodeRef)
     {

lib/CfgTie/TieGeneric.pm  view on Meta::CPAN


        #Tie in the key
        tie %{$self->{Contents}->{$key}}, $A,$B;
     }
   if (exists $self->{Cache}->{$key}) {return $self->{Cache}->{$key};}
   #Try to get the local thing first
   if (exists $self->{Contents}->{$key}) {return $self->{Contents}->{$key};}
   return undef;
}

sub HTML($)
{
   my $self=shift;
   my $A='';
   for (my $I=FIRSTKEY($self); $I; $I=NEXTKEY($self,$I))
    {
       $A.="<tr>".CfgTie::Cfgfile::td("<a href=\"$I\">$I</a>")."</tr>";
    }
   CfgTie::Cfgfile::table('Directory',$A,1);
}

lib/CfgTie/TieGroup.pm  view on Meta::CPAN

   my $name = shift;

   #Basically delete the group now.
   CfgTie::filever::system("$CfgTie::TieGroup_rec'groupdel $name");

   #Remove it from our cache
   if (exists $CfgTie::TieGroup_rec'by_name{$name})
     {delete $CfgTie::TieGroup_rec'by_name{$name};}
}

sub HTML($$)
{
   my ($self,$CodeRef)=@_;
   my %A;
   for (my $I=FIRSTKEY($self); $I; $I=NEXTKEY($self,$I))
    {
       my $U=FETCH($self,$I);
       #See if the caller wants us to pass
       if (defined $CodeRef && !&$CodeRef($U)) {next;}
       $A{$I} = CfgTie::Cfgfile::trx(
		"<a href=\"group/$I\">$I</a>",

lib/CfgTie/TieGroup.pm  view on Meta::CPAN

   else
        {
           #Just remove our local copy
           delete $self->{$lkey};
        }
}


sub trx   {CfgTie::Cfgfile::trx(@_);}
sub table {CfgTie::Cfgfile::table(@_);}
sub HTML($)
{
   # A routine to HTMLize the user
   my $self=shift;

   my %Keys2 = map {$_,1} (keys %{$self});

   delete $Keys2{name};
   delete $Keys2{id};
   delete $Keys2{password};
   delete $Keys2{members};

lib/CfgTie/TieGroup.pm  view on Meta::CPAN

                 'passwd' =>$x[1],
                 'id'     =>$x[2],
                 'members'=>[split(/(?:\s+|\,)/, $x[3])]
              };
         }
   }

   $F->close;
}

sub format($$)
{
   "$_[1]: ".join(',',@{$_[1]})."\n";
}

lib/CfgTie/TieMTab.pm  view on Meta::CPAN

   my $dev = Quota::getdev($path);

   #If it failed, it does not exist
   if (!defined $dev) {return undef;}

   if (!exists $by_dev{$dev}) {$by_dev{$dev}=[$dev];}

   $by_dev{$dev};
}

sub MTab_scan()
{
   Quota::setmntent();
   while (my @A=Quota::getmntent())
    {
       $by_dev {$A[0]}=\@A;
       $by_path{$A[1]}=\@A;	 
    }
   Quota::endmntent();
}

lib/CfgTie/TieNamed.pm  view on Meta::CPAN

#       $AUTOLOAD eq 'reload'|| $AUTOLOAD eq 'status')
#     {
#        return (tied $serv)->$AUTOLOAD(@_);
#     }

   #Pass the message along
#   $self->{delegate}->$AUTOLOAD(@_);
#}

#List the reverses addresses spaces we primary (except loopback)
sub RevSpaces($)
{
   my $self=shift;

   # Get the goodies of the real deal
#   if (exists $self->{delegate}) {$self = $self->{delegate};}

   my $P=$_;
   my @Ret;
   foreach $_ (keys %{$self->{Contents}->{primary}})
    {
       if (/^0.0.127\.in-addr\.arpa$/i) {next;}
       if (/\.in-addr\.arpa$/i) {push @Ret, $_;}
    }
   $_=$P;
   @Ret;
}

#List the name spaces that we primary (except loopback and the reverse)
sub FwdSpaces($)
{
   my $self=shift;

   my $P=$_;
   my @Ret;
   foreach $_ (keys %{$self->{Contents}->{primary}})
    {
       if (/\.in-addr\.arpa$/i) {next;}
       push @Ret,$_;
    }

lib/CfgTie/TieNamed.pm  view on Meta::CPAN

     }
   "$Ret</table>\n";
}

package CfgTie::TieNamed_primary;
@ISA=qw(CfgTie::Cfgfile);
#A tie hash for a single primary file...

my @days_per_month=(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

sub SerialNum_next($)
{
   # A routine to guess the human format of the serial number and come up with
   # the next one.  The minimal rule here is that the returned value will be
   # no matter what, greater than the previous one.
   # We are allowed 9 digits in base 10.
   my $SN = shift;

   my ($sec,$min,$hour,$MDay,$Month,$Year,$WDay,$YDay,$isDST)=localtime;

   #Try YEAR-MONTH-DayOfMonth-Rev

lib/CfgTie/TieRCService.pm  view on Meta::CPAN


sub FETCH
{
   my $self=shift;
   my $key = shift;
   return $Services{$key};
}

sub trx {CfgTie::Cfgfile::trx(@_);}
sub table {CfgTie::Cfgfile::table(@_);}
sub num2chk($)
{
   my @Ret;
   foreach my $I (@{$_[0]})
    {
       if ($I) 
         {push @Ret, "<font face=\"Wingdings\">x</font>";}
        else
         {push @Ret, "<font face=\"Wingdings\"> </font>";}
    }
}

lib/CfgTie/TieRCService.pm  view on Meta::CPAN

    foreach my $I (sort keys %Services)
     {$A.= trx("<a href=\"runlevel/$I\">$I</a>",@{$Services{$I}->{levels}});}

   table("Run levels",
   "<tr><th>Service</th><th>0</th><th>1</th><th>2</th><th>3</th><th>4</th>".
   "<th>5</th><th>6</th><th>7</th><th>8</th><th>9</th></tr>\n$A",11);
}

package CfgTie::TieRCServ_rec;

sub proc_sig($$)
{
   my $pid = proc_id($_[0]);

   if (defined $pid)
     {
        kill $_[1], $pid;
        return 1;
     }
    return -1;
}

sub scan_for_script($$)
{
   my ($serv, $path) = @_;
   $FNum++;
   opendir FNum, $path;
   my @RCfiles = grep {/^$serv$/} (readdir(FNum));
   closedir FNum;
   if (!scalar @RCfiles) {return;}
   my ($R) = @RCfiles;
   $R;
}

sub scan_rcscript($)
{
   my $self=shift;
   my $F = new Secure::File "<".$self->{'path'};
   while (<$F>)
    {
       if (/^\s*\#\s*chkconfig\s*:\s*(\d+)/i) 
         {
	    my @A=(0,0,0,0,0,0,0,0,0,0);
            for (my $I=0; $I< length $1; $I++)
             {$A[substr($1,$I,1)]=1;}

lib/CfgTie/TieRCService.pm  view on Meta::CPAN

{
   my ($self,$name,$levels)=@_;
   my $Node =
 	{
	    levels=>$levels,'name'=>$name,
	};

   return bless $Node, $self;
}

sub proc_id($)
{
   my $key = shift;

   if (!defined $key || !-e "/var/run/$key.pid") {return undef;}

   #use the canonically process ID
   my $F = new Secure::File "</var/run/$key.pid" or return undef;
   my ($I,$pid);
   while (<$F>)
    {
       if (/^(\d+)$/) {$pid=$1;}
    }
   $F->close;
   return $pid;
}

sub _stat($)
{
   my $self=shift;
   if (!defined $self) {return undef;}
   return stat("/var/run/".$self->{'name'}.".pid");
}

sub EXISTS ($$)
{
   my ($self,$key)=@_;
   my $lkey=lc($key);

lib/CfgTie/TieRCService.pm  view on Meta::CPAN

            "   my \$self = shift;\n".
	    "   delete \$self->{pid};\n".
	    "   delete \$self->{'stat'};\n".
            "   if (exists \$self->{path})\n".
            "     {return system(\$self->{path}.\" $I\");}\n".
            "}\n\n";
    }
   eval $X;
}

sub reload($)
{
   my $self=shift;
   delete $self->{pid};
   delete $self->{status};
   if (-x "/usr/sbin/".$self->{'name'}.".reload")
     {
        return system("/usr/sbin/".$self->{'name'}.".reload");
     }
    else
     {

lib/CfgTie/TieUser.pm  view on Meta::CPAN


=head1 Author

Randall Maas (L<randym@acm.org>)

=cut

my $Chg_FS = 1; #By default we want to update the file system when the user
# Id changes

sub stat($)
{
  # the information for the /etc/passwd file
  stat '/etc/passwd';
}

sub TIEHASH
{
   my $self = shift;
   my $node = {};
   return bless $node, $self;

lib/CfgTie/TieUser.pm  view on Meta::CPAN

   my $name = shift;

   #Basically delete the user now.
   CfgTie::filver::system("$CfgTie::TieUser_rec'userdel $name");

   #Remove it from our cache
   if (exists $CfgTie::TieUser_rec'by_name{$name})
     {delete $CfgTie::TieUser_rec'by_name{$name};}
}

sub HTML($$)
{
   my ($self,$CodeRef)=@_;
   my %A;
   for (my $I=FIRSTKEY($self); $I; $I=NEXTKEY($self,$I))
    {
       my $U=FETCH($self,$I);
       #See if the caller wants us to pass
       if (defined $CodeRef && !&$CodeRef($U)) {next;}
       $A{$I} = CfgTie::Cfgfile::trx(
		"<a href=\"user/$I\">$I</a>",

lib/CfgTie/TieUser.pm  view on Meta::CPAN

		"<a href=\"mailto:$I\">$I</a>"
		);
    }
   my $Us;
   foreach my $I (sort keys %A) {$Us.=$A{$I};}
   CfgTie::Cfgfile::table('Users',
	"<th class=\"cfgattr\">login</th><th class=\"cfgattr\">Full Name</th>".
	 "<th class=\"cfgattr\">mailto:</th></tr>\n".$Us, 3);
}

sub add_scalar($$)
{
   my ($name,$package) =@_;
   $name=lc($name);
   $CfgTie::TieUser_rec::SDelegates->{$name}=$package;
}

sub add_hash($$)
{
   my ($name,$package) =@_;
   $name=lc($name);
   $CfgTie::TieUser_rec::HDelegates->{$name}=$package;
}

package CfgTie::TieUser_id;

sub status
{

lib/CfgTie/TieUser.pm  view on Meta::CPAN

   #while ($a = scalar each %{$EKeys})
   # {
   #    if (exists $self->{$a}) {next;}
   #    return $a;
   # }
   return $a;
}

#Modified from PERL Cookbook:
my $lastlog_fmt="L a16 A16"; #on sunos "L A8 A16"
sub lastlog_FETCH($)
{
   use User::pwent;
   use IO::Seekable qw(SEEK_SET);

   my $LASTLOG= new Secure::File "</var/log/lastlog";
   return unless defined $LASTLOG;

   my $User = shift;
   my $U = ($User =~ /^\d+$/) ? getpwuid($User) : getpwnam($User);
   if (!$U) {goto ret_from_here;}

lib/CfgTie/TieUser.pm  view on Meta::CPAN

        }
   else
        {
           #Just remove our local copy
           delete $self->{$lkey};
        }
}

sub trx {CfgTie::Cfgfile::trx(@_);}

sub HTML($)
{
   # A routine to HTMLize the user
   my $self=shift;

   my %Keys2 = map {$_,1} (keys %{$self});
   $Keys2{'last'}=1;

   delete $Keys2{gcos};
   delete $Keys2{name};
   delete $Keys2{id};

lib/CfgTie/TieUser.pm  view on Meta::CPAN

  {
     #Add the quota stuff in
     $CfgTie::TieUser_rec::HDelegate{'usage'}='CfgTie::TieUser_quota_usage';
     $CfgTie::TieUser_rec::HDelegate{'limits'}='CfgTie::TieUser_quota_limits';
     $CfgTie::TieUser_rec::HDelegate{'timeleft'}='CfgTie::TieUser_quota_timeleft';
    }

my $DB={usage=>{},timeleft=>{},limits=>{}};
1;

sub Query($$)
{
   #A wrapper around the Quota::query routine... converts into our internal
   #usage form

   my ($uid,$dev) = @_;

   #Get the information
   my ($Block_Curr, $Block_Soft, $Block_Hard, $Block_TimeLeft,
       $INode_Curr, $INode_Soft, $INode_Hard, $INode_TimeLeft) =
	 Quota::query($dev,$uid);

lib/CfgTie/TieUser.pm  view on Meta::CPAN

   

   if (exists $DB->{$key} && exists $DB->{$key}->{$self->{uid}}->{$dev})
   {
       return $DB->{$key}->{$self->{uid}}->{$dev};
   }
   undef;
}

package CfgTie::TieUser_quota_limits;
sub new(@_)     {TIEHASH(@_);}
sub TIEHASH     {return bless {uid=>$_[1]}, $_[0];}
sub EXISTS ($$) {CfgTie::TieUser_quota::Exists($_[0],'limits',$_[1]);}
sub FETCH ($$)  {CfgTie::TieUser_quota::Fetch($_[0],'limits',$_[1]);}

sub STORE ($$)
{
   my ($self,$key,$val)=@_;

   #Convert the path into q form that can be used in a query
   #(The representation will vary with each system)
   #The key is the path
   my $dev = Query::getqcarg($key);
  
   #clear out the keys
   delete $limits{$self->{uid}};

   Quota::setqlim($dev, $self->{uid}, @{$val});
}

package CfgTie::TieUser_quota_usage;
sub new(@_)     {TIEHASH(@_);}
sub TIEHASH     {return bless {uid=>$_[1]}, $_[0];}
sub EXISTS ($$) {CfgTie::TieUser_quota::Exists($_[0],'usage',$_[1]);}
sub FETCH ($$)  {CfgTie::TieUser_quota::Fetch ($_[0],'usage',$_[1]);}

package CfgTie::TieUser_quota_timeleft;
sub new(@_)     {TIEHASH(@_);}
sub TIEHASH     {return bless {uid=>$_[1]}, $_[0];}
sub EXISTS ($$) {CfgTie::TieUser_quota::Exists($_[0],'timeleft',$_[1]);}
sub FETCH ($$)  {CfgTie::TieUser_quota::Fetch ($_[0],'timeleft',$_[1]);}

package CfgTie::TieUser_file;
use CfgTie::Cfgfile;
@ISA=qw(CfgTie::Cfgfile);

sub files
{

lib/CfgTie/TieUser.pm  view on Meta::CPAN

                 'passwd' =>$x[1],
                 'id'     =>$x[2],
                 'members'=>[split(/(?:\s+|\,)/, $x[3])]
              };
         }
   }

   $F->close;
}

sub format($$)
{
   "$_[1]: ".join(',',@{$_[1]})."\n";
}

lib/CfgTie/filever.pm  view on Meta::CPAN

  if (!defined $Num) {$Num = $RollDepth;}

  if ($Num < 1) {return;}

  my $Base = $File.$Sep;
  rename $Base.'1',$File;
  for (my $I=1; $I < $RollDepth; $I++)
   {rename $Base.($I+1),$Base.$I;}
}

sub RCS_path($$)
{
   my ($RCSObj, $Path) = @_;
   if ($Path =~ /^(.+)\/([^\/]+)$/)
     {
        $RCSObj->workdir($1);
        $RCSObj->file($2);

        #Make the working directory and archive directory make sense
        my $t = $RCSObj->rcsdir;
        if (!defined $t || (substr($t,0,1) ne '/' && substr($1,0,1) ne '.'))

lib/CfgTie/filever.pm  view on Meta::CPAN


     }
    else
     {
        $RCSObj->file($Path);
     }
}

use FileHandle;

sub open($)
{
   local($name)=@_;
   #Save the environment so we can restore it
   my $E=\%ENV;

   #Erase the path, and other environment information
   %ENV=();
   $ENV{'PATH'}='/bin:/sbin';
   my $F=eval ('new FileHandle $name');

   #Restore the environment
   %ENV=%{$E};
   $F;
}

sub system($)
{
   my $F= &filever::open($_[0]."|");
   $F->close;
}


my @UID_paths; # Holder of file paths that match 

sub UID_worker
{

lib/Secure/File.pm  view on Meta::CPAN

     }
   return 0 unless @S;
   if ($self->handle_check(@S))
     {
        return $self;
     }
   $self->close();
   return 0;
}

sub open_precheck($$)
{
   my $name=shift;
   if ($name =~ /^<\s*([^\s]+)$/)
        {
	   r_check($1);
	}
   elsif ($name =~ /^>\s*([^\s]+)$/)
        {
	   w_check($1);
        }



( run in 1.152 second using v1.01-cache-2.11-cpan-65fba6d93b7 )