105 lines
3.2 KiB
Plaintext
Executable File
105 lines
3.2 KiB
Plaintext
Executable File
<html>
|
|
<head><title>Admin Console</title></head>
|
|
<body>
|
|
<?_code
|
|
|
|
use strict;
|
|
use vars qw(%POST %cmd);
|
|
|
|
my ($ret, $sth);
|
|
|
|
my $commands = $POST{'commands'};
|
|
my $remote = LJ::get_remote();
|
|
|
|
if ($commands)
|
|
{
|
|
unless (LJ::did_post()) {
|
|
return "<b>Error:</b> requires post.";
|
|
}
|
|
|
|
if ($remote && $remote->{'user'} ne $POST{'remoteuser'}) {
|
|
return "<b>Error:</b> invalid user.";
|
|
}
|
|
|
|
$ret .= "[ <A HREF=\"./\">console</A> | <A HREF=\"reference.bml\">reference</A> ]<P>";
|
|
|
|
foreach my $cmd (split(/\n/, $commands))
|
|
{
|
|
my @args = LJ::Con::parse_line($cmd);
|
|
next unless @args;
|
|
|
|
my $first = 1;
|
|
$ret .= "<P><TABLE BORDER=1 CELLPADDING=5><TR>";
|
|
foreach (@args) {
|
|
my $arg = BML::eall($_);
|
|
if ($first) {
|
|
$ret .= "<TD><B>$arg</B></TD>";
|
|
$first = 0;
|
|
} else {
|
|
$ret .= "<TD>$arg</TD>";
|
|
}
|
|
}
|
|
$ret .= "</TR></TABLE>";
|
|
|
|
my @output;
|
|
my $rv;
|
|
|
|
# TODO: make the entire console library not take $db args.
|
|
my $dbh = LJ::get_db_writer();
|
|
$rv = LJ::Con::execute($dbh, $remote, \@args, \@output);
|
|
|
|
unless ($rv) { $ret .= "<P><B><FONT COLOR=#FF0000>Failed!</FONT></B>"; }
|
|
if (@output) {
|
|
$ret .= "<PRE><B>";
|
|
foreach my $line (@output) {
|
|
my $color = "#000000";
|
|
if ($line->[0] eq "error") {
|
|
$color = "#FF0000";
|
|
}
|
|
if ($line->[0] eq "info") {
|
|
$color = "#008800";
|
|
}
|
|
|
|
$ret .= "<FONT COLOR=$color>".LJ::eall($line->[1])."</FONT>\n";
|
|
|
|
}
|
|
$ret .= "</B></PRE>";
|
|
}
|
|
}
|
|
|
|
$ret .= "<form method=post><p>";
|
|
$ret .= "<tt>enter commands:</tt><br>";
|
|
$ret .= LJ::html_hidden('remoteuser', $remote->{'user'}) if $remote;
|
|
$ret .= "<textarea name=commands rows=3 cols=60 wrap=off></textarea> ";
|
|
$ret .= "<input type=submit value=\"execute\"></form>\n";
|
|
|
|
return $ret;
|
|
|
|
}
|
|
else
|
|
{
|
|
$ret .= "[ console | <A HREF=\"reference.bml\">reference</A> ]<P>";
|
|
|
|
$ret .= "<FORM METHOD=POST>";
|
|
$ret .= LJ::html_hidden('remoteuser', $remote->{'user'}) if $remote;
|
|
$ret .= "<TABLE WIDTH=400><TR VALIGN=BOTTOM>";
|
|
$ret .= "<TD><IMG SRC=\"$LJ::IMGPREFIX/nerd_small.jpg\" WIDTH=167 HEIGHT=169 HSPACE=2 VSPACE=2></TD>";
|
|
$ret .= "<TD><B><TT>command console.</TT></B>";
|
|
$ret .= "<P>welcome to the livejournal console. from here administrators can do administrative type things. you will forget the commands, so there is a <A HREF=\"reference.bml\">reference</A>.</TD>";
|
|
$ret .= "</TR>";
|
|
$ret .= "<TR><TD COLSPAN=2>";
|
|
$ret .= "<P><tt>enter commands:</tt><BR>";
|
|
$ret .= "<TEXTAREA NAME=commands ROWS=10 COLS=60 WRAP=OFF></TEXTAREA></TD></TR>\n";
|
|
$ret .= "<TR><TD COLSPAN=2 ALIGN=RIGHT><INPUT TYPE=SUBMIT VALUE=\"execute\"></P></TD></TR></TABLE></FORM>\n";
|
|
return $ret;
|
|
}
|
|
|
|
_code?>
|
|
</body>
|
|
</html>
|
|
<?_c <LJDEP>
|
|
lib: cgi-bin/console.pl, cgi-bin/ljlib.pl
|
|
link: htdocs/admin/console/reference.bml
|
|
post: htdocs/admin/console/index.bml
|
|
</LJDEP> _c?>
|