# Passer Creatio de http à https et vice versa en un click

# Passer Creatio de http à https et vice versa en un click

**Cet article concerne uniquement l’installation de Creatio on-site.**

## Introduction

Afin de changer un environnement Creatio de http à https, un lien est directement fourni par Creatio sur l’académie : [https://academy.creatio.com/docs/user/on\_site\_deployment/net\_framework\_application\_server\_on\_windows/switch\_creatio\_to\_https/switch\_creatio\_website\_from\_http\_to\_https](https://academy.creatio.com/docs/user/on_site_deployment/net_framework_application_server_on_windows/switch_creatio_to_https/switch_creatio_website_from_http_to_https)

Cet article est subdivisé en deux étapes distinctes : "IIS Setup" et "Web.config setup". Le script proposé ci-dessous viendra automatiser la partie "Web.config setup", la partie "IIS Setup" doit s'effectuer manuellement.

## Passer de http à https via un script Powershell

Bien que la première partie s’occupant de traiter la configuration des certificats dans l’IIS ainsi que les « bindings » correspondants doit être faite manuellement, cet article vient proposer un script powershell afin d’automatiser le changement des lignes des fichiers "Web.config".

### Le script

```plaintext
$http = $true
$rootPath = "ROOT WEB CONFIG PATH"
$webPath = "TERRASOFT WEB CONFIG PATH"
$file_data = Get-Content -path $rootPath | Where-Object {$_ -like '*Terrasoft.WebApp\ServiceModel\https\behaviors.config*'}

if($file_data -like '*https*') {
    $http = $false
}



if ($http) {
    ((Get-Content -path $rootPath) -replace 'Terrasoft.WebApp\\ServiceModel\\http\\behaviors.config','Terrasoft.WebApp\ServiceModel\https\behaviors.config') | Set-Content -Path $rootPath
    ((Get-Content -path $rootPath) -replace 'Terrasoft.WebApp\\ServiceModel\\http\\bindings.config','Terrasoft.WebApp\ServiceModel\https\bindings.config') | Set-Content -Path $rootPath
    ((Get-Content -path $webPath) -replace 'type="Terrasoft.Messaging.MicrosoftWSService.MicrosoftWSService, Terrasoft.Messaging.MicrosoftWSService" encrypted="false"','type="Terrasoft.Messaging.MicrosoftWSService.MicrosoftWSService, Terrasoft.Messaging.MicrosoftWSService" encrypted="true"') | Set-Content -Path $webPath
    ((Get-Content -path $webPath) -replace 'services configSource="ServiceModel\\http\\services.config','services configSource="ServiceModel\https\services.config') | Set-Content -Path $webPath

    Write-Output "Configuration changed from http to https"
}
else {
    ((Get-Content -path $rootPath) -replace 'Terrasoft.WebApp\\ServiceModel\\https\\behaviors.config','Terrasoft.WebApp\ServiceModel\http\behaviors.config') | Set-Content -Path $rootPath
    ((Get-Content -path $rootPath) -replace 'Terrasoft.WebApp\\ServiceModel\\https\\bindings.config','Terrasoft.WebApp\ServiceModel\http\bindings.config') | Set-Content -Path $rootPath
    ((Get-Content -path $webPath) -replace 'type="Terrasoft.Messaging.MicrosoftWSService.MicrosoftWSService, Terrasoft.Messaging.MicrosoftWSService" encrypted="true"','type="Terrasoft.Messaging.MicrosoftWSService.MicrosoftWSService, Terrasoft.Messaging.MicrosoftWSService" encrypted="false"') | Set-Content -Path $webPath
    ((Get-Content -path $webPath) -replace 'services configSource="ServiceModel\\https\\services.config','services configSource="ServiceModel\http\services.config') | Set-Content -Path $webPath

    Write-Output "Configuration changed from https to http"
}
```

Ce script reconnaît si le site est en http ou en https et le convertit automatiquement en faisant l’opération inverse.

### Personnalisation selon l'environnement

Afin que le script fonctionne selon votre environnement, vous devez remplacer la valeur de la variable $rootpath et $webPath par, respectivement, le chemin d’accès au fichier web.config qui se trouve dans le « website root directory » de votre environnement et par le le chemin d’accès au fichier web.config qui se trouve dans le « website root directory\\Terrasoft.WebApp » de votre environnement.

Voici un exemple :

```plaintext
$rootPath = "D:\Creatio\DEV\web.config"
$webPath = "D:\Creatio\DEV\Terrasoft.WebApp\web.config"
```

### Comment l'exécuter ?

Vous devrez simplement le démarrer via un terminal powershell afin que vos fichiers web.config correspondants soient changés dans la version souhaitée.

### Output final

![powershell.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1656493045930/I-ays29YB.png align="left")

## A propos de l'auteur

![photo_profil_jon-modified (1).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1663831032092/0SDU8hlJc.png align="center")

[*Jonathan Quendoz*](https://www.linkedin.com/in/jonathan-quendoz/) *Consultant technique SAP / CRM Creatio @* [Dina](https://www.dina.ch/)
