Project

General

Profile

Bug #14276 » one.com-dyndns-patch.diff

Alexander Arques, 04/13/2023 01:21 PM

View differences:

etc/inc/dyndns.class 2023-04-12 21:54:49.096627500 +0200 → etc/inc/dyndns.class 2023-04-13 20:03:21.329706400 +0200
1296 1296
					/* see https://redmine.pfsense.org/issues/11293
1297 1297
					 * and https://redmine.pfsense.org/issues/12352 */
1298 1298

  
1299
					$cookieFile = "/var/tmp/one.com.cookie";
1300

  
1299 1301
					curl_setopt($ch, CURLOPT_URL, "https://www.one.com/admin/");
1300
					curl_setopt($ch, CURLOPT_HEADER, 1); //return the full headers to extract the cookies
1302
					curl_setopt($ch, CURLOPT_HEADER, 0);
1303
					curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
1301 1304
					curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
1302 1305
					curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
1303 1306
					$output = curl_exec($ch);
1304
					$last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
1305

  
1306
					// extract the cookies
1307
					preg_match_all("/^Set-cookie: (.*?);/ism", $output, $cookies);
1308
					if (count($cookies[1]) > 0) {
1309
						$cookie_data = implode("; ", $cookies[1]);
1310
					}
1307
					$dom = new DOMDocument;
1308
					$dom->loadHTML($output);
1309
					$formTag = $dom->getElementsByTagName("form")[0];
1310
					$login_url = $formTag->getAttribute("action");
1311 1311

  
1312 1312
					// login in
1313 1313
					$post_data['username'] = $this->_dnsUser;
1314 1314
					$post_data['password'] = $this->_dnsPass;
1315 1315
					$post_data['credentialId'] = '';
1316 1316

  
1317
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
1318
					curl_setopt($ch, CURLOPT_URL, $last_url);
1319
					curl_setopt($ch, CURLOPT_COOKIE, $cookie_data);
1320
					curl_setopt($ch, CURLOPT_HEADER, 1); //return the full headers to extract the cookies
1317
					curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
1318
					curl_setopt($ch, CURLOPT_POST, 1);
1319
					curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=' . $this->_dnsUser . '&password=' . $this->_dnsPass . '&credentialId=');
1320
					curl_setopt($ch, CURLOPT_URL, $login_url);
1321 1321
					curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
1322 1322
					$output = curl_exec($ch);
1323 1323

  
1324
					// extract the cookies
1325
					preg_match_all("/^Set-cookie: (.*?);/ism", $output, $cookies);
1326
					if (count($cookies[1]) > 0) {
1327
						$cookie_data = implode("; ", $cookies[1]);
1328
					}
1329

  
1330 1324
					// gets all DNS records of the domain.
1331 1325
					$post_data = null;
1332
					$url = "https://www.one.com/admin/api/domains/" . $this->_dnsDomain + "/dns/custom_records";
1326
					$url = "https://www.one.com/admin/api/domains/" . $this->_dnsDomain . "/dns/custom_records";
1333 1327
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
1334
					curl_setopt($ch, CURLOPT_COOKIE, $cookie_data);
1328
					curl_setopt($ch, CURLOPT_POST, 0);
1335 1329
					curl_setopt($ch, CURLOPT_HEADER, 0);
1336 1330
					curl_setopt($ch, CURLOPT_URL, $url);
1337
					curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
1338 1331
					curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
1339 1332
					$output = curl_exec($ch);
1340 1333
					$result = json_decode($output, true);
1341 1334
					$records = $result['result']['data'];
1342 1335

  
1336
					$this->_dnsHostname = $this->_dnsHostname == "@" ? "" : $this->_dnsHostname; // Allow "@" to indicate root domain
1343 1337
					// finds the record id of a record from it's subdomain
1344 1338
					foreach ($records as $rec) {
1339
						log_error($rec['attributes']['prefix'] . ":" . $this->_dnsHostname);
1345 1340
						if ($rec['attributes']['prefix'] == $this->_dnsHostname) {
1346 1341
							$id = $rec['id'];
1347 1342
							break;
......
1349 1344
					}
1350 1345
					if (!$id) {
1351 1346
						log_error("Could not find one.com hostname record id");
1347
						unlink($cookieFile);
1352 1348
						return false;
1353 1349
					}
1354 1350

  
......
1716 1712
				@curl_close($ch);
1717 1713
				$this->_checkStatus($http_code, $curl_error, $data, $header);
1718 1714
			}
1715

  
1716
			if (isset($cookieFile)) {
1717
				unlink($cookieFile);
1718
			}
1719 1719
		}
1720 1720

  
1721 1721
		/**
usr/local/www/services_dyndns_edit.php 2023-04-13 19:52:39.707765400 +0200 → usr/local/www/services_dyndns_edit.php 2023-04-13 20:01:28.802407300 +0200
127 127
		} elseif (($pconfig['type'] == "cloudflare") || ($pconfig['type'] == "cloudflare-v6")) {
128 128
			$host_to_check = $_POST['host'] == '@' ? $_POST['domainname'] : ( $_POST['host'] . '.' . $_POST['domainname'] );
129 129
			$allow_wildcard = true;
130
		} elseif (substr($pconfig['type'], 0, 6) == "onecom") {
131
			$host_to_check = $_POST['host'] == '@' ? $_POST['domainname'] : ( $_POST['host'] . '.' . $_POST['domainname'] );
130 132
		} elseif ((($pconfig['type'] == "godaddy") || ($pconfig['type'] == "godaddy-v6")) && ($_POST['host'] == '@.' || $_POST['host'] == '@')) {
131 133
			$host_to_check = $_POST['domainname'];
132 134
		} elseif (($pconfig['type'] == "digitalocean" || $pconfig['type'] == "digitalocean-v6") && ($_POST['host'] == '@.' || $_POST['host'] == '@')) {
(1-1/2)