Fix abstract passwords in host/domain manage planel logins

This commit is contained in:
Deon George 2012-06-22 15:12:59 +10:00
parent 0eecfe8abd
commit df82268405
12 changed files with 93 additions and 42 deletions

View File

@ -52,6 +52,14 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
->set('so',$this); ->set('so',$this);
} }
public function username_value() {
return $this->service_username;
}
public function password_value() {
return $this->service_password;
}
/** /**
* Return the IP Address for the service * Return the IP Address for the service
*/ */
@ -307,7 +315,7 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
$traffic_type = $this->get_traffic_data_daily($period,TRUE); $traffic_type = $this->get_traffic_data_daily($period,TRUE);
// @todo If no data comes in, then this can be stuck reporting traffic for an old date. // @todo If no data comes in, then this can be stuck reporting traffic for an old date.
$day = count($traffic_type) ? max(array_keys($traffic_type)) : 1; $day = count($traffic_type) ? max(array_keys($traffic_type)) : 1;
$lastday = date('d',strtotime('last day of',$period)); $lastday = date('d',strtotime('last day of',$period));
foreach ($traffic as $k => $v) { foreach ($traffic as $k => $v) {
// If we are the last day of the period // If we are the last day of the period

View File

@ -14,14 +14,14 @@ class Model_Domain_Registrar extends ORMOSB {
/** /**
* The button that provides a login to the Registrar to manage the domain license * The button that provides a login to the Registrar to manage the domain license
*/ */
public function manage_button($u,$p,$d) { public function manage_button(Model_Service_Plugin_Domain $spdo,$t) {
$c = sprintf('Service_Domain_%s',$this->file); $c = sprintf('Service_Domain_%s',$this->file);
if (! class_exists($c)) if (! class_exists($c))
return ''; return '';
$po = new $c($this->id); $po = new $c($this->id);
return $po->manage_button($u,$p,$d); return $po->manage_button($spdo,$t);
} }
} }
?> ?>

View File

@ -57,16 +57,26 @@ class Model_Service_Plugin_Domain extends Model_Service_Plugin {
->set('so',$this); ->set('so',$this);
} }
public function username_value() {
return $this->registrar_username;
}
public function password_value() {
return $this->registrar_password;
}
/** /**
* This provides us with a manage button to jump to the registrar * This provides us with a manage button to jump to the registrar
* to manage the domain. * to manage the domain.
*/ */
public function manage_button() { public function manage_button($t='') {
return ($this->registrar_username AND $this->registrar_password) ? $this->domain_registrar->manage_button($this->registrar_username,$this->registrar_password,$this->name()) : _('Please contact us'); parent::manage_button($t);
return ($this->username_value() AND $this->password_value()) ? $this->domain_registrar->manage_button($this,$t) : _('Please contact us');
} }
public function manage_dns_button() { public function manage_dns_button() {
return $this->service_plugin_host->manage_button(); return $this->service_plugin_host->manage_button('service_plugin_host');
} }
} }
?> ?>

View File

