theos
26th January 2010, 20:43
Hi all,
I've created a little plugin that creates a htpassword-file containing all passwords of the clients that are created in ispconfig3.
I usually use this file to secure webapps like phpmyadmin.
Maybe it is useful for others. This is my first ispconfig3-plugin. Comments are welcome :)
Copy this file to /usr/local/ispconfig/server/plugins-available/adminpassword_plugin.inc.php
Then create a symlink in /usr/local/ispconfig/server/plugins-available
and create the entry $conf['services']['adminpassword'] = true; in /usr/local/ispconfig/lib/config.inc.php
<?php
// this plugin automatically creates /var/www/.htpasswd_admin
// TL Snelleman
// borrowed some code from: http://www.howtoforge.com/forums/showthread.php?t=33026
class adminpassword_plugin {
var $plugin_name = 'adminpassword_plugin';
var $class_name = 'adminpassword_plugin';
//* This function is called during ispconfig installation to determine
// if a symlink shall be created for this plugin.
function onInstall() {
global $conf;
if(@$conf['services']['adminpassword'] == true) {
return true;
} else {
return false;
}
}
/*
This function is called when the plugin is loaded
*/
function onLoad() {
global $app;
/*
Register for the events
*/
$app->plugins->registerEvent('client_insert',$this->plugin_name,'client_insert');
$app->plugins->registerEvent('client_update',$this->plugin_name,'client_update');
$app->plugins->registerEvent('client_delete',$this->plugin_name,'client_delete');
}
function htpassword_update($event_name,$data) {
global $app, $conf;
$result = $app->db->queryAllRecords("SELECT * FROM client c");
$fp = fopen("/var/www/.htpasswd_admin","w");
if ($fp) {
foreach($result as $row)
{
$username = $row['username'];
$password = $row['password'];
if ($password != "") {
fwrite($fp,$username.":".$password."\n");
}
}
}
fclose($fp);
}
function client_insert($event_name,$data) {
global $app, $conf;
$this->htpassword_update($event_name,$data);
}
function client_update($event_name,$data) {
global $app, $conf;
$this->htpassword_update($event_name,$data);
}
function client_delete($event_name,$data) {
global $app, $conf;
$this->htpassword_update($event_name,$data);
}
} //adminpassword_plugin
?>
I've created a little plugin that creates a htpassword-file containing all passwords of the clients that are created in ispconfig3.
I usually use this file to secure webapps like phpmyadmin.
Maybe it is useful for others. This is my first ispconfig3-plugin. Comments are welcome :)
Copy this file to /usr/local/ispconfig/server/plugins-available/adminpassword_plugin.inc.php
Then create a symlink in /usr/local/ispconfig/server/plugins-available
and create the entry $conf['services']['adminpassword'] = true; in /usr/local/ispconfig/lib/config.inc.php
<?php
// this plugin automatically creates /var/www/.htpasswd_admin
// TL Snelleman
// borrowed some code from: http://www.howtoforge.com/forums/showthread.php?t=33026
class adminpassword_plugin {
var $plugin_name = 'adminpassword_plugin';
var $class_name = 'adminpassword_plugin';
//* This function is called during ispconfig installation to determine
// if a symlink shall be created for this plugin.
function onInstall() {
global $conf;
if(@$conf['services']['adminpassword'] == true) {
return true;
} else {
return false;
}
}
/*
This function is called when the plugin is loaded
*/
function onLoad() {
global $app;
/*
Register for the events
*/
$app->plugins->registerEvent('client_insert',$this->plugin_name,'client_insert');
$app->plugins->registerEvent('client_update',$this->plugin_name,'client_update');
$app->plugins->registerEvent('client_delete',$this->plugin_name,'client_delete');
}
function htpassword_update($event_name,$data) {
global $app, $conf;
$result = $app->db->queryAllRecords("SELECT * FROM client c");
$fp = fopen("/var/www/.htpasswd_admin","w");
if ($fp) {
foreach($result as $row)
{
$username = $row['username'];
$password = $row['password'];
if ($password != "") {
fwrite($fp,$username.":".$password."\n");
}
}
}
fclose($fp);
}
function client_insert($event_name,$data) {
global $app, $conf;
$this->htpassword_update($event_name,$data);
}
function client_update($event_name,$data) {
global $app, $conf;
$this->htpassword_update($event_name,$data);
}
function client_delete($event_name,$data) {
global $app, $conf;
$this->htpassword_update($event_name,$data);
}
} //adminpassword_plugin
?>