[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Kill Applications remotely on MacHTTP/WebStar



This is a simple web utility I made to remotely kill applications that are 
running on a mac web server.  It is written in MacPerl but uses a little 
AppleScript.  I thought it might come in handy for other Mac web 
admins.  Try it, see how you like it, or can improve upon it, share it...

kenn herman


###
$app_name = "Kill Chooser";
$version  = ".9";
$author   = "Kenn Herman";
$emailurl = "mailto:kennh@wce.wwu.edu";
$date     = "06/21/96";
print "<HTML>\n<HEAD><TITLE>Kill Chooser</TITLE></HEAD>\n<BODY>\n";
print "<CENTER><H1>Kill Chooser</H1></CENTER>\n";
print "This is a perl cgi that queries the Web server for all apps currently running, and ";
print "allows you to kill any that except the quit AppleEvent.\n<UL>\n";
print "<LI>Be sure to use the newest MacPerl CGI glue to be able to quit MacPerl CGI Scripts</LI>\n";
print "<LI>Name this app \"kill.cgi\" so it can link to itself...without the %ENV bloat.</LI>\n";
print "<LI>Feel free to make any changes, but please <a href=\"$emailurl\">email me</a> the changes.</LI>\n";
print "<LI>Make sure this is in a secured realm before leaving on your serve.</LI>\n</UL>";

&killApp() if $ENV{'QUERY_STRING'};
&killList();
print "<HR><CENTER>\"$app_name\" Copyright &#169; Version $version , created by <a href=\"$emailurl\">$author</a><br>\n";
print "Last Modified on $date</CENTER>\n</BODY>\n</HTML>";

### kill the application given by the CGI var $ENV{'QUERY_STRING'}
sub killApp {
  local($app) = $ENV{'QUERY_STRING'};
  $app =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig;  ###decode for silly humans

  &MacPerl'DoAppleScript("tell application \"$app\" to quit");
  print "<H2>Quit AppleEvent sent to \"$app\"...</H2>\n";
}

### return a list of currently running process (applications)
sub killList {
  local($processes,@array,$item,$itemEncoded);
  $processes = &MacPerl'DoAppleScript("tell application \"Finder\" to return processes");
  $processes =~ s/{|}|(, some)? ?application ?//g;
  $processes =~ s/^"|"$//g;

  @array = split(/","/,$processes);
  print "<H2>Choose an application to kill</H2>\n<UL><H3>\n";
  foreach $item (@array) {
    local($itemEncoded) = $item;                 ###encode for URL
    $itemEncoded =~ s/(\W)/sprintf("%s%x","%",ord($1))/ge;
    print "<LI><a href=\"kill.cgi\?$itemEncoded\">$item</a></LI>\n";
  }
  print "</H3></UL>\n";
}