예제 #1
0
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';
}
예제 #2
0
 public function clearBackupedConfigData()
 {
     $sql = "UPDATE mod_namecheapssl SET configdata_copy='' WHERE id='" . $this->_customRow['id'] . "'";
     NcSql::q($sql);
 }
예제 #3
0
function Namecheapssl_hook_sync_2($user, $password, $debugMode = false)
{
    require_once dirname(__FILE__) . "/../../modules/servers/namecheapssl/namecheapapi.php";
    require_once dirname(__FILE__) . "/../../modules/servers/namecheapssl/namecheapssl.php";
    namecheapssl_log('hook.sync', 'sync_hook_started', $user);
    $sync_date_offset = NcSql::sql2cell("SELECT value FROM mod_namecheapssl_settings WHERE name='sync_date_offset'");
    $api = new NamecheapApi($user, $password, $debugMode);
    $iPageSize = 22;
    $requestParams = array("Page" => 1, "PageSize" => $iPageSize);
    try {
        $response = $api->request("namecheap.ssl.getList", $requestParams);
        $result = $api->parseResponse($response);
    } catch (Exception $e) {
        echo $e->getMessage();
        return;
        //exit();
    }
    if ($result) {
        $iTotalPages = (int) ceil($result['Paging']['TotalItems'] / $iPageSize);
    }
    for ($i = 1; $i <= $iTotalPages; $i++) {
        if (1 != $i) {
            try {
                $requestParams = array("Page" => $i, "PageSize" => $iPageSize);
                $response = $api->request("namecheap.ssl.getList", $requestParams);
                $result = $api->parseResponse($response);
            } catch (Exception $e) {
                echo $e->getMessage();
                return;
                //exit();
            }
        }
        foreach ($result["SSLListResult"]["SSL"] as $aCertInfo) {
            if ('active' == $aCertInfo['@attributes']['Status'] || 'replaced' == $aCertInfo['@attributes']['Status']) {
                // synchronize expire date
                list($month, $day, $year) = explode("/", $aCertInfo['@attributes']['ExpireDate']);
                //
                $res = Namecheapssl_hook_sync_mysql_query("SELECT h.id FROM `tblhosting` h INNER JOIN `tblsslorders` s ON s.serviceid=h.id  WHERE s.remoteid='{$aCertInfo['@attributes']['CertificateID']}' AND h.`nextduedate` != '{$year}-{$month}-{$day}'");
                if (mysql_num_rows($res)) {
                    $iHostingId = array_shift(mysql_fetch_array($res));
                    $duedate = "{$year}-{$month}-{$day}";
                    if ($sync_date_offset) {
                        $duedate = date('Y-m-d', strtotime($duedate . "-{$sync_date_offset} days"));
                    }
                    $sql = "update `tblhosting`\n                                   set `nextduedate` = '{$duedate}',\n                                       `nextinvoicedate` = '{$duedate}'\n                                 where `id` = '{$iHostingId}'";
                    Namecheapssl_hook_sync_mysql_query($sql);
                    namecheapssl_log('hook.sync', 'sync_hook_updated_duedate', array("{$duedate}"), $iHostingId);
                }
                // sync domain
                if (!empty($aCertInfo['@attributes']['HostName']) && 'active' == $aCertInfo['@attributes']['Status']) {
                    $domain = mysql_real_escape_string($aCertInfo['@attributes']['HostName']);
                    $res = Namecheapssl_hook_sync_mysql_query("SELECT h.id FROM `tblhosting` h INNER JOIN `tblsslorders` s ON s.serviceid=h.id  WHERE s.remoteid='{$aCertInfo['@attributes']['CertificateID']}' AND h.`domain` != '{$domain}'");
                    if (mysql_num_rows($res)) {
                        $iHostingId = array_shift(mysql_fetch_array($res));
                        $sql = "update `tblhosting`\n                                        set `domain` = '{$domain}'\n                                        where `id` = '{$iHostingId}'";
                        Namecheapssl_hook_sync_mysql_query($sql);
                        namecheapssl_log('hook.sync', 'sync_hook_updated_domain', array($domain), $iHostingId);
                    }
                }
            }
            if ('replaced' == $aCertInfo['@attributes']['Status']) {
                // synchronize reissue state
                $sql = "SELECT * FROM tblsslorders WHERE remoteid='{$aCertInfo['@attributes']['CertificateID']}'";
                $r = Namecheapssl_hook_sync_mysql_query($sql);
                if (mysql_num_rows($r)) {
                    $aWhmcsCert = mysql_fetch_assoc($r);
                    // get replaced certificate info
                    try {
                        $replaced_cert_request_params = array('CertificateID' => (int) $aWhmcsCert['remoteid']);
                        $replaced_cert_response = $api->request("namecheap.ssl.getInfo", $replaced_cert_request_params);
                        $replaced_cert_result = $api->parseResponse($replaced_cert_response);
                        if (!empty($replaced_cert_result["SSLGetInfoResult"]["@attributes"]["ReplacedBy"])) {
                            $replacedBy = (int) $replaced_cert_result["SSLGetInfoResult"]["@attributes"]["ReplacedBy"];
                            if (0 == $replacedBy) {
                                echo 'Wrong "replaced by" attribute: ' . $replaced_cert_result["SSLGetInfoResult"]["@attributes"]["ReplacedBy"];
                                return;
                                //exit();
                            }
                            $sql = "UPDATE tblsslorders SET remoteid='{$replacedBy}' WHERE remoteid='{$aCertInfo['@attributes']['CertificateID']}'";
                            Namecheapssl_hook_sync_mysql_query($sql);
                            $sql = "UPDATE mod_namecheapssl SET certificate_id='{$replacedBy}' WHERE certificate_id='{$aCertInfo['@attributes']['CertificateID']}'";
                            Namecheapssl_hook_sync_mysql_query($sql);
                            namecheapssl_log('hook.sync', 'sync_hook_updated_remoteid', array($aCertInfo['@attributes']['CertificateID'], $replacedBy), $aWhmcsCert['serviceid']);
                        }
                    } catch (Exception $e) {
                        echo $e->getMessage();
                        return;
                        //exit();
                    }
                }
            }
        }
    }
}
예제 #4
0
function namecheapssl_check_install()
{
    $path = dirname(__FILE__) . '/../../addons/namecheap_ssl/namecheap_ssl.php';
    if (!file_exists($path)) {
        return false;
    }
    include_once $path;
    $configarray = namecheap_ssl_config();
    $version = $configarray['version'];
    // need to activate module
    $sql = "SELECT * FROM tbladdonmodules WHERE module='namecheap_ssl' AND setting='version' AND value='" . NcSql::e($version) . "'";
    return (bool) NcSql::sqlNumRows($sql);
}