Skip to content

Commit b7710ee

Browse files
[php][js] ssl uploading
1 parent ff84992 commit b7710ee

File tree

3 files changed

+50
-101
lines changed

3 files changed

+50
-101
lines changed

web/js/html.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,20 @@ App.HTML.Build.web_domain_form = function (options, id) {
146146
tpl.set(':title', 'Edit WEB domain');
147147
tpl.set(':save_button', 'SAVE');
148148
tpl.set(':DELETE_ACTION', App.Templates.get('DELETE_ACTION', 'general').finalize());
149-
if (options.SSL == 'yes') {
149+
if (options.SSL == 'on') {
150150
tpl.set(':ssl_checked', 'checked="checked"');
151151
}
152152
else {
153153
tpl.set(':ssl_checked', '');
154154
}
155+
if (options.SSL_HOME == 'on') {
156+
tpl.set(':ssl_home_checked', 'checked="checked"');
157+
}
158+
else{
159+
tpl.set(':ssl_home_checked', '');
160+
}
155161
}
162+
156163
options = !App.Helpers.isEmpty(options) ? options : App.Empty.WEB_DOMAIN;
157164
if (in_edit == true) {
158165
options.STATS_PASSWORD = options.STATS_LOGIN.trim() != '' ? App.Settings.PASSWORD_IMMUTE : '';
@@ -176,6 +183,25 @@ App.HTML.Build.web_domain_form = function (options, id) {
176183
tpl.set(':ACTIVE_PASSWORD', 'hidden');
177184
tpl.set(':stats_auth_checked', '');
178185
}
186+
187+
if (options.SSL == 'on') {
188+
tpl.set(':ssl_checked', 'checked="checked"');
189+
if (options.SSL_HOME == 'on') {
190+
tpl.set(':ssl_home_checked', 'checked="checked"');
191+
}
192+
else{
193+
tpl.set(':ssl_home_checked', '');
194+
}
195+
}
196+
else {
197+
tpl.set(':ssl_checked', '');
198+
tpl.set(':ssl_home_checked', '');
199+
tpl.set(':SSL_HOME', '');
200+
tpl.set(':SSL_CRT', '');
201+
tpl.set(':SSL_KEY', '');
202+
tpl.set(':SSL_CA', '');
203+
}
204+
179205
return tpl.finalize();
180206
}
181207

web/js/templates.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ App.Templates.html = {
669669
<input type="checkbox" name="SSL" class="styled do_action_toggle_ssl_support ssl_support" ~!:ssl_checked~! value="~!SSL~!">\
670670
</div>\
671671
<div class="form-row cc ssl-crtfct-box">\
672-
<label for="#" class="field-label">SSL Document Root:</label>\
673-
<input type="text" name="SSL_HOME" class="text-field" value="~!:SSL_HOME~!">\
672+
<label for="#" class="field-label">SSL Shared DocRoot:</label>\
673+
<input type="checkbox" name="SSL_HOME" class="styled" ~!:ssl_home_checked~! value="~!SSL_HOME~!">\
674674
</div>\
675675
<div class="form-row ssl-crtfct-box cc">\
676676
<label for="#" class="field-label">SSL Crtificate: <span class="remark">(upload file or paste as text)</span></label>\

web/vesta/api/WEB_DOMAIN.class.php

Lines changed: 21 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function getListExecute(Request $request)
3636
'ELOG' => $record['ELOG'],
3737
'STAT' => $record['STATS'],
3838
'STATS_LOGIN' => $record['STATS_AUTH'],
39-
'SSL' => $record['SSL'],
40-
'SSL_HOME' => $record['SSL_HOME'],
39+
'SSL' => $record['SSL'] == 'yes' ? 'on' : 'off',
40+
'SSL_HOME' => $record['SSL_HOME'] == 'tsingle' ? 'off' : 'on',
4141
'SSL_CRT' => '',
4242
'SSL_KEY' => '',
4343
'SSL_CA' => '',
@@ -170,29 +170,10 @@ public function addExecute(Request $request)
170170
}
171171
}
172172

