Last active
March 5, 2018 07:48
-
-
Save athlan/36bbd6441cae0c5f63ebf28b86934910 to your computer and use it in GitHub Desktop.
Script pastes the SSL certificates into Direct Admin panel via CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// h - host | |
// u - user | |
// p - pass | |
// d - domain | |
// c - cert | |
// k - private key | |
$options = getopt("h:u:p:d:c:k:"); | |
$hostname = $options['h']; | |
$username = $options['u']; | |
$password = $options['p']; | |
$domain = $options['d']; | |
$file_cer = $options['c']; | |
$file_key = $options['k']; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "http://$hostname/CMD_API_SSL"); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); | |
$certificate = ''; | |
$certificate .= file_get_contents($file_key); | |
$certificate .= file_get_contents($file_cer); | |
$certificate = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $certificate); | |
$data = array( | |
'domain' => $domain, | |
'action' => 'save', | |
'type' => 'paste', | |
'active' => 'yes', | |
'certificate' => $certificate, | |
); | |
var_dump($data); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); | |
$output = curl_exec($ch); | |
$info = curl_getinfo($ch); | |
curl_close($ch); | |
var_dump($info); | |
var_dump($output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment