SRCDS Steam group


PHP Console Retreiver
#1
A lot of game server hosts don't give you access to a console log, especially ones that use TCAdmin. I was fed up with it, so I wrote a simple PHP script that connects to your server via FTP and downloads the console.log file. To use this, you need to add -condebug to your server's command line. In addition, make sure your web host allows FTP connections through PHP. READ BELOW FOR INSTALLATION INSTRUCTIONS

PHP Code:
<?php

/**************************
* SRCDS PHP console viewer
* Written by abcorn - http://goo.gl/hlIZL
**************************/

/***********
* SETTINGS
***********/

$ftp_server 'ftp server'// PUT YOUR FTP SERVER ADDRESS HERE
$ftp_user_name 'ftp user'// PUT YOUR FTP USERNAME HERE
$ftp_user_pass 'ftp password'// PUT YOUR FTP PASSWORD HERE
$ftp_directory 'ftp directory'// PUT YOUR DIRECTORY TO console.log HERE, FOR EXAMPLE '/123.456.789.012 port 27015/tf' IF console.log IS LOCATED IN '/123.456.789.012 port 27015/tf/console.log' IN YOUR FTP SERVER'S ROOT

$allow_clear 0// SET THIS TO 1 IF YOU WANT USERS TO BE ABLE TO CLEAR console.log FROM THIS SCRIPT. REQUIRES THE OPTION BELOW TO BE SET.
$filename 'script filename'// SET THIS TO THE FILENAME OF THIS SCRIPT, FOR EXAMPLE 'console.php' IF YOU SET THE ABOVE OPTION TO 1.

$txt_filename 'consolelog.txt'// ONLY CHANGE THIS IF YOU UPLOADED A .txt NAMED SOMETHING OTHER THAN 'consolelog.txt'. IT MUST BE CHMODDED TO 777.

// set up basic connection
$conn_id ftp_connect($ftp_server); 

// login with username and password
$login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass); 

ftp_pasv($conn_idtrue);

// check connection
if ((!$conn_id) || (!$login_result)) {
    die(
"<code>FTP connection has failed!</code>");
}

if (!
ftp_chdir($conn_id$ftp_directory)) {
    die(
"<code>Couldn't change directory to ".$ftp_directory.".</code>");
}

if(
$_GET['clear'] && $allow_clear) {
    if(!
$file fopen($txt_filename'w')) {
        die(
"<code>Couldn't open ".$txt_filename."!");
    }
    if(!
fwrite($file' ')) {
        die(
"<code>Couldn't write to ".$txt_filename."!");
    }
    
fclose($file);
    
    if (!
ftp_put($conn_id"console.log"$txt_filenameFTP_ASCII)) {
        die(
"<code>Couldn't upload blank file to console.log.</code>");
    }
    
    
header("location: ".$filename);
    exit(
0);
}

if (!
ftp_get($conn_id$txt_filename$ftp_directory."/console.log"FTP_ASCII)) {
    die(
"<code>Couldn't get console log from server.</code>");
}

if(!
$file fopen($txt_filename'r')) {
    die(
"<code>Couldn't open ".$txt_filename."!");
    }
$text fread($filefilesize($txt_filename));
fclose($file);

// close the connection
ftp_close($conn_id);
?>
<html>
<head>
<title>SRCDS Console Output</title>
</head>
<body>
<code>
<a href="javascript:location.reload(true)">Refresh</a><?php if($allow_clear) { ?> | <a href="<?php echo $filename?>?clear=1">Clear Console</a><?php ?><br><hr>
<?php echo nl2br($text); ?><br>
<hr><a href="javascript:location.reload(true)">Refresh</a><?php if($allow_clear) { ?> | <a href="<?php echo $filename?>?clear=1">Clear Console</a><?php ?>
</code>
</body>
</html> 

INSTALLATION
Put this into a .php file, for example, console.php, and upload it to your web server. In the same directory, upload a text file named consolelog.txt, and chmod it to 777. You can name this text file something else if you want, just change the $txt_filename value in the PHP script. Also change the settings with your FTP connection information. MAKE SURE WHEN YOU UPLOAD THE PHP SCRIPT THERE ARE NO BLANK LINES BEFORE THE <?php LINE!

If you get a PHP Warning of "Length parameter must be greater than 0", don't worry about it. All it means is that your console.log file is blank, and PHP doesn't like that.

If you want to donate, please feel free. Just send me a PM. Big Grin
[Image: 76561198006409530.png]
If I helped you, I would love some rep. Smile
Reply
#2
So this is for windows servers? I never saw a console.log on linux.

Also what happens If the log is very big like > 16MB?

My php setup would result in memory allorcation exhausted if I would try to view such a file.

If the php space supports fopen you could do it easier with that function.
Interactive web based config creator for CS, CSS, TF2 and DODS
Creates server and client configs in an explained dialog.

You`ll also find precompiled debian gameserver kernels for download
Reply
#3
I use this on Windows, but it should work on Linux provided the Linux version of SRCDS allows you to use -condebug on the command line.

Yes, fopen would be a better way to do this, but I have never heard of a game server host that gives you PHP space on the game server itself.

If your console.log is that big, then just clear it. I highly doubt you need to know what happened on your server two years ago. I wrote a script that runs every day by cron that backs up and clears my console.log automatically, making a new local txt file with the date as the name. I might put it up here.
[Image: 76561198006409530.png]
If I helped you, I would love some rep. Smile
Reply
#4
-condebug gives you a very detailed debug.log and is deactivated for a reason by default.

With Linux you run you server in a screen which gives you the ability to write a screenlog. Aiming for that would be better.

Just because you rotate your logs does not mean everybody does. If an unexpierienced user tries to use your skript he will run into trouble and dump it because it does not work.

fopen is able to retreave files per ftp:
PHP Code:
fopen("ftp://username:password@ip/path/file""r"); 
Interactive web based config creator for CS, CSS, TF2 and DODS
Creates server and client configs in an explained dialog.

You`ll also find precompiled debian gameserver kernels for download
Reply
#5
Directly from the Valve Developer Wiki:

Quote:-condebug - Logs all console output into the console.log text file.


Does fwrite() work through FTP?


This script is not difficult for inexperienced users. All of the options are clearly defined in the script comments. This isn't the one that automatically rotates the logs, simply retrieves it.
[Image: 76561198006409530.png]
If I helped you, I would love some rep. Smile
Reply
#6
Hmm not sure if it is the correct login, however it seems to me that you've left your FTP information in the script above. Smile
Reply
#7
(03-30-2011, 12:35 AM)realchamp Wrote:  Hmm not sure if it is the correct login, however it seems to me that you've left your FTP information in the script above. Smile

Whoops, thanks. It was late. Shy Removed it and invalidated the password.
[Image: 76561198006409530.png]
If I helped you, I would love some rep. Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)