@ -37,7 +37,7 @@ abstract class Service_Domain {
/** /**
* Our HTML button that will enable us to manage this domain. * Our HTML button that will enable us to manage this domain.
*/ */
abstract public function manage_button($u,$p,$d); abstract public function manage_button(Model_Service_Plugin_Domain $spdo,$t);
/** /**
* Return an instance of this class * Return an instance of this class

View File

@ -16,17 +16,18 @@ class Service_Domain_TPP extends Service_Domain {
private $login_pass_field = 'password'; private $login_pass_field = 'password';
// Our required abstract classes // Our required abstract classes
public function manage_button($u,$p,$d) { public function manage_button(Model_Service_Plugin_Domain $spdo,$t) {
$debug = FALSE;
$output = ''; $output = '';
$output .= Form::open( $output .= Form::open(
sprintf('%s/%s',$this->so->whitelabel_url,'execute/logon'), $debug ? 'debug/site' : sprintf('%s/%s',$this->so->whitelabel_url,'execute/logon'),
array('target'=>'tpp','method'=>'post') array('target'=>'tpp','method'=>'post','id'=>sprintf('id_%s_%s',$spdo->service_id,$t))
); );
$output .= Form::input($this->login_user_field,$u,array('type'=>'hidden')); $output .= Form::input($this->login_user_field,$spdo->username_value(),array('type'=>'hidden','id'=>sprintf('u_%s_%s',$spdo->service_id,$t)));
$output .= Form::input($this->login_pass_field,$p,array('type'=>'hidden')); $output .= Form::input($this->login_pass_field,substr(md5($spdo->password_value()),0,8),array('type'=>'hidden','id'=>sprintf('p_%s_%s',$spdo->service_id,$t)));
$output .= Form::button('submit',_('Manage'),array('class'=>'form_button'));
$output .= Form::close(); $output .= Form::close();
$output .= Form::button('submit',_('Manage'),array('class'=>'form_button','value'=>sprintf('%s:%s',$spdo->service_id,$t)));
return $output; return $output;
} }

View File

@ -14,14 +14,14 @@ class Model_Host_Server extends ORMOSB {
// Host Server doesnt use the update column // Host Server doesnt use the update column
protected $_updated_column = FALSE; protected $_updated_column = FALSE;
public function manage_button($u,$p,$d) { public function manage_button(Model_Service_Plugin_Host $spho,$t) {
$c = sprintf('Service_Host_%s',$this->provision_plugin); $c = sprintf('Service_Host_%s',$this->provision_plugin);
if (! class_exists($c)) if (! class_exists($c))
return ''; return '';
$po = new $c($this->id); $po = new $c($this->id);
return $po->manage_button($u,$p,$d); return $po->manage_button($spho,$t);
} }
public function prov_plugin_data() { public function prov_plugin_data() {

View File

@ -58,31 +58,26 @@ class Model_Service_Plugin_Host extends Model_Service_Plugin {
->set('so',$this); ->set('so',$this);
} }
public function username_value() {
return $this->host_username;
}
public function password_value() {
return $this->host_password;
}
/** /**
* This provides us with a manage button to jump to the hosting server * This provides us with a manage button to jump to the hosting server
* to manage the domain. * to manage the domain.
*/ */
public function manage_button() { public function manage_button($t='') {
$k = Random::char(); parent::manage_button($t);
Session::instance()->set('manage_button',$k);
Script::add(array('type'=>'stdin','data'=>'
$(document).ready(function() {
var x=0;
$("button[name=submit]").click(function() {
if (x++) { alert("Please refresh the page"); return false; }
$.getJSON("'.URL::site('user/service/ajaxmanage/'.$this->service_id).'", { k: "'.$k.'" }, function(data) {
$.each(data, function(key, val) { $("#"+key).val(val); });
}).error(function() { alert("There was a problem with the request"); return false; }).success(function() { $("#manage").submit(); });
});
});'
));
// @todo Convert this to a Static_List display // @todo Convert this to a Static_List display
if ($this->service->queue == 'PROVISION') if ($this->service->queue == 'PROVISION')
return _('To Be Provisioned'); return _('To Be Provisioned');
return ($this->host_username AND $this->host_password) ? $this->host_server->manage_button($this->host_username,substr(md5($this->host_password),0,8),$this->name()) : ''; return ($this->username_value() AND $this->password_value()) ? $this->host_server->manage_button($this,$t) : _('Please contact us');
} }
} }
?> ?>

View File

