From 5ab2d6205f3ca0ee6f92056f6dcd2860d4d15ab8 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 27 Jul 2016 14:25:17 +1000 Subject: [PATCH] Optimised Service Display, extended SSL module functionality --- .../Database/{Mysql.php => MySQLi.php} | 2 +- .../classes/Database/Query/Builder/Join.php | 21 +++ application/classes/Model/Account.php | 6 +- application/config/database.php | 43 ++++++- application/config/session.php | 18 +++ application/media/guide/img/logo-small.png | Bin 0 -> 2225 bytes modules/lnapp | 2 +- .../classes/Controller/Admin/Service.php | 5 +- modules/service/classes/Model/Service.php | 5 +- modules/service/views/service/admin/edit.php | 43 +++---- modules/service/views/service/info.php | 72 +++++------ .../views/service/user/invoice/list.php | 18 +++ .../views/service/user/invoice/next.php | 6 + modules/service/views/service/user/view.php | 121 ++++-------------- .../views/service/user/view/charges.php | 12 ++ .../views/service/user/view/emails.php | 17 +++ .../service/views/service/user/view/memos.php | 13 ++ .../views/service/user/view/payment.php | 13 ++ .../Controller/Reseller/Service/Ssl.php | 2 + .../ssl/classes/Controller/Reseller/Ssl.php | 2 + modules/ssl/classes/Controller/SSL.php | 14 -- modules/ssl/classes/Controller/Ssl.php | 64 +++++++++ modules/ssl/classes/Controller/User/Ssl.php | 27 +++- .../ssl/classes/Model/Service/Plugin/Ssl.php | 24 +++- modules/ssl/classes/SSL.php | 2 +- .../views/service/admin/plugin/ssl/edit.php | 14 +- .../views/service/user/plugin/ssl/view.php | 65 +--------- .../user/plugin/ssl/view/certificate.php | 18 +++ .../service/user/plugin/ssl/view/chain.php | 20 +++ .../service/user/plugin/ssl/view/details.php | 44 +++++++ 30 files changed, 455 insertions(+), 258 deletions(-) rename application/classes/Database/{Mysql.php => MySQLi.php} (89%) create mode 100644 application/classes/Database/Query/Builder/Join.php create mode 100644 application/config/session.php create mode 100644 application/media/guide/img/logo-small.png create mode 100644 modules/service/views/service/user/invoice/list.php create mode 100644 modules/service/views/service/user/invoice/next.php create mode 100644 modules/service/views/service/user/view/charges.php create mode 100644 modules/service/views/service/user/view/emails.php create mode 100644 modules/service/views/service/user/view/memos.php create mode 100644 modules/service/views/service/user/view/payment.php delete mode 100644 modules/ssl/classes/Controller/SSL.php create mode 100644 modules/ssl/classes/Controller/Ssl.php create mode 100644 modules/ssl/views/service/user/plugin/ssl/view/certificate.php create mode 100644 modules/ssl/views/service/user/plugin/ssl/view/chain.php create mode 100644 modules/ssl/views/service/user/plugin/ssl/view/details.php diff --git a/application/classes/Database/Mysql.php b/application/classes/Database/MySQLi.php similarity index 89% rename from application/classes/Database/Mysql.php rename to application/classes/Database/MySQLi.php index 5b7e889f..a3e1b64b 100644 --- a/application/classes/Database/Mysql.php +++ b/application/classes/Database/MySQLi.php @@ -12,7 +12,7 @@ * @copyright (c) 2009-2013 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Database_MySQL extends Kohana_Database_MySQL { +class Database_MySQLi extends Kohana_Database_MySQLi { // MySQL uses a backtick for identifiers protected $_identifier = ''; } diff --git a/application/classes/Database/Query/Builder/Join.php b/application/classes/Database/Query/Builder/Join.php new file mode 100644 index 00000000..975c95f1 --- /dev/null +++ b/application/classes/Database/Query/Builder/Join.php @@ -0,0 +1,21 @@ +_on[] = array($this->_table.'.site_id','=',Site::id()); + + return parent::compile($db); + } +} +?> diff --git a/application/classes/Model/Account.php b/application/classes/Model/Account.php index e8fe2fdb..7174fc01 100644 --- a/application/classes/Model/Account.php +++ b/application/classes/Model/Account.php @@ -50,6 +50,10 @@ class Model_Account extends Model_Auth_UserDefault { return sprintf('%s-%04s',Company::instance()->site(TRUE),$this->id); } + public function activated() { + return $this->has('group'); + } + /** * Get the groups that an account belongs to */ @@ -135,7 +139,7 @@ class Model_Account extends Model_Auth_UserDefault { if (empty($result[$mmo->id])) $result[$mmo->id] = $mmo; - Sort::MAsort($result,'module->name,menu_display'); + Sort::MAsort($result,array('module->name','menu_display')); return $result; } diff --git a/application/config/database.php b/application/config/database.php index 896a3e43..30faa4b1 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -12,7 +12,7 @@ return array ( - 'default' => array + 'old' => array ( 'type' => 'mysql', 'connection' => array( @@ -39,5 +39,46 @@ return array 'compress' => FALSE, 'profiling' => TRUE, ), + 'pdo' => array( + 'type' => 'PDO', + 'connection' => array( + /** + * The following options are available for PDO: + * + * string dsn Data Source Name + * string username database username + * string password database password + * boolean persistent use persistent connections? + */ + 'dsn' => 'mysql:host=localhost;dbname=database', + 'username' => 'username', + 'password' => 'password', + 'persistent' => FALSE, + ), + /** + * The following extra options are available for PDO: + * + * string identifier set the escaping identifier + */ + 'table_prefix' => 'ab_', + 'charset' => 'utf8', + 'caching' => FALSE, + ), + 'default' => array( + 'type' => 'MySQLi', + 'connection' => array( + 'hostname' => 'localhost', + 'username' => 'username', + 'password' => 'password', + 'persistent' => FALSE, + 'database' => 'database', + 'ssl' => NULL, + ), + 'table_prefix' => 'ab_', + 'charset' => 'utf8', + 'caching' => FALSE, + 'compress' => FALSE, + 'profiling' => TRUE, + ), ); ?> diff --git a/application/config/session.php b/application/config/session.php new file mode 100644 index 00000000..c0bfec9b --- /dev/null +++ b/application/config/session.php @@ -0,0 +1,18 @@ + array( + 'name'=>'OSB', + ), +); +?> diff --git a/application/media/guide/img/logo-small.png b/application/media/guide/img/logo-small.png new file mode 100644 index 0000000000000000000000000000000000000000..2fc13978cef1e3304a5c891cfa040a571cea2ff2 GIT binary patch literal 2225 zcmV;i2u}BjP)Px##!yUDMG06&_xJbj@9+Hl`~V++=jZ3%-rmN>#?8&n*4EYm9B=>^Spp`SBuAe| zZoQhIt_muL!N=04th_c>tg^)4GeU0x5=Cfyx3sy(c8$fr!NZTC+YC0xjg+VbEwW^6 zgu%?=RCmK5Mzxflzbi+PQgh%LJeQKR<8GPUE?C`VbDT|DgQ&sr2op1Sevv&zUM*ex zccb|eC0u5K;4xUo$JFLie)(dN`wTnXEH+Zv;Os|Xpd(A)#@_Mb=k3_r;N|G`0001( zMG;p30004WQchCmc74NO)>PtsWBM7Yl%N zk6)T$=k#>cV=Rc?LEleVk@xT2Lu{#^s~cpzG|n8(`CZ6@j^j8)CC+MGb+c(^fBw`+ z^9ne8ZIG(t{1}}9lF!F1XgLm1O>w--V4>J>)ck3b=4sgjt#0s8fa!UhpEQ7pa05MB zdsh6tR+~Q?=3c0s!dw**eBuMs^DdF;<OT2>GqRkyMxv)L@u&~+^?>QR zE;2+P;^~P2AvU&P?es#fo)^4{)x5%8<+2H!b zv2xrU)a%X3KY1IQ?ReS@Z_dvjK(7IM?Pw3vAYZQQxEvdk_A4XteLqkFnBV|Nd-9V~ zd@`kR-F=B`#4NMUOqr%Mme~h%?8Y0N-0GI%4j~w@O(DA0KMBZ6_AZmCLy~QzLKrD4Kes2Mk>VN{iud_v~ z)qkyHJM!GO`k4^3+Ys8PF#X@IOqrK6O_(niEI8wy=Yq`*Cajgv*I*4hq~}fHKZbkq zo!St!bWw)AizN&{kV#?wfN-czqX9B&QM15Q0z1AlcIsU=i44-E_Vbv%64Sk&2FL`x zq`)jo?Hrf^G9kbXCgj#vWE3hSAZDMK-Zx;nP(b5JJdE7h{XH_DKo7T)1DMW_G4q2C zhSS`NGcehkz|QL;Q<%W+klCG5)zurX_cNI!6elvdQ?@4<=H&oNV&>LrH#ncQO{Q@1 z*Q8;YeV5vXdBd!XCy`~k6zD!CY#vu_bz@7N>_tHJna#|bq>I|IxhCb1D1shRGZiyMe26v_{5tvXL zVH1kVFj3}=!AbK3uEmk5AwR`xj*Z6kHCw`p0iVK?{NyWVLYTf<)K*B`0@&3}+(PCI z7Ln)8nZNM72~K>weICbCe?cp#eHRat&hV`lfD5>4+130qKjO=nV4AfX=Ole(;ugTd z!MF+Q^VVzvOas|7Cjl%Ewy1fuYFV9R2}swQ;v9vIQB?NWX5(zIRnbFqpxwda!dK`_ zb1;Sz^(GJ;c1Q1upe!(+7#CpVvPEt8f%IhQlY(JBj_NBYYc@I%QPd2X>OYR*81c_w zKf77b(Z#*!d<2M;lLuZ4*NPu3T(diIK7<>Zmpv0#bEe-Ip>;Z!UX!sX8p*^kvn;x zl6_B_whTRs+>I){wyoP+{Rg}ZR##A`SnavuCT{x$e(Tlxptt+{F@B?H3Y=XQHg9YV zIPfjd7W;YzfA8m+BJ@+AEdGbjPY0~5-}eRTLt?7ZUj!vmN&cx%J2I2`Po-3ae;%2k zh>Fm9$7eH@CEF@GTg9oetb*EGLW(lW60Wo{!IMg+%+D0=XW+Po8=%XjO0DBsC(x(3$U1>mc%BUuM%z9^s^sA~Nwd z7P=^Sn$g@UlLyK)F|jBlUDgH-jGIbdRRb~Mnwq&t=xP+PG%yxqCKQdbi8p1SEmNB~ z!4jIq)oX@G@=uX>Yi4H4i%L49RiG(hq^PW2g*6P*V7e+;VHl_>G^$>-m*O%>Op%bk z)R3!s(aNqgnbMvBH!^L)vk62+MOLntSF9)TCG;#t}Q0pY^%aP zRM=BC1%gs5type('form-horizontal') ->title('Add/View Charge') - ->title_icon('icon-wrench') + ->title_icon('fa fa-wrench') ->body(View::factory('service/admin/add')); } @@ -169,7 +170,7 @@ $(document).ready(function() { Block::factory() ->type('form-horizontal') ->title(sprintf('%s: %s %s',_('Update Service'),$id,$so->name())) - ->title_icon('icon-wrench') + ->title_icon('fa fa-wrench') ->body(View::factory('service/admin/edit') ->set('o',$so) ->set('plugin_form',$so->plugin_edit()) diff --git a/modules/service/classes/Model/Service.php b/modules/service/classes/Model/Service.php index 2b45d0de..2abe972a 100644 --- a/modules/service/classes/Model/Service.php +++ b/modules/service/classes/Model/Service.php @@ -156,7 +156,7 @@ class Model_Service extends ORM_OSB { /** * List invoices for this service */ - public function invoice_list($due=FALSE) { + public function invoice_list($due=FALSE,$num=NULL) { $result = array(); $x = $this->invoice->distinct('id'); @@ -165,6 +165,9 @@ class Model_Service extends ORM_OSB { if ($due) $x->where_unprocessed(); + if (! is_null($num)) + $x->limit($num); + foreach ($x->find_all() as $io) if (! $due OR $io->due()) array_push($result,$io); diff --git a/modules/service/views/service/admin/edit.php b/modules/service/views/service/admin/edit.php index 21b91018..f0252f6c 100644 --- a/modules/service/views/service/admin/edit.php +++ b/modules/service/views/service/admin/edit.php @@ -1,42 +1,29 @@ -
+
Update Service -
- status,FALSE,array('label'=>'Active','class'=>'span1')); ?> -
+ status,FALSE,array('label'=>'Active')); ?> -
- recur_schedule,FALSE,array('label'=>'Billing Period','required'));?> -
+ recur_schedule,FALSE,array('label'=>'Billing Period','required'));?> -
-
- display('date_next_invoice'),array('class'=>'span2','label'=>'Date Next Invoice','add-on'=>'','disabled')); ?> -
+ +
+ + +
+ date_next_invoice); ?> - date_next_invoice); ?> -
+ taxable,FALSE,array('label'=>'Taxable')); ?> -
- taxable,FALSE,array('label'=>'Taxable','class'=>'span1')); ?> -
+ suspend_billing,FALSE,array('label'=>'Suspend Billing')); ?> -
- suspend_billing,FALSE,array('label'=>'Suspend Billing','class'=>'span1')); ?> -
- -
- price_override,array('label'=>'Override Price','class'=>'span1')); ?> -
+ price_override,array('label'=>'Override Price')); ?>
-
- - -
+ +
-
+
diff --git a/modules/service/views/service/info.php b/modules/service/views/service/info.php index a7b4b38d..344f37ad 100644 --- a/modules/service/views/service/info.php +++ b/modules/service/views/service/info.php @@ -1,46 +1,44 @@ -
-
- Service Information +
+ Service Information -
-
Account
-
account->name(),$o->account->accnum()); ?>
+
+
Account
+
account->name(),$o->account->accnum()); ?>
- external_billing) : ?> -
External Billed
-
display('external_billing'); ?>
- - -
Service Active
-
display('status'); ?>
+ external_billing) : ?> +
External Billed
+
display('external_billing'); ?>
-
Billing Period
-
display('recur_schedule');?>
+ +
Service Active
+
display('status'); ?>
-
Cost
-
price_override) ? sprintf('%s ',$o->price(TRUE,TRUE,TRUE)) : ''). $o->price(TRUE,TRUE); if ($o->pending_change()) echo ' *'; ?>
+
Billing Period
+
display('recur_schedule');?>
+ +
Cost
+
price_override) ? sprintf('%s ',$o->price(TRUE,TRUE,TRUE)) : ''). $o->price(TRUE,TRUE); if ($o->pending_change()) echo ' *'; ?>
- price) OR ($o->price<=$o->product->price($o->price_group,$o->recur_schedule,'base'))) : ?> -
Service
-
product_id,$o->product->title()); ?>
- - -
Invoiced To
-
invoiced_to(TRUE); ?>
- -
Paid To
-
paid_to(TRUE); ?>
- -
Date Next Invoice
-
suspend_billing ? '%s' : '%s',$o->display('date_next_invoice')); ?>
- -
Current Invoices Due
-
due(TRUE); ?>
+ price) OR ($o->price<=$o->product->price($o->price_group,$o->recur_schedule,'base'))) : ?> +
Service
+
product_id,$o->product->title()); ?>
-
-
- product->feature_summary(); ?> -
+
Invoiced To
+
invoiced_to(TRUE); ?>
+ +
Paid To
+
paid_to(TRUE); ?>
+ +
Date Next Invoice
+
suspend_billing ? '%s' : '%s',$o->display('date_next_invoice')); ?>
+ +
Current Invoices Due
+
due(TRUE); ?>
+ + + + +product->feature_summary(); ?> diff --git a/modules/service/views/service/user/invoice/list.php b/modules/service/views/service/user/invoice/list.php new file mode 100644 index 00000000..0644096d --- /dev/null +++ b/modules/service/views/service/user/invoice/list.php @@ -0,0 +1,18 @@ + +
+ Invoices for this Service + + data($o->invoice_list(FALSE,20)) + ->columns(array( + 'id'=>'ID', + 'void'=>'Void', + 'date_orig'=>'Date', + 'due_date'=>'Due', + 'total(TRUE)'=>'Amount', + 'due(TRUE)'=>'Due', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('user','invoice/view/')), + )); ?> +
diff --git a/modules/service/views/service/user/invoice/next.php b/modules/service/views/service/user/invoice/next.php new file mode 100644 index 00000000..2d95af65 --- /dev/null +++ b/modules/service/views/service/user/invoice/next.php @@ -0,0 +1,6 @@ + +
+ Next Invoice Charges + + add_service($o)->render('html','body',array('noid'=>TRUE)); ?> +
diff --git a/modules/service/views/service/user/view.php b/modules/service/views/service/user/view.php index 048bb1e9..64b49fad 100644 --- a/modules/service/views/service/user/view.php +++ b/modules/service/views/service/user/view.php @@ -1,104 +1,39 @@ -set('o',$o); ?> -service_view(); ?> +
+set('o',$o); -service_billing->loaded()) : ?> -
-
- Automatic Payment Details + if ($o->status AND ! $o->external_billing) : + echo View::factory('service/user/invoice/next')->set('o',$o); + endif; -
-
Direct Payment
-
service_billing->checkout->display('name'); ?>
- service_billing->checkout_amount)) : ?> -
Standard Amount
-
service_billing->display('checkout_amount'); ?>
- -
-
-
- + if ($o->service_billing->loaded()) : + echo View::factory('service/user/view/payment')->set('o',$o); + endif; +?> +
+ +
+ service_view(); ?> +
+ +
+ set('o',$o); ?> +
charges()) : ?> -
-
- Service Charges to Bill: charges(TRUE,TRUE); ?> - - data($o->charge_list(TRUE)) - ->columns(array( - 'date_orig'=>'Date', - 'description'=>'Description', - 'total(TRUE)'=>'Amount', - )); ?> -
-
+
+ set('o',$o); ?> +
-status AND ! $o->external_billing) : ?> -
-
- Next Invoice Charges - - add_service($o)->render('html','body',array('noid'=>TRUE)); ?> -
-
- - -
-
- Invoices for this Service - - data($o->invoice_list()) - ->columns(array( - 'id'=>'ID', - 'void'=>'Void', - 'date_orig'=>'Date', - 'due_date'=>'Due', - 'total(TRUE)'=>'Amount', - 'due(TRUE)'=>'Due', - )) - ->prepend(array( - 'id'=>array('url'=>URL::link('user','invoice/view/')), - )); ?> -
-
- service_memo->find_all(); if ($x->count()) : ?> -
-
- Service Memos - - data($x) - ->columns(array( - 'id'=>'ID', - 'date_orig'=>'Date', - 'account->name()'=>'Account', - 'memo'=>'Memo', - )); ?> -
-
+
+ set('o',$o); ?> +
email()->find_all(); if ($x->count()) : ?> -
-
- Emails about this service - - data($x) - ->columns(array( - 'id'=>'ID', - 'date_orig'=>'Date', - 'resolve("subject")'=>'Subject', - )) - ->prepend(array( - 'id'=>array('url'=>URL::link('user','email/view/')), - )) - ->postproc(array( - 'resolve("subject")'=>array('trim'=>45), - )); ?> -
-
+
+ set('o',$o); ?> +
diff --git a/modules/service/views/service/user/view/charges.php b/modules/service/views/service/user/view/charges.php new file mode 100644 index 00000000..15952d54 --- /dev/null +++ b/modules/service/views/service/user/view/charges.php @@ -0,0 +1,12 @@ + +
+ Service Charges to Bill: charges(TRUE,TRUE); ?> + + data($o->charge_list(TRUE)) + ->columns(array( + 'date_orig'=>'Date', + 'description'=>'Description', + 'total(TRUE)'=>'Amount', + )); ?> +
diff --git a/modules/service/views/service/user/view/emails.php b/modules/service/views/service/user/view/emails.php new file mode 100644 index 00000000..1234ae3e --- /dev/null +++ b/modules/service/views/service/user/view/emails.php @@ -0,0 +1,17 @@ +
+ Emails about this service + + data($o->email()->limit(20)->find_all()) + ->columns(array( + 'id'=>'ID', + 'date_orig'=>'Date', + 'resolve("subject")'=>'Subject', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('user','email/view/')), + )) + ->postproc(array( + 'resolve("subject")'=>array('trim'=>45), + )); ?> +
diff --git a/modules/service/views/service/user/view/memos.php b/modules/service/views/service/user/view/memos.php new file mode 100644 index 00000000..382401d3 --- /dev/null +++ b/modules/service/views/service/user/view/memos.php @@ -0,0 +1,13 @@ + +
+ Service Memos + + data($o->service_memo->find_all()) + ->columns(array( + 'id'=>'ID', + 'date_orig'=>'Date', + 'account->name()'=>'Account', + 'memo'=>'Memo', + )); ?> +
diff --git a/modules/service/views/service/user/view/payment.php b/modules/service/views/service/user/view/payment.php new file mode 100644 index 00000000..93f17841 --- /dev/null +++ b/modules/service/views/service/user/view/payment.php @@ -0,0 +1,13 @@ + +
+ Automatic Payment Details + +
+
Direct Payment
+
service_billing->checkout->display('name'); ?>
+ service_billing->checkout_amount)) : ?> +
Standard Amount
+
service_billing->display('checkout_amount'); ?>
+ +
+
diff --git a/modules/ssl/classes/Controller/Reseller/Service/Ssl.php b/modules/ssl/classes/Controller/Reseller/Service/Ssl.php index 64da60a7..2553d8d6 100644 --- a/modules/ssl/classes/Controller/Reseller/Service/Ssl.php +++ b/modules/ssl/classes/Controller/Reseller/Service/Ssl.php @@ -10,6 +10,8 @@ * @license http://dev.osbill.net/license.html */ class Controller_Reseller_Service_Ssl extends Controller_Service { + protected $auth_required = TRUE; + protected $secure_actions = array( 'list'=>TRUE, ); diff --git a/modules/ssl/classes/Controller/Reseller/Ssl.php b/modules/ssl/classes/Controller/Reseller/Ssl.php index ca5f4939..f8693f2e 100644 --- a/modules/ssl/classes/Controller/Reseller/Ssl.php +++ b/modules/ssl/classes/Controller/Reseller/Ssl.php @@ -10,6 +10,8 @@ * @license http://dev.osbill.net/license.html */ class Controller_Reseller_SSL extends Controller_SSL { + protected $auth_required = TRUE; + protected $secure_actions = array( 'add'=>TRUE, 'edit'=>TRUE, diff --git a/modules/ssl/classes/Controller/SSL.php b/modules/ssl/classes/Controller/SSL.php deleted file mode 100644 index 6d5a8138..00000000 --- a/modules/ssl/classes/Controller/SSL.php +++ /dev/null @@ -1,14 +0,0 @@ - diff --git a/modules/ssl/classes/Controller/Ssl.php b/modules/ssl/classes/Controller/Ssl.php new file mode 100644 index 00000000..7ffb994a --- /dev/null +++ b/modules/ssl/classes/Controller/Ssl.php @@ -0,0 +1,64 @@ +request->param('id')); + + $this->response->body($o->loaded() ? $o->sign_cert."\n" : NULL); + + $this->response->headers(array('Content-Type' => 'text/plain')); + if ($o->loaded() AND ! is_null($this->request->query('download'))) + $this->response->headers('Content-Disposition','attachment; filename="'.$o->id.'.ca.crt"'); + $this->auto_render = FALSE; + } + + /** + * Render the public certificate of a service + */ + public function action_cert() { + $o = ORM::factory('Service',$this->request->param('id')); + + if ($o->loaded() and ($o->plugin() instanceof Model_Service_Plugin)) + $this->response->body($o->plugin()->cert."\n"); + + $this->response->headers(array('Content-Type' => 'text/plain')); + if ($o->loaded() AND ! is_null($this->request->query('download'))) + $this->response->headers('Content-Disposition','attachment; filename="'.$o->id.'.crt"'); + $this->auto_render = FALSE; + } + + /** + * Render out an SSL CA chain + */ + public function action_chain() { + $result = ''; + + $o = ORM::factory('Service',$this->request->param('id')); + + if ($o->loaded() and $o->plugin() instanceof Model_Service_Plugin_Ssl) { + foreach ($o->plugin()->chain() as $cao) + $result .= $cao->sign_cert."\n"; + } + + $this->response->body($result); + $this->response->headers(array('Content-Type' => 'text/plain')); + if ($o->loaded() AND ! is_null($this->request->query('download'))) + $this->response->headers('Content-Disposition','attachment; filename="ca.crts"'); + $this->auto_render = FALSE; + } +} +?> diff --git a/modules/ssl/classes/Controller/User/Ssl.php b/modules/ssl/classes/Controller/User/Ssl.php index 9bd4d2b6..6afde677 100644 --- a/modules/ssl/classes/Controller/User/Ssl.php +++ b/modules/ssl/classes/Controller/User/Ssl.php @@ -9,9 +9,12 @@ * @copyright (c) 2009-2013 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Controller_User_SSL extends Controller_SSL { +class Controller_User_Ssl extends Controller_Ssl { + protected $auth_required = TRUE; + protected $secure_actions = array( - 'download'=>FALSE, + 'download'=>TRUE, + 'key'=>TRUE, ); public function action_download() { @@ -22,7 +25,7 @@ class Controller_User_SSL extends Controller_SSL { $passwd = $this->request->post('passwd'); - if (strlen($passwd) < Kohana::$config->load('ssl')->minpass_length) { + if (! Auth::instance()->get_user()->isAdmin() AND strlen($passwd) < Kohana::$config->load('ssl')->minpass_length) { SystemMessage::add(array( 'title'=>_('Validation failed'), 'type'=>'error', @@ -50,5 +53,23 @@ class Controller_User_SSL extends Controller_SSL { $this->response->headers('Content-Disposition','attachment; filename="'.basename($file).'"'); $this->response->body($x); } + + /** + * Render the private key of a service + */ + public function action_key() { + $so = ORM::factory('Service',$this->request->param('id')); + + if (! $so->loaded() OR ! Auth::instance()->authorised($so->account)) + throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it'); + + if ($so->plugin() instanceof Model_Service_Plugin) + $this->response->body($so->plugin()->pk."\n"); + + $this->response->headers(array('Content-Type' => 'text/plain')); + if ($so->loaded() AND ! is_null($this->request->query('download'))) + $this->response->headers('Content-Disposition','attachment; filename="'.$so->id.'.key"'); + $this->auto_render = FALSE; + } } ?> diff --git a/modules/ssl/classes/Model/Service/Plugin/Ssl.php b/modules/ssl/classes/Model/Service/Plugin/Ssl.php index 28cd78be..e18d5f12 100644 --- a/modules/ssl/classes/Model/Service/Plugin/Ssl.php +++ b/modules/ssl/classes/Model/Service/Plugin/Ssl.php @@ -86,6 +86,7 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin { /** * Return all our CA Certs for this certificate + * @deprecated Use chain() instead. */ public function cacerts() { $result = array(); @@ -100,15 +101,34 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin { return $result; } + /** + * Return the Certificate Chain + * + * @return array Of SSL_CA Objects representing the Chain + */ + public function chain() { + $result = array(); + + // Get the first parent CA certificate + $po = $this->ca; + + while ($po AND $po->loaded()) { + array_push($result,$po); + $po = ($po->validParent()) ? $po->parent : NULL; + } + + return $result; + } + public function download_button() { - if (! $this->service->status OR ! preg_match('/client/',$this->service->product->plugin()->extensions) OR $this->valid_to() < time()) + if (! $this->pk OR ! $this->service->status OR ! preg_match('/client/',$this->service->product->plugin()->extensions) OR $this->valid_to() < time()) return ''; $output = Form::open(URL::link('user','ssl/download'),array('class'=>'form-inline')); $output .= Form::hidden('sid',$this->service->id); $output .= '
'; $output .= Form::password('passwd','',array('placeholder'=>_('Choose a password'),'required','nocg'=>TRUE,'pattern'=>'.{6,}','title'=>'Minimum 6 chars')); - $output .= Form::button('download','Download',array('class'=>'btn btn-default','nocg'=>TRUE)); + $output .= Form::button('download','PKCS12',array('class'=>'btn btn-default','nocg'=>TRUE)); $output .= '
'; $output .= Form::close(); diff --git a/modules/ssl/classes/SSL.php b/modules/ssl/classes/SSL.php index 5c0c56cf..41bf218a 100644 --- a/modules/ssl/classes/SSL.php +++ b/modules/ssl/classes/SSL.php @@ -108,7 +108,7 @@ class SSL { if ($i++) $result .= ','; - $result .= sprintf('%s=%s',$k,$v); + $result .= sprintf('%s=%s',$k,(is_array($v) ? join(','.$k.'=',$v) : $v)); } return $result; diff --git a/modules/ssl/views/service/admin/plugin/ssl/edit.php b/modules/ssl/views/service/admin/plugin/ssl/edit.php index 74c6000d..bff575f9 100644 --- a/modules/ssl/views/service/admin/plugin/ssl/edit.php +++ b/modules/ssl/views/service/admin/plugin/ssl/edit.php @@ -1,15 +1,7 @@
SSL Certificate Service Details -
- service->plugin()->csr,array('class'=>'span6','label'=>'CSR','placeholder'=>'CSR','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->csr))); ?> -
- -
- service->plugin()->pk,array('class'=>'span6','label'=>'Private Key','placeholder'=>'Private Key','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->pk))); ?> -
- -
- service->plugin()->cert,array('class'=>'span6','label'=>'Public Certificate','placeholder'=>'Public Certificate','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->cert))); ?> -
+ service->plugin()->csr,array('label'=>'CSR','placeholder'=>'CSR','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->csr),'cols'=>Form::textarea_width($o->service->plugin()->csr))); ?> + service->plugin()->pk,array('label'=>'Private Key','placeholder'=>'Private Key','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->pk),'cols'=>Form::textarea_width($o->service->plugin()->pk))); ?> + service->plugin()->cert,array('label'=>'Public Certificate','placeholder'=>'Public Certificate','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->cert),'cols'=>Form::textarea_width($o->service->plugin()->cert))); ?>
diff --git a/modules/ssl/views/service/user/plugin/ssl/view.php b/modules/ssl/views/service/user/plugin/ssl/view.php index 2281f73e..539c8601 100644 --- a/modules/ssl/views/service/user/plugin/ssl/view.php +++ b/modules/ssl/views/service/user/plugin/ssl/view.php @@ -1,62 +1,3 @@ -
-
- Service Details - -
-
DN
-
dn(); ?>
- - isCSR()) : ?> -
Serial Number
-
serial(); ?>
- -
Subject Key Id
-
ski(); ?>
- -
Issuer
-
- validCA() AND $o->authorised($o->ca)) : ?> - ca->id,$o->issuer()); ?> - - issuer(); ?> - -
- -
Issuer Serial
-
aki_keyid(), $o->aki_serial()); ?>
- -
Valid From
-
valid_from(TRUE); ?>
- -
Valid To
-
valid_to(TRUE); ?>
- -
Hash
-
hash(); ?>
- -
Version
-
version(); ?>
- -
Algorithm
-
algorithm(); ?>
- - -
-
-
- -
-
- Certificate - -
cert; ?>
- - download_button(); - if ($ao=Auth::instance()->get_user() AND ($ao->isAdmin() OR $ao->isReseller()) AND $o->service->status AND ($o->valid_to()-(Kohana::$config->load('ssl.min_renew_days')*86400) <= time()) AND $o->service->paid_to() > time()) : - echo Form::open(URL::link('reseller','ssl/renew/'.$o->service->id)); - echo Form::button('submit','Renew',array('class'=>'btn btn-primary')); - endif - ?> -
-
+set('o',$o); ?> +set('o',$o); ?> +set('o',$o); ?> diff --git a/modules/ssl/views/service/user/plugin/ssl/view/certificate.php b/modules/ssl/views/service/user/plugin/ssl/view/certificate.php new file mode 100644 index 00000000..7f56468a --- /dev/null +++ b/modules/ssl/views/service/user/plugin/ssl/view/certificate.php @@ -0,0 +1,18 @@ +
+ Certificate + +
cert; ?>
+ + download_button(); + if ($ao=Auth::instance()->get_user() AND ($ao->isAdmin() OR $ao->isReseller()) AND $o->service->status AND ($o->valid_to()-(Kohana::$config->load('ssl.min_renew_days')*86400) <= time()) AND $o->service->paid_to() > time()) : + echo Form::open(URL::link('reseller','ssl/renew/'.$o->service->id)); + echo Form::button('submit','Renew',array('class'=>'btn btn-primary','nocg'=>TRUE)); + else : ?> + Cert Download + pk) : ?> + Key Download + + +
diff --git a/modules/ssl/views/service/user/plugin/ssl/view/chain.php b/modules/ssl/views/service/user/plugin/ssl/view/chain.php new file mode 100644 index 00000000..b64a867f --- /dev/null +++ b/modules/ssl/views/service/user/plugin/ssl/view/chain.php @@ -0,0 +1,20 @@ +cert) : ?> +
+ Certificate Chain + + data($o->chain()) + ->columns(array( + 'id'=>'ID', + 'subject()'=>'Cert', + 'valid_to(TRUE)'=>'Expires', + 'issuer()'=>'Issuer', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('','/ssl/ca/')), + )); ?> + + Download +
+ + diff --git a/modules/ssl/views/service/user/plugin/ssl/view/details.php b/modules/ssl/views/service/user/plugin/ssl/view/details.php new file mode 100644 index 00000000..97200713 --- /dev/null +++ b/modules/ssl/views/service/user/plugin/ssl/view/details.php @@ -0,0 +1,44 @@ +
+ Service Details + +
+
DN
+
dn(); ?>
+ + isCSR()) : ?> +
Serial Number
+
serial(); ?>
+ +
Subject Key Id
+
ski(); ?>
+ +
Issuer
+
+ validCA() AND $o->authorised($o->ca)) : ?> + ca->id,$o->issuer()); ?> + + issuer(); ?> + +
+ +
Issuer Serial
+
aki_keyid(), $o->aki_serial()); ?>
+ +
Valid From
+
valid_from(TRUE); ?>
+ +
Valid To
+
valid_to(TRUE); ?>
+ +
Hash
+
hash(); ?>
+ +
Version
+
version(); ?>
+ +
Algorithm
+
algorithm(); ?>
+ + +
+