| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671 |
- <?php
- /**
- * DOMAIN
- *
- * @author Naumov-Socolov <naumov.socolov@gmail.com>
- * @author Malishev Dima <dima.malishev@gmail.com>
- * @author vesta, http://vestacp.com/
- * @copyright vesta 2010-2011
- */
- class WEB_DOMAIN extends AjaxHandler
- {
-
- /**
- * Get list
- *
- * @param Request $request
- * @return
- */
- public function getListExecute($request)
- {
- $_user = 'vesta';
- $reply = array();
- $result = Vesta::execute(Vesta::V_LIST_WEB_DOMAINS, array($_user, Config::get('response_type')));
- foreach ($result['data'] as $web_domain => $data)
- {
- $reply[$web_domain] = array(
- 'IP' => $record['IP'],
- 'U_DISK' => $record['U_DISK'],
- 'U_BANDWIDTH' => $record['U_BANDWIDTH'],
- 'TPL' => $record['TPL'],
- 'ALIAS' => $record['ALIAS'],
- 'PHP' => $record['PHP'],
- 'CGI' => $record['CGI'],
- 'ELOG' => $record['ELOG'],
- 'STATS' => $record['STATS'],
- 'STATS_AUTH' => $record['STATS_AUTH'],
- 'SSL' => $record['SSL'],
- 'SSL_HOME' => $record['SSL_HOME'],
- 'SSL_CERT' => $record['SSL_CERT'],
- 'NGINX' => $record['NGINX'],
- 'NGINX_EXT' => $record['NGINX_EXT'],
- 'SUSPEND' => $record['SUSPEND'],
- 'DATE' => date(Config::get('ui_date_format', strtotime($record['DATE'])))
- );
- }
- if (!$result['status'])
- {
- $this->errors[] = array($result['error_code'] => $result['error_message']);
- }
- return $this->reply($result['status'], $reply);
- }
-
- /**
- * Add entry
- *
- * @param Request $request
- * @return
- */
- public function addExecute($request)
- {
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
-
- $params = array(
- 'USER' => $_user,
- 'DOMAIN' => $_s['DOMAIN'],
- 'IP' => $_s['IP']
- );
-
- $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN, $params);
-
- if (!$result['status'])
- {
- $this->errors[] = array(
- $result['error_code'] => $result['error_message']
- );
- }
-
- if ($_s['TPL'])
- {
- $params = array(
- 'USER' => $_user,
- 'DOMAIN' => $_s['DOMAIN'],
- 'TPL' => $_s['TPL']
- );
- $result = 0;
- $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_TPL, $params);
-
- if (!$result['status'])
- {
- $this->errors['CHANGE_TPL'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
- if ($_s['ALIAS'])
- {
- $alias_arr = explode(',', $_s['ALIAS']);
-
- foreach ($alias_arr as $alias)
- {
- $params = array(
- 'USER' => $_user,
- 'DOMAIN' => $_s['DOMAIN'],
- 'ALIAS' => trim($alias)
- );
- $result = 0;
-
- $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ALIAS, $params);
-
- if (!$result['status'])
- {
- $this->errors['ALIAS'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
- }
-
- if ($_s['STAT'])
- {
- $params = array(
- 'USER' => $_user,
- 'DOMAIN' => $_s['DOMAIN'],
- 'STAT' => $_s['STAT']
- );
- $result = 0;
- $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT, $params);
-
- if (!$result['status'])
- {
- $this->errors['STATS'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
-
- if ($_s['STAT_AUTH'])
- {
- $params = array(
- 'USER' => $_user,
- 'DOMAIN' => $_s['DOMAIN'],
- 'STAT_USER' => $_s['STAT_USER'],
- 'STAT_PASSWORS' => $_s['STAT_PASSWORD']
- );
- $result = 0;
- $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT_AUTH, $params);
-
- if (!$result['status'])
- {
- $this->errors['STAT_AUTH'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
-
-
- if ($_s['SSL'])
- {
- $params = array(
- 'USER' => $_user,
- 'DOMAIN' => $_s['DOMAIN'],
- 'SSL_CERT' => $_s['SSL_CERT']
- );
-
- if ($_s['SSL_HOME'])
- {
- $params['SSL_HOME'] = $_s['SSL_HOME'];
- }
-
- if ($_s['SSL_TEXT'])
- {
- // TODO: write it up
- }
-
- $result = 0;
- $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSL, $params);
-
- if (!$result['status'])
- {
- $this->errors['SSL'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
-
- if ($_s['CREATE_DNS_DOMAIN'])
- {
- $params = array(
- 'USER' => $_user,
- 'DNS_DOMAIN' => $_s['DOMAIN'],
- 'IP' => $_s['IP']
- );
-
- require_once V_ROOT_DIR . 'api/DNS.class.php';
-
- $dns = new DNS();
- $result = 0;
- $result = $dns->addExecute($params);
- if (!$result['status'])
- {
- $this->errors['DNS_DOMAIN'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
-
- if ($_s['CREATE_MAIL_DOMAIN'])
- {
- $params = array(
- 'USER' => $_user,
- 'MAIL_DOMAIN' => $_s['DOMAIN'],
- 'IP' => $_s['IP']
- );
-
- require_once V_ROOT_DIR . 'api/MAIL.class.php';
-
- $mail = new MAIL();
- $result = 0;
- $result = $mail->addExecute($params);
- if (!$result['status'])
- {
- $this->errors['MAIL_DOMAIN'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
-
- return $this->reply($result['status'], $result['data']);
- }
-
- /**
- * Delete entry
- *
- * @param Request $request
- * @return
- */
- public function delExecute($request)
- {
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
-
- $params = array(
- 'USER' => $_user,
- 'DOMAIN' => $_s['DOMAIN']
- );
-
- $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN, $params);
-
- if (!$result['status'])
- $this->errors[] = array(
- $result['error_code'] => $result['error_message']
- );
-
- $params = array(
- 'USER' => $_user,
- 'DNS_DOMAIN' => $_s['DOMAIN']
- );
-
- require_once V_ROOT_DIR . 'api/DNS.class.php';
- $dns = new DNS();
- $result = $dns->delExecute($params);
-
- if (!$result['status'] && $result['error_code'] != 31) // domain not found
- {
- $this->errors['DNS'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
-
- require_once V_ROOT_DIR . 'api/DNS.class.php';
-
- $params = array(
- 'USER' => $_user,
- 'MAIL_DOMAIN' => $_s['DOMAIN']
- );
-
- return $this->reply($result['status'], $result['data']);
- }
-
- /**
- * Change entry
- *
- * @param Request $request
- * @return
- */
- public function changeExecute($request)
- {
- $r = new Request();
- $_s = $r->getSpell();
- $_old = $_s['old'];
- $_new = $_s['new'];
-
- $_user = 'vesta';
- $_DOMAIN = $_new['DOMAIN'];
-
- if ($_old['IP'] != $_new['IP'])
- {
- $result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_IP, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN,
- 'IP' => $_new['IP']
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['IP_ADDRESS'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
-
- if ($_old['TPL'] != $_new['TPL'])
- {
- $result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_TPL, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN,
- 'TPL' => $_new['TPL']
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['TPL'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
-
- if ($_old['ALIAS'] != $_new['ALIAS'])
- {
- $result = array();
-
- $old_arr = explode(',', $_old['ALIAS']);
- $new_arr = explode(',', $_new['ALIAS']);
-
- $added = array_diff($new_arr, $old_arr);
- $deleted = array_diff($old_arr, $new_arr);
-
- foreach ($added as $alias)
- {
- $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ALIAS, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN,
- 'ALIAS' => $alias
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['ADD_ALIAS'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
- foreach ($deleted as $alias)
- {
- $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_ALIAS, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN,
- 'ALIAS' => $alias
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['DEL_ALIAS'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
- }
-
-
- if ($_old['STAT'] != $_new['STAT'])
- {
- if ($_new['STAT'] == true)
- {
- $result = array();
- $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN,
- 'STAT' => $_new['STAT']
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['ADD_STAT'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
-
- if ($_new['STAT'] == false)
- {
- $result = array();
- $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_STAT, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['DEL_STAT'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- $result = array();
-
- $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_STAT_AUTH, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN,
- 'STAT_USER' => $_new['STAT_USER']
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['DEL_STAT_AUTH'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
- }
- if ($_old['SSL'] != $_new['SSL'])
- {
- if ($_new['SSL'] == true)
- {
- // TODO: write it
- }
- if ($_new['SSL'] == false)
- {
- // TODO: write it
- }
- }
- else
- {
- if ($_old['SSL_CERT'] != $_new['SSL_CERT'])
- {
- $result = array();
- $_SSL_CERT = $_new['SSL_CERT'];
- // or read uploaded tmp file
-
- $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_CERT, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN,
- 'SSL_CERT' => $_SSL_CERT
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['SSL_CERT'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
- if ($_old['SSL_HOME'] != $_new['SSL_HOME'])
- {
- $result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_SSLHOME, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN,
- 'SSL_HOME' => $_new['SSL_HOME']
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['SSL_HOME'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
- }
-
- if ($_old['CGI'] != $_new['CGI'])
- {
- if ($_new['CGI'] == true)
- {
- $result = array();
- $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_CGI, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['ADD_CGI'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
- if ($_new['CGI'] == false)
- {
- $result = array();
- $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_CGI, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['DEL_CGI'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
- }
-
- if ($_old['ELOG'] != $_new['ELOG'])
- {
- if ($_new['ELOG'] == true)
- {
- $result = array();
- $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ELOG, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['ADD_ELOG'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
- if ($_new['ELOG'] == false)
- {
- $result = array();
- $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_ELOG, array(
- 'USER' => $_user,
- 'DOMAIN' => $_DOMAIN
- ));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['DEL_ELOG'] = array(
- $result['error_code'] => $result['error_message']
- );
- }
- }
- }
-
-
- return $this->reply($result['status'], $result['data']);
- }
-
- /**
- * Suspend entry
- *
- * @param Request $request
- * @return
- */
- public function suspendExecute($request)
- {
- $r = new Request();
- $_s = $r->getSpell();
-
- $_user = 'vesta';
-
- $params = array(
- 'USER' => $_user,
- 'DOMAIN' => $_s['DOMAIN']
- );
-
- $result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, $params);
-
- if (!$result['status'])
- {
- $this->errors[] = array(
- $result['error_code'] => $result['error_message']
- );
- }
-
- return $this->reply($result['status'], $result['data']);
- }
-
- /**
- * Unsuspend entry
- *
- * @param Request $request
- * @return
- */
- public function unsuspendExecute($request)
- {
- $r = new Request();
- $_s = $r->getSpell();
-
- $_user = 'vesta';
-
- $params = array(
- 'USER' => $_user,
- 'DOMAIN' => $_s['DOMAIN']
- );
-
- $result = Vesta::execute(Vesta::V_UNSUSPEND_WEB_DOMAIN, $params);
-
- if (!$result['status'])
- {
- $this->errors[] = array(
- $result['error_code'] => $result['error_message']
- );
- }
-
- return $this->reply($result['status'], $result['data']);
- }
-
- /**
- * Batch suspend entries
- *
- * @param Request $request
- * @return
- */
- public function suspendAllExecute($request)
- {
- $r = new Request();
- $_s = $r->getSpell();
-
- $_user = 'vesta';
-
- $params = array(
- 'USER' => $_user
- );
-
- $result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAINS, $params);
-
- if (!$result['status'])
- {
- $this->errors[] = array(
- $result['error_code'] => $result['error_message']
- );
- }
-
- return $this->reply($result['status'], $result['data']);
- }
-
- /**
- * Batch unsuspend entry
- *
- * @param Request $request
- * @return
- */
- public function unsuspendAllExecute($request)
- {
- $r = new Request();
- $_s = $r->getSpell();
-
- $_user = 'vesta';
-
- $params = array(
- 'USER' => $_user
- );
-
- $result = Vesta::execute(Vesta::V_UNSUSPEND_WEB_DOMAINS, $params);
-
- if (!$result['status'])
- {
- $this->errors[] = array(
- $result['error_code'] => $result['error_message']
- );
- }
-
- return $this->reply($result['status'], $result['data']);
- }
-
- }
|