Allowing users to execute premade scripts through DA?

chibi

Verified User
Joined
Apr 26, 2005
Messages
18
Location
Canada
Hello. I am thinking this thread is supposed to go here.. if this is the wrong spot I apologise.

I just bought a server 2 days ago with Direct Admin as the control panel. I can get around in linux fairly well, I just dont know the ins and outs of the OS.

I am going to host some game servers for a community I am involved in, but I do not want to give any of them shell/ssh access to the box.

What I want to do, is from within Direct Admin have a button or link or something that they can just click on and it will exectute a .sh file located on the box within their user reach (assuming the .sh file was setup with correct permissions).

Just simple start and stop scripts for their gameservers. (I dont need help writing them I already have them working).
For example:

#!/bin/sh
./server start
echo Your 32 Slot Private Server Has Been Started

I for the life of me cannot find an area in DA for this, but thats probably because it is a cronjob - something foreign that I do not understand.

I would very much so appreciate some help in this matter. It really does mean alot to me and the people I am helping out. The game we play isnt very popular so Im the only one promising to bring some good hosting.

Where can I go to set these up for each user?

Thank you for your any help :)

-Jeff
 
You make it sound so easy x_x. Did you read those instructions at all? I did and followed.. this is what I got..

/usr/local/directadmin/plugins/sg_start/

inside this folder I have my plugin.conf file:

name=Server Start
id=sg_start
author=Chibi
version=1.0
update_url=
active=yes
installed=yes

and then these directories:

admin
images
reseller
user

Inside the user folder, I stuck my start.sh file. I changed all the permissions of all the files/folders I made so that u:g is diradmin:diradmin.

I login as a regular user (no admin) in DA, and I dont see any new options. So now I am stuck... what do I do next?

If I login as an admin and check out the plugins area, it does say I have my plugin installed.

The rest of the instructions where it says:

There are no file_user.conf files like in the skins. The plugins system will allow files to be accessed directly, eg:

domain.com:2222/CMD_PLUGINS/plug_name/index.html

SKINS:
admin/content_main.html:
|PLUGIN_0_ADMIN_TXT|
|PLUGIN_1_ADMIN_TXT|
|PLUGIN_2_ADMIN_TXT|
|PLUGIN_3_ADMIN_TXT|
OR for image based skins with icons:
|PLUGIN_0_ADMIN_IMG|
|PLUGIN_1_ADMIN_IMG|
|PLUGIN_2_ADMIN_IMG|
|PLUGIN_3_ADMIN_IMG|

...is completely foreign to me I have no idea what it means or what I am supposed to do with that. Should I be making an index.html file, where does it go what should it contain where will the user see it? Aaaaaaah my head xD.

Thanks :)

-Jeff
 
Last edited:
You also need a directory named "hooks" which is where DirectAdmin determines the link to show on the corresponding page.

Valid file names are:
user_txt.html
user_img.html
reseller_txt.html
reseller_img.html
admin_txt.html
admin_img.html

Where any *_img.html file is for the original theme that DirectAdmin used about a year ago which accepted images and any *_txt.html for most, if not all current skins.

Each file corresponds to the access level the link will show on, replacing the bold with your plugin information

Here's an example of what the user_txt.html file would contain
Code:
<a href='/CMD_PLUGINS/[b]plugin_id[/b]/index.html'>[b]Link Name[/b]</a>"
 
Thank you for your continued help. I am going to take a look. I am still not completely clear but maybe once I download the example and take a look it will make more sense.

I'll post if I have any problems. I think this is the last issue I have. Everything else has been rectified.

-Chibi
 
Okay I think I understand how it works, and I am going to try to work on one myself and see if it gives me the results I think I will get...

BUT.. I have to wonder at this point.. how will I make them dynamic per user?

Ohh how to explain... Okay say I have 2 users. named bob and tom. bob has 3 gameservers while tom has one. (servers are all the same kind)

/home/bob/gameservers/serv1/serverexec
/home/bob/gameservers/serv2/serverexec
/home/bob/gameservers/serv3/serverexec

I need bob to be able to login to DA, and have his plugin menu. And be presented with start/stop scripts for all 3 of his servers:

--------------
menu
--------------
start server 1
start server 2
start server 3
--
stop server 1
stop server 2
stop server 3

But then there is Tom. When Tom logs into his control panel, it is imperative that he doesnt have the access to Bob's scripts; while still being able to use his own.

