\
+
\
\
reported to:\
naumov.socolov@gmail.com,\
diff --git a/web/js/validators.js b/web/js/validators.js
index ae8746e1..86d39b88 100644
--- a/web/js/validators.js
+++ b/web/js/validators.js
@@ -16,8 +16,12 @@ App.Validate.Is = {
App.Validate.getFieldName = function(elm)
{
fb.log(elm);
- fb.warn($(elm).prev('label').text());
- return ['', $(elm).prev('label').text(), ''].join('');
+ var txt_label = $(elm).prev('label').text();
+ if (txt_label.trim() == '') {
+ txt_label = $(elm).parents('.field-box').select('label:first').text();
+ }
+
+ return ['', txt_label, ''].join('');
}
App.Validate.Rule = {
@@ -27,15 +31,21 @@ App.Validate.Rule = {
}
return {VALID: true};
},
+ 'numeric': function(elm) {
+ if ($(elm).val().trim() != '' && isNaN(parseInt($(elm).val(), 10))) {
+ return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' is incorrect'};
+ }
+ return {VALID: true};
+ },
'no-spaces': function(elm) {
- if ($(elm).val().search(/\s/) != -1) {
+ if ($(elm).val().trim() != '' && $(elm).val().search(/\s/) != -1) {
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' cannot contain spaces'};
}
return {VALID: true};
},
'abc': function(elm) {
- if ($(elm).val().search(/[^a-zA-Z]+/) != -1) {
- return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' must contain only letters'};
+ if ($(elm).val().trim() != '' && $(elm).val().search(/[^a-zA-Z]+/) != -1) {
+ return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' must contain only letters without spaces or other symbols'};
}
return {VALID: true};
},
@@ -44,6 +54,74 @@ App.Validate.Rule = {
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid email'};
}
return {VALID: true};
+ },
+ 'ip': function(elm) {
+ if ($(elm).val().trim() != '' && (/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/).test($(elm).val()) == false) {
+ return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid IP value'};
+ }
+ return {VALID: true};
+ },
+ 'domain': function(elm) {
+ if ($(elm).val().trim() != '' && (/^([a-z0-9\.])*[a-z0-9][a-z0-9\-]+[a-z0-9](\.[a-z]{2,4})+$/).test($(elm).val()) == false) {
+ return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid domain name'};
+ }
+ return {VALID: true};
+ },
+ 'ns': function(elm) {
+ if ($(elm).val().trim() != '' && (/^([a-z0-9\.])*[a-z0-9][a-z0-9\-]+[a-z0-9](\.[a-z]{2,4})+$/).test($(elm).val()) == false) {
+ return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid NS name'};
+ }
+ return {VALID: true};
+ },
+ 'minute': function(elm) {
+ if ($(elm).val() == '*') {
+ return {VALID: true};
+ }
+ var minute = parseInt($(elm).val(), 10);
+ if (minute > 60 || minute < 0) {
+ return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong minute value'};
+ }
+ return {VALID: true};
+ },
+ 'hour': function(elm) {
+ if ($(elm).val() == '*') {
+ return {VALID: true};
+ }
+ var hour = parseInt($(elm).val(), 10);
+ if (hour > 60 || hour < 0) {
+ return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong hour value'};
+ }
+ return {VALID: true};
+ },
+ 'wday': function(elm) {
+ if ($(elm).val() == '*') {
+ return {VALID: true};
+ }
+ var wday = parseInt($(elm).val(), 10);
+ if (wday > 7 || wday < 1) {
+ return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong week day value'};
+ }
+ return {VALID: true};
+ },
+ 'month': function(elm) {
+ if ($(elm).val() == '*') {
+ return {VALID: true};
+ }
+ var month = parseInt($(elm).val(), 10);
+ if (month > 1 || month < 12) {
+ return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong month value'};
+ }
+ return {VALID: true};
+ },
+ 'day': function(elm) {
+ if ($(elm).val() == '*') {
+ return {VALID: true};
+ }
+ var day = parseInt($(elm).val(), 10);
+ if (day > 31 || day < 1) {
+ return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong day value'};
+ }
+ return {VALID: true};
}
}
@@ -53,7 +131,12 @@ App.Validate.form = function(world, elm)
var form_valid = true;
App.Env.FormError = [];
$(elm).find('select, input, textarea').each(function(i, field)
- {
+ {
+ if ($(field).attr('type') == 'checkbox') {
+ var value = $(field).attr('checked') ? 'on' : 'off';
+ $(field).val(value);
+ }
+
if ($.inArray($(field).attr('name'), ['target', 'source', 'save']) != -1) {
//return; // pass
}
@@ -61,7 +144,7 @@ App.Validate.form = function(world, elm)
var rules = App.Validate.getRules(field);
$(rules).each(function(i, rule)
{
- fb.log('Validate with %o %o', rule, field);
+ fb.log('Validate with %o %o', rule, field);
if (App.Validate.Rule[rule]) {
var result = App.Validate.Rule[rule](field);
fb.log(result);
@@ -96,18 +179,24 @@ App.Validate.displayFormErrors = function(world, elm)
App.Validate.getRules = function(elm)
{
- var rules_string = $(elm).attr('class');
- var rules = [];
- $(rules_string.split(/\s/)).each(function(i, str)
- {
- var rule = str.split('rule-');
- if (rule.length > 1) {
- rules[rules.length++] = rule[1];
- }
- });
-
- return rules;
+ try {
+ var rules_string = $(elm).attr('class');
+ var rules = [];
+ $(rules_string.split(/\s/)).each(function(i, str)
+ {
+ var rule = str.split('rule-');
+ if (rule.length > 1) {
+ rules[rules.length++] = rule[1];
+ }
+ });
+
+ return rules;
+ }
+ catch(e) {
+ return [];
+ }
}
+
diff --git a/web/vesta/api/CRON.class.php b/web/vesta/api/CRON.class.php
index 6eb9c6ab..d66fdee3 100644
--- a/web/vesta/api/CRON.class.php
+++ b/web/vesta/api/CRON.class.php
@@ -18,9 +18,9 @@ class CRON extends AjaxHandler
*/
public function getListExecute($request)
{
- $_user = 'vesta';
+ $user = $this->getLoggedUser();
$reply = array();
- $result = Vesta::execute(Vesta::V_LIST_CRON_JOBS, array($_user, Config::get('response_type')));
+ $result = Vesta::execute(Vesta::V_LIST_CRON_JOBS, array($user['uid'], Config::get('response_type')));
foreach ($result['data'] as $id => $record) {
$reply[$id] = array(
@@ -30,8 +30,9 @@ class CRON extends AjaxHandler
'DAY' => $record['DAY'],
'MONTH' => $record['MONTH'],
'WDAY' => $record['WDAY'],
- 'SUSPEND' => $record['SUSPEND'],
- 'DATE' => date(Config::get('ui_date_format', strtotime($record['DATE'])))
+ 'SUSPENDED' => $record['SUSPEND'],
+ 'DATE' => date(Config::get('ui_date_format', strtotime($record['DATE']))),
+ 'JOB' => $id
);
}
@@ -48,26 +49,25 @@ class CRON extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function addExecute($request)
+ public function addExecute(Request $request)
{
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
+ $user = $this->getLoggedUser();
+ $spell = $request->getParameter('spell');
$params = array(
- 'USER' => $_user,
- 'MIN' => $_s['MIN'],
- 'HOUR' => $_s['HOUR'],
- 'DAY' => $_s['DAY'],
- 'MONTH' => $_s['MONTH'],
- 'WDAY' => $_s['WDAY'],
- 'CMD' => $_s['CMD']
+ 'USER' => $user['uid'],
+ 'MIN' => $spell['MIN'],
+ 'HOUR' => $spell['HOUR'],
+ 'DAY' => $spell['DAY'],
+ 'MONTH' => $spell['MONTH'],
+ 'WDAY' => $spell['WDAY'],
+ 'CMD' => $spell['CMD']
);
$result = Vesta::execute(Vesta::V_ADD_CRON_JOB, $params);
- if ($_s['REPORTS']) {
+ if ($spell['REPORTS']) {
$result = array();
- $result = Vesta::execute(Vesta::V_ADD_SYS_USER_REPORTS, array('USER' => $_user));
+ $result = Vesta::execute(Vesta::V_ADD_SYS_USER_REPORTS, array('USER' => $user['uid']));
if (!$result['status']) {
$this->status = FALSE;
$this->errors['REPORTS'] = array($result['error_code'] => $result['error_message']);
@@ -87,15 +87,13 @@ class CRON extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function delExecute($request)
+ public function deleteExecute(Request $request)
{
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
-
+ $user = $this->getLoggedUser();
+ $spell = $request->getParameter('spell');
$params = array(
- 'USER' => $_user,
- 'JOB' => $_s['JOB']
+ 'USER' => $user['uid'],
+ 'JOB' => $spell['JOB']
);
$result = Vesta::execute(Vesta::V_DEL_CRON_JOB, $params);
@@ -113,18 +111,15 @@ class CRON extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function changeExecute($request)
+ public function changeExecute(Request $request)
{
- $r = new Request();
- $_s = $r->getSpell();
- $_old = $_s['old'];
- $_new = $_s['new'];
- $_user = 'vesta';
- $_JOB = $_new['JOB'];
+ $user = $this->getLoggedUser();
+ $_old = $request->getParameter('old');
+ $_new = $request->getParameter('new');
$result = array();
$params = array(
- 'USER' => $_user,
- 'JOB' => $_JOB,
+ 'USER' => $user['uid'],
+ 'JOB' => $_old['JOB'],
'MIN' => $_new['MIN'],
'HOUR' => $_new['HOUR'],
'DAY' => $_new['DAY'],
@@ -149,15 +144,13 @@ class CRON extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function suspendExecute($request)
+ public function suspendExecute(Request $request)
{
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
- $_JOB = $_s['JOB'];
+ $user = $this->getLoggedUser();
+ $spell = $request->getParameter('spell');
$params = array(
- 'USER' => $_user,
- 'JOB' => $_JOB
+ 'USER' => $user['uid'],
+ 'JOB' => $spell['JOB']
);
$result = Vesta::execute(Vesta::V_SUSPEND_CRON_JOB, $params);
@@ -176,16 +169,14 @@ class CRON extends AjaxHandler
* @return string - Ajax Reply
*/
public function unsuspendExecute($request)
- {
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
- $_JOB = $_s['JOB'];
+ {
+ $user = $this->getLoggedUser();
+ $spell = $request->getParameter('spell');
$params = array(
- 'USER' => $_user,
- 'JOB' => $_JOB
+ 'USER' => $user['uid'],
+ 'JOB' => $spell['JOB']
);
-
+
$result = Vesta::execute(Vesta::V_UNSUSPEND_CRON_JOB, $params);
if (!$result['status']) {
@@ -202,7 +193,7 @@ class CRON extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function suspendAllExecute($request)
+ /*public function suspendAllExecute($request)
{
$r = new Request();
$_s = $r->getSpell();
@@ -219,7 +210,7 @@ class CRON extends AjaxHandler
}
return $this->reply($result['status'], $result['data']);
- }
+ }*/
/**
* Batch unsuspend CRON entries
@@ -227,7 +218,7 @@ class CRON extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function unsuspendAllExecute($request)
+ /*public function unsuspendAllExecute($request)
{
$r = new Request();
$_s = $r->getSpell();
@@ -243,6 +234,6 @@ class CRON extends AjaxHandler
}
return $this->reply($result['status'], $result['data']);
- }
+ }*/
}
diff --git a/web/vesta/api/DNS.class.php b/web/vesta/api/DNS.class.php
index 7c5e3989..0c1e89f3 100644
--- a/web/vesta/api/DNS.class.php
+++ b/web/vesta/api/DNS.class.php
@@ -22,9 +22,9 @@ class DNS extends AjaxHandler
*/
public function getListExecute($request)
{
- $_user = 'vesta';
+ $user = $this->getLoggedUser();
$reply = array();
- $result = Vesta::execute(Vesta::V_LIST_DNS_DOMAINS, array($_user, Config::get('response_type')));
+ $result = Vesta::execute(Vesta::V_LIST_DNS_DOMAINS, array($user['uid'], Config::get('response_type')));
foreach ($result['data'] as $dns_domain => $details) {
$reply[] = array(
'DNS_DOMAIN' => $dns_domain,
@@ -53,12 +53,11 @@ class DNS extends AjaxHandler
*/
public function getListRecordsExecute($request)
{
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
+ $_s = $request->getParameter('spell');
+ $user = $this->getLoggedUser();
$reply = array();
- $result = Vesta::execute(Vesta::V_LIST_DNS_DOMAIN_RECORDS, array($_user, $_s['DNS_DOMAIN'], Config::get('response_type')));
+ $result = Vesta::execute(Vesta::V_LIST_DNS_DOMAIN_RECORDS, array($user['uid'], $_s['DNS_DOMAIN'], Config::get('response_type')));
foreach ($result['data'] as $record_id => $details) {
$reply[$record_id] = array(
'RECORD_ID' => $record_id,
@@ -78,7 +77,7 @@ class DNS extends AjaxHandler
}
/**
- * Add DB entry
+ * Add DNS entry
*
* v_add_dns_domain user domain ip [template] [exp] [soa] [ttl]
* http://95.163.16.160:8083/dispatch.php?jedi_method=DNS.add&USER=vesta&DOMAIN=dev.vestacp.com&IP_ADDRESS=95.163.16.160&TEMPLATE=default&EXP=01-01-12&SOA=ns1.vestacp.com&TTL=3600
@@ -86,21 +85,14 @@ class DNS extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function addExecute($_spell = false)
+ public function addExecute($request)
{
- $r = new Request();
- if ($_spell) {
- $_s = $_spell;
- }
- else {
- $_s = $r->getSpell();
- }
-
- $_user = 'vesta';
- $params = array(
- 'USER' => $_user, /// OWNER ???
+ $user = $this->getLoggedUser();
+ $_s = $request->getParameter('spell');
+ $params = array(
+ 'USER' => $user['uid'], /// OWNER ???
'DNS_DOMAIN' => $_s['DNS_DOMAIN'],
- 'IP' => $_s['IP']
+ 'IP' => $_s['IP']
);
// TODO: rewrite this block. Get away from if/if/if/if
if ($_s['TPL']) {
@@ -135,12 +127,11 @@ class DNS extends AjaxHandler
*/
public function addRecordExecute($request)
{
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
-
+ $user = $this->getLoggedUser();
+ $_s = $request->getParameter('spell');
+
$params = array(
- 'USER' => $_s['USER'], /// OWNER ???
+ 'USER' => $user['uid'], /// OWNER ???
'DOMAIN' => $_s['DOMAIN'],
'RECORD' => $_s['RECORD'],
'RECORD_TYPE' => $_s['TYPE'],
@@ -166,19 +157,12 @@ class DNS extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function delExecute($_spell = false)
+ public function deleteExecute($request)
{
- $r = new Request();
- if ($_spell) {
- $_s = $_spell;
- }
- else {
- $_s = $r->getSpell();
- }
-
- $_user = 'vesta';
+ $user = $this->getLoggedUser();
+ $_s = $request->getParameter('spell');
$params = array(
- 'USER' => $_user, /// OWNER ???
+ 'USER' => $user['uid'], /// OWNER ???
'DOMAIN' => $_s['DNS_DOMAIN'],
);
@@ -202,12 +186,11 @@ class DNS extends AjaxHandler
*/
public function delRecordExecute($request)
{
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
+ $_s = $request->getParameter('spell');
+ $user = $this->getLoggedUser();
$params = array(
- 'USER' => $_user, // TODO: OWNER ???
+ 'USER' => $user['uid'], // TODO: OWNER ???
'DOMAIN' => $_s['DOMAIN'],
'RECORD_ID' => $_s['RECORD_ID']
);
@@ -232,19 +215,17 @@ class DNS extends AjaxHandler
* @return string - Ajax Reply
*/
public function changeExecute($request)
- {
- $r = new Request();
- $_s = $r->getSpell();
- $_old = $_s['old'];
- $_new = $_s['new'];
- $_user = 'vesta';
- $_DNS_DOMAIN = $_new['DNS_DOMAIN'];
+ {
+ $_old = $request->getParameter('old');
+ $_new = $request->getParameter('new');
+ $user = $this->getLoggedUser();
+ $_DNS_DOMAIN = $_old['DNS_DOMAIN'];
if ($_old['IP'] != $_new['IP']) {
$result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_IP, array('USER' => $_user, 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_new['IP']));
+ $result = Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_IP, array('USER' => $user['uid'], 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_new['IP']));
if (!$result['status']) {
$this->status = FALSE;
$this->errors['IP_ADDRESS'] = array($result['error_code'] => $result['error_message']);
@@ -253,7 +234,7 @@ class DNS extends AjaxHandler
if ($_old['TPL'] != $_new['TPL']) {
$result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_TPL, array('USER' => $_user, 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_new['TPL']));
+ $result = Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_TPL, array('USER' => $user['uid'], 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_new['TPL']));
if (!$result['status']) {
$this->status = FALSE;
$this->errors['TPL'] = array($result['error_code'] => $result['error_message']);
@@ -262,7 +243,7 @@ class DNS extends AjaxHandler
if ($_old['TTL'] != $_new['TTL']) {
$result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_TTL, array('USER' => $_user, 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_new['TTL']));
+ $result = Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_TTL, array('USER' => $user['uid'], 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_new['TTL']));
if (!$result['status']) {
$this->status = FALSE;
$this->errors['TTL'] = array($result['error_code'] => $result['error_message']);
@@ -271,7 +252,7 @@ class DNS extends AjaxHandler
if ($_old['EXP'] != $_new['EXP']) {
$result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_EXP, array('USER' => $_user, 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_new['EXP']));
+ $result = Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_EXP, array('USER' => $user['uid'], 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_new['EXP']));
if (!$result['status']) {
$this->status = FALSE;
$this->errors['EXP'] = array($result['error_code'] => $result['error_message']);
@@ -280,7 +261,7 @@ class DNS extends AjaxHandler
if ($_old['SOA'] != $_new['SOA']) {
$result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_SOA, array('USER' => $_user, 'DNS_DOMAIN' => $_new['DNS_DOMAIN'], 'IP' => $_new['SOA']));
+ $result = Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_SOA, array('USER' => $user['uid'], 'DNS_DOMAIN' => $_new['DNS_DOMAIN'], 'IP' => $_new['SOA']));
if (!$result['status']) {
$this->status = FALSE;
$this->errors['SOA'] = array($result['error_code'] => $result['error_message']);
@@ -288,11 +269,11 @@ class DNS extends AjaxHandler
}
if (!$this->status) {
- Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_IP, array('USER' => $_user, 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_old['IP']));
- Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_TPL, array('USER' => $_user, 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_old['TPL']));
- Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_TTL, array('USER' => $_user, 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_old['TTL']));
- Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_EXP, array('USER' => $_user, 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_old['EXP']));
- Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_SOA, array('USER' => $_user, 'DNS_DOMAIN' => $_new['DNS_DOMAIN'], 'IP' => $_old['SOA']));
+ Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_IP, array('USER' => $user['uid'], 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_old['IP']));
+ Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_TPL, array('USER' => $user['uid'], 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_old['TPL']));
+ Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_TTL, array('USER' => $user['uid'], 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_old['TTL']));
+ Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_EXP, array('USER' => $user['uid'], 'DNS_DOMAIN' => $_DNS_DOMAIN, 'IP' => $_old['EXP']));
+ Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_SOA, array('USER' => $user['uid'], 'DNS_DOMAIN' => $_new['DNS_DOMAIN'], 'IP' => $_old['SOA']));
}
return $this->reply($this->status, '');
@@ -306,11 +287,9 @@ class DNS extends AjaxHandler
*/
public function changeRecordsExecute($request)
{
- $r = new Request();
- $_s = $r->getSpell();
- $_old = $_s['old'];
- $_new = $_s['new'];
- $_user = 'vesta';
+ $_old = $request->getParameter('old');
+ $_new = $request->getParameter('new');
+ $user = $this->getLoggedUser();
$_DNS_DOMAIN = $_s['DNS_DOMAIN'];
foreach ($_new as $record_id => $record_data) {
@@ -318,7 +297,7 @@ class DNS extends AjaxHandler
if (is_array($_old[$record_id])) {
$result = Vesta::execute(Vesta::V_CHANGE_DNS_DOMAIN_RECORD,
array(
- 'USER' => $_user,
+ 'USER' => $user['uid'],
'DNS_DOMAIN' => $_DNS_DOMAIN,
'ID' => $record_id,
'RECORD' => $record_data['RECORD'],
@@ -331,7 +310,7 @@ class DNS extends AjaxHandler
}
}
else {
- $result = Vesta::execute(Vesta::V_ADD_DNS_DOMAIN_RECORD, array('USER' => $_user, 'DNS_DOMAIN' => $_DNS_DOMAIN, 'RECORD' => $record_data['RECORD'], 'TYPE' => $record_data['RECORD_TYPE'], 'VALUE' => $record_data['RECORD_VALUE'], 'ID' => $record_id));
+ $result = Vesta::execute(Vesta::V_ADD_DNS_DOMAIN_RECORD, array('USER' => $user['uid'], 'DNS_DOMAIN' => $_DNS_DOMAIN, 'RECORD' => $record_data['RECORD'], 'TYPE' => $record_data['RECORD_TYPE'], 'VALUE' => $record_data['RECORD_VALUE'], 'ID' => $record_id));
if (!$result['status']) {
$this->status = FALSE;
$this->errors[$record_id] = array($result['error_code'] => $result['error_message']);
diff --git a/web/vesta/api/IP.class.php b/web/vesta/api/IP.class.php
index 0f363b03..d82fceaf 100644
--- a/web/vesta/api/IP.class.php
+++ b/web/vesta/api/IP.class.php
@@ -17,10 +17,10 @@ class IP extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function getListExecute($request)
+ public function getListExecute(Request $request)
{
$reply = array();
- $result = Vesta::execute(Vesta::V_LIST_SYS_IPS, array(Config::get('response_type')));
+ $result = Vesta::execute(Vesta::V_LIST_SYS_IPS, array(Config::get('response_type')));
foreach ($result['data'] as $ip => $details) {
$reply[] = array_merge(
array(
@@ -42,10 +42,10 @@ class IP extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function getListUserIpsExecute($request)
+ public function getListUserIpsExecute(Request $request)
{
$reply = array();
- $result = Vesta::execute(Vesta::V_LIST_SYS_IPS, array(Config::get('response_type')));
+ $result = Vesta::execute(Vesta::V_LIST_SYS_IPS, array(Config::get('response_type')));
foreach ($result['data'] as $ip => $details) {
$reply[] = array_merge(
array(
@@ -67,19 +67,17 @@ class IP extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function addExecute($request)
+ public function addExecute(Request $request)
{
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
-
+ $user = $this->getLoggedUser();
+ $spell = $request->getParameter('spell');
$params = array(
- 'IP_ADDRESS' => $_s['IP_ADDRESS'],
- 'MASK' => $_s['MASK'],
- 'INTERFACE' => $_s['INTERFACE'],
- 'OWNER' => $_s['OWNER'],
- 'IP_STATUS' => $_s['IP_STATUS'],
- 'IP_NAME' => $_s['IP_NAME']
+ 'IP_ADDRESS' => $spell['IP_ADDRESS'],
+ 'MASK' => $spell['NETMASK'],
+ 'INTERFACE' => $spell['INTERFACE'],
+ 'OWNER' => $spell['OWNER'],
+ 'IP_STATUS' => $spell['STATUS']
+ //'IP_NAME' => $spell['NAME']
);
$result = Vesta::execute(Vesta::V_ADD_SYS_IP, $params);
@@ -97,13 +95,12 @@ class IP extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function delExecute($request)
+ public function deleteExecute(Request $request)
{
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
+ $spell = $request->getParameter('spell');
+ $user = $this->getLoggedUser();
$params = array(
- 'IP_ADDRESS' => $_s['IP_ADDRESS']
+ 'IP_ADDRESS' => $spell['IP_ADDRESS']
);
$result = Vesta::execute(Vesta::V_DEL_SYS_IP, $params);
@@ -121,13 +118,11 @@ class IP extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function changeExecute($request)
+ public function changeExecute(Request $request)
{
- $r = new Request();
- $_s = $r->getSpell();
- $_old = $_s['old'];
- $_new = $_s['new'];
- $_user = 'vesta';
+ $user = $this->getLoggedUser();
+ $_old = $request->getParameter('old');
+ $_new = $request->getParameter('new');
if ($_old['OWNER'] != $_new['OWNER']) {
$result = array();
@@ -138,14 +133,15 @@ class IP extends AjaxHandler
}
}
- if ($_old['NAME'] != $_new['NAME']) {
+ // TODO: Handle NAME parameter
+ /*if ($_old['NAME'] != $_new['NAME']) {
$result = array();
$result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_NAME, array('IP' => $_new['IP_ADDRESS'], 'NAME' => $_new['NAME']));
if (!$result['status']) {
$this->status = FALSE;
$this->errors['NAME'] = array($result['error_code'] => $result['error_message']);
}
- }
+ }*/
if ($_old['IP_STATUS'] != $_new['IP_STATUS']) {
$result = array();
diff --git a/web/vesta/api/MAIN.class.php b/web/vesta/api/MAIN.class.php
index 40de2336..983cf877 100644
--- a/web/vesta/api/MAIN.class.php
+++ b/web/vesta/api/MAIN.class.php
@@ -47,16 +47,16 @@ class MAIN extends AjaxHandler
require_once V_ROOT_DIR . 'api/USER.class.php';
// IP
$ip_obj = new IP();
- $user_ips = json_decode($ip_obj->getListUserIpsExecute(), TRUE);
+ $user_ips = json_decode($ip_obj->getListUserIpsExecute($request), TRUE);
foreach ($user_ips['data'] as $ip) {
$ips[$ip['IP_ADDRESS']] = $ip['IP_ADDRESS'];
}
// USER
$user_obj = new USER();
- $users = json_decode($user_obj->getListExecute(), TRUE);
- $user_names = array_keys($users['data']['data']);
+ $users = json_decode($user_obj->getListExecute($request), TRUE);
+ $user_names = array_keys($users['data']);
$db_types = array('mysql' => 'mysql', 'postgress' => 'postgress');
- $interfaces_arr = json_decode($ip_obj->getSysInterfacesExecute(), TRUE);
+ $interfaces_arr = json_decode($ip_obj->getSysInterfacesExecute($request), TRUE);
$interfaces = $interfaces_arr['data'];
$data_web_domain = array('ips' => $ips);
@@ -133,8 +133,12 @@ class MAIN extends AjaxHandler
*/
public function getIpParams($data = array())
{
+ $users = array();
+ foreach ((array)$data['user_names'] as $user) {
+ $users[$user] = $user;
+ }
return array(
- 'SYS_USERS' => $data['user_names'],
+ 'SYS_USERS' => $users,
'STATUSES' => array(
'shared' => 'shared',
'exclusive' => 'exclusive'
@@ -163,7 +167,7 @@ class MAIN extends AjaxHandler
public function getDnsParams($data = array())
{
return array(
- 'IP' => $data['ips'],
+ 'IP' => @$data['ips'],
'TPL' => array('default' => 'default'),
'EXP' => array(),
'SOA' => array(),
diff --git a/web/vesta/api/USER.class.php b/web/vesta/api/USER.class.php
index 57089160..513f9c58 100644
--- a/web/vesta/api/USER.class.php
+++ b/web/vesta/api/USER.class.php
@@ -29,9 +29,12 @@ class USER extends AjaxHandler
foreach ($result['data'] as $user => $details) {
$fullname_id = rand(0, count($users)-1);
- $fullname = $users[$fullname_id];
-
- $reply[$user] = array(
+ $fullname = implode('', array($details['FNAME'], ' ', $details['LNAME']));
+ //if ($user == 'TestGOOD') {var_dump($details);die();}
+ $nses = $this->getNS($user, $details);
+ $user_details = array(
+ "FNAME" => $details['FNAME'],
+ "LNAME" => $details['LNAME'],
"LOGIN_NAME" => $user,
"FULLNAME" => $fullname, // TODO skid
"PACKAGE" => $details['PACKAGE'],
@@ -45,8 +48,8 @@ class USER extends AjaxHandler
"DNS_DOMAINS" => $details['DNS_DOMAINS'],
"DISK_QUOTA" => $details['DISK_QUOTA'],//$disk_quota,
"BANDWIDTH" => $details['BANDWIDTH'],//$bandwidth,
- "NS_LIST" => array($details['NS1'], $details['NS2']), // TODO skid
- "SHELL" => $details['"SHELL'],
+ //"NS_LIST" => array($details['NS1'], $details['NS2']), // TODO skid
+ "SHELL" => $details['SHELL'],
"BACKUPS" => $details['BACKUPS'],
"WEB_TPL" => $details['WEB_TPL'],
"MAX_CHILDS" => $details['MAX_CHILDS'],
@@ -69,6 +72,7 @@ class USER extends AjaxHandler
"U_MAIL_FORWARDERS" => rand(1, 10), // TODO: skid
"REPORTS_ENABLED" => 'enabled' // TODO: skid
);
+ $reply[$user] = array_merge($user_details, $nses);
}
return $this->reply(TRUE, $reply);
@@ -85,18 +89,23 @@ class USER extends AjaxHandler
$spell = $request->getParameter('spell');
$user = $this->getLoggedUser();
$params = array(
- 'USER' => $spell['USER'],
+ 'USER' => $spell['LOGIN_NAME'],
'PASSWORD' => $spell['PASSWORD'],
- 'EMAIL' => $spell['EMAIL'],
+ 'EMAIL' => $spell['CONTACT'],
'ROLE' => $spell['ROLE'],
'OWNER' => $user['uid'],
'PACKAGE' => $spell['PACKAGE'],
- 'NS1' => $spell['NS1'],
- 'NS2' => $spell['NS2']
+ 'FNAME' => $spell['FNAME'],
+ 'LNAME' => $spell['LNAME']
);
- $result = Vesta::execute(Vesta::V_ADD_SYS_USER, $params);
-
+ $result = Vesta::execute(Vesta::V_ADD_SYS_USER, $params);
+ // Reports
+ $enable_reports = Utils::getCheckboxBooleanValue($spell['REPORTS_ENABLED']);
+ $reports_result = $this->setUserReports($spell['LOGIN_NAME'], $spell['REPORTS_ENABLED']);
+ // NS
+ $ns_result = $this->setNSentries($spell['LOGIN_NAME'], $spell);
+
if (!$result['status']) {
$this->errors[] = array($result['error_code'] => $result['error_message']);
}
@@ -110,21 +119,14 @@ class USER extends AjaxHandler
* @param Request $request
* @return string - Ajax Reply
*/
- public function delExecute($_spell = false)
+ public function deleteExecute(Request $request)
{
- $r = new Request();
- if ($_spell) {
- $_s = $_spell;
- }
- else {
- $_s = $r->getSpell();
- }
-
- $_user = 'vesta';
+ $user = $this->getLoggedUser();
+ $spell = $request->getParameter('spell');
$params = array(
- 'USER' => $_s['USER']
+ 'USER' => $spell['LOGIN_NAME']
);
-
+
$result = Vesta::execute(Vesta::V_DEL_SYS_USER, $params);
if (!$result['status']) {
@@ -142,25 +144,10 @@ class USER extends AjaxHandler
*/
public function changeExecute($request)
{
- $r = new Request();
- $_s = $r->getSpell();
- $_old = $_s['old'];
- $_new = $_s['new'];
+ $_new = $request->getParameter('new');
+ $_old = $request->getParameter('old');
- $_USER = $_new['USER'];
-
- if ($_old['USER'] != $_new['USER']) {
- $result = array();
- // creating new user
- $result = $this->addExecute($_new);
- // deleting old
- if ($result['status']) {
- $result = array();
-
- $result = $this->delExecute($_old);
- return $this->reply($this->status, '');
- }
- }
+ $_USER = $_old['LOGIN_NAME'];
if ($_old['PASSWORD'] != $_new['PASSWORD']) {
$result = array();
@@ -180,32 +167,37 @@ class USER extends AjaxHandler
}
}
- if ($_old['EMAIL'] != $_new['EMAIL']) {
+ if ($_old['CONTACT'] != $_new['CONTACT']) {
$result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_CONTACT, array('USER' => $_USER, 'EMAIL' => $_new['EMAIL']));
+ $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_CONTACT, array('USER' => $_USER, 'EMAIL' => $_new['CONTACT']));
if (!$result['status']) {
$this->status = FALSE;
$this->errors['EMAIL'] = array($result['error_code'] => $result['error_message']);
}
}
- if ($_old['NS1'] != $_new['NS1'] || $_old['NS2'] != $_new['NS2']) {
- $result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_NS, array('USER' => $_USER, 'NS1' => $_new['NS1'], 'NS2' => $_new['NS2']));
- if (!$result['status']) {
- $this->status = FALSE;
- $this->errors['NS'] = array($result['error_code'] => $result['error_message']);
- }
+ $this->setNSentries($_USER, $_new);
+
+ $names = array(
+ 'USER' => $_USER,
+ 'NAME' => $_new['LOGIN_NAME'],
+ 'FNAME' => $_new['FNAME'],
+ 'LNAME' => $_new['LNAME']
+ );
+ $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_NAME, $names);
+ if (!$result['status']) {
+ $this->status = FALSE;
+ $this->errors['NAMES'] = array($result['error_code'] => $result['error_message']);
}
- if ($_old['SHELL'] != $_new['SHELL']) {
+ /*if ($_old['SHELL'] != $_new['SHELL']) {
$result = array();
$result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_SHELL, array('USER' => $_USER, 'SHELL' => $_new['SHELL']));
if (!$result['status']) {
$this->status = FALSE;
$this->errors['SHELL'] = array($result['error_code'] => $result['error_message']);
}
- }
+ }*/
if (!$this->status) {
Vesta::execute(Vesta::V_CHANGE_SYS_USER_PASSWORD, array('USER' => $_USER, 'PASSWORD' => $_old['PASSWORD']));
@@ -217,4 +209,48 @@ class USER extends AjaxHandler
return $this->reply($this->status, '');
}
+
+ protected function setUserReports($user, $enabled)
+ {
+ if ($enabled === true) {
+ $result = Vesta::execute(Vesta::V_ADD_SYS_USER_REPORTS, array('USER' => $user));
+ }
+ else {
+ $result = Vesta::execute(Vesta::V_DEL_SYS_USER_REPORTS, array('USER' => $user));
+ }
+
+ return $result['status'];
+ }
+
+ protected function setNSentries($user, $data)
+ {
+ $ns = array();
+ $ns['USER'] = $user;
+ $ns['NS1'] = $data['NS1'];
+ $ns['NS2'] = $data['NS2'];
+ $ns['NS3'] = isset($data['NS3']) ? $data['NS3'] : '';
+ $ns['NS4'] = isset($data['NS4']) ? $data['NS4'] : '';
+ $ns['NS5'] = isset($data['NS5']) ? $data['NS5'] : '';
+ $ns['NS6'] = isset($data['NS6']) ? $data['NS6'] : '';
+ $ns['NS7'] = isset($data['NS7']) ? $data['NS7'] : '';
+ $ns['NS8'] = isset($data['NS8']) ? $data['NS8'] : '';
+
+ $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_NS, $ns);
+
+ return $result['status'];
+ }
+
+ protected function getNS($user, $data)
+ {
+ $result = array();
+ $ns_str = $data['NS'];
+ $ns_list = explode(',', $ns_str);
+
+ foreach (range(0, 7) as $index) {
+ $result['NS'.($index + 1)] = @trim(@$ns_list[$index]);
+ }
+
+ return $result;
+ }
+
}
diff --git a/web/vesta/app.init.php b/web/vesta/app.init.php
index a4aa2976..90c54c9e 100644
--- a/web/vesta/app.init.php
+++ b/web/vesta/app.init.php
@@ -1,5 +1,17 @@
post,
$this->get,
$this->global);
- $this->_spell = json_decode($this->_merged['spell'], true);
+ //$this->_spell = json_decode($this->_merged['spell'], true);
}
/**
@@ -52,7 +52,12 @@ class Request
*/
public function getParameter($key, $default=false)
{
- return isset($this->_merged[$key]) ? $this->_merged[$key] : $default;
+ $param = isset($this->_merged[$key]) ? $this->_merged[$key] : $default;
+ if ($json = @json_decode($param, true)) {
+ return $json;
+ }
+
+ return $param;
}
/**
@@ -60,10 +65,10 @@ class Request
*
* @return array
*/
- public function getSpell()
+ /*public function getSpell()
{
return $this->_spell;
- }
+ }*/
/**
* Check if parameter is set
diff --git a/web/vesta/core/Vesta.class.php b/web/vesta/core/Vesta.class.php
index 825fbfb6..6ac71519 100644
--- a/web/vesta/core/Vesta.class.php
+++ b/web/vesta/core/Vesta.class.php
@@ -55,6 +55,7 @@ class Vesta
const V_CHANGE_SYS_USER_SHELL = 'v_change_sys_user_shell';
const V_CHANGE_SYS_USER_ROLE = 'v_change_sys_user_role';
const V_DEL_SYS_USER = 'v_del_sys_user';
+ const V_CHANGE_SYS_USER_NAME = 'v_change_sys_user_name';
// WEB_DOMAIN
const V_LIST_WEB_DOMAINS = 'v_list_web_domains';
const V_LIST_WEB_DOMAINS_ALIAS = 'v_list_web_domains_alias';
@@ -124,12 +125,16 @@ class Vesta
$params = array(
'sudo' => Config::get('sudo_path'),
'functions' => Config::get('vesta_functions_path'),
- 'parameters' => implode("' '", $parameters),
+ 'parameters' => implode("' '", $parameters),
);
+ if (!isset($params['reply'])) {
+ $params['reply'] = '';
+ }
+
// e.g.: /usr/bin/sudo /usr/local/vesta/bin/v_list_sys_users vesta json
$cmd = "{$params['sudo']} {$params['functions']}{$cmd_command} '{$params['parameters']}' {$params['reply']}";
-
+// print $cmd;//die();
exec($cmd, $output, $return);
$result = 0;
diff --git a/web/vesta/core/utils/error_logger.php b/web/vesta/core/utils/error_logger.php
index d9f601f1..dc70920c 100644
--- a/web/vesta/core/utils/error_logger.php
+++ b/web/vesta/core/utils/error_logger.php
@@ -10,7 +10,7 @@ function error_dumper($errno, $errstr, $errfile, $errline)
switch ($errno) {
case E_USER_ERROR:
- $o = "ERROR: [$errno] $errstr\n";
+ $o = date('Y-m-d H:i:s')."ERROR: $errstr [$errfile $errline]\n";
$o.= " Fatal error on line $errline in file $errfile";
$o.= ", PHP " . PHP_VERSION . " (" . PHP_OS . ")\n";
$o.= "Aborting...\n";
@@ -20,19 +20,19 @@ function error_dumper($errno, $errstr, $errfile, $errline)
break;
case E_USER_WARNING:
- $o = "WARNING: [$errno] $errstr\n";
+ $o = date('Y-m-d H:i:s')."WARNING: $errstr [$errfile $errline]\n";
fwrite($log, $o);
fclose($log);
break;
case E_USER_NOTICE:
- $o = "NOTICE: [$errno] $errstr\n";
+ $o = date('Y-m-d H:i:s')."NOTICE: $errstr [$errfile $errline]\n";
fwrite($log, $o);
fclose($log);
break;
default:
- $o = "Unknown error type: [$errno] $errstr\n";
+ $o = date('Y-m-d H:i:s')."Unknown error type: $errstr [$errfile $errline]\n";
fwrite($log, $o);
fclose($log);
break;