root il y a 1 mois
commit
33776ba83c
6 fichiers modifiés avec 345 ajouts et 0 suppressions
  1. 2 0
      classes/index.php
  2. 200 0
      classes/switchepp.class.php
  3. 88 0
      includes/homepage.php
  4. 2 0
      includes/index.php
  5. 2 0
      index.php
  6. 51 0
      wgs_switchepp.php

+ 2 - 0
classes/index.php

@@ -0,0 +1,2 @@
+<?php
+header("Location: ../../../../index.php");

+ 200 - 0
classes/switchepp.class.php

@@ -0,0 +1,200 @@
+<?php
+
+use Illuminate\Database\Capsule\Manager as Capsule;
+
+class SWITCHEPP {
+
+    private $apiUrl;
+    private $port;
+    private $regId;
+    private $regPw;
+    private $passPhrase;
+    private $dnsSec;
+
+    public function __construct() {
+        $this->WgsSwitchEppGetModuleParams();
+    }
+
+    public function WgsSwitchEppGetModuleParams() {
+        $getRegModuleDetail = Capsule::table('tblregistrars')->where('registrar', 'switchepp')->orderBy('id', 'asc')->get();
+        foreach ($getRegModuleDetail as $detail) {
+            $detail = (array) $detail;
+            if ($detail['setting'] == 'eppurl')
+                $this->apiUrl = decrypt($detail['value']);
+            if ($detail['setting'] == 'eppport')
+                $this->port = decrypt($detail['value']);
+            if ($detail['setting'] == 'registrar_id')
+                $this->regId = decrypt($detail['value']);
+            if ($detail['setting'] == 'registrar_password')
+                $this->regPw = decrypt($detail['value']);
+            if ($detail['setting'] == 'passphrase')
+                $this->passPhrase = decrypt($detail['value']);
+            if ($detail['setting'] == 'dnssec')
+                $this->dnsSec = decrypt($detail['value']);
+        }
+    }
+
+    public function WgsSwitchEppGetWHMCS_Admin() {
+        $admin = Capsule::table('tbladmins')->limit(1)->get();
+        return $admin[0]->id;
+    }
+
+    public function WgsSwitchEppGetPoll() {
+
+        $client = $this->WgsSwitchEppConnect();
+        if (is_array($client)) {
+            $error = $client['msg'];
+            return ['status' => 'error', 'msg' => $error];
+        }
+
+        $login = $this->WgsSwitchEppLoggedIn($client);
+
+        if ($login['status'] == 'error')
+            return $login;
+
+        $loginXmlArr = simplexml_load_string($login['resp']);
+        $loginCode = $loginXmlArr->response->result->attributes()->code[0];
+        if ($loginCode == 1000) {
+            $poll = $this->WgsSwitchEppPoll($client);
+            $pollXmlArr = simplexml_load_string($poll['resp']);
+            $pollCode = $pollXmlArr->response->result->attributes()->code[0];
+            $msgid = $pollXmlArr->response->msgQ->attributes()->id[0];
+
+            if ($pollCode == 1300 || $pollCode == 1301) {
+                return ['status' => 'success', 'msg' => $pollXmlArr->response->result->msg, 'resp' => $poll['resp'], 'msgid' => $msgid];
+            } else {
+                return ['status' => 'error', 'msg' => $pollXmlArr->response->result->msg];
+            }
+        } else {
+            foreach ($loginXmlArr->response->result as $resp) {
+                $error = $resp->msg;
+            }
+            return ['status' => 'error', 'msg' => $error];
+        }
+        $logout = $this->WgsSwitchEppLogout($client);
+    }
+
+    public function WgsSwitchEppPoll($client) {
+        $request = '<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
+                        <command>
+                            <poll op="req"/>
+                            <clTRID>POLL-' . rand(10000, 99999) . '</clTRID>
+                        </command>
+                    </epp>';
+        $response = $client->request($request);
+        logModuleCall('SWITCH EPP Addon Module', 'Get Poll', $request, $response);
+        return ['status' => 'success', 'req' => $request, 'resp' => $response];
+    }
+
+    public function WgsSwitchEppAckConfirm($msgId) {
+        $client = $this->WgsSwitchEppConnect();
+        if (is_array($client)) {
+            $error = $client['msg'];
+            return ['status' => 'error', 'msg' => $error];
+        }
+
+        $login = $this->WgsSwitchEppLoggedIn($client);
+
+        if ($login['status'] == 'error')
+            return $login;
+
+        $loginXmlArr = simplexml_load_string($login['resp']);
+        $loginCode = $loginXmlArr->response->result->attributes()->code[0];
+        if ($loginCode == 1000) {
+            $pollCnfrm = $this->WgsSwitchEppAckConfirmCommand($client, $msgId);
+            $pollCnfrmXmlArr = simplexml_load_string($pollCnfrm['resp']);
+            $pollCnfrmCode = $pollCnfrmXmlArr->response->result->attributes()->code[0];
+
+            if ($pollCnfrmCode == 1000) {
+                return ['status' => 'success', 'msg' => $pollCnfrmXmlArr->response->result->msg, 'resp' => $pollCnfrm['resp']];
+            } else {
+                return ['status' => 'error', 'msg' => $pollCnfrmXmlArr->response->result->msg];
+            }
+        } else {
+            foreach ($loginXmlArr->response->result as $resp) {
+                $error = $resp->msg;
+            }
+            return ['status' => 'error', 'msg' => $error];
+        }
+        $logout = $this->WgsSwitchEppLogout($client);
+    }
+
+    public function WgsSwitchEppAckConfirmCommand($client, $msgId) {
+        $request = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+                        <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
+                            <command>
+                                <poll op="ack" msgID="' . $msgId . '"/>
+                                <clTRID>POLLCF-' . rand(1000, 9999) . '</clTRID>
+                            </command>
+                        </epp>';
+        $response = $client->request($request);
+        logModuleCall('SWITCH EPP Addon Module', 'Confirm Acknowledge', $request, $response);
+        return ['status' => 'success', 'req' => $request, 'resp' => $response];
+    }
+
+    public function WgsSwitchEppLoggedIn($client) {
+        if ($this->regId && $this->regPw) {
+            $request = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+                <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
+                    <command>
+                        <login>
+                            <clID>' . $this->regId . '</clID>
+                            <pw>' . $this->regPw . '</pw>
+                            <options>
+                                <version>1.0</version>
+                                <lang>en</lang>
+                            </options>
+                            <svcs>
+                                <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
+                                <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
+                                <objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
+                            </svcs>
+                        </login>
+                    <clTRID>' . rand(9999999, 100000) . '</clTRID>
+                    </command>
+                </epp>';
+            $response = $client->request($request);
+            return ['status' => 'success', 'req' => $request, 'resp' => $response];
+        } else {
+            return ['status' => 'error', 'msg' => 'Registrar id or Registrar password missing'];
+        }
+    }
+
+    public function WgsSwitchEppLogout($client) {
+        $request = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+                        <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
+                            <epp:command xmlns:epp="urn:ietf:params:xml:ns:epp-1.0">
+                                <epp:logout />
+                                <epp:clTRID>' . $this->regId . '</epp:clTRID>
+                            </epp:command>
+                        </epp>';
+        $response = $client->request($request);
+        return ['status' => 'success', 'req' => $request, 'resp' => $response];
+    }
+
+    public function WgsSwitchEppConnect() {
+        try {
+            $certFile = __DIR__ . '/../../../registrars/switchepp/cert/cert.pem';
+            $client = new Net_EPP_Client();
+            $use_ssl = true;
+            if (file_exists($certFile)) {
+                $context = stream_context_create();
+                stream_context_set_option($context, 'ssl', 'verify_peer', false);
+                stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
+                stream_context_set_option($context, 'ssl', 'local_cert', $certFile);
+                stream_context_set_option($context, 'ssl', 'passphrase', $this->passPhrase);
+                $client->connect($this->apiUrl, $this->port, 300, $use_ssl, $context) or die("Not connected with epp server");
+            } else {
+                $context = false;
+                $client->connect($this->apiUrl, $this->port, 300, $use_ssl, $context) or die("Not connected with epp server");
+            }
+        } catch (Exception $e) {
+            $port = $this->port;
+            $client = ["error" => 'true', 'msg' => "Connection Error: " . $e->getMessage()];
+        }
+        return $client;
+    }
+
+}
+
+?>

