├── LICENSE
├── README.md
├── install_instructions.txt
└── linodedns
├── client_templates
├── access_error.tpl
├── add_record.tpl
├── add_zone.tpl
├── edit_record.tpl
├── edit_zone.tpl
├── linode_dns_main.tpl
└── submit_add_zone.tpl
├── hooks.php
├── lang
└── english.php
├── linode_api
├── Linode
│ └── Exception.php
└── Services
│ ├── Linode.php
│ ├── Services_Linode
│ └── api.xml
│ └── api.xml
├── linodedns.php
└── templates
├── clientaccess.php
├── dnsskeleton.php
├── servers.php
├── skeleton_add.php
└── skeleton_edit.php
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Shawn Purdy
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WHMCS-Linode-DNS-Addon
2 | Auto creation of dns zones, client access to dns zones
3 |
4 | You can donate to our open source projects by going to: http://purdydesigns.com/en/Open-Source-Donation
5 |
6 | In order to use this addon you will need a few things.
7 |
8 | 1. You will install the following PEAR modules into PHP
9 |
10 | $ sudo pear install Net_URL2-0.3.1
11 | $ sudo pear install HTTP_Request2-0.5.2
12 | $ sudo pear channel-discover pear.keremdurmus.com
13 | $ sudo pear install krmdrms/Services_Linode
14 |
15 |
16 | 2. You will need to create an API key at linode within your linode account.
17 | I suggest you create a second user that only has access to DNS related functions.
18 |
19 | 3. Copy the entire linodedns folder into your WHMCS installation
20 | in the directory /modules/addons
21 |
22 | If your WHMCS is installed in a subfolder than your directory structure would be
23 | /subfolder/modules/addons
24 |
25 | 4. Once you have done this. Goto your admin area in WHMCS, and Navigate to
26 | -> Setup -> Addon Modules
27 | Scroll down until you see "Linode DNS Manager" Click on Activate
28 |
29 | 5. Once it is activated click on Configure. Fill in the information request. You must enter your linode API key, and your SOA Email address. The Enable SSL and Homepage Display options are optional. (Make sure to click the checkbox for Full Administrator.
30 |
31 | 6. Within WHMCS Admin navigate to: -> Addons -> Linode DNS Manager
32 |
33 | 7. This is the admin interface where you can make some changes. To get started you will likely want to click the Servers button. Here will have a list of your servers. Simply select which servers you want to use this addon module on and click save.
34 |
35 | 8. Once this is done you can now also link your existing hosting accounts within WHMCS to your domains zone files at linode by pushing the link accounts button. At this point your clients will have access to the domains assoicated with they're accounts within WHMCS.
36 |
37 | 9. If your clients have add-on domains or parked domains that already exist. You can give them access to those zones as well by pushing the Client Access Domains button. Select the client and the domain and Click Add. You can also remove access rights from this screen as well.
38 |
39 | 10. Lastly. We provide a basic DNS skeleton automatically for each server within your WHMCS install. You can customize these skeletons if you like. This skeleton is used when a client either add's a zone from the client area. Or a new or existing client orders hosting services. These DNS Records will be automatically added with the correct ip address and other relivant information.
40 |
--------------------------------------------------------------------------------
/install_instructions.txt:
--------------------------------------------------------------------------------
1 | In order to use this addon you will need a few things.
2 |
3 | 1. You will install the following PEAR modules into PHP
4 | $ sudo pear install Net_URL2-0.3.1
5 | $ sudo pear install HTTP_Request2-0.5.2
6 | $ sudo pear channel-discover pear.keremdurmus.com
7 | $ sudo pear install krmdrms/Services_Linode
8 |
9 | 2. You will need to create an API key at linode within your linode account.
10 | I suggest you create a second user that only has access to DNS related functions.
11 |
12 | 3. Copy the entire linodedns folder into your WHMCS installation
13 | in the directory /modules/addons
14 |
15 | If your WHMCS is installed in a subfolder than your directory structure would be
16 | /subfolder/modules/addons
17 |
18 | 4. Once you have done this. Goto your admin area in WHMCS, and Navigate to
19 | -> Setup -> Addon Modules
20 | Scroll down until you see "Linode DNS Manager" Click on Activate
21 |
22 | 5. Once it is activated click on Configure. Fill in the information request. You must enter your linode API key, and your SOA Email address. The Enable SSL and Homepage Display options are optional. (Make sure to click the checkbox for Full Administrator.
23 |
24 | 6. Within WHMCS Admin navigate to: -> Addons -> Linode DNS Manager
25 |
26 | 7. This is the admin interface where you can make some changes. To get started you will likely want to click the Servers button. Here will have a list of your servers. Simply select which servers you want to use this addon module on and click save.
27 |
28 | 8. Once this is done you can now also link your existing hosting accounts within WHMCS to your domains zone files at linode by pushing the link accounts button. At this point your clients will have access to the domains assoicated with they're accounts within WHMCS.
29 |
30 | 9. If your clients have add-on domains or parked domains that already exist. You can give them access to those zones as well by pushing the Client Access Domains button. Select the client and the domain and Click Add. You can also remove access rights from this screen as well.
31 |
32 | 10. Lastly. We provide a basic DNS skeleton automatically for each server within your WHMCS install. You can customize these skeletons if you like. This skeleton is used when a client either add's a zone from the client area. Or a new or existing client orders hosting services. These DNS Records will be automatically added with the correct ip address and other relivant information.
--------------------------------------------------------------------------------
/linodedns/client_templates/access_error.tpl:
--------------------------------------------------------------------------------
1 | You don't have permission to access this page
--------------------------------------------------------------------------------
/linodedns/client_templates/add_record.tpl:
--------------------------------------------------------------------------------
1 | Add Record
2 |
--------------------------------------------------------------------------------
/linodedns/client_templates/add_zone.tpl:
--------------------------------------------------------------------------------
1 | Add Zone
2 |
--------------------------------------------------------------------------------
/linodedns/client_templates/edit_record.tpl:
--------------------------------------------------------------------------------
1 | Edit Record
2 |
--------------------------------------------------------------------------------
/linodedns/client_templates/edit_zone.tpl:
--------------------------------------------------------------------------------
1 | DNS Zone For:
2 |
5 |
6 |
7 |
8 |
9 |
10 | Type
11 | Prefix
12 | Address
13 | Actions
14 |
15 |
16 |
17 | {foreach from=$api_result item=value}
18 |
19 | {$value.TYPE}
20 | {$value.NAME}
21 | {$value.TARGET|truncate}
22 |
23 | Edit Record
24 | Delete Record
25 |
26 |
27 | {/foreach}
28 |
29 |
--------------------------------------------------------------------------------
/linodedns/client_templates/linode_dns_main.tpl:
--------------------------------------------------------------------------------
1 | Manage DNS Zones
2 |
5 |
6 |
7 |
8 |
9 |
10 | Domain
11 | Actions
12 |
13 |
14 |
15 | {foreach from=$domains item=value name=domains}
16 |
17 | {$value}
18 |
19 | Edit Zone
20 |
21 |
22 | {/foreach}
23 |
24 |
--------------------------------------------------------------------------------
/linodedns/client_templates/submit_add_zone.tpl:
--------------------------------------------------------------------------------
1 | {if $api_error eq ''}
2 | Your Zone was added successfully
3 | {else}
4 | {$api_error}
5 | {/if}
--------------------------------------------------------------------------------
/linodedns/hooks.php:
--------------------------------------------------------------------------------
1 | Manage DNS Zones ";
43 | $footer_return .= "";
44 | $footer_return .= "";
45 | $footer_return .= " ";
46 | $footer_return .= "
";
47 | break;
48 | }
49 | }
50 | else
51 | {
52 | $footer_return = '';
53 | }
54 | }
55 | return $footer_return;
56 | }
57 | }
58 |
59 | function linodedns_dns_records($vars)
60 | {
61 | $sql3 = "SELECT * FROM tbladdonmodules WHERE module = 'linodedns'";
62 | $r3 = mysql_query($sql3);
63 | while ($row3=mysql_fetch_assoc($r3))
64 | {
65 | if($row3['setting'] == 'option1')
66 | {
67 | $option1 = $row3['value'];
68 | }
69 | if($row3['setting'] == 'option4')
70 | {
71 | $option4 = $row3['value'];
72 | }
73 | }
74 | if($vars['params']['type'] == 'hostingaccount' OR $vars['params']['type'] == 'reselleraccount')
75 | {
76 |
77 | require_once dirname(__FILE__) . "/linode_api/Services/Linode.php";
78 | $server_status = false;
79 | $domain = $vars['params']['domain'];
80 | $serverip = $vars['params']['serverip'];
81 | $serverid = $vars['params']['serverid'];
82 | $userid = $vars['params']['userid'];
83 | //$email = $vars['email'];
84 | $sql4 = "SELECT serverid FROM mod_linodedns_servers WHERE serverid = $serverid";
85 | $r4 = mysql_query($sql4);
86 | while ($row4=mysql_fetch_assoc($r4))
87 | {
88 | $server_status = true;
89 | break;
90 | }
91 | if($server_status == true)
92 | {
93 | $sql = "SELECT * FROM mod_linodedns_skeleton WHERE serverid = $serverid";
94 | $r = mysql_query($sql);
95 | // We will connect to the linode api in order to send information.
96 | try
97 | {
98 | $linode = new Services_Linode($option1);
99 | $linode->batching = true;
100 | $linode->domain_create(array('Domain' => $domain, 'Type' => 'Master', 'SOA_Email' => $option4));
101 | $result = $linode->batchFlush();
102 | $domain_id = $result[0]['DATA']['DomainID'];
103 | while ($row=mysql_fetch_assoc($r))
104 | {
105 | if($row['type'] == 'MX')
106 | {
107 | $linode->domain_resource_create(array('DomainID' => $domain_id, 'Type' => $row['type'], 'Target' => $row['prefix_name'].'.'.$domain, 'Priority' => $row['priority']));
108 | }
109 | elseif($row['type'] == 'A')
110 | {
111 | $linode->domain_resource_create(array('DomainID' => $domain_id, 'Type' => $row['type'], 'Name' => $row['prefix_name'], 'Target' => $serverip));
112 | }
113 | elseif($row['type'] == 'TXT')
114 | {
115 | $linode->domain_resource_create(array('DomainID' => $domain_id, 'Type' => $row['type'], 'Name' => $row['prefix_name'], 'Target' => $row['address']));
116 | }
117 | elseif($row['type'] == 'CNAME')
118 | {
119 | $linode->domain_resource_create(array('DomainID' => $domain_id, 'Type' => $row['type'], 'Name' => $row['prefix_name'], 'Target' => $row['address']));
120 | }
121 | }
122 | $result2 = $linode->batchFlush();
123 | $sql5 = "INSERT INTO mod_linodedns_access (`clientid`,`domainid`) VALUES($userid,$domain_id)";
124 | $r5 = mysql_query($sql5);
125 | }
126 |
127 | catch (Services_Linode_Exception $e)
128 | {
129 | echo $e->getMessage();
130 | }
131 | }
132 | }
133 | }
134 | // Define Client Login Hook Call
135 | add_hook("ClientAreaHomepage",1,"linodedns_clientgui");
136 | add_hook("AfterModuleCreate",1,"linodedns_dns_records");
137 | ?>
--------------------------------------------------------------------------------
/linodedns/lang/english.php:
--------------------------------------------------------------------------------
1 | DNS Skeleton
5 | Client Access Domains
6 | Servers
7 | ";
8 | $_ADDONLANG['documentation'] = "";
--------------------------------------------------------------------------------
/linodedns/linode_api/Linode/Exception.php:
--------------------------------------------------------------------------------
1 |
37 | * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
38 | * @version @package_version@
39 | * @link http://github.com/krmdrms/linode/
40 | * @link http://www.linode.com/api/autodoc.cfm
41 | */
42 |
43 | require_once 'PEAR/Exception.php';
44 |
45 | /**
46 | * Services_Linode_Exception
47 | *
48 | * @package Services_Linode
49 | * @category Services
50 | * @author Kerem Durmus
51 | * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
52 | * @version @package_version@
53 | * @link http://github.com/krmdrms/linode/
54 | * @link http://www.linode.com/api/autodoc.cfm
55 | */
56 | class Services_Linode_Exception extends PEAR_Exception {}
--------------------------------------------------------------------------------
/linodedns/linode_api/Services/Linode.php:
--------------------------------------------------------------------------------
1 |
37 | * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
38 | * @version @package_version@
39 | * @link http://github.com/krmdrms/linode/
40 | * @link http://www.linode.com/api/autodoc.cfm
41 | */
42 |
43 | require_once 'HTTP/Request2.php';
44 | require_once 'Services/Linode/Exception.php';
45 |
46 | /**
47 | * Services_Linode
48 | *
49 | * @package Services_Linode
50 | * @category Services
51 | * @author Kerem Durmus
52 | * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
53 | * @version @package_version@
54 | * @link http://github.com/krmdrms/linode/
55 | * @link http://www.linode.com/api/autodoc.cfm
56 | */
57 | class Services_Linode
58 | {
59 | /**
60 | * Request Url
61 | *
62 | * @var string $apiUrl
63 | */
64 | private static $apiUrl = 'https://api.linode.com/';
65 |
66 | /**
67 | * Default HTTP_Request2 config parameters
68 | *
69 | * @var array
70 | */
71 | private $httpConfig = array('ssl_verify_peer' => false);
72 |
73 | /**
74 | * Instance of {@link HTTP_Request2}
75 | *
76 | * @var object $request
77 | */
78 | protected $request;
79 |
80 | /**
81 | * API mapping. Constructed by api.xml
82 | *
83 | * @var array $api
84 | */
85 | protected $api = array();
86 |
87 | /**
88 | * Request array which will send to Linode Api
89 | *
90 | * @var array $requestArray
91 | */
92 | protected $requestArray = array();
93 |
94 | /**
95 | * Default API Response format
96 | *
97 | * @var string $responseFormat
98 | */
99 | protected $responseFormat = 'json';
100 |
101 | /**
102 | * Cache for batching request
103 | *
104 | * @var array $batchCache
105 | */
106 | protected $batchCache = array();
107 |
108 | /**
109 | * Linode API key
110 | *
111 | * @var string $api_key
112 | */
113 | public $apiKey;
114 |
115 | /**
116 | * Batching request
117 | *
118 | * @var bool
119 | */
120 | public $batching = false;
121 |
122 | /**
123 | * Constructor
124 | *
125 | * @param string $api_key Your linode api key
126 | * @param boolean $batch Enables batch request
127 | * @return void
128 | */
129 | public function __construct($apiKey = null, $batching = false)
130 | {
131 | if(!isset($apiKey)) {
132 | throw new Services_Linode_Exception('You must set your api key');
133 | }
134 | $this->apiKey = $apiKey;
135 | $this->batching = $batching;
136 | $this->loadAPI();
137 | }
138 |
139 | /**
140 | * Overloading method to call given api method and parameters
141 | *
142 | * @param string $method
143 | * @param array $args
144 | * @return array
145 | */
146 | public function __call($method, array $args = array())
147 | {
148 | $method = strtolower(str_replace('_','.',$method));
149 |
150 | if (isset($this->api[$method])) {
151 |
152 | list($method,$params) = $this->prepareRequest($this->api[$method],$args);
153 |
154 | if($this->batching == true) {
155 | $params['api_action'] = $method;
156 | $this->cacheParams($params);
157 | } else {
158 | $response = $this->sendRequest($method, $params);
159 | return $this->decodeBody($response);
160 | }
161 |
162 | } else {
163 | throw new Services_Linode_Exception('Unknown method: '.$method);
164 | }
165 | }
166 |
167 | /**
168 | * Sends cached api requests to api
169 | *
170 | * @return array
171 | */
172 | public function batchFlush()
173 | {
174 | $this->setParam('api_requestArray', json_encode($this->batchCache));
175 | $response = $this->sendRequest('batch');
176 |
177 | return $this->decodeBody($response);
178 | }
179 |
180 | /**
181 | * Cache api requests when batching enabled
182 | *
183 | * @var array $params
184 | * @return void
185 | */
186 | protected function cacheParams($params)
187 | {
188 | $this->batchCache[] = $params;
189 | }
190 |
191 | /**
192 | * Sets api request parameter
193 | *
194 | * @param string $key
195 | * @param string $value
196 | * @return void
197 | */
198 | protected function setParam($key,$value)
199 | {
200 | $this->requestArray[$key] = $value;
201 | }
202 |
203 | /**
204 | * Returns set parameters
205 | *
206 | * @return array
207 | */
208 | protected function getParams()
209 | {
210 | return $this->requestArray;
211 | }
212 |
213 | /**
214 | * Returns the HTTP_Request2 instance.
215 | *
216 | * @return object
217 | */
218 | protected function httpRequest()
219 | {
220 | if ($this->request === null) {
221 | $this->request = new HTTP_Request2();
222 | $this->request->setConfig($this->httpConfig);
223 | $this->request->setMethod(HTTP_Request2::METHOD_POST);
224 | $this->request->setUrl(self::$apiUrl);
225 | $this->request->setHeader(array('User-Agent' => 'Linode PHP/@package_version@'));
226 | }
227 |
228 | return $this->request;
229 | }
230 |
231 | /**
232 | * Send request to api
233 | *
234 | * @var $method
235 | * @var $params
236 | * @return array
237 | */
238 | protected function sendRequest($method, $params = null)
239 | {
240 |
241 | $this->setParam('api_key', $this->apiKey);
242 | $this->setParam('api_responseFormat', $this->responseFormat);
243 | $this->setParam('api_action', $method);
244 |
245 | if($this->batching == false) {
246 | foreach($params as $param => $value) {
247 | $this->setParam($param,$value);
248 | }
249 | }
250 |
251 | try {
252 | $request = clone $this->httpRequest();
253 | $request->addPostParameter($this->requestArray);
254 | $response = $request->send();
255 | } catch(HTTP_Request2_Exception $e) {
256 | throw new Services_Linode_Exception($e->getMessage());
257 | }
258 |
259 | return $response->getBody();
260 | }
261 |
262 | /**
263 | * Decodes body
264 | *
265 | * @var string $body
266 | * @return array
267 | */
268 | protected function decodeBody($body)
269 | {
270 | if($this->responseFormat = 'json') {
271 | $decoded_body = json_decode($body, TRUE);
272 | } else {
273 | $decoded_body = $body;
274 | }
275 |
276 | return $decoded_body;
277 | }
278 |
279 | /**
280 | * Validates argument and prepare to request
281 | *
282 | * @var $method
283 | * @var $args
284 | * @return array
285 | */
286 | protected function prepareRequest($method, array $args = array())
287 | {
288 | $count_args = count($method->xpath('param[@required="true" or @required="1"]'));
289 |
290 | $path = (string) $method['name'];
291 | $params = array();
292 |
293 | if ($count_args && (!isset($args[0]) || is_array($args[0]) && $count_args > count($args[0]))) {
294 | throw new Services_Linode_Exception(
295 | 'Not enough arguments for '.$path
296 | );
297 | }
298 | $req_args = $count_args;
299 |
300 | foreach($method->param as $param) {
301 | $name = (string) $param['name'];
302 | $type = (string) $param['type'];
303 | $required = (string) $param['required'] == 'true' || $req_args;
304 |
305 | if ($required && !is_array($args[0])) {
306 | $arg = array_shift($args);
307 | $req_args--;
308 | } else if (isset($args[0][$name])) {
309 | $arg = $args[0][$name];
310 | $req_args--;
311 | } else {
312 | continue;
313 | }
314 |
315 | try {
316 | $this->validateArg($name, $arg , $type);
317 | } catch (Services_Linode_Exception $e) {
318 | echo $e->getMessage();
319 | }
320 |
321 | $params[$name] = $arg;
322 | }
323 | return array($path,$params);
324 | }
325 |
326 | /**
327 | * Validates an argument according to api xml mapping
328 | *
329 | * @var $name
330 | * @var $val
331 | * @var $type
332 | * @return void
333 | */
334 | protected function validateArg($name, &$val, $type)
335 | {
336 | $msg = null;
337 | switch ($type) {
338 | case 'boolean':
339 | if (!is_bool($val)) {
340 | $msg = $name . ' must be a boolean';
341 | }
342 | $val = $val ? 'true' : 'false';
343 | break;
344 | case 'integer':
345 | if (!is_numeric($val)) {
346 | $msg = $name . ' must be an integer';
347 | }
348 | break;
349 | case 'string':
350 | if (!is_string($val)) {
351 | $msg = $name . ' must be a string';
352 | }
353 | break;
354 | }
355 |
356 | if ($msg !== null) {
357 | throw new Services_Linode_Exception($msg);
358 | }
359 | }
360 |
361 | /**
362 | * Loads the XML API definition.
363 | *
364 | * @return void
365 | */
366 | protected function loadAPI()
367 | {
368 | $filePath = dirname(__FILE__) . "/Services_Linode/";
369 | $feed = file_get_contents($filePath.'api.xml');
370 | $xmlApi = simplexml_load_string($feed);
371 | foreach ($xmlApi->method as $method) {
372 | $method_name = (string) $method['name'];
373 | $this->api[$method_name] = $method;
374 | }
375 | }
376 | }
--------------------------------------------------------------------------------
/linodedns/linode_api/Services/Services_Linode/api.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
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 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
--------------------------------------------------------------------------------
/linodedns/linode_api/Services/api.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
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 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
--------------------------------------------------------------------------------
/linodedns/linodedns.php:
--------------------------------------------------------------------------------
1 | "Linode DNS Manager",
22 | "description" => "Linode API DNS Manager. For client control of DNS records and Domains, and automation of DNS Entries.",
23 | "version" => "1.1",
24 | "author" => "PurdyDesigns",
25 | "language" => "english",
26 | "fields" => array(
27 | "option1" => array ("FriendlyName" => "Linode API Key", "Type" => "text", "Size" => "25", "Description" => "Enter your linode api key. You can get your api key from your account at linode.", "Default" => "API KEY", ),
28 | "option3" => array ("FriendlyName" => "Enable SSL", "Type" => "yesno", "Size" => "25", "Description" => "To force ssl on client area. If your using forced ssl in whmcs you should set to true. Otherwise set to false", "Default" => "", ),
29 | "option4" => array ("FriendlyName" => "SOA Email", "Type" => "text", "Size" => "25", "Description" => "Enter your email address for zone creation (required by linode api)", "Default" => "email address", ),
30 | "option5" => array ("FriendlyName" => "Homepage Display", "Type" => "yesno", "Size" => "25", "Description" => "To Enable Client Area Homepage Access (you will need to create your own access point if you disable)", "Default" => "", ),
31 | ));
32 | return $configarray;
33 | }
34 |
35 | function linodedns_activate() {
36 |
37 | # Create Custom DB Table
38 | $query = "CREATE TABLE `mod_linodedns_access` (`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,`clientid` INT( 11 ) NOT NULL, `domainid` INT( 11 ) NOT NULL )";
39 | $result = full_query($query);
40 |
41 | $query = "CREATE TABLE `mod_linodedns_servers` (`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,`serverid` INT( 11 ) NOT NULL)";
42 | $result = full_query($query);
43 |
44 | $query = "CREATE TABLE `mod_linodedns_skeleton` (`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY, `serverid` int( 11 ) NOT NULL ,`type` enum('MX','A','CNAME','TXT') NOT NULL, `prefix_name` varchar( 100 ) NOT NULL ,`address` varchar( 100 ) NOT NULL,`priority` int( 11 ) NOT NULL,`ttl` INT( 11 ) NOT NULL)";
45 | $result = full_query($query);
46 |
47 | $sql22 = "SELECT id FROM tblservers";
48 | $r22 = mysql_query($sql22);
49 | while ($row22=mysql_fetch_assoc($r22))
50 | {
51 | $sid = $row22['id'];
52 | $query2 = "INSERT INTO `mod_linodedns_skeleton` (`serverid`, `type`, `prefix_name`, `address`, `priority`, `ttl`) VALUES($sid, 'MX', 'mail', '', 10, 3600),($sid, 'A', '', '', 0, 3600),($sid, 'A', 'www', '', 0, 3600),($sid, 'A', '*', '', 0, 3600),($sid, 'A', 'mail', '', 0, 3600)";
53 | $result = full_query($query2);
54 | }
55 |
56 | # Return Result
57 | return array('status'=>'success','description'=>'Module has been activated successfully. Select your servers you wish to use the linode DNS manager. For pre-existing clients you will need to manually provide access to domains.');
58 | return array('status'=>'error','description'=>'Error installing module.');
59 | return array('status'=>'info','description'=>'');
60 |
61 | }
62 |
63 | function linodedns_deactivate() {
64 |
65 | # Remove Custom DB Table
66 | $query = "DROP TABLE `mod_linodedns_access`";
67 | $result = full_query($query);
68 |
69 | $query = "DROP TABLE `mod_linodedns_servers`";
70 | $result = full_query($query);
71 |
72 | $query = "DROP TABLE `mod_linodedns_skeleton`";
73 | $result = full_query($query);
74 |
75 | # Return Result
76 | return array('status'=>'success','description'=>'If successful, you can return a message to show the user here');
77 | return array('status'=>'error','description'=>'If an error occurs you can return an error message for display here');
78 | return array('status'=>'info','description'=>'If you want to give an info message to a user you can return it here');
79 |
80 | }
81 |
82 | function linodedns_upgrade($vars) {
83 |
84 | $version = $vars['version'];
85 | /*
86 | # Run SQL Updates for V1.0 to V1.1
87 | if ($version < 1.1) {
88 | $query = "ALTER `mod_addonexample` ADD `demo2` TEXT NOT NULL ";
89 | $result = full_query($query);
90 | }
91 |
92 | # Run SQL Updates for V1.1 to V1.2
93 | if ($version < 1.2) {
94 | $query = "ALTER `mod_addonexample` ADD `demo3` TEXT NOT NULL ";
95 | $result = full_query($query);
96 | }
97 | */
98 | }
99 |
100 | function linodedns_output($vars) {
101 | $modulelink = $vars['modulelink'];
102 | $version = $vars['version'];
103 | $option1 = $vars['option1'];
104 | $option3 = $vars['option3'];
105 | $option4 = $vars['option4'];
106 | $LANG = $vars['_lang'];
107 |
108 | require_once dirname(__FILE__) . "/linode_api/Services/Linode.php";
109 |
110 | if (!empty($_REQUEST['action'])){
111 | $action = $_REQUEST['action'];
112 | }else{
113 | $action = 'default';
114 | }
115 | if ('servers'==$action){
116 | $sql = "SELECT id,name FROM tblservers ORDER BY id ASC";
117 | $r = mysql_query($sql);
118 | }
119 |
120 | if ('link_accounts'==$action){
121 | $linode = new Services_Linode($option1);
122 | $linode->batching = true;
123 | $linode->domain_list();
124 | $api_r = $linode->batchFlush();
125 | for($i = 0; $i<=count($api_r[0]['DATA']);$i++)
126 | {
127 | $domain = $api_r[0]['DATA'][$i]['DOMAIN'];
128 | //echo $api_r[0]['DATA'][$i]['DOMAIN'];
129 | $sql = "SELECT userid,domain FROM tblhosting WHERE domain = '$domain'";
130 | $r = mysql_query($sql);
131 | while ($row=mysql_fetch_assoc($r))
132 | {
133 | //echo "test";
134 | $clientid = $row['userid'];
135 | $domain_id = $api_r[0]['DATA'][$i]['DOMAINID'];
136 | $sql3 = "SELECT * from mod_linodedns_access WHERE clientid = $clientid AND domainid = $domain_id";
137 | $r3 = mysql_query($sql3);
138 | if(mysql_fetch_assoc($r3))
139 | {
140 | while ($row3=mysql_fetch_assoc($r3))
141 | {
142 | $sql2 = "INSERT INTO mod_linodedns_access (`clientid`,`domainid`) VALUES($clientid,$domain_id)";
143 | $r2 = mysql_query($sql2);
144 | }
145 | }
146 | else
147 | {
148 | $sql2 = "INSERT INTO mod_linodedns_access (`clientid`,`domainid`) VALUES($clientid,$domain_id)";
149 | $r2 = mysql_query($sql2);
150 | }
151 | }
152 | }
153 | }
154 |
155 | if ('servers_submit'==$action)
156 | {
157 | $sql = "TRUNCATE TABLE mod_linodedns_servers";
158 | $r = mysql_query($sql);
159 | if (isset($_POST['server_id'])) {
160 | $server_ids = $_POST['server_id'];
161 | }
162 | //print_r($server_ids);
163 | for($i = 0; $i <= count($server_ids); $i++)
164 | {
165 | $sql2 = "INSERT INTO mod_linodedns_servers (`serverid`) VALUES($server_ids[$i])";
166 | $r2 = mysql_query($sql2);
167 | }
168 | }
169 |
170 | if ('dnsskeleton'==$action){
171 | $sql = "SELECT * FROM mod_linodedns_skeleton";
172 | $r = mysql_query($sql);
173 | }
174 |
175 | if ('skeleton_add'==$action){
176 | }
177 |
178 | if ('submit_skeleton_add'==$action){
179 | $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
180 | $serverid = $_POST['serverid'];
181 | $type = $_POST['type'];
182 | $prefix_name = $_POST['prefix_name'];
183 | $address = $_POST['address'];
184 | $priority = $_POST['priority'];
185 | $ttl = $_POST['ttl'];
186 | //print_r($_POST);
187 | $sql2 = "INSERT INTO mod_linodedns_skeleton (`serverid`,`prefix_name`,`address`,`priority`,`ttl`,`type`) VALUES($serverid,'$prefix_name','$address',$priority,$ttl,$type)";
188 | $r2 = mysql_query($sql2);
189 | }
190 |
191 | if ('skeleton_edit'==$action){
192 | if($_REQUEST['rid'] == '')
193 | {
194 | }
195 | else
196 | {
197 | $rid = $_REQUEST['rid'];
198 | $sql = "SELECT * FROM mod_linodedns_skeleton WHERE id = $rid";
199 | $r = mysql_query($sql);
200 | }
201 | }
202 |
203 | if ('submit_skeleton_edit'==$action){
204 | if($_REQUEST['rid'] == '')
205 | {
206 | }
207 | else
208 | {
209 | $rid = $_REQUEST['rid'];
210 | $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
211 | $serverid = $_POST['serverid'];
212 | $type = $_POST['type'];
213 | $prefix_name = $_POST['prefix_name'];
214 | $address = $_POST['address'];
215 | $priority = $_POST['priority'];
216 | $ttl = $_POST['ttl'];
217 | //print_r($_POST);
218 | $sql2 = "UPDATE mod_linodedns_skeleton SET serverid = $serverid, type = $type, prefix_name = '$prefix_name', address = '$address', priority = $priority, ttl = $ttl WHERE id = $rid";
219 | $r2 = mysql_query($sql2);
220 | }
221 | }
222 |
223 | if ('skeleton_delete'==$action){
224 | if($_REQUEST['rid'] == '')
225 | {
226 | }
227 | else
228 | {
229 | $rid = $_REQUEST['rid'];
230 | $sql = "DELETE FROM mod_linodedns_skeleton WHERE id = $rid";
231 | $r = mysql_query($sql);
232 | }
233 | }
234 |
235 | if ('clientaccess'==$action){
236 | $sql = "SELECT id,firstname,lastname FROM tblclients ORDER BY firstname ASC";
237 | $r = mysql_query($sql);
238 | $sql2 = "SELECT id,firstname,lastname FROM tblclients ORDER BY firstname ASC";
239 | $r2 = mysql_query($sql2);
240 | try
241 | {
242 | $linode = new Services_Linode($option1);
243 | $linode->batching = true;
244 | $linode->domain_list();
245 | $api_r = $linode->batchFlush();
246 | }
247 | catch (Services_Linode_Exception $e)
248 | {
249 | echo $e->getMessage();
250 | }
251 | }
252 |
253 | if ('client_add_submit'==$action){
254 | $clientid = $_POST['clientid_add'];
255 | $domainid = $_POST['domainid_add'];
256 | $exists = false;
257 | $sql = "SELECT id FROM mod_linodedns_access WHERE clientid = $clientid AND domainid = $domainid";
258 | $r = mysql_query($sql);
259 | while ($row=mysql_fetch_assoc($r))
260 | {
261 | $exists = true;
262 | }
263 | if($exists == false)
264 | {
265 | $sql2 = "INSERT INTO mod_linodedns_access (`clientid`,`domainid`) VALUES($clientid,$domainid)";
266 | $r2 = mysql_query($sql2);
267 | }
268 | }
269 |
270 | if ('client_remove_submit'==$action){
271 | $clientid = $_POST['clientid_remove'];
272 | $domainid = $_POST['domainid_remove'];
273 | $sql = "DELETE FROM mod_linodedns_access WHERE clientid = $clientid AND domainid = $domainid";
274 | $r = mysql_query($sql);
275 | }
276 |
277 | echo ''.$LANG['intro'].'
278 | '.$LANG['description'].'
279 | '.$LANG['documentation'].'
';
280 |
281 | $view['global']['mod_action_url'] = $view['global']['mod_url'] . '&action=' . $action;
282 | $view['global']['action'] = $action;
283 |
284 | include dirname(__FILE__) . '/templates/' . $action . '.php';
285 |
286 | }
287 |
288 | function linodedns_sidebar($vars) {
289 |
290 | $modulelink = $vars['modulelink'];
291 | $version = $vars['version'];
292 | $option1 = $vars['option1'];
293 | $option3 = $vars['option3'];
294 | $option4 = $vars['option4'];
295 | $LANG = $vars['_lang'];
296 |
297 | $sidebar = '
298 | ';
301 | return $sidebar;
302 |
303 | }
304 |
305 | function linodedns_clientarea($vars)
306 | {
307 | $modulelink = $vars['modulelink'];
308 | $version = $vars['version'];
309 | $option1 = $vars['option1'];
310 | $option3 = $vars['option3'];
311 | $option4 = $vars['option4'];
312 | $option5 = $vars['option5'];
313 |
314 | if($option3 == 'on')
315 | {
316 | $ssl = true;
317 | }
318 | elseif($option3 == '')
319 | {
320 |
321 | $ssl = false;
322 | }
323 |
324 | require_once dirname(__FILE__) . "/linode_api/Services/Linode.php";
325 |
326 | if (!empty($_REQUEST['action'])){
327 | $action = $_REQUEST['action'];
328 | }else{
329 | $action = 'default';
330 | }
331 | if ('edit_zone'==$action)
332 | {
333 | $client_id = $_SESSION['uid'];
334 |
335 | if(!empty($_REQUEST['did']))
336 | {
337 | $did = $_REQUEST['did'];
338 | }
339 | else
340 | {
341 | $did = '';
342 | }
343 | if($did != '')
344 | {
345 | $sql = "SELECT clientid,domainid FROM mod_linodedns_access WHERE domainid = $did";
346 | $r = mysql_query($sql);
347 | while ($row=mysql_fetch_assoc($r))
348 | {
349 | $cid = $row['clientid'];
350 | }
351 | if($cid == $client_id)
352 | {
353 | $linode = new Services_Linode($option1);
354 | $linode->batching = true;
355 | $linode->domain_resource_list(array('DomainID' => $did));
356 | $api_r = $linode->batchFlush();
357 | return array
358 | (
359 | 'pagetitle' => 'DNS Management',
360 | 'templatefile' => 'client_templates/edit_zone',
361 | 'requirelogin' => true,
362 | 'forcessl' => $ssl,
363 | 'vars' => array
364 | (
365 | 'api_result' => $api_r[0]['DATA'],
366 | 'domain_id' => $api_r[0]['DATA'][0]['DOMAINID']
367 | )
368 | );
369 | }
370 | else
371 | {
372 | return array
373 | (
374 | 'pagetitle' => 'DNS Management',
375 | 'templatefile' => 'client_templates/access_error',
376 | 'requirelogin' => true,
377 | 'forcessl' => $ssl,
378 | );
379 | }
380 | }
381 | }
382 |
383 | if ('add_record'==$action)
384 | {
385 | $client_id = $_SESSION['uid'];
386 |
387 | if(!empty($_REQUEST['did']))
388 | {
389 | $did = $_REQUEST['did'];
390 | }
391 | else
392 | {
393 | $did = '';
394 | }
395 | if($did != '')
396 | {
397 | $sql = "SELECT clientid,domainid FROM mod_linodedns_access WHERE domainid = $did";
398 | $r = mysql_query($sql);
399 | while ($row=mysql_fetch_assoc($r))
400 | {
401 | $cid = $row['clientid'];
402 | }
403 | if($cid == $client_id)
404 | {
405 | return array
406 | (
407 | 'pagetitle' => 'DNS Management',
408 | 'templatefile' => 'client_templates/add_record',
409 | 'requirelogin' => true,
410 | 'forcessl' => $ssl,
411 | 'vars' => array
412 | (
413 | 'did' => $did,
414 | )
415 | );
416 | }
417 | else
418 | {
419 | return array
420 | (
421 | 'pagetitle' => 'DNS Management',
422 | 'templatefile' => 'client_templates/access_error',
423 | 'requirelogin' => true,
424 | 'forcessl' => $ssl,
425 | );
426 | }
427 | }
428 | }
429 | if ('submit_add_record'==$action)
430 | {
431 | $client_id = $_SESSION['uid'];
432 |
433 | if(!empty($_REQUEST['did']))
434 | {
435 | $did = $_REQUEST['did'];
436 | }
437 | else
438 | {
439 | $did = '';
440 | }
441 | if($did != '')
442 | {
443 | $sql = "SELECT clientid,domainid FROM mod_linodedns_access WHERE domainid = $did";
444 | $r = mysql_query($sql);
445 | while ($row=mysql_fetch_assoc($r))
446 | {
447 | $cid = $row['clientid'];
448 | }
449 | if($cid == $client_id)
450 | {
451 | $linode = new Services_Linode($option1);
452 | $linode->batching = true;
453 | if($_POST['type'] == 'MX')
454 | {
455 | $linode->domain_resource_create(array('DomainID' => $did, 'Type' => $_POST['type'], 'Target' => $_POST['prefix_name'], 'Priority' => $_POST['priority'], 'TTL_sec' => $_POST['ttl']));
456 | }
457 | elseif($_POST['type'] == 'A')
458 | {
459 | $linode->domain_resource_create(array('DomainID' => $did, 'Type' => $_POST['type'], 'Name' => $_POST['prefix_name'], 'Target' => $_POST['address'], 'TTL_sec' => $_POST['ttl']));
460 | }
461 | elseif($_POST['type'] == 'TXT')
462 | {
463 | $linode->domain_resource_create(array('DomainID' => $did, 'Type' => $_POST['type'], 'Name' => $_POST['prefix_name'], 'Target' => $_POST['address'], 'TTL_sec' => $_POST['ttl']));
464 | }
465 | elseif($_POST['type'] == 'CNAME')
466 | {
467 | $linode->domain_resource_create(array('DomainID' => $did, 'Type' => $_POST['type'], 'Name' => $_POST['prefix_name'], 'Target' => $_POST['address'], 'TTL_sec' => $_POST['ttl']));
468 | }
469 | $api_r = $linode->batchFlush();
470 | $url='index.php?m=linodedns&action=edit_zone&did='.$did;
471 | header("Location: ".$url);
472 | }
473 | }
474 | }
475 |
476 | if ('edit_record'==$action)
477 | {
478 | $client_id = $_SESSION['uid'];
479 |
480 | if(!empty($_REQUEST['did']))
481 | {
482 | $did = $_REQUEST['did'];
483 | }
484 | else
485 | {
486 | $did = '';
487 | }
488 | if($did != '')
489 | {
490 | $sql = "SELECT clientid,domainid FROM mod_linodedns_access WHERE domainid = $did";
491 | $r = mysql_query($sql);
492 | while ($row=mysql_fetch_assoc($r))
493 | {
494 | $cid = $row['clientid'];
495 | }
496 | if($cid == $client_id)
497 | {
498 | if(!empty($_REQUEST['drid']))
499 | {
500 | $drid = $_REQUEST['drid'];
501 | $linode = new Services_Linode($option1);
502 | $linode->batching = true;
503 | $linode->domain_resource_list(array('DomainID' => $did, 'ResourceID' => $drid));
504 | $api_r = $linode->batchFlush();
505 | return array
506 | (
507 | 'pagetitle' => 'DNS Management',
508 | 'templatefile' => 'client_templates/edit_record',
509 | 'requirelogin' => true,
510 | 'forcessl' => $ssl,
511 | 'vars' => array
512 | (
513 | 'did' => $did,
514 | 'drid' => $drid,
515 | 'api_result' => $api_r[0]['DATA']
516 | )
517 | );
518 | }
519 | else
520 | {
521 | return array
522 | (
523 | 'pagetitle' => 'DNS Management',
524 | 'templatefile' => 'client_templates/access_error',
525 | 'requirelogin' => true,
526 | 'forcessl' => $ssl,
527 | );
528 | }
529 | }
530 | }
531 | }
532 |
533 | if ('submit_edit_record'==$action)
534 | {
535 | $client_id = $_SESSION['uid'];
536 |
537 | if(!empty($_REQUEST['did']))
538 | {
539 | $did = $_REQUEST['did'];
540 | }
541 | else
542 | {
543 | $did = '';
544 | }
545 | if($did != '')
546 | {
547 | $sql = "SELECT clientid,domainid FROM mod_linodedns_access WHERE domainid = $did";
548 | $r = mysql_query($sql);
549 | while ($row=mysql_fetch_assoc($r))
550 | {
551 | $cid = $row['clientid'];
552 | }
553 | if($cid == $client_id)
554 | {
555 | if(!empty($_REQUEST['drid']))
556 | {
557 | $drid = $_REQUEST['drid'];
558 | $linode = new Services_Linode($option1);
559 | $linode->batching = true;
560 | if($_POST['type'] == 'MX')
561 | {
562 | $linode->domain_resource_update(array('DomainID' => $did, 'ResourceID' => $drid, 'Type' => $_POST['type'], 'Target' => $_POST['prefix_name'], 'Priority' => $_POST['priority'], 'TTL_sec' => $_POST['ttl']));
563 | }
564 | elseif($_POST['type'] == 'A')
565 | {
566 | $linode->domain_resource_update(array('DomainID' => $did, 'ResourceID' => $drid, 'Type' => $_POST['type'], 'Name' => $_POST['prefix_name'], 'Target' => $_POST['address'], 'TTL_sec' => $_POST['ttl']));
567 | }
568 | elseif($_POST['type'] == 'TXT')
569 | {
570 | $linode->domain_resource_update(array('DomainID' => $did, 'ResourceID' => $drid, 'Type' => $_POST['type'], 'Name' => $_POST['prefix_name'], 'Target' => $_POST['address'], 'TTL_sec' => $_POST['ttl']));
571 | }
572 | elseif($_POST['type'] == 'CNAME')
573 | {
574 | $linode->domain_resource_update(array('DomainID' => $did, 'ResourceID' => $drid, 'Type' => $_POST['type'], 'Name' => $_POST['prefix_name'], 'Target' => $_POST['address'], 'TTL_sec' => $_POST['ttl']));
575 | }
576 | $api_r = $linode->batchFlush();
577 | $url='index.php?m=linodedns&action=edit_zone&did='.$did;
578 | header("Location: ".$url);
579 | }
580 | }
581 | }
582 | }
583 |
584 | if ('delete_record'==$action)
585 | {
586 | $client_id = $_SESSION['uid'];
587 |
588 | if(!empty($_REQUEST['did']))
589 | {
590 | $did = $_REQUEST['did'];
591 | }
592 | else
593 | {
594 | $did = '';
595 | }
596 | if($did != '')
597 | {
598 | $sql = "SELECT clientid,domainid FROM mod_linodedns_access WHERE domainid = $did";
599 | $r = mysql_query($sql);
600 | while ($row=mysql_fetch_assoc($r))
601 | {
602 | $cid = $row['clientid'];
603 | }
604 | if($cid == $client_id)
605 | {
606 | if(!empty($_REQUEST['drid']))
607 | {
608 | $drid = $_REQUEST['drid'];
609 | $linode = new Services_Linode($option1);
610 | $linode->batching = true;
611 | $linode->domain_resource_delete(array('DomainID' => $did, 'ResourceID' => $drid));
612 | $api_r = $linode->batchFlush();
613 | $url='index.php?m=linodedns&action=edit_zone&did='.$did;
614 | header("Location: ".$url);
615 | }
616 |
617 | }
618 | else
619 | {
620 | return array
621 | (
622 | 'pagetitle' => 'DNS Management',
623 | 'templatefile' => 'client_templates/access_error',
624 | 'requirelogin' => true,
625 | 'forcessl' => $ssl,
626 | );
627 | }
628 | }
629 | }
630 |
631 | if ('add_zone'==$action)
632 | {
633 | $server_status = false;
634 | $client_id = $_SESSION['uid'];
635 | $ip_array = array();
636 | $active = 'Active';
637 | $sql = "SELECT dedicatedip,server,domainstatus FROM tblhosting WHERE userid = $client_id";
638 | $r = mysql_query($sql);
639 | while ($row=mysql_fetch_assoc($r))
640 | {
641 | if($row['domainstatus'] == 'Active' AND $row['server'] != '0')
642 | {
643 | if($row['dedicatedip'] == '')
644 | {
645 | }
646 | else
647 | {
648 | array_push($ip_array, $row['dedicatedip']);
649 | }
650 | $server_id = $row['server'];
651 | $sql2 = "SELECT ipaddress FROM tblservers WHERE id = $server_id";
652 | $r2 = mysql_query($sql2);
653 | while ($row2=mysql_fetch_assoc($r2))
654 | {
655 | if(in_array($row2['ipaddress'], $ip_array))
656 | {
657 | }
658 | else
659 | {
660 | $server_id = $row['server'];
661 | $sql4 = "SELECT serverid FROM mod_linodedns_servers WHERE serverid = $server_id";
662 | $r4 = mysql_query($sql4);
663 | while ($row4=mysql_fetch_assoc($r4))
664 | {
665 | array_push($ip_array, $row2['ipaddress']);
666 | }
667 | }
668 | }
669 |
670 | $server_id = $row['server'];
671 | $sql3 = "SELECT serverid FROM mod_linodedns_servers WHERE serverid = $server_id";
672 | $r3 = mysql_query($sql3);
673 | while ($row3=mysql_fetch_assoc($r3))
674 | {
675 | $server_status = true;
676 | break;
677 | }
678 | }
679 | else
680 | {
681 | }
682 | }
683 | if($server_status == true)
684 | {
685 | return array
686 | (
687 | 'pagetitle' => 'DNS Management',
688 | 'templatefile' => 'client_templates/add_zone',
689 | 'requirelogin' => true,
690 | 'forcessl' => $ssl,
691 | 'vars' => array
692 | (
693 | 'ips' => $ip_array,
694 | )
695 | );
696 | }
697 | }
698 |
699 | if ('submit_add_zone'==$action)
700 | {
701 | if($_POST['domain'] == '')
702 | {
703 | }
704 | else
705 | {
706 | if($_POST['ip_address'] == '')
707 | {
708 | }
709 | else
710 | {
711 | $client_id = $_SESSION['uid'];
712 | $cur_ip = $_POST['ip_address'];
713 |
714 | //check for dedicated ip address
715 | $sql4 = "SELECT server FROM tblhosting WHERE userid = $client_id AND dedicatedip = '$cur_ip'";
716 | $r4 = mysql_query($sql4);
717 | while ($row4=mysql_fetch_assoc($r4))
718 | {
719 | $sid = $row4['server'];
720 | }
721 |
722 | //check for dedicated ip address
723 | $sql2 = "SELECT id FROM tblservers WHERE ipaddress = '$cur_ip'";
724 | $r2 = mysql_query($sql2);
725 | while ($row2=mysql_fetch_assoc($r2))
726 | {
727 | $sid = $row2['id'];
728 | }
729 | //echo $sid;
730 | $sql = "SELECT * FROM mod_linodedns_skeleton WHERE serverid = '$sid'";
731 | $r = mysql_query($sql);
732 | $linode = new Services_Linode($option1);
733 | $linode->batching = true;
734 | $linode->domain_create(array('Domain' => $_POST['domain'], 'Type' => 'Master', 'SOA_Email' => $option4));
735 | $api_r = $linode->batchFlush();
736 | $domain_id = $api_r[0]['DATA']['DomainID'];
737 | while ($row=mysql_fetch_assoc($r))
738 | {
739 | if($row['type'] == 'MX')
740 | {
741 | $linode->domain_resource_create(array('DomainID' => $domain_id, 'Type' => $row['type'], 'Target' => $row['prefix_name'].'.'.$_POST['domain'], 'Priority' => $row['priority']));
742 | }
743 | elseif($row['type'] == 'A')
744 | {
745 | $linode->domain_resource_create(array('DomainID' => $domain_id, 'Type' => $row['type'], 'Name' => $row['prefix_name'], 'Target' => $_POST['ip_address']));
746 | }
747 | elseif($row['type'] == 'TXT')
748 | {
749 | $linode->domain_resource_create(array('DomainID' => $domain_id, 'Type' => $row['type'], 'Name' => $row['prefix_name'], 'Target' => $row['address']));
750 | }
751 | elseif($row['type'] == 'CNAME')
752 | {
753 | $linode->domain_resource_create(array('DomainID' => $domain_id, 'Type' => $row['type'], 'Name' => $row['prefix_name'], 'Target' => $row['address']));
754 | }
755 | }
756 | $result2 = $linode->batchFlush();
757 | $sql5 = "INSERT INTO mod_linodedns_access (`clientid`,`domainid`) VALUES($client_id,$domain_id)";
758 | $r5 = mysql_query($sql5);
759 | //print_r($api_r);
760 | }
761 | }
762 | }
763 |
764 | //We need to determine which domains this user has access too
765 | $client_id = $_SESSION['uid'];
766 | $sql = "SELECT clientid,domainid FROM mod_linodedns_access WHERE clientid = $client_id";
767 | $r = mysql_query($sql);
768 | $domain_ids = array();
769 | $domains = array();
770 | while ($row=mysql_fetch_assoc($r))
771 | {
772 | array_push($domain_ids, $row['domainid']);
773 | }
774 |
775 | for($i = 0; $i <= count($domain_ids) -1; $i++)
776 | {
777 | $linode = new Services_Linode($option1);
778 | $linode->batching = true;
779 | $linode->domain_list(array('DomainID' => $domain_ids[$i]));
780 | $api_r = $linode->batchFlush();
781 | //print_r($api_r);
782 | array_push($domains, $api_r[0]['DATA'][0]['DOMAIN']);
783 | }
784 | //print_r($domain_ids);
785 | $server_status = false;
786 | $sql = "SELECT dedicatedip,server,domainstatus FROM tblhosting WHERE userid = $client_id";
787 | $r = mysql_query($sql);
788 | while ($row=mysql_fetch_assoc($r))
789 | {
790 | if($row['domainstatus'] == 'Active' AND $row['server'] != '0')
791 | {
792 | $server_id = $row['server'];
793 | $sql2 = "SELECT ipaddress FROM tblservers WHERE id = $server_id";
794 | $r2 = mysql_query($sql2);
795 | while ($row2=mysql_fetch_assoc($r2))
796 | {
797 | $server_id = $row['server'];
798 | $sql3 = "SELECT serverid FROM mod_linodedns_servers WHERE serverid = $server_id";
799 | $r3 = mysql_query($sql3);
800 | while ($row3=mysql_fetch_assoc($r3))
801 | {
802 | $server_status = true;
803 | }
804 | }
805 | }
806 | }
807 | if($server_status == true)
808 | {
809 | return array(
810 |
811 | 'pagetitle' => 'DNS Management',
812 | 'templatefile' => 'client_templates/linode_dns_main',
813 | 'requirelogin' => true,
814 | 'forcessl' => $ssl,
815 | 'vars' => array(
816 | 'domain_ids' => $domain_ids,
817 | 'domains' => $domains
818 | )
819 |
820 | );
821 | }
822 | else
823 | {
824 | return array(
825 |
826 | 'pagetitle' => 'DNS Management',
827 | 'templatefile' => 'client_templates/access_error',
828 | 'requirelogin' => true,
829 | 'forcessl' => $ssl,
830 |
831 | );
832 | }
833 | }
--------------------------------------------------------------------------------
/linodedns/templates/clientaccess.php:
--------------------------------------------------------------------------------
1 |
4 | Client Domain Access
5 | Below you can select which clients have access to specific domain zone files. Simply select the client, and check off what domains they have access too.
6 |
7 | Add Access
8 |
23 |
24 | Remove Access
25 |
--------------------------------------------------------------------------------
/linodedns/templates/dnsskeleton.php:
--------------------------------------------------------------------------------
1 | DNS Skeleton
2 | Here you can control the default DNS Records that are created when a customer orders hosting services. You can have a custom skeleton for each server within your WHMCS Installation.
3 | Note: You do NOT need to enter ip address or domain information as this will be automatically entered when a hosting account is created. This is so you can add addtional custom records.
4 |
7 |
8 |
9 |
10 | Server ID
11 | Type
12 | Prefix_name
13 | Address
14 | Priority
15 | TTL
16 | Actions
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | Edit
30 | Delete
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/linodedns/templates/servers.php:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 | Servers
11 | Select the servers below that you would like to use the linode DNS Manager on
12 | After you have selected your servers and clicked on Save . Link your linode domains to your clients Link Accounts
13 |
14 |
15 |
16 | Opt-In
17 | Server
18 |
19 |
20 |
21 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/linodedns/templates/skeleton_add.php:
--------------------------------------------------------------------------------
1 |
10 | Add Skeleton Record
11 |
--------------------------------------------------------------------------------
/linodedns/templates/skeleton_edit.php:
--------------------------------------------------------------------------------
1 |
10 | Edit Skeleton Record
11 |
12 |
40 |
--------------------------------------------------------------------------------