@ -36,8 +36,10 @@ abstract class Service_Host {
/** /**
* Our HTML button that will enable us to manage this domain. * Our HTML button that will enable us to manage this domain.
*
* @param so Our Service Object
*/ */
abstract public function manage_button($u,$p,$d); abstract public function manage_button(Model_Service_Plugin_Host $spho,$t);
/** /**
* Return an instance of this class * Return an instance of this class

View File

@ -16,17 +16,18 @@ class Service_Host_Plesk extends Service_Host {
private $login_pass_field = 'passwd'; private $login_pass_field = 'passwd';
// Our required abstract classes // Our required abstract classes
public function manage_button($u,$p,$d) { public function manage_button(Model_Service_Plugin_Host $spho,$t) {
$debug = FALSE;
$output = ''; $output = '';
$output .= Form::open( $output .= Form::open(
sprintf('%s/%s',$this->so->manage_url,'login_up.php3'), $debug ? 'debug/site' : sprintf('%s/%s',$this->so->manage_url,'login_up.php3'),
array('target'=>'w24','method'=>'post','id'=>'manage') array('target'=>'w24','method'=>'post','id'=>sprintf('id_%s_%s',$spho->service_id,$t))
); );
$output .= Form::input($this->login_user_field,$u,array('type'=>'hidden','id'=>'u')); $output .= Form::input($this->login_user_field,$spho->username_value(),array('type'=>'hidden','id'=>sprintf('u_%s_%s',$spho->service_id,$t)));
$output .= Form::input($this->login_pass_field,$p,array('type'=>'hidden','id'=>'p')); $output .= Form::input($this->login_pass_field,substr(md5($spho->password_value()),0,8),array('type'=>'hidden','id'=>sprintf('p_%s_%s',$spho->service_id,$t)));
$output .= Form::close(); $output .= Form::close();
$output .= Form::button('submit',_('Manage'),array('class'=>'form_button')); $output .= Form::button('submit',_('Manage'),array('class'=>'form_button','value'=>sprintf('%s:%s',$spho->service_id,$t)));
return $output; return $output;
} }

View File

@ -22,10 +22,11 @@ class Controller_User_Service extends Controller_TemplateDefault_User {
$so = ORM::factory('service',$this->request->param('id')); $so = ORM::factory('service',$this->request->param('id'));
$k = Session::instance()->get_once('manage_button'); $k = Session::instance()->get_once('manage_button');
$amo = $so->plugin(isset($_REQUEST['t']) ? $_REQUEST['t'] : '');
$o = array( $o = array(
'u'=>$so->plugin()->host_username ? $so->plugin()->host_username : strtolower($so->plugin()->name()), 'u'=>$amo->username_value() ? $amo->username_value() : strtolower($amo->name()),
'p'=>(! $k OR ! $this->request->is_ajax() OR ! $so->loaded() OR ! isset($_REQUEST['k']) OR $k != $_REQUEST['k']) ? Random::char() : $so->plugin()->host_password, 'p'=>(! $k OR ! $this->request->is_ajax() OR ! $so->loaded() OR ! isset($_REQUEST['k']) OR $k != $_REQUEST['k']) ? Random::char() : $amo->password_value(),
); );
$this->response->headers('Content-Type','application/json'); $this->response->headers('Content-Type','application/json');

View File

@ -49,14 +49,16 @@ class Model_Service extends ORMOSB {
/** /**
* Return the object of the product plugin * Return the object of the product plugin
*/ */
public function plugin() { public function plugin($type='') {
if (! $this->product->prod_plugin_file) if (! $this->product->prod_plugin_file)
return NULL; return NULL;
if (! is_numeric($this->product->prod_plugin_data)) if (! is_numeric($this->product->prod_plugin_data))
throw new Kohana_Exception('Missing plugin_id for :product (:type)',array(':product'=>$this->product->id,':type'=>$this->product->prod_plugin_file)); throw new Kohana_Exception('Missing plugin_id for :product (:type)',array(':product'=>$this->product->id,':type'=>$this->product->prod_plugin_file));
return ORM::factory(sprintf('service_plugin_%s',$this->product->prod_plugin_file),array('service_id'=>$this->id)); $o = ORM::factory(sprintf('service_plugin_%s',$this->product->prod_plugin_file),array('service_id'=>$this->id));
return $type ? $o->$type : $o;
} }
/** /**

View File

@ -36,6 +36,37 @@ abstract class Model_Service_Plugin extends ORMOSB {
*/ */
abstract public function service_view(); abstract public function service_view();
/**
* The table attributes that provide username/password values
*/
abstract public function username_value();
abstract public function password_value();
public function manage_button() {
static $k = '';
// If $k is already set, we've rendered this JS
if ($k)
return;
$k = Random::char();
Session::instance()->set('manage_button',$k);
Script::add(array('type'=>'stdin','data'=>'
$(document).ready(function() {
var x=0;
$("button[name=submit]").click(function() {
var t=$(this).val().split(":");
if (x++) { alert("Please refresh the page"); return false; }
$.getJSON("'.URL::site('user/service/ajaxmanage/'.$this->service_id).'", { k: "'.$k.'",t: t[1] }, function(data) {
$.each(data, function(key, val) { $("#"+key+"_"+t[0]+"_"+t[1]).val(val); });
}).error(function() { alert("There was a problem with the request"); return false; }).success(
function() { $("form[id=id_"+t[0]+"_"+t[1]+"]").submit(); });
});
});'
));
}
/** /**
* Get specific service details for use in other modules * Get specific service details for use in other modules
* For Example: Invoice * For Example: Invoice