[Plugin] SA:MP Shell Plugin
#1

sampshell.dll (Win32) / sampshell.so (Debian 7 (Wheezy), CentOS, Ubuntu 14.04.1) / sampshell.inc
SA:MP Shell Plugin



About
This plugin allows you to execute shell commands on your server.



Documentation


Setup
Put the plugin binary into your server's "plugins" folder and set in server.cfg

Windows:

Код:
plugins sampshell
LINUX:
Код:
plugins sampshell.so
After that you can use the sampshell include in your scripts:
pawn Код:
// On top of your script
#include <sampshell>
// your code
Compile and run.



Downloads

sampshell.dll (Win32), sampshell.inc - Solidfiles
sampshell.so (Debian 7 (Wheezy)), sampshell.inc - Solidfiles
sampshell.so (CentOS), sampshell.inc - Solidfiles
sampshell.so (Ubuntu 14.04.1), sampshell.inc - Solidfiles
source code - Solidfiles

sampshell.inc - Pastebin
makefile - Pastebin
main.cpp - sampshell - Pastebin
sampshelltest.pwn - Pastebin



Credits
If you are interested to compile this for other LINUX distributions, just let me know by personal messaging me and leave me links to download the compiled binar(y/ies).
You'll be added into the credits, of course.

Quote:
  • BigETI for the source code and compiled binaries for Windows distributions and Ubuntu 14.04.1
  • SA:MP development team
  • Bluescreen for compiling this for Debian 7 (Wheezy)
  • Mark™ for compiling this for CentOS

Best Regards

~ BigETI
Reply
#2

A similar plugin has already been done here which I use to automatically start my local MySQL server when starting the SA-MP server.

This does seem to offer additional features however such as tracking of results and messages - good job.
Reply
#3

Quote:
Originally Posted by Jay_
Посмотреть сообщение
A similar plugin has already been done here
I told him it's not needed as it already exists but the Get-The-Output feature then made it worth it.
Reply
#4

The receive message callback, detects/receives (dunno what is more right) only the text which the user typed in or it also gives the text which running programs/installations are outputting ?
Reply
#5

Quote:
Originally Posted by xkirill
Посмотреть сообщение
The receive message callback, detects/receives (dunno what is more right) only the text which the user typed in or it also gives the text which running programs/installations are outputting ?
It only retrieves the messages the shell sends back, that means for example if you run application a, and it causes some output, you'll retrieve the output through this callback.
Reply
#6

Interesting, I am sure this could probably be exploited on some hosts that only provide web access control of the SAMP server.
Reply
#7

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Interesting, I am sure this could probably be exploited on some hosts that only provide web access control of the SAMP server.
^
I like the way it is coded thought, the construct that is used to control the interpreter parses and interprets is pretty interesting. I'll be experimenting with this, good job.
Reply
#8

Can you explain what a shell ID actually is, and how it can be used? For instance how can I check if a program actually launched correctly? I tried doing this:
pawn Код:
if(cmdresult != 0)
how-ever it returns a shell ID so I can't really use this method. And how would I go about launching something from the root server directory? Documentation on these things would be helpful.

I've noticed that the shell ID seems to increase by 16 steadily. Is there any reasoning for this?
Reply
#9

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Can you explain what a shell ID actually is, and how it can be used? For instance how can I check if a program actually launched correctly? I tried doing this:
pawn Код:
if(cmdresult != 0)
how-ever it returns a shell ID so I can't really use this method. And how would I go about launching something from the root server directory? Documentation on these things would be helpful.

I've noticed that the shell ID seems to increase by 16 steadily. Is there any reasoning for this?
The command is executed in other thread, so the id is for identify the executed command. Example:

This script prints your current gamemode:
pawn Код:
new Shell:dirlist, Shell:serverinfo, Shell:gminfo;

public OnFilterScriptInit() {
    dirlist = SHELL_Execute("dir"); // dump directory files and folders
}

public OnRecieveShellMessage(Shell:id, msg[])
{
    if (id == dirlist) {
        if (strfind(msg, "server.cfg") != -1) {
            printf("server.cfg found. Dumping server info...");
            serverinfo = SHELL_Execute("more server.cfg");
        }
        print(msg);
    } else if (id == serverinfo) {
        new
            linepos;
        if ((linepos = strfind(msg, "gamemode0")) != -1) {
           
            new
                gamemode_filename[40],
                count;
               
            // find for gamemode0 script!
            for (new i = linepos+strlen("gamemode0 "); i <  strlen(msg); i++) {
               
                if (msg[i] == '\n' || msg[i] == ' ') { // gamemode text end
                    break;
                }
                gamemode_filename[count++] = msg[i]; // Copy message gamemode chars.
            }
           
            // Add file extension
            strcat(gamemode_filename, ".pwn");
            printf("Your gamemode is: '%s'. ", gamemode_filename);
           
            format(gamemode_filename, 40, "more gamemodes\\%s", gamemode_filename); // Shell command for dump file data: "more filename"
            printf("shell command: %s", gamemode_filename);
            gminfo = SHELL_Execute(gamemode_filename);
        }
    } else if (id == gminfo) {
       
        // Print gamemode
        printf(msg);
    }
   
}
Using "more" command, you can read files in other thread from pawn, without affecting server performance.
Reply
#10

Updated files, see main post.
Reply
#11

Quote:
Originally Posted by ******
Посмотреть сообщение
A few things:

1) OnRecieveShellMessage

Receive*
:o
Fixed!


