#!/usr/local/bin/perl -w use strict; my $VERSION = '2.0.0.0043'; my $usage = <<"EOM"; Usage: cmd_admin.pl Password=MyPassword listrealms cmd_admin.pl Password=MyPassword rebuild "My Realm 1" cmd_admin.pl Password=MyPassword rebuild "All" cmd_admin.pl Password=MyPassword listrules cmd_admin.pl Password=MyPassword setrule "crawler: rogue" 1 This script is a general example of how to use FDSE as an API. EOM # Step 1. general preparation: if ($ENV{'SERVER_SOFTWARE'}) { print "Warning: You have ENV SERVER_SOFTWARE defined. Unset it.\n"; print "Content-Type: text/html\n\n"; print "This script can only be called from the command-line. Sorry.\n"; exit; } unless ((@ARGV) and ($ARGV[0] =~ m!^Password=.+$!) and ($ARGV[1])) { die $usage; } # Step 2. define code to be executed inside of FDSE admin module: use vars qw! $FDSE_CALLBACK_SUB !; $FDSE_CALLBACK_SUB = <<'EOC'; $const{'is_cmd'} = 1; my $action = $ARGV[1] || ''; if ($action eq 'listrealms') { my $p_realm_data = (); foreach $p_realm_data ($realms->listrealms('all')) { print "Realm: $$p_realm_data{'name'}\n"; } } elsif ($action eq 'rebuild') { $FORM{'Action'} = 'rebuild'; if (lc($ARGV[2]) eq 'all') { my $p_realm_data = (); foreach $p_realm_data ($realms->listrealms('all')) { delete $FORM{'LimitSite'}; delete $FORM{'StartTime'}; $FORM{'Realm'} = $$p_realm_data{'name'}; &ui_Rebuild(); } } else { $FORM{'Realm'} = $ARGV[2]; &ui_Rebuild(); } } elsif ($action eq 'listrules') { foreach (sort keys %Rules) { print "$_: $Rules{$_}\n\n"; } } elsif ($action eq 'setrule') { $err = &WriteRule( $ARGV[2], $ARGV[3] ); next Err if ($err); } else { print "Action '$action' not recognized.\n"; } EOC # Step 3. Call FDSE as an API; FDSE will initialize and then execute the code in $FDSE_CALLBACK_SUB push(@ARGV,'Mode=Admin'); $ENV{'FDSE_NO_EXEC'} = 1; chdir('../..') || die $!; $0 = ''; Found: { if (-e "search.pl") { require "search.pl"; last Found; } if (-e "search.cgi") { require "search.cgi"; last Found; } print "Warning: unable to find 'search.pl' or 'search.cgi' in ../..\n"; }