#!/usr/bin/perl -w
#------------------------------------------------------------------------------
# /var/config/www/cgi-bin/init.pl - interface to /etc/init.d
#
# Copyright (c) 2004  eisfair webconf team
#
# Creation:     10.10.2004
# Last Update:  $Id$
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#------------------------------------------------------------------------------

use strict;
use CGI::Carp qw(fatalsToBrowser);
use webconf_base;
use navigation;

my @args = split(/&/,$ENV{'QUERY_STRING'});

my ($package, $task, $title) = ("", "", "");
my $script = "";

foreach (0 .. $#args)
{
    if    ($args[$_] =~ /^package=(.*)/)   { $package = decode_string($1); }
    elsif ($args[$_] =~ /^title=(.*)/)     { $title   = decode_string($1); }
    elsif ($args[$_] =~ /^task=(.*)/)      { $task    = decode_string($1); }
}

print_head("executing function", $package, "class=\"result\"");
print_caption($title, $package, "class=\"result\"");
print_navigation("base", "setup.menu", "setup.services.menu");

my @scripts = split(/ /,$package);
my @tasks   = split(/ /,$task);

foreach $script (@scripts)
{
    print "<h2>Executing init script of $script ...</h2>\n";
    print "<div class=\"output\">";

    my @args = ("/etc/init.d/$script", @tasks);
    my $retval = system(@args);

    print "</div>\n";
}

print_foot("class=\"result\"");

