Skip to content

Commit b1ea8b2

Browse files
committed
Session handling
1 parent e101104 commit b1ea8b2

File tree

10 files changed

+243
-91
lines changed

10 files changed

+243
-91
lines changed

web/js/actions.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
App.Actions.authorize = function()
2+
{
3+
if ($('#authorize-form').length > 0) {
4+
return;
5+
}
6+
7+
App.View.popup('login');
8+
}
9+
10+
App.Actions.do_authorise = function()
11+
{
12+
$('#authorize-error').text('');
13+
App.Ajax.request('MAIN.signin', {'login':$('#authorize-login').val(), 'password':$('#authorize-login'.val())}, function(reply)
14+
{
15+
if (reply.result) {
16+
location.href = '';
17+
}
18+
else {
19+
$('#authorize-error').text(reply.message);
20+
}
21+
});
22+
}
23+
124
App.Actions.delete_entry = function(evt)
225
{
326
var confirmed = confirm(App.i18n.getMessage('confirm'));
@@ -351,3 +374,14 @@ App.Actions.view_template_info = function(evt)
351374
}
352375
});
353376
}
377+
378+
App.Actions.toggle_stats_block = function(evt)
379+
{
380+
var elm = $(evt.target);
381+
if (!!elm.attr('checked')) {
382+
elm.parents('.stats-settings').find('.stats-block').removeClass('hidden');
383+
}
384+
else {
385+
elm.parents('.stats-settings').find('.stats-block').addClass('hidden');
386+
}
387+
}

web/js/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ App.Ajax.request = function(jedi_method, data, callback)
191191
reply = jsonParse(reply);
192192

193193
if (reply.result == 'NOT_AUTHORISED') {
194-
195-
return alert('NOT AUTH');
194+
$('#content').html('<center><h1 style="font-size: 18px;color:red;">Not Authorized</h1></center>');
195+
App.Helpers.afterAjax();
196+
return App.Actions.authorize();
196197
}
197198

198199
//timer.start();

web/js/html.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ App.HTML.Build.web_domain_entry = function(o, key)
296296
}
297297
tpl.set(':SUSPENDED_TPL', sub_tpl.finalize());
298298

299+
if (o.STATS_LOGIN.trim() != '') {
300+
tpl.set(':STATS_AUTH', '+auth');
301+
}
302+
else {
303+
tpl.set(':STATS_AUTH', '');
304+
}
305+
299306
return tpl.finalize();
300307
}
301308

@@ -304,6 +311,12 @@ App.HTML.Build.web_domain_form = function(options, id)
304311
if('undefined' == typeof App.Env.initialParams) {
305312
return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
306313
}
314+
315+
var in_edit = false;
316+
if (!App.Helpers.isEmpty(options)) {
317+
in_edit = true;
318+
}
319+
307320
var tpl = App.Templates.get('FORM', 'web_domain');
308321
tpl.set(':source', options);
309322
tpl.set(':id', id || '');
@@ -318,10 +331,32 @@ App.HTML.Build.web_domain_form = function(options, id)
318331
}
319332

320333
options = !App.Helpers.isEmpty(options) ? options : App.Empty.WEB_DOMAIN;
321-
334+
if (in_edit == true) {
335+
options.STATS_PASSWORD = options.STATS_LOGIN.trim() != '' ? App.Settings.PASSWORD_IMMUTE : '';
336+
}
322337
tpl = App.HTML.setTplKeys(tpl, options, true);
323338
tpl = App.HTML.Build.web_domain_selects(tpl, options);
324339

340+
if (options.CGI == 'yes') {
341+
tpl.set(':CHECKED_CGI', 'checked="checked"');
342+
}
343+
344+
if (options.ELOG == 'yes') {
345+
tpl.set(':CHECKED_ELOG', 'checked="checked"');
346+
}
347+
348+
if (options.STATS_LOGIN.trim() != '') {
349+
tpl.set(':STAT_AUTH', 'checked="checked"');
350+
tpl.set(':ACTIVE_LOGIN', '');
351+
tpl.set(':ACTIVE_PASSWORD', '');
352+
tpl.set(':stats_auth_checked', 'checked="checked"');
353+
}
354+
else {
355+
tpl.set(':ACTIVE_LOGIN', 'hidden');
356+
tpl.set(':ACTIVE_PASSWORD', 'hidden');
357+
tpl.set(':stats_auth_checked', '');
358+
}
359+
325360
return tpl.finalize();
326361
}
327362

