Inactive [WEB/DEV/ADMIN] HTTPConsole 0.3.0 - Issue Console Commands Over HTTP [803]

Discussion in 'Inactive/Unsupported Plugins' started by BlueJeansAndRain, Apr 11, 2011.

  1. HTTPConsole - Issue Console Commands Over HTTP
    Version: 0.3.0

    I wrote this because I have a bash script which I use to backup the worlds and do mapping and various other manipulations directly on world data. So, I needed a way for the script to tell the server to save-all, then disable saving to copy the worlds, then re-enable saving. I know there are plugins out there that expose a limited API over HTTP, and there's even one that provides telnet access. But the APIs didn't provide the access I wanted and telnet access is too cumbersome.

    While I was at it I figured I would make it capable of issuing any console command. You never know what you might need :).

    WARNING: If you configure this plugin to listen on an ip address open to the internet, and don't restrict client IP addresses (using the white and black lists) to specific IP addresses you trust, someone will hack your server.

    This is my first plugin... actually this is the first thing I've ever written in Java, so be gentle with my source :p. Suggestions welcome.

    Features:
    • Issue any command over HTTP that you can issue on the console.
    • Change the listener IP address, port, and log-level through the config file.
    • Get back the output of the issued command.
      • This only works for some commands, specifically commands that are not "threaded".
    • Accepts GET and POST (url or json encoded) requests.
    • Client IP address whitelist/blacklist.
    • Host name filtering.
    Trouble Shooting: If it doesn't appear to be working, try the following solutions.
    • Change the "port: 8765" configuration option to a different number. Valid values are 1024 - 65565
    • Make sure your firewall is allowing access to the port.
    Download the plugin Jar

    Source Code
    Usage (open)

    Make requests to http://127.0.0.1:8765/console?command=<command> (assuming you're using the default port and the server is running on localhost). If you're running your server locally, just open up your browser and type http://127.0.0.1:8765/console?command=save-all and SAVE THE WORLD!
    Default config.yml (open)

    Code:
    # The IP address that HTTPConsole will listen on. "any" can be used to listen on
    #  any address.
    # The default is 127.0.0.1
    ip-address: 127.0.0.1
    
    # The TCP listening port that HTTPConsole will bind to.
    # The default is 8765.
    port: 8765
    
    # Controls how important a console message must be to be shown.
    # Possible values: severe, warning, info
    # The default is severe, meaning only severe log messages will be visible.
    log-level: severe
    
    # Controls whether messages beginning with "ConsoleCommandSender:" are filtered
    #  out of the console log.
    # The default value is true.
    filter-command-sender: true
    
    # This sets what ip addresses are not allowed to send requests to HTTPConsole.
    # To add more values, just add more "- ipaddress" lines to the list.
    # Add "- any" (no quotes) to the list to block all ip addresses from connecting
    #  to HTTPConsole.
    # Ranges of ip addresses can be set by using two ip addresses seperated by a
    #  hyphen (-), or by using an asterisk (*) in place of any number.
    # Hyphens and asterisks are special characters in yml files so they will have
    #  to be surrounded by quotes (see examples below).
    client-ip-blacklist:
    #   - 192.168.3.2
    #   - "192.168.4.*"
    #   - "192.168.5.1-192.168.6.254"
    #   - any
    
    # This sets what ip addresses are allowed to send requests to HTTPConsole.
    # All ip addresses and ranges that are valid for the blacklist are also valid
    #  for the whitelist.
    client-ip-whitelist:
    #   Example:
    #   - 192.168.1.100
    #   - "192.168.2.*"
    #   - "192.168.0.1-192.168.0.254"
    #   - any
    
    # This changes the order in which the whitelist and blacklist are checked.
    # Possible Values:
    #
    #  "Deny,Allow"
    #   The whitelist is only checked when an ip address matches the blacklist.
    #   If the ip address matches both lists, it will be allowed. If it matches
    #    neither list, it will be allowed.
    #   This behavior matches the Apache "Deny,Allow" Order directive.
    #   This is the default value.
    #
    #  "Allow,Deny"
    #   The blacklist is only checked when an ip address matches the whitelist.
    #   If the ip address matches both lists, it will be denied. If it matches
    #    neither list, it will be denied.
    #   This behavior matches the Apache "Allow,Deny" Order directive.
    #
    white-black-list-order: "Deny,Allow"
    
    # This is a list of the allowed hostnames (domains) that HTTPConsole will
    #  accept requests on. This means that if someone uses
    #  "http://my.domain.com:8765/console?command=stop" to issue the
    #  stop command to your server, and my.domain.com is not listed below, the
    #  connection will be refused.
    # The one exception to the above rule is that If no hostnames are listed than
    #  any hostname will be allowed.
    # This is similar to virtual hosting except that HTTPConsole only uses the
    #  hostname to allow or deny the request.
    # This feature combined with the cross site scripting restrictions in modern
    #  browsers is designed to make it more difficult for unauthorized people
    #  to target your server from client side (browser) scripts. This does not make
    #  it impossible however as they can always create a proxy if they really want
    #  to send requests from the browser.
    # If any hostnames are listed, requests to bare ip addresses will be denied
    #  unless the ip address is 127.0.0.1.
    # An asterisk (*) in the left most label will match any valid label or labels.
    # At the very least one label and a top level domain (com, org, net, etc.) must
    #  be given per hostname.
    allowed-hosts:
    #   - theanticookie.com
    #   - notch.tumblr.com
    #   - "*.minecraft.net"
    
    # Controls whether connection refused log messages are always sent, or only sent
    #  when log-level is set to info.
    # The default value is false. Connection refused messages will only be visible
    #  if the log-level is set to info.
    always-log-refused-connections: false
    
    Example Backup Bash Script (open)

    This is the backup script I use for my own server.
    Code:
    #!/bin/bash
    BACKUP_DAYS=28
    MINECRAFT_DIR=/home/me/minecraft
    BACKUP_DIR=$MINECRAFT_DIR/backup
    HTTPCONSOLE_URL="http://127.0.0.1:8765"
    
    BASENAME=`basename $0`
    LOCK_FILE=/tmp/$BASENAME.lock
    if [ ! -e "$LOCK_FILE" ]; then
            trap "rm -f \"$LOCK_FILE\"; exit" INT TERM EXIT
            touch $LOCK_FILE
    else
            echo "Backup already running."
            exit
    fi
    
    if [ "$1" == "" ]; then
            echo No worlds specified.
            exit
    fi
    
    TIMESTAMP=`date +%Y-%m-%d_%T`
    
    function console_command
    {
            curl --data-urlencode "command=$*" $HTTPCONSOLE_URL/console
    }
    
    function backup
    {
            WORLD=$1
            SOURCE=$MINECRAFT_DIR/$WORLD/
            TARGET_DIR=$BACKUP_DIR/$WORLD
            TARGET=$TARGET_DIR/$TIMESTAMP
    
            if [ ! -d "$SOURCE" ]; then
                    echo World directory \"$SOURCE\" does not exist.
                    return
            fi
    
            if [ -d "$TARGET_DIR" ]; then
                    if [ -e "$TARGET" ]; then
                            echo Backup path \"$TARGET\" already exists.
                            return
                    fi
    
                    NEWEST_FILE=`ls -t "$TARGET_DIR" 2>/dev/null | head -1`
                    if [ "$NEWEST_FILE" != "" ]; then
                            NEWEST_FILE=$TARGET_DIR/$NEWEST_FILE
                            echo Sourcing Most Recent Backup \"$NEWEST_FILE\"
                            cp -al "$NEWEST_FILE" "$TARGET"
                    else
                            echo No Prior Backups
                    fi
    
                    echo Deleting Backups Older Than $BACKUP_DAYS Days
                    find "$TARGET_DIR/"* -maxdepth 0 -mtime +$BACKUP_DAYS -delete
            elif [ -e "$TARGET_DIR" ]; then
                    echo The backup path \"$TARGET_DIR exists but is not a directory.
                    return
            else
                    mkdir -p "$TARGET_DIR"
            fi
    
            echo Syncing \"$SOURCE\" to \"$TARGET\"
            rsync -a --delete "$SOURCE" "$TARGET"
    }
    
    echo Saving All Minecraft Worlds
    console_command say Backing Up Worlds...
    console_command save-all
    console_command save-off
    echo
    
    for LEVEL in "[email protected]"; do
            echo Backing Up \"$LEVEL\"
            backup $LEVEL
            echo
    done
    
    console_command save-on
    console_command say Backup Complete.
    
    Todo (open)

    • Wait for some log output before completing a request.
    • Return command output.
    • Have the response body be more meaningful than "Recieved Command <command>"
    • Respond to URL or JSON encoded POST requests.
    • Allow the listener address to be changed (not just 127.0.0.1 anymore).
    • Client ip whitelist.
    • Client ip blacklist.
    • Host name filtering.
    • Cookie based sessions. (finished, testing)
    • Get back buffered console output. (finished, testing)
    • Basic/Digest http authorization. (in progress)
    • Command whitelist/blacklist. Allow or disallow some commands.
    • Allow disabling of POST xor GET requests.
    • Write example web page for a console in your browser.
    • Possibly create a new service for restarting the server?
      • Not going to add this because it can be added by getting a plugin that does server restarts and then giving that plugin commands through HTTPConsole.
    • Expose a request handling API to bukkit allowing developers to easily add web service functionality to their plugins.
    • Profit?!
    Change Log (open)


    Version 0.3.0
    • Added blacklist.
    • Added host name filtering.
    • Changed default port to 8765.
    • Bug Fixes
    Version 0.2.1
    • Fixed input stream parsing.
    Version 0.2
    • Reworked logging and output.
    • Handle POST requests (url or json encoded data).
    • Return output from command (easier than I expected).
    • Abstracted a lot of the framework to pave the way for increased future functionality.
    • Listener ip address can be changes via the config.yml file.
    • A client ip address whitelist can be set via the config.yml file.
    Version 0.1
    • Initial Release
     
  2. Offline

    Stonebreak

    for the http console
     
  3. Offline

    King_KYl3

    Can you say this could be used for donating, once some1 donates thouhgt your website and when the money goes thought into paypal it issues a command and ranks them up?
     
  4. Offline

    mnpeep

    1 question, sorry if its written and I didn't read, can I use multiple variables in a command?
    EX: http:/ip:1337/console?command=groupadd bleh waiting tinykraft

    is that possible? this command is from permissions plus if it helps
     
  5. Offline

    Herover

    If you URL-encode it, yes.
    The code for a space would be %20, so your request would be:
    http:/ip:1337/console?command=groupadd%20bleh%20waiting%20tinykraft
     
  6. Offline

    mnpeep

    Yeah I just tested it, it does work.

    THANKS MAN! Helping me make a registration system for my server!
     
  7. Will this be moved over to bukkitdev? I really LOVE this plugin, and losing it would be horrible for my server.
     
  8. Offline

    Doc

    With bukkit 1192+
    Blocked access to ColouredConsoleSenders constructor, implemented getConsoleSender
    LogBlock and others need 1191 or higher for bugfixes.

    Code:
    [SEVERE] Error occurred while enabling HTTPConsole v0.3.0 (Is it up to date?): tried to access method org.bukkit.command.ConsoleCommandSender.<init>(Lorg/bukkit/Server;)V from class org.theanticookie.bukkit.httpconsole.ConsoleRequestHandler
    java.lang.IllegalAccessError: tried to access method org.bukkit.command.ConsoleCommandSender.<init>(Lorg/bukkit/Server;)V from class org.theanticookie.bukkit.httpconsole.ConsoleRequestHandler
            at org.theanticookie.bukkit.httpconsole.ConsoleRequestHandler.<init>(ConsoleRequestHandler.java:73)
            at org.theanticookie.bukkit.HTTPConsole.onEnable(HTTPConsole.java:180)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:126)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:920)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:174)
            at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:157)
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:297)
            at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:284)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:152)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:348)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
     
  9. Great. :C
    If anyone wants to pick this up, I'd greatly appreciate it.
     
  10. Offline

    Herover

    I found this to be working on the newest bukkit.
     
  11. Offline

    spunkiie

    Yeap, this great plugin doesn't work with recent builds, the author doesn't log in since june.. so, yes, we can assume it's dead :(

    Can any developer please take over the project ?
     
  12. Offline

    Doc

    We knew this day was coming! This is NOW broken...(officially)
    RB1240
    This plugin is broken on build 1192+

    Blocked access to ColouredConsoleSenders constructor, implemented getConsoleSender
    LogBlock and others need 1191 or higher for bugfixes.

    Code:
    [SEVERE] Error occurred while enabling HTTPConsole v0.3.0 (Is it up to date?): tried to access method org.bukkit.command.ConsoleCommandSender.<init>(Lorg/bukkit/Server;)V from class org.theanticookie.bukkit.httpconsole.ConsoleRequestHandler
    java.lang.IllegalAccessError: tried to access method org.bukkit.command.ConsoleCommandSender.<init>(Lorg/bukkit/Server;)V from class org.theanticookie.bukkit.httpconsole.ConsoleRequestHandler
            at org.theanticookie.bukkit.httpconsole.ConsoleRequestHandler.<init>(ConsoleRequestHandler.java:73)
            at org.theanticookie.bukkit.HTTPConsole.onEnable(HTTPConsole.java:180)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:126)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:920)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:174)
            at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:157)
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:297)
            at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:284)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:152)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:348)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
    I was hoping that the developer was just waiting until it was an official release.
    Is the dev active? In my opinion this is the best plugin out there.
    AND the only one that runs from shell natively.
     
  13. Offline

    VADemon

    @Doc
    Agree, it's broken.
    And the dev will never come back! never... never... never...
    "BlueJeansAndRain was last seen:
    Jun 6, 2011"
     
  14. Offline

    Engelier

  15. Offline

    VADemon

  16. Offline

    spunkiie

    Engelier: Thank you very much. :)

    Work like a charm
     
  17. Offline

    Fatih199415

    Dont work with "Recommended Build: 1240 (MC: 1.8.1)"

    Code:
    19:02:43 [SCHWERWIEGEND] Error occurred while enabling HTTPConsole v0.3.0 (Is it up to date?): tried to access method org.bukkit.command.ConsoleCommandSender.<init>(Lorg/bukkit/Server;)V from class org.theanticookie.bukkit.httpconsole.ConsoleRequestHandler
    java.lang.IllegalAccessError: tried to access method org.bukkit.command.ConsoleCommandSender.<init>(Lorg/bukkit/Server;)V from class org.theanticookie.bukkit.httpconsole.ConsoleRequestHandler
            at org.theanticookie.bukkit.httpconsole.ConsoleRequestHandler.<init>(ConsoleRequestHandler.java:73)
            at org.theanticookie.bukkit.HTTPConsole.onEnable(HTTPConsole.java:180)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:126)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:941)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:174)
            at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:157)
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:297)
            at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:284)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:152)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:348)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
    
     
  18. I'm talking with a developer to work some sort of solution out with this.
     
  19. Offline

    clayfreeman

    I love this plugin. I am currently using it to manage user groups to make users Veterans after they have been whitelisted for 28 days. It also checks for user group title conflicts. I have a ranking system in place that overrides someone's title if PermissionsEx assigns them the wrong title. It also has a backup function that rsyncs to my DreamHost (web hosting company) FTP account so that I can have a donor package for people to download world backups for single player. And last, but not least, I have it flush the world to disk every 15 mins. so that chunk degeneration is a thing of the past. This is all written in PHP which is run from the PHP-CLI in my crontab. I _LOVE_ this plugin! Thanks for writing it!
     
    HmmmQuestionMark likes this.
  20. Offline

    Source011

  21. Offline

    Engelier

  22. Offline

    childersc

    This does not seem to be working on the 1337 release.

     
  23. Offline

    VADemon

  24. Offline

    KA_Gamer

    Is there an update for 1.0.1?
     
  25. Offline

    VADemon

  26. Offline

    NaNdummy

    Can I implement your plug-in in my plug-in?
     
  27. Offline

    Noobscraft

    Please update this awesome plugin :3
     
  28. Offline

    Stortcraft

    HI can you use this to rank people up when they sign up on a website?
     
  29. Offline

    Doc

    Yes!
    I created a registration system based around this. It is VERY handy.
     
  30. Offline

    Stortcraft

    oh brilliant could u send me how to do it please :)
     
  31. Offline

    Harley

    @VADemon Even with using that latest link, the errors still occur.

    Code:
    20:09:49 [SEVERE] HTTPConsole: Error creating HTTP server
    2012-01-01 20:09:49 [SEVERE] null
    java.lang.NullPointerException
        at org.theanticookie.bukkit.HTTPConsole.onEnable(HTTPConsole.java:188)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:188)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:968)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:186)
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:169)
        at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:432)
        at org.bukkit.Bukkit.reload(Bukkit.java:187)
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:22)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:165)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:374)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:370)
        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:558)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:535)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    2012-01-01 20:09:49 [SEVERE] Error occurred while disabling HTTPConsole v0.3.2 (Is it up to date?): null
    java.lang.NullPointerException
        at org.theanticookie.bukkit.httpconsole.HTTPServer.stopServer(HTTPServer.java:301)
        at org.theanticookie.bukkit.HTTPConsole.onDisable(HTTPConsole.java:208)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:190)
        at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:989)
        at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:296)
        at org.theanticookie.bukkit.HTTPConsole.disablePlugin(HTTPConsole.java:95)
        at org.theanticookie.bukkit.HTTPConsole.onEnable(HTTPConsole.java:198)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:188)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:968)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:186)
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:169)
        at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:432)
        at org.bukkit.Bukkit.reload(Bukkit.java:187)
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:22)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:165)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:374)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:370)
        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:558)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:535)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    @Engelier @HmmmQuestionMark Any updates on this?

    @childersc we both had those errors, i found out why.

    For anyone in the same position, the errors are caused by the config (config.yml) not existing. Should have been obvious to me!

    Anyway, thanks for an awesome plugin!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016

Share This Page