public function clearBackupedConfigData() { $sql = "UPDATE mod_namecheapssl SET configdata_copy='' WHERE id='" . $this->_customRow['id'] . "'"; NcSql::q($sql); }
function namecheap_ssl_output($vars) { if (!empty($_REQUEST['action'])) { $action = $_REQUEST['action']; } else { $action = 'default'; } global $_LANG; namecheapssl_initlang(); $view = array('global' => array('mod_url' => '?module=namecheap_ssl', 'module' => 'namecheap_ssl')); if ('log' == $action) { // prepare data for actions filters // actions $view['filter_action_options'] = array(); $sql = "SELECT DISTINCT action FROM mod_namecheapssl_log"; $r = mysql_query($sql); if (mysql_numrows($r)) { while ($row = mysql_fetch_assoc($r)) { if (!empty($row['action'])) { $view['filter_action_options'][] = $row['action']; } } } // detect selected action if (!empty($_REQUEST['filter_action']) && in_array($_REQUEST['filter_action'], $view['filter_action_options'])) { $view['filter_action_value'] = $_REQUEST['filter_action']; } else { $view['filter_action_value'] = ''; } // $view['filter_date_from_value'] = empty($_REQUEST['filter_date_from']) ? '' : $_REQUEST['filter_date_from']; $view['filter_date_to_value'] = empty($_REQUEST['filter_date_to']) ? '' : $_REQUEST['filter_date_to']; $view['filter_user_value'] = empty($_REQUEST['filter_user']) ? '' : $_REQUEST['filter_user']; // prepare query for page items $iOffset = empty($vars['log_items_per_page']) ? 50 : (int) $vars['log_items_per_page']; $page = !empty($_REQUEST['page']) ? (int) $_REQUEST['page'] : 1; $iLimit = $page <= 1 ? 0 : ($page - 1) * $iOffset; // create WHERE for sql query $sqlWhereArray = array(); // action value if (!empty($view['filter_action_value'])) { $sqlWhereArray[] = sprintf(" action='%s' ", mysql_real_escape_string($view['filter_action_value'])); } // date from value if (!empty($view['filter_date_from_value'])) { $sqlWhereArray[] = sprintf("date>='%s'", toMySQLDate($view['filter_date_from_value'])); } // date to value if (!empty($view['filter_date_to_value'])) { $sqlWhereArray[] = sprintf("date<='%s'", toMySQLDate($view['filter_date_to_value']) . ' 23:59:59'); } // admin / client filter if (!empty($view['filter_user_value'])) { if (false !== strpos($view['filter_user_value'], '@')) { $sqlWhereArray[] = sprintf("c.email = '%s'", mysql_real_escape_string($view['filter_user_value'])); } else { $sqlWhereArray[] = sprintf("log.user LIKE '%s%%'", mysql_real_escape_string($view['filter_user_value'])); } } if (!empty($sqlWhereArray)) { $sqlWhere = ' WHERE ' . implode(' AND ', $sqlWhereArray); } else { $sqlWhere = ''; } $sql = "SELECT log.*,c.email FROM mod_namecheapssl_log log LEFT JOIN tblclients AS c ON (log.userid=c.id AND user='******') {$sqlWhere} ORDER BY log.id DESC LIMIT {$iLimit},{$iOffset}"; $view['log_items'] = array(); $r = mysql_query($sql); if (mysql_numrows($r)) { while ($row = mysql_fetch_assoc($r)) { $view['log_items'][] = $row; } } // query for count $sql = "SELECT COUNT(log.id) FROM mod_namecheapssl_log log LEFT JOIN tblclients AS c ON (log.userid=c.id AND user='******') {$sqlWhere}"; $r = mysql_query($sql); $row = mysql_fetch_array($r); $iCountOfLogItems = array_shift($row); $iCountOfPages = (int) ceil($iCountOfLogItems / $iOffset); $view['log_items_count'] = $iCountOfLogItems; $view['log_items_count_of_pages'] = $iCountOfPages; $view['log_items_current_page'] = $page <= 1 ? 1 : $page; } else { if ('sync' == $action) { if (!empty($_REQUEST['hostingid'])) { $view['hostingid'] = (int) $_REQUEST['hostingid']; // search product $r = mysql_query('SELECT orderid, tblhosting.domain, tblproducts.name AS productname FROM tblhosting JOIN tblproducts ON tblhosting.packageid=tblproducts.id WHERE tblhosting.id=' . (int) $_REQUEST['hostingid']); $row = mysql_fetch_assoc($r); // check san certificate // get config options $certHasSanOption = false; $r = mysql_query('SELECT tblproductconfigoptions.optionname FROM tblproductconfigoptions JOIN tblhostingconfigoptions ON (tblhostingconfigoptions.configid=tblproductconfigoptions.id) WHERE tblhostingconfigoptions.relid=' . (int) $_REQUEST['hostingid']); $optionNames = array(); while (false !== ($optionsRow = mysql_fetch_assoc($r))) { $optionNames[] = $optionsRow['optionname']; if ('san' == substr($optionsRow['optionname'], 0, 3)) { $certHasSanOption = true; } } $view['cert_has_san_option'] = $certHasSanOption; if (false == $row || $certHasSanOption) { $view['found'] = false; } else { // select nc remote id $r = mysql_query('SELECT * FROM tblsslorders WHERE serviceid=' . (int) $_REQUEST['hostingid']); $ssl_order = mysql_fetch_array($r); if (false == $ssl_order) { $view['found'] = false; } else { $view['found'] = true; $view['hosting'] = array('hostingid' => $_REQUEST['hostingid'], 'orderid' => $row['orderid'], 'domain' => $row['domain'], 'productname' => $row['productname'], 'ssl_order_remoteid' => $ssl_order['remoteid'], 'ssl_order_certtype' => $ssl_order['certtype'], 'ssl_order_id' => $ssl_order['id']); if (isset($_REQUEST['message']) && 'updated' == $_REQUEST['message']) { $view['updated'] = true; } else { $view['updated'] = false; } // final level verification // assign remote id if (!empty($_POST['remoteid']) && !empty($_POST['ssl_order_id'])) { // two mysql queries // update whmcs native table mysql_query('UPDATE tblsslorders SET remoteid=' . (int) $_POST['remoteid'] . ' WHERE id=' . $_POST['ssl_order_id']); // update custom module table mysql_query('UPDATE mod_namecheapssl SET certificate_id=' . (int) $_POST['remoteid'] . ' WHERE id=' . $_POST['ssl_order_id']); // redirect $query_string = '?module=namecheap_ssl&action=sync&hostingid=' . $_REQUEST['hostingid'] . '&message=updated'; namecheapssl_log('addon.sync', 'addon_updated_remoteid', array($ssl_order['remoteid'], $_POST['remoteid']), $ssl_order['serviceid']); header('Location: ' . $query_string); exit; } } } } else { $view['hostingid'] = ''; } } else { if ('list' == $action) { $users = array(); // production certs $query = "SELECT DISTINCT configoption1 AS user, configoption2 AS password, 'production' AS acc FROM tblproducts WHERE configoption9='' AND configoption1!='' AND configoption2!='' AND servertype='namecheapssl'"; $r = mysql_query($query); while (false !== ($row = mysql_fetch_assoc($r))) { $view['userlist'][] = array('user' => $row['user'], 'acc' => 'production'); $users['production'][$row['user']] = $row; } // sandbox users $query = "SELECT DISTINCT configoption3 AS user, configoption4 AS password, 'sandbox' AS acc FROM tblproducts WHERE configoption9='on' AND configoption3!='' AND configoption4!='' AND servertype='namecheapssl'"; $r = mysql_query($query); while (false !== ($row = mysql_fetch_assoc($r))) { $view['userlist'][] = array('user' => $row['user'], 'acc' => 'sandbox'); $users['sandbox'][$row['user']] = $row; } if (!empty($_REQUEST['user']) && !empty($_REQUEST['acc'])) { if ('sandbox' != $_REQUEST['acc'] && 'production' != $_REQUEST['acc']) { echo 'unknown user'; exit; } if (!empty($users[$_REQUEST['acc']][$_REQUEST['user']])) { $user = $users[$_REQUEST['acc']][$_REQUEST['user']]['user']; $password = $users[$_REQUEST['acc']][$_REQUEST['user']]['password']; } else { echo 'unknown user'; exit; } $view['user'] = array('user' => $user, 'acc' => $_REQUEST['acc']); $itemsOnPage = 20; $page = empty($_REQUEST['page']) ? 1 : $_REQUEST['page']; $view['current_page'] = $page; $requestParams = array("Page" => $page, "PageSize" => $itemsOnPage); $api = new NamecheapApi($user, $password, $_REQUEST['acc'] == 'sandbox'); try { $response = $api->request("namecheap.ssl.getList", $requestParams); $result = $api->parseResponse($response); if (!empty($result['SSLListResult']['SSL'])) { $items = array(); foreach ($result['SSLListResult']['SSL'] as $k => $item) { // get whmcs product $items[$k]['namecheap'] = $item['@attributes']; $query = sprintf("SELECT serviceid,status FROM tblsslorders WHERE module='namecheapssl' AND remoteid='%s'", $item['@attributes']['CertificateID']); $r = mysql_query($query); if (mysql_num_rows($r)) { $items[$k]['whmcs'] = mysql_fetch_assoc($r); } } $view['items'] = $items; } $view['pages'] = array(); for ($i = 1; $i <= ceil($result['Paging']['TotalItems'] / $itemsOnPage); ++$i) { $view['pages'][] = $i; } } catch (Exception $e) { var_dump($e->getMessage()); exit; $view['globals']['error'] = $e->getMessage(); } } } else { if ('settings' == $action) { // message $view['message'] = ''; if (!empty($_REQUEST['message']) && 'updated' == $_REQUEST['message']) { $view['message'] = $_LANG['ncssl_addon_changes_saved_success']; } // prepare information for view $view['settings'] = NcSql::sql2set_keyval("SELECT name,value FROM mod_namecheapssl_settings"); $view['control_options'] = array('sync_date_offset' => array(0 => '0', 5 => '5', 15 => '15', 30 => '30')); // process incoming data if (isset($_REQUEST['settings'])) { foreach ($_REQUEST['settings'] as $name => $value) { NcSql::q(sprintf("DELETE FROM mod_namecheapssl_settings WHERE name='%s'", NcSql::e($name))); NcSql::q(sprintf("INSERT INTO mod_namecheapssl_settings SET name='%s', value='%s'", NcSql::e($name), NcSql::e($value))); } // redirect $query_string = '?module=namecheap_ssl&action=settings&message=updated'; namecheapssl_log('addon.settings', 'addon_updated_settings'); header('Location: ' . $query_string); exit; } } else { $action = 'default'; } } } } $view['global']['mod_action_url'] = $view['global']['mod_url'] . '&action=' . $action; $view['global']['action'] = $action; include dirname(__FILE__) . '/templates/' . $action . '.php'; }
function namecheapssl_log($action, $messageKey, $args = null, $serviceId = 0) { static $_M; if (empty($_M)) { include_once dirname(__FILE__) . '/namecheaplog.php'; } if (empty($_M[$messageKey])) { ##### //// exit('empty log alias'); return false; } // try to detect user $username = '******'; $userid = 0; if (!empty($_SESSION['adminid'])) { $userid = $_SESSION["adminid"]; $sql = "SELECT username FROM tbladmins WHERE id='" . (int) $userid . "'"; $username = NcSql::sql2cell($sql); } if (!empty($_SESSION['uid'])) { $userid = $_SESSION['uid']; $username = '******'; } $action = 'mod.' . $action; if (is_null($args)) { $message = $_M[$messageKey]; } else { if (is_string($args)) { $args = array($args); } $message = vsprintf($_M[$messageKey], $args); } $sql = "INSERT INTO mod_namecheapssl_log SET date=NOW(), debug='0', action='" . NcSql::e($action) . "', serviceid='" . (int) $serviceId . "', description='" . NcSql::e($message) . "', ipaddr='" . NcSql::e($_SERVER['REMOTE_ADDR']) . "', userid='" . (int) $userid . "', user='******'"; NcSql::q($sql); return NcSql::insertId(); }