PDA

View Full Version : Scripting in SKINS : PHP, Perl etc.



DirectAdmin Support
12-30-2003, 12:09 PM
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:


<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
12-30-2003, 10:04 PM
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
01-02-2004, 11:10 AM
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
01-02-2004, 11:33 AM
Use


|$/usr/bin/php



Instead of


|$/usr/local/bin/php


Chris

Zachary
01-02-2004, 11:40 AM
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
01-02-2004, 12:04 PM
Does /usr/bin/php or /usr/bin/local/php exist?

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

Chris

loopforever
01-02-2004, 12:53 PM
Lets just make this simple. Type:

whereis php

And use the binary path that comes up ;).

CyberAlien
01-02-2004, 05:07 PM
Thanks! That's great present to me and other designers for new year!

Zachary
01-02-2004, 06:13 PM
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
01-03-2004, 02:26 AM
Update> /usr/bin/perl doesn't work as well.

Is it a bug or something?

CyberAlien
01-03-2004, 04:52 AM
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?

l0rdphi1
01-03-2004, 05:53 AM
chdir("/usr/local/directadmin/data/skins/{name}");
?

CyberAlien
01-03-2004, 05:57 AM
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).

l0rdphi1
01-03-2004, 06:01 AM
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
01-03-2004, 06:06 AM
Originally posted by l0rdphi1
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
01-03-2004, 01:02 PM
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:
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
01-03-2004, 01:12 PM
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
01-14-2004, 10:56 AM
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

CyberAlien
01-14-2004, 11:05 AM
Thanks a lot!

That list has everything i need and even more :)

warpsmith
01-16-2004, 05:12 PM
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?

ProWebUK
01-16-2004, 06:34 PM
Faily sure you cant use FTP.

Chris

DirectAdmin Support
01-17-2004, 01:07 PM
Hello,

The only way to set that up (a bit weary about doing it) is to add the username to the /etc/proftpd.passwd file.

1) find the UID and GID #'s for "diradmin"
id diradmin

2) run this:

echo "directadminskins:cryptedpass:UID:GID:comments:/usr/local/directadmin/data/skins:/bin/false" >> /etc/proftpd.passwd

replace UID and GID with the numbers found in step 1.
replace crytpedpass with a password of your chosing:

[server]# php
<?
echo crypt("password","randomcharacters")."\n";
?>
press ctrl-D twice to finish. The generated text will be the crypted password.

Then just login as directadminskins to the server IP with "password" and you should be sitting in the skins directory.

John

warpsmith
01-17-2004, 01:22 PM
Thank you for the detailed reply.

Based on the caveats, I will continue to work on trying to get embedded PHP to work in an admin template, rather than a server template. So far, having no luck with either type of template, but still trying...

DirectAdmin Support
01-17-2004, 02:16 PM
Hello,

What exactly are you trying to do with the scripts? The skin scripts won't have the required privilege to upload a skin to be server wide because the scripts are run as the logged in user, not diradmin.

John

warpsmith
01-17-2004, 08:24 PM
Thanks for the follow-up.

I am trying to get PHP to work embedded within a skin.

Earlier posts in this thread seemed to imply that the process has a better chance of working as a server template. So I tried that and got the familiar 'file not found' that others are getting, even as a server template. Then I realized that developing and maintaining a server template is a bit more difficult (for good reason, given the extra security built in).

So now I am trying to get the embedded PHP to work within an admin-owned template. Even tried putting PHP under the admin directory, but still hitting problems. Will keep trying - having PHP with a DA skin opens up a lot of uses for DA for us.

CyberAlien
01-18-2004, 02:46 AM
Weird. PHP doesn't work when skin is uploaded server-wide, but works fine if skin is uploaded to admin account in skins directory. Any solutions?

DirectAdmin Support
01-18-2004, 12:26 PM
Hello,

There isn't any difference for the DA program other than the document root path.. it's probably something else like a permissions issue.. Try breaking it down to a very simple php command "echo 'hi';" or something and work up from there.

John

loopforever
01-18-2004, 12:29 PM
It appears I'm having this problem also, but only on the File Manager and Password Protected Directories pages. Check it out:

http://jonny.ath.cx:8082/~jonny/ppd.jpg

CyberAlien
01-18-2004, 12:40 PM
Even more weird: same skin uploaded to same directory using same account (admin). First time was uploaded using wget using account admin and unpacked on server. Second time it was unpacked on computer and uploaded using ftp. Only when uploaded with ftp php can be used. When uploaded with wget it shows same error as on loopforever's screenshot.

DirectAdmin Support
01-18-2004, 01:17 PM
Hello,

Right now the scripting won't work in the filemanager because it's chrooted. Other things like the password protected directories are also chrooted to /home/username, so when you're accessing php, it would be looking in:

/home/username/usr/local/bin/php

Not too sure how to get around that.

John

CyberAlien
01-18-2004, 01:25 PM
Yes, but php doesn't work even in other scripts, not only filemanager. It doesn't work even on index page, unless i'm uploading with ftp to my home directory.

DirectAdmin Support
01-19-2004, 10:56 AM
Hello,

I'm working on the filemanger issue right now. It should be working on all other pages (excluding filemanger and protected directories). If your upload method changes the functionality using the same script then either the permissions are weird or possibly the file format is non-standard (ie. windows sometimes adds ^M characters at the end of the lines).

John

CyberAlien
01-19-2004, 02:51 PM
interesting idea. i'll convert all files to unix format before compressing it and will try it. thanks.

edit: it was indeed \r\n instead of \n at the end of files that was causing problem. thanks a lot!!!