<?xml version="1.0" encoding="UTF-8"?><feed
  xmlns="http://www.w3.org/2005/Atom"
  xmlns:thr="http://purl.org/syndication/thread/1.0"
  xml:lang="fr-FR"
  xml:base="http://www.wamania.com/wp-atom.php"
   >
	<title type="text">Wamania</title>
	<subtitle type="text">PHP5, jQuery, Admin serveur, Domotique et... le reste</subtitle>

	<updated>2016-04-18T09:45:05Z</updated>

	<link rel="alternate" type="text/html" href="http://www.wamania.com" />
	<id>http://www.wamania.com/feed/atom</id>
	<link rel="self" type="application/atom+xml" href="http://www.wamania.com/feed/atom" />

	<generator uri="https://wordpress.org/" version="4.5">WordPress</generator>
	<entry>
		<author>
			<name>admin</name>
					</author>
		<title type="html"><![CDATA[Prestashop &#8211; Module en ligne de commande]]></title>
		<link rel="alternate" type="text/html" href="http://www.wamania.com/prestashop/prestashop-module-en-ligne-de-commande.html" />
		<id>http://www.wamania.com/?p=186</id>
		<updated>2016-04-18T09:45:05Z</updated>
		<published>2016-04-18T09:20:59Z</published>
		<category scheme="http://www.wamania.com" term="Prestashop" />		<summary type="html"><![CDATA[J&#8217;avais trouvé y a un moment de la doc pour utiliser PHP en ligne de commande dans un module (ou ailleurs) sur prestashop, mais impossible de remettre la main dessus. Par exemple, pour relancer une indexation totale de votre base en ligne de commande : 1 2 3 4 5 6 7 8 &#60;?php // ... <span class="more"><a class="more-link" href="http://www.wamania.com/prestashop/prestashop-module-en-ligne-de-commande.html">[Read more...]</a></span>]]></summary>
		<content type="html" xml:base="http://www.wamania.com/prestashop/prestashop-module-en-ligne-de-commande.html"><![CDATA[<p>J&rsquo;avais trouvé y a un moment de la doc pour utiliser PHP en ligne de commande dans un module (ou ailleurs) sur prestashop, mais impossible de remettre la main dessus.</p>
<p>Par exemple, pour relancer une indexation totale de votre base en ligne de commande :<br />
<span id="more-186"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// BUG FIX : https://www.prestashop.com/forums/topic/260215-prestashop-and-cron-jobs-or-cli/</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_PS_ADMIN_DIR_'</span><span style="color: #339933;">,</span> <span style="color: #990000;">getcwd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// chemin à adapter si besoin</span>
<span style="color: #b1b100;">include_once</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/../../config/config.inc.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Search<span style="color: #339933;">::</span><span style="color: #004000;">indexation</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Puis :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="sh" style="font-family:monospace;">php indexation.php</pre></td></tr></table></div>

]]></content>
			<link rel="replies" type="text/html" href="http://www.wamania.com/prestashop/prestashop-module-en-ligne-de-commande.html#comments" thr:count="0"/>
		<link rel="replies" type="application/atom+xml" href="http://www.wamania.com/prestashop/prestashop-module-en-ligne-de-commande.html/feed/atom" thr:count="0"/>
		<thr:total>0</thr:total>
		</entry>
		<entry>
		<author>
			<name>admin</name>
					</author>
		<title type="html"><![CDATA[Stemmer Snowball PHP5 natif]]></title>
		<link rel="alternate" type="text/html" href="http://www.wamania.com/php5/stemmer-snowball-php5-natif.html" />
		<id>http://www.wamania.com/?p=173</id>
		<updated>2016-04-15T09:22:55Z</updated>
		<published>2016-04-15T09:12:55Z</published>
		<category scheme="http://www.wamania.com" term="PHP5" />		<summary type="html"><![CDATA[En linguistique, la racinisation ou désuffixation (anglais : stemming) est un procédé de transformation des flexions en leur radical ou racine (anglais : stem). La racinisation est très utile notammant pour les moteurs de recherche. Pour rappel, ça vous permet de ressortir les mêmes résultats pour &#171;&#160;achetez clés usb vert&#160;&#187; et &#171;&#160;acheter clé usb vertes&#160;&#187;. Les techniques ... <span class="more"><a class="more-link" href="http://www.wamania.com/php5/stemmer-snowball-php5-natif.html">[Read more...]</a></span>]]></summary>
		<content type="html" xml:base="http://www.wamania.com/php5/stemmer-snowball-php5-natif.html"><![CDATA[<blockquote><p>En <a title="Linguistique" href="https://fr.wikipedia.org/wiki/Linguistique">linguistique</a>, la <b>racinisation</b> ou <b>désuffixation</b> (anglais : <i>stemming</i>) est un procédé de transformation des flexions en leur <a title="Radical (linguistique)" href="https://fr.wikipedia.org/wiki/Radical_%28linguistique%29">radical</a> ou racine (anglais : <i>stem</i>).</p></blockquote>
<p>La racinisation est très utile notammant pour les moteurs de recherche. Pour rappel, ça vous permet de ressortir les mêmes résultats pour &laquo;&nbsp;achetez clés usb vert&nbsp;&raquo; et &laquo;&nbsp;acheter clé usb vertes&nbsp;&raquo;.<br />
Les techniques pour raciniser sont multiples, allant du simple dictionnaire d&rsquo;équivalences listant tous les mots possibles et leur racine, à des algo comme le Snwoball de Porter permettant de raciniser en fonction de règles précises, et donc sans aucun dictionnaire.<br />
C&rsquo;est ce dernier qui nous intéresse ici.</p>
<p>Un groupe de recherche basé sur le travail de Porter a développé <a href="http://snowballstem.org/">l&rsquo;algorithme snowball</a> pour beaucoup d&rsquo;autres langues.</p>
<p>Ils ont aussi développé un langage: le snowball, adapté à leurs algorithmes. Grâce à ce langage, ils ont écris un générateur de code en C.<br />
A la suite de quoi, plusieurs wrappers ont été écris dans différents languages, notamment<br />
&#8211; en <a href="https://github.com/snowballstem/pystemmer">python</a><br />
&#8211; en <a href="https://bitbucket.org/tebeka/snowball">Go</a><br />
&#8211; en Java<br />
&#8211; et en <a href="http://pecl.php.net/package/stem">PHP</a></p>
<p>Tous ont en communs qu&rsquo;ils utilisent le code généré en C.</p>
<p>Les inconvénients sont multiples :<br />
&#8211; On ne comprends rien au code généré<br />
&#8211; On est dépendant d&rsquo;une install serveur en PHP, car l&rsquo;implémentation actuelle est une extension PHP à compiler.</p>
<p>C&rsquo;est pourquoi, je me suis lancé dans l&rsquo;écriture d&rsquo;une série de classe native en PHP5, implémentant l&rsquo;algorithme Snowball, en espérant que ça serve à d&rsquo;autres.</p>
<p><a href="https://github.com/wamania/php-stemmer">https://github.com/wamania/php-stemmer</a></p>
]]></content>
			<link rel="replies" type="text/html" href="http://www.wamania.com/php5/stemmer-snowball-php5-natif.html#comments" thr:count="0"/>
		<link rel="replies" type="application/atom+xml" href="http://www.wamania.com/php5/stemmer-snowball-php5-natif.html/feed/atom" thr:count="0"/>
		<thr:total>0</thr:total>
		</entry>
		<entry>
		<author>
			<name>admin</name>
					</author>
		<title type="html"><![CDATA[OpenVZ &#8211; Firewall et backup]]></title>
		<link rel="alternate" type="text/html" href="http://www.wamania.com/server/openvz-firewall-et-backup.html" />
		<id>http://www.wamania.com/?p=142</id>
		<updated>2011-03-04T13:30:58Z</updated>
		<published>2011-03-04T13:14:41Z</published>
		<category scheme="http://www.wamania.com" term="Serveur" />		<summary type="html"><![CDATA[Aujourd&#8217;hui, je vais vous parler de Openvz, une solution de virtualisation simple et efficace. OpenVZ est une technique de virtualisation de niveau système d&#8217;exploitation basée sur le noyau Linux. &#160; Je n&#8217;expliquerais pas ici l&#8217;installation, ni même le peu de configuration à faire, mais plutôt des 2 points importants qui changent par rapport à la ... <span class="more"><a class="more-link" href="http://www.wamania.com/server/openvz-firewall-et-backup.html">[Read more...]</a></span>]]></summary>
		<content type="html" xml:base="http://www.wamania.com/server/openvz-firewall-et-backup.html"><![CDATA[<p>Aujourd&rsquo;hui, je vais vous parler de Openvz, une solution de virtualisation simple et efficace.</p>
<blockquote><p><strong>OpenVZ</strong> est une technique de virtualisation de niveau système d&rsquo;exploitation basée sur le noyau Linux.</p></blockquote>
<p>&nbsp;</p>
<p>Je n&rsquo;expliquerais pas ici l&rsquo;installation, ni même le peu de configuration à faire, mais plutôt des 2 points importants qui changent par rapport à la mise en place d&rsquo;un simple serveur physique: le firewall et les sauvegardes.<br />
Tout ce qui suis n&rsquo;a été testé que pour openVZ.</p>
<h2>Firewall</h2>
<p>La complexité du firewall avec openVZ réside dans le fait qu&rsquo;il y a au final plusieurs systèmes d&rsquo;exploitation sur un même serveur. Les serveurs virtuels ne sont pas totalement isolés de la machine physique comme le sont les KVM ou VirtualBox. Ainsi, le firewall de chaque VZ doit être configuré sur le serveur physique et non dans la VZ !</p>
<p>Comme j&rsquo;aime bien tout faire à la main, et savoir <strong>exactement</strong> ce qui se passe au niveau du firewall, je vais utiliser <a title="Iptables" href="http://fr.wikipedia.org/wiki/Iptables" target="_blank"><strong>iptables</strong></a>.</p>
<blockquote><p><em>Iptables</em> est également fréquemment utilisé pour faire référence aux composants de bas niveau (niveau kernel).</p></blockquote>
<p>Si vous êtes arrivé ici, vous êtes peut-être déjà tombé sur cette page : <a href="http://wiki.openvz.org/Setting_up_an_iptables_firewall">http://wiki.openvz.org/Setting_up_an_iptables_firewall</a><br />
J&rsquo;ai testé cette solution, et elle fonctionne pas trop mal à un défaut prêt, c&rsquo;est que j&rsquo;utilise Proxmox pour gérer mes VZ, et Proxmox, comme les autres gestionnaires à mon avis, utilisent les fichiers de config des VZ. Hors, l&rsquo;ajout de cette partie firewall rendait le fichier de config &laquo;&nbsp;illisible&nbsp;&raquo; par Proxmox. De plus, ça reste un script qui génère quelque chose qu&rsquo;on peut très bien faire nous même&#8230; alors faisons le nous même !</p>
<p>Créez un fichier /etc/init.d/firewall.sh</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Vider les tables actuelles</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-F</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-X</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> - Vidage : <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Si aucune règle n'est définie pour cette connexion, on accepte la connexion</span>
<span style="color: #666666; font-style: italic;"># Ainsi, aucun risque qu'on soit déco du SSH si qq chose se passait mal</span>
<span style="color: #666666; font-style: italic;"># A la fin du script, TOUTES les connexions auront une règle, et ne</span>
<span style="color: #666666; font-style: italic;"># passeront donc jamais par ces valeurs par défauts.</span>
iptables <span style="color: #660033;">-P</span> INPUT ACCEPT
iptables <span style="color: #660033;">-P</span> FORWARD ACCEPT
iptables <span style="color: #660033;">-P</span> OUTPUT ACCEPT
<span style="color: #7a0874; font-weight: bold;">echo</span> - Régle ACCEPT par défaut <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Autoriser le ping sur le serveur</span>
<span style="color: #666666; font-style: italic;"># Vous pouvez mettre DROP si vous refusez le ping</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #7a0874; font-weight: bold;">echo</span> - Autoriser <span style="color: #c20cb9; font-weight: bold;">ping</span> : <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># On autorise le loopback</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> lo <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-o</span> lo <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> lo <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #7a0874; font-weight: bold;">echo</span> - Autoriser loopback : <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Pour éviter de couper les connexions en cours</span>
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> RELATED,ESTABLISHED <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> RELATED,ESTABLISHED <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #7a0874; font-weight: bold;">echo</span> - Ne pas couper les connexions en cours : <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Autoriser les connexions SSH sur le serveur</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #7a0874; font-weight: bold;">echo</span> - Autoriser SSH : <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Régles pour notre VZ 101</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-s</span> 111.222.333.100 <span style="color: #660033;">-d</span> 111.222.333.101 <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-d</span> 111.222.333.101 <span style="color: #660033;">-m</span> multiport <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dports</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #7a0874; font-weight: bold;">echo</span> - Serveur physique 111.222.333.100 autorisé sur la VZ <span style="color: #000000;">101</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> - Connexions SSH autorisées sur la VZ <span style="color: #000000;">101</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Régles pour notre VZ 102</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-s</span> 111.222.333.100 <span style="color: #660033;">-d</span> 111.222.333.102 <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-d</span> 111.222.333.102 <span style="color: #660033;">-m</span> multiport <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dports</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #7a0874; font-weight: bold;">echo</span> - Serveur physique 111.222.333.100 autorisé sur la VZ <span style="color: #000000;">102</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> - Connexions SSH autorisées sur la VZ <span style="color: #000000;">102</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Toutes les autres connexions sur les VZ sont rejetées</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-d</span> 111.222.333.101 <span style="color: #660033;">-j</span> DROP
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-d</span> 111.222.333.102 <span style="color: #660033;">-j</span> DROP
<span style="color: #7a0874; font-weight: bold;">echo</span> - Connexions entrantes des VZ rejetées <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># On accepte évidemment toutes les connexions sortantes de nos VZ</span>
<span style="color: #666666; font-style: italic;"># et de notre serveur physique</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-s</span> 111.222.333.101 <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-s</span> 111.222.333.102 <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #7a0874; font-weight: bold;">echo</span> - Connexions sortantes des VZ acceptées <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Toutes les connexions entrantes sur le serveur physique sont rejetées</span>
<span style="color: #666666; font-style: italic;"># sauf celles dont on a définit les règles précédemment (notamment SSH plus haut)</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-j</span> DROP
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-j</span> DROP
&nbsp;
<span style="color: #666666; font-style: italic;"># Empêcher le Syn-Flood</span>
iptables <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--syn</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">/</span>second <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-p</span> udp <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">/</span>second <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #7a0874; font-weight: bold;">echo</span> - Limiter le Syn-Flood : <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Empêcher le spoofing</span>
iptables <span style="color: #660033;">-N</span> SPOOFED
iptables <span style="color: #660033;">-A</span> SPOOFED <span style="color: #660033;">-s</span> 127.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> DROP
iptables <span style="color: #660033;">-A</span> SPOOFED <span style="color: #660033;">-s</span> 169.254.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">12</span> <span style="color: #660033;">-j</span> DROP
iptables <span style="color: #660033;">-A</span> SPOOFED <span style="color: #660033;">-s</span> 172.16.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">12</span> <span style="color: #660033;">-j</span> DROP
iptables <span style="color: #660033;">-A</span> SPOOFED <span style="color: #660033;">-s</span> 192.168.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">16</span> <span style="color: #660033;">-j</span> DROP
iptables <span style="color: #660033;">-A</span> SPOOFED <span style="color: #660033;">-s</span> 10.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> DROP
<span style="color: #7a0874; font-weight: bold;">echo</span> - Bloquer le Spoofing : <span style="color: #7a0874; font-weight: bold;">&#91;</span>OK<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>

<p>Dans lequel :</p>
<ul>
<li>111.222.333.100 est le serveur physique</li>
<li>111.222.333.101 est notre VZ 101</li>
<li>111.222.333.102 est notre VZ 102</li>
</ul>
<p>Je vais m&rsquo;attarder un peu sur les 2 lignes correspondantes au VZ</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-s</span> 111.222.333.100 <span style="color: #660033;">-d</span> 111.222.333.102 <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-d</span> 111.222.333.102 <span style="color: #660033;">-m</span> multiport <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dports</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT</pre></td></tr></table></div>

<p><em>Notez que<strong> -s = source</strong> et <strong>-d = destination</strong></em></p>
<p>La 1ère autorise toute connexion de notre serveur physique sur n&rsquo;importe quel port de notre VZ. J&rsquo;utilise ce type d&rsquo;autorisation par exemple pour autoriser un serveur web à voir complétement un serveur de base de données. Le reste du monde verra un mur, mais le serveur web aura un accès total.<br />
La 2ième ligne autorise le reste du monde (et notamment nous) à se connecter au port 22, donc par SSH pour pouvoir contrôler notre VZ. Mais on pourrait aussi supprimer cette ligne, ce qui rendrait le serveur totalement invisible de l&rsquo;extérieur. Il faudrait alors passer par le serveur physique pour établir la connexion SSH sur notre VZ. Ce qui est un peu contraignant, mais assure une sécurité maximale !</p>
<p>C&rsquo;est ensuite à vous d&rsquo;adapter ! Si votre VZ est un serveur web, autorisez le port 80, etc</p>
<p>Pour l&rsquo;activer au démarrage :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># votre fichier firewall.sh doit bien être dans /etc/init.d/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> update-rc.d firewall.sh defaults</pre></td></tr></table></div>

<p>Notez que vous pouvez le relancer n&rsquo;importe quand sans problème, notamment lorsque vous y faites une modification.</p>
<p>&nbsp;</p>
<h2>Backup</h2>
<p>Ce script de backup a été honteusement pompé, mais je ne sais plus où.</p>
<p>Je l&rsquo;ai malgré tout modifié, notamment sur les commandes FTP d&rsquo;effacement des vieux backup, pour permettre d&rsquo;effacer des répertoires non-vides.<br />
Pour le faire tourner, il vous faudra <strong>ncftp</strong> et bien sûr <strong>vzdump</strong> qui doit être avec OpenVZ</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### Configuration system ###</span>
<span style="color: #007800;">BACKUP</span>=<span style="color: #000000; font-weight: bold;">/</span>vz<span style="color: #000000; font-weight: bold;">/</span>dump<span style="color: #000000; font-weight: bold;">/</span>backup.<span style="color: #007800;">$$</span>
<span style="color: #007800;">NOW</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%Y-%m-%d&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">LAST</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y-<span style="color: #000000; font-weight: bold;">%</span>m-<span style="color: #000000; font-weight: bold;">%</span>d <span style="color: #660033;">-d</span> <span style="color: #ff0000;">'-14 days'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">DAY</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%a&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">HOSTNAME</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(hostname)</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### Configuration du serveur FTP ###</span>
<span style="color: #007800;">FTPD</span>=<span style="color: #ff0000;">&quot;/&quot;</span>
<span style="color: #007800;">FTPU</span>=<span style="color: #ff0000;">&quot;user&quot;</span>
<span style="color: #007800;">FTPP</span>=<span style="color: #ff0000;">&quot;password&quot;</span>
<span style="color: #007800;">FTPS</span>=<span style="color: #ff0000;">&quot;host&quot;</span>
<span style="color: #007800;">NCFTP</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(which ncftp)</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### Mail ###</span>
<span style="color: #007800;">EMAILID</span>=<span style="color: #ff0000;">&quot;wamania@ailleurs.fr&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### On crée le répertoire local de backup ###</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$BACKUP</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$BACKUP</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### dump des VZ ###</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>vzdump <span style="color: #660033;">--suspend</span> <span style="color: #660033;">--compress</span> <span style="color: #660033;">--stdexcludes</span> <span style="color: #660033;">--dumpdir</span>=<span style="color: #007800;">$BACKUP</span> <span style="color: #000000;">103</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>vzdump <span style="color: #660033;">--suspend</span> <span style="color: #660033;">--compress</span> <span style="color: #660033;">--stdexcludes</span> <span style="color: #660033;">--dumpdir</span>=<span style="color: #007800;">$BACKUP</span> <span style="color: #000000;">104</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>vzdump <span style="color: #660033;">--suspend</span> <span style="color: #660033;">--compress</span> <span style="color: #660033;">--stdexcludes</span> <span style="color: #660033;">--dumpdir</span>=<span style="color: #007800;">$BACKUP</span> <span style="color: #000000;">107</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### On envoi le répertoire par FTP et on efface celui de J-14 ###</span>
<span style="color: #007800;">$NCFTP</span> <span style="color: #660033;">-u</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$FTPU</span>&quot;</span> <span style="color: #660033;">-p</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$FTPP</span>&quot;</span> <span style="color: #007800;">$FTPS</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
mkdir $FTPD/$NOW
cd $FTPD/$NOW
lcd $BACKUP
mput *
cd $FTPD/$LAST
rm *.*
cd $FTPD
rmdir $FTPD/$LAST
quit
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### Find out if ftp backup failed or not ### </span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> == <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span> 
<span style="color: #007800;">T</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>backup.success 
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Date: <span style="color: #007800;">$(date)</span>&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #007800;">$T</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Hostname: <span style="color: #007800;">$(hostname)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span><span style="color: #007800;">$T</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup success&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span><span style="color: #007800;">$T</span>
mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;BACKUP SUCCESS&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$EMAILID</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$T</span>  
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #007800;">$T</span>  
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #007800;">$BACKUP</span>  
<span style="color: #000000; font-weight: bold;">else</span>  
<span style="color: #007800;">T</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>backup.fail  
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Date: <span style="color: #007800;">$(date)</span>&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #007800;">$T</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Hostname: <span style="color: #007800;">$(hostname)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span><span style="color: #007800;">$T</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup failed&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span><span style="color: #007800;">$T</span>
mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;BACKUP FAILED&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$EMAILID</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$T</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #007800;">$T</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>

<p>Et en cadeau bonus, j&rsquo;y inclus un script qui permet de lister le contenu de votre FTP récursivement en ligne de commande.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### Configuration du serveur FTP ###</span>
<span style="color: #007800;">FTPD</span>=<span style="color: #ff0000;">&quot;/&quot;</span>
<span style="color: #007800;">FTPU</span>=<span style="color: #ff0000;">&quot;user&quot;</span>
<span style="color: #007800;">FTPP</span>=<span style="color: #ff0000;">&quot;password&quot;</span>
<span style="color: #007800;">FTPS</span>=<span style="color: #ff0000;">&quot;host&quot;</span>
<span style="color: #007800;">NCFTP</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(which ncftp)</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Liste récursive</span>
<span style="color: #007800;">$NCFTP</span> <span style="color: #660033;">-u</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$FTPU</span>&quot;</span> <span style="color: #660033;">-p</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$FTPP</span>&quot;</span> <span style="color: #007800;">$FTPS</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
dir -Rt $FTPD
quit
EOF</span></pre></td></tr></table></div>

]]></content>
			<link rel="replies" type="text/html" href="http://www.wamania.com/server/openvz-firewall-et-backup.html#comments" thr:count="2"/>
		<link rel="replies" type="application/atom+xml" href="http://www.wamania.com/server/openvz-firewall-et-backup.html/feed/atom" thr:count="2"/>
		<thr:total>2</thr:total>
		</entry>
		<entry>
		<author>
			<name>admin</name>
					</author>
		<title type="html"><![CDATA[Domowam &#8211; Text-to-speech]]></title>
		<link rel="alternate" type="text/html" href="http://www.wamania.com/domotique/domowam-text-to-speech.html" />
		<id>http://www.wamania.com/?p=108</id>
		<updated>2011-02-24T10:20:05Z</updated>
		<published>2011-02-24T10:18:49Z</published>
		<category scheme="http://www.wamania.com" term="Domotique" />		<summary type="html"><![CDATA[La synthèse vocale n'est pas vraiment indispensable pour de la domotique, mais bon, on est des geeks ou pas ?
Après avoir essayé un paquet de truc, je suis tombé sur google translate et son moteur de text-to-speech intégré. Clairement c'est une des meilleures synthèses vocales que j'ai entendu, j'ai donc décidé de l'utiliser (uniquement en ligne, faudra donc un accès internet constant (ou presque)).]]></summary>
		<content type="html" xml:base="http://www.wamania.com/domotique/domowam-text-to-speech.html"><![CDATA[<p><img class="alignleft size-full wp-image-136" title="text-to-speech-icon-large" src="http://www.wamania.com/wp-content/uploads/2011/02/text-to-speech-icon-large.png" alt="" width="163" height="163" srcset="http://www.wamania.com/wp-content/uploads/2011/02/text-to-speech-icon-large.png 163w, http://www.wamania.com/wp-content/uploads/2011/02/text-to-speech-icon-large-150x150.png 150w, http://www.wamania.com/wp-content/uploads/2011/02/text-to-speech-icon-large-140x140.png 140w" sizes="(max-width: 163px) 100vw, 163px" /></p>
<h3>Text-to-Speech</h3>
<p>La synthèse vocale n&rsquo;est pas vraiment indispensable pour de la domotique, mais bon, on est des geeks ou pas ?</p>
<p>Après avoir essayé un paquet de truc, je suis tombé sur google translate et son moteur de text-to-speech intégré. Clairement c&rsquo;est une des meilleures synthèses vocales que j&rsquo;ai entendu, j&rsquo;ai donc décidé de l&rsquo;utiliser (uniquement en ligne, faudra donc un accès internet constant (ou presque)).<br />
Mais avant tout, les pré-requis :</p>
<p>En effet, si comme moi vous avez installé une ubuntu server, vous n&rsquo;avez pas le son. Il faut installer ALSA :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> alsa-utils
<span style="color: #c20cb9; font-weight: bold;">sudo</span> adduser ton_user audio
<span style="color: #c20cb9; font-weight: bold;">sudo</span> adduser www-data audio
<span style="color: #c20cb9; font-weight: bold;">sudo</span> reboot</pre></td></tr></table></div>

<p>A ce stade, le son fonctionne, mais les volumes sont à 0, donc vous entendrez rien, il faut monter le son !<br />
Pour cela, on va utiliser <strong>amixer</strong> :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> amixer <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #ff0000;">&quot;Speaker&quot;</span> <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> unmute
<span style="color: #c20cb9; font-weight: bold;">sudo</span> amixer <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #ff0000;">&quot;Master&quot;</span> <span style="color: #000000;">70</span><span style="color: #000000; font-weight: bold;">%</span> unmute</pre></td></tr></table></div>

<p>Maintenant que vous avez du son, passons à la synthèse vocale !<br />
Vous aurez besoin de wget pour récupérer les sons chez google et nous allons utiliser madplay comme lecteur</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> <span style="color: #c20cb9; font-weight: bold;">wget</span> madplay</pre></td></tr></table></div>

<p>Enfin, le script <strong>speech.sh</strong> , que je commenterais après :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">EXP</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">|</span> md5sum <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">DIR</span>=<span style="color: #000000; font-weight: bold;">/</span>chemin<span style="color: #000000; font-weight: bold;">/</span>vers<span style="color: #000000; font-weight: bold;">/</span>domoyou<span style="color: #000000; font-weight: bold;">/</span>tts<span style="color: #000000; font-weight: bold;">/</span>cache
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$DIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$EXP</span>.mp3 <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">--user-agent</span> <span style="color: #ff0000;">&quot;Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.04 (lucid) Firefox/3.6.13&quot;</span> \
    <span style="color: #660033;">-O</span> <span style="color: #007800;">$DIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$EXP</span>.mp3 \
    <span style="color: #ff0000;">&quot;http://translate.google.fr/translate_tts?q=$1&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
madplay <span style="color: #007800;">$DIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$EXP</span>.mp3</pre></td></tr></table></div>

<p>Nous définissons 2 variables :</p>
<ul>
<li>EXP correspond au code md5 de la phrase que vous avez passé en paramètre.</li>
<li>DIR sera le répertoire de cache</li>
</ul>
<p>Comme nous devons interroger google pour récupérer les MP3 correspondants à nos phrases, il est préférable de mettre un petit système de cache, pour éviter de redemander à chaque fois les mêmes phrases.<br />
Ainsi la ligne suivante vérifie si le MP3 correspondant à la phrase en paramètre existe, si non, alors on la demande à google.<br />
Notez le user-agent obligatoire</p>
<p>Enfin dernière ligne, on lance la lecture du MP3</p>
<p>Deux choses à pas oublier !</p>
<ul>
<li>Pensez à créer le répertoire de cache</li>
<li>Pensez à brancher des enceintes (huhu)</li>
</ul>
<p>Pour l&rsquo;utiliser :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>chemin<span style="color: #000000; font-weight: bold;">/</span>vers<span style="color: #000000; font-weight: bold;">/</span>domoyou<span style="color: #000000; font-weight: bold;">/</span>tts<span style="color: #000000; font-weight: bold;">/</span>speech.sh <span style="color: #ff0000;">&quot;Alors les geeks, ça rox ou pas ?&quot;</span></pre></td></tr></table></div>

]]></content>
	<link href="http://translate.google.fr/translate_tts?q=" rel="enclosure" length="0" type="audio/mpeg" />
		<link rel="replies" type="text/html" href="http://www.wamania.com/domotique/domowam-text-to-speech.html#comments" thr:count="0"/>
		<link rel="replies" type="application/atom+xml" href="http://www.wamania.com/domotique/domowam-text-to-speech.html/feed/atom" thr:count="0"/>
		<thr:total>0</thr:total>
		</entry>
		<entry>
		<author>
			<name>admin</name>
					</author>
		<title type="html"><![CDATA[Domowam &#8211; La carte relais]]></title>
		<link rel="alternate" type="text/html" href="http://www.wamania.com/domotique/domowam-la-carte-relais.html" />
		<id>http://www.wamania.com/?p=104</id>
		<updated>2011-02-24T09:33:11Z</updated>
		<published>2011-02-23T14:55:09Z</published>
		<category scheme="http://www.wamania.com" term="Domotique" />		<summary type="html"><![CDATA[<u><b>Driver de la carte</u></b>

Dans ce post, nous allons installer un driver plus basique pour la carte de relais de l'installation décrite dans le précédent post.
On va compiler le driver directement sur la carte mère !

Il est constitué de 2 fichiers .cpp (et un makefile): relayd.cpp sera un démon, toujours en fonctionnement et qui écoutera le système en attente d'un ordre., relay.cpp sera un simple programme en ligne de commande permettant d'envoyer un ordre.
]]></summary>
		<content type="html" xml:base="http://www.wamania.com/domotique/domowam-la-carte-relais.html"><![CDATA[<h2>Driver de la carte</h2>
<p>Dans ce post, nous allons installer un driver basique pour la carte de relais de l&rsquo;installation décrite dans le précédent post.</p>
<p><a href="http://www.wamania.com/wp-content/uploads/2011/02/product_159.jpg"><img class="aligncenter size-full wp-image-113" title="Carte relais" src="http://www.wamania.com/wp-content/uploads/2011/02/product_159.jpg" alt="Carte relais" width="300" height="300" srcset="http://www.wamania.com/wp-content/uploads/2011/02/product_159.jpg 300w, http://www.wamania.com/wp-content/uploads/2011/02/product_159-150x150.jpg 150w, http://www.wamania.com/wp-content/uploads/2011/02/product_159-140x140.jpg 140w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>On va compiler le driver directement sur la carte mère !<br />
Vous trouverez les drivers ici : <a href="http://www.wamania.com/public/domowam/driver_relay.zip">drivers carte relais</a></p>
<p>Très largement inspiré d&rsquo;ici : <a href="http://www.civade.com/post/2009/05/23/36-domotique-homeautomationx10-open-source-heyu-linux-ubuntu-relais-usb-velleman-k8055" target="_blank">http://www.civade.com/post/2009/05/23/36-domotique-homeautomationx10-open-source-heyu-linux-ubuntu-relais-usb-velleman-k8055</a></p>
<p>Il est constitué de 2 fichiers .cpp  et un makefile</p>
<ul>
<li>relayd.cpp est un démon, toujours en fonctionnement et qui écoutera le système en attente d&rsquo;un ordre.</li>
<li>relay.cpp est un simple programme en ligne de commande permettant d&rsquo;envoyer un ordre.</li>
</ul>
<p>Voici les modification que j&rsquo;y ai apporté :</p>
<ul>
<li>Suppression du fork (explication plus loin)</li>
<li>Ajout de #include &lt;stdio.h&gt; dans relay.cpp (pcq sinon -&gt; error)</li>
</ul>
<p>Je rappelle que tout ça doit se faire sur sur votre installation, d&rsquo;ailleurs donnons lui un nom : <strong>DomoYou !</strong></p>
<p>Pour compiler ça, on va avoir besoin de :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> <span style="color: #c20cb9; font-weight: bold;">g++</span> libusb-dev</pre></td></tr></table></div>

<p>Ensuite, créez un répertoire relayd, mettez y les 3 fichiers et tapez simplement :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span></pre></td></tr></table></div>

<p>et enfin, si tout se passe bien</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> .<span style="color: #000000; font-weight: bold;">/</span>relayd</pre></td></tr></table></div>

<p>Chez moi, la carte relay est sur USB0 et l&rsquo;as toujours été. Si ça ne fonctionne pas pour vous, essayez de changer ça dans le relayd.cpp et ressayez.</p>
<p>Pour tester la carte relais, taper simplement</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># pour allumer</span>
.<span style="color: #000000; font-weight: bold;">/</span>relay <span style="color: #c20cb9; font-weight: bold;">write</span> digital <span style="color: #000000;">1</span> <span style="color: #000000;">1</span>
<span style="color: #666666; font-style: italic;"># pour éteindre</span>
.<span style="color: #000000; font-weight: bold;">/</span>relay <span style="color: #c20cb9; font-weight: bold;">write</span> digital <span style="color: #000000;">1</span> <span style="color: #000000;">0</span></pre></td></tr></table></div>

<p>Vous devez clairement et distinctement entendre le &laquo;&nbsp;clic&nbsp;&raquo; du relais.<br />
Pour info, le 1er &laquo;&nbsp;1&nbsp;&raquo; est le numéro du port, donc de 1 à 8<br />
Le seconde &laquo;&nbsp;1&nbsp;&raquo; ou &laquo;&nbsp;0&nbsp;&raquo; signifie juste &laquo;&nbsp;on&nbsp;&raquo; ou &laquo;&nbsp;off&nbsp;&raquo;</p>
<p>Vous pouvez aussi essayer :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>relay <span style="color: #c20cb9; font-weight: bold;">read</span> digital <span style="color: #000000;">1</span></pre></td></tr></table></div>

<p>Sur ce dernier point, je reviens sur ma raison de l&rsquo;élimination du fork dans le code de la partie démon du driver. Une carte relais ne contient pas d&rsquo;indication de statut, c&rsquo;est à dire que si on ne garde pas nous même une trace du statut (ON ou OFF), on ne peut pas demander à la carte relais, ça n&rsquo;est pas prévu. Hors, le fork va créer un nouveau processus indépendant à chaque nouvel ordre. C&rsquo;est le principe de fonctionnement de beaucoup de logiciel serveur. Mais c&rsquo;est complétement inutile et même embêtant ici.<br />
En effet, imaginons :</p>
<ul>
<li>le port 1 est à OFF</li>
<li>On envoi l&rsquo;ordre de mettre le port 1 à ON</li>
<li>le démon reçoit l&rsquo;ordre et crée un processus fils pour exécuter l&rsquo;ordre.</li>
<li>Le processus fils exécute l&rsquo;ordre, puis meurt</li>
<li>Le démon n&rsquo;a aucun retour du processus fils, et ne sait donc pas s&rsquo;il y a eu changement de statut.</li>
</ul>
<p>C&rsquo;est d&rsquo;autant plus ironique que le développeur de ces drivers a inclus la gestion du statut des ports, mais n&rsquo;a pas pensé à le faire mettre à jour par les processus fils. J&rsquo;ai préféré simplement enlevé le fork, c&rsquo;est à dire qu&rsquo;il ne reste que le démon &laquo;&nbsp;parent&nbsp;&raquo; et que c&rsquo;est lui et lui seul qui exécute les ordres. Comme ça, nos statuts sont toujours à jour.</p>
<p>Nous allons maintenant faire en sorte que le démon relayd se lance automatiquement au démarrage. Pour cela, créez le fichier <strong>/etc/init.d/relayd</strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Script de demarage du driver de la carte relay /usr/bin/relayd</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">##################################################</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-e</span>
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>lsb<span style="color: #000000; font-weight: bold;">/</span>init-functions <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    . <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>lsb<span style="color: #000000; font-weight: bold;">/</span>init-functions
    <span style="color: #007800;">logbegin</span>=<span style="color: #ff0000;">&quot;log_begin_msg&quot;</span>
    <span style="color: #007800;">logend</span>=<span style="color: #ff0000;">&quot;log_end_msg&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #007800;">logbegin</span>=<span style="color: #ff0000;">&quot;echo -n&quot;</span>
    <span style="color: #007800;">logend</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;echo .<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Exit if the daemon binary is NOT available, executable, etc.</span>
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-x</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>relayd <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Start function</span>
d_start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    start-stop-daemon <span style="color: #660033;">--start</span> <span style="color: #660033;">--name</span> relayd <span style="color: #660033;">--exec</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>relayd
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Stop function</span>
d_stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    start-stop-daemon <span style="color: #660033;">--stop</span> <span style="color: #660033;">--name</span> relayd
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
    start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #007800;">$logbegin</span> <span style="color: #ff0000;">&quot;Starting relayd...&quot;</span>
        d_start
        <span style="color: #007800;">$logend</span> <span style="color: #007800;">$?</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
    stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #007800;">$logbegin</span> <span style="color: #ff0000;">&quot;Stopping relayd...&quot;</span>
        d_stop
        <span style="color: #007800;">$logend</span> <span style="color: #007800;">$?</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
    restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #007800;">$0</span> stop
        <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
        <span style="color: #007800;">$0</span> start
        <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        log_success_msg <span style="color: #ff0000;">&quot;Usage: $0 {start|stop|reload|restart}&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></td></tr></table></div>

<p>Attention, il faudra bien penser à copier le binaire relayd vers /usr/bin/</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>chemin<span style="color: #000000; font-weight: bold;">/</span>vers<span style="color: #000000; font-weight: bold;">/</span>domoyou<span style="color: #000000; font-weight: bold;">/</span>relayd <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>relayd</pre></td></tr></table></div>

<p>Enfin, pour appeler automatiquement au démarrage :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> update-rc.d relayd defaults</pre></td></tr></table></div>

<p><em><strong>On a maintenant une carte relais qui vous obéit au doigt et à l&rsquo;oeil !</strong></em></p>
]]></content>
			<link rel="replies" type="text/html" href="http://www.wamania.com/domotique/domowam-la-carte-relais.html#comments" thr:count="0"/>
		<link rel="replies" type="application/atom+xml" href="http://www.wamania.com/domotique/domowam-la-carte-relais.html/feed/atom" thr:count="0"/>
		<thr:total>0</thr:total>
		</entry>
		<entry>
		<author>
			<name>admin</name>
					</author>
		<title type="html"><![CDATA[Domowam &#8211; La domotique Home made]]></title>
		<link rel="alternate" type="text/html" href="http://www.wamania.com/domotique/domowam-la-domotique-home-made.html" />
		<id>http://www.wamania.com/?p=13</id>
		<updated>2011-02-23T17:45:02Z</updated>
		<published>2011-02-21T19:48:00Z</published>
		<category scheme="http://www.wamania.com" term="Domotique" />		<summary type="html"><![CDATA[<u><b>Présentation</b></u>

Ce post est le 1er d'une longue série (enfin j'espère) concernant un système de domotique dont le but sera d'être à la fois complet, simple et surtout peu cher.
Je posterais au fur à mesure que je le construit, mais son état d'avancement me permet déjà d'en parler un peu.]]></summary>
		<content type="html" xml:base="http://www.wamania.com/domotique/domowam-la-domotique-home-made.html"><![CDATA[<h2>Présentation</h2>
<p>Ce post est le 1er d&rsquo;une longue série (enfin j&rsquo;espère) concernant un système de domotique dont le but sera d&rsquo;être à la fois complet, simple et surtout peu cher.<br />
Je posterais au fur à mesure que je le construis, mais son état d&rsquo;avancement me permet déjà d&rsquo;en parler un peu.</p>
<h2>Matériel</h2>
<p>On commence par là parce que forcement, sans matos, on peut pas faire grand chose.<br />
N&rsquo;étant pas fan des centrales nucléaires pour alimenter une lumière, j&rsquo;ai décidé de faire un système le plus adapté possible.<br />
Il répond à 3 critères primordiaux :</p>
<ul>
<li>totalement silencieux</li>
<li>très faible consommation</li>
<li>relativement faible coût.</li>
</ul>
<p>Il se compose de :</p>
<h3>Carte mère</h3>
<p>Une carte mère ITX (17cmx17cm) neuve achetée sur CDiscount : <a hreflang="fr" href="http://www.cdiscount.com/informatique/cartes-meres/asus-at5nm10-i/f-107651101-at5nm10i.html">AT5NM10-I</a>, 76€ au moment ou j&rsquo;écris. Cette carte est totalement silencieuse, et son gros radiateur passif est plutôt rassurant. Elle contient déjà le processeur, un atom (donc faible consommation).<br />
A l&rsquo;origine, j&rsquo;ai cherché une veille carte mère sur ebay, mais au final, mettre 30 ou 40€ pour avoir une épave, souvent avec ventilo&#8230; alors qu&rsquo;à 76€ on peut trouver ce petit bijoux&#8230;<br />
Comme RAM, j&rsquo;ai pris une 1Go, ce qui largement suffisant pour ce qu&rsquo;on veut en faire, inutile d&rsquo;augmenter les coûts&#8230;</p>
<p><a title="asus AT5NM10-I" href="/public/domowam/asus_at5nm10_i.jpg"><img style="display: block; margin: 0 auto;" title="asus AT5NM10-I, fév. 2011" src="/public/domowam/.asus_at5nm10_i_m.jpg" alt="asus AT5NM10-I" /></a></p>
<h3>Disque dur</h3>
<p>Je viens de le recevoir aujourd&rsquo;hui, il s&rsquo;agit d&rsquo;un Corsair SSD Force series de 40Go<br />
Les SSD c&rsquo;est cool, faible consommation, aucun bruit et 40Go, c&rsquo;est largement suffisant pour la domotique.<br />
Acheté sur ebay pour 65€ tout compris.</p>
<p><a title="Corsair SSD f40" href="/public/domowam/corsair-ssd-force-f40.jpeg"><img style="display: block; margin: 0 auto;" title="Corsair SSD f40, fév. 2011" src="/public/domowam/.corsair-ssd-force-f40_m.jpg" alt="Corsair SSD f40" /></a></p>
<h3>Carte relais</h3>
<p>Un relais est un mécanisme permettant grâce à de petits courants de piloter de gros interrupteurs.<br />
En d&rsquo;autres termes, ça permet de contrôler du 220v jusqu&rsquo;à 2500W (ce qui est largement suffisant pour nos lampes de 60W) grâce à un port série ou USB<br />
Une carte relais est assez limité pour de la domotique, mais ça sera notre première étape. Elle coûte 38€ pour 8 ports, ce qui fait 4.75€ par port. Ça en fait la solution la moins cher pour contrôler nos prises de courant.<br />
<a hreflang="fr" href="http://sigma-shop.com/product/8/eight-channel-usb-relay-controller-rs232-serial-controlled-12v.html">Achetée ici</a> (il en existe des moins chères avec moins de port)</p>
<p><img style="display: block; margin: 0 auto;" title="carte relais, fév. 2011" src="/public/domowam/product_159.jpg" alt="carte relais" /></p>
<h3>Alimentation</h3>
<p>J&rsquo;ai commencé par un pavé de 450W et son ventilo de 747.<br />
Puis, j&rsquo;ai cherché ce qui pouvait exister. Et j&rsquo;ai trouvé les Picopsu, ce sont de minuscules alim pour PC qui ne comprennent pas de transfo : <a title="picopsu 150" href="/public/domowam/picopsu150xt_4.jpg"><img style="display: block; margin: 0 auto;" title="picopsu 150, fév. 2011" src="/public/domowam/.picopsu150xt_4_m.jpg" alt="picopsu 150" /></a></p>
<p><strong>Attention</strong> : J&rsquo;ai d&rsquo;abord acheté un picopsu 120, qui est théoriquement largement suffisant, sauf qu&rsquo;il n&rsquo;a qu&rsquo;une broche 20pins et pas de broche ATX-P4, j&rsquo;ai tout essayé pour le faire marcher, mais rien à faire. Il faudra donc bien prendre un picopsu 150 qui lui est adapté aux cartes récentes.<br />
Acheté sur ebay, 37$ en provenance des States (4 semaines pour arriver, grrrrr)</p>
<p>Il faudra y ajouter un transfo 12v d&rsquo;environ 90W.<br />
En pratique, mon installation consomme environ 18W, mais vaut mieux prévoir de la marge, déjà pour éviter de faire chauffer le transfo en cas de charge, et en plus parce qu&rsquo;on ne sait ce qu&rsquo;on va y ajouter à l&rsquo;avenir !<br />
Bref, j&rsquo;ai préféré ne pas économiser 3 kopek là dessus.<br />
Avec un peu de chance vous aurez ça sous la main. (tout geek possède son stock de transfo de vieux pc portables).</p>
<p>Résultat : <a title="Installation domowam" href="/public/domowam/IMG041.jpg"><img style="display: block; margin: 0 auto;" title="Installation domowam, fév. 2011" src="/public/domowam/.IMG041_m.jpg" alt="Installation domowam" /></a></p>
<h2>Installation</h2>
<p>Bon, on a tout !<br />
Evidemment, pas de windows, faut pas abuser.<br />
J&rsquo;ai donc installé une ubuntu-server-amd64, installation que je ne décrirais pas ici, mais pensez bien à mettre une IP static pour pouvoir s&rsquo;y connecter ensuite. Sur le SSD j&rsquo;ai créé une partition principale de 15Go, une swap de 1Go et une partition indépendante de 24Go ou on y mettra notre bazar.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get update</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get upgrade</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> openssh-server</pre></td></tr></table></div>

<p>On peut commencer les choses sérieuses &#8230; dans le prochain post !</p>
]]></content>
			<link rel="replies" type="text/html" href="http://www.wamania.com/domotique/domowam-la-domotique-home-made.html#comments" thr:count="1"/>
		<link rel="replies" type="application/atom+xml" href="http://www.wamania.com/domotique/domowam-la-domotique-home-made.html/feed/atom" thr:count="1"/>
		<thr:total>1</thr:total>
		</entry>
		<entry>
		<author>
			<name>admin</name>
					</author>
		<title type="html"><![CDATA[PHP et Exchange 2007/2010]]></title>
		<link rel="alternate" type="text/html" href="http://www.wamania.com/php5/php-et-exchange-2007-2010.html" />
		<id>http://www.wamania.com/?p=16</id>
		<updated>2011-02-22T15:51:54Z</updated>
		<published>2010-07-23T11:22:00Z</published>
		<category scheme="http://www.wamania.com" term="PHP5" />		<summary type="html"><![CDATA[<p>Je vais vous présenter ici comment interfacer PHP avec Exchange.</p> <h2>Introduction</h2> <p>Exchange est un incontournable dans le milieu de l'entreprise. Malheureusement, c'est du M$, donc fermé et réservé au C#.</p> <p>Jusqu'à maintenant, et si vous êtes arrivé là, vous devez déjà le savoir, on pouvait utiliser WebDav.</p> <p>Or, M$ a annoncé la fin de WebDav sur Exchange 2010, au profit de EWS (Exchange Web Services), un système de services Web en Soap. La première approche n'est pas évidente. J'ai donc décidé d'en faire un tuto ici.</p>]]></summary>
		<content type="html" xml:base="http://www.wamania.com/php5/php-et-exchange-2007-2010.html"><![CDATA[<p>Je vais vous présenter ici comment interfacer PHP avec Exchange.<br />
<img class="alignleft size-thumbnail wp-image-54" title="hosted-exchange-logo" src="http://www.wamania.com/wp-content/uploads/2010/07/hosted-exchange-logo-150x150.jpg" alt="" width="150" height="150" /></p>
<h2>Introduction</h2>
<p>Exchange est un incontournable dans le milieu de l&rsquo;entreprise. Malheureusement, c&rsquo;est du M$, donc fermé et réservé au C#.</p>
<p>Jusqu&rsquo;à maintenant, et si vous êtes arrivé là, vous devez déjà le savoir, on pouvait utiliser WebDav.</p>
<p>Or, M$ a annoncé la fin de WebDav sur Exchange 2010, au profit de EWS (Exchange Web Services), un système de services Web en Soap. La première approche n&rsquo;est pas évidente. J&rsquo;ai donc décidé d&rsquo;en faire un tuto ici.</p>
<p><span id="more-16"></span></p>
<h2>Prérequis</h2>
<ul>
<li>Un serveur Exchange 2007 SP1 ou 2010</li>
<li>Un serveur avec PHP5.2 avec cUrl et Soap (logiquement installés par défaut) en ligne de commande de préférence.</li>
</ul>
<h2>PHP-EWS</h2>
<p>Un gars bien a réunis ses idées avec celles d&rsquo;autres pour créer une librairie cohérente. Malheureusement, ce gars bien n&rsquo;est pas doué pour la doc&#8230; http://code.google.com/p/php-ews/</p>
<p>Il faudra prendre la version sur le SVN (sous windows vous pouvez utiliser &laquo;&nbsp;Tortoise&nbsp;&raquo;)</p>
<p>Considérons donc que vous avez un répertoire de travail EWS, placez y php-ews dedans. J&rsquo;ai appelé le répertoire contenant php-ews tout simplement &laquo;&nbsp;php-ews&nbsp;&raquo; (je sais, trop original&#8230;)</p>
<h2>Let&rsquo;s go !</h2>
<h3>Des problèmes, y en aura !</h3>
<p>Ça c&rsquo;est sûr, ça ne marchera pas du 1er coup&#8230; Donc on va installer quelques bouts de codes pour nous aider !</p>
<h4>Affichage des erreur de cUrl</h4>
<p>Dans le fichier NTLMSoapClient.php, vers la ligne 71, à la fin de la définition des options de cUrl, ajoutez</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_FAILONERROR<span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Erreur Curl : '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">curl_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>(commentez le $response = curl_exec($ch) déjà présent bien sûr)</p>
<p>Ce qui nous permettra de voir les erreurs HTTP du style Error 404 (même si ça sera probablement des error 401 qui faudra gérer) Évidemment, il faudra virer ça lorsque tout fonctionnera..</p>
<h3>NTLM &#8230; ou pas</h3>
<p>Suivant la configuration de votre serveur (que je n&rsquo;expliquerais pas, j&rsquo;y connais rien&#8230;) l&rsquo;authentification peut se faire par NTLM, ou pas. Créez un fichier index.php et mettez y ceci</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'php-ews/EWS_Exception.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'php-ews/ExchangeWebServices.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'php-ews/NTLMSoapClient.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'php-ews/NTLMStream.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'php-ews/NTLMStream/Exchange.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'php-ews/NTLMSoapClient/Exchange.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// A modifier évidemment</span>
<span style="color: #000088;">$server</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'serveur-exchange.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'guillaume'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'passpass'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ExchangeWebServices<span style="color: #009900;">&#40;</span><span style="color: #000088;">$server</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateItem</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Exécutez, et si vous obtenez</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">Erreur Curl : The requested URL returned error: <span style="color: #000000;">401</span></pre></td></tr></table></div>

<p>C&rsquo;est que le serveur n&rsquo;utilise pas NTLM, il faudra donc commenter la ligne</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HTTPAUTH<span style="color: #339933;">,</span> CURLAUTH_NTLM<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>dans NTLMSoapClient.php</p>
<p>Réessayez, et vous devez obtenir une erreur 500 (normal, on a envoyé une requête nulle), mais au moins, l&rsquo;authentification passe.</p>
<h3>On envoi notre 1er mail</h3>
<p>Nous allons donc envoyer un 1er mail. Pour cela nous utilisons la doc sur MSDN.</p>
<p>On peut voir dessus la forme de l&rsquo;XML qui doit être envoyé. Soap se chargeant de transformer nos objets en XML, il nous faut donc fabriquer un objet constitué des informations attendues par le serveur. Avant de commencer, je vais montrer ce qu&rsquo;on veut, c&rsquo;est-à-dire le XML avec mes infos, et l&rsquo;objet qu&rsquo;on doit créer pour l&rsquo;obtenir. La comparaison permet de mieux comprendre comment fabriquer son objet.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SOAP-ENV:Envelope</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:SOAP-ENV</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:ns1</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/exchange/services/2006/types&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:ns2</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/exchange/services/2006/messages&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SOAP-ENV:Body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>	
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ns2:CreateItem</span> <span style="color: #000066;">MessageDisposition</span>=<span style="color: #ff0000;">&quot;SendAndSaveCopy&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> 
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ns2:SavedItemFolderId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ns1:DistinguishedFolderId</span> <span style="color: #000066;">Id</span>=<span style="color: #ff0000;">&quot;sentitems&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ns2:SavedItemFolderId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ns2:Items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ns1:Message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ns1:ItemClass<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>IPM.Note<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ns1:ItemClass<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ns1:Subject<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Test envoi de mail<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ns1:Subject<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ns1:Body</span> <span style="color: #000066;">BodyType</span>=<span style="color: #ff0000;">&quot;HTML&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
Voici le 1er mail envoyé par du code pur et dur ! Ca bazoote ! C'est envoyé par le serveur exchange, et bien visible dans les mails envoyés.
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ns1:Body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ns1:ToRecipients<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ns1:Mailbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ns1:EmailAddress<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>destinaire@server.fr<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ns1:EmailAddress<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ns1:Mailbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ns1:ToRecipients<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ns1:Message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ns2:Items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ns2:CreateItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SOAP-ENV:Body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SOAP-ENV:Envelope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Et l&rsquo;objet Soap correspondant</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">stdClass Object <span style="color: #009900;">&#40;</span>
	<span style="color: #009900;">&#91;</span>MessageDisposition<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> SendAndSaveCopy    
	<span style="color: #009900;">&#91;</span>SavedItemFolderId<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> stdClass Object <span style="color: #009900;">&#40;</span>
		<span style="color: #009900;">&#91;</span>DistinguishedFolderId<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> stdClass Object <span style="color: #009900;">&#40;</span>
			<span style="color: #009900;">&#91;</span>Id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> sentitems
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#91;</span>Items<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> stdClass Object <span style="color: #009900;">&#40;</span>
		<span style="color: #009900;">&#91;</span>Message<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span>
			<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> stdClass Object <span style="color: #009900;">&#40;</span>
				<span style="color: #009900;">&#91;</span>ItemClass<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> IPM<span style="color: #339933;">.</span>Note
				<span style="color: #009900;">&#91;</span>Subject<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Test subject sans stream
				<span style="color: #009900;">&#91;</span>Body<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> stdClass Object <span style="color: #009900;">&#40;</span> 
					<span style="color: #009900;">&#91;</span>BodyType<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> HTML
					<span style="color: #009900;">&#91;</span>_<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Voici le 1er <span style="color: #990000;">mail</span> envoyé par du code pur et dur <span style="color: #339933;">!</span> Ca bazoote <span style="color: #339933;">!</span> C est envoyé par le serveur exchange<span style="color: #339933;">,</span> et bien visible dans les <span style="color: #339933;">&lt;</span>em<span style="color: #339933;">&gt;</span>mails envoyés<span style="color: #339933;">&lt;/</span>em<span style="color: #339933;">&gt;</span>
				<span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#91;</span>ToRecipients<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> stdClass Object <span style="color: #009900;">&#40;</span>
					<span style="color: #009900;">&#91;</span>Mailbox<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span>
						<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> stdClass Object <span style="color: #009900;">&#40;</span>
							<span style="color: #009900;">&#91;</span>EmailAddress<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> destinaire<span style="color: #339933;">@</span>server<span style="color: #339933;">.</span>fr
						<span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Let&rsquo;s go !<br />
Pour cela, je vais faire une fonction à part, auquel on paasera d&rsquo;une part le client SOAP, et d&rsquo;autre part les infos liées au mail.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> sendMail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000088;">$createItem</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MessageDisposition</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SendAndSaveCopy'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$createItem</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SavedItemFolderId</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DistinguishedFolderId</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Id</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'sentitems'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ItemClass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'IPM.Note'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Subject'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$message</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>SubJect <span style="color: #339933;">=</span> <span style="color: #0000ff;">'No subject'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Subject</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Subject'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'BodyType'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">BodyType</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Text'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">BodyType</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'BodyType'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Body'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span><span style="color: #339933;">-&gt;</span>_ <span style="color: #339933;">=</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Recipients'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$mail</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ToRecipients</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Mailbox</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EmailAddress</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mail</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$createItem</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Items</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Message</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span><span style="color: #339933;">;</span>
&nbsp;
    try <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Send the request to create and send the e-mail item, and get the response.</span>
        <span style="color: #000088;">$createItemResponse</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateItem</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$createItem</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Determine whether the request was a success.</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$createItemResponse</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ResponseMessages</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateItemResponseMessage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ResponseClass</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'Error'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #000088;">$createItemResponse</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ResponseMessages</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateItemResponseMessage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MessageText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Item was created&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span> catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Il ne nous reste plus qu&rsquo;à reprendre notre code du début, mais au lieu d&rsquo;envoyer un Item null, on appelle notre fonction</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'php-ews/EWS_Exception.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'php-ews/ExchangeWebServices.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'php-ews/NTLMSoapClient.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'php-ews/NTLMStream.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'php-ews/NTLMStream/Exchange.php'</span><span style="color: #339933;">;</span><span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'php-ews/NTLMSoapClient/Exchange.php'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// A modifier évidemment</span>
<span style="color: #000088;">$server</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'serveur-exchange.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'guillaume'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'passpass'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ExchangeWebServices<span style="color: #009900;">&#40;</span><span style="color: #000088;">$server</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
sendMail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'Subject'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Test subject sans stream'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'BodyType'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'HTML'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'Body'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Voici le 1er mail envoyé par du code pur et dur ! Ca bazoote ! C\'est envoyé par le serveur exchange, et bien visible dans les &lt;em&gt;mails envoyés&lt;/em&gt;'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'Recipients'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'destinaire@server.fr'</span>
    <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Et voila, logiquement vous devriez avoir un victorieux &laquo;&nbsp;Item was created&nbsp;&raquo; \o/<br />
Si ce n&rsquo;est pas le cas, vous pouvez afficher votre objet ($createItem dans la fonction sendMail), ainsi que l&rsquo;XML de sortie ($resquest dans __doRequest du fichier NTLMSoapClient), et enfin pour voir mieux l&rsquo;erreur, le résultat $createItemResponse dans la fonction sendMail</p>
<p>Bon courage, et vive M$ (.. ou pas)</p>
]]></content>
			<link rel="replies" type="text/html" href="http://www.wamania.com/php5/php-et-exchange-2007-2010.html#comments" thr:count="13"/>
		<link rel="replies" type="application/atom+xml" href="http://www.wamania.com/php5/php-et-exchange-2007-2010.html/feed/atom" thr:count="13"/>
		<thr:total>13</thr:total>
		</entry>
		<entry>
		<author>
			<name>admin</name>
					</author>
		<title type="html"><![CDATA[Aedituus 2.0.6]]></title>
		<link rel="alternate" type="text/html" href="http://www.wamania.com/aedituus/aedituus-2-0-6.html" />
		<id>http://www.wamania.com/?p=6</id>
		<updated>2010-06-25T15:12:00Z</updated>
		<published>2010-06-25T15:12:00Z</published>
		<category scheme="http://www.wamania.com" term="Aedituus" />		<summary type="html"><![CDATA[Bonjour le peuple, PHP avançant, je devais rattraper un peu le retard. Cependant, les changement avec PHP 5.3 ne rendent pas la tâche facile. Je publie donc ici une 1ère version de Aedituus 2.0.6. Je me suis mis sous PHP 5.3.2, en mode E_ALL &#124; E_STRICT pour essayer de ne RIEN laisser passer, mais il ... <span class="more"><a class="more-link" href="http://www.wamania.com/aedituus/aedituus-2-0-6.html">[Read more...]</a></span>]]></summary>
		<content type="html" xml:base="http://www.wamania.com/aedituus/aedituus-2-0-6.html"><![CDATA[<p>Bonjour le peuple,</p>
<p>PHP avançant, je devais rattraper un peu le retard. Cependant, les changement avec PHP 5.3 ne rendent pas la tâche facile.</p>
<p>Je publie donc ici une 1ère version de Aedituus 2.0.6.</p>
<p>Je me suis mis sous PHP 5.3.2, en mode E_ALL | E_STRICT pour essayer de ne RIEN laisser passer, mais il reste obligatoirement des choses que je n&rsquo;ai pas dû voir (et j&rsquo;avoue avoir fais ça un peu vite).</p>
<p>Merci donc de me remonter toute erreur, je corrigerais au fur-et-à-mesure, de façon à obtenir une version fiable pour PHP 5.3</p>
<p><a href="/public/aedituus/aedituus_2.0.6.1.zip">Aedituus 2.0.6.1</a></p>
]]></content>
			<link rel="replies" type="text/html" href="http://www.wamania.com/aedituus/aedituus-2-0-6.html#comments" thr:count="0"/>
		<link rel="replies" type="application/atom+xml" href="http://www.wamania.com/aedituus/aedituus-2-0-6.html/feed/atom" thr:count="0"/>
		<thr:total>0</thr:total>
		</entry>
		<entry>
		<author>
			<name>admin</name>
					</author>
		<title type="html"><![CDATA[Lucid Lynx et XEN]]></title>
		<link rel="alternate" type="text/html" href="http://www.wamania.com/ubuntu/lucid-lynx-et-xen.html" />
		<id>http://www.wamania.com/?p=26</id>
		<updated>2010-06-16T11:01:00Z</updated>
		<published>2010-06-16T11:01:00Z</published>
		<category scheme="http://www.wamania.com" term="Ubuntu" />		<summary type="html"><![CDATA[J&#8217;aime ma Ubuntu, mais là franchement, je lui en veux. Si vous avez un système complet fonctionnant sous XEN et Hardy, ne faites pas la mise à jour ! En effet, Xen n&#8217;est plus soutenu officiellement. Je trouve ceci déplorable, sachant que pour Hardy, on avait un noyau officiel. Sur un serveur, je n&#8217;installe que ... <span class="more"><a class="more-link" href="http://www.wamania.com/ubuntu/lucid-lynx-et-xen.html">[Read more...]</a></span>]]></summary>
		<content type="html" xml:base="http://www.wamania.com/ubuntu/lucid-lynx-et-xen.html"><![CDATA[<p>J&rsquo;aime ma Ubuntu, mais là franchement, je lui en veux.</p>
<p>Si vous avez un système complet fonctionnant sous XEN et Hardy, <strong>ne faites pas la mise à jour !</strong> En effet, Xen n&rsquo;est plus soutenu officiellement. Je trouve ceci déplorable, sachant que pour Hardy, on avait un noyau officiel.</p>
<p>Sur un serveur, je n&rsquo;installe que des LTS, donc au final, en 2 versions on est passé de &laquo;&nbsp;maintenu officiellement&nbsp;&raquo; à &laquo;&nbsp;plus maintenu du tout&nbsp;&raquo;.</p>
<p>Il n&rsquo;y a pas de noyau XEN dans les dépôts&#8230; donc si vous faites une mise à jour, vous resterez sur le noyau Xen Hardy. Malheureusement, Lucid Lynx est incompatible avec ce noyau, donc au 1er reboot, ça sera le clash.</p>
<p>J&rsquo;ai vu à travers le web qqs gars qui avaient compilé des noyaux. C&rsquo;est utile pour sauver les meubles, mais bon&#8230; Il me semblent y en avoir aussi un dans les backports.</p>
<p>Conclusion, je commence de plus en plus à me dire que la Ubuntu n&rsquo;est pas faites pour être mise sur un serveur. Les cycles de développement trop rapides sont un obstacle à une vision sur du long terme, et donc, à mon Uptime&nbsp;!</p>
]]></content>
			<link rel="replies" type="text/html" href="http://www.wamania.com/ubuntu/lucid-lynx-et-xen.html#comments" thr:count="0"/>
		<link rel="replies" type="application/atom+xml" href="http://www.wamania.com/ubuntu/lucid-lynx-et-xen.html/feed/atom" thr:count="0"/>
		<thr:total>0</thr:total>
		</entry>
		<entry>
		<author>
			<name>admin</name>
					</author>
		<title type="html"><![CDATA[Lithium &#8211; L’ORM PHP5 vraiment vraiment léger]]></title>
		<link rel="alternate" type="text/html" href="http://www.wamania.com/php5/lithium-orm-php5-vraiment-vraiment-leger.html" />
		<id>http://www.wamania.com/?p=15</id>
		<updated>2011-02-23T09:59:38Z</updated>
		<published>2010-01-05T14:58:00Z</published>
		<category scheme="http://www.wamania.com" term="PHP5" />		<summary type="html"><![CDATA[Aujourd&#8217;hui j&#8217;ai décidé de partager avec vous mon dernier bébé. Un ORM du nom de Lithium que je développe et que j&#8217;utilise depuis 1ans environ. Alors, je vois déjà les questions, les têtes bizarres, etc.. OUI, encore un. Mais le mien il est mieux (comme ceux des autres quoi ^^) L&#8217;idée derrière Lithium je l&#8217;ai ... <span class="more"><a class="more-link" href="http://www.wamania.com/php5/lithium-orm-php5-vraiment-vraiment-leger.html">[Read more...]</a></span>]]></summary>
		<content type="html" xml:base="http://www.wamania.com/php5/lithium-orm-php5-vraiment-vraiment-leger.html"><![CDATA[<p><img title="elephpant_powered_php.gif, aoû 2008" style="margin: 0 1em 1em 0; float: left;" alt="" src="/public/php5/elephpant_powered_php.gif" />Aujourd&rsquo;hui j&rsquo;ai décidé de partager avec vous mon dernier bébé. Un <a href="http://fr.wikipedia.org/wiki/Mapping_objet-relationnel" mce_href="http://fr.wikipedia.org/wiki/Mapping_objet-relationnel" target="_blank">ORM</a> du nom de <a href="http://fr.wikipedia.org/wiki/Lithium" mce_href="http://fr.wikipedia.org/wiki/Lithium" target="_blank">Lithium</a> que je développe et que j&rsquo;utilise depuis 1ans environ.</p>
<p>Alors, je vois déjà les questions, les têtes bizarres, etc..<br />
 OUI, encore un. Mais le mien il est mieux (comme ceux des autres quoi ^^)</p>
<p>L&rsquo;idée derrière Lithium je l&rsquo;ai eu en cherchant moi-même un ORM &laquo;&nbsp;réputé&nbsp;&raquo; sur lequel appuyer mes développements. J&rsquo;ai eu le choix entre des usines qui ne s&rsquo;en cachent pas, et des &laquo;&nbsp;très très très légers ORM&nbsp;&raquo; de 35 fichiers PHP de 1000 lignes chacun. Ce n&rsquo;était pas ma définition de léger !!</p>
<p>De plus, j&rsquo;étais assez intrigué sur le fonctionnement de ces outils pour le moins complexe. J&rsquo;ai donc disséqué, trituré, bidouillé, puis j&rsquo;ai commencé.</p>
<p>Aujourd&rsquo;hui, je suis arrivé là ou je voulais ! 3 fichiers principaux + 4 fichiers pour les associations. Aucun des fichiers ne dépasse 300 lignes sans commentaires, les 4 fichiers d&rsquo;associations faisant même environ 100 lignes sans les commentaires.<br />
 Mon but était de trier les fonctionnalités en fonction de du rapport bénéfice/complexité. C&rsquo;est d&rsquo;ailleurs pour cette raison que Lithium n&rsquo;évoluera plus en terme de fonctionnalité, mais uniquement en terme de stabilité et légéreté.</p>
<p><img title="180px-Limetal.JPG, jan 2010" style="margin: 0 auto; display: block;" alt="" src="/public/php5/180px-Limetal.JPG" /></p>
<p>Pourquoi l&rsquo;appeler Lithium ?<br />
 Selon wikipedia :<em> C&rsquo;est l&rsquo;élément solide le plus léger.</em></p>
<p><strong>Doc et téléchargement ici : <a href="http://lithium.wamania.com/" mce_href="http://lithium.wamania.com" target="_blank">http://lithium.wamania.com</a></strong></p>
]]></content>
			<link rel="replies" type="text/html" href="http://www.wamania.com/php5/lithium-orm-php5-vraiment-vraiment-leger.html#comments" thr:count="1"/>
		<link rel="replies" type="application/atom+xml" href="http://www.wamania.com/php5/lithium-orm-php5-vraiment-vraiment-leger.html/feed/atom" thr:count="1"/>
		<thr:total>1</thr:total>
		</entry>
	</feed>
