-
-
Notifications
You must be signed in to change notification settings - Fork 6
T11699: Create a job to automate CNAME checks #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bd09967
6fc0103
56975c6
ef0bd57
f153e0b
1b68ce9
82d6934
aeb4153
afad519
10a203f
c26841b
150df09
353b6ba
f177229
97f230b
dd2c70d
0b45bee
a6ee8f0
407a0be
ddbf437
fb5a4c7
051415b
6090427
163d280
c3c9502
97f1142
0e1a6f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,65 @@ | ||||||||||||||||||||||||||||||||
<?php | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
namespace Miraheze\RequestSSL\Jobs; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
use Config; | ||||||||||||||||||||||||||||||||
use ConfigFactory; | ||||||||||||||||||||||||||||||||
use GenericParameterJob; | ||||||||||||||||||||||||||||||||
use Job; | ||||||||||||||||||||||||||||||||
use Miraheze\RequestSSL\RequestSSLManager; | ||||||||||||||||||||||||||||||||
use MediaWiki\User\User; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
class DomainCheckJob extends Job implements GenericParameterJob { | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
/** @var Config */ | ||||||||||||||||||||||||||||||||
private $config; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
/** @var int */ | ||||||||||||||||||||||||||||||||
private $requestID; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
/** @var RequestSSLManager */ | ||||||||||||||||||||||||||||||||
private $requestSslManager; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||
* @param array $params | ||||||||||||||||||||||||||||||||
* @param ConfigFactory $configFactory | ||||||||||||||||||||||||||||||||
* @param RequestSSLManager $requestSslManager | ||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||
public function __construct( | ||||||||||||||||||||||||||||||||
array $params, | ||||||||||||||||||||||||||||||||
ConfigFactory $configFactory, | ||||||||||||||||||||||||||||||||
RequestSSLManager $requestSslManager | ||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||
parent::__construct( 'DomainCheckJob', $params ); | ||||||||||||||||||||||||||||||||
$this->requestID = $params['requestID']; | ||||||||||||||||||||||||||||||||
$this->config = $configFactory->makeConfig( 'RequestSSL' ); | ||||||||||||||||||||||||||||||||
$this->requestSslManager = $requestSslManager; | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||
* @return bool | ||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||
public function run() { | ||||||||||||||||||||||||||||||||
$this->requestSslManager->fromID( $this->requestID ); | ||||||||||||||||||||||||||||||||
$customDomain = parse_url( $this->requestSslManager->getCustomDomain(), PHP_URL_HOST ); | ||||||||||||||||||||||||||||||||
if ( !$customDomain ) { | ||||||||||||||||||||||||||||||||
// Custom domain does not have a hostname, bail out. | ||||||||||||||||||||||||||||||||
$this->setLastError( 'Custom domain does not have a hostname.' ); | ||||||||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
$cname = $this->config->get( 'RequestSSLDomainCheckCNAME' ); | ||||||||||||||||||||||||||||||||
// TODO: Support rDNS and NS checks | ||||||||||||||||||||||||||||||||
// CNAME check | ||||||||||||||||||||||||||||||||
$dnsCNAMEData = dns_get_record( $customDomain, DNS_CNAME ); | ||||||||||||||||||||||||||||||||
if ( !$dnsCNAMEData ) { | ||||||||||||||||||||||||||||||||
$this->requestSslManager->addComment( 'RequestSSL could not determine whether or not this domain is pointed: DNS returned no data during CNAME check.', User::newSystemUser( 'RequestSSL Extension' ) ); | ||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||
if ( $dnsCNAMEData[0]['type'] === 'CNAME' && $dnsCNAMEData[0]['target'] === $cname ) { | ||||||||||||||||||||||||||||||||
$this->requestSslManager->addComment( 'Domain is pointed via CNAME.', User::newSystemUser( 'RequestSSL Extension' ) ); | ||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||
$this->requestSslManager->addComment( 'Domain is not pointed via CNAME. It is possible it is pointed via other means.', User::newSystemUser( 'RequestSSL Extension' ) ); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
Comment on lines
+55
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor to improve readability and reduce duplication. The method + $systemUser = User::newSystemUser('RequestSSL Extension');
...
- User::newSystemUser('RequestSSL Extension')
+ $systemUser Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||||||||
Comment on lines
+42
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Address potential issues with DNS lookup failure handling. The method |
||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I think we should use a single associative array config,
RequestSSLDomainChecks
or something then an option for likeCNAME
,A
,AAAA
, andNS
keys for supported options for checking.