I am going to have to create a plugin for each server a user has.
Or, unless there is a way to use one main plugin that is accessible to all the users (who all have the same kind of server).. but detects what user they are and uses assigned variables or something to change the paths. Oh that sounds complicated we might wanna stick to the first idea..

So I guess the real question is, am I able to enable/disable certain plugins for certain users? I cant have them able to start and stop eachothers servers. Thats not very nice.

I think if my php skills were more adept I would be able to figure this out more.

all I keep thinking is "how is it gonna know whos who". Just seems like alot of work to run a file x_x.

You've been very good about helping with this. Any clarity to add?

-Jeff
 
Last edited:
It would be pretty easy in php actually since the plugin scripts are executed with the same permissons as the person logged in to DirectAdmin.
Would would get the username and store it to a variable.
PHP:
$username = $_SERVER['USER'];

Then you might do a glob in that users home directory for a list of servers.
Something like
PHP:
$path = "/home/" . $username . "/gameservers/*";
foreach (glob($path) as $x)
{
	$gameservers[] .= $x;
}
Then you would simply use the $gameservers array to output a list of links. Upon clicking one of them, the php script would execute your shell script (or better yet another php script) passing the arguments.
Then you would rewrite your shell or php script to use the provided argument instead of a set value.

This will save you from having to create a seperate plugin for each user or having to implement a complicated per-user access system.
 
Last edited:
Haha. You are too smart for me. This is going to be fun.

I think what I will aim to do, is make one plugin called 'Game Manager' which appears in the list.

And then once they click on that, inside the -new- area, this is where I will put all their options.

It will detect what user, then scan what gameservers they have installed (as you so kindly suggested).

There are 2 gameserver types, and also voice communication software that could be installed, so this could get interesting.

And then it will display a heading for each gameserver/software type, and the available options to them.

Oh man this has made me excited.. isnt that freaky :P I just hope it is possible. But I am going to get started on the core right away, and then I guess find a php tutorial :)

I will go as far as I can and show you what I got. Thanks!

-Jeff
 
This is what I've got so far. I need to hit the sack its 5am. My php is very bad, but I did get it to give me some decent output to start. Your sample code was very helpful.

PHP:
#!/usr/local/bin/php
<?php
$username = $_SERVER['USER'];
$amount = 0;
$x = 0;

$path = "/home/" . $username . "/gameservers/*";
foreach (glob($path) as $x)
{
	$amount++;
	$gameservers[] .= $x;
}

echo "<b>SERVERS MANAGEMENT</b>";
echo "<br><br>";
echo "Managing Servers For: $username";
echo "<br><br><br>";
echo "<b>Your Game Servers:</b>";
echo "<br><br>";

for ($i=0; $i!=$amount; $i++)
{
	echo "$gameservers[$i] <br>";
}

?>
It doesnt really do anything yet, but wow that is a start. I am feeling alot better about this now :) I made a gameservers/ folder and stuck in three other dirs, and it worked and outputted just fine. I am gonna have to figure out how to get it to only display the folder names and not the entire paths.

I think I might make the foldernames help people keep track of their settings. like 12slot_pri/ and 20slot_pub/ etc. And then use the folder names as the link titles they click on to execute the script.

Youre my hero :P g'night!

-Jeff
 
I am gonna have to figure out how to get it to only display the folder names and not the entire paths.

If you change directories into the path and then run the glob on "*" there won't be the path, or you could use something like preg_replace to replace the path with "" before storing it to a variable.
 
I am completely revamping it. It feels so cool doing things like this. S'why I love linux so much.

When I get more of the new method done I will paste it too. I am sure there could be other people who would benefit from it. Because what I am trying to do is already offered by other control panels. Before I hosted things myself I would get it from other people, and they would just stick some buttons in the cp for me that lead to shell scrips :P

While I am doing this, I have a question for you too if you dont mind. (if its not your field its quite alright). But cronjobs, what is that for and what does it do? I know its some kind of process manager.
I was thinking of maybe writing a script that would check server configuration settings for values that users are not permitted to use but are using anyways becuase they think they are sneaky and then alert me that it has been done.
OR write a script that writes to a configuration file to keep certain values static. If the user changes them, they would revert back after the script is run. Does cronjobs help me with this? Can I tell it to execute a script every hour or something to that affect? Do tell I am very interested. I love knowledge :P

I might be off to sleep soon. I like working at night it feels so peaceful, but my body is demanding of rest :)

