Skip to content

Commit b13c07c

Browse files
committed
Log in as user / Logout to real user.
1 parent 29772cb commit b13c07c

File tree

6 files changed

+111
-32
lines changed

6 files changed

+111
-32
lines changed

web/js/__init__.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ $('document').ready(function() {
1111
App.Utils.detectBrowser();
1212
App.Ref.init();
1313

14-
//App.Env.world = 'USER';
14+
App.Env.world = 'USER';
1515
// Disabled cookie tab restoring. Enable if needed
16-
if ('undefined' != typeof App.Tmp.loadTAB) {
16+
/*if ('undefined' != typeof App.Tmp.loadTAB) {
1717
App.Env.world = App.Tmp.loadTAB;
1818
}
1919
@@ -25,7 +25,7 @@ $('document').ready(function() {
2525
else {
2626
App.Env.world = App.Constants.TABS[0];
2727
}
28-
}
28+
}*/
2929

3030
App.Pages.init();
3131
App.Core.listen();

web/js/actions.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
App.Actions.login_as = function(evt)
2+
{
3+
var elm = $(evt.target);
4+
var ref = elm.parents('.row');
5+
var source = App.Helpers.evalJSON($(ref).find('.source').val())
6+
App.Ajax.request('USER.loginAs', {'user': source.LOGIN_NAME}, function(reply) {
7+
if (reply.result) {
8+
location.href = "";
9+
}
10+
else {
11+
App.Helpers.alert('You cannot do this action. Please contact support');
12+
}
13+
});
14+
}
15+
116
App.Actions.toggle_suspend = function(evt)
217
{
318
var elm = $(evt.target);
@@ -156,6 +171,19 @@ App.Actions.change_password = function(evt)
156171
App.Actions.profile_exit = function(evt)
157172
{
158173
evt.preventDefault();
174+
if (App.Env.initialParams.real_user) { // exit "logged in as" state
175+
App.Ajax.request('USER.logoutAs', {}, function(reply) {
176+
if (reply.result) {
177+
location.href = "";
178+
}
179+
else {
180+
App.Helpers.alert('You cannot do this action. Please contact support');
181+
}
182+
});
183+
return;
184+
}
185+
186+
159187
App.Ajax.request('MAIN.logoff', {}, function(reply) {
160188
location.href = '';
161189
});

web/js/helpers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ App.Helpers.updateInitial = function()
134134
});
135135
$('#user-name').html(App.Env.initialParams.PROFILE.uid);
136136
$('#page').removeClass('hidden');
137+
138+
if (App.Env.initialParams.real_user) {
139+
var tpl = App.Templates.get('logged_as', 'general');
140+
tpl.set(':YOU_ARE', App.Env.initialParams.real_user);
141+
tpl.set(':USER', App.Env.initialParams.auth_user.uid.uid);
142+
$('body').prepend(tpl.finalize());
143+
}
137144
}
138145

139146
App.Helpers.beforeAjax = function(jedi_method)

web/js/templates.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ App.Templates.html = {
1616
"Well," the farmer said, "I didn\'t have anymore rope, so I took off my belt and tied her tail to the rafter. In that moment, my pants fell down and my wife walked in ... Some things you just can\'t explain."']
1717
},
1818
general: {
19-
over_bar: ['<span style="width:~!:OVER_PERCENTS~!%;right:-~!:OVER_PERCENTS_2~!%;" class="bar_overdraft"></span>'],
19+
logged_as: ['<div id="logged-in-as">You (<i>~!:YOU_ARE~!</i>) are viewing <strong style="font-weight: bold; color: #2A8FBD;">~!:USER~!</strong> interface. Exit it to return to your own.</div>'],
20+
over_bar: ['<span style="width:~!:OVER_PERCENTS~!%;right:-~!:OVER_PERCENTS_2~!%;" class="bar_overdraft"></span>'],
2021
loading: ['<div id="loading" style="border-radius: 0 0 6px 6px;top: 0;font-size:19px;font-weight: bol;position:fixed;width: 150px; background-color:#6E6E62;z-index: 9999; padding: 8px;left: 50%;margin-left:-75px;">\
2122
<center><div style="width: 105px; height:30px;background-image: url(\'../images/loading.png\');"></center>\
2223
</div>'],
@@ -397,13 +398,13 @@ App.Templates.html = {
397398
</div>\
398399
<div class="form-row cc">\
399400
<label for="#" class="field-label">Package:</label>\
400-
<select name="PACKAGE" class="styled">\
401+
<select name="PACKAGE" class="styled disabled" >\
401402
~!:PACKAGE_OPTIONS~!\
402403
</select>\
403404
</div>\
404405
<div class="form-row cc">\
405406
<label for="#" class="field-label">Shell:</label>\
406-
<select class="styled" name="SHELL">\
407+
<select class="styled disabled" name="SHELL">\
407408
~!:SHELL_OPTIONS~!\
408409
</select>\
409410
</div>\
@@ -474,6 +475,9 @@ App.Templates.html = {
474475
</span>\
475476
</div>\
476477
<div class="user-details-box">\
478+
<span class="prop-box prop-box_group-values cc user-details do_action_login_as">\
479+
<span class="prop-value login-as do_action_login_as">login as</span>\
480+
</span>\
477481
<span class="prop-box user-name">\
478482
<span class="prop-title">name:</span>\
479483
<span class="prop-value">~!:FULLNAME~!</span>\

web/vesta/api/MAIN.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ public function getInitialExecute(Request $request)
227227
'DB' => $this->getDbParams($data_db),
228228
'USERS' => $this->getUsersParams($data_user),
229229
'totals' => $totals,
230-
'PROFILE' => $user
230+
'PROFILE' => $user,
231+
'real_user' => $_SESSION['real_user'] ? $_SESSION['real_user'] : NULL
231232
);
232233

233234
return $this->reply(true, $reply);

web/vesta/api/WEB_DOMAIN.class.php

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function addExecute(Request $request)
158158
}
159159
}
160160

161-
/* if ($_s['SSL']) {
161+
/* if ($_s['SSL']) {
162162
$params = array(
163163
'USER' => $user['uid'],
164164
'DOMAIN' => $_s['DOMAIN'],
@@ -178,7 +178,7 @@ public function addExecute(Request $request)
178178
}
179179
if ($_s['SSL_HOME']) {
180180
181-
}*/
181+
}*/
182182

183183
/*if (!empty($_s['DNS'])) {
184184
$params = array(
@@ -194,7 +194,7 @@ public function addExecute(Request $request)
194194
$result = $dns->addExecute($params);
195195
if (!$result['status']) {
196196
$this->errors['DNS_DOMAIN'] = array($result['error_code'] => $result['error_message']);
197-
}
197+
}
198198
}*/
199199

200200

@@ -264,25 +264,42 @@ public function changeExecute(Request $request)
264264

265265
$_old['ELOG'] = $_old['ELOG'] == 'yes' ? 'on' : 'off';
266266
$_old['CGI'] = $_old['CGI'] == 'yes' ? 'on' : 'off';
267-
$_old['AUTH'] = $_old['AUTH'] == 'yes' ? 'on' : 'off';
267+
$_old['AUTH'] = $_old['AUTH'] == 'yes' ? 'on' : 'off';
268268
$_old['SSL'] = $_old['SSL'] == 'yes' ? 'on' : 'off';
269269

270270
$user = $this->getLoggedUser();
271271
$_DOMAIN = $_new['DOMAIN'];
272272

273-
if ($_new['SUSPEND'] == 'on') {
274-
$result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
275-
if (!$result['status']) {
276-
$this->status = FALSE;
277-
$this->errors['SUSPEND'] = array($result['error_code'] => $result['error_message']);
273+
if ($_old['SUSPEND'] != $_new['SUSPEND']) {
274+
if ($_new['SUSPEND'] == 'on') {
275+
$result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
276+
if (!$result['status']) {
277+
$this->status = FALSE;
278+
$this->errors['SUSPEND'] = array($result['error_code'] => $result['error_message']);
279+
}
280+
// return $this->reply($result['status']);
278281
}
279-
// return $this->reply($result['status']);
280-
}
281-
else {
282-
$result = Vesta::execute(Vesta::V_UNSUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
283-
if (!$result['status']) {
284-
$this->status = FALSE;
285-
$this->errors['UNSUSPEND'] = array($result['error_code'] => $result['error_message']);
282+
else {
283+
$result = Vesta::execute(Vesta::V_UNSUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
284+
if (!$result['status']) {
285+
$this->status = FALSE;
286+
$this->errors['UNSUSPEND'] = array($result['error_code'] => $result['error_message']);
287+
}
288+
}
289+
if ($_new['SUSPEND'] == 'on') {
290+
$result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
291+
if (!$result['status']) {
292+
$this->status = FALSE;
293+
$this->errors['SUSPEND'] = array($result['error_code'] => $result['error_message']);
294+
}
295+
// return $this->reply($result['status']);
296+
}
297+
else {
298+
$result = Vesta::execute(Vesta::V_UNSUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
299+
if (!$result['status']) {
300+
$this->status = FALSE;
301+
$this->errors['UNSUSPEND'] = array($result['error_code'] => $result['error_message']);
302+
}
286303
}
287304
}
288305

@@ -422,7 +439,7 @@ public function changeExecute(Request $request)
422439
}
423440
}
424441

425-
if ($_new['SSL']) {
442+
/*if ($_new['SSL']) {
426443
$params = array(
427444
'USER' => $user['uid'],
428445
'DOMAIN' => $_new['DOMAIN'],
@@ -439,16 +456,19 @@ public function changeExecute(Request $request)
439456
if (!$result['status']) {
440457
$this->errors['SSL'] = array($result['error_code'] => $result['error_message']);
441458
}
442-
}
459+
}*/
443460

444-
if ($_s['SSL_KEY']) {
461+
if (!empty($_s['SSL_KEY'])) {
462+
$ssl_file = tempnam(sys_get_temp_dir(), 'ssl');
463+
file_put_contents($ssl_file, $_s['SSL_KEY']);
464+
445465
$params = array(
446466
'USER' => $user['uid'],
447467
'DOMAIN' => $_s['DOMAIN'],
448-
'SSL_KEY' => $_s['SSL_KEY']
468+
'SSL_KEY' => $ssl_file
449469
);
450470

451-
if ($_s['SSL_HOME']) {
471+
if (!empty($_s['SSL_HOME'])) {
452472
$params['SSL_HOME'] = $_s['SSL_HOME'];
453473
}
454474

@@ -460,6 +480,26 @@ public function changeExecute(Request $request)
460480
}
461481
}
462482

483+
484+
if (!empty($_s['SSL_CERT'])) {
485+
$sslcert_file = tempnam(sys_get_temp_dir(), 'ssl');
486+
file_put_contents($sslcert_file, $_s['SSL_CERT']);
487+
488+
$params = array(
489+
'USER' => $user['uid'],
490+
'DOMAIN' => $_s['DOMAIN'],
491+
'SSL_CERT' => $sslcert_file
492+
);
493+
494+
$result = 0;
495+
$result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSLCERT, $params);
496+
497+
if (!$result['status']) {
498+
$this->errors['SSL_CERT'] = array($result['error_code'] => $result['error_message']);
499+
}
500+
}
501+
502+
463503
return $this->reply($result['status'], $result['data']);
464504
}
465505

@@ -511,7 +551,7 @@ public function massiveSuspendExecute(Request $request)
511551
$_entities = $request->getParameter('entities');
512552

513553
foreach($_entities as $entity){
514-
$result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], $entity['DOMAIN']));
554+
$result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, array('USER' => $user, $entity['DOMAIN']));
515555
}
516556

517557
return $this->reply($result['status'], $result['data']);
@@ -523,7 +563,7 @@ public function massiveUnsuspendExecute(Request $request)
523563
$_entities = $request->getParameter('entities');
524564

525565
foreach($_entities as $entity){
526-
$result = Vesta::execute(Vesta::V_UNUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], $entity['DOMAIN']));
566+
$result = Vesta::execute(Vesta::V_UNUSPEND_WEB_DOMAIN, array('USER' => $user, $entity['DOMAIN']));
527567
}
528568

529569
return $this->reply($result['status'], $result['data']);
@@ -535,10 +575,9 @@ public function massiveDeleteExecute(Request $request)
535575
$_entities = $request->getParameter('entities');
536576

537577
foreach($_entities as $entity){
538-
$result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN, array('USER' => $user['uid'], $entity['DOMAIN']));
578+
$result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN, array('USER' => $user, $entity['DOMAIN']));
539579
}
540580

541581
return $this->reply($result['status'], $result['data']);
542582
}
543-
544583
}

0 commit comments

Comments
 (0)