GameServerManagers / LinuxGSM

The command-line tool for quick, simple deployment and management of Linux dedicated game servers.
https://linuxgsm.com
MIT License
4.31k stars 820 forks source link

JimTR Web Interface #814

Closed JimTR closed 7 years ago

JimTR commented 8 years ago

Currently The Code I have written has the following features -

  1. Allows Game control from either a local host or a remote host , the remote option does require a valid unix user on the remote machine & this user name & password is passed to the remote server to ensure the permissions are correct.
  2. HTML is created via a template engine I coded for another project, which ensures that php code is not allowed in the html file, all results from PHP are fed into the html using variables before PHP renders the completed file, from this a subset of files can be added to the main html file meaning jscript etc. can be added before the browser loads the file so the included are all in-line rather than being loaded from a resource as the browser renders the page.

Requirements from lgsm is to remove the ansi codes from its displays as the web interface currently uses the PHP exec function to get the data back from lsgm example - exec($path."gmodserver start",$output1) where the $path variable has been setup up earlier ( point 1) and lgsm's responses, in this example, are stored in the variable $output1 ... $output1 then has to be sanitized of ansi ( as css will style the responses back from lgsm). I guess a variable in the lgsm script could be set to stop ansi codes being sent maybe gui = 1 or 0 depending if ansi is required or not. apart from that I guess everything will work fine .... I'll let you know if I hit other points. Currently there is No Git for this project but I will drop a link here when I have the structure of the git done

dgibbs64 commented 8 years ago

Hmmm not sure the best way to go about striping/adding the ansi code in the correct places since they are pretty much just part of the echo commands. Having to separate messages its inefficient so my guess is teh best way to go about it is to somehow insert the ansi by default and have an option to disable it. I don't really want to loose the pretty command line colours haha. I will have a good think about this. Suggestions welcome

Also do you have a screenshot I would like to see what it looks like :)

AlexCS1337 commented 8 years ago

Interesting!

JimTR commented 8 years ago

How the panel will look like is up to you, So I could send you a screen shot of how I see it & within 10 mins someone else could alter the css and or HTML to look totally different, however I will up load a screen shot of how I set the html ... example of the way a html file is coded is `

Your Resource

Game Ports
#ownedports#
Game Slots
#ownedslots#
Disk Space
#total#



Used Resource

Allocated Ports
#usedports#/#ownedports#
Allocated Slots
Slots In Use
#total_players#
` from this you can see the responses from lsgm are injected into the html before it is rendered so **** contains the total number of players on the server ... bad example really as this value is returned from the gameQ class and not lsgm... if you want I'll throw up a game server & an example of how I think the html should look ... I'll post back when the demo is running
UltimateByte commented 8 years ago

So if i'm getting it, you need a single user for all servers in order for it to work ? And the PHP/Web server has to be on the same machine as the "game" server ? Or can it be another machine, or even a slave, and a master ?

An amazing thing would be to have some kind of an admin interface to manage users and give them permissions to control some servers only (using a database for example). That way, you could allow a given admin to view some server status, start/stop/restart it, but not wipe/reinstall or port change.

Game query is a good example actually, we talked about it at some point. It's really something to add to LGSM that would allow nice features.(like saving CPU by rebooting a server if 0 players are connected, but CPU usage is > 50%). I'll open an issue after the next major update. :)

JimTR commented 8 years ago

you can have a remote game server to the web server ... a simple method is to have both on the same server but the demo I am putting up at the moment will show the web interface on one server & the game running on another

UltimateByte commented 8 years ago

So it's a master/slave system, but they can also be both on the same machine. Perfect :) Security will have to rock on this though. But all servers have to be on the same user, right ?

JHulsmans commented 8 years ago

I think it's best to differentiate between LSGM for personal use and LSGM for use with multiple servers and multiple different users. With the lather it'd be best to have each server run on a different user.

I don't think there's much overhead for having different users per server anyway so it might be best practice to always do this.

JimTR commented 8 years ago

That is exactly how the remote setup works

UltimateByte commented 8 years ago

So PHP is able to run commands as a user onto the slave as long as it has its IDs. Couldn't dream better. :)

JimTR commented 8 years ago

there are some caveats which I will explain later but are of no real problem if you can use linux ... so we have a demo running .... goto lightsoundstudios.eu login with the username 'tracey' password is tester . click my area then click game control panel you will notice the web stuff is on a different IP/machine/server to the game server. currently all the controls have been disabled as this is just an idea on what my html looks like

JimTR commented 8 years ago

Something else that I forgot could lgsm add the port to the service name so when servicename is defined, it is like this - servicename="servername-"${port} this may require an extra setup question to confirm the port ... however I guess the web interface could write all used ports to a file & lgsm just add 1 to the last entry in the file as the web interface would just write the file in port order

jaredballou commented 8 years ago

It should be able to read the lgsm script or config to extract the port, right?

JimTR commented 8 years ago

no this just makes it a bit easier to identify the tmux window when you are running more than one server, example - gmodserver-27015 & gmodserver-27035 rather than reading the script(s) each time you want to find out what the tmux window has been created as . The web GUi on install, names the base script with it's port appended so I guess I could rename the service name at the same time of altering the port in the script.

JimTR commented 8 years ago

Over the weekend I have taken the web gui away from a plugin to my frame work and made it a stand alone project there is a demo at http://noideergames.cu.cc/ with the same login ... This is going to be a little harder to get right as a stand alone (there were so many framework functions the plugin used but it may be a better design in the end. I have opened up the 'join game' button so you can test the players online function

JimTR commented 8 years ago

I really need some way around this ... for web purpose perhaps the scripts are a bit too verbose I get returns from them like