@@ -601,6 +636,14 @@ App.HTML.Build.web_domain_selects = function(tpl, options)
601636
var obj = App.Env.initialParams.WEB_DOMAIN.TPL;
602637
var opts = App.HTML.Build.options(obj, options.TPL);
603638
tpl.set(':TPL_OPTIONS', opts);
639+
640+
// TPL
641+
var obj = App.Env.initialParams.WEB_DOMAIN.STAT;
642+
var opts = App.HTML.Build.options(obj, options.STAT);
643+
tpl.set(':STAT_OPTIONS', opts);
644+
645+
646+
//<input type="checkbox" name="STATS" ~!:stats_checked~!="" value="~!:STATS~!" class="not-styled">\
604647
}
605648
catch (e) {
606649
return tpl;

web/js/templates.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ App.Templates.html = {
3535
SUSPENDED_TPL_SUSPENDED : ['<span class="ip-status-info ip-suspended-status do_action_unsuspend"><span class="ip-status-text do_action_unsuspend">suspended</span></span>']
3636
},
3737
popup: {
38-
error: ['<div class="error"><center><h1 style="color: red;">Important: An Error Has Occured.</h1><hr></center>&nbsp;&nbsp;&nbsp;&nbsp;Something went wrong and some of your actions can be not saved in system. Mostly, it happens when you have network connection errors.<br>,&nbsp;&nbsp;&nbsp;&nbsp;However, please notify us about the situation. It would be helpfull if you will write us approximate time the error occured and last actions you were performing. You send your petition on <a href="mail_to">this email: BLABLA</a>,<br><br><center><span style="color: rgb(92, 92, 92);">Sorry for inconvinience. (We recommend you to reload the page)</span></center></div>']
38+
error: ['<div class="error"><center><h1 style="color: red;">Important: An Error Has Occured.</h1><hr></center>&nbsp;&nbsp;&nbsp;&nbsp;Something went wrong and some of your actions can be not saved in system. Mostly, it happens when you have network connection errors.<br>,&nbsp;&nbsp;&nbsp;&nbsp;However, please notify us about the situation. It would be helpfull if you will write us approximate time the error occured and last actions you were performing. You send your petition on <a href="mail_to">this email: BLABLA</a>,<br><br><center><span style="color: rgb(92, 92, 92);">Sorry for inconvinience. (We recommend you to reload the page)</span></center></div>'],
39+
login: ['<div class="error" id="authorize-form"><center><h1 style="color: red;">Please authorize.</h1><hr><div id="auth-error" style="color:red"></div>Login: <input type="text" id="authorize-login" / ><br/>Password: <input type="password" id="authorize-password"/><br /><button class="do_action_do_authorize">Log in</button></center></center></div>']
3940
},
4041
dates: {
4142
'lock_plan_date' : ['<button class="do.savePlanDate(~!:task_id~!)">Lock plan dates</button><button class="do.lockPlanDate(~!:task_id~!)">Lock plan dates</button>'],
@@ -511,13 +512,11 @@ App.Templates.html = {
511512
</select>\
512513
</div>\
513514
</div>\
514-
<div class="form-row cc">\
515-
<label for="#" class="field-label">CGI:</label>\
516-
<input type="checkbox" value="~!:CGI~!" ~!:CHECKED_CGI~! name="CGI" class="not-styled">\
517-
</div>\
518-
<div class="form-row cc">\
519-
<label for="#" class="field-label">ELOG:</label>\
520-
<input type="checkbox" value="~!:ELOG~!" ~!:CHECKED_ELOG~! name="ELOG" class="not-styled">\
515+
<div class="form-row cc adv_opts">\
516+
<label for="#" class="field-label">template:</label>\
517+
<select class="not-styled" name="TPL">\
518+
~!:TPL_OPTIONS~!\
519+
</select>\
521520
</div>\
522521
<!-- advanced options -->\
523522
<div class="form-options-group">\
@@ -527,30 +526,32 @@ App.Templates.html = {
527526
</span> \
528527
</div>\
529528
<div class="sub_section hidden">\
530-
<div class="form-row cc adv_opts">\
531-
<label for="#" class="field-label">template:</label>\
532-
<select class="not-styled" name="TPL">\
533-
~!:TPL_OPTIONS~!\
534-
</select>\
535-
</div>\
536529
<div class="form-row cc">\
530+
<label for="#" class="field-label">CGI:</label>\
531+
<input type="checkbox" value="~!:CGI~!" ~!:CHECKED_CGI~! name="CGI" class="not-styled">\
532+
</div>\
533+
<div class="form-row cc">\
534+
<label for="#" class="field-label">ELOG:</label>\
535+
<input type="checkbox" value="~!:ELOG~!" ~!:CHECKED_ELOG~! name="ELOG" class="not-styled">\
536+
</div>\
537+
<div class="form-row cc">\
537538
<label for="#" class="field-label">alias list:</label>\
538539
<textarea name="ALIAS" class="textarea">~!:ALIAS~!</textarea>\
539540
</div>\
540541
<div class="form-row cc">\
541542
<label for="#" class="field-label">statistics:</label>\
542-
<input type="checkbox" name="STATS" ~!:stats_checked~!="" value="~!:STATS~!" class="not-styled">\
543+
<select name="STAT">~!:STAT_OPTIONS~!</select>\
543544
</div>\
544545
<div class="stats-settings">\
545546
<div class="form-row cc">\
546547
<label for="#" class="field-label">stats auth:</label>\
547-
<input id="stats-auth-enable" type="checkbox" name="STATS_AUTH" ~!:stats_auth_checked~!="" value="~!:STATS_AUTH~!" class="not-styled">\
548+
<input id="stats-auth-enable" type="checkbox" name="STATS_AUTH" ~!:stats_auth_checked~!="" value="~!:STATS_AUTH~!" class="not-styled do_action_toggle_stats_block">\
548549
</div>\
549-
<div class="form-row cc">\
550+
<div class="form-row stats-block ~!:ACTIVE_LOGIN~! cc">\
550551
<label for="#" class="field-label">stats login:</label>\
551552
<input type="text" class="text-field rule-statslogin" name="STATS_LOGIN" value="~!:STATS_LOGIN~!">\
552553
</div>\
553-
<div class="form-row pwd-box cc">\
554+
<div class="form-row pwd-box ~!:ACTIVE_PASSWORD~! stats-block cc">\
554555
<label for="#" class="field-label">password:</label>\
555556
<input type="text" value="~!:STATS_PASSWORD~!" name="STATS_PASSWORD" class="text-field rule-statspassword password">\
556557
<span class="generate-pwd do_action_generate_pass">Generate</span>\
@@ -576,7 +577,7 @@ App.Templates.html = {
576577
</div>\
577578
</div><!-- // advanced options -->\
578579
</div>\
579-
<div class="form-options-group">\
580+
<div class="form-options-group hidden">\
580581
<div class="group-header cc collapsed">\
581582
<span class="group-title-outer do_action_toggle_section">\
582583
<span class="group-title do_action_toggle_section">DNS options</span>\
@@ -588,7 +589,7 @@ App.Templates.html = {
588589
<input type="checkbox" value="~!:DNS~!" ~!:CHECKED_DNS~! name="DNS" class="not-styled">\
589590
</div>\
590591
</div><!-- DNS options -->\
591-
<div class="form-options-group">\
592+
<div class="form-options-group hidden">\
592593
<div class="group-header cc collapsed">\
593594
<span class="group-title-outer do_action_toggle_section">\
594595
<span class="group-title do_action_toggle_section">Mail options</span>\
@@ -678,7 +679,7 @@ App.Templates.html = {
678679
</span>\
679680
<span class="prop-box stats-box">\
680681
<span class="prop-title">stats:</span>\
681-
<span class="prop-value">~!:STATS~!</span>\
682+
<span class="prop-value">~!:STAT~!</span>\
682683
<span class="stats-auth stats-auth-on">\
683684
<span class="stats-auth-text">~!:STATS_AUTH~!</span>\
684685
</span>\

web/js/validators.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ App.Validate.Rule = {
3030
if ($(elm).val().trim() == '' || $(elm).val().search(/[^a-zA-Z_]+/) != -1) {
3131
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' is invalid'};
3232
}
33-
if ($(elm).val().trim() != '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
33+
if ($(elm).val().trim() != '' && $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
3434
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
3535
}
3636
}
@@ -41,7 +41,7 @@ App.Validate.Rule = {
4141
if ($(elm).val().trim() == '') {
4242
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' is required'};
4343
}
44-
if ($(elm).val().trim() != '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
44+
if ($(elm).val().trim() != '' && $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
4545
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
4646
}
4747
}
@@ -51,7 +51,7 @@ App.Validate.Rule = {
5151
if ($(elm).val().trim() != '' && $(elm).val().search(/[^a-zA-Z_]+/) != -1) {
5252
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' is invalid'};
5353
}
54-
if ($(elm).val().trim() != '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
54+
if ($(elm).val().trim() != '' && $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
5555
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
5656
}
5757
return {VALID: true};
@@ -78,7 +78,7 @@ App.Validate.Rule = {
7878
if ($(elm).val().trim() != '' && $(elm).val().search(/[^a-zA-Z]+/) != -1) {
7979
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' must contain only letters without spaces or other symbols'};
8080
}
81-
if ($(elm).val().trim() != '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
81+
if ($(elm).val().trim() != '' && $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
8282
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
8383
}
8484
return {VALID: true};
@@ -87,7 +87,7 @@ App.Validate.Rule = {
8787
if ($(elm).val().search(/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/) == -1) {
8888
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid email'};
8989
}
90-
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
90+
if ($(elm).val().trim() == '' && $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
9191
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
9292
}
9393
return {VALID: true};
@@ -109,7 +109,7 @@ App.Validate.Rule = {
109109
if ($(elm).val().trim() != '' && (/^([a-z0-9\.])*[a-z0-9][a-z0-9\-]+[a-z0-9](\.[a-z]{2,4})+$/).test($(elm).val()) == false) {
110110
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid NS name'};
111111
}
112-
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
112+
if ($(elm).val().trim() == '' && $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
113113
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
114114
}
115115
return {VALID: true};
@@ -118,7 +118,7 @@ App.Validate.Rule = {
118118
if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
119119
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong minute value'};
120120
}
121-
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.MINUTE_MAX_LEN) {
121+
if ($(elm).val().trim() == '' && $(elm).val().length > App.Settings.MINUTE_MAX_LEN) {
122122
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
123123
}
124124
return {VALID: true};
@@ -130,7 +130,7 @@ App.Validate.Rule = {
130130
if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
131131
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong hour value'};
132132
}
133-
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.HOURS_MAX_LEN) {
133+
if ($(elm).val().trim() == '' && $(elm).val().length > App.Settings.HOURS_MAX_LEN) {
134134
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
135135
}
136136
return {VALID: true};
@@ -142,7 +142,7 @@ App.Validate.Rule = {
142142
if ($(elm).val().trim() != '' && $(elm).val().search(/[^123456\/\*-,]+/) != -1) {
143143
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong week day value'};
144144
}
145-
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.WDAY_MAX_LEN) {
145+
if ($(elm).val().trim() == '' && $(elm).val().length > App.Settings.WDAY_MAX_LEN) {
146146
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
147147
}
148148
return {VALID: true};
@@ -154,7 +154,7 @@ App.Validate.Rule = {
154154
if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
155155
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong month value'};
156156
}
157-
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.MONTH_MAX_LEN) {
157+
if ($(elm).val().trim() == '' && $(elm).val().length > App.Settings.MONTH_MAX_LEN) {
158158
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
159159
}
160160
return {VALID: true};
@@ -166,7 +166,7 @@ App.Validate.Rule = {
166166
if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
167167
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong day value'};
168168
}
169-
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.DAY_MAX_LEN) {
169+
if ($(elm).val().trim() == '' && $(elm).val().length > App.Settings.DAY_MAX_LEN) {
170170
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
171171
}
172172
return {VALID: true};

web/vesta/api/AjaxHandler.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ public function getLoggedUser()
4242
public function dispatch(Request $request)
4343
{
4444
$method = Request::parseAjaxMethod($request);
45+
if (!in_array($method['namespace'].'.'.$method['function'], array('MAIN.signin', 'MAIN.logout'))) {
46+
$user = $this->getLoggedUser();
47+
}
48+
4549
$inc_file = V_ROOT_DIR . 'api' . DIRECTORY_SEPARATOR . $method['namespace'] . '.class.php';
4650
if (!is_readable($inc_file)) {
4751
throw new SystemException(Message::INVALID_METHOD);
4852
}
49-
50-
// return $this->reply('NOT_AUTHORISED');
51-
5253
require $inc_file;
5354

5455
$space = new $method['namespace'];

0 commit comments

Comments
 (0)