mirror of
https://github.com/ovh/php-ovh.git
synced 2023-11-05 03:20:26 +01:00
Fix typo
Improve script Signed-off-by: Vincent Casse <vincent.casse@corp.ovh.com>
This commit is contained in:
parent
324d42ea3c
commit
aded4f28f7
@ -13,7 +13,7 @@ This documentation will help you to create an HTTP redirection from a subdomain
|
|||||||
- Download the latest release **with dependencies** on github: https://github.com/ovh/php-ovh/releases
|
- Download the latest release **with dependencies** on github: https://github.com/ovh/php-ovh/releases
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# When this article was written, latest version is 2.0.0
|
# When this article is written, latest version is 2.0.0
|
||||||
wget https://github.com/ovh/php-ovh/releases/download/v2.0.0/php-ovh-2.0.0-with-dependencies.tar.gz
|
wget https://github.com/ovh/php-ovh/releases/download/v2.0.0/php-ovh-2.0.0-with-dependencies.tar.gz
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -23,89 +23,24 @@ wget https://github.com/ovh/php-ovh/releases/download/v2.0.0/php-ovh-2.0.0-with-
|
|||||||
tar xzvf php-ovh-2.0.0-with-dependencies.tar.gz
|
tar xzvf php-ovh-2.0.0-with-dependencies.tar.gz
|
||||||
```
|
```
|
||||||
|
|
||||||
- Create a new token
|
## Create a new token
|
||||||
You can create a new token using these url: [https://api.ovh.com/createToken/?GET=/domain/zone/*&POST=/domain/zone/*&DELETE=/domain/zone/*](https://api.ovh.com/createToken/?GET=/domain/zone/*&POST=/domain/zone/*&DELETE=/domain/zone/*). Keep application key, application secret and consumer key to complete the script.
|
|
||||||
|
|
||||||
Be warn, this token is only validated for this script and to use **/domain/zone/\*** APIs.
|
You can create a new token using this url: [https://api.ovh.com/createToken/?GET=/domain/zone/*&POST=/domain/zone/*&DELETE=/domain/zone/*](https://api.ovh.com/createToken/?GET=/domain/zone/*&POST=/domain/zone/*&DELETE=/domain/zone/*). Keep application key, application secret and consumer key to complete the script.
|
||||||
If you need a more generic token, you had to change right field.
|
|
||||||
|
|
||||||
- Create php file to create your new HTTP redirection. You can download [this file](https://github.com/ovh/php-ovh/blob/master/examples/create-Redirection/apiv6.php)
|
Be warned, this token is only valid for this script on **/domain/zone/\*** APIs.
|
||||||
|
If you need a more generic token, you may adjust the **Rights** fields at your needs.
|
||||||
|
|
||||||
```php
|
## Download the script
|
||||||
<?php
|
|
||||||
require __DIR__ . '/vendor/autoload.php';
|
|
||||||
use \Ovh\Api;
|
|
||||||
|
|
||||||
// Informations about your application
|
- Download and edit the php php file to create your new HTTP redirection. You can download [this file](https://github.com/ovh/php-ovh/blob/master/examples/create-Redirection/apiv6.php). **You had to replace some variables in the beginning of the file**.
|
||||||
$applicationKey = "your_app_key";
|
|
||||||
$applicationSecret = "your_app_secret";
|
|
||||||
$consumer_key = "your_consumer_key";
|
|
||||||
|
|
||||||
// Information about API and rights asked
|
## Run script
|
||||||
$endpoint = 'ovh-eu';
|
|
||||||
|
|
||||||
// Information about your domain and redirection
|
|
||||||
$domain = 'yourdomain.ovh';
|
|
||||||
$subDomain = 'www'; // Here, the redirection will come from www.yourdomain.com
|
|
||||||
$targetDomain = 'my_target.ovh';
|
|
||||||
$type = 'visible'; // can be "visible", "invisible", "visiblePermanent"
|
|
||||||
|
|
||||||
// Field to complete in case of invisible redirection
|
|
||||||
$title = '';
|
|
||||||
$keywords = '';
|
|
||||||
$description = '';
|
|
||||||
|
|
||||||
// Get servers list
|
|
||||||
$conn = new Api( $applicationKey,
|
|
||||||
$applicationSecret,
|
|
||||||
$endpoint,
|
|
||||||
$consumer_key);
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
// check if dns record are available
|
|
||||||
$recordIds = $conn->get('/domain/zone/' . $domain . '/record');
|
|
||||||
|
|
||||||
foreach ($recordIds as $recordId) {
|
|
||||||
$record = $conn->get('/domain/zone/' . $domain . '/record/' . $recordId);
|
|
||||||
|
|
||||||
// If record include A, AAAA or CNAME for subdomain asked, we delete it
|
|
||||||
if ( strcmp( $record['subDomain'], $subDomain) === 0 &&
|
|
||||||
in_array( $record['fieldType'], array( 'A', 'AAAA', 'CNAME' ) ) ) {
|
|
||||||
|
|
||||||
echo "We will delete field " . $record['fieldType'] . " for " . $record['zone'] . PHP_EOL;
|
|
||||||
$conn->delete('/domain/zone/' . $domain . '/record/' . $recordId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We apply zone changes
|
|
||||||
$conn->post('/domain/zone/' . $domain . '/refresh');
|
|
||||||
|
|
||||||
// Now, we are ready to create our new redirection
|
|
||||||
$redirection = $conn->post('/domain/zone/' . $domain . '/redirection', array(
|
|
||||||
'subDomain' => $subDomain,
|
|
||||||
'target' => $targetDomain,
|
|
||||||
'type' => $type,
|
|
||||||
'title' => $title,
|
|
||||||
'description' => $description,
|
|
||||||
'keywords' => $keywords,
|
|
||||||
));
|
|
||||||
|
|
||||||
print_r( $redirection );
|
|
||||||
|
|
||||||
} catch ( Exception $ex ) {
|
|
||||||
print_r( $ex->getMessage() );
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
```
|
|
||||||
|
|
||||||
## Run php file
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
php apiv6.php
|
php apiv6.php
|
||||||
```
|
```
|
||||||
|
|
||||||
For instance, with example values in script, the answer is
|
For instance, using the example values in this script, the answer would look like:
|
||||||
```
|
```
|
||||||
(
|
(
|
||||||
[zone] => yourdomain.ovh
|
[zone] => yourdomain.ovh
|
||||||
|
@ -7,7 +7,7 @@ $applicationKey = "your_app_key";
|
|||||||
$applicationSecret = "your_app_secret";
|
$applicationSecret = "your_app_secret";
|
||||||
$consumer_key = "your_consumer_key";
|
$consumer_key = "your_consumer_key";
|
||||||
|
|
||||||
// Information about API and rights asked
|
// Information about API endpoint used
|
||||||
$endpoint = 'ovh-eu';
|
$endpoint = 'ovh-eu';
|
||||||
|
|
||||||
// Information about your domain and redirection
|
// Information about your domain and redirection
|
||||||
@ -16,7 +16,7 @@ $subDomain = 'www'; // Here, the redirection will come from www.yourdomain.com
|
|||||||
$targetDomain = 'my_target.ovh';
|
$targetDomain = 'my_target.ovh';
|
||||||
$type = 'visible'; // can be "visible", "invisible", "visiblePermanent"
|
$type = 'visible'; // can be "visible", "invisible", "visiblePermanent"
|
||||||
|
|
||||||
// Field to complete in case of invisible redirection
|
// Field to set in case of invisible redirection
|
||||||
$title = '';
|
$title = '';
|
||||||
$keywords = '';
|
$keywords = '';
|
||||||
$description = '';
|
$description = '';
|
||||||
@ -30,23 +30,19 @@ $conn = new Api( $applicationKey,
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
// check if dns record are available
|
// check if dns record are available
|
||||||
$recordIds = $conn->get('/domain/zone/' . $domain . '/record');
|
$recordIds = $conn->get('/domain/zone/' . $domain . '/record?subDomain='. $subDomain );
|
||||||
|
|
||||||
foreach ($recordIds as $recordId) {
|
foreach ($recordIds as $recordId) {
|
||||||
$record = $conn->get('/domain/zone/' . $domain . '/record/' . $recordId);
|
$record = $conn->get('/domain/zone/' . $domain . '/record/' . $recordId);
|
||||||
|
|
||||||
// If record include A, AAAA or CNAME for subdomain asked, we delete it
|
// If record include A, AAAA or CNAME for subdomain asked, we delete it
|
||||||
if ( strcmp( $record['subDomain'], $subDomain) === 0 &&
|
if ( in_array( $record['fieldType'], array( 'A', 'AAAA', 'CNAME' ) ) ) {
|
||||||
in_array( $record['fieldType'], array( 'A', 'AAAA', 'CNAME' ) ) ) {
|
|
||||||
|
|
||||||
echo "We will delete field " . $record['fieldType'] . " for " . $record['zone'] . PHP_EOL;
|
echo "We will delete field " . $record['fieldType'] . " for " . $record['zone'] . PHP_EOL;
|
||||||
$conn->delete('/domain/zone/' . $domain . '/record/' . $recordId);
|
$conn->delete('/domain/zone/' . $domain . '/record/' . $recordId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We apply zone changes
|
|
||||||
$conn->post('/domain/zone/' . $domain . '/refresh');
|
|
||||||
|
|
||||||
// Now, we are ready to create our new redirection
|
// Now, we are ready to create our new redirection
|
||||||
$redirection = $conn->post('/domain/zone/' . $domain . '/redirection', array(
|
$redirection = $conn->post('/domain/zone/' . $domain . '/redirection', array(
|
||||||
'subDomain' => $subDomain,
|
'subDomain' => $subDomain,
|
||||||
@ -57,6 +53,9 @@ try {
|
|||||||
'keywords' => $keywords,
|
'keywords' => $keywords,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// We apply zone changes
|
||||||
|
$conn->post('/domain/zone/' . $domain . '/refresh');
|
||||||
|
|
||||||
print_r( $redirection );
|
print_r( $redirection );
|
||||||
|
|
||||||
} catch ( Exception $ex ) {
|
} catch ( Exception $ex ) {
|
||||||
|
@ -13,7 +13,7 @@ This documentation will help you to get informations about your web hosting offe
|
|||||||
- Download the latest release **with dependencies** on github: https://github.com/ovh/php-ovh/releases
|
- Download the latest release **with dependencies** on github: https://github.com/ovh/php-ovh/releases
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# When this article was written, latest version is 2.0.0
|
# When this article is written, latest version is 2.0.0
|
||||||
wget https://github.com/ovh/php-ovh/releases/download/v2.0.0/php-ovh-2.0.0-with-dependencies.tar.gz
|
wget https://github.com/ovh/php-ovh/releases/download/v2.0.0/php-ovh-2.0.0-with-dependencies.tar.gz
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ tar xzvf php-ovh-2.0.0-with-dependencies.tar.gz
|
|||||||
```
|
```
|
||||||
|
|
||||||
- Create a new token
|
- Create a new token
|
||||||
You can create a new token using these url: [https://api.ovh.com/createToken/?GET=/hosting/web/my_domain&GET=/hosting/web/offerCapabilities](https://api.ovh.com/createToken/?GET=/hosting/web/my_domain&GET=/hosting/web/offerCapabilities). Keep application key, application secret and consumer key to complete the script.
|
You can create a new token using this url: [https://api.ovh.com/createToken/?GET=/hosting/web/my_domain&GET=/hosting/web/offerCapabilities](https://api.ovh.com/createToken/?GET=/hosting/web/my_domain&GET=/hosting/web/offerCapabilities). Keep application key, application secret and consumer key to complete the script.
|
||||||
|
|
||||||
Be warn, this token is only validated for this script and for hosting called **my_domain**. Please replace **my_domain** by your web hosting reference!
|
Be warn, this token is only validated for this script and for hosting called **my_domain**. Please replace **my_domain** by your web hosting reference!
|
||||||
If you need a more generic token, you had to change right field.
|
If you need a more generic token, you had to change right field.
|
||||||
|
Loading…
Reference in New Issue
Block a user