These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * /classes/DomainMOD/DreamHost.php |
||
4 | * |
||
5 | * This file is part of DomainMOD, an open source domain and internet asset manager. |
||
6 | * Copyright (c) 2010-2017 Greg Chetcuti <[email protected]> |
||
7 | * |
||
8 | * Project: http://domainmod.org Author: http://chetcuti.com |
||
9 | * |
||
10 | * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public |
||
11 | * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later |
||
12 | * version. |
||
13 | * |
||
14 | * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
||
15 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see |
||
18 | * http://www.gnu.org/licenses/. |
||
19 | * |
||
20 | */ |
||
21 | //@formatter:off |
||
22 | namespace DomainMOD; |
||
23 | |||
24 | class DreamHost |
||
25 | { |
||
26 | |||
27 | View Code Duplication | public function getApiUrl($api_key, $command) |
|
28 | { |
||
29 | $base_url = 'https://api.dreamhost.com/?key=' . $api_key; |
||
30 | if ($command == 'domainlist') { |
||
31 | return $base_url . '&cmd=domain-list_registrations&format=json'; |
||
32 | } else { |
||
33 | return 'Unable to build API URL'; |
||
34 | } |
||
35 | } |
||
36 | |||
37 | View Code Duplication | public function apiCall($full_url) |
|
38 | { |
||
39 | $handle = curl_init($full_url); |
||
40 | curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true ); |
||
41 | $result = curl_exec($handle); |
||
42 | curl_close($handle); |
||
43 | return $result; |
||
44 | } |
||
45 | |||
46 | public function getDomainList($dbcon, $api_key, $account_id) |
||
47 | { |
||
48 | $error = new Error(); |
||
49 | $api_url = $this->getApiUrl($api_key, 'domainlist'); |
||
50 | $api_results = $this->apiCall($api_url); |
||
51 | $array_results = $this->convertToArray($api_results); |
||
52 | |||
53 | // confirm that the api call was successful |
||
54 | if ($array_results['result'] == 'success') { |
||
55 | |||
56 | $domain_list = array(); |
||
57 | $domain_count = 0; |
||
58 | |||
59 | foreach ($array_results['data'] as $value) { |
||
60 | |||
61 | $domain_list[] = $value['domain']; |
||
62 | $expiry_date = $this->processExpiry($value['expires']); |
||
63 | View Code Duplication | if ($value['ns1'] != '' && $value['ns1'] != 'unknown') $ns1 = $value['ns1']; |
|
64 | View Code Duplication | if ($value['ns2'] != '' && $value['ns2'] != 'unknown') $ns2 = $value['ns2']; |
|
65 | View Code Duplication | if ($value['ns3'] != '' && $value['ns3'] != 'unknown') $ns3 = $value['ns3']; |
|
66 | View Code Duplication | if ($value['ns4'] != '' && $value['ns4'] != 'unknown') $ns4 = $value['ns4']; |
|
67 | View Code Duplication | if ($value['ns5'] != '' && $value['ns5'] != 'unknown') $ns5 = $value['ns5']; |
|
68 | View Code Duplication | if ($value['ns6'] != '' && $value['ns6'] != 'unknown') $ns6 = $value['ns6']; |
|
69 | View Code Duplication | if ($value['ns7'] != '' && $value['ns7'] != 'unknown') $ns7 = $value['ns7']; |
|
70 | View Code Duplication | if ($value['ns8'] != '' && $value['ns8'] != 'unknown') $ns8 = $value['ns8']; |
|
71 | View Code Duplication | if ($value['ns9'] != '' && $value['ns9'] != 'unknown') $ns9 = $value['ns9']; |
|
72 | View Code Duplication | if ($value['ns10'] != '' && $value['ns10'] != 'unknown') $ns10 = $value['ns10']; |
|
73 | $autorenew = $this->processAutorenew($value['autorenew']); |
||
74 | $privacy = '0'; |
||
75 | |||
76 | $sql = "INSERT INTO domain_queue_temp |
||
77 | (account_id, domain, expiry_date, ns1, ns2, ns3, ns4, ns5, ns6, ns7, ns8, ns9, ns10, autorenew, privacy) |
||
78 | VALUES |
||
79 | ('" . $account_id . "', '" . $domain_list[$domain_count] . "', '" . $expiry_date . "', '" . $ns1 . "', '" . $ns2 . "', '" . $ns3 . "', '" . $ns4 . "', '" . $ns5 . "', '" . $ns6 . "', '" . $ns7 . "', '" . $ns8 . "', '" . $ns9 . "', '" . $ns10 . "', '" . $autorenew . "', '" . $privacy . "')"; |
||
80 | $result = mysqli_query($dbcon, $sql) or $error->outputSqlError($dbcon, '1', 'ERROR'); |
||
81 | |||
82 | $domain_count++; |
||
83 | |||
84 | } |
||
85 | |||
86 | } else { |
||
87 | |||
88 | // if the API call failed assign empty values |
||
89 | $domain_list = ''; |
||
90 | $domain_count = ''; |
||
91 | |||
92 | } |
||
93 | |||
94 | return array($domain_count, $domain_list); |
||
95 | } |
||
96 | |||
97 | View Code Duplication | public function getFullInfo($dbcon, $account_id, $domain) |
|
98 | { |
||
99 | $error = new Error(); |
||
100 | $sql = "SELECT id, expiry_date, ns1, ns2, ns3, ns4, ns5, ns6, ns7, ns8, ns9, ns10, autorenew, privacy |
||
101 | FROM domain_queue_temp |
||
102 | WHERE account_id = '" . $account_id . "' |
||
103 | AND domain = '" . $domain . "' |
||
104 | ORDER BY id ASC"; |
||
105 | $result = mysqli_query($dbcon, $sql) or $error->outputSqlError($dbcon, '1', 'ERROR'); |
||
106 | |||
107 | $dns_result = array(); |
||
108 | |||
109 | while ($row = mysqli_fetch_object($result)) { |
||
110 | |||
111 | $expiration_date = $row->expiry_date; |
||
112 | |||
113 | $dns_result[0] = $row->ns1; |
||
114 | $dns_result[1] = $row->ns2; |
||
115 | $dns_result[2] = $row->ns3; |
||
116 | $dns_result[3] = $row->ns4; |
||
117 | $dns_result[4] = $row->ns5; |
||
118 | $dns_result[5] = $row->ns6; |
||
119 | $dns_result[6] = $row->ns7; |
||
120 | $dns_result[7] = $row->ns8; |
||
121 | $dns_result[8] = $row->ns9; |
||
122 | $dns_result[9] = $row->ns10; |
||
123 | $dns_servers = $this->processDns($dns_result); |
||
124 | |||
125 | $privacy_status = $row->privacy; |
||
126 | |||
127 | $autorenewal_status = $row->autorenew; |
||
128 | |||
129 | $sql_temp = "DELETE FROM domain_queue_temp |
||
130 | WHERE id = '" . $row->id . "'"; |
||
131 | mysqli_query($dbcon, $sql_temp) or $error->outputSqlError($dbcon, '1', 'ERROR'); |
||
132 | |||
133 | } |
||
134 | |||
135 | return array($expiration_date, $dns_servers, $privacy_status, $autorenewal_status); |
||
136 | } |
||
137 | |||
138 | public function convertToArray($api_result) |
||
139 | { |
||
140 | return json_decode($api_result, true); |
||
141 | } |
||
142 | |||
143 | public function processExpiry($expiry_result) |
||
144 | { |
||
145 | $unix_expiration_date = strtotime($expiry_result); |
||
146 | return gmdate("Y-m-d", $unix_expiration_date); |
||
147 | } |
||
148 | |||
149 | View Code Duplication | public function processDns($dns_result) |
|
1 ignored issue
–
show
|
|||
150 | { |
||
151 | $dns_servers = array(); |
||
152 | if (!empty($dns_result)) { |
||
153 | $dns_servers = array_filter($dns_result); |
||
154 | } else { |
||
155 | $dns_servers[0] = 'no.dns-servers.1'; |
||
156 | $dns_servers[1] = 'no.dns-servers.2'; |
||
157 | } |
||
158 | return $dns_servers; |
||
159 | } |
||
160 | |||
161 | public function processAutorenew($autorenewal_result) |
||
162 | { |
||
163 | if ($autorenewal_result == 'yes') { |
||
164 | $autorenewal_status = '1'; |
||
165 | } else { |
||
166 | $autorenewal_status = '0'; |
||
167 | } |
||
168 | return $autorenewal_status; |
||
169 | } |
||
170 | |||
171 | } //@formatter:on |
||
172 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.