Writing a plugin
How do I create a plugin?
The documentation for our plugin system can be found here.
To start, we recommend you install our hello_world.tar.gz sample, and see how it works, and go from there.
Plugins are quite simple, they're basically just a list of files, extracted to a directory, some of which are scripts to execute code you want. Included in the files are also "hooks", data that is inserted into the DA skins allowing you to add links to your plugin from DA itself.
Another example.
Other related features with the plugins: Ability to completely control the socket , which lets you send files. It allows you to remove the DirectAdmin html "bubble" (header and footer) and also gives you control of the headers. Without this option, your output is inserted into the middle of the DA window.
More related items can be found in the versions system.
How to call php with your php.ini
If you're running a plugin, and you need to use your own php.ini file, then use the following shebang line with your php.ini file's location:
#!/usr/local/bin/php -nc /usr/local/directadmin/plugins/NAME/yourphp.ini
It's important that you use the -n option, especially with CustomBuild 2.0, or else you may have modules loaded twice due the hard-coded nature of the with-config-file-scan-dir, which could load extra ini files, resulting in the loading of modules twice (like zend/ioncube), which would cause errors.
You'll also notice that all php command line options and values are added as one shebang option. Shebang only supports 1 extra option after the interpreter, so they must all be put together into 1 option. (Limitation of the shebang line design).
If you want to run php and not use any php.ini (internal defaults), then use:
#!/usr/local/bin/php -n
to force your php instance to ignore all php.ini settings you may have set in your global php.ini.
Debugging
It's been noted that if you've saved your files in "dos" mode, the shebang line (#!/usr/..) can often have issues with options after the space, like the -nc/usr.. flag. Ensure you save your files is unix format. To do this, you can use the dos2unix command, install dos2unix if it's missing:
yum install dos2unix
dos2unix index.html
How to use $_GET and $_POST in a plugin
The DirectAdmin plugin system can use php, however the php used is /usr/local/bin/php, and not the same php used by Apache. The differences are that many of the default/loaded variables made available to php coders are not there by default with the command line version.
This is a basic php code to convert the environment variables that DA does pass, into the $_GET and $_POST arrays that you're used to working with through Apache:
//make code look like CLI for $_GET and $_POST
$_GET = Array();
$QUERY_STRING=getenv('QUERY_STRING');
if ($QUERY_STRING != "")
{
parse_str(html_entity_decode($QUERY_STRING), $get_array);
foreach ($get_array as $key => $value)
{
$_GET[urldecode($key)] = urldecode($value);
}
}
$_POST = Array();
$POST_STRING=getenv('POST');
if ($POST_STRING != "")
{
parse_str(html_entity_decode($POST_STRING), $post_array);
foreach ($post_array as $key => $value)
{
$_POST[urldecode($key)] = urldecode($value);
}
}
Optional template: plugin_iframe.html
Not present by default, but this is used with the following plugin feature:
iframe=yes
which current hard-codes the iframe html output around the |OUTPUT| token.
This new optional template, if created, would be used in place of the hardcoded html. Main purpose is to make debugging easier and should not be needed for most cases.
/usr/local/directadmin/data/templates/custom/plugin_iframe.html
Sample:
<html><head><base target="_parent" />
<meta charset="utf-8" />
</head><body><div id="iframe-container">
|OUTPUT|
</div></body></html>