Array ( [0] => [ .... ] Starting gmod-server-27015: Garry's Mod Web GUI Test [ INFO ] Starting gmod-server-27015: Garry's Mod Web GUI Test is already running )

where as all I need is a flag .. E.G Started,didn't start,already running so the script could just return 1 of 3 values E.G 0 or 1 or 2 rather than searching the return string for something (example : - already running ) as if the text is changed by either language or content the web interface will fail

dgibbs64 commented 8 years ago

sounds like you need exit codes. if you run a command then to echo $? you get the exit code. this normally returns 0 for OK or another number for an error.

Since you already know the command you are running you simply need to basically get an OK or FAIL message so the web interface knows if the command worked or not. LGSM already uses exit codes 0 and 1. However I can customize the codes and then put together a list of what the error mean. that way if the script returns for example error 5 you can print on the interface "FAIL! Low disk space" or something to that effect.

Let me know if you think exit codes could work for your interface

JimTR commented 8 years ago

Exit codes will work well, the php exec function has a return variable for that. so a list of exit codes and their meanings will be spot on

dgibbs64 commented 8 years ago

Cool I dont have a list of anything yet but I will start putting together something.

JimTR commented 8 years ago

There is now a git .. here To be fair don't download the code yet as there is no install routine yet but if you are brave let me know & I'll walk you through the install. But I guess you can open issues there regarding the demo noted above.

elstringer commented 8 years ago

I think there is too much apelle outdoor URL to retrieve a lot of information

JimTR commented 8 years ago

If I understood what you said I could respond

dgibbs64 commented 8 years ago

Im wondering if somthing like this might help https://github.com/pixelb/scripts/blob/master/scripts/ansi2html.sh

JimTR commented 8 years ago

had a play with ansi2html.sh and it does not really do it as it returns formatted html and not just the data and (to date) I have not found a method to echo to the screen rather than a file. Php retruns the terminal output and exit code to the calling proceedure via the exec function. So using exit codes is by far the best option .. using codes I can just disregard the output from LGSM and use the exit code to display what is required.

dgibbs64 commented 8 years ago

The issue I can see with disregarding messages from LGSM is that should the message change you will have to update the message on the web interface manually. It would be better to be able to use the LGSM message. Currently 99% of my exit codes are either 0 or 1 as more complex codes have not yet been required. I was wondering if its possible for php to strip the ANSI color codes from the output before displaying the output to the interface? I currently do similar with sed in BASH for stripping stuff out of config files. Maybe something along these lines? http://stackoverflow.com/questions/1176904/php-how-to-remove-all-non-printable-characters-in-a-string

I am just trying to figure out a way to cut out us having to do a load of work now and in the future. Being able to strip out the ANSI codes and also return a pass or fail should be enough most of the time. Unless a different exit code is specifically required which we can do on a case by case basis.

I also want to try and avoid your interface accidentally breaking should I make any changes.

Also just a reminder I am by no means a php expert and know very little myself so you will have to bear with me when it comes to some php stuff

federicovilla commented 8 years ago

Really interesting project!

JimTR commented 8 years ago

I was going to update the strings on LGSM to suit language so the web interface could display 'starting gmodserver' to an english speaking client & 'Démarrage gmod - serveur' to a french speaking client ! The web interface has basic IP country tracking so another feature of the web interface was to switch langs where applicable, so if there are any non English speakers out there that wish to translate the strings into their mother tongue open an issue on my git. From that all i need is exit codes perhaps a structure could be built like so : function code
check.sh 1x check_config.sh 2x check_deps.sh 3x and so on. As you can see the first number could indicate the script and x is the exit code. eg 10 could equal check.sh terminated without errors & 11 could mean check.sh terminated with some error etc.

the sent link is how I have implemented already but thinking of translations it not going to work very well where as exit codes will !

`

JimTR commented 8 years ago

I have started on the install page now my question is :- is there a resource somewhere that gives me a list of all server scripts that have been made and a url for them so the web interface can download the right script & run the install routine. With regard to dependants is there a resource that tells me what is required for each script or are all dependants the same on all scripts ?

rip1980 commented 8 years ago

I was just looking because I'm doing something similar for a non-technical user on linux.

Simply using MONIT (Not affiliated in anyway, for the curious: https://mmonit.com/monit/#about) and kludging my way into the scripts, for instance on cs1.6:

./csserver monitor >> /dev/null ; echo $?

To get an easy status without changing anything. Just mentioning it because it may be helpful hacking up something existing than starting from scratch.

JimTR commented 8 years ago

I don't really need this as PHP returns the exit code

dgibbs64 commented 8 years ago

@JimTR I think you need to message me directory on Steam as im missing stuff on here and I will be able to answer you a quicker.

dgibbs64 commented 8 years ago

OK so I will look at adding exit codes as suggested each file will have a number and the exit code of either 0 or 1 I will create a branch for this to investigate https://github.com/dgibbs64/linuxgsm/tree/exitcodes

dgibbs64 commented 8 years ago

Exit codes have been added to the master branch now use ./gamserver dev-debug to see the codes in the script. Also in core_messages.sh is is possible to turn off ANSI. However i am yet to add the variable to the main script files.

JimTR commented 8 years ago

Ok cool so all I need to do is download the functions again or do I need to add the main script ?

dgibbs64 commented 8 years ago

you have just update the functions in the normal way with ./gameserver uf (do this a couple of times. You can also add the variable ansi=off to the main script file and it will remove any colouring.

WriggleDev commented 7 years ago

Any further work on this or someone else doing anything for this at all?

dgibbs64 commented 7 years ago

No update on this in a while. I will close this

lock[bot] commented 6 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.