[REQ] Communication FROM craftbukkit TO webserver

Discussion in 'Archived: Plugin Requests' started by MariuszT, Jun 10, 2011.

  1. Offline

    MariuszT

    Hi all!

    I found some plugins that allows communication from PHP/Bash/etc. to Craftbukkit but there is no plugin that would operate in the other direction.

    It would be great if I could type the command /websend XYZ and plugin will send to selected PHP script information XYZ (and who has sent a command) via GET/POST. I think it would be necessary a secret password that no one could call the script from the web browser.

    What do you think about it?
     
  2. Offline

    vericgar

    I could maybe probably do this, it would be a good first plugin to cut my teeth on... but I need to know if how I'm reading your request is correct. When you type /websend XYZ in game, it would do a POST (or GET) to a PHP script (or any URL really), and make that data available in a php script with the following variables:

    $_POST['secret'] (shared secret between bukkit and php script - simple authentication)
    $_POST['who'] (the minecraft user who sent the command)
    $_POST['payload'] (whatever you typed)

    The configuration for bukkit would look something like:

    url: http://example.com/yourscript.php
    secret: shared-sekrit-goes-here
     
  3. Offline

    mrvertigo27

    the way i read it was bukkit outputs to a web language for interpretation. do you mean like dynmap with added commands or command line?

    or maybe a gui with config controls checkboxes for mobs on off ect like setting up a router.....
     
  4. Offline

    MariuszT

    Exactly! I have nothing more to write, you understood me perfectly :)

    I propose a POST method.
     
  5. Offline

    Waterflames

  6. Offline

    Waterflames

    I made a alpha version of my plugin. (MinePHPTalk)

    Instructions:
    • Download the zip.
    • Copy the plugin to your minecraft server plugin folder.
    • Run the server to allow the configuration to be generated.
    • In the downloaded zip, open "PACP1Generator.jar".
    • Write a password in the textbox (no numbers or special symbols allowed). Be sure to remember the password. We will need it later on.
    • Click the generate button, copy the code and open "minecraftPHPcom.php".
    • Replace "PasteYourCodeHere" with the code.
    • Upload minecraftPHPcom.php to your web server.
    • In your server folder go to /plugins/MinePHPTalk and open config.txt
    • Replace the url and the password with the right values.
    • Save, reload the server and enjoy. (Type /php.send setweather to test)
    Try it out so I can get some bugs out before I release it.
     

    Attached Files:

  7. Offline

    MariuszT

    It's working! :)

    First of all, maybe change the name of the plugin? He is not limited to PHP. The name should be something like "WebSend".

    Secondly, why use PACP1Generator.jar? Better to use MD5.

    Is the script could send an $_POST array? $_POST['args'][0], $_POST['args'][1] instead of $_POST['arg0'], $_POST['arg1'].

    I propose to change the command from /php.send to /websend (The dot is annoying :) ).

    When sending text "A'B" from PHP to server, slash is added ("A\'B").

    There is no lag! Cool! :)
     
  8. Offline

    Waterflames

    Great!

    Not a problem, I will change it.

    Because I have absolutely no experience with MD5 in PHP nor Java nor anywhere else, but I will look into it.

    I tried. And failed. I can try again, maybe I overlooked something.

    Again, not a problem. :)

    Hmmm, thats weird, but I am going to do the other items before this one.

    Hail to the awesome multi threading!
     
  9. Offline

    MariuszT

    Using MD5 in PHP is very simple:

    PHP:
    echo md5('SOME_STRING');
    I don't know Java but Google gives many answers :)


    How you build POST to send? You have something like this?

    Code:
    arg0=A&arg1=B
    If yes, try this:

    Code:
    args[]=A&args[]=B

    PHP adds slashes to data when POST/GET is delivered. Maybe in Java it's also default setting. Look for something that will remove slashes (stripslashes() in PHP) or replace:

    Code:
    \' -> '
    \" -> "
    \\ -> \
     
  10. Offline

    Waterflames

    Thanks, but I found out the array thing 1 hour ago :) It will be in the next version.
    MD5: I'll look into it, but an encryption would be more usefull than a hash...
    About the info on the slashes: really helpfull, I didn't know that!
     
  11. Offline

    MariuszT

    In my opinion, MD5 is a good solution. It's 32 length with letters and digits and everyone knows what is MD5.

    I prepared my proposal PHP script. I have not tested it yet because it has already prepared for changes in plugin :)

    What changed:
    - $_POST arguments in array

    - prepared for MD5 (checks $_POST['md5'] and merges with current date)
    - changing too long /Command/ExecuteBukkitCommand to /ExecuteBukkitCommand (maybe this command should be configurable?)

    Of course this is your plugin and make changes to what you want :) You can use my PHP code if you want.
     

    Attached Files:

  12. Offline

    Waterflames

    Ok, new version. Download below.
    Configuration can just be copied from the old folder to the new.
    Old scripts aren't compatible anymore.

    Fixes:
    ✔Name (MinePHPTalk -> Websend)
    ✔MD5 (easier to configure)
    ✔Array (easier to use in scripts)
    ✔Command Change (/php.send -> /websend)
    ✔Permissions support ("websend")

    Not fixed yet:
    -Bug: When sending text "A'B" from PHP to server, slash is added ("A\'B").

    I haven't been able to reproduce that bug... Could you send me your script?

    Thanks for testing, and be sure to post when you find bugs!

    Missed your post there :p

    MD5 is fine, not secure enough anymore for professional use (SHA256 is better), but has good compatibility.
    I appreciate the input!
    I left out the date stuff, MD5 hash on its own is probably secure enough for this project.
    If you really want me to, I can put it back in.

    The reasoning behind the /Command/ is so I can add more commands later. Leaving it in would make it more clear for the user and the bukkit plugin.
    I can shorten it tho (Something like: /Cmd/DoBukkitCmd

    Next version will have a short command: "ws" (I forgot to put it in this version)
     

    Attached Files:

    Last edited by a moderator: May 16, 2016
  13. Offline

    MariuszT

    OK, I will prepare a new PHP script but at now I have a little problem. I am using the password "qwerty" and the hash from Java is different from hash in PHP. I tested your script.


    $_POST['pancakemix'] ? :D Maybe $_POST['authKey'] ?
     
  14. Offline

    Waterflames

    I thought I fixed that, I will look into that tomorrow. Its becoming late here.
    :p I'll change it.
     
  15. Offline

    MariuszT

    I attached my updated script. It should work with the new plugin.

    - a new way of authentication via MD5
    - return to /Command/ExecuteBukkitCommand
    - $_POST['authKey'] instead of $_POST['pacakemix']


    Try this in PHP:

    PHP:
    echo "A'B";
     

    Attached Files:

  16. Offline

    Waterflames

    The plugin and your php file work just fine with me... Are you sure both the config file and the php have exactly the same password? (PASS=somepassword != PASS= somepassword)

    Also, I am still unable to reproduce the bug as seen in the screenshots (I added echo "A'B"; to the code.)
    2011-07-16_13.05.22.png
    2011-07-16_13.05.29.png
     
  17. Offline

    MariuszT

    I change the password and plugin always sends the same hash.
     
  18. Offline

    Waterflames

    I found the problem, I left some debug code in -_-

    Zip is in attachment, authKey and short command "/ws" are also implemented.
     

    Attached Files:

  19. Offline

    MariuszT

    OK, plugin is almost perfect :p I have one, small and last problem.

    In your PHP script you used /n for new line. Everywhere new line are: \n, \r, \n\r or \r\n. If I'll use \n everything works fine except line with /Command/ExecuteBukkitCommand:. It's just displayed.
     
  20. Offline

    Waterflames

    You meant something like this right?
    PHP:
    echo '/Command/ExecuteBukkitCommand:time day/n';
    If that is what you meant, you don't need a /n there because there wont be output
    (except for bukkit output, which already includes newLine characters.)
     
  21. Offline

    MariuszT

    If there is no /n on the end of line with /Command/ExecuteBukkitCommand: this line connects to the next one.
     
  22. Offline

    Waterflames

    True, missed that. Still, even when I add /n I don't have any problems. Could you post the line of code?
     
  23. Offline

    MariuszT

    I don't know why but I don't have this problem any more :) Sorry.

    Me too :) But when I try to use \n then I've got normal line, without effect in game.
     
  24. Offline

    Waterflames

    You mean you would like to be able to use \n for a new line instead/as well as /n?
     
  25. Offline

    MariuszT

    Yes, every programming language uses the \n, \r, \r\n and \n\r. Also Java. Where it came from this /n ? :p
     
  26. Offline

    Waterflames

    I dunno, mixed up things I guess. :D
    I'll change it.

    EDIT: added new .jar
     

    Attached Files:

  27. Offline

    MariuszT

    Unfortunately, at now none of these lines works:

    PHP:
    echo "/Command/ExecuteBukkitCommand:weather sun";

    echo 
    "/Command/ExecuteBukkitCommand:weather sun\n";

    echo 
    "/Command/ExecuteBukkitCommand:weather sun/n";

    The first two should work.
     
  28. Offline

    Waterflames

    Found the problem: \ is recognized as an escape character instead of the raw symbol.
    Fix should be done soon.

    It was a little bit harder than I originally thought, but I found out how to fix it.
    Jar is in attachment.
     

    Attached Files:

    Last edited by a moderator: May 16, 2016
  29. Offline

    MariuszT

    Doesn't work :( With what you have exactly the problem?

    I was thinking about it. Only one line should work:

    PHP:
    echo "/Command/ExecuteBukkitCommand:weather sun\n";
    We must put \n on the end of line because without it Java receive a long line, connected with another line, without any break, space etc.

    I can prepare a regexp that will pull out any command from the text.

    EDIT:
    My example in PHP:

    PHP:
    <pre>

    <?php

    echo $text "/Command/ExecuteBukkitCommand:AAA\r\nTEST\n/Command/ExecuteBukkitCommand:BBB\rTEST/Command/ExecuteBukkitCommand:CCC\n\r/Command/ExecuteBukkitCommand:";
    echo 
    "\n\n\n";

    $lines preg_split('/[\n|\r]/'$text);

    foreach (
    $lines AS $line) {

      if (
    trim($line) != '') {
        
    preg_match('@^(/Command/ExecuteBukkitCommand):(.+)$@si'$line$out);

        
    print_r($out);
      }
    }

    ?>

    </pre>
     
  30. Offline

    Waterflames

    I have a regex that, in theory, should work perfectly. However, since the \ sign has a double function (it is also an escape character for things like \t) things get a little more complicated.

    To prevent java from interpretating \ as an escape char, I need to type \\.
    This works for the if(line.contains()) line, but for the line.split() I used \\\\. That worked for my script, so I posted it here...
     

Share This Page