Added password change to plesk

This commit is contained in:
Deon George 2012-07-12 21:18:22 +10:00
parent 8100fa2540
commit 25c73e2819
6 changed files with 102 additions and 3 deletions

View File

@ -0,0 +1,36 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for providing password from a password genarator
*
* @package lnApp
* @subpackage PWGen
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_PWgen {
public static function get($pwonly=TRUE) {
if (! Kohana::Config('pwgen.host') OR ! Kohana::Config('pwgen.port'))
throw new Kohana_Exception('No configuration for host or port (:host/:port)',array(':host'=>Kohana::Config('pwgen.host'),':port'=>Kohana::Config('pwgen.port')));
$ps = socket_create(AF_INET,SOCK_STREAM,0);
if (! socket_connect($ps,Kohana::Config('pwgen.host'),Kohana::Config('pwgen.port')))
throw new Kohana_Exception('Unable to connect to password server');
// echo "Reading response:\n\n";
$pw = '';
while ($out = socket_read($ps,64))
$pw .= rtrim($out);
// echo "Closing socket...";
socket_close ($ps);
list($passwd,$passwdSay) = explode(' ',$pw);
// print " Password [$passwd] ($passwdSay) [$pw] ".md5($passwd)."<BR>";
return $pwonly ? $passwd : array('pw'=>$passwd,'say'=>$passwdSay);
}
}
?>

View File

@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class PWGen extends lnApp_PWGen {}
?>

View File

@ -0,0 +1,18 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB Configuration - PWGen Configuration
*
* @package OSB
* @subpackage PWGen
* @category PWGen
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
return array(
'host' => '127.0.0.1',
'port' => '129',
);
?>

View File

@ -25,6 +25,7 @@ class Controller_Task_Host extends Controller_Task {
case 'gettraffic':
case 'migrate':
case 'provision':
case 'resetpw':
$this->so = ORM::factory('service',$this->request->param('id'));
if (! $this->so->loaded())
@ -252,5 +253,17 @@ class Controller_Task_Host extends Controller_Task {
$result = $this->hpo->provision($this->so);
print_r((string)$result);
}
public function action_resetpw() {
$pw = PWGen::get(TRUE);
$spho = $this->so->plugin();
$spho->host_password = $pw;
if (! ($result = $this->hpo->setpasswd($this->so,$pw)) OR ! $result->loaded() OR ! $spho->save())
throw new Kohana_Exception('Unable to set password.');
echo _('Password Reset Success');
}
}
?>

View File

@ -47,7 +47,7 @@ class Host_Plugin_Plesk_10 extends Host_Plugin_Plesk {
$client = $this->packet->add_node('customer');
$get = $client->add_node('get');
$filter = $get->add_node('filter');
$filter->add_node('login',$so->plugin()->host_account);
$filter->add_node('login',$so->plugin()->host_username);
$dataset = $get->add_node('dataset');
foreach ($items as $k)
$dataset->add_node($k);
@ -172,7 +172,7 @@ class Host_Plugin_Plesk_10 extends Host_Plugin_Plesk {
$gen_info->add_node('cname',$so->account->company);
$gen_info->add_node('pname',sprintf('%s %s',$so->account->first_name,$so->account->last_name));
$gen_info->add_node('login',$so->plugin()->host_account);
$gen_info->add_node('login',$so->plugin()->host_username);
$gen_info->add_node('passwd',$so->plugin()->host_password);
$gen_info->add_node('status',0);
@ -229,5 +229,19 @@ class Host_Plugin_Plesk_10 extends Host_Plugin_Plesk {
return $this->packet->add_node($type);
}
public function setpasswd(Model_Service $so,$pw) {
$this->init();
$client = $this->packet->add_node('customer');
$set = $client->add_node('set');
$filter = $set->add_node('filter');
$filter->add_node('login',$so->plugin()->host_username);
$values = $set->add_node('values');
$gen_info = $values->add_node('gen_info');
$gen_info->add_node('passwd',$pw);
return $this->server_command($this->xml);
}
}
?>

View File

@ -88,7 +88,7 @@ class Host_Plugin_Plesk_9 extends Host_Plugin_Plesk {
$client = $this->packet->add_node('client');
$get = $client->add_node('get');
$filter = $get->add_node('filter');
$filter->add_node('login',$so->plugin()->host_account);
$filter->add_node('login',$so->plugin()->host_username);
$dataset = $get->add_node('dataset');
foreach ($items as $k)
$dataset->add_node($k);
@ -303,5 +303,19 @@ class Host_Plugin_Plesk_9 extends Host_Plugin_Plesk {
return $this->server_command($this->xml);
*/
}
public function setpasswd(Model_Service $so,$pw) {
$this->init();
$client = $this->packet->add_node('client');
$set = $client->add_node('set');
$filter = $set->add_node('filter');
$filter->add_node('login',$so->plugin()->host_username);
$values = $set->add_node('values');
$gen_info = $values->add_node('gen_info');
$gen_info->add_node('passwd',$pw);
return $this->server_command($this->xml);
}
}
?>