diff --git a/application/classes/lnapp/pwgen.php b/application/classes/lnapp/pwgen.php new file mode 100644 index 00000000..31e8bb0b --- /dev/null +++ b/application/classes/lnapp/pwgen.php @@ -0,0 +1,36 @@ +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)."
"; + + return $pwonly ? $passwd : array('pw'=>$passwd,'say'=>$passwdSay); + } +} +?> diff --git a/application/classes/pwgen.php b/application/classes/pwgen.php new file mode 100644 index 00000000..025ab76d --- /dev/null +++ b/application/classes/pwgen.php @@ -0,0 +1,4 @@ + diff --git a/application/config/pwgen.php b/application/config/pwgen.php new file mode 100644 index 00000000..70feb2aa --- /dev/null +++ b/application/config/pwgen.php @@ -0,0 +1,18 @@ + '127.0.0.1', + 'port' => '129', +); +?> diff --git a/modules/host/classes/controller/task/host.php b/modules/host/classes/controller/task/host.php index 25794d8b..2b7f5c50 100644 --- a/modules/host/classes/controller/task/host.php +++ b/modules/host/classes/controller/task/host.php @@ -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'); + } } ?> diff --git a/modules/host/classes/host/plugin/plesk/10.php b/modules/host/classes/host/plugin/plesk/10.php index 0da9560c..30a51327 100644 --- a/modules/host/classes/host/plugin/plesk/10.php +++ b/modules/host/classes/host/plugin/plesk/10.php @@ -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); + } } ?> diff --git a/modules/host/classes/host/plugin/plesk/9.php b/modules/host/classes/host/plugin/plesk/9.php index 8064f70f..c61bc59a 100644 --- a/modules/host/classes/host/plugin/plesk/9.php +++ b/modules/host/classes/host/plugin/plesk/9.php @@ -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); + } } ?>