Scripting in SKINS : PHP, Perl etc.

DirectAdmin Support

Administrator
Staff member
Joined
Feb 27, 2003
Messages
9,051
Hello,

I'm proud to say that I've introduced scripting into the skins/templates. It's been tested a little bit, and is still in beta, but I feel is ready for the general community to start playing with.

Usage:
PHP:
<html>
welcome to my webpage<br>

|$/usr/local/bin/php
<?
echo "this is php code with tokens: |USERNAME|";
?>
DONE| 

</html>
You can replace /usr/local/bin/php with /usr/bin/perl if you like perl better. Your script will get 4 seconds to run before DA toasts it, but that can be increased/changed if needed. You can run multiple scripts within one page, no problems. The script will be run as the logged in user with setgid/setuid, so you can't increase to root privilege. The scripts are run as if they were run from an ssh prompt... so things like GET/POST values won't be passed via environment (can be changed).. but other things like sending header data will not work, because by the time the script is run, the DA headers will have already been sent out.

This scripting functionality can be changed if required, so stay tuned to this thread in case there are any. Scripting available as of 1.20.5, but it's BETA and not official (everyone should have it)

John
 

ProWebUK

Verified User
Joined
Jun 9, 2003
Messages
2,326
Location
UK
Good news :D

i was about to ask about the priviliges the scripts are run as in the other thread although looking at this it has been answered :)

Chris
 

Zachary

Verified User
Joined
Sep 1, 2003
Messages
19
script exits with a "cannot find file: /usr/local/bin/php" error.

I tried and was able to access /usr/local/bin/php with both diradmin and my account username using ssh.
 

ProWebUK

Verified User
Joined
Jun 9, 2003
Messages
2,326
Location
UK
Use

PHP:
|$/usr/bin/php

Instead of

PHP:
|$/usr/local/bin/php
Chris
 

Zachary

Verified User
Joined
Sep 1, 2003
Messages
19
Didn't work either:

cannot find file: /usr/bin/php


My code:

|$/usr/bin/php
<?
$var = str_ireplace(
"action=protect\">",
"action=protect\" target=\"_blank\">",
"|DIRECTORIES|"
);
echo $var;
?>
DONE|

No custom installation of apache was done. What when wrong?
 

ProWebUK

Verified User
Joined
Jun 9, 2003
Messages
2,326
Location
UK
Does /usr/bin/php or /usr/bin/local/php exist?

also i advise you to use <?php to start php instaed of <?

Chris
 

Zachary

Verified User
Joined
Sep 1, 2003
Messages
19
it still doesn't work.

whereis php
php: /usr/local/bin/php /usr/local/lib/php /usr/local/lib/php.ini

i tried but they still return the same 'cannot find file' error.

Chris: tried <?php as well
 

Zachary

Verified User
Joined
Sep 1, 2003
Messages
19
Update> /usr/bin/perl doesn't work as well.

Is it a bug or something?
 

CyberAlien

Verified User
Joined
Oct 28, 2003
Messages
229
Location
Mars
I can't find way to include other files in php code.

The problem is that current directory is set to /usr/local/directadmin instead of html file's directory, variable __FILE__ doesn't work and there is nothing in $_ENV or $argv that can help. And |HTM_SOMEFILE| (to include file with directadmin) also doesn't work inside php code.

Anyone got a solution?
 
Last edited:

CyberAlien

Verified User
Joined
Oct 28, 2003
Messages
229
Location
Mars
Will work only if skin is installed for everyone, but won't work if skin is installed by some admin or reseller. For example i don't have access to that directory on server where i test skins and i upload skins in "skins" directory in my home dir (/home/slava/skins in my case).
 
Last edited:

l0rdphi1

Verified User
Joined
Jun 22, 2003
Messages
1,471
Well, yes.. I see. I was going to say just make everyone install skins in the same directory, but now, I see that won't work.

Hmm... it's logically correct for the . directory to be the skin's dir, so I'm sure we can get John to change this for us.

So.. John.. :D
 

CyberAlien

Verified User
Joined
Oct 28, 2003
Messages
229
Location
Mars
l0rdphi1 said:
Hmm... it's logically correct for the . directory to be the skin's dir, so I'm sure we can get John to change this for us.

So.. John.. :D
Yes, that would be great.

Also it would be nice if directadmin includes like |HTM_SOMEFILE| would be processed before running script (just insert content of that file instead of variable).
 

DirectAdmin Support

Administrator
Staff member
Joined
Feb 27, 2003
Messages
9,051
Hello,

I think the best solution for the include issue would be for me to add an environmental variable (or many more as needed) to let the script know where it's running from.
ie:
PHP:
include($_ENV('DOC_ROOT')."/myfile.php");
or something like that. Let me know what you guys think/want. (or a token would work too).

As for the file not found issue, we've figured it out, and it's because the php code was in the filemanager skins, which is chrooted to /home/username. So there is no way to accsess /usr/local/lib/php from there (unless you create /home/username/usr/local/lib/php) ... so scripting might not work in the filemanager.. but any suggestions/ideas are welcome on how to get around this.

John
 

CyberAlien

Verified User
Joined
Oct 28, 2003
Messages
229
Location
Mars
I think it would be better to have token. And also tokens for GET and for POST parameters would be nice.

One more question: how can designer increase 4 seconds timeout of script?
 

DirectAdmin Support

Administrator
Staff member
Joined
Feb 27, 2003
Messages
9,051
Hello,

I've upped the timeout to 8 seconds. But one trick might be to have 2 sepearte php script calls in the same html, as each one will be limited by their own time out, (ie: 8 seconds for each). The timeout is currently hard coded.

Also, I've added a whole pile of new environmental variables, including GET and POST, and DOCUMENT_ROOT..yadda yadda :)

http://www.directadmin.com/features.php?id=285

John
 

warpsmith

Verified User
Joined
Nov 14, 2003
Messages
8
When setting up a server-wide skin, is it possible to FTP to the skins directory as the "diradmin" user? How do we find the password of this user?
 
Top