173-
/* if ($_s['SSL']) {
174-
$params = array(
175-
'USER' => $user['uid'],
176-
'DOMAIN' => $_s['DOMAIN'],
177-
'SSL_CERT' => $_s['SSL_CERT']
178-
);
179-
180-
if ($_s['SSL_HOME']) {
181-
$params['SSL_HOME'] = $_s['SSL_HOME'];
182-
}
183-
184-
$result = 0;
185-
$result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSL, $params);
186-
187-
if (!$result['status']) {
188-
$this->errors['SSL'] = array($result['error_code'] => $result['error_message']);
189-
}
190-
}
191-
if ($_s['SSL_HOME']) {
192-
193-
}*/
194-
195-
/*if (!empty($_s['DNS'])) {
173+
if (($_s['DNS_DOMAIN']) == 'on') {
174+
echo 'adding dns domain';
175+
echo '<br>';
176+
196177
$params = array(
197178
'USER' => $user['uid'],
198179
'DNS_DOMAIN' => $_s['DOMAIN'],
@@ -207,7 +188,7 @@ public function addExecute(Request $request)
207188
if (!$result['status']) {
208189
$this->errors['DNS_DOMAIN'] = array($result['error_code'] => $result['error_message']);
209190
}
210-
}*/
191+
}
211192

212193

213194
/*if (!empty($_s['MAIL'])) {
@@ -277,11 +258,15 @@ public function changeExecute(Request $request)
277258
$_old['ELOG'] = $_old['ELOG'] == 'yes' ? 'on' : 'off';
278259
$_old['CGI'] = $_old['CGI'] == 'yes' ? 'on' : 'off';
279260
$_old['AUTH'] = $_old['AUTH'] == 'yes' ? 'on' : 'off';
280-
$_old['SSL'] = $_old['SSL'] == 'yes' ? 'on' : 'off';
261+
// $_old['SSL'] = $_old['SSL'] == 'yes' ? 'on' : 'off';
262+
// $_new['SSL'] = $_new['SSL'] == 'yes' ? 'on' : 'off';
263+
// $_new['SSL_HOME'] = $_new['SSL_HOME'] == 'no' ? 'shared' : 'single';
281264

282265
$user = $this->getLoggedUser();
283266
$_DOMAIN = $_new['DOMAIN'];
284267

268+
$result['status'] = TRUE;
269+
285270
if ($_old['SUSPEND'] != $_new['SUSPEND']) {
286271
if ($_new['SUSPEND'] == 'on') {
287272
$result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
@@ -451,113 +436,51 @@ public function changeExecute(Request $request)
451436
}
452437
}
453438

454-
/*
455-
if (!empty($_s['SSL_KEY'])) {
456-
$ssl_file = tempnam(sys_get_temp_dir(), 'ssl');
457-
file_put_contents($ssl_file, $_s['SSL_KEY']);
458-
459-
$params = array(
460-
'USER' => $user['uid'],
461-
'DOMAIN' => $_s['DOMAIN'],
462-
'SSL_KEY' => $ssl_file
463-
);
464-
465-
if (!empty($_s['SSL_HOME'])) {
466-
$params['SSL_HOME'] = $_s['SSL_HOME'];
467-
}
468-
469-
$result = 0;
470-
$result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSL, $params);
471-
472-
if (!$result['status']) {
473-
$this->errors['SSL'] = array($result['error_code'] => $result['error_message']);
474-
}
475-
}
476-
477-
478-
if (!empty($_s['SSL_CERT'])) {
479-
$sslcert_file = tempnam(sys_get_temp_dir(), 'ssl');
480-
file_put_contents($sslcert_file, $_s['SSL_CERT']);
481-
482-
$params = array(
483-
'USER' => $user['uid'],
484-
'DOMAIN' => $_s['DOMAIN'],
485-
'SSL_CERT' => $sslcert_file
486-
);
487-
488-
$result = 0;
489-
$result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSLCERT, $params);
490-
491-
if (!$result['status']) {
492-
$this->errors['SSL_CERT'] = array($result['error_code'] => $result['error_message']);
493-
}
494-
}
495-
*/
496439