+ 88 - 0
includes/homepage.php

@@ -0,0 +1,88 @@
+<?php
+if (isset($_POST['confirm']) && !empty($_POST['msgid'])) {
+    $error = $cnfrmSuccess = '';
+    $pollCnfrm = $SWITCHEPP->WgsSwitchEppAckConfirm($_POST['msgid']);
+    if ($pollCnfrm['status'] == 'error')
+        $error = $pollCnfrm['msg'];
+    elseif ($pollCnfrm['status'] == 'success')
+        $cnfrmSuccess = $pollCnfrm['msg'];
+} elseif (isset($_POST['confirm']) && empty($_POST['msgid']))
+    $error = 'msgId is missing!';
+
+if (isset($_POST['getpoll']) && !empty($_POST['getpoll'])) {
+    $error = $success = '';
+    $pollList = $SWITCHEPP->WgsSwitchEppGetPoll();
+    if ($pollList['status'] == 'error')
+        $error = $pollList['msg'];
+    elseif ($pollList['status'] == 'success')
+        $success = $pollList['msg'];
+    if (!empty($success)) {
+        $pollArr = simplexml_load_string($pollList['resp']);
+        $msgid = $pollList['msgid'];
+        $domainName = $pollArr->response->resData->children("domain", true)->trnData->name;
+        $status = $pollArr->response->resData->children("domain", true)->trnData->trStatus;
+        $reDate = substr($pollArr->response->resData->children("domain", true)->trnData->reDate, 0, 10);
+        $pollMsg = $pollArr->response->msgQ->msg;
+    }
+}
+?>
+<style>
+    .poll_cont {
+        text-align: center;
+    }
+    .poll_cont input[type="submit"] {
+        background: green;
+        border: 1px solid green;
+        color: #fff;
+        padding: 8px 20px;
+    }
+    .pollsuccess {
+        background: #cbf39f;
+        margin: 10px;
+        padding: 10px;
+        color: #406f0b;
+    }
+    .pollerror {
+        background: #f5d2d2;
+        margin: 10px;
+        padding: 10px;
+        color: #bb1313;
+    }
+</style>
+<div class="poll_cont">
+    <form method="post" action="">
+        <input type="submit" name="getpoll" value="Get Poll">
+    </form>
+    <?php
+    if (!empty($error))
+        echo '<div class="pollerror">' . $error . '</div>';
+    elseif (!empty($cnfrmSuccess))
+        echo '<div class="pollsuccess">' . $cnfrmSuccess . '</div>';
+    elseif (!empty($success)) {
+        echo '<div class="pollsuccess">' . $success . '</div>';
+        ?>
+        <form action="" method="post">
+            <input type="hidden" name="msgid" value="<?php echo $msgid ?>">
+            <table class="datatable" style="width: 100%;">
+                <thead>
+                <th>Domain Name</th>
+                <th>Status</th>
+                <th>Msg</th>
+                <th>Reg. Date</th>
+                <th>Action</th>
+                </thead>
+                <tbody>
+                    <?php if (!empty($msgid)) { ?>
+                    <td><?php echo $domainName; ?></td>
+                    <td><?php echo $status; ?></td>
+                    <td><?php echo $pollMsg; ?></td>
+                    <td><?php echo $reDate; ?></td>
+                    <td><input type="submit" name="confirm" value="Confirm"></td>
+                <?php } else { ?>
+                    <td colspan="100%">No messages</td>
+                <?php } ?>
+                </tbody>
+            </table>
+        </form>
+    <?php } ?>
+</div>