Quote:
Originally Posted by ******
Посмотреть сообщение
2) That callback should probably differentiate between stdout and stderr for incoming messages.
Actually it gets the output of stdout, so I would rather redirect stderr to stdout, or dump stderr's output into a file via command.


Quote:
Originally Posted by ******
Посмотреть сообщение
3) An execute function that doesn't reaturn a handle may also be useful. At the moment if you don't care about it, you have to discard the result manually. Or just this:

pawn Код:
#define SHELL_Fire(%0) SHELL_Release(SHELL_Execute((%0)))
I've added
pawn Код:
SHELL::System(const cmd[])
for this.

Thank you very much.
Reply
#12

Good job ETI!

OFF: What happend to Operantion San Fierro - Zombies?
Reply
#13

Good job.

CentOS - http://www.solidfiles.com/d/f094facd0f/sampshell.so

Ubuntu - http://www.solidfiles.com/d/fdf4801a74/sampshell.so
Reply
#14

Got issue with this code:
Код:
public OnRconCommand(cmd[])
{
    if(cmd[0]=='s' && cmd[1]=='h' && cmd[2]=='e' && cmd[3]=='l' && cmd[4]=='l')
    {
        strdel(cmd, 0, 6);
        //SHELL_System(cmd);
        thisshell = SHELL_Execute(cmd);
    }
    return 1;
}

public OnReceiveShellMessage(Shell:handle, msg[])
{
    if(handle == thisshell)
    {
        print(msg);
    }
}
Log:
Код:
Console input: shell dir
[14:31:13] dir
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13]  Wolumin w stacji F to GOODRAM

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13]  Numer seryjny woluminu: 9EF5-FBB4

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13]  Katalog: F:\sampsvr\zombie

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  14:18    <DIR>          .

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  14:18    <DIR>          ..

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-01-16  16:41            40˙960 announce.exe

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2013-11-23  17:21               404 audio.ini

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  11:00    <DIR>          audiopacks

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2013-08-28  14:14               282 Ceny punkt˘w.txt

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2013-10-04  18:56                61 connect.txt

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  14:29           503˙323 crashinfo.txt

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-24  21:59        11˙091˙722 Debug.txt

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  13:49    <DIR>          filterscripts

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  11:01    <DIR>          gamemodes

[14:31:13] [sampgdk] error: Too many callback arguments (at most 32 allowed)
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  11:01    <DIR>          include

[14:31:13] [sampgdk] error: Too many callback arguments (at most 32 allowed)
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2013-08-07  12:28           270˙336 libcurl.dll

[14:31:13] [sampgdk] error: Too many callback arguments (at most 32 allowed)
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2012-09-13  12:50         1˙519˙616 libmysql.dll

[14:31:13] [sampgdk] error: Too many callback arguments (at most 32 allowed)
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  11:01    <DIR>          linux

[14:31:13] [sampgdk] error: Too many callback arguments (at most 32 allowed)
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2013-09-30  14:55             7˙729 logo.png

[14:31:13] [sampgdk] error: Too many callback arguments (at most 32 allowed)
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------
Reply
#15

Quote:
Originally Posted by KubiPL
Посмотреть сообщение
Got issue with this code:
Код:
public OnRconCommand(cmd[])
{
    if(cmd[0]=='s' && cmd[1]=='h' && cmd[2]=='e' && cmd[3]=='l' && cmd[4]=='l')
    {
        strdel(cmd, 0, 6);
        //SHELL_System(cmd);
        thisshell = SHELL_Execute(cmd);
    }
    return 1;
}

public OnReceiveShellMessage(Shell:handle, msg[])
{
    if(handle == thisshell)
    {
        print(msg);
    }
}
Log:
Код:
Console input: shell dir
[14:31:13] dir
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13]  Wolumin w stacji F to GOODRAM

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13]  Numer seryjny woluminu: 9EF5-FBB4

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13]  Katalog: F:\sampsvr\zombie

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  14:18    <DIR>          .

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  14:18    <DIR>          ..

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-01-16  16:41            40˙960 announce.exe

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2013-11-23  17:21               404 audio.ini

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  11:00    <DIR>          audiopacks

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2013-08-28  14:14               282 Ceny punkt˘w.txt

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2013-10-04  18:56                61 connect.txt

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  14:29           503˙323 crashinfo.txt

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-24  21:59        11˙091˙722 Debug.txt

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  13:49    <DIR>          filterscripts

[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  11:01    <DIR>          gamemodes

[14:31:13] [sampgdk] error: Too many callback arguments (at most 32 allowed)
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  11:01    <DIR>          include

[14:31:13] [sampgdk] error: Too many callback arguments (at most 32 allowed)
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2013-08-07  12:28           270˙336 libcurl.dll

[14:31:13] [sampgdk] error: Too many callback arguments (at most 32 allowed)
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2012-09-13  12:50         1˙519˙616 libmysql.dll

[14:31:13] [sampgdk] error: Too many callback arguments (at most 32 allowed)
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2014-11-25  11:01    <DIR>          linux

[14:31:13] [sampgdk] error: Too many callback arguments (at most 32 allowed)
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------

[14:31:13] 2013-09-30  14:55             7˙729 logo.png

[14:31:13] [sampgdk] error: Too many callback arguments (at most 32 allowed)
[14:31:13] 
---------------------------------------
[14:31:13] Running Grand Larceny

[14:31:13] ---------------------------------------
I would like to know, what plugins you are using for this.
Reply
#16

sscanf 2.8.1, streamer v 2.7.4 by Incognito and MySQL R5.
Reply
#17

Looks like, that if there is no OnReceiveShellMessage() in the gamemode, it will call main(). This has been now fixed.
Thank you very much!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)