Fixed DSL traffic fetch to work with KH 3.1

This commit is contained in:
Deon George 2011-08-04 00:24:38 +10:00
parent 5953e28f22
commit f1c960aa9f
7 changed files with 54 additions and 43 deletions

View File

@ -19,7 +19,6 @@ abstract class ORMOSB extends ORM {
protected $_created_column = array('column'=>'date_orig','format'=>TRUE); protected $_created_column = array('column'=>'date_orig','format'=>TRUE);
protected $_updated_column = array('column'=>'date_last','format'=>TRUE); protected $_updated_column = array('column'=>'date_last','format'=>TRUE);
// @todo Rules are no longer used?
public function rules() { public function rules() {
return array( return array(
'id'=>array( 'id'=>array(

View File

@ -24,7 +24,6 @@ class Model_Service_ADSL extends Model_Service {
'service_connect_date'=>array( 'service_connect_date'=>array(
array('Config::date',array(':value')), array('Config::date',array(':value')),
), ),
); );
/** /**

View File

@ -13,11 +13,16 @@
class Model_Service_ADSL_Traffic extends ORMOSB { class Model_Service_ADSL_Traffic extends ORMOSB {
protected $_table_name = 'service__adsl_traffic'; protected $_table_name = 'service__adsl_traffic';
protected $_primary_key = 'service'; protected $_primary_key = 'service';
protected $_callbacks = array(
'site_id'=>array('set_site_id'),
);
protected $_created_column = FALSE; protected $_created_column = FALSE;
protected $_updated_column = FALSE; protected $_updated_column = FALSE;
public function rules() {
return array(
'site_id'=>array(
array('ORMOSB::set_site_id',array(':validation',':model',':field')),
),
);
}
} }
?> ?>

View File

@ -89,7 +89,7 @@ class Service_Traffic_ADSL {
$traffic = ORM::factory('service_adsl_traffic'); $traffic = ORM::factory('service_adsl_traffic');
foreach ($data as $item) { foreach ($data as $item) {
$traffic->values($item); $traffic->values($item,array_keys($item));
$traffic->supplier_id = $this->so->id; $traffic->supplier_id = $this->so->id;
if ($traffic->check()) if ($traffic->check())

View File

@ -33,25 +33,27 @@ class Service_Traffic_ADSL_ExetelHSPA extends Service_Traffic_ADSL {
if (! empty(Service_Traffic_ADSL_ExetelHSPA::$return[$date])) if (! empty(Service_Traffic_ADSL_ExetelHSPA::$return[$date]))
return Service_Traffic_ADSL_ExetelHSPA::$return[$date]; return Service_Traffic_ADSL_ExetelHSPA::$return[$date];
include_once 'includes/kohana/modules/simplehtmldom/classes/simple_html_dom.php';
// Find our services that need to be collected this way. // Find our services that need to be collected this way.
$update = array(); $update = array();
foreach ($this->so->services() as $so) { foreach ($this->so->services() as $so) {
if ($so->service_adsl->service_stats_collect AND $so->service_adsl->service_stats_lastupdate < $date) { if ($so->service_adsl->service_stats_collect AND $so->service_adsl->service_stats_lastupdate < $date) {
$postfields = http_build_query(array(
$this->login_user_field=>$so->service_adsl->service_username,
$this->login_pass_field=>$so->service_adsl->service_password,
'doLogin'=>1,
'submit'=>'Login',
));
// Start Session // Start Session
Remote::clear(); $request = Request::factory($this->so->stats_url)
$data = Remote::get($this->so->stats_url, ->method('POST')
$this->curlopts+array( ->post($this->login_user_field,$so->service_adsl->service_username)
CURLOPT_POSTFIELDS=>$postfields, ->post($this->login_pass_field,$so->service_adsl->service_password)
CURLOPT_COOKIEJAR=>sprintf('/tmp/usage.cookies.%s.txt',$so->service_adsl->service_number), ->post('doLogin',1)
), ->post('submit','Login');
TRUE);
$request->get_client()->options($this->curlopts+array(
CURLOPT_COOKIEJAR=>sprintf('/tmp/usage.cookies.%s.txt',$so->service_adsl->service_number),
));
$response = $request->execute();
$data = $response->body();
if (! $data) { if (! $data) {
// @todo Log into a log file // @todo Log into a log file
@ -62,8 +64,6 @@ class Service_Traffic_ADSL_ExetelHSPA extends Service_Traffic_ADSL {
continue; continue;
} }
include_once 'includes/kohana/modules/simplehtmldom/classes/simple_html_dom.php';
for ($servicedate=date('Y-m-d',strtotime($this->so->stats_lastupdate.'+1 day')); for ($servicedate=date('Y-m-d',strtotime($this->so->stats_lastupdate.'+1 day'));
$servicedate <= $this->today; $servicedate <= $this->today;
$servicedate=date('Y-m-d',strtotime('+1 month',strtotime(date('Y-m',strtotime($servicedate)).'-01')))) { $servicedate=date('Y-m-d',strtotime('+1 month',strtotime(date('Y-m',strtotime($servicedate)).'-01')))) {
@ -72,21 +72,26 @@ class Service_Traffic_ADSL_ExetelHSPA extends Service_Traffic_ADSL {
if (strtotime($lastday) > time()) if (strtotime($lastday) > time())
$lastday = date('Y-m-d',strtotime('yesterday')); $lastday = date('Y-m-d',strtotime('yesterday'));
$postfields = http_build_query(array(
'year_search_key'=>date('Y',strtotime($servicedate)),
'month_search_key'=>date('m',strtotime($servicedate)),
'start_day_search_key'=>date('d',strtotime($servicedate)),
'end_day_search_key'=>date('d',strtotime($lastday)),
'do_usage_search'=>1,
));
$html = new simple_html_dom(); $html = new simple_html_dom();
$notdebug = TRUE; $notdebug = TRUE;
if ($notdebug) { if ($notdebug) {
$result = Remote::get($this->so->stats_url.'usage_customize_query.php',$this->curlopts+array(CURLOPT_POSTFIELDS=>$postfields),TRUE); $request = Request::factory($this->so->stats_url.'usage_customize_query.php')
->method('POST')
->post('year_search_key',date('Y',strtotime($servicedate)))
->post('month_search_key',date('m',strtotime($servicedate)))
->post('start_day_search_key',date('d',strtotime($servicedate)))
->post('end_day_search_key',date('d',strtotime($lastday)))
->post('do_usage_search',1);
$request->get_client()->options($this->curlopts+array(
CURLOPT_COOKIEFILE=>sprintf('/tmp/usage.cookies.%s.txt',$so->service_adsl->service_number),
));
$response = $request->execute();
$result = $response->body();
$html->load($result); $html->load($result);
$html->save(sprintf('/afs/local/tmp/usage.%s.%s.html',$so->service_adsl->service_number,$servicedate)); #$html->save(sprintf('/afs/local/tmp/usage.%s.%s.html',$so->service_adsl->service_number,$servicedate));
} else { } else {
$html->load_file(sprintf('/tmp/usage.%s.%s.txt',$so->service_adsl->service_number,$servicedate)); $html->load_file(sprintf('/tmp/usage.%s.%s.txt',$so->service_adsl->service_number,$servicedate));
} }

View File

@ -16,20 +16,23 @@ class Service_Traffic_ADSL_ExetelVisp extends Service_Traffic_ADSL {
private $date_field = 'date'; private $date_field = 'date';
protected function getdata($date) { protected function getdata($date) {
$return = array();
// Assume we have a bad fetch, unless otherwise specified. // Assume we have a bad fetch, unless otherwise specified.
$this->fetchresult = FALSE; $this->fetchresult = FALSE;
$return = array(); $request = Request::factory($this->so->stats_url)
->method('POST')
->post($this->login_user_field,$this->so->stats_username)
->post($this->login_pass_field,$this->so->stats_password)
->post($this->date_field,$date);
$data = Remote::get($this->so->stats_url,$this->curlopts+array( $request->get_client()->options($this->curlopts+array(
CURLOPT_POST => TRUE, CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => http_build_query(array( ));
$this->login_user_field=>$this->so->stats_username,
$this->login_pass_field=>$this->so->stats_password, $response = $request->execute();
$this->date_field=>$date, $data = $response->body();
)
))
);
$resultarray = explode("\n",$data); $resultarray = explode("\n",$data);

View File

@ -51,7 +51,8 @@
| <a href="?_page=account:account&amp;_logout=Y">{t}Logout{/t}</a> | <a href="?_page=account:account&amp;_logout=Y">{t}Logout{/t}</a>
{else} {else}
| <a href="index.php?_page=account:user_login">{t}Login{/t}</a> | <a href="login">{t}User Login{/t}</a>
| <a href="index.php?_page=account:user_login">{t}Admin Login{/t}</a>
| <a href="index.php?_page=account:user_add">{t}Register{/t}</a> | <a href="index.php?_page=account:user_add">{t}Register{/t}</a>
{if $smarty.const.SHOW_CHECKOUT_LINK}| <a href="{$SSL_URL}?_page=checkout:checkout&amp;s={$SESS}">{t}Checkout{/t}</a>{/if} {if $smarty.const.SHOW_CHECKOUT_LINK}| <a href="{$SSL_URL}?_page=checkout:checkout&amp;s={$SESS}">{t}Checkout{/t}</a>{/if}
{/if} {/if}
@ -78,7 +79,6 @@
{elseif $smarty.const.DEFAULT_PAGE != ''} {elseif $smarty.const.DEFAULT_PAGE != ''}
{$block->display($smarty.const.DEFAULT_PAGE)} {$block->display($smarty.const.DEFAULT_PAGE)}
{else} {else}
{$block->display('account:user_login')}
{/if} {/if}
</div> </div>
</td> </td>