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) {
|
1345 |
1339 |
if ($rec['attributes']['prefix'] == $this->_dnsHostname) {
|
... | ... | |
1349 |
1343 |
}
|
1350 |
1344 |
if (!$id) {
|
1351 |
1345 |
log_error("Could not find one.com hostname record id");
|
|
1346 |
unlink($cookieFile);
|
1352 |
1347 |
return false;
|
1353 |
1348 |
}
|
1354 |
1349 |
|
... | ... | |
1716 |
1711 |
@curl_close($ch);
|
1717 |
1712 |
$this->_checkStatus($http_code, $curl_error, $data, $header);
|
1718 |
1713 |
}
|
|
1714 |
|
|
1715 |
if (isset($cookieFile)) {
|
|
1716 |
unlink($cookieFile);
|
|
1717 |
}
|
1719 |
1718 |
}
|
1720 |
1719 |
|
1721 |
1720 |
/**
|