1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
#!/usr/bin/perl
# Configuration.
$package="jhcore";
$init_script="/etc/init.d/lambdamoo";
$wizard_object="#2";
$login_object="#10";
$login_message='{"Welcome to the JHCore database.", "", "Type \'connect wizard <password>\' to log in.", "", "You will probably want to change this text, which is stored in $login.welcome_message.", "", "Before you do, though, please read \`help core-copyright\' (linked to \`help copyright\') for the exceedingly broad copyright on JHCore.", "", "You will also want to read \`help getting-started\' for some more information about starting a JHCore MOO."}';
$db_file="/var/lib/lambdamoo/jhcore.db";
$alternative_priority=90;
$lambdamoo_prog="/usr/sbin/lambdamoo";
$password_info_text=<<EOF;
It's important to set a wizard password now so others can't get into your
server. The wizard's password is equivilant to the root password of a unix
system -- with the wizard password, a malicious person could perform denial
of service attacks (using up all memory/CPU/disk space) on your system, and
perform attacks on other computers on your network. So it's important to come
up with a good wizard password.
EOF
$|=1;
$stopped=undef;
# Fix permissions of /var/lib/lambdamoo, which were messed up by old
# versions of this package.
system "chown daemon.daemon /var/lib/lambdamoo";
system "chmod 700 /var/lib/lambdamoo";
# Check to see what file is currently providing /var/lib/lambdamoo/moo.db
@pointsto=grep(m/currently points to/,`update-alternatives --display moo.db`);
if ($pointsto[0] ne '$db_file') {
# Run update-alternatives to register this package as providing
# /var/lib/lambdamoo/moo.db
system("update-alternatives --quiet --install /var/lib/lambdamoo/moo.db moo.db $db_file $alternative_priority") == 0 or die "update-alternatives failed: $? $!\n";
# Check to see what it points to now.
@nowpointsto=grep(m/currently points to/,`update-alternatives --display moo.db`);
# Has it changed? If so, we need to restart the server, if it's running.
if ($nowpointsto[0] ne $pointsto[0] && -e '/var/run/lambdamoo.pid' && -x '/etc/init.d/lambdamoo') {
system($init_script,"stop");
$stopped=1;
}
}
if ($0 ne 'abort-upgrade' && $0 ne 'abort-remove' && $0 ne 'abort-deconfigure' && -f $db_file) {
# Check the md5sum of the database file to see if it has changed
# from what is installed with the package. If so, the wizard
# password does not need to be set.
# Get the md5sum info from dpkg.
@origsum=grep(m/ $db_file/,`dpkg -s $package`);
($origsum)=$origsum[0]=~m/ $db_file (.*)/;
# Get the md5sum of the file as it is now, for comparison.
$sum=`md5sum $db_file`;
($sum)=$sum=~m/(.*?)\s/;
if ($sum eq $origsum) {
# Check if the server is currently running. Even if it is not using this
# database, we have to stop it so we can run it with this database to check
# the wizard password in the postinst.
if (-e '/var/run/lambdamoo.pid' && -x '/etc/init.d/lambdamoo') {
system($init_script,"stop");
}
$db_out_file=$db_file;
$db_out_file=~s/\.db$/.new/;
print $password_info_text;
$password=getpass();
print "Setting the password...";
$tmpfile=TempFile();
open (MOO, "|$lambdamoo_prog -e $db_file $db_out_file > $tmpfile 2>&1") || die $!;
print MOO "; $wizard_object.password = crypt(\"$password\")\n";
print MOO "; $login_object.welcome_message = $login_message\n";
print MOO "quit\n";
close MOO;
open (RESULT,"<$tmpfile") || die "Can't read $tmpfile: $!";
$set=undef;
while (<RESULT>) {
chomp;
if (/ => \".*\"$/ ne undef) {
print "done.\n";
$set=1;
}
}
close RESULT;
Parse_Error() if !$set;
unlink $tmpfile;
system "mv", $db_out_file, $db_file;
}
}
# Now make sure the server is running.
if (-x $init_script && ! -e '/var/run/lambdamoo.pid') {
exec($init_script,"start") || die "Server restart failed: $!";
}
# Prompt for and get a password, without echoing. Lifted from dupload.
sub getpass {
my $okpw=undef;
do {
system "stty -echo cbreak </dev/tty"; $? and fatal("stty");
print "Enter the wizard password to use: ";
chomp($_ = <STDIN>);
print "\n\n";
system "stty echo -cbreak </dev/tty"; $? and fatal("stty");
# Verify the password is ok.
if (/[ "]/) {
print STDERR "Passwords may not contain spaces or quotes.\n";
}
else {
$okpw=1;
}
} until $okpw;
return $_;
};
sub Parse_Error {
print "error!\n";
print STDERR <<EOF;
This program has gotten confused about what the output from the MOO means.
Please examine the file $tmpfile, and if you think this
is a bug, mail that file, this message, and any other information to the
maintainer of this package.
I'm leaving your wizard password alone for now.
EOF
print "Press Enter to continue.";
<STDIN>;
print "\n";
exit;
}
# Retuns a safe temp file name.
sub TempFile {
my $tmpfile=`tempfile -p log.`;
chomp $tmpfile;
if (!$tmpfile) {
$tmpfile="/var/run/log.$$";
}
return $tmpfile;
}
|