Uname: Linux premium72.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software: LiteSpeed
PHP version: 8.2.29 [ PHP INFO ] PHP os: Linux
Server Ip: 198.54.125.95
Your Ip: 216.73.216.132
User: matican (532) | Group: matican (531)
Safe Mode: OFF
Disable Function:
NONE

name : le-cpapi.php
<?php

/**
 * @package WP Encryption
 *
 * @author     Go Web Smarty
 * @copyright  Copyright (C) 2019-2023, Go Web Smarty
 * @link       https://gowebsmarty.com
 * @since      Class available since Release 5.0.4
 *
 */

require_once WPLE_DIR . 'classes/cPanel/cPanel.php';

class WPLE_UAPI
{
  public function __construct()
  {
    if (!wple_fs()->is_plan('firewall', true)) {
      if (FALSE == ($fstage = get_option('wple_firewall_stage')) || $fstage != 6) {
        add_action('admin_menu', array($this, 'wple_cpapi_menu__premium_only'), 15);
      }
    }
  }

  public function wple_cpapi_menu__premium_only()
  {
    add_submenu_page(WPLE_SLUG, 'cPanel Login', 'cPanel Login', 'manage_options', 'wp_encryption_cpanel', array($this, 'wple_cpapi_page__premium_only'));
  }

  public function wple_cpapi_page__premium_only()
  {
    $this->wple_cpapi_handler();

    $opts = (FALSE !== get_option('wple_cpapi')) ? get_option('wple_cpapi') : array();

    $uh = isset($opts['uhost']) ? esc_attr($opts['uhost']) : '';

    $un = isset($opts['uname']) ? esc_attr($opts['uname']) : '';
    //$tk = isset($opts['token']) ? esc_attr($opts['token']) : '';

    $up = isset($opts['upass']) ? esc_attr($opts['upass']) : '';

    $gform = '<form method="post" class="le-genform">
    <label>cPanel Host</label>
    <input type="text" name="cpapi_host" placeholder="cPanel Host Url" value="' . $uh . '"><br />
    <small style="display: block; margin-bottom: 20px;">Please leave the above Host field empty unless you have cPanel in different url than your domain</small><br />
    <label>cPanel Username</label>
    <input type="text" name="cpapi_name" placeholder="Enter your cPanel Username" value="' . $un . '"><br />
    <label style="min-width: 140px;display: inline-block;">cPanel Password</label>
    <input type="password" name="cpapi_pass" placeholder="Enter your cPanel Password" value="' . $up . '"><br />    
    ' . wp_nonce_field('wple_cpapi', 'wplecpanelapi', false, false) . '
    <button type="submit" name="cpapi_save">Save Settings</button>
    </form>';

    $html = '<div class="wple-header">
      <img src="' . WPLE_URL . 'admin/assets/logo.png" class="wple-logo"/> <span class="wple-version">v' . WPLE_PLUGIN_VER . '</span>
    </div>';

    $html .= '<div id="wple-sslgen" class="wple-gdaddy">
    <h2>cPanel Login</h2>';

    $html .= do_action('wple_notice');

    $html .= '<p>Please use this backup feature Only if you receive an error saying <b>shell_exec</b> function not enabled on your server.<br><strong>NOTE:</strong> Please leave these fields <b>empty</b> if you have shell_exec function enabled and SSL installation is working fine.</p>
    ' . $gform . '
    <!--<video width="500" height="370" controls>
      <source src="https://gowebsmarty.com/cPanelAPI.webm" type="video/webm">
      Your browser does not support the video tag.
    </video>-->
    </div>';

    echo $html;
  }

  public function wple_cpapi_handler()
  {

    if (isset($_POST['wplecpanelapi'])) {

      if (!wp_verify_nonce($_POST['wplecpanelapi'], 'wple_cpapi') || !current_user_can('manage_options')) {
        exit('No cheating allowed');
      }

      $opts = array();
      $opts['uname'] = sanitize_text_field($_POST['cpapi_name']);
      $opts['uhost'] = sanitize_text_field($_POST['cpapi_host']);
      $token = $_POST['cpapi_pass'];

      if ($opts['uname'] == '' && $token == '') {
        delete_option('wple_cpapi');
      } else {

        if (base64_encode(base64_decode($token, true)) === $token) { //already encoded input
          $opts['upass'] = $token;
        } else {
          $opts['upass'] = base64_encode($token);
        }

        $decodedtoken = base64_decode($opts['upass']);

        $rootdomain = WPLE_Trait::get_root_domain();
        $host = is_ssl() ? 'https://' . $rootdomain : 'http://' . $rootdomain;

        if ($opts['uhost'] != '') {
          $host = $opts['uhost'];
        }
        $CP_host = WPLE_LogMeIn::getCpanelHost($host);
        $CP = new WPLE_cPanel($CP_host, $opts['uname'], $decodedtoken);

        if (!$CP->checkConnection()) {
          update_option('wple_cpapi', array());
          add_action('wple_notice', array($this, 'wple_cpapi_error_notice'));
          return;
        }

        update_option('wple_cpapi', $opts);
      }

      add_action('wple_notice', array($this, 'wple_cpapi_saved_notice'));
    }
  }

  public function wple_cpapi_saved_notice()
  {

    $html = '<div class="notice notice-success">
    <p><strong>Login saved! Please run the SSL install form now.</strong></p>
    </div>';

    echo $html;
  }

  public function wple_cpapi_error_notice()
  {

    $html = '<div class="notice notice-error">
    <p><strong>cPanel connection failed! Please double check your username and password.</strong></p>
    </div>';

    echo $html;
  }


  public static function wple_install_ssl__premium_only($cpcred, $domain, $cert, $key, $ca)
  {

    if ($cpcred['uname'] == '' || $cpcred['upass'] == '') {
      wp_die('cPanel Username or Password missing! Please go back and check cPanel login page.');
    }

    $cptoken = base64_decode($cpcred['upass']);

    $rootdomain = WPLE_Trait::get_root_domain();
    $host = is_ssl() ? 'https://' . $rootdomain : 'http://' . $rootdomain;

    if ($cpcred['uhost'] != '') {
      $host = $cpcred['uhost'];
    }
    $CP_host = WPLE_LogMeIn::getCpanelHost($host);
    $CP = new WPLE_cPanel($CP_host, $cpcred['uname'], $cptoken);

    return $CP->installSSL($rootdomain, ABSPATH . 'keys', true);
  }
}
© 2025 XylotrechusZ