diff --git a/EXAMPLES/complex_docker_compose/README.md b/EXAMPLES/complex_docker_compose/README.md new file mode 100644 index 0000000..c779f0f --- /dev/null +++ b/EXAMPLES/complex_docker_compose/README.md @@ -0,0 +1,17 @@ +Using of this example +===================== + +Run the create_certs.bash to generate certificates for server and client + + ./create_certs.bash + +Edit the data/server.json according to your settings + +Start the container of restgomail + + docker-compose up -d + +Now you can send messages to the container with the php sample + + php ./send_sample_request.php + diff --git a/EXAMPLES/complex_docker_compose/create_certs.bash b/EXAMPLES/complex_docker_compose/create_certs.bash new file mode 100755 index 0000000..33bc040 --- /dev/null +++ b/EXAMPLES/complex_docker_compose/create_certs.bash @@ -0,0 +1,19 @@ +#!/bin/bash + +# Generate certificates for server and client + +SERVERCERTNAME="restgomail" +CLIENTCERTNAME="rgmclient" + +openssl genrsa -out ${SERVERCERTNAME}.key 2048 +openssl ecparam -genkey -name secp384r1 -out ${SERVERCERTNAME}.key +openssl req -new -x509 -sha256 -key ${SERVERCERTNAME}.key -out ${SERVERCERTNAME}.crt -days 365 + +openssl genrsa -out ${CLIENTCERTNAME}.key 2048 +openssl ecparam -genkey -name secp384r1 -out ${CLIENTCERTNAME}.key +openssl req -new -x509 -sha256 -key ${CLIENTCERTNAME}.key -out ${CLIENTCERTNAME}.crt -days 365 + +mv ${SERVERCERTNAME}.key ./data/ +mv ${SERVERCERTNAME}.crt ./data/ + +cp ${CLIENTCERTNAME}.crt ./data/${CLIENTCERTNAME}.crt \ No newline at end of file diff --git a/EXAMPLES/complex_docker_compose/data/server.json b/EXAMPLES/complex_docker_compose/data/server.json new file mode 100644 index 0000000..4c2d82d --- /dev/null +++ b/EXAMPLES/complex_docker_compose/data/server.json @@ -0,0 +1,17 @@ +{ + "restgomail": { + "smtpHost": "smtp.gmail.com", + "smtpPort": "587", + "smtpAuthRequired": true, + "smtpAuthPassword": "gmailpasswordsample", + "smtpAllowedFromAddressOnly": "sampleuser@gmail.com", + "httpsListenPort": "44325", + "tlsKeyFile": "restgomail.key", + "tlsCertFile": "restgomail.crt", + "allowOnlyKnownCertificates": true, + "knownCertificates": { + "civisdbContainer": "@rgmclient.crt" + }, + "waitSecondsAfterSmtpreq": 10 + } +} diff --git a/EXAMPLES/complex_docker_compose/docker-compose.yml b/EXAMPLES/complex_docker_compose/docker-compose.yml new file mode 100644 index 0000000..87be9c6 --- /dev/null +++ b/EXAMPLES/complex_docker_compose/docker-compose.yml @@ -0,0 +1,8 @@ +services: + restgomail: + image: hyperprog/restgomail + container_name: restgomail + ports: + - "44325:44325" + volumes: + - ./data:/restgomail diff --git a/EXAMPLES/complex_docker_compose/send_sample_request.php b/EXAMPLES/complex_docker_compose/send_sample_request.php new file mode 100644 index 0000000..a4852b1 --- /dev/null +++ b/EXAMPLES/complex_docker_compose/send_sample_request.php @@ -0,0 +1,53 @@ +RestGoMail" + } + }'; + +$r = SendHttpPostWithCert("https://127.0.0.1:44325/sendmail",$json,"rgmclient.crt","rgmclient.key"); +print("Received:".$r); + +function SendHttpPostWithCert($url, $postdata, $certfile, $keyfile) +{ + $curl = curl_init(); + + curl_setopt($curl, CURLOPT_POST, 1); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); + + curl_setopt($curl, CURLOPT_SSLKEY, $keyfile); + curl_setopt($curl, CURLOPT_SSLCERT, $certfile); + + curl_setopt($curl, CURLOPT_CERTINFO, true); + + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); + + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15); + curl_setopt($curl, CURLOPT_TIMEOUT, 60); + + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + + $result = curl_exec($curl); + $info = curl_getinfo($curl,CURLINFO_CERTINFO); + + print "You can check this certificate:" + print "\n=============================\n"; + $c = $info[0]['Cert']; + $c = preg_replace('/\-+BEGIN CERTIFICATE\-+/','',$c); + $c = preg_replace('/\-+END CERTIFICATE\-+/','',$c); + $c = trim($c); + print $c; + print "\n=============================\n"; + + curl_close($curl); + + return $result; +} +