Posts: 1,046
Threads: 29
Joined: Mar 2010
22.11.2014, 20:18
(
Последний раз редактировалось BigETI; 24.04.2015 в 06:46.
)
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:
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
Posts: 3,004
Threads: 12
Joined: May 2011
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 ?
Posts: 1,046
Threads: 29
Joined: Mar 2010
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.
Posts: 4,885
Threads: 57
Joined: Jun 2012
Reputation:
0
Interesting, I am sure this could probably be exploited on some hosts that only provide web access control of the SAMP server.
Posts: 263
Threads: 11
Joined: Nov 2014
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.
Posts: 263
Threads: 6
Joined: Mar 2012
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:
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.
Posts: 1,046
Threads: 29
Joined: Mar 2010
Updated files, see main post.
Posts: 1,046
Threads: 29
Joined: Mar 2010
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.
Posts: 91
Threads: 8
Joined: Aug 2014
Good job ETI!
OFF: What happend to Operantion San Fierro - Zombies?
Posts: 1,046
Threads: 29
Joined: Mar 2010
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.
Posts: 159
Threads: 35
Joined: Feb 2012
Reputation:
0
sscanf 2.8.1, streamer v 2.7.4 by Incognito and MySQL R5.
Posts: 1,046
Threads: 29
Joined: Mar 2010
Looks like, that if there is no OnReceiveShellMessage() in the gamemode, it will call main(). This has been now fixed.
Thank you very much!