Take care

ADDED TODAY:
I am stuck again on something php related. Most of it is related to direct admin so I will say all. (you seem very knowledgeable anyways)

I need php to find me 3 things about their DA account:

1. the user's default domain (im only giving them one)
2. the ip assigned to their domain name.
3. the ip of the user who is logged into DA

Some of these might be general php commands, others may need to look in a special location related to DA.. I am not sure.

My script plugin code is coming along nicely. I feel so accomplished. For the most part I just have to organize it/put it all together correctly. Few loops n things to write.

Thanks a bunch for everything youve done for me, you dont need to feel obligated to continue because I know I keep dragging this on until I finish :P
 
Last edited:
What you described above is exactly what cronjobs are for, "allow you to execute scheduled commands on your website", such as scripts.

Regarding the 3 things you need to find you can use DirectAdmin's API.
I think the "CMD_API_SHOW_USER_CONFIG" command will get what you want.

A list of all API commands can be found here: http://directadmin.com/api.html#user_apis

And here is a php class that you can use to communicate with the API, provided by l0rdphi1:
http://www.directadmin.com/forum/showthread.php?threadid=258
 
Hi again.

Sorry I havent responded in a long time. I have been coding my plugin nonstop. I gave myself a deadline of May 1st. It is getting really close. I had a really vicious array issue thing that finally got fixed.

I've got all the server detection downpat, as well as all the configuration output.

All I am missing is getting their domain name. And then theres the part to start/stop the server... which is turning out to be way harder than I thought. It is a nightmare actually.

I dont know if I should be writing the scripts as .php or .sh.. but I dont know if php can grep ps aux and stuff like that to determine if the server is already running n things..

So what I thought to start would be to get php to open the .sh files (using the shell_exec() command).. but in order to do that the user first has to click on a link from within the original generated page of the plugin, and then the shell_exec script to execute the .sh file is housed in the new window that opens up. But after the new window executes the .sh file I am not sure how to send output back to the window... I havent even been able to test this yet because...

...my problem is, when the user clicks on the link...it cant find the new page that houses shell_exec in it..

I guess this pretty much means I have no idea what im doing x_x. It sends them to http:// 100.100.100.100:2222/home/testuser/correct/location/start.php but 'file not found' and start.php has ugo=rwx too to make sure..
(I put a space to stop it from turning into a link on this post)

I am starting to feel guilty asking for help all the time. Its like I cant do anything on my own. (Which is probably true).

I very much so like the:
$_SERVER['SERVER_ADDR']; commands and the like :P There isnt one for dmain names..

So I thought I would take a break from that for a moment and try this.. API thing.

I think this is like some kinda downward spiral :P So I took a look at that thing lordphil made. Of course, it makes no sense to me whatsoever. The examples dont really shed light. There needs to be instructions or something.. But I feel even more dumb because I am reading the post and everyone just... gets it. They understand what to do and how it works and I am sitting there going "aaaaahhhhh".

Example:

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('yoursite.com',2222);
$sock->set_login('admin','{admin_password}');

My php code is a plugin page, I am already logged into DA.. do I still need to resend the login information? And since this is for a plugin.. theres going to be more than one user accessing this code.. so the login information cant even be static..I want to use this code to find the donaim name but I have to enter the donaim name in the first place so whats the point x_x. I just know I am not explaining this very well.

Am I even making sense? Sometimes I wonder..

I just want to get the user's default domain :( And I dunno what to do and im so tired and sad and frustrated. I've gone from hyper to depressed and now I am scaring you with my whining and aahh I've only had 5 hours of sleep everynight for awhile....this has become an obsession.

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->query('/CMD_API_SHOW_USER_CONFIG,
array(
'domain' => 'domain'
));
$result = $sock->fetch_body();

echo $result;

Is this right? maybe I should test it.. I guess I shouldnt expect you to know everything :\ I better settle down before I come off as rude or something. I should post about it in the forum for scripting...

I am going to go try this now, but I am not really confident on the success..

Btw sorry for my rambling cry for help :|
 
Last edited:
Well, I finally fixed it. In order to get it to do anything, I had to refresh the current page (rather than opening a new one) but give the page some arguments and then feed it into an if/switch cluster to determine the output.

There is still alot of work to be done but at least it is workable now. When I finish it I may very well post it here as an example. It might help someone :)

Thank you to everyone who contributed.
 
Back
Top