497-
498-
if (!empty($_new['SSL_KEY']) && !empty($_new['SSL_CRT'])) {
499-
// $ssl_dir = sys_get_temp_dir().'/ssl/'.rand();
440+
if (( !empty($_new['SSL_KEY']) && !empty($_new['SSL_CRT']) && $_new['SSL'] == 'on') || $_old['SSL_HOME'] != $_new['SSL_HOME']) {
500441
$ssl_dir = sys_get_temp_dir().'/';
501-
// if(!mkdir($ssl_dir)){
502-
// return $this->reply(FALSE, array('error' => 'can\'t create temp ssl dir: '.$ssl_dir));
503-
// }
504-
505-
506442

507443
$ssl_crt_file = $ssl_dir . $_new['DOMAIN'] . '.crt';
508-
if(!file_put_contents($ssl_crt_file, $_new['SSL_CRT']))
444+
file_put_contents($ssl_crt_file, $_new['SSL_CRT']);
509445

510446
$ssl_key_file = $ssl_dir . $_new['DOMAIN'] . '.key';
511447
file_put_contents($ssl_key_file, $_new['SSL_KEY']);
512448

513449
if (!empty($_new['SSL_CA'])) {
514450
$ssl_ca_file = $ssl_dir . $_new['DOMAIN'] . '.ca';
515-
// file_put_contents($ssl_ca_file, $_new['SSL_CA']);
451+
file_put_contents($ssl_ca_file, $_new['SSL_CA']);
516452
}
517453

518-
519-
// echo '<br>';
520-
// echo $ssl_crt_file;
521-
// echo '<br>';
522-
// echo $ssl_key_file;
523-
// echo '<br>';
524-
// echo $ssl_ca_file;
525-
526454
$params = array(
527455
'USER' => $user['uid'],
528456
'DOMAIN' => $_DOMAIN,
529-
'SSL_DIR' => $ssl_dir
530-
// 'SSL_DIR' => 'tmp'
457+
'SSL_DIR' => $ssl_dir,
458+
'SSL_HOME' => $_new['SSL_HOME'] == 'on' ? 'shared' : 'single'
531459
);
532460

533-
// if (!empty($_s['SSL_HOME'])) {
534-
// $params['SSL_HOME'] = $_s['SSL_HOME'];
535-
// }
536-
537461
$result = 0;
538-
539462
if($_old['SSL'] == 'on'){
540463
$result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_SSL, $params);
541464
}
542465
else{
543466
$result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSL, $params);
544467
}
545468

546-
// print_r($result);
547-
548469
if (!$result['status']) {
549470
$this->errors['SSL'] = array($result['error_code'] => $result['error_message']);
550471
}
551472

552473
unlink($ssl_crt_file);
553474
unlink($ssl_key_file);
554475
unlink($ssl_ca_file);
555-
556476
}
557477

558-
if (empty($_new['SSL_KEY']) && empty($_new['SSL_CRT']) && $_old['SSL'] == 'on') {
478+
if ( ((empty($_new['SSL_KEY']) || empty($_new['SSL_CRT'])) && $_old['SSL'] == 'on') || ( $_old['SSL'] == 'on' && $_new['SSL'] == 'off') ){
559479
$result = 0;
560480
$result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_SSL, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
481+
if (!$result['status']) {
482+
$this->errors['SSL_REMOVING'] = array($result['error_code'] => $result['error_message']);
483+
}
561484
}
562485

563486
return $this->reply($result['status'], $result['data']);

0 commit comments

Comments
 (0)