Commit 43b978df authored by Leigh Stoller's avatar Leigh Stoller

Some console support changes:

* utils/spewconlog.in: New script to ssh to the host tipserver and cat
  the console log for a node. In admin mode cats the .log file, while
  in mere user mode, cats the .run file.

* www/shownode.php3: Added a "Show Console Log" function.

* www/showconlog.php3: New script to invoke spewconlog backend script
  and dump the console log to the user.
parent 3779f54c
...@@ -19,9 +19,11 @@ BIN_SCRIPTS = delay_config sshtb create_image node_admin link_config \ ...@@ -19,9 +19,11 @@ BIN_SCRIPTS = delay_config sshtb create_image node_admin link_config \
SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
eventping grantnodetype import_commitlog dhcpd_wrapper \ eventping grantnodetype import_commitlog dhcpd_wrapper \
opsreboot deletenode node_statewait grabwebcams \ opsreboot deletenode node_statewait grabwebcams \
grabswitchconfig backupswitches cvsinit checkquota grabswitchconfig backupswitches cvsinit checkquota \
spewconlog
LIBEXEC_SCRIPTS = webcreateimage newnode webdeletenode spewleds webcopy \ LIBEXEC_SCRIPTS = webcreateimage newnode webdeletenode spewleds webcopy \
websetdest spewsource weblinkmon_ctl webcvsweb websetdest spewsource weblinkmon_ctl webcvsweb \
webspewconlog
# #
# Force dependencies on the scripts so that they will be rerun through # Force dependencies on the scripts so that they will be rerun through
...@@ -51,6 +53,8 @@ post-install: ...@@ -51,6 +53,8 @@ post-install:
chmod u+s $(INSTALL_SBINDIR)/grabwebcams chmod u+s $(INSTALL_SBINDIR)/grabwebcams
chown root $(INSTALL_SBINDIR)/checkquota chown root $(INSTALL_SBINDIR)/checkquota
chmod u+s $(INSTALL_SBINDIR)/checkquota chmod u+s $(INSTALL_SBINDIR)/checkquota
chown root $(INSTALL_SBINDIR)/spewconlog
chmod u+s $(INSTALL_SBINDIR)/spewconlog
# #
# Control node installation (okay, plastic) # Control node installation (okay, plastic)
......
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
#
# Spew a console log from the tipserver that hosts it.
#
sub usage()
{
print(STDOUT "Usage: spewconlog node\n");
exit(-1);
}
my $optlist = "";
my $logdir = "/var/log/tiplogs";
my $logname;
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $SSH = "$TB/bin/sshtb";
my $SAVEUID = $UID;
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# We don't want to run this script unless its the real version.
#
if ($EUID != 0) {
die("*** $0:\n".
" Must be setuid! Maybe its a development version?\n");
}
#
# This script is setuid, so please do not run it as root. Hard to track
# what has happened.
#
if ($UID == 0) {
die("*** $0:\n".
" Please do not run this as root! Its already setuid!\n");
}
#
# Turn off line buffering on output. Very important for this script!
#
$| = 1;
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use libdb;
use libtestbed;
# Be careful not to exit on transient error
$libdb::DBQUERY_MAXTRIES = 30;
#
# Locals
#
my $logfile;
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
usage()
if (@ARGV != 1);
my $node = $ARGV[0];
# Untaint
if ($node =~ /^([-\w]+)$/) {
$node = $1;
}
else {
die("*** Tainted node name: $node\n");
}
#
# Check permission.
#
if (!TBAdmin($UID) &&
(! TBNodeAccessCheck($UID, TB_NODEACCESS_READINFO, ($node)))) {
die("*** $0:\n".
" You not have permission to view console log for $node!\n");
}
#
# Grab DB data.
#
my $query_result =
DBQueryFatal("select server from tiplines where node_id='$node'");
if (!$query_result->numrows) {
die("*** $0:\n".
" No console log (tipline) available for $node!\n");
}
my ($tipserver) = $query_result->fetchrow_array();
#
# Form the logfile name; admin users get the .log while users get .run.
#
if (!TBAdmin($UID)) {
$logname = "$logdir/${node}.run"
}
else {
$logname = "$logdir/${node}.log"
}
#
# Run an ssh command in a child process, protected by an alarm to
# ensure that the ssh is not hung up forever if the machine is in
# some funky state.
#
my $syspid = fork();
#
# Parent waits for ssh to complete.
#
if ($syspid) {
local $SIG{ALRM} = sub { kill("TERM", $syspid); };
alarm 20;
waitpid($syspid, 0);
my $exitstatus = $?;
alarm 0;
if ($exitstatus) {
exit(1);
}
exit(0);
}
#
# Now we want to ssh over and cat the file.
#
$UID = 0;
system("sshtb -host $tipserver cat $logname");
$UID = $SAVEUID;
exit(($? == 0 ? 0 : 1));
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
#
# This gets invoked from the Web interface. Simply a wrapper ...
#
#
# Configure variables
#
my $TB = "@prefix@";
#
# Run the real thing, and never return.
#
exec "$TB/sbin/spewconlog", @ARGV;
die("webspewconlog: Could not exec spewconlog: $!");
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
include("showstuff.php3");
#
# No PAGEHEADER since we spit out a Location header later. See below.
#
#
# Only known and logged in users can do this.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);
#
# Check to make sure a valid nodeid.
#
if (isset($node_id) && strcmp($node_id, "")) {
if (! TBvalid_node_id($node_id)) {
PAGEARGERROR("Illegal characters in node_id!");
}
if (! TBValidNodeName($node_id)) {
USERERROR("$node_id is not a valid node name!", 1);
}
if (!$isadmin &&
!TBNodeAccessCheck($uid, $node_id, $TB_NODEACCESS_READINFO)) {
USERERROR("You do not have permission to view the console log ".
"for $node_id!", 1);
}
}
else {
PAGEARGERROR("Must specify a node ID!");
}
#
# A cleanup function to keep the child from becoming a zombie.
#
$fp = 0;
function SPEWCLEANUP()
{
global $fp;
if (connection_aborted() && $fp) {
pclose($fp);
}
exit();
}
register_shutdown_function("SPEWCLEANUP");
$fp = popen("$TBSUEXEC_PATH $uid nobody webspewconlog $node_id", "r");
if (! $fp) {
USERERROR("Spew console log failed!", 1);
}
header("Content-Type: text/plain; charset=us-ascii");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
flush();
while (!feof($fp)) {
$string = fgets($fp, 1024);
echo "$string";
flush();
}
pclose($fp);
$fp = 0;
?>
...@@ -108,6 +108,9 @@ if (TBHasSerialConsole($node_id)) { ...@@ -108,6 +108,9 @@ if (TBHasSerialConsole($node_id)) {
WRITESUBMENUBUTTON("Connect to Serial Line</a> " . WRITESUBMENUBUTTON("Connect to Serial Line</a> " .
"<a href=\"faq.php3#tiptunnel\">(howto)", "<a href=\"faq.php3#tiptunnel\">(howto)",
"nodetipacl.php3?node_id=$node_id"); "nodetipacl.php3?node_id=$node_id");
WRITESUBMENUBUTTON("Show Console Log",
"showconlog.php3?node_id=$node_id");
} }
# #
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment