2018-03-12 03:46:05 -07:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use UI::Dialog;
|
|
|
|
use Term::ReadKey;
|
|
|
|
use Term::ANSIScreen qw(cls);
|
|
|
|
|
2018-03-12 05:22:13 -07:00
|
|
|
my $FileEditor = "/bin/nano";
|
2018-03-12 03:46:05 -07:00
|
|
|
my $InitDName = "/etc/init.d/minetest";
|
2018-03-12 04:28:30 -07:00
|
|
|
my $MINETESTDIR = "/root/minetest";
|
2018-07-12 21:37:39 -07:00
|
|
|
my $BackupCommand = "/root/MineBackup/minebackup.pl";
|
2018-08-16 16:34:02 -07:00
|
|
|
my $PagerCommand = "/usr/bin/less";
|
|
|
|
my $Logfile = "/root/minetest/minetest.log";
|
|
|
|
my $PlayersDir = "/var/games/minetest-server/.minetest/worlds/world/players";
|
2018-08-18 21:53:01 -07:00
|
|
|
my $MinetestConf = "/root/minetest/minetest.conf";
|
2018-03-12 03:46:05 -07:00
|
|
|
|
|
|
|
###################################################
|
|
|
|
# No changes below here
|
|
|
|
###################################################
|
|
|
|
|
2018-08-17 01:13:29 -07:00
|
|
|
my $MySettings = "$ENV{'HOME'}/.mmcrc";
|
|
|
|
|
2018-08-21 15:49:26 -07:00
|
|
|
my $MMC_ver = "1.3.0";
|
2018-03-12 03:46:05 -07:00
|
|
|
my $Record = "false"; # Are results saved?
|
|
|
|
my $TempDir = "/tmp";
|
|
|
|
my $RobotName = "";
|
|
|
|
my $BotVersion = "";
|
|
|
|
my $UserName = "";
|
|
|
|
my $ServerStatus = "foo";
|
|
|
|
|
|
|
|
my $d = new UI::Dialog ( backtitle => "Minetest Management Console v$MMC_ver", height => 20, width => 65, listheight => 5,
|
|
|
|
order => [ 'ascii', 'cdialog', 'xdialog' ]);
|
|
|
|
|
|
|
|
my $windowtitle = "Welcome to the Minetest Management Console!";
|
|
|
|
my $enjoyedtitle = "We hope you enjoyed MMC!";
|
|
|
|
my $introtext =
|
|
|
|
"This is the Minetest Management Console, a utility for Minetest operators
|
|
|
|
to manage their servers from a text GUI rather than the command line.";
|
|
|
|
|
|
|
|
$d->msgbox( title => $windowtitle, text => $introtext );
|
|
|
|
|
|
|
|
if (($d->state() eq "ESC") || ($d->state() eq "CANCEL"))
|
|
|
|
{
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
2018-08-17 01:13:29 -07:00
|
|
|
# Check for config file
|
|
|
|
if (-f $MySettings)
|
|
|
|
{
|
|
|
|
# Read in settings
|
|
|
|
open (my $FH, "<", $MySettings) or die "Could not read default file '$MySettings' $!";
|
|
|
|
while (<$FH>)
|
|
|
|
{
|
2018-08-17 01:24:04 -07:00
|
|
|
chop();
|
2018-08-17 01:13:29 -07:00
|
|
|
my ($Command, $Setting) = split(/=/, $_);
|
|
|
|
if ($Command eq "fileeditor")
|
|
|
|
{
|
|
|
|
$FileEditor = $Setting;
|
|
|
|
}
|
|
|
|
if ($Command eq "initdname")
|
|
|
|
{
|
|
|
|
$InitDName = $Setting;
|
|
|
|
}
|
|
|
|
if ($Command eq "minetestdir")
|
|
|
|
{
|
|
|
|
$MINETESTDIR = $Setting;
|
|
|
|
}
|
|
|
|
if ($Command eq "backupcommand")
|
|
|
|
{
|
|
|
|
$BackupCommand = $Setting;
|
|
|
|
}
|
|
|
|
if ($Command eq "pagercommand")
|
|
|
|
{
|
|
|
|
$PagerCommand = $Setting;
|
|
|
|
}
|
|
|
|
if ($Command eq "logfile")
|
|
|
|
{
|
2018-08-17 01:24:04 -07:00
|
|
|
$Logfile = $Setting;
|
2018-08-17 01:13:29 -07:00
|
|
|
}
|
|
|
|
if ($Command eq "playerdir")
|
|
|
|
{
|
|
|
|
$PlayersDir = $Setting;
|
|
|
|
}
|
2018-08-18 21:53:01 -07:00
|
|
|
if ($Command eq "minetestconf")
|
|
|
|
{
|
|
|
|
$MinetestConf = $Setting;
|
|
|
|
}
|
2018-08-17 01:13:29 -07:00
|
|
|
}
|
|
|
|
close($FH);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# Store defaults
|
|
|
|
open (my $FH, ">", $MySettings) or die "Could not create default file '$MySettings' $!";
|
|
|
|
print $FH "fileeditor=/bin/nano\n";
|
|
|
|
print $FH "initdname=/etc/init.d/minetest\n";
|
|
|
|
print $FH "minetestdir=/root/minetest\n";
|
|
|
|
print $FH "backupcommand=/root/MineBackup/minebackup.pl\n";
|
|
|
|
print $FH "pagercommand=/usr/bin/less\n";
|
|
|
|
print $FH "logfile=/root/minetest/minetest.log\n";
|
|
|
|
print $FH "playerdir=/var/games/minetest-server/.minetest/worlds/world/players\n";
|
2018-08-18 21:53:01 -07:00
|
|
|
print $FH "minetestconf=/root/minetest/minetest.conf\n";
|
2018-08-17 01:13:29 -07:00
|
|
|
close($FH);
|
|
|
|
}
|
|
|
|
|
2018-03-12 03:46:05 -07:00
|
|
|
my $menuselection = "";
|
|
|
|
|
2018-08-17 01:13:29 -07:00
|
|
|
|
2018-03-12 03:46:05 -07:00
|
|
|
sub CheckServerStatus
|
|
|
|
{
|
|
|
|
my $running=`ps ax|grep minetestserver|grep -v grep`;
|
|
|
|
if ($running ne "")
|
|
|
|
{
|
|
|
|
$ServerStatus = "Running";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$ServerStatus = "Stopped";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sub MainMenu
|
|
|
|
{
|
2018-03-12 04:28:30 -07:00
|
|
|
my $WantRespawn="ON";
|
2018-03-12 03:46:05 -07:00
|
|
|
CheckServerStatus();
|
2018-03-12 04:28:30 -07:00
|
|
|
if (-f "$MINETESTDIR/nostart")
|
|
|
|
{
|
|
|
|
$WantRespawn="OFF";
|
|
|
|
}
|
|
|
|
|
|
|
|
$menuselection = $d->menu( title => "Main Menu", text => "Server is $ServerStatus and respawn is $WantRespawn - Select one:",
|
2018-03-12 03:46:05 -07:00
|
|
|
list => [ '1', 'Start Server',
|
|
|
|
'2', 'Stop Server',
|
|
|
|
'3', 'Server Console',
|
2018-03-12 04:28:30 -07:00
|
|
|
'4', 'Turn Off Respawn',
|
|
|
|
'5', 'Turn Respawn On',
|
2018-03-12 05:22:13 -07:00
|
|
|
'6', 'Edit World Cfg',
|
2018-03-19 02:56:51 -07:00
|
|
|
'7', 'Edit minetest.conf',
|
2018-07-12 21:37:39 -07:00
|
|
|
'8', 'Run Backup',
|
2018-08-16 16:34:02 -07:00
|
|
|
'9', 'View Log',
|
|
|
|
'10', 'View Players',
|
2018-08-21 15:49:26 -07:00
|
|
|
'11', 'Edit Settings',
|
2018-03-12 03:46:05 -07:00
|
|
|
'q', 'Quit MMC' ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
while (-1)
|
|
|
|
{
|
|
|
|
MainMenu();
|
|
|
|
if (($menuselection eq "CANCEL") || ($menuselection eq "ESC") || ($menuselection eq "") || ($menuselection eq "q") || ($menuselection eq "Q"))
|
|
|
|
{
|
|
|
|
$d->msgbox( title => $enjoyedtitle, text => "Thanks for using MMC..." );
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
if ($menuselection eq "1")
|
|
|
|
{
|
|
|
|
system("$InitDName start");
|
|
|
|
}
|
|
|
|
elsif ($menuselection eq "2")
|
|
|
|
{
|
2018-03-12 04:03:21 -07:00
|
|
|
if ($d->yesno( text => "Confirm stopping the server", text => "Are you sure you want to shut down the server?" ))
|
|
|
|
{
|
|
|
|
system("$InitDName stop");
|
2018-03-12 04:06:47 -07:00
|
|
|
sleep(5);
|
2018-08-21 15:36:27 -07:00
|
|
|
system("killall startminetest");
|
2018-03-12 04:03:21 -07:00
|
|
|
}
|
2018-03-12 03:46:05 -07:00
|
|
|
}
|
|
|
|
elsif ($menuselection eq "3")
|
|
|
|
{
|
2018-03-12 05:03:03 -07:00
|
|
|
$d->msgbox( text => "To exit the minetest console and return to MMC press CTRL-A CTRL-D" );
|
2018-03-12 03:46:05 -07:00
|
|
|
system("screen -r");
|
|
|
|
}
|
|
|
|
elsif ($menuselection eq "4")
|
|
|
|
{
|
2018-03-12 04:28:30 -07:00
|
|
|
# Turn off respawn
|
|
|
|
system("touch $MINETESTDIR/nostart");
|
2018-03-12 03:46:05 -07:00
|
|
|
}
|
|
|
|
elsif ($menuselection eq "5")
|
|
|
|
{
|
2018-03-12 04:28:30 -07:00
|
|
|
# Turn respawn back on
|
|
|
|
if (-f "$MINETESTDIR/nostart")
|
|
|
|
{
|
|
|
|
unlink("$MINETESTDIR/nostart");
|
|
|
|
}
|
2018-03-12 03:46:05 -07:00
|
|
|
}
|
2018-03-12 05:22:13 -07:00
|
|
|
elsif ($menuselection eq "6")
|
|
|
|
{
|
|
|
|
# Edit world.mt file
|
|
|
|
system("$FileEditor $MINETESTDIR/worlds/world/world.mt");
|
|
|
|
}
|
2018-03-19 02:56:51 -07:00
|
|
|
elsif ($menuselection eq "7")
|
|
|
|
{
|
|
|
|
# Edit minetest.conf file
|
2018-08-18 21:53:01 -07:00
|
|
|
system("$FileEditor $MinetestConf");
|
2018-03-19 02:56:51 -07:00
|
|
|
}
|
2018-07-12 21:37:39 -07:00
|
|
|
elsif ($menuselection eq "8")
|
|
|
|
{
|
|
|
|
# Run a backup
|
2018-08-16 16:34:02 -07:00
|
|
|
system("clear");
|
2018-07-12 21:37:39 -07:00
|
|
|
system("$BackupCommand");
|
2018-08-16 16:34:02 -07:00
|
|
|
print "Press Enter To Continue";
|
|
|
|
my $entered = <STDIN>;
|
|
|
|
}
|
|
|
|
elsif ($menuselection eq "9")
|
|
|
|
{
|
|
|
|
# View log file
|
|
|
|
system("$PagerCommand $Logfile");
|
|
|
|
}
|
|
|
|
elsif ($menuselection eq "10")
|
|
|
|
{
|
|
|
|
# View users
|
|
|
|
system("clear");
|
|
|
|
system("ls $PlayersDir");
|
|
|
|
print "Press Enter To Continue";
|
|
|
|
my $entered = <STDIN>;
|
2018-07-12 21:37:39 -07:00
|
|
|
}
|
2018-08-21 15:49:26 -07:00
|
|
|
elsif ($menuselection eq "11")
|
|
|
|
{
|
|
|
|
# Edit minetest.conf file
|
|
|
|
system("$FileEditor $MySettings");
|
|
|
|
}
|
2018-03-12 03:46:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|