cozaeppsync.php 7.08 KB
Newer Older
1
2
<?
# Copyright (c) 2012, AllWorldIT
3
#
4
5
6
7
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
8
#
9
10
11
12
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
13
#
14
15
16
17
18
19
20
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


# Official Website:
# http://devlabs.linuxassist.net/projects/whmcs-coza-epp

21
# Lead developer:
22
23
24
25
26
# Nigel Kukard <nkukard@lbsd.net>


# ! ! P L E A S E   N O T E  ! !

27
# * If you make changes to this file, please consider contributing
28
29
#   anything useful back to the community. Don't be a sour prick.

30
# * If you find this module useful please consider making a
31
32
33
#   donation to support modules like this.


34
35
# WHMCS hosting, theming, module development, payment gateway
# integration, customizations and consulting all available from
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# http://allworldit.com



# This file brings in a few constants we need
require_once dirname(__FILE__) . '/../../../dbconnect.php';
# Setup include dir
$include_path = ROOTDIR . '/modules/registrars/cozaepp';
set_include_path($include_path . PATH_SEPARATOR . get_include_path());
# Include EPP stuff we need
require_once 'cozaepp.php';
# Additional functions we need
require_once ROOTDIR . '/includes/functions.php';
# Include registrar functions aswell
require_once ROOTDIR . '/includes/registrarfunctions.php';

# Grab module parameters
$params = getregistrarconfigoptions('cozaepp');

55
56
57
58
59
60
61
62
63
64
# Grab the configuration setting for DomainSyncEnabled
$query = "select value from tblconfiguration where setting = 'DomainSyncEnabled'";
$res = mysql_query($query);
$row = mysql_fetch_array($res);

if (!empty($row) && !$row['value'] == 'on') {
	echo("COZAEPP domain sync disabled due to system setting");
	exit(0);
}

65
66
67
68
echo("COZA-EPP Domain Sync Report\n");
echo("---------------------------------------------------\n");

# Request balance from registrar
69
70
try {
	$client = _cozaepp_Client();
71

72
73
74
75
76
	# Pull list of domains which are registered using this module
	$queryresult = mysql_query("SELECT domain FROM tbldomains WHERE registrar = 'cozaepp'");
	while($data = mysql_fetch_array($queryresult)) {
		$domains[] = trim(strtolower($data['domain']));
	}
77

78
79
80
	# Loop with each one
	foreach($domains as $domain) {
		sleep(1);
81

82
83
84
		# Query domain
		$output = $client->request('
<epp:epp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epp="urn:ietf:params:xml:ns:epp-1.0"
85
86
87
88
89
90
91
92
93
		xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
	<epp:command>
		<epp:info>
			<domain:info xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
				<domain:name hosts="all">'.$domain.'</domain:name>
			</domain:info>
		</epp:info>
	</epp:command>
</epp:epp>
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
	');

		$doc= new DOMDocument();
		$doc->loadXML($output);
		$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
		if($coderes == '1000') {
			if( $doc->getElementsByTagName('status')) {
				if($doc->getElementsByTagName('status')->item(0)) {
					$statusres = $doc->getElementsByTagName('status')->item(0)->getAttribute('s');
					$createdate = substr($doc->getElementsByTagName('crDate')->item(0)->nodeValue,0,10);
					$nextduedate = substr($doc->getElementsByTagName('exDate')->item(0)->nodeValue,0,10);
				} else {
					$status = "Domain $domain not registered!";
					continue;
				}
109
			}
110
111
112
113
		} else if($coderes == '2303') {
			# Domain does not exist
			$status = "Domain $domain does not exist, setting state to cancelled!";
			$statusres = 'cancelled';
114
115
116
		} else {
			echo "Domain check on $domain not successful: "._cozaepp_message($coderes)." (File a bug report here: http://devlabs.linuxassist.net/projects/whmcs-coza-epp/issues/new)";
			continue;
117
118
		}

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
		# Checking for transfer status if transfer in progress
		$output = $client->request($xml = '
<epp:epp xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  <epp:command>
    <epp:transfer op="query">
      <domain:transfer>
        <domain:name>'.$domain.'</domain:name>
      </domain:transfer>
    </epp:transfer>
  </epp:command>
</epp:epp>');

		$transferstatus = '';

		# parsing for transfer status
		$doc= new DOMDocument();
		$doc->loadXML($output);
		$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
		if($coderes == '1000') {
			if( $doc->getElementsByTagName('trnData')) {
				if($doc->getElementsByTagName('trnData')->item(0)->getElementsByTagName('trStatus')->item(0)) {
					$transferstatus = $doc->getElementsByTagName('trnData')->item(0)->getElementsByTagName('trStatus')->item(0)->nodeValue;
				} else {
					$transferstatus = "Domain $domain not being transfered!";
					continue;
				}
			}
		} else {
			echo "Domain check on $domain not successful: "._cozaepp_message($coderes)." (File a bug report here: http://devlabs.linuxassist.net/projects/whmcs-coza-epp/issues/new)";
			continue;
		}

151
152
153
154
		# This is the template we going to use below for our updates
		$querytemplate = "UPDATE tbldomains SET status = '%s', registrationdate = '%s', expirydate = '%s', nextduedate = '%s' WHERE domain = '%s'";

		# Check status and update
155
		if ($statusres == "ok" || $transferstatus == "clientApproved") {
156
157
158
159
160
161
162
163
			mysql_query(sprintf($querytemplate,"Active",
					mysql_real_escape_string($createdate),
					mysql_real_escape_string($nextduedate),
					mysql_real_escape_string($nextduedate),
					mysql_real_escape_string($domain)
			));
			echo "Updated $domain expiry to $nextduedate\n";

164
165
		} elseif ($statusres == "serverHold" || $transferstatus == "pending") {
			mysql_query(sprintf($querytemplate,"Pending",
166
167
168
169
170
					mysql_real_escape_string($createdate),
					mysql_real_escape_string($nextduedate),
					mysql_real_escape_string($nextduedate),
					mysql_real_escape_string($domain)
			));
171
			echo "Domain $domain is PENDING (Registration: $createdate, Expiry: $nextduedate)\n";
172

173
		} elseif ($statusres == "expired" || $statusres == "pendingDelete" || $statusres == "inactive") {
174
175
176
177
178
179
180
			mysql_query(sprintf($querytemplate,"Expired",
					mysql_real_escape_string($createdate),
					mysql_real_escape_string($nextduedate),
					mysql_real_escape_string($nextduedate),
					mysql_real_escape_string($domain)
			));
			echo "Domain $domain is EXPIRED (Registration: $createdate, Expiry: $nextduedate)\n";
181

182
183
184
185
186
187
188
189
190
		} elseif ($statusres == "cancelled") {
			mysql_query(sprintf($querytemplate,"Cancelled",
					mysql_real_escape_string($createdate),
					mysql_real_escape_string($nextduedate),
					mysql_real_escape_string($nextduedate),
					mysql_real_escape_string($domain)
			));
			echo "Domain $domain does not exist\n";

191
192
193
		} else {
			echo "Domain $domain has unknown status '$statusres' (File a bug report here: http://devlabs.linuxassist.net/projects/whmcs-coza-epp/issues/new)\n";
		}
194
195
	}

196
197
198
199
} catch (Exception $e) {
	echo("ERROR: ".$e->getMessage()."\n");
	exit;
}
200
201

?>