+ 2 - 0
includes/index.php

@@ -0,0 +1,2 @@
+<?php
+header("Location: ../../../../index.php");

+ 2 - 0
index.php

@@ -0,0 +1,2 @@
+<?php
+header("Location: ../../../index.php");

+ 51 - 0
wgs_switchepp.php

@@ -0,0 +1,51 @@
+<?php
+
+use Illuminate\Database\Capsule\Manager as Capsule;
+
+if (!defined("WHMCS"))
+    die("This file cannot be accessed directly");
+
+if (!class_exists('Net_EPP_Protocol')) {
+    if (file_exists(__DIR__ . "/../../registrars/switchepp/Net/EPP/Client.php"))
+        require_once __DIR__ . "/../../registrars/switchepp/Net/EPP/Client.php";
+}
+
+if (file_exists(__DIR__ . '/classes/switchepp.class.php'))
+    require_once __DIR__ . '/classes/switchepp.class.php';
+
+function wgs_switchepp_config() {
+    $configarray = array(
+        "name" => "Switch EPP",
+        "description" => "In this addon you can manage the poll and confirmation messege of Switch EPP registrar",
+        "version" => "3.0.5",
+        "author" => '<a href = "https://whmcsglobalservices.com" target = "_blank;">WHMCSGLOBALSERVICES</a>',
+        "language" => "english"
+    );
+    return $configarray;
+}
+
+function wgs_switchepp_activate() {
+    # Return Result
+    return array('status' => 'success', 'description' => 'Addons Image');
+}
+
+function wgs_switchepp_deactivate($vars) {
+    return array('status' => 'success', 'description' => 'Deactivated successfully.');
+}
+
+function wgs_switchepp_output($vars) {
+    $modulelink = $vars['modulelink'];
+    $LANG = $vars['_lang'];
+    $SWITCHEPP = new SWITCHEPP();
+    if (isset($_REQUEST["action"])) {
+        if (file_exists(__DIR__ . '/includes/' . $_REQUEST["action"] . '.php')) {
+            require_once __DIR__ . '/includes/' . $_REQUEST["action"] . '.php';
+        }
+    } else {
+        if (file_exists(__DIR__ . '/includes/' . 'homepage.php')) {
+            require_once __DIR__ . '/includes/' . 'homepage.php';
+        }
+    }
+}
+
+?>