1. When making a thread, please tag your thread accordingly using the menu to the left of the textfield where you name your thread where applicable. Server Advertisements and Mod Releases should be contained to their respective subforums.

Tutorial Custom Linux Admin Tools

Discussion in 'Multiplayer' started by mcapplbee, Dec 11, 2013.

  1. mcapplbee

    mcapplbee Space Hobo

    Hey guys,

    I wrote 2 tools so far that I use on my starbound server. They might become useless without notice, or the features they try to replicate might get patched in. Maybe you'll appreciate them, maybe not.

    Here goes


    who.py
    Parses your starbound_server.log and tells you who is currently connected to your server. It's really hacky, but (to my knowledge) there's no other way to get current player count / connection info without digging through the log. This script probably works on Windows as well with Python 2.7X for Windows.


    Requirements
    Python 2.7+ (uses all built-in commands, no dependencies)


    Configuration
    Change STARBOUND_LOGFILE to point to your log location.


    Usage
    $ ./who.py
    Total Connected Players: 2
    [client Jimbo = connected]
    [client billy crystal awesome guy = connected]


    Caveats
    Because of how I wrote it, it will take longer and longer the bigger your starbound_server.log file gets. The execution time is still negligible as the script imports absolutely no modules. In any case, you should probably set up logrotate. Massive single-file logs benefit no one.


    setup-whitelist.sh
    Sets up iptables rules (but only on the starbound port). It will drop all traffic on STARBOUND_PORT except to whichever ip addresses you specify. Basically, your starbound server will be invisible to the outside world unless you explicitly whitelist an IP address.

    Requirements
    root / sudo access to server. iptables installed.


    Configuration
    insert every IP address you wish to whitelist in between the double quotes
    WHITELIST=\
    "
    x.x.x.x
    y.y.y.y
    z.z.z.z
    "

    Caveats
    Must be executed as root. Must be re-run every single time you update the WHITELIST variable. The changes will go into effect immediately (user will basically be kick / banned). This will also clear any iptables rules you have previously set up... although if you know how to do that already, you don't need my script.
    If you want to reverse all the changes this script causes, just run $ sudo iptables --flush
     
    Last edited: Dec 23, 2013
    false_chicken and Fleder like this.
  2. Churpy

    Churpy Void-Bound Voyager

    Pretty neat and handy, nice work.
     
  3. Clinton

    Clinton Zero Gravity Genie

    Nice work!
     
    gnosticJade likes this.
  4. bkg

    bkg Subatomic Cosmonaut

    Nice.
     
  5. BMZ_G

    BMZ_G Poptop Tamer

    Can't believe they haven't hooked up IP's to the connection log.
     
  6. Lila

    Lila Phantasmal Quasar

  7. sovredcat

    sovredcat Big Damn Hero

    Hey, awesome! However who.py doesn't work for players with spaces in their names.
     
  8. Katorone

    Katorone Giant Laser Beams

    It is possible to give the user you're running it on sudo privileges to iptables as well (and only iptables). This makes the script less likely to exploit other root commands, but opens up iptables for any users of that login.
     
  9. Shirou

    Shirou Aquatic Astronaut

    Will this work on Windows?
     
  10. Churpy

    Churpy Void-Bound Voyager

    It will probably need some tweaking and you will need to install Python for Windows, of course.
     
  11. Shirou

    Shirou Aquatic Astronaut

    I got Python installed on my windows server, what tweaking will be needed to get this working on windows?
     
  12. Churpy

    Churpy Void-Bound Voyager

    I've not taken a look at the python scripts but you might need to change stuff like path names and anything that would differ between Windows and Linux operating systems. Perhaps not, sadly my server is Linux so I can't test this out for you.
     
  13. Shirou

    Shirou Aquatic Astronaut

    Yea need some scripts for windows like this would be cool :) really don't feel like loading a linux server just for this.
     
  14. mcapplbee

    mcapplbee Space Hobo

    Hey guys! Thanks for all the positive feedback!
    @sovredcat I've fixed who.py, it now parses users with spaces in their name. :) -- the only thing that might break it is players with < or > characters in their names.
    The script *should* work on windows out of the box, the only thing you need to change is the path (unix paths use /path/to/file, windows paths are C:\path\to\file) , so you just change the STARBOUND_LOGFILE variable to point to where your log is.
     
  15. Darthkatzs

    Darthkatzs Space Hobo

    Very nice, I'll take a look at these.
     
  16. Shirou

    Shirou Aquatic Astronaut

    Hi, i've install that version on my windows server and then open the gui and copy the who.py in it and change the log location to mine and then press enter but nothing happens?
     
  17. Shirou

    Shirou Aquatic Astronaut

    Got it working :) now the question is to auto run this each time and save it to a php file or something..
     
  18. shibdib

    shibdib Starship Captain

    Safe to say I don't know python (I have it installed and the script runs.. i think).. what does who.py "print" too on windows? Anyway I can have it write to a text file?
     
    Last edited: Dec 12, 2013
  19. mcapplbee

    mcapplbee Space Hobo

    You can use an output redirect to have it write to a text file

    linux
    $ ./who.py > players.txt

    windows
    $ python who.py > players.txt

    > will overwrite the file
    >> will append to the end of the file.
     
  20. shibdib

    shibdib Starship Captain

    Where would I use that line?
     

Share This Page