Jump to content

Execute a command on the server from the browser :: Example to delete PB logs


LFA

Recommended Posts

*** This script has been tested with version 1.0.2753.32400. It might not work with older versions. ***

 

To edit this script so it executes a different command or deletes files in a different folder just edit the values of each variable in the Variables section. You can also set stopGameServer = True if you want it to stop the game server before executing the command.

 

 

1- Create a text file named deletepblogs.aspx in C:\program Files\TCAdmin Control Panel\Web\Templates\Default with the following code:

 

<%
       [b]'''''''''''''''''''''''''''''''''''''''''''
       'Variables
       '''''''''''''''''''''''''''''''''''''''''''

       Dim pageTitle As String = "Delete Punkbuster Logs"
       Dim stopGameServer As Boolean = False
       Dim relativePath As String = "pb\svlogs"
       Dim command As String = "del %path%\*.log"
       Dim startMessage As String = "Deleting log files...<br>"
       Dim endMessage As String = "Log files have been deleted.<br>You can close this window."

       '''''''''''''''''''''''''''''''''''''''''''
       '''''''''''''''''''''''''''''''''''''''''''[/b]

       Response.Write("<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">")
       Response.Write("<HTML><TITLE>" & pageTitle & "</TITLE><BODY bgcolor=""#000000""><font face=""Lucida Console"" size=""2"" color=""#FFFFFF"">")

       If TCAdminSDK.Web.Session.IsAuthenticated Then
           Dim serviceid As String = Request.QueryString("serviceid")
           Dim service As New TCAdminSDK.Objects.Service
           service.ServiceID = serviceid
           If service.Find Then

               Dim path As String = System.IO.Path.Combine(service.AutomationFilesPath, relativePath)
               command = command.Replace("%path%", path)

               Response.Write(startMessage)
               Response.Flush()

               If service.UserID = TCAdminSDK.Web.Session.CurrentUser Or TCAdminSDK.Web.Session.CurrentUserType = TCAdminSDK.Objects.UserType.Admin Or TCAdminSDK.Web.Session.CurrentUserType = TCAdminSDK.Objects.UserType.SubAdmin Then

                   Dim serviceWasRunning As Boolean = False
                   If stopGameServer And service.CurrentStatus = TCAdminSDK.Objects.ServiceStatus.Running Then
                       Response.Write("Stopping the game server...")
                       Response.Flush()

                       service.Stop()
                       serviceWasRunning = True
                   End If

                   Dim serverplugin As TCAdminBase.Plugins.IGenericPlugIn = TCAdminSDK.Remote.InstanceCreator.GetPluginFromServer(service.ServerID, "TCAdminMonitor.StandardPlugins.RemoteServers.ServerUtilities")
                   serverplugin.Execute(New Object() {"ExecuteScript", service.WorkingDirectory, command})

                   If serviceWasRunning Then
                       Response.Write("Starting the game server...")
                       Response.Flush()
                       service.Start()
                   End If
               End If

               Response.Write(endMessage)
               Response.Flush()
           End If
       End If

       Response.Write("</font></BODY></HTML>")
%>

2- Create a custom link in System Settings > Custom Links with the following information:

 

[b]Page:[/b] Game Server Home Page
[b]Visible For:[/b] Any game that uses Punkbuster
[b]URL:[/b] javascript:void OpenConsoleWindow('deletepblogs.aspx?serviceid=%serviceid%','deletepblogs%serviceid%','This will delete the Punkbuster log files. Do you want to continue?')
[b]Icon Text:[/b] Delete Punkbuster Logs
[b]Image URL[/b] Images/MenuIcons/PunkBuster.png
[b]Mouse Over Text:[/b] Delete this game server's Punkbuster logs.
[b]Place After Icon:[/b] Update Punkbuster

If you select a game server of that game type you should see the delte pb logs icon.

 

Important information if you add more than one of these icons

Since the URL is the table's key it should be different for every icon you create. To work around this problem you can make each URL slightly different. For example:

javascript:void OpenConsoleWindow('deletepblogs.aspx?serviceid=%serviceid%&1','deletepblogs%serviceid%','This will delete the Punkbuster log files. Do you want to continue?')

 

javascript:void OpenConsoleWindow('deletepblogs.aspx?serviceid=%serviceid%&2','deletepblogs%serviceid%','This will delete the Punkbuster log files. Do you want to continue?')

 

javascript:void OpenConsoleWindow('deletepblogs.aspx?serviceid=%serviceid%&3','deletepblogs%serviceid%','This will delete the Punkbuster log files. Do you want to continue?')

Edited by LFA
Link to comment
Share on other sites

To see the complete command being executed you can change:

serverplugin.Execute(New Object() {"ExecuteScript", service.WorkingDirectory, command})

to:

Response.Write("Command: " & command & "<br>")
serverplugin.Execute(New Object() {"ExecuteScript", service.WorkingDirectory, command})

 

Then you can run the command shown from a command prompt on the server to see if there is any error shown.

Link to comment
Share on other sites

  • 2 weeks later...

Mine says it's deleting the files, yet the files still remain

 

Deleting log files...
Command: del C:\UserFiles\xxx\GameServers\TC56536020848438344322342\pb\svlogs\*.log
Log files have been deleted.
You can close this window.

 

//edit never mind I see the error

Link to comment
Share on other sites

You need to change the relative path because logs and images are stored in a different folder.

 

Dim relativePath As String = "pb"

 

 

And each command needs a new line:

Dim newline as String = chr(13) & chr(10)
Dim command As String = "del %path%\svlogs\*.log" & newline & "del %path%\svss\*.png"

Link to comment
Share on other sites

  • 2 weeks later...
You can modify the script so it generates 2 del commands instead of one.

 

I am confused about execute both comands in one script.

 

Could you please post an example script that:

 

stop server

delete log folder

delete ss folder

start server

 

thanks

Link to comment
Share on other sites

optmized for cod use

 

delete main/logs

delete pb/ss

delete pb/logs

 

<%

'''''''''''''''''''''''''''''''''''''''''''

'Variables

'''''''''''''''''''''''''''''''''''''''''''

 

Dim pageTitle As String = "Delete Punkbuster Logs"

Dim stopGameServer As Boolean = True

Dim relativePath As String = "pb"

Dim newline as String = chr(13) & chr(10) & chr(10) & chr(10)

Dim command As String = "del %path%\svlogs\*.log" & newline & "del %path%\svss\*.png" & newline & "del

 

%path%\svss\*.htm" & newline & "del main\*.log"

Dim startMessage As String = "Deleting log files...<br>"

Dim endMessage As String = "Log and screenshot files have been deleted.<br>You can close this window."

 

'''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''''''''''''''

 

Response.Write("<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">")

Response.Write("<HTML><TITLE>" & pageTitle & "</TITLE><BODY bgcolor=""#000000""><font face=""Lucida Console""

 

size=""2"" color=""#FFFFFF"">")

 

If TCAdminSDK.Web.Session.IsAuthenticated Then

Dim serviceid As String = Request.QueryString("serviceid")

Dim service As New TCAdminSDK.Objects.Service

service.ServiceID = serviceid

If service.Find Then

 

Dim path As String = System.IO.Path.Combine(service.AutomationFilesPath, relativePath)

command = command.Replace("%path%", path)

 

Response.Write(startMessage)

Response.Flush()

 

If service.UserID = TCAdminSDK.Web.Session.CurrentUser Or TCAdminSDK.Web.Session.CurrentUserType =

 

TCAdminSDK.Objects.UserType.Admin Or TCAdminSDK.Web.Session.CurrentUserType = TCAdminSDK.Objects.UserType.SubAdmin Then

 

Dim serviceWasRunning As Boolean = False

If stopGameServer And service.CurrentStatus = TCAdminSDK.Objects.ServiceStatus.Running Then

Response.Write("Stopping the game server...")

Response.Flush()

 

service.Stop()

serviceWasRunning = True

End If

 

Dim serverplugin As TCAdminBase.Plugins.IGenericPlugIn =

 

TCAdminSDK.Remote.InstanceCreator.GetPluginFromServer(service.ServerID,

 

"TCAdminMonitor.StandardPlugins.RemoteServers.ServerUtilities")

Response.Write("Command: " & command & "<br>")

serverplugin.Execute(New Object() {"ExecuteScript", service.WorkingDirectory, command})

 

If serviceWasRunning Then

Response.Write("Starting the game server...")

Response.Flush()

service.Start()

End If

End If

 

Response.Write(endMessage)

Response.Flush()

End If

End If

 

Response.Write("</font></BODY></HTML>")

%>2- Create a custom link in System Settings > Custom Links

Link to comment
Share on other sites

I'm getting this error:

 

Access is denied.

Description: An error occurred while accessing the resources required to serve this request. You might not have permission to view the requested resources.

 

Error message 401.3: You do not have permission to view this directory or page using the credentials you supplied (access denied due to ACLs). Ask the Web server's administrator to give you access.

Link to comment
Share on other sites

Would it be as simple as adding another line?

 

Dim relativePath As String =

 

I'd be interested in making this script clean up all of PB by removing screenshots and their HTM files as well. :D

 

I added this already to the scripts section.

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use