# $Id: majordomo-admin.cf,v 1.5 1997/02/25 05:40:57 fitz Exp $
# Config file for Majordomo administration commands
#

package config;
$name = "Majordomo";

# Tell MailServ that we need a password

$needPassword = 1;

# Minimum size (characters) for the newconfig command
# This will help prevent screwups.  Not yet implemented.

$newconfigSize = 100;

#----------------------------------------------------------------------
# Majordomo commands, and the order in which they should appear.
# If you don't want to support a particular command,
# just comment it out of this array.
#
@commands =
    (
     "subscribe",
     "unsubscribe",
     "who",
     "lists",
     "which",
     "passwd",
     "help",
     "enter",
     "", # split the table into two columns
     "mkdigest",
     "index",
     "get",
     "info",
     "newinfo",
     "config",
     "newconfig",
     "writeconfig",
     );

 # Corresponding desciption for command
%description =
    (
     "subscribe", "Subscribe",
     "unsubscribe", "Unsubscribe",
     "passwd", "Change the list password.",
     "mkdigest", "Generate a digest for the list.",
     "who", "Who is on the mailing list?",
     "lists", "Show other lists on this server.",
     "help", "Get help for <em>$name</em> commands.",
     "enter", "Enter <EM>Majordomo</EM> commands",
     "info", "Get the list info file.",
     "newinfo", "Replace the list info file:",
     "config", "Get the list config file.",
     "newconfig", "Replace the list config file:",
     "writeconfig", "Re-write the list config file.",
     "which", "Search all list subscriptions for:",
     "index", "List files in the archive.",
     "get", "Get a file from the archive:",
     );

#######################################################################
#----------------------------------------------------------------------
# Majordomo command forms
#----------------------------------------------------------------------
#######################################################################

# Code for the commands that are used in both the administrative
# interface and the user interface

require "majordomo-share.cf";

use strict;

#----------------------------------------------------------------------
# subscribe command
#
$config::command{"subscribe"} = <<EOT;
<TABLE>
 <TR VALIGN=top>
  <TD ALIGN=right><FONT SIZE="-1">Addresses:</FONT></TD>
  <TD>
   <FONT SIZE="-1">
   <TEXTAREA NAME="majordomoSubscribe" ROWS=3 COLS="$main::size"></TEXTAREA>
   </FONT>
  </TD>
 </TR>
</TABLE>
EOT

sub process_subscribe
{
    my(@commands,$addr);

    &main::error("Before you can subscribe an address ",
                "you must enter the name of the mailing list.")
        unless $main::in{"list"};

    &main::error("Before you can subscribe an address ",
                "you must enter the list admin password.")
        unless $main::in{"password"};

    &main::error("You must enter an address to subscribe.")
        unless $main::in{"majordomoSubscribe"};

    # approve <password> subscribe <listname> <address>

    # Multiple files are allowed
    foreach $addr (split(/\n/, $main::in{"majordomoSubscribe"}))
    {
        # Skip empty lines
        next if $addr =~ /^\s*$/;

        push(@commands,
             ("approve " .
              &hidePassword($main::in{password}) .
              " subscribe $main::in{list} $addr"));
    }

    # Return the commands
    @commands;
}

#----------------------------------------------------------------------
# unsubscribe command
#
$config::command{"unsubscribe"} = <<EOT;
<TABLE>
 <TR VALIGN=top>
  <TD ALIGN=right><FONT SIZE="-1">Addresses:</FONT></TD>
  <TD>
   <FONT SIZE="-1">
   <TEXTAREA NAME="majordomoUnsubscribe" ROWS=3 COLS="$main::size"></TEXTAREA>
   </FONT>
  </TD>
 </TR>
</TABLE>
EOT

sub process_unsubscribe
{
    my(@commands,$addr);

    &main::error("Before you can unsubscribe an address, ",
                "you must enter the name of the mailing list.")
        unless $main::in{"list"};

    &main::error("Before you can unsubscribe an address, ",
                "you must enter the list admin password.")
        unless $main::in{"password"};

    &main::error("You must enter an address to unsubscribe.")
        unless $main::in{"majordomoUnsubscribe"};

    # approve <password> unsubscribe <listname> <address>

    foreach $addr (split(/\n/, $main::in{"majordomoUnsubscribe"}))
    {
        # Skip empty lines
        next if $addr =~ /^\s*$/;

        push(@commands,
             ("approve " .
              &hidePassword($main::in{password}) .
              " unsubscribe $main::in{list} $addr"));
    }

    # Return the commands
    @commands;
}

#----------------------------------------------------------------------
# passwd command
#
$config::command{"passwd"} = <<EOT;
<TABLE>
<TR>
<TD ALIGN=right><FONT SIZE="-1">New:</FONT></TD>
<TD>
<FONT SIZE="-1"><INPUT TYPE=password NAME="majordomoPassNew" SIZE="$main::size"></FONT>
</TD>
</TR>
<TR>
<TD ALIGN=right><FONT SIZE="-1">Retype:</FONT></TD>
<TD>
<FONT SIZE="-1"><INPUT TYPE=password NAME="majordomoPassRetype" SIZE="$main::size"></FONT>
</TD>
</TR>
</TABLE>
EOT

