03-29-2011, 11:45 AM (This post was last modified: 03-30-2011, 02:45 AM by abcorn.)
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_id, true);
// 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>");
}
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.
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.
-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.
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.
(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.
Whoops, thanks. It was late. Removed it and invalidated the password.