sub process_passwd
{
    &main::error("Before you can change the password ",
                "you must enter the name of the mailing list.")
        unless $main::in{"list"};

    &main::error("Before you can change the password ",
                "you must enter the current password.")
        unless $main::in{"password"};

    &main::error("You must enter the new password twice.")
        unless ($main::in{"majordomoPassNew"}
                && $main::in{"majordomoPassRetype"});

    &main::error("The new password must match the retyped password.")
        unless ($main::in{"majordomoPassNew"}
                eq $main::in{"majordomoPassRetype"});

    # passwd <listname> <current-pass> <new-pass>

    "passwd $main::in{list} " .
        &hidePassword($main::in{password}) . " " .
            &hidePassword($main::in{majordomoPassNew});
}

#----------------------------------------------------------------------
# mkdigest command
#
sub process_mkdigest
{
    &main::error("Before you can make a digest ",
                "you must enter the digest listname.")
        unless ($main::in{"list"});

    &main::error("Before you can make a digest ",
                "you must enter the list admin password.")
        unless $main::in{"password"};

    # mkdigest <listname> <password>

    "mkdigest $main::in{list} " . &hidePassword($main::in{"password"});
}

#----------------------------------------------------------------------
# newinfo command
#
$config::command{"newinfo"} = <<EOT;
<TABLE>
<TR VALIGN=top>
<TD ALIGN=right><FONT SIZE="-1">New info:</FONT></TD>
<TD>
<FONT SIZE="-1"><TEXTAREA NAME="majordomoNewinfo" ROWS=5 COLS="$main::size"></TEXTAREA></FONT>
</TD>
</TR>
<TR>
<TD></TD>
<TD><FONT SIZE="-1">(paste your modified list info file into the field above)</FONT></TD>
</TABLE>
EOT

sub process_newinfo
{
    local($*) = 1; # allow multi-line matches

    &main::error("Before you can set the list info ",
                "you must enter the listname.")
        unless $main::in{"list"};

    &main::error("Before you can update the list info ",
                "you must enter the list admin password.")
        unless $main::in{"password"};

    &main::error("You must enter a new info file.")
        unless $main::in{"majordomoNewinfo"};

    # newinfo <listname> <password>
    # <info file>
    # ...
    # EOF

    # Add "EOF" to the end (if it is not already there)

    $main::in{"majordomoNewinfo"} .= "\nEOF\n"
        unless $main::in{"majordomoNewinfo"} =~ /\s*EOF\s*$/;

    "newinfo $main::in{list} " .
        &hidePassword($main::in{"password"}) . "\n" .
            $main::in{"majordomoNewinfo"};
}

#----------------------------------------------------------------------
# config command
#
sub process_config
{
    &main::error("Before you can get the list config ",
                "you must enter the listname.")
        unless ($main::in{"list"});

    &main::error("Before you can get the list config ",
                "you must enter the list admin password.")
        unless $main::in{"password"};

    # config <listname> <password>

    "config $main::in{list} " . &hidePassword($main::in{"password"});
}

#----------------------------------------------------------------------
# newconfig command
#
$config::command{"newconfig"} = <<EOT;
<TABLE>
<TR VALIGN=top>
<TD ALIGN=right><FONT SIZE="-1">New config:</FONT></TD>
<TD>
<FONT SIZE="-1"><TEXTAREA NAME="majordomoNewconfig" ROWS=5 COLS="$main::size"></TEXTAREA></FONT>
</TD>
</TR>
<TR>
<TD></TD>
<TD><FONT SIZE="-1">(paste your modified list config file into the field above)</FONT></TD>
</TABLE>
EOT

sub process_newconfig
{
    local($*) = 1; # allow multi-line matches

    &main::error("Before you can update the list config ",
                "you must enter the listname.")
        unless $main::in{"list"};

    &main::error("Before you can update the list config ",
                "you must enter the list admin password.")
        unless $main::in{"password"};

    &main::error("You must enter a new config file.")
        unless $main::in{"majordomoNewconfig"};

    # newconfig <listname> <password>
    # <config file>
    # ...
    # EOF

    # Add "EOF" to the end (if it is not already there)

    $main::in{"majordomoNewconfig"} .= "\nEOF\n"
        unless $main::in{"majordomoNewconfig"} =~ /\s*EOF\s*$/;
        
    "newconfig $main::in{list} " .
        &hidePassword($main::in{"password"}) . "\n" .
            $main::in{"majordomoNewconfig"};
}

#----------------------------------------------------------------------
# writeconfig command
#
sub process_writeconfig
{
    &main::error("Before you can re-write the list config ",
                "you must enter the listname.")
        unless ($main::in{"list"});

    &main::error("Before you can get re-write list config ",
                "you must enter the list admin password.")
        unless $main::in{"password"};

    # writeconfig <listname> <password>

    "writeconfig $main::in{list} " . &hidePassword($main::in{"password"});
}

1;
