Blog du grouik - Mot-clé - Tutoriel-mémoLe blog du grouik. Memos d'un Admin sys linux windows, logiciels libres, imprimante 3D2024-01-16T12:12:27+00:00Gniearkurn:md5:87c2396a7331cd5cd18f8751d216ec7bDotclearMémo - Installation de DreamFactoryurn:md5:ecb1fcf597b04b68c27a3cc7a6c7c91e2016-09-17T22:29:00+02:002017-02-24T11:57:12+01:00gniearkServeurs http web et autresApachedreamfactoryPHPserveurTutoriel-mémo <p>::TOC::</p>
<p>L'installation de Dreamfactory par une image Bitnami est très bien pour tester, mais elle me fait craindre quelques problèmes de stabilité. C'est un peu caca, bitnami en met partout, dur de s'y retrouver lorsque des optimisations sont à faire coté apache php ou mysql etc... et les scripts Bitnami de redémarrages de services oublient de faire des logrotates et font d'autres erreurs.</p>
<p>Bref avant de passer Dreamfactory en production, installons le proprement à la main. voici le mémo.</p>
<p>Le wiki de Dreamfactory explique bien comment faire. <a href="http://wiki.dreamfactory.com/DreamFactory/Installation">http://wiki.dreamfactory.com/DreamFactory/Installation</a> je m'attacherai ici à détailler un eu plus, dont le paramétrage serveur.</p>
<h2>Prérequis</h2>
<p>Débian 8 Fraichement installée.</p>
<p>Je choisis un trio PHP7 + Apache + mysql</p>
<h2>Apache, php et ses modules, et autres prérequis</h2>
<h3>ajouter le dépôt dotdeb</h3>
<p>PHP 7 n'est pas dans les dépôts de la version stable de debian. C'est la logique de leur cycle de développement, ils ne sortent pas de version majeures d un logiciel. On va donc utiliser le dépôt dotdeb.</p>
<pre class="brush: bash">echo "deb http://packages.dotdeb.org jessie all" > /etc/apt/sources.list.d/dotdeb.list
wget -O- https://www.dotdeb.org/dotdeb.gpg | apt-key add -
apt-get update</pre>
<p>''<a href="https://angristan.fr/installer-php-7-debian-8-jessie-depot-dotdeb/">Source'</a>'</p>
<h3>Installer tous paquets nécessaires directement et indirectement à dreamfactory.</h3>
<pre class="brush: bash">apt-get install git curl apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert php7.0 php7.0-mysql php7.0-curl php7.0-json php7.0-gd php7.0-mcrypt php7.0-msgpack php7.0-memcached php7.0-intl php7.0-sqlite3 php7.0-gmp php7.0-geoip php7.0-mbstring php7.0-xml php7.0-zip php7.0 libapache2-mod-php7.0 php7.0-mysql php7.0-curl php7.0-json php7.0-gd php7.0-mcrypt php7.0-msgpack php7.0-memcached php7.0-intl php7.0-sqlite3 php7.0-gmp php7.0-geoip php7.0-mbstring php7.0-xml php7.0-zip php7.0-dev php-pear mysql-server mysql-client libcurl4-openssl-dev pkg-config
pecl channel-update pecl.php.net
#la lib mongodb est un peu chiante à installer
#(Plusieurs paquets ci dessus en sont des prérequis, et il faut enregistrer le module)
pecl install mongodb-alpha
echo "extension=mongodb.so">/etc/php/7.0/cli/conf.d/20-mongo.ini
echo "extension=mongodb.so">/etc/php/7.0/mods-available/mongo.ini</pre>
<p>Mettez un mot de passe root à mysql quand il le demande.</p>
<h3>php.ini</h3>
<p>vi /etc/php/7.0/apache2/php.ini
Si votre API dreamfactory aura aussi pour vocation du transfert de fichiers, relevez les valeurs par défaut en fonction de vos besoins.</p>
<pre>
post_max_size = 40M
upload_max_filesize = 40M
max_file_uploads = 20
</pre>
<h3>Composer</h3>
<pre class="brush: bash">curl -s https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer</pre>
<h3>Créer une base mysql</h3>
<pre class="brush: bash">mysql -u root -p</pre>
<pre class="brush: sql">CREATE DATABASE dreamfactory;
GRANT ALL ON dreamfactory.* TO 'dreamfactory'@'localhost' IDENTIFIED BY '*hjiQM,NER!';
quit</pre>
<h2>Installer dreamfactory</h2>
<pre class="brush: bash">cd /var/www
git clone https://github.com/dreamfactorysoftware/dreamfactory.git
cd dreamfactory/
composer install --no-dev
php artisan dreamfactory:setup</pre>
<p>Voici mon retour écran pour la dernière commande:</p>
<pre>
root@dreamfactory:/var/www/dreamfactory# php artisan dreamfactory:setup
**********************************************************************************************************************
* Configuring DreamFactory...
**********************************************************************************************************************
Created .env file with default configuration.
Application key [base64:9AZJkz07XobEu5IQ72kRCVjIiJKUg0HrhY/WD1McPUw=] set successfully.
Created phpunit.xml with default configuration.
Which database would you like to use for system tables? [sqlite]:
[0] sqlite
[1] mysql
[2] pgsql
[3] sqlsrv
> 1
Enter your mysql Host:
> localhost
Enter your database name:
> dreamfactory
Enter your database username:
> dreamfactory
Enter your database password:
>
Re-enter your database password:
>
Enter your Database Port [3306]:
>
CACHE DRIVER is not supported. Using default driver file.
Configuration complete!
*************************************************** WARNING! *********************************************************
*
* Please take a moment to review the .env file. You can make any changes as necessary there.
*
* Please run "php artisan dreamfactory:setup" again to complete the setup process.
*
**********************************************************************************************************************
</pre>
<p>Un petit tour dans le fichier .env nous indique entre autre qu'il veut bien de redis comme systeme de cache. Let's do it:</p>
<pre class="brush: bash">apt-get install redis-server</pre>
<p>Maintenant on édite le fichier .env, et on gère le cache comme ça:</p>
<pre>
##------------------------------------------------------------------------------
## Cache and Session Settings
##------------------------------------------------------------------------------
CACHE_DRIVER=redis
SESSION_DRIVER=array
MAIL_DRIVER=mail
##------------------------------------------------------------------------------
## Redis cache settings. Uncomment if the CACHE_DRIVER is changed to redis and
## the default values are not appropriate
##------------------------------------------------------------------------------
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
#REDIS_DATABASE=
#REDIS_PASSWORD=
</pre>
<p>On relance la commande:</p>
<pre class="brush: bash">php artisan dreamfactory:setup</pre>
<p>Voici mon retour écran</p>
<pre>
root@dreamfactory:/var/www/dreamfactory# php artisan dreamfactory:setup
**********************************************************************************************************************
* Welcome to DreamFactory setup wizard.
**********************************************************************************************************************
Running Migrations...
Migration table created successfully.
Migration driver used: mysql
Migrated: 2015_01_27_190908_create_system_tables
Migrated: 2015_02_03_161456_create_sqldb_tables
Migrated: 2015_02_03_161457_create_couchdb_tables
Migrated: 2015_02_03_161457_create_mongodb_tables
Migrated: 2015_03_10_135522_create_aws_tables
Migrated: 2015_03_10_200756_create_azure_tables
Migrated: 2015_03_11_143913_create_rackspace_tables
Migrated: 2015_03_20_205504_create_remote_web_service_tables
Migrated: 2015_05_02_134911_update_user_table_for_oauth_support
Migrated: 2015_05_21_190727_create_user_config_table
Migrated: 2015_07_10_161839_create_user_custom_table
Migrated: 2015_08_25_202632_db_alias
Migrated: 2015_11_06_155036_db_function
Migrated: 2015_11_10_225902_db_foreign_key
Migrated: 2016_01_21_213101_add_curl_options
Migrated: 2016_03_15_235903_add_username_field_to_user_table
Migrated: 2016_05_11_134231_remove_service_and_script_type
Migrated: 2016_05_17_020359_db_config_add
Migrated: 2016_06_20_195319_event_affects_content
Migrated: 2016_07_11_155716_create_cassandra_config_table
Migrated: 2016_07_25_214132_adding_a_custom_field_for_oauth_config
Migrated: 2016_08_02_153513_create_redis_config_table
Migrated: 2016_08_02_193216_create_local_cache_config
Migrated: 2016_08_04_140705_create_memcached_config_table
Migrated: 2016_08_09_202900_create_jobs_table
Migrated: 2016_08_10_145124_create_failed_jobs_table
Migrated: 2016_08_10_191349_queueable_scripts
Migration completed successfully.
**********************************************************************************************************************
**********************************************************************************************************************
Running Seeder...
Service resources created: system, api_docs, files, db
Seeded: DreamFactory\Core\Models\Seeds\ServiceSeeder
App resources created: admin, api_docs, file_manager
Seeded: DreamFactory\Core\Models\Seeds\AppSeeder
Email Template resources created: User Invite Default, User Registration Default, Password Reset Default
Seeded: DreamFactory\Core\User\Models\Seeds\EmailTemplateSeeder
Service resources created: email
Seeded: DreamFactory\Core\User\Models\Seeds\EmailServiceSeeder
Service resources created: user
Seeded: DreamFactory\Core\User\Models\Seeds\UserServiceSeeder
Seeded: DreamFactory\Core\User\Models\Seeds\DatabaseSeeder
All tables were seeded successfully.
**********************************************************************************************************************
**********************************************************************************************************************
Creating the first admin user...
Enter your first name:
> Gnieark
Enter your last name:
> Grouik
Enter display name:
> Gnieark Grouik
Enter your email address?:
> gnieark@domaoine.com
Choose a password:
>
Re-enter password:
>
Successfully created first admin user.
**********************************************************************************************************************
*************************************************** WARNING! *********************************************************
* Please make sure following directories and all directories under them are readable and writable by your web server
* -> storage/
* -> bootstrap/cache/
* Example:
* > sudo chown -R {www user}:{your user group} storage/ bootstrap/cache/
* > sudo chmod -R 2775 storage/ bootstrap/cache/
**********************************************************************************************************************
*********************************************** Setup Successful! ****************************************************
* Setup is complete! Your instance is ready. Please launch your instance using a browser.
* You can run "php artisan serve" to try out your instance without setting up a web server.
**********************************************************************************************************************
</pre>
<p>On applique les droits:</p>
<pre class="brush: bash">chown -R www-data:www-data storage/ bootstrap/cache/
chmod -R 2775 storage/ bootstrap/cache/</pre>
<h2>Configuration d'apache</h2>
<pre class="brush: bash">a2enmod rewrite</pre>
<p>Editer le fichier /etc/apache2/sites-available/000-default.conf
Pour y mettre:</p>
<pre>
<VirtualHost *:80>
DocumentRoot /var/www/dreamfactory/public
<Directory /var/www/dreamfactory/public>
AddOutputFilterByType DEFLATE text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride All
AllowOverride None
Require all granted
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]
<LimitExcept GET HEAD PUT DELETE PATCH POST>
Allow from all
</LimitExcept>
</Directory>
</VirtualHost>
</pre>
<pre class="brush: bash">service apache2 restart</pre>
<p>Se rendre sur le serveur via un navigateur:
<a href="https://blog-du-grouik.tinad.fr/public/Capture_du_2016-09-18_23-50-53.png" title="Capture_du_2016-09-18_23-50-53.png"><img src="https://blog-du-grouik.tinad.fr/public/.Capture_du_2016-09-18_23-50-53_m.png" alt="Capture_du_2016-09-18_23-50-53.png" style="display:table; margin:0 auto;" title="Capture_du_2016-09-18_23-50-53.png, sept. 2016" /></a></p>
<p>Voila,
Il ne reste plus qu'à configurer apache pour le https, mais ça, je vous laisse faire.</p>proftp sur comptes mysqlurn:md5:b91dfbcc2538e12d51966d31fcc39a9e2015-11-23T13:00:00+01:002017-03-18T22:57:08+01:00gniearkServeurs http web et autresftpLogiciel-libreserveurTutoriel-mémo <p>Ok, le ftp en 2015, c'est à éviter. Je suppose que vous ferez ça en local sur une DMZ uniquement. On va voir ici comment installer proftp, avec une gestion des comptes sur une base mysql.</p>
<h2>Roadmap du document:</h2>
<ul>
<li>06/10/2010: création</li>
<li>23/11/2015: Correction erreur mysql, fichier de conf de proftp, ajout d'un exemple de création d'un utilisateur.</li>
</ul>
<h2>Bases de données:</h2>
<p>La database se nome ftp, l'user 'proftpd'@'localhost' y a accès.
Dans le prompt mysql pour créer la base et l'user:</p>
<pre class="brush: sql">CREATE database ftp;
GRANT ALL ON ftp.* TO 'proftpd'@'localhost' IDENTIFIED BY 'mot-de-passe';
QUIT</pre>
<p>Puis pour créer les tables, télécharger le script sur ce blog.</p>
<pre class="brush: bash">cd ~
wget https://blog-du-grouik.tinad.fr/public/createtablesftp.sql
mysql -u root -p ftp < createtablesftp.sql</pre>
<h3>Installation</h3>
<pre class="brush: bash">apt-get install proftpd proftpd-mod-mysql</pre>
<p><img src="https://blog-du-grouik.tinad.fr/public/.proftpd-inetd-ou-Indep_m.jpg" alt="proftpd-inetd-ou-Indep.jpg" style="display:table; margin:0 auto;" title="proftpd-inetd-ou-Indep.jpg, oct. 2010" />
je choisis indépendant, (proftp tournera en permanence et pompera un peu plus de ressources. c'est pas bien vu mon utilisation, mais c'est plus stable et plus simple à configurer.)</p>
<pre class="brush: bash">addgroup proftpd</pre>
<h3>Activer le module mysql:</h3>
<p>Dans le fichier /etc/proftpd/modules.conf dé-commenter les lignes suivantes:</p>
<blockquote><p>LoadModule mod_sql.c<br />
LoadModule mod_sql_mysql.c</p></blockquote>
<h3>Paramétrage proftpd:</h3>
<p>Remplacez le fichier /etc/proftpd/proftpd.conf par celui ci dessous proposé ici:</p>
<pre class="brush: bash">cd /etc/proftpd
mv proftpd.conf proftpd.conf.old
wget https://blog-du-grouik.tinad.fr/public/proftpd.conf
vi proftpd.conf</pre>
<p>Remplacez ************** par le mot de passe mysql de proftpd dans la ligne <em>SQLConnectInfo ftp@localhost proftpd **********</em></p>
<p>Mais c'est pas bien, je le conçois, idéalement l'user ftp devrait être le propriétaire des dossiers publics (faisant partie du site) avec des droits en écriture et lecture. tandis que www-data devrait faire partie du groupe de l'user, ce dernier ayant accès en lecture uniquement (sauf dans les répertoires où le site internet a besoin d'écrire).</p>
<p>Une telle organisation pourrait limiter les conséquences de l'exploitation d'une faille dans un script php. mais à gérer site par site, c'est super lourd.</p>
<p>Redémarrer proftpd:</p>
<pre class="brush: bash">service proftpd restart</pre>
<h2>Créer des utilisateurs</h2>
<pre class="brush: bash">#Créer le repertoire
mkdir -p /home/ftp/user1
chown -R ftp:ftp /home/ftp/user1</pre>
<p>Créer l'user en dans la base de donnée. "120" correspond à l'uid unix du compte ftp.</p>
<pre class="brush: sql">USE ftp;
INSERT INTO ftpuser(userid,passwd,uid,gid,homedir,modified) VALUES
('user1',ENCRYPT('mot-de-passe'),'120','120','/home/ftp/user1',NOW());</pre>
<p>Vous pouvez ajouter des utilisateurs dans la base de données en utilisant phpmyadmin par exemple.</p>Fournir, puis demander à un utilisateur un certificat pour l'authentifier sur notre site internet.urn:md5:a0b24a179c3339372a15cdc97abe89c42015-03-13T21:06:00+01:002021-08-30T21:12:00+02:00gniearkSSL HTTPS chiffrement et certificatsApacheLogiciel-librepkcsserveurSSLTLSTutoriel-mémo <p><img src="https://blog-du-grouik.tinad.fr/public/.rsaPlp_m.png" alt="rsaPlp.png" style="display:table; margin:0 auto;" title="rsaPlp.png, mar. 2015" /></p>
<p>::TOC::</p>
<h2>Pourquoi faire ça?</h2>
<p>A moins de s'appeler le trésor public<sup>[<a href="https://blog-du-grouik.tinad.fr/post/2015/03/13/Authentifier-un-client-web-via-un-certificat-TLS#wiki-footnote-1" id="rev-wiki-footnote-1">1</a>]</sup>, cette sécurité peut paraître exagérée.</p>
<p>Ça va me servir dans quelques semaines à sécuriser une appli web du travail pour laquelle seuls une dizaine d'utilisateurs auront accès depuis l'extérieur (via un reverse proxy apache) .</p>
<h2>Présentation des techniques employées:</h2>
<p>La configuration se fait au niveau d'apache et du module SSL.
Ce n'est pas compliqué, Mais c'est chiant à expliquer de façon claire. J'en suis à la troisième re-rédaction de ce billet pour tenter d'éclaircir les explications.</p>
<p>Ce billet contient tout un mémo de création d'une chaine de certification avec openSSL et un peu de config Apache.</p>
<p>Sur le serveur (mon Raspberry pi), je vais créer trois sites virtuels (VHOST) dans la configuration d'apache:</p>
<ul>
<li>home.tinad.fr (en http)</li>
<li>home.tinad.fr (en https)</li>
<li>prive.tinad.fr (en https, avec obligation pour l'utilisateur de posséder un certificat personnel signé par l'autorité de certification qu'on va créer):</li>
</ul>
<h2>Créer son autorité de certification et des certificats pour les deux sites en https</h2>
<h3>l'autorité de certification</h3>
<p>Malheureusement, il n'est pas possible d'obtenir un certificat ayant le rôle "autorité de certification" reconnu par tous les navigateurs. On devra faire en sorte que les utilisateurs ajoutent notre certificat dans leur navigateur. Je ne détaillerai pas ici comment faire, mais il voici trois pistes:</p>
<ul>
<li>Créer une page web intermédiaire fournissant le certificat, et expliquant comment et pourquoi l'installer</li>
<li>Si les utilisateurs sont dans un réseau sur lequel on est l'administrateur réseau : Via une GPO.</li>
<li>Offrir une boite de kinder chocolat à l'administrateur réseau pour qu'il fasse une GPO.</li>
<li>L'installer manuellement sur tous les postes.</li>
</ul>
<h4>Configuration</h4>
<pre class="brush: bash">#On créé l'architecture de dossiers et fichiers nécessaires à une gestion des
#clés et certificats dans le repertoire /srv/ssl
mkdir /srv/ssl
cd /srv/ssl
mkdir certs crl newcerts private
echo 01 > serial
touch index.txt
echo 01 > crlnumber
cp /usr/lib/ssl/openssl.cnf .</pre>
<h4>Editer le fichier /srv/ssl/openssl.conf et modifiez les parametres suivants:</h4>
<p>Dans le bloc CA_default :</p>
<ul>
<li>dir=/srv/ssl</li>
</ul>
<p>Dans le bloc [req_distinguished_name] :
.</p>
<pre class="brush: bash">countryName_default = FR
stateOrProvinceName_default = France</pre>
<h4>Clé privée certificat et signature</h4>
<pre class="brush: bash">#Créer une clé privée
openssl genrsa -des3 -out private/cakey.pem 4096
#certif signé
openssl req -config openssl.cnf -new -x509 -nodes -sha1 -days 1825 -key private/cakey.pem -out cacert.pem</pre>
<p>Adaptez les réponses en fonction,s de votre site, mais ne mettez pas le FDQN dans le common name. Il s'agit du certificat autorité, pas celui de votre site web.
Voici mon retour écran:</p>
<pre class="brush: bash">root@raspberrypi:/srv/ssl# openssl req -config openssl.cnf -new -x509 -nodes -sha1 -days 1825 -key private/cakey.pem -out cacert.pem
Enter pass phrase for private/cakey.pem:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [FR]:
State or Province Name (full name) [France]:
Locality Name (eg, city) []:Rouen
Organization Name (eg, company) [Internet Widgits Pty Ltd]:tinad
Organizational Unit Name (eg, section) []:Gnieark
Common Name (e.g. server FQDN or YOUR name) []:tinad.fr
Email Address []:gnieark@free.fr</pre>
<h4>Publier le certificat de l'autorité de certification</h4>
<pre class="brush: bash">cp /srv/ssl/cacert.pem /var/www/cacert.crt</pre>
<p>(Lors de la copie, on change l'extension .pem en .crt, car .crt est un type mime connu dans la configuration standard d'apache)</p>
<h4>Enregistrez le certificat dans le magasin de confiance de votre ordinateur local</h4>
<p>Ouvrez tout simplement votre navigateur à l'URL http://VotreServeur/cacert.crt
et cochez toutes les cases:</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/firefoxCacertTinad.png" alt="firefoxCacertTinad.png" style="display:table; margin:0 auto;" title="firefoxCacertTinad.png, mai 2013" /></p>
<h3>Créer un certificat pour le serveur Web home.tinad.fr</h3>
<p>changez "home.tinad.fr" par le FDQN de votre serveur pour la suite des tests.</p>
<pre class="brush: bash">cd /srv/ssl
#Création de la clé privée pour home.tinad.fr
openssl genrsa -des3 -out home.tinad.fr.key.pem 4096
#demande de certificat:
openssl req -config openssl.cnf -new -key home.tinad.fr.key.pem -out home.tinad.fr.csr.pem</pre>
<p>Voici mon retour écran:</p>
<pre class="brush: bash">root@raspberrypi:/srv/ssl# openssl req -config openssl.cnf -new -key home.tinad.fr.key.pem -out home.tinad.fr.csr.pem
Enter pass phrase for home.tinad.fr.key.pem:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [FR]:
State or Province Name (full name) [France]:
Locality Name (eg, city) []:Rouen
Organization Name (eg, company) [Internet Widgits Pty Ltd]:tinad
Organizational Unit Name (eg, section) []:home
Common Name (e.g. server FQDN or YOUR name) []:home.tinad.fr
Email Address []:gnieark@free.fr
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:</pre>
<p>Signature de la demande:</p>
<pre class="brush: bash">openssl ca -config openssl.cnf -policy policy_anything -out home.tinad.fr.cert.pem -infiles home.tinad.fr.csr.pem</pre>
<p>La valeur la plus importante est le common name. Elle corrspond au FDQN pour les autres champs, essayez simplement d'etre logique avec l'autorité de certification
Voici mon retour écran:</p>
<pre class="brush: bash">root@raspberrypi:/srv/ssl# openssl ca -config openssl.cnf -policy policy_anything -out home.tinad.fr.cert.pem -infiles home.tinad.fr.csr.pem
Using configuration from openssl.cnf
Enter pass phrase for /srv/ssl/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: May 3 19:25:04 2013 GMT
Not After : May 3 19:25:04 2014 GMT
Subject:
countryName = FR
stateOrProvinceName = France
localityName = Rouen
organizationName = tinad
organizationalUnitName = home
commonName = home.tinad.fr
emailAddress = gnieark@free.fr
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
81:4B:C7:3E:9B:C6:EA:60:78:26:B3:8F:77:B4:43:07:07:DE:A8:02
X509v3 Authority Key Identifier:
keyid:BE:1D:5D:B9:F1:53:D6:BD:11:90:8E:5C:0F:D2:BC:99:22:BE:F1:48
Certificate is to be certified until May 3 19:25:04 2014 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated</pre>
<p>Voila, on a notre certificat signé: /srv/ssl/home.tinad.fr.cert.pem et sa clé privée: /srv/ssl/home.tinad.fr.key.pem (chiffrée par un mot de passe là)</p>
<p>On remarque au passage openssl a incrémenté la valeur dans le fichier /srv/ssl/serial .</p>
<p>Créer une clé non protégée par un mot de passe (ça servira à Apache)</p>
<pre class="brush: bash">cd /srv/ssl
openssl rsa -in home.tinad.fr.key.pem -out home.tinad.fr-EnClair.key.pem</pre>
<h3>Créer un certificat pour le serveur Web prive.tinad.fr</h3>
<p>Idem qu'au châpitre précedent, du coup je ne détaille pas:</p>
<pre class="brush: bash">cd /srv/ssl
#Création de la clé privée pour prive.tinad.fr
openssl genrsa -des3 -out prive.tinad.fr.key.pem 4096
#demande de certificat:
openssl req -config openssl.cnf -new -key prive.tinad.fr.key.pem -out prive.tinad.fr.csr.pem
#signature de la demande:
openssl ca -config openssl.cnf -policy policy_anything -out prive.tinad.fr.cert.pem -infiles prive.tinad.fr.csr.pem
#créer une clé non protégée:
openssl rsa -in prive.tinad.fr.key.pem -out prive.tinad.fr-EnClair.key.pem</pre>
<h2>Configuration du serveur web</h2>
<pre class="brush: bash">cd /var/www
#on va créer 5 dossier pour des vhosts:
mkdir home.tinad.fr
mkdir home.tinad.fr-https
mkdir prive.tinad.fr-https
#Il me semble que le VHOST par défault d'apache est le premier par ordre alphabétique;
#d'où le "0" au début du nom
mkdir 0-default
mkdir 0-default-https
#Supprimer les fichiers de vhosts créés à l’installation d'apache
cd /etc/apache2/sites-enabled
rm *</pre>
<h3>configuration des vhost</h3>
<p>Comme vous le verrez, je reste sur une configuration méga basique des VHOST, préférant les valeurs par défaut d’apache aux paramètres non ou mal compris.
De plus je n'utilise pas de script CGI, donc autant ne pas les activer.</p>
<h4>vi /etc/apache2/sites-available/home.tinad.fr</h4>
<pre class="brush: bash"><VirtualHost *:80>
ServerName home.tinad.fr
DocumentRoot /var/www/home.tinad.fr
</VirtualHost></pre>
<h4>vi /etc/apache2/sites-available/home.tinad.fr-https</h4>
<p>Ce VHOST est chiffré en HTTPS, cependant, aucune restriction d'accès n'est effectuée. Pour le test, j'ai mis le certificat de notre propre autorité de certification. Mais en production, autant mettre un vrai certificat (comptez maxi 30€/an). Pour cette maquette, j'y publie le certificat de l'autorité de certification, j'explique comment l'insérer, et je mets un formulaire qui permettra aux utilisateurs de demander leurs propres certificats. (dans le projet final ce sera l'administrateur qui aura accès au formulaire pour générer les certificats)</p>
<pre class="brush: bash"><VirtualHost *:443>
ServerName home.tinad.fr
DocumentRoot /var/www/home.tinad.fr-https
SSLEngine On
SSLCertificateFile /srv/ssl/home.tinad.fr.cert.pem
SSLCertificateKeyFile /srv/ssl/home.tinad.fr-EnClair.key.pem
SSLProtocol all -SSLv2
</Virtualhost></pre>
<h4>vi /etc/apache2/sites-available/prive.tinad.fr-https</h4>
<pre class="brush: bash"><VirtualHost *:443>
ServerName prive.tinad.fr
DocumentRoot /var/www/prive.tinad.fr-https
SSLEngine On
SSLCertificateFile /srv/ssl/prive.tinad.fr.cert.pem
SSLCertificateKeyFile /srv/ssl/prive.tinad.fr-EnClair.key.pem
SSLProtocol all -SSLv2
SSLCACertificateFile /srv/ssl/cacert.pem
SSLCARevocationFile /srv/ssl/crl.pem
SSLVerifyClient require
SSLVerifyDepth 1
SSLOptions +StdEnvVars
</Virtualhost></pre>
<p>Ce VHOST étant le plus intéressant, expliquons les directives</p>
<ul>
<li>SSLEngine On : active le SSL</li>
<li>SSLCertificateFile le fichier contenant le certificat TLS pour prive.tinad.fr</li>
<li>SSLCertificateKeyFile le fichier contenant la clé qui servira à chiffrer les connexions (à garder bien cachée ;) )</li>
<li>SSLProtocol all -SSLv2 On accepte tous les protocoles ssl supportés sauf le SSLV2 qui présente une faiblesse)</li>
<li>SSLCACertificateFile Le fichier certificat de l'autorité qui signe les certificats clients (apache vérifie les signatures)</li>
<li>SSLCARevocationFile Le fichier qui contient la liste des certificats révoqués (nécessaire si on veut gérer les utilisateurs)</li>
<li>SSLVerifyClient require Seuls les clients ayant un certificat valide sont admis</li>
<li>SSLVerifyDepth 1 On limite à une autorité de certification intermédiaire</li>
<li>SSLOptions +StdEnvVars Cette directive permet d'ajouter les informations concernant le certificat client aux variables d'environnement. On pourra ainsi adapter le code PHP en fonction du certificat de l'utilisateur.</li>
</ul>
<h4>Activation des vhost:</h4>
<pre class="brush: bash">a2ensite home.tinad.fr
a2ensite home.tinad.fr-https
a2ensite prive.tinad.fr-https
/etc/init.d/apache2 reload</pre>
<h3>Créer un couple certificat-clé client (fichier PKCS#12):</h3>
<pre class="brush: bash">cd /srv/ssl
mkdir home.tinad.fr-Clefs-clients
cd home.tinad.fr-Clefs-clients</pre>
<p>creer clé</p>
<pre class="brush: bash">openssl genrsa -des3 -out gnieark.home.tinad.fr.key.pem</pre>
<p>Créer le certificat:</p>
<pre class="brush: bash">openssl req -config ../openssl.cnf -new -key gnieark.home.tinad.fr.key.pem -out gnieark.home.tinad.fr.csr.pem</pre>
<p>Retour écran de la dernière commande:</p>
<pre class="brush: bash">Enter pass phrase for gnieark.home.tinad.fr.key.pem:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [FR]:
State or Province Name (full name) [France]:
Locality Name (eg, city) []:Rouen
Organization Name (eg, company) [Internet Widgits Pty Ltd]:tinad
Organizational Unit Name (eg, section) []:home
Common Name (e.g. server FQDN or YOUR name) []:gnieark
Email Address []:gnieark@free.fr
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:</pre>
<p>Signer le certificat:</p>
<pre class="brush: bash">openssl ca -config ../openssl.cnf -policy policy_anything -out gnieark.home.tinad.fr.cert.pem -infiles gnieark.home.tinad.fr.csr.pem</pre>
<p>Retour écran de la commande:</p>
<pre class="brush: bash">root@raspberrypi:/srv/ssl/home.tinad.fr-Clefs-clients# openssl ca -config ../openssl.cnf -policy policy_anything -out gnieark.home.tinad.fr.cert.pem -infiles gnieark.home.tinad.fr.csr.pem
Using configuration from ../openssl.cnf
Enter pass phrase for /srv/ssl/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 2 (0x2)
Validity
Not Before: May 12 17:18:18 2013 GMT
Not After : May 12 17:18:18 2014 GMT
Subject:
countryName = FR
stateOrProvinceName = France
localityName = Rouen
organizationName = tinad
organizationalUnitName = home
commonName = gnieark
emailAddress = gnieark@free.fr
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
47:E4:92:85:3A:43:6A:BC:43:C7:5B:41:F4:67:66:E2:36:CA:D7:69
X509v3 Authority Key Identifier:
keyid:BE:1D:5D:B9:F1:53:D6:BD:11:90:8E:5C:0F:D2:BC:99:22:BE:F1:48
Certificate is to be certified until May 12 17:18:18 2014 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated</pre>
<p>Concatener et convertir au forlat PKCS#12 (.p12)</p>
<pre class="brush: bash">openssl pkcs12 -export -inkey gnieark.home.tinad.fr.key.pem -in gnieark.home.tinad.fr.cert.pem -out gnieark.home.tinad.fr.cert.p12 -name "Gnieark"</pre>
<p>Ça y est, j'ai une clé à) fournir à l'utilisateur Gnieark, il pourra l'intégrer à Firefox ou Internet Explorer (lol) et ainsi accéder au site que j'ai protégé précédent.</p>
<h2>Révoquer un certificat:</h2>
<p>En imaginant que je révoque un Zigazou</p>
<pre class="brush: bash">cd /srv/ssl
openssl ca -config openssl.cnf -revoke prive.tinad.fr/zigazou.prive.tinad.fr.cert.pem
#générer la liste de révocation:
openssl ca -config openssl.cnf -gencrl -out crl.pem
#la visualiser:
openssl crl -in crl.pem -text</pre>
<div class="footnotes"><h4>Note</h4>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2015/03/13/Authentifier-un-client-web-via-un-certificat-TLS#rev-wiki-footnote-1" id="wiki-footnote-1">1</a>] Pour déclarer nos impôts il n'y a plus besoin de certificat personnel, mais les interlocuteurs (fonctionnaires de collectivités) ont leurs propres clés PKCS pour communiquer avec cette administration</p></div>
IPTables2, Router via passerelle une différente en fonction du port de destinationurn:md5:aa5f1b79d8bbc0859009de51c4515c532014-07-08T16:10:00+02:002017-02-24T00:39:30+01:00gniearkServeurs http web et autresIPTablesRéseauTutoriel-mémo <p><a href="https://blog-du-grouik.tinad.fr/public/switch.jpg" title="switch.jpg"><img src="https://blog-du-grouik.tinad.fr/public/.switch_m.jpg" alt="switch.jpg" style="display:table; margin:0 auto;" title="switch.jpg, juil. 2014" /></a></p>
<p>::TOC::</p>
<h2>Descriptif de la passerelle</h2>
<p>Un serveur sous debian 7 qui sert de passerelle avec trois cartes réseaux.</p>
<ul>
<li>eth0 vers le LAN</li>
<li>eth1 vers un modem Orange Buisness</li>
<li>eth2 vers une Box Bouygues Telecom</li>
</ul>
<p>Les cartes sont configurées comme ceci dans le fichier /etc/network/interfaces</p>
<pre class="brush: bash">#s file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo eth0 eth1 eth2
iface lo inet loopback
# The primary network interface Carte vers le LAN
allow-hotplug eth0
iface eth0 inet static
address 192.168.15.253
netmask 255.255.255.0
network 192.168.15.0
broadcast 192.168.15.255
dns-nameservers 127.0.0.1 192.168.15.254
dns-search lan
#carte reseau vers le modem Orange
iface eth1 inet static
address 192.168.10.252
netmask 255.255.255.0
broadcast 192.168.10.255
network 192.168.10.0
gateway 192.168.10.1
#carte reseau vers le modem Bouygues (IP bytel box 192.168.1.254)
iface eth2 inet static
address 192.168.1.10
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0</pre>
<p>A ce niveau là, toutes les connexions vers l'extérieur passent par le lien Orange, mais on peut pinguer la box Bouygues.</p>
<p>La commande route -n retourne:</p>
<pre>
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.10.1 0.0.0.0 UG 0 0 0 eth1
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.15.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
</pre>
<p>Dans ce tuto je suppose que vous avez su configurer vos trois cartes réseau à peu près de cette manière.</p>
<h2>Objectif</h2>
<p>Dans ce billet, je ne vais pas décrire comment faire un vrai load balancing à base d'IPtable. Tout simplement parce que les deux points d'accès internet n'ont pas les même particularités. Le lien Orange Buisness a une IP fixe et un reverse DNS paramétré. Le smtp par exemple, doit absolument sortir par ce lien. Tandis que la box Bouygues est techniquement la même chose que ce qu'ils offrent aux particuliers (TV en moins).</p>
<p>On va router de cette manière:</p>
<ul>
<li>Par défaut: ça passe par le lien Orange</li>
<li>Le HTTPS et le HTTP (le surf du personnel et des quelques patients à qui je fournis un point internet) passent par le lien Bouygues.</li>
</ul>
<p>Ça me permet d'alléger le lien Orange, et aussi d'anonymiser un peu le surf des utilisateurs de l’Hôpital qui m'emploie. Jusqu'à avant hier, lorsqu'un patient allait sur internet, le webmaster du site pouvait voir avec le Reverse DNS et le WHOIS que la connexion provenait d'un centre Hospitalier (à vocation gériatrique vu l'intitulé qu'a mis Orange dans le Whois).</p>
<h2>C'est parti pour le paramétrage</h2>
<h3>Créer une deuxième table de routage</h3>
<p>Vu que dans le fichier /etc/network/interfaces la gateway est renseignée pour le lien Orange, la table de routage par défaut est automatiquement créée. On ne va donc pas se occuper d'Orange, mais seulement du lien bouygues dans la suite.</p>
<p>On ajoute "2 bouygues" à la fin du fichier /etc/iproute2/rt_tables comme ceci:</p>
<pre>
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
2 bouygues
</pre>
<h3>IPTABLES: Quand et comment le serveur doit appliquer cette table de routage.</h3>
<p>Toute la suite, je la fais dans mon script qui me sert de pare feu, et qui est lancé au démarrage du serveur.
Seule la fin du script sert au forwarding. L'idée est que vous puissiez adapter votre propre script de parefeu de votre passerelle.</p>
<pre></pre>
<p>Les explications sont en commentaire.</p>
<pre class="brush: bash">#! /bin/sh
### BEGIN INIT INFO
# Provides: firewall
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: firewall
# Description:
### END INIT INFO
# Interface qui est sur Internet (WAN) Lien Orange IP fixe
WAN_IFACE="eth1"
#Inerface Bouygues (IP publique non fixe)
WAN_IFACE_BYTEL="eth2"
# Interface qui est dans votre réseau local (LAN)
LAN_IFACE="eth0"
###### Debut Initialisation ######
# Réinitialisation
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
# Les tables sont effacées.
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
iptables -t nat -X
iptables -t mangle -X
# bloquer le trafic (comportement par défaut).
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD ACCEPT
########### Regles pour que le serveur fonctionne (SSH, HTTP, HTTPS) ##########
#Cette partie est mise à titre d'exemple mais ce n'est pas l'objet de ce billet,
#Pour les règles concernant le FORWARDING et la répartition entre les deux tables
#de routage, allez directement à la fin du script
# Autoriser loopback
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A OUTPUT -o lo -j ACCEPT
#on accepte le ping
iptables -A INPUT -p icmp -j ACCEPT
iptables -A OUTPUT -p icmp -m conntrack --ctstate NEW,ESTABLISHED,RELATED -j ACCEPT
#NTP (synchronisation de l'heure du serveur)
iptables -A OUTPUT -p udp --dport 123 -j ACCEPT
iptables -A INPUT -p udp --sport 123 -j ACCEPT
#DNS (le serveur DNS est configuré pour ne pas répondre à une requete
# Ne provenant pas du LAN)
iptables -t filter -A INPUT -p tcp --destination-port 53 -j ACCEPT
iptables -t filter -A INPUT -p udp --destination-port 53 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --destination-port 53 -j ACCEPT
iptables -t filter -A OUTPUT -p udp --destination-port 53 -j ACCEPT
#SSH (accessible depuis l'extérieur avec une clé uniquement)
iptables -t filter -A INPUT -p tcp --destination-port 22 -j ACCEPT
# HTTP HTTPS
#Commentez ces lignes si votre serveur ne sert pas de serveur WEB
iptables -A INPUT -p tcp --destination-port 80 -j ACCEPT
iptables -A INPUT -p tcp --destination-port 443 -j ACCEPT
#Pour que le serveur puisse faire des requetes http et https
iptables -A OUTPUT -p tcp --destination-port 80 -j ACCEPT
iptables -A OUTPUT -p tcp --destination-port 443 -j ACCEPT
# Dans mon cas, c'est un serveur de Mail
iptables -t filter -A INPUT -p tcp --destination-port 25 -j ACCEPT
iptables -t filter -A INPUT -p tcp --destination-port 110 -j ACCEPT
iptables -t filter -A INPUT -p tcp --destination-port 143 -j ACCEPT
iptables -t filter -A INPUT -p tcp --destination-port 993 -j ACCEPT
iptables -t filter -A INPUT -p tcp --destination-port 587 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --destination-port 993 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --destination-port 25 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --destination-port 110 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --destination-port 143 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --destination-port 587 -j ACCEPT
##Depuis Le LAN uniquement:
#c'est un serveur DHCP. Supprimez les lignes si non
iptables -t filter -A INPUT -i $LAN_IFACE -p tcp --destination-port 67:68 -j ACCEPT
iptables -t filter -A INPUT -i $LAN_IFACE -p udp --destination-port 67:68 -j ACCEPT
iptables -t filter -A OUTPUT -o $LAN_IFACE -p tcp --destination-port 67:68 -j ACCEPT
iptables -t filter -A OUTPUT -o $LAN_IFACE -p udp --destination-port 67:68 -j ACCEPT
#Proxy Squid
iptables -t filter -A INPUT -i $LAN_IFACE -p tcp --destination-port 3128 -j ACCEPT
#Puppet
iptables -t filter -A INPUT -i $LAN_IFACE -p tcp --destination-port 8140 -j ACCEPT
iptables -t filter -A OUTPUT -i $LAN_IFACE -p tcp --destination-port 8140 -j ACCEPT
# FTP
#Le FTP est autorisé depuis le lan untiqument
modprobe ip_conntrack_ftp
iptables -A INPUT -p tcp --dport ftp -j ACCEPT
iptables -A INPUT -p tcp --dport ftp-data -j ACCEPT
iptables -A INPUT -p ALL -i $LAN_IFACE -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -o $LAN_IFACE -p tcp --sport ftp -j ACCEPT
iptables -A OUTPUT -o $LAN_IFACE -p tcp --sport ftp-data -j ACCEPT
iptables -A INPUT -i $LAN_IFACE -m state --state NEW -p tcp --dport 49152:65534 -j ACCEPT
#serveur de cache de mise à jour pour les postes linux
iptables -A INPUT -i $LAN_IFACE -p tcp --dport 3142 -j ACCEPT
iptables -A OUTPUT -i $LAN_IFACE -p tcp --dport 3142 -j ACCEPT
################## FORWARDING ET ROUTAGE ######################################
#C'est là que commence l'objet du billet sur le blog du Grouik
#Pour débian
echo 0 > /proc/sys/net/ipv4/tcp_ecn
#activer le forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
#Forcer le passage dans le proxy: (à supprimer si vous nb'utilisez pas squid)
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
#iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 3128
#Empécher le transit de paquets SMTP.
#Je les envoie au serveur de mail (qui les rejettera mais loguera)
#supprimez si votre passerelle ne fait pas de mail
iptables -t nat -A PREROUTING -i $LAN_IFACE -p tcp --dport 25 -j REDIRECT --to-port 25
#!!!!!!!!!!!!!!!!!!!!!!!!!!!
#Marquer les paquets http et https qu'on fera passer par la connexion bouygues
#Le reste passe par la connexion par défaut (orange IP fixe)
#Marquage des paquets en Forward
iptables -A PREROUTING -t mangle -p tcp --dport 80 -j MARK --set-mark 2
iptables -A PREROUTING -t mangle -p tcp --dport 443 -j MARK --set-mark 2
#Optionnel, mais utile si vous utilisez squid; Marquer les paquets HTTP
#et HTTPS générés par le serveur lui même
iptables -t mangle -A OUTPUT -p tcp --dport 80 -j MARK --set-mark 2
iptables -t mangle -A OUTPUT -p tcp --dport 443 -j MARK --set-mark 2
######### TABLE DE ROUTAGE ##########
#delete, puis place la table de routage boutygues
ip rule delete table bouygues
#Lui indiquer la passerelle (l'IP de la box)
ip route add default via 192.168.1.254 dev $WAN_IFACE_BYTEL table bouygues
#Les paquets marqués 2 doivent passer par la table bouygues:
ip rule add fwmark 2 table bouygues
#Autoriser le forwading dans les deux sens
#Bouygues
iptables -A FORWARD -i eth2 -o eth0 -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
#Orange
iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE
exit 0</pre>
<p>Envoyer</p>Libre office calc requéter une base MySQLurn:md5:0f9fb7815d4ac8b05590110fa922920f2013-12-20T13:34:00+01:002017-02-24T19:00:16+01:00gniearkDépannages informatiqueslibre officeMySqlTutoriel-mémoubuntu <p>::TOC::</p>
<p>On va voir dans ce billet comment charger dans le tableur de libre office des données provenant d'une base MySQL.
Le PC client est une kubuntu. Le serveur de bdd est une débian (mais ça ça n'a pas d'importance).</p>
<h2>Prérequis:</h2>
<ul>
<li>Un serveur MySQL installé</li>
<li>Libre office installé sur le poste client</li>
</ul>
<h2>Permettre l'accès distant sur le serveur MySQL.</h2>
<p>Editez le fichier /etc/mysql/my.cnf</p>
<p>Afin de permettre les connexions depuis d'autres ordinateurs modifiez la ligne bind-adress par celle-ci</p>
<pre>
bind-address = 0.0.0.0
</pre>
<pre class="brush: bash">#Redémarrez mysql
/etc/init.d/mysql restart
#puis connectez vous à mysql
mysql -u root -p</pre>
<p>Ajoutez un utilisateur ayant les droits depuis un poste distant (remplacer localhost par % dans la commande GRANT)</p>
<pre class="brush: sql">#pour un accès en lecture seulement:
GRANT SELECT ON votrebase.* TO 'user'@'%' IDENTIFIED BY 'votreMotDePasse';
#Si vous souhaitez un acces total à la base:
GRANT ALL ON votrebase.* TO 'user'@'%' IDENTIFIED BY 'votreMotDePasse';</pre>
<p>Si nécessaire, ouvrez le pare-feu pour permettre les connexions mysql (port 3306). Voici un exemple si votre firewall est à base d'iptables et que votre LAN est 192.168.0.* :</p>
<pre>
iptables -A INPUT -p tcp --destination-port 3306 -m iprange --src-range 192.168.0.1-192.168.0.254 -j ACCEPT
</pre>
<h2>Sur le poste client</h2>
<p>Installer le connecteur sur le client</p>
<pre class="brush: bash">sudo apt-get install libreoffice-mysql-connector</pre>
<p>Voila, on a tout ce qu'il faut. L'application libre office base servira d'intermédiaire entre calc et le serveur mysql.
Depuis un microsoft office. MS query aurait servi d'intermédiaire mais il est plus transparent que oooBase,.</p>
<p>Ouvrez libre office -> nouveau document-base de donnée.</p>
<p>Dans l'assistant de base de données, choisissez "Se connecter à une base de donnée existante", et "Mysql" comme ça:</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/loMysql1.jpeg" alt="loMysql1.jpeg" style="display:table; margin:0 auto;" title="loMysql1.jpeg, déc. 2013" /></p>
<p>"Connecter directement" (c'est plus simple)</p>
<pre><img src="https://blog-du-grouik.tinad.fr/public/loMysql2.jpeg" alt="loMysql2.jpeg" style="display:table; margin:0 auto;" title="loMysql2.jpeg, déc. 2013" /></pre>
<p>Ma base s'appelle tinaderp. Adaptez en fonction de la votre, ainsi que l'IP du serveur:
<img src="https://blog-du-grouik.tinad.fr/public/loMysql3.jpeg" alt="loMysql3.jpeg" style="display:table; margin:0 auto;" title="loMysql3.jpeg, déc. 2013" /></p>
<p>Puis l'user Mysql:
<img src="https://blog-du-grouik.tinad.fr/public/loMysql4.jpeg" alt="loMysql4.jpeg" style="display:table; margin:0 auto;" title="loMysql4.jpeg, déc. 2013" /></p>
<p>A l'étape suivante, surtout cochez "Oui, je souhaite que l'assistant référence la base de données" Ce sera beaucoup plus facile pour retrouver les données dans le tableur puis cliquez sur terminer</p>
<p>Il vous demande d'enregistrer le fichier. Je vous conseille de donner au fichier le nom de votre base de donnée.</p>
<p>On arrive sur cette interface:
<img src="https://blog-du-grouik.tinad.fr/public/.loMysql6_m.jpg" alt="loMysql6.jpeg" style="display:table; margin:0 auto;" title="loMysql6.jpeg, déc. 2013" /></p>
<h3>Créer quelques requêtes</h3>
<p>Mon objectif ici est de pouvoir faire des statistiques. La bdd étant relativement brute. Si j'importe la base de données direct dans un tableur, ça va être pénible. (Ceux qui ont fait déjà des formules de recherches matricielles dans un tableur me comprendront).
Je vais donc créer les requêtes SQL qui me feront les sous totaux, les décomptages tout en liant les tables afin d'avoir les intitulés et pas les clés. Bref, je veux avoir les tableaux que je n'aurai qu'à sélectionner pour établir les graphiques. Si ce n'est pas votre cas, que le contenu des tables de façon brute vous suffit. passez directement au chapitre suivant.</p>
<p>Requetes -> Creer une requête en mode SQL</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.loMysql7_m.jpg" alt="loMysql7.jpeg" style="display:table; margin:0 auto;" title="loMysql7.jpeg, déc. 2013" /></p>
<p>Testez la requête puis enregistrez la. je lui donne le nom sommeParTypeParMois
Enregistrez votre fichier de base de données.</p>
<h3>Dans le tableur scalc</h3>
<p>Données -> table et pilote -> Créer</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.loMysql8_m.jpg" alt="loMysql8.jpeg" title="loMysql8.jpeg, déc. 2013" /></p>
<p>Source de données enregistrée sous libre office
<img src="https://blog-du-grouik.tinad.fr/public/loMysql9.jpeg" alt="loMysql9.jpeg" style="display:table; margin:0 auto;" title="loMysql9.jpeg, déc. 2013" /></p>
<ul>
<li>Sélectionnez votre base (qui a le nom du fichier base).</li>
<li>Le type: feuille si vous voulez une table brute, ou requête si vous voulez récupérer les données d'une requête.</li>
</ul>
<p><img src="https://blog-du-grouik.tinad.fr/public/loMysql10.jpeg" alt="loMysql10.jpeg" style="display:table; margin:0 auto;" title="loMysql10.jpeg, déc. 2013" /></p>
<p>Organisez comme il faut colonnes lignes et données en faisant du glisser déposer.
<img src="https://blog-du-grouik.tinad.fr/public/.loMysql11_m.jpg" alt="loMysql11.jpeg" style="display:table; margin:0 auto;" title="loMysql11.jpeg, déc. 2013" /></p>
<h2>Enjoy!</h2>
<p><img src="https://blog-du-grouik.tinad.fr/public/.loMysql12_m.jpg" alt="loMysql12.jpeg" style="display:table; margin:0 auto;" title="loMysql12.jpeg, déc. 2013" /></p>Dotclear, ajouter une table des matières dans un billeturn:md5:af92b3a68ede6b5ae63debbd5ee55fb82012-06-28T21:57:00+02:002017-04-07T09:08:43+02:00gniearkdev webdotclearjavascriptTutoriel-mémo <p>::TOC::</p>
<h2>Edit:</h2>
<p>Je rajoute (et recommande) une première méthode, le plugin multitoc qui m'a été signalée dans les commentaires et qui a l'avantage de ne pas faire passer un code javascript qui parcourt la page. (plus propre).</p>
<h2>La méthode du plugin multitoc</h2>
<h3>Installez les pluggins</h3>
<p><a href="http://plugins.dotaddict.org/dc2/details/multiToc" hreflang="fr">multitoc</a> et <a href="http://plugins.dotaddict.org/dc2/details/stacker">stackers</a></p>
<p>L'extension "Table des matières" apparait dans le bandeau de gauche de l'administration de dotclear.</p>
<p>Allez y pour activer les tables des matières sur les billets.</p>
<h3>Dans le CSS j'ai ajouté:</h3>
<pre class="brush: css">.post-toc {
background-color: #FFFFFF;
border: 1px solid #8CACBB;
padding: 0.5em 0 0.7em;
text-align: left;
color: #1D2B4F;
margin-bottom: 10px;
clear: both;
float: right;
font-size: 80%;
margin: 1.2em 0 0 2em;
width: 200px;
z-index: 10;
}
.post-toc a{color: #1D2B4F;}
.post-toc ul{padding: 2px; margin:10px;}
.post-toc ul li{padding-bottom: 4px;}</pre>
<p>pour personnaliser la table des matières.</p>
<h3>Dans l'interface de rédaction d'un billet</h3>
<p>L'icone
<img src="https://blog-du-grouik.tinad.fr/public/bt_multitoc.png" alt="bt_multitoc.png" title="bt_multitoc.png, juil. 2012" />
permet d'ajouter le sommaire.</p>
<h2>Méthode JavaScript</h2>
<p>Je vais vous expliquer la technique que j'ai utilisée pour mettre une table des matières dans ce billet. Celle-ci reprend automatiquement les titres; marqués par des !!!! dans le mode wiki, puis des balises <h1> <h2> etc....</p>
<p>Techniquement la solution est moche<sup>[<a href="https://blog-du-grouik.tinad.fr/post/2012/06/28/Dotclear%2C-ajouter-une-table-des-mati%C3%A8res-dans-un-billet#wiki-footnote-1" id="rev-wiki-footnote-1">1</a>]</sup>: c'est un code javascript qui crée le sommaire de toute pièce.</p>
<h3>Descriptif de la méthode.</h3>
<p>Rendons à Cesar ce qui appartient à César, je n'ai pas fait grand chose.
J'utilise le plugin MyMeta codé par un ami de tous les dotcleariens <a href="http://plugins.dotaddict.org/dc2/details/mymeta">MyMeta sur dottatict</a> -- Bruno Hondelatte et je me suis basé sur le javascript et l'explication donnée par <a href="http://fr.blog.thomasmuguet.info/index.php?post/2011/07/31/Generer-une-table-des-matieres-dans-les-billets-dotclear">Thomas Muguet sur son blog</a> (l'art de modifier un truc que je n'aurai pas été capable de faire)</p>
<p>Mymeta sert à identifier les billet qui auront un sommaire (je le mettrai sur ceux qui sont assez longs). pour ces billets, on met une sorte de marqueur dans son qui permettra au script ajouté sur le site d'insérer la table des matières uniquement dans ce billet.</p>
<p>Cette dernière se repose sur les principe des ancres HTML</p>
<h3>MyMeta pour repérer les billets qui auront un sommaire:</h3>
<p>Installez sur le sur votre blog, <a href="http://plugins.dotaddict.org/dc2/details/mymeta">MyMeta sur dottatict</a></p>
<p>Puis creez un méta de type case à cocher, comme ça:</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.mymeta-sommaire_m.jpg" alt="mymeta-sommaire.jpeg" style="display:table; margin:0 auto;" title="mymeta-sommaire.jpeg, juin 2012" /></p>
<p>Pensez à activer le méta.</p>
<p>Maintenant, dans l'interface de rédaction d'un billet, j'ai une case à cocher "sommaire" en bas.</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.mymeta-sommaire1_m.jpg" alt="mymeta-sommaire1.jpeg" style="display:table; margin:0 auto;" title="mymeta-sommaire1.jpeg, juin 2012" /></p>
<p>(inception inside)</p>
<p>On a vu comment différencier les billets à sommariser et maintenant, une nouvelle partie à ce billet (et donc un nouveau element de mon sommaire):</p>
<h3>Adapter le template:</h3>
<h4>Au niveau d'un billet (post)</h4>
<p>Dans le contenu d'un billet, dans la div class="post-content", (et au début de celle-ci); s'il y a un sommaire il faut qu'il y ait la div avec l'id toc.</p>
<pre class="brush: html"><tpl:MyMetaIf type="sommaire" value="1">
<div class="toc">
<h2>Table des matières:</h2>
</div>
</tpl:MyMetaIf></pre>
<p>en fait, le j'ai mis ainsi (seulement pour les billets qui sont entièrement affichés):</p>
<pre class="brush: html"><!-- # Entry without excerpt -->
<tpl:EntryIf extended="0">
<div class="post-content"><tpl:MyMetaIf type="sommaire" value="1"><div class="toc"><h2>Table des matières:</h2></div></tpl:MyMetaIf>{{tpl:EntryContent}}</div>
</tpl:EntryIf></pre>
<p>C'est à faire dans tous les fichiers de template qui donnent le contenu d'un billet (avec le jeu des include, je n'en ai qu'un pour le template de ce blog)</p>
<h4>Ajouter le script javascript</h4>
<p>dans le fichier _head.html de votre template, ajoutez:</p>
<pre>
<script type="text/javascript" src="{{tpl:BlogThemeURL}}/tableDesMatieres2.js"></script>
</pre>
<p>et déposez le fichier <a href="https://blog-du-grouik.tinad.fr/themes/aorakit-2D/tableDesMatieres2.js">http://blog-du-grouik.tinad.fr/themes/aorakit-2D/tableDesMatieres2.js</a> à la racine du thème de votre blog.</p>
<p>Comme indiqué en intro, il s'agit d'une adaptation du code de <a href="http://fr.blog.thomasmuguet.info/index.php?post/2011/07/31/Generer-une-table-des-matieres-dans-les-billets-dotclear">thomasmuguet.info</a></p>
<p>Il contient ça (des fois que je venais à le déplacer en oubliant d'éditer ce billet):</p>
<pre class="brush: javascript">/*
* Script modifié de façon mineure par Gnieark http://blog-du-grouik.tinad.fr juin 2012
* (place le sommaire dans le post-content afin de mieux pouvoir le gérer en CSS)
* Sépare les ancres des titres (juste avant, c'est plus joli)
*
* Script initial par Thomas Muguet:
* http://fr.blog.thomasmuguet.info/index.php?post/2011/07/31/Generer-une-table-des-matieres-dans-les-billets-dotclear
*
*/
// Unique ID for each element in TOC
var uid=0;
// Generate the TOC from an element, at a certain depth
function getTOCLevel(from, level) {
var content = '';
// Depending on the depth, detect where to stop traversing the DOM
var to = (level == 2) ? ".post-content" : "h2";
if (level > 3) {to += " h3";}
if (level > 4) {to += " h4";}
if (level > 5) {to += " h5";}
// Traverse the DOM for all elements
$.each(from.nextUntil(to, "h"+level), function() {
// Get the title and the UID
var title = $(this).text();
var aname = "toc_"+uid;
uid++;
// Create an anchor so the user can reach the header element
$(this).append('<a name="'+aname+'"/>');
// Create the TOC entry
content += '<li><a href="#'+aname+'">'+title+'</a>';
// "We need to go deeper"
if (level < 6) { // This is where you choose the maximum depth
content += getTOCLevel($(this), level+1);
}
content += '</li>';
});
if (content == '') {return "";}
return '<ul>' + content + '</ul>';
}
$(document).ready(function() {
// Parse each TOC
$.each($(".toc"), function() {
// Generate the TOC
var toccontent = getTOCLevel($(this), 2);
if (toccontent == "") {
$(this).hide();
} else {
$(this).append(toccontent);
$(this).show();
}
});
});</pre>
<h4>Dans le css ajoutez/personnalisez:</h4>
<pre class="brush: css">.toc {
background-color: #FFFFFF;
border: 1px solid #8CACBB;
padding: 0.5em 0 0.7em;
text-align: left;
color: #1D2B4F;
margin-bottom: 10px;
clear: both;
float: right;
font-size: 80%;
margin: 1.2em 0 0 2em;
width: 200px;
z-index: 10;
}
.toc a{color: #1D2B4F;}
.toc ul{padding: 2px; margin:10px;}
.toc ul li{padding-bottom: 4px;}</pre>
<h3>Finaliser l'installation</h3>
<p>Changez de thème et remettez votre thème pour que dotclear prenne en compte toutes les modifications.</p>
<p>Evidemment, si un pluggin qui fait ça manque à dotclear, c'est c'est parcequ'il est un moteur de blog. Mon utilisation du blog du grouik, se situe entre le blog et le wiki.</p>
<div class="footnotes"><h4>Note</h4>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2012/06/28/Dotclear%2C-ajouter-une-table-des-mati%C3%A8res-dans-un-billet#rev-wiki-footnote-1" id="wiki-footnote-1">1</a>] Le principe de faire un script qui parcourt l'ensemble d'une page html pour l'adapter est assez moche, j'en conviens. La création d'un plugin qui génère le sommaire "en dur" dans le code html du billet n'est pas évident, et je ne suis ni assez callé sur ce cms, ni certain que ce soit possible via l'api dotclear.</p></div>
Serveur de sauvegarde -- BackupPCurn:md5:057cbb0d8351dd8a41f2d0281adb25812012-06-25T23:37:00+02:002017-03-31T22:50:08+02:00gniearkServeurs http web et autresLogiciel-libreRéseausauvegardeserveurTutoriel-mémo <p>::TOC::</p>
<p>Ce billet est le deuxième volet de ma recherche du système de sauvegarde.</p>
<p>Crevons le suspense de suite, je retiens cette solution, mais j'y apporterai des compléments (liés aux limitation de backupPC)</p>
<p>Comme je dédierai un petit <sup>[<a href="https://blog-du-grouik.tinad.fr/post/2012/06/25/Serveur-de-sauvegarde-BackupPC#wiki-footnote-1" id="rev-wiki-footnote-1">1</a>]</sup> serveur à cette fonction (il est en commande). Là pour ce mémo, je pars d'une débian sans interface graphique, ni rien, fraichement (ré-)installée.</p>
<p>Quelques screens sont faits de chez moi avec le test depuis une fedora et une debian dans une virtual box, d'autres, depuis le test en live du LAN du travail. Sur les impressions d'écran les IP ne sont pas toujours cohérentes avec l'ordre du tutoriel, n'y faites pas attention.</p>
<h2>Installer apache (basique, sans php) et backuppc</h2>
<p>Le Gui de backupPc fonctionne avec des scripts CGI, pas besoin de base de donnée mysql, ni de PHP.</p>
<p>En root exécuter:</p>
<pre class="brush: bash">apt-get install apache2 apache2-doc backuppc</pre>
<p>Il va installer plein de dépendances, dont samba qui vous pose cette question:</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.Backup-PC-samba_m.jpg" alt="Backup-PC-samba.jpeg" style="display:table; margin:0 auto;" title="Backup-PC-samba.jpeg, juin 2012" /></p>
<p>Là je suis dans mon réseau de virtualbox, donc je laisse workgroup, cependant lors des tests effectués au travail, j'avais mis le nom du domaine windows.</p>
<p>Ensuite il propose d'auto-configurer un VHOST apache:</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.Backup-PC-apache_m.jpg" alt="Backup-PC-apache.jpeg" style="display:table; margin:0 auto;" title="Backup-PC-apache.jpeg, juin 2012" /></p>
<p>Appuyez la barre espace pour cocher "apache" puis tab et entrée pour valider :p</p>
<p>Notez le mot de passe qu'il vous indique!</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.Backup-PC-apache-htpassword_m.jpg" alt="Backup-PC-apache-htpassword.jpeg" style="display:table; margin:0 auto;" title="Backup-PC-apache-htpassword.jpeg, juin 2012" /></p>
<p>Si comme moi (lors de la première installation avant de rédiger ce billet) vous avez oublié le mot de passe, vous pouvez le changer ainsi:</p>
<pre class="brush: bash">htpasswd /etc/backuppc/htpasswd backuppc</pre>
<h2>Rendez vous sur la page d'admin de BackupPc</h2>
<p>l'adresse est http://IpDuServeurDeBackup/backuppc dans mon cas: http://192.168.0.31/backuppc/</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.Backup-PC-auth_m.jpg" alt="Backup-PC-auth.jpeg" style="display:table; margin:0 auto;" title="Backup-PC-auth.jpeg, juin 2012" /></p>
<p>Vous l'aurez compris, c'est une identification par un .htpassword seulement. Dans l'état actuel, ce serait une jolie négligence d'ouvrir l'interface sur le Web. Je reviendrai en fin du billet sur la façon de sécuriser un peu mieux cette interface (https) si j'ai le temps.</p>
<p>La première chose que je fais, c'est passer l'interface en français. aller dans "Edit Config" puis l'onglet "CGI" pour passer l'interface en Français.</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.BackupPC-french_m.jpg" alt="BackupPC-french.jpeg" style="display:table; margin:0 auto;" title="BackupPC-french.jpeg, juin 2012" /></p>
<p>Cliquez sur le gros bouton save qui est apparu.</p>
<h2>Maintenant on va configurer les sauvegardes.</h2>
<p>On va voir comment sauver une machine sous windows, puis un linux.</p>
<p>Si vous avez un contrôleur du domaine, avec un active directory correctement configuré, créez un compte "sauveur" avec un mot de passe bien bourrin et donnez donnez lui les droits administrateurs afin qu'il puisse passer partout.</p>
<p>Le Lan dans lequel j'installerai BackupPc a les particularités suivantes:</p>
<ul>
<li>Les clients sont des adresses dynamiques (DHCP), mais une stratégie de profils itinérants est déployée, ce qui fait que je ne vais pas sauvegarder les postes clients, mais juste le serveur accueillant les profils itinérants. (et les autres serveurs)</li>
<li>Les serveurs ont des adresses IP fixes.</li>
</ul>
<p>Du coup, je vais utiliser les IP des machines, mais il serait tout à fait possible d'utiliser les noms DNS de ces dernières des fois que ce soit dynamique.</p>
<h3>Sauvegarder un windows</h3>
<h4>Créer un utilisateur qui aura accès à tout le poste.</h4>
<p>Le principe, est de créer un partage à la racine du / des disques durs, qu'on ouvre à un compte windows qui a tous les droits :D</p>
<div id="divToHide1">
<script type="text/javascript">
document.getElementById("divToHide1").style.display='none';
</script>
<p>Là c'est parce que je suis en dehors d'un domaine pour les tests, je le ferai au niveau du contrôleur de domaine lors du vrai déploiement de cette solution. Mais dans l'immédiat, sur le Windows qui me sert de test, on va créer un nouvel administrateur du dit poste.</p>
<p>Le principe est le même sur un widows Seven, c'est juste que je n'ai pas de license en rabe pour en virtualiser un.</p>
<p>Allez hop, j'allume un windows dans une vbox.</p>
<p>Click droit sur le poste de travail, gérer, allez dans utilisateurs et groupes, puis utilisateurs.</p>
<h5>Un click droit pour créer un nouvel utilisateur:</h5>
<p><img src="https://blog-du-grouik.tinad.fr/public/.winXPnouvelUtilisateur_m.jpg" alt="winXPnouvelUtilisateur.jpeg" style="display:table; margin:0 auto;" title="winXPnouvelUtilisateur.jpeg, juin 2012" /></p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.winXP-Partage-C1_m.jpg" alt="winXP-Partage-C1.jpeg" style="display:table; margin:0 auto;" title="winXP-Partage-C1.jpeg, juin 2012" /></p>
<h5>Rendez vous dans les groupes, Celui administrateurs, click droit -> propriétés -> onglet "Membres" pour ajouter le compte sauveur:</h5>
<p><img src="https://blog-du-grouik.tinad.fr/public/.winXP-Partage-C3_m.jpg" alt="winXP-Partage-C3.jpeg" style="display:table; margin:0 auto;" title="winXP-Partage-C3.jpeg, juin 2012" /></p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.winXP-Partage-C4_m.jpg" alt="winXP-Partage-C4.jpeg" style="display:table; margin:0 auto;" title="winXP-Partage-C4.jpeg, juin 2012" /></p>
<h5>Dans le poste de travail, click droit sur le disque c, propriétés, et dans l'onglet partage:</h5>
<p><img src="https://blog-du-grouik.tinad.fr/public/.winXP-Partage-C_m.jpg" alt="winXP-Partage-C.jpeg" style="display:table; margin:0 auto;" title="winXP-Partage-C.jpeg, juin 2012" /></p>
<h5>Et un petit tour dans les autorisation pour donner tous les droits au groupe "Administrateurs"</h5>
<p><img src="https://blog-du-grouik.tinad.fr/public/.winXP-Partage-C5_m.jpg" alt="winXP-Partage-C5.jpeg" style="display:table; margin:0 auto;" title="winXP-Partage-C5.jpeg, juin 2012" /></p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.winXP-Partage-C6_m.jpg" alt="winXP-Partage-C6.jpeg" style="display:table; margin:0 auto;" title="winXP-Partage-C6.jpeg, juin 2012" /></p>
<p>Voila, on a fini pour la préparation du poste windows, retournons à BackupPc.</p>
</div>
<p><a onclick='document.getElementById("divToHide1").style.display="";'>Voir les impression d'écran et le mémo pour créer le partage</a></p>
<h4>Configurer le backup d'une machine windows</h4>
<p>Dans l'interface de backupPc, je vais dans "Modifier les machines" et j'ajoute la nouvelle:</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.BackupPc-addMachine_m.jpg" alt="BackupPc-addMachine.jpeg" style="display:table; margin:0 auto;" title="BackupPc-addMachine.jpeg, juin 2012" /></p>
<p>Une fois ajoutée, je sélectionne la nouvelle machine dans la liste déroulante en haut à gauche et je vais dans modifier la configuration.</p>
<p>onglet Xfer et j'ajoute les paramètres samba:</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.BackupPc-addMachine1_m.jpg" alt="BackupPc-addMachine1.jpeg" style="display:table; margin:0 auto;" title="BackupPc-addMachine1.jpeg, juin 2012" /></p>
<h3>Sauvegarder un linux</h3>
<p>Ça va être moins galère à expliquer que sur windows ça.</p>
<ul>
<li>192.0.168.254 c'est le client</li>
<li>192.0.168.31 c'est le serveur</li>
</ul>
<p>Evidemment, remplacez ces IP par les votres dans la suite.</p>
<h4>Générer des clés ssh sur le serveur</h4>
<p>Les clés ssh du serveur lui permettront de se connecter aux clients à sauver.</p>
<p>En tant que root, sur le serveur:</p>
<pre class="brush: bash">#installer openssh-server
apt-get install openssh-server
#se mettre en user backuppc
su -l backuppc
#générer un couple de clés
ssh-keygen -t rsa
#laissez le chemin par défaut (/var/lib/backuppc/.ssh/id_rsa dans mon cas),
#et ne mettez pas de mot de passe
#redevenir root
exit
#envoyer la clé publique sur le repertoire web du serveur
cp /var/lib/backuppc/.ssh/id_rsa.pub /var/www/</pre>
<h4>Sur le PC client:</h4>
<p>Il faut lui autoriser les connexions avec la clé qu'on vient de générer sur le serveur backuppc
en Root:</p>
<pre class="brush: bash">apt-get install openssh-server
#remplacez l'IP ici donnée par celle de votre serveur
wget http://192.168.0.31/id_rsa.pub
mkdir
touch ~/.ssh/authorized_keys
cat id_rsa.pub >> ~/.ssh/authorized_keys</pre>
<h4>revenir sur le serveur</h4>
<p>en root:</p>
<pre class="brush: bash">su -l backuppc
#faire une connexion ssh vers le client histoire de l'enregistrer dans le fichier know_hosts
ssh root@192.0.168.254
#validez par yes
#au passage, supprimez la clé publique du dossier web (on l'a mise là tout à l'heure)
rm /var/www/id_rsa.pub</pre>
<h4>Revenir sur l'interface web de backuppc pour ajouter la machine linux</h4>
<p>Serveur>Modifier les machines, ajoutez votre machine.
Bilan des machines -> selectionnez celle qui correspond à la nouvelle.
Modifiez la configuration -> onglet Xfer
et mettez les paramètres comme ceci:</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.backuppc-cles1_m.jpg" alt="backuppc-cles1.jpeg" style="display:table; margin:0 auto;" title="backuppc-cles1.jpeg, juin 2012" /></p>
<p>nottemment:</p>
<ul>
<li>XferMethod rsync</li>
</ul>
<p>Le reste des paramètres était ok par défaut.</p>
<p>Enfin lancez la sauvegarde.</p>
<h2>Et comment qu'on restaure?</h2>
<p>Dans le Gui web, tous simplement, sur une machine, en allant dans "explorer les sauvegardes"</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.backuppc-restaure_m.jpg" alt="backuppc-restaure.jpeg" style="display:table; margin:0 auto;" title="backuppc-restaure.jpeg, juin 2012" /></p>
<h2>BackupPc Peut-il saturer les disques d'un serveur? -- Créer une partition uniquement pour les sauvegardes</h2>
<p>Oui et non:</p>
<p>Voici le screen du test de BackupPC que j'avais laissé tourner sans m'en occuper sur un serveur du travail.
<img src="https://blog-du-grouik.tinad.fr/public/.backuppc-full3_m.jpg" alt="backuppc-full3.jpg" style="display:table; margin:0 auto;" title="backuppc-full3.jpg, juin 2012" /></p>
<p>A 97% de la place occupée il s'est arrêté de faire des sauvegardes, S'il n'a pas la place de sauvegarder, il ne sauvegarde pas. Dans mon cas, les 3% restant suffisaient au fonctionnement normal des autres fonctions du serveur (ouf)</p>
<p>Bref pour être tranquilou, le plus simple est d'obliger backuppc de sauvegarder sur un disque séparé, ou au moins une autre partition que la partition système.
Pour modifier le lieu où backupPC va mettre ses sauvegardes, dans le fichier /etc/backuppc/config.pl
.changez la ligne</p>
<pre class="brush: php">$Conf{TopDir} = '/var/lib/backuppc';</pre>
<p>par ce que vous voulez,</p>
<p>Dans le cas du serveur de test en attendant la livraison du serveur qui sera dédié à cette tâche, je mets: /home/backuppc/ car /home est monté sur un autre groupe de disques qui a un chouilla plus d'espace.</p>
<pre class="brush: bash">#créer le repertoire avec les bons droits
mkdir /home/backuppc
chown -R backuppc:backuppc /home/backuppc
#y mettre l'arboressence dont backuppc se sert
cd /var/lib/backuppc
mv * /home/backuppc/</pre>
<h2>Complément: mySQL et SQL-Serveur</h2>
<p>Pour <a href="https://blog-du-grouik.tinad.fr/post/2012/07/17/Backup-de-bases-de-donn%C3%A9es-mySQL-et-Microsoft-SQL-server">préparer les bases avant leurs sauvegardes, c'est traité dans ce billet.</a></p>
<h2>Conclusion</h2>
<p>Backuppc répond totalement à ma problématique de l'utilisateur qui a perdu un fichier il y a plusieurs jours. Pour la sauvegarde des bases de données et éventuellement envisager la sauvegrade de partitions entières, l'outil seul ne suffit pas. Je ferai prochainement un mémo sur comment faire un backup d'un serveur Microsoft SQL et d'une base de données MySQL.</p>
<div class="footnotes"><h4>Note</h4>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2012/06/25/Serveur-de-sauvegarde-BackupPC#rev-wiki-footnote-1" id="wiki-footnote-1">1</a>] dimmensionné à 4 GO de RAM et je sais plus quoi en processeur, mais 4 Téras octets mis en raid 1, donc 8 téras de disques durs</p></div>
Test de Mumble et tuto d'installation du serveur Murmururn:md5:58e565097da71695bfc1ef4fc388de682012-03-23T14:00:00+01:002017-04-04T08:09:03+02:00gniearkServeurs http web et autresaudioLogiciel-libretchattelephoneTutoriel-mémo <p><img src="https://blog-du-grouik.tinad.fr/public/.myvoice_m.jpg" alt="myvoice.jpg" style="display:table; margin:0 auto;" title="myvoice.jpg, mar. 2012" /></p>
<p>Après <a href="https://blog-du-grouik.tinad.fr/post/2012/03/15/test-de-Teamspeak">teamspeak</a>, voici le test de mumble, dans le domaine des systèmes de conférences VOIP. L'avantage de mumble c'est qu'il est libre et se trouve dans les dépôts de la plupart des distributions (donc facile à installer)! Je vais rapidement présenter en quelques impressions d'écran l'interface de mumble, l'interface de MAP (qui est un code tiers) permettant d'administrer le serveur. Puis mes notes pour l'installation de Murmur (le nom donné à la partie serveur de mumble)</p>
<h2>Mumble en Quelques screens</h2>
<h3>L'ouverture de Mumble</h3>
<p><img src="https://blog-du-grouik.tinad.fr/public/.mumble-b_m.jpg" alt="mumble-b.jpg" style="display:table; margin:0 auto;" title="mumble-b.jpg, mar. 2012" /></p>
<h3>Paramètres de connexion à un serveur (non listé)</h3>
<p><img src="https://blog-du-grouik.tinad.fr/public/mumble1-b.jpg" alt="mumble1-b.jpg" style="display:table; margin:0 auto;" title="mumble1-b.jpg, mar. 2012" /></p>
<h3>Connecté à un serveur</h3>
<p><img src="https://blog-du-grouik.tinad.fr/public/.mumble2-b_m.jpg" alt="mumble2-b.jpg" style="display:table; margin:0 auto;" title="mumble2-b.jpg, mar. 2012" /></p>
<h2>Installer le client mumble:</h2>
<pre class="brush: bash">#sous fedora
yum install mumble
#sous débian ou ubuntu
apt-get install mumble</pre>
<h3>Rustine pour Fedora 64 bits</h3>
<p>Sous fedora 64 bits lors de la connexion à un serveur, vous aurez le message d'erreur suivant:</p>
<pre>
Incapable de trouver des codecs CELT correspondant aux autres clients. Vous ne serez pas capable de parler aux autres utilisateurs.
</pre>
<p><a href="https://bugzilla.redhat.com/show_bug.cgi?id=672092">La rustine est donnée par Dirk Schlüter sur les tickets de red Hat</a></p>
<pre class="brush: bash">#Rustine pour fedora 64 bits
cd /usr/local/src/
wget http://th0br0.fedorapeople.org/celt071-0.7.1/celt071-0.7.1-1.fc13.src.rpm
rpm -i celt071-0.7.1-1.fc13.src.rpm
cd /root/rpmbuild/
yum install libogg-devel
rpmbuild -ba SPECS/celt071.spec
#dans la ligne suivante changez éventuellement celt071-0.7.1-1.fc15.x86_64.rpm par celt071-0.7.1-1.fc14.x86_64.rpm
#en fonction de votre version de fedora
rpm -ivh /root/rpmbuild/RPMS/x86_64/celt071-0.7.1-1.fc15.x86_64.rpm
ln -s /usr/lib64/libcelt071.so.0 /usr/lib64/libcelt0.so.0.0.0</pre>
<h2>le serveur (test sur une débian):</h2>
<h3>Installation</h3>
<pre class="brush: bash">apt-get install mumble-server
dpkg-reconfigure mumble-server
#démarrer le serveur mumble:
/etc/init.d/mumble-server start</pre>
<p>A cette étape, le serveur mumble fonctionne, vous pouvez vous y connecter, sauf qu'il sera impossible de le paramétrer. Il faut définir un mot de passe administrateur
Sur le serveur:</p>
<pre class="brush: bash">murmurd -ini /etc/mumble-server.ini -supw VotreMotDePasse</pre>
<h3>Administrer le serveur</h3>
<p>Connectez vous via le client avec l'identifiant "superuser"</p>
<p>serveur -> connexion -> ajouter un serveur. Comme ceci:</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/mumble.jpg" alt="mumble.jpg" style="display:table; margin:0 auto;" title="mumble.jpg, mar. 2012" /></p>
<p>Bon ok, dans le client, je n'ai pas trouvé où mettre le mot de passe. c'est pas grave, avec cet identifiant, il vous le demandera.</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.mumble2_m.jpg" alt="mumble2.jpeg" style="display:table; margin:0 auto;" title="mumble2.jpeg, mar. 2012" /></p>
<p>Dans le client, le click droit sur le nom du serveur mumble, sur un channel ou la zone blanche vous permettra d'accéder à quelques outils d'administration. Cependant les possibilités ne sont pas exhaustives.</p>
<p>Le wiki anglophone conseille d'utiliser "ICE", on va dans ce billet utiliser une interface web php utilisant la librairie ice. Cependant notez que d'autres solutions existent.</p>
<p>De mon coté, il y a déja un LAMP sur le serveur. j'ajoute la librairie ICE simplement ainsi:</p>
<pre class="brush: bash">apt-get install php-zeroc-ice</pre>
<h3>Configurer mumble-server pour pouvoir utiliser ice.</h3>
<p>Éditez le fichier /etc/mumble-server.ini
et ajoutez ou dé-commentez les lignes suivantes:</p>
<pre>
dbus=session
ice="tcp -h 127.0.0.1 -p 6502"
</pre>
<h3>Interface d'administration (MAP Mumble Admin Plugin)</h3>
<p>Je ne détaille pas, ça s'installe comme n'importe que CMS.</p>
<ul>
<li>Créez préalablement une base de données mysql sur le serveur.</li>
<li>Téléchargez MAP sur ce site: <a href="http://mumble.sourceforge.net/MAP_-_Mumb1e_Admin_Plugin" hreflang="en">http://mumble.sourceforge.net/MAP_-_Mumb1e_Admin_Plugin</a>. Vous devrez créer un compte pour pouvoir télécharger.</li>
<li>Décompresser l'archive dans un dossier WEB du serveur mumble (le billet ici n'explique pas comment installer un serveur LAMP, référez vous à celui là ou celui là)</li>
<li>Rendez vous via un navigateur sur l'interface de MAP.</li>
</ul>
<h3>Quelques screens de MAP</h3>
<h4>La page de connexion</h4>
<p><img src="https://blog-du-grouik.tinad.fr/public/.map_m.jpg" alt="map.jpg" style="display:table; margin:0 auto;" title="map.jpg, mar. 2012" /></p>
<h4>La liste des serveurs administrables</h4>
<p><img src="https://blog-du-grouik.tinad.fr/public/.map1_m.jpg" alt="map1.jpg" style="display:table; margin:0 auto;" title="map1.jpg, mar. 2012" /></p>
<h4>MAP fournit à la page http://VotreURL/request une interface où les utilisateurs potentiels peuvent s'inscrire si vous souhaitez n'autoriser que les users avec mot de passe.</h4>
<p><img src="https://blog-du-grouik.tinad.fr/public/.map2_m.jpg" alt="map2.jpg" style="display:table; margin:0 auto;" title="map2.jpg, mar. 2012" /></p>
<h4>On peut accepter ou non les requetes d'inscription dans l'interface d'admin.</h4>
<p><img src="https://blog-du-grouik.tinad.fr/public/.map3_m.jpg" alt="map3.jpg" style="display:table; margin:0 auto;" title="map3.jpg, mar. 2012" /></p>
<h2>Conclusion</h2>
<p>Mumble est super sympa, la qualité de son me semble meilleure que teamspeak. En plus pour les essais, je me suis incrusté sur des chans "Salut je suis gnieark, je vous embête juste le temps d'un test". Les mecs sur lesquels je suis tombé étaient sympas. (Je m'étais fait insulter sur teamspeak <sup>[<a href="https://blog-du-grouik.tinad.fr/post/2012/03/15/test-de-mumble#wiki-footnote-1" id="rev-wiki-footnote-1">1</a>]</sup>). Autre point Mumble n'est pas spécialisé jeux en ligne, Il y a des salons plus généralistes. C'est assez sympa.</p>
<p>Enfin concernant l'enregistrement, c'était l'objectif pour les causeries, Mumble ne le propose pas. Cependant pour les linuxiens, vu que mumble utilise le système de son du système<sup>[<a href="https://blog-du-grouik.tinad.fr/post/2012/03/15/test-de-mumble#wiki-footnote-2" id="rev-wiki-footnote-2">2</a>]</sup> l'ouverture d'un "magnétophone" sur l'ordinateur enregistre super bien.</p>
<div class="footnotes"><h4>Notes</h4>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2012/03/15/test-de-mumble#rev-wiki-footnote-1" id="wiki-footnote-1">1</a>] Enfin je soupçonne d’être tombé sur l'ex de mon ex qui sait que je suis Gnieark, et heu dans ses propos pas supers compréhensibles, je crois qu'il requérait que je le sodomise.</p>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2012/03/15/test-de-mumble#rev-wiki-footnote-2" id="wiki-footnote-2">2</a>] j'ai du mal à expliquer les détails techniques là</p></div>
limesurvey CMS de création d'enquetes et de sondages.urn:md5:027721be6a5df2f52811b4fa8bce67af2012-02-29T01:44:00+01:002017-04-04T08:21:17+02:00gniearkDecouvertes, tips and shits sur le webApacheBig-BrotherLogiciel-libreTutoriel-mémo <p>La demande qui m'a été faite était de mettre en place un outil qui aide le service qualité à créer ses enquêtes (et surement aussi pour les versions papiers, une aide à la ressaisie<sup>[<a href="https://blog-du-grouik.tinad.fr/post/2012/02/27/limesurvey#wiki-footnote-1" id="rev-wiki-footnote-1">1</a>]</sup> et au traitement statistique).</p>
<p>Après quelques recherches infructueuses, c'est un collègue d'un établissement voisin qui m'a conseillé <a href="http://www.limesurvey.org/fr" hreflang="fr">Limesurvey.</a> Je ne regrette pas car limesurvey correspond entièrement à ce que je cherchais, et j'en profite pour partager sur ce blog cette pépite.</p>
<p>LimeSurvey s'installe sur un serveur web relativement standard (php 5.3, une base de données). Je vais vous le présenter en quelques screensShoots, mets un sondage absurde sur ce billet, puis explique l'installation.</p>
<h3>Présentation</h3>
<p>Il permet de gérer des questionnaires et à première tous les cas de figures sont prévus:
Des types de réponse, des questions qui ne sont affichées qu'en fonction des réponses précédente.
Il permet de publier, générer des statistiques, exporter les réponses dans divers formats. Il est méga complet (du coup je ne vais pas tout détailler ici) et pas trop compliqué.</p>
<pre></pre>
<h3>Quelques screens shoots de l'interface d'admin:</h3>
<h4>Il est entièrement traduit en français:</h4>
<p><img src="https://blog-du-grouik.tinad.fr/public/.limeSurvey_m.jpg" alt="limeSurvey.jpeg" style="display:table; margin:0 auto;" title="limeSurvey.jpeg, fév. 2012" /></p>
<h4>Je crée un nouveau questionnaire</h4>
<p><img src="https://blog-du-grouik.tinad.fr/public/.limeSurvey2-creer-Questionnaire_m.jpg" alt="limeSurvey2-creer-Questionnaire.jpeg" style="display:table; margin:0 auto;" title="limeSurvey2-creer-Questionnaire.jpeg, fév. 2012" /></p>
<h4>Un groupe de questions</h4>
<p><img src="https://blog-du-grouik.tinad.fr/public/.limeSurvey4-creer-Groupe_m.jpg" alt="limeSurvey4-creer-Groupe.jpeg" style="display:table; margin:0 auto;" title="limeSurvey4-creer-Groupe.jpeg, fév. 2012" /></p>
<h4>Une question:</h4>
<p><img src="https://blog-du-grouik.tinad.fr/public/.limeSurvey6-creer-Question_m.jpg" alt="limeSurvey6-creer-Question.jpeg" style="display:table; margin:0 auto;" title="limeSurvey6-creer-Question.jpeg, fév. 2012" /></p>
<h4>Voici le détail des possibilités de types de réponses attendus:</h4>
<p><img src="https://blog-du-grouik.tinad.fr/public/.limeSurvey8-type-de-reponses_m.jpg" alt="limeSurvey8-type-de-reponses.jpeg" title="limeSurvey8-type-de-reponses.jpeg, fév. 2012" /></p>
<h3>Installation de lime survey</h3>
<p>Bien qu'il n'y ait pas un GUI pour le paramétrage de la connexion, l'installation reste super simple.</p>
<h4>Creez la base de données et un user mysql si nécessaire.</h4>
<pre class="brush: sql">CREATE DATABASE limesurvey;
mysql> GRANT ALL ON limesurvey.* TO 'limesurvey'@'localhost' IDENTIFIED BY 'lkjdplopf32dfdfdf!!!?;sfsd:/';</pre>
<p>Remplacez lkjdplopf32dfdfdf!!!?;sfsd:/ par le mot de passe de votre choix.</p>
<h4>Télécharger limesurvey.</h4>
<p>Vous trouverez la dernière version de limeSurvey sur leur site.<a href="http://www.limesurvey.org/fr/stable-release" hreflang="fr"> http://www.limesurvey.org/fr/stable-release</a> Téléchargez la et décompressez le dossier sur votre site internet.</p>
<h4>Paramétrer LimeSurvey</h4>
<p>Editez le fichier config.php en renseignant dans les variables PHP correspondant aux parametres de votre base de données.
Perso pour une configuration standard (mysql),
j'ai juste changé les variables suivantes:</p>
<pre class="brush: php">$databaselocation = 'localhost';
$databasename = 'limesurvey';
$databaseuser = 'limesurvey';
$databasepass = 'lkjdplopf32dfdfdf!!!?;sfsd:/';
$dbprefix = 'lime_';</pre>
<p>et un peu plus loin, le compte administrateur (il sera possible d'en créer d'autres dans l'interface ultérieurement)</p>
<pre class="brush: php">// Installation Setup
$defaultuser = 'gnieark'; // This is the username when LimeSurvey is installed and the administration user is created on installation
$defaultpass = 'toto'; // This is the password for the administration user when LimeSurvey is installed</pre>
<p>Pour plus d'info, la documentation est <a href="http://docs.limesurvey.org/Installation+en+Francais&structure=Instructions+fran%C3%A7aises+pour+LimeSurvey" hreflang="fr">par là en Français</a></p>
<h3>Pour le reste, l'installation se fera automatiquement, rendez vous simplement à l'URL http://VotreSite.com/limesurvey/admin/install/</h3>
<p>Et suivez les indications. jusqu'à ce qu'il vous demande de supprimmer le repertoire admin/install (faites le)</p>
<div class="footnotes"><h4>Note</h4>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2012/02/27/limesurvey#rev-wiki-footnote-1" id="wiki-footnote-1">1</a>] Je travaille en gériatrie, lorsque les personnes interrogées seront les résidents, pas évident de leur faire aller sur un site internet</p></div>
Le NAS de la Freebox V6 pour les nulsurn:md5:c675017ae3fbdbf7cde4d8c1630697322011-06-21T02:13:00+02:002017-04-10T14:31:22+02:00gniearkDépannages informatiquesfreeboxftpRéseauTutoriel-mémowindows <p><img src="https://blog-du-grouik.tinad.fr/public/.freebox-v6-revolution_s.jpg" alt="freebox-v6-revolution.jpg" style="float:left; margin: 0 1em 1em 0;" title="freebox-v6-revolution.jpg, juin 2011" />C'est sympa d'avoir un disque accessible par tous les ordinateurs (voire consoles, téléviseurs chaine hifi) du réseau domestique.</p>
<p>Chers lecteurs, vous n'êtes pas tous des admins réseau habitués à faire du mappage de lecteurs toussa, d'où ce petit tutoriel expliquant comment profiter de son NAS, ici celui de la freebox V6.</p>
<p>C'est assez chiant de devoir se connecter manuellement à chaque fois. On va voir sur linux, puis sous windows comment se faire un raccourci, puis mieux comment monter de façon permanente le lecteur.</p>
<p>La freebox supporte plusieurs protocoles:</p>
<ul>
<li>FTP</li>
<li>Partages windows (samba)</li>
</ul>
<p>Le choix de l'un ou l'autre peut être un débat passionné. Je choisis le partage windows même sous linux<sup>[<a href="https://blog-du-grouik.tinad.fr/post/2011/06/21/Freebox-V6-faciliter-l-acc%C3%A8s-au-NAS#wiki-footnote-1" id="rev-wiki-footnote-1">1</a>]</sup></p>
<h3>Les paramétrages de la freebox.</h3>
<h4>Sur l'interface de la freebox (http://mafreebox.freebox.fr), NAS > Windows; comme ceci:</h4>
<p><img src="https://blog-du-grouik.tinad.fr/public/.freebox-nas-windows_m.jpg" alt="freebox-nas-windows.jpg" style="display:table; margin:0 auto;" title="freebox-nas-windows.jpg, juin 2011" /></p>
<h3>Linux</h3>
<h4>Juste un raccourci</h4>
<p>la commande</p>
<pre class="brush: bash">nautilus "smb://freebox/disque dur"</pre>
<p>permet d'ouvrir le disque dur de la box.</p>
<p>Cilck droit sur le bureau > créer un lanceur;
<img src="https://blog-du-grouik.tinad.fr/public/freebox-lanceur.jpg" alt="freebox-lanceur.jpg" style="display:table; margin:0 auto;" title="freebox-lanceur.jpg, juin 2011" /></p>
<p>C'est cool, à présent d'un double click sur l'icone on accede au NAS.</p>
<p>Oui mais si vous allez un peu au delà d'une utilisation "glisser déposer des fichiers". Genre utiliser des scripts de sauvegardes; il sera préférable de monter cet emplacement réseau de façon permanente.</p>
<h4>Emplacement monté de façon permanente sur le système de fichiers.<sup>[<a href="https://blog-du-grouik.tinad.fr/post/2011/06/21/Freebox-V6-faciliter-l-acc%C3%A8s-au-NAS#wiki-footnote-2" id="rev-wiki-footnote-2">2</a>]</sup></h4>
<p>Les commandes suivantes sont à utiliser en tant que root</p>
<pre class="brush: bash">#creer le repertoire dans lequel sera monté le NAS
mkdir /media/freebox
#éditer le fichier fstab
vi /etc/fstab</pre>
<p>et y ajouter la ligne suivante:</p>
<pre>
//mafreebox.freebox.fr/disque\040dur/ /media/freebox cifs _netdev,rwx,uid=1000,gid=1000,credentials=/root/.smbcredentials,iocharset=utf8 0 0
</pre>
<p>Créer le fichier credentials</p>
<pre class="brush: bash">vi /root/.smbcredentials</pre>
<p>y mettre ceci:</p>
<pre>
username=
password=
</pre>
<p>(ne pas remplir l'userame et le password)</p>
<p>Monter:</p>
<pre class="brush: bash">mount /media/freebox</pre>
<p>(ce sera monté a chaque démarrage)</p>
<h3>Windaube</h3>
<h4>Juste créer un raccourci</h4>
<p>Allez dans démarrer puis exécuter
<img src="https://blog-du-grouik.tinad.fr/public/.freebox-nas-windaube_m.jpg" alt="freebox-nas-windaube.jpg" style="display:table; margin:0 auto;" title="freebox-nas-windaube.jpg, juin 2011" />
entrez:</p>
<pre>
//FREEBOX
</pre>
<p>On arrive sur la racine du NAS, plus qu'à créer un raccourci du partage disque dur sur le bureau.
<img src="https://blog-du-grouik.tinad.fr/public/.freebox-nas-windaube1_m.jpg" alt="freebox-nas-windaube1.jpg" style="display:table; margin:0 auto;" title="freebox-nas-windaube1.jpg, juin 2011" /></p>
<h4>Créer un lecteur réseau, avec une tête de lecteur genre i:</h4>
<p>démarrer exécuter</p>
<pre>
net use i: "\\freebox\Disque dur"
</pre>
<p>et la freebox apparait dans le poste de travail. Magique non?</p>
<h3>Pour les sauvegardes vers le NAS de la freebox;</h3>
<p>Sous linux, de façon totalement objective je conseille backup-manager, mais avec un export en FTP.</p>
<p>Sous windows, <a href="http://www.fbackup.com/" hreflang="fr">Freebackup</a> me parait pas mal.</p>
<div class="footnotes"><h4>Notes</h4>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2011/06/21/Freebox-V6-faciliter-l-acc%C3%A8s-au-NAS#rev-wiki-footnote-1" id="wiki-footnote-1">1</a>] On reste dans un LAN domestique, la sécurité ne rentre pas en compte pour le choix. Si vous êtes sous windows, le partage windows est beaucoup mieux pris en charge que le ftp (pas toujours la possibilité d'éditer les fichiers directement sur le serveur). Si vous êtes sous linux, le choix devrait dépendre de l'utilisation. Si le NAS vous servira juste à basculer des gros fichiers pour de la sauvegarde, préferez le FTP, ce sera plus efficace. Par contre, si vous déposez des vidéos, préférez le partage samba. Je ne pense pas qu'en FTP, l'OS puisse demander à lire juste un morceau d'un fichier, celui ci doit etre chargé linéairement. Ça empêche de pouvoir naviguer dans un film.</p>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2011/06/21/Freebox-V6-faciliter-l-acc%C3%A8s-au-NAS#rev-wiki-footnote-2" id="wiki-footnote-2">2</a>] Solution expliquée par philarete sur ce <a href="http://freebox.toosurtoo.com/forum/viewtopic.php?f=62&t=2552#p32596" hreflang="fr">forum</a></p></div>
Tutoriel: Samba, un controleur de domaine, sous linuxurn:md5:330bc3821a47c197ef36f9b8da6db7292011-03-29T12:53:00+02:002017-03-10T15:19:39+01:00gniearkServeurs http web et autresdebianRéseauserveurTutoriel-mémowindows <p><img src="https://blog-du-grouik.tinad.fr/public/Reseau4.jpg" alt="Reseau4.jpg" style="display:table; margin:0 auto;" title="Reseau4.jpg, mar. 2011" /></p>
<p>On va tenter l'installation d'un contrôleur de domaine (terme windowsien) sous une débian 6. Car oui, depuis pas mal de temps déjà, samba sait aller au delà du partage de fichiers et d'imprimantes.</p>
<p>Pour le moment je reste basique. C'est à dire authentification des utilisateurs avec quelques mappages de dossiers. J'essaierai d'aller au delà dans un autre billet.</p>
<p>On verra le paramétrage, puis un test sur windows7.</p>
<h2>Quelques documents</h2>
<p>Il y a pleins de tutoriels là dessus, je ne suis pas original mais perso, j'ai du en croiser plusieurs pour faire ce que je voulais.</p>
<ul>
<li>Sur Tux planet, un super tutoriel très simple. <a href="http://www.tux-planet.fr/un-controleur-de-domaine-avec-samba/" hreflang="fr">Un contrôleur de domaine avec Samba</a>, Je m'appuierai dessus pour une bonne partie de la suite. Bien que basé sur une ancienne version de samba.</li>
<li><a href="http://ferry.eof.eu.org/lesjournaux/pg/public_html/x4243.html" hreflang="fr">Une Excellente documentation aussi, à jour</a>. Qui a l'intérêt d'aborder la gestion du serveur.</li>
<li>Pour l'intégration d'un windows 7, les clés de registres à modifier ou le patch microsoft sont expliqués sur le <a href="https://wiki.samba.org/index.php/Windows7" hreflang="en">wiki samba</a>.</li>
</ul>
<h2>Serveur</h2>
<p>Un serveur débian propre, sans rien de plus.</p>
<h2>Samba!</h2>
<h3>Installation</h3>
<pre class="brush: bash">apt-get install samba</pre>
<p>Actuellement dans les paquets de débian Lenny, c'est la version 3.5 de samba qui est installée.</p>
<h3>Configuration.</h3>
<h4>Explication. / synoptique</h4>
<ul>
<li>Chaque utilisateur aura un dossier personnel, une tête de lecteur réseau H sur leur poste de travail, qui pointe en fait vers le homedir de l'user linux correspondant.</li>
<li>Les profils itinérants sont stockés sur le serveur dans /home/samba/profiles/username. Le partage réseau quand à lui est //serveur/profiles/username</li>
<li>Netlogon (/home/samba/netlogon sur le serveur; //serveur/netlogon en chemin UnC) Sert aux scripts de démarrage et de directives qui s'appliquent aux ordinateurs, ou lors de la connexion des utilisateurs. Cependant Dans cette version de samba, il n'y a pas besoin de créer à la mano les fichiers batch pour monter des dossiers. Il va les générer tout seul comme un grand à partir des directives mises dans son fichier de configuration.</li>
</ul>
<p>Le fichier de configuration /etc/samba/smb.conf est divisé en plusieurs parties:
[global] et une mini partie par partage. Voyons le Global.</p>
<h4>Configuration générale</h4>
<p>Je liste dans un premier temps quelques directives du fichier sur lesquelles je pense utile de faire un petit commentaire.</p>
<p>Le nom du domaine ou workgroup:</p>
<pre>
workgroup = dom_grouik
</pre>
<p>Le nom du serveur sur le réseau sera son nom d'installation:</p>
<pre>
server string = %h
</pre>
<p>Pour le moment je laisse WINS désactivé. WINS assure (assurait, ça parait obsolète) un service de noms netbios, Un équivalent du DNS quoi, mais à plus petite échelle. A cette étape du tuto, je ne sais pas encore si je vais retenir cette solution, ou me baser sur un bind ou autre.</p>
<pre>
# wins support = no
</pre>
<p>Je laisse interfaces commentée car par défaut, samba répondra à toutes les requêtes. Mais si vous souhaitiez limiter à un VLAN particulier, c'est là qu'il faut le mettre:</p>
<pre>
; interfaces = 127.0.0.0/8 eth0
</pre>
<pre>
security = user
</pre>
<p>Les mots de passe unix et samba seront synchronisés. Cette commande active l’exécution du programme externe défini à la directive passwd program, lors du changement de mot de passe samba</p>
<pre>
unix password sync = yes
</pre>
<p>C'est le maitre (par opposition à contrôleur de domaine secondaire):</p>
<pre>
domain master = yes
</pre>
<p>Mouais, je n'ai pas trop saisi le but de la directive suivante:
L'OS level si je me souviens bien c'est lorsqu'il y a plusieurs controleur de domaine celui qui aura l'OS le plus eleve sera choisi.
<em>Explication de zilozi dans les commentaires</em>... Un peu comme le champs MX dans les DNS quoi</p>
<pre>
os level = 33
</pre>
<p>Pour insister sur le fait que c'est le maitre (surtout en cas de conflit):</p>
<pre>
preferred master = yes
</pre>
<p>C'est le partage où sera placé le profil de l'user (son "documents and settings" quoi)</p>
<pre>
logon path = \\%N\profiles\%U
</pre>
<p>Samba permet de monter directement (sans faire à la main un script batch) le home_dir de l'user unix sur une tête de lecteur. Il aura besoin de placer les scripts dans un partage "netlogon" (plus bas):</p>
<pre>
logon drive = H:%%%
logon home = \\%N\%U
</pre>
<p>scripts lors de l'ajout d'users ou de machines depuis un pc client:</p>
<pre>
add user script = /usr/sbin/adduser -g dom_users -c Utilisateur -d /dev/null -s /bin/false '%u'%%%
add machine script = /usr/sbin/useradd -g dom_pc -c "%u machine account" -d /dev/null -s /bin/false '%u'%%%
add group script = /usr/sbin/groupadd '%g'%%%
delete user script = /usr/sbin/userdel -r '%u'%%%
delete group script = /usr/sbin/groupdel '%g'%%%
delete user from group script = /usr/bin/gpasswd -d '%u' '%g'%%%
set primary group script = /usr/sbin/usermod -g '%g' '%u' %%%
</pre>
<p>En retirant toutes les lignes commentées ça donne:</p>
<pre>
[global]
workgroup = dom_grouik
server string = %h
dns proxy = no
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0
panic action = /usr/share/samba/panic-action %d
security = user
encrypt passwords = true
passdb backend = tdbsam
obey pam restrictions = yes
unix password sync = yes
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
pam password change = yes
domain master = yes
os level = 33
preferred master = yes
domain logons = yes
logon path = \\%N\profiles\%U
logon drive = H:
logon home = \\%N\%U
add user script = /usr/sbin/adduser -g dom_users -c Utilisateur -d /dev/null -s /bin/false '%u'
add machine script = /usr/sbin/useradd -g dom_pc -c "%u machine account" -d /dev/null -s /bin/false '%u'
add group script = /usr/sbin/groupadd '%g'
delete user script = /usr/sbin/userdel -r '%u'
delete group script = /usr/sbin/groupdel '%g'
delete user from group script = /usr/bin/gpasswd -d '%u' '%g'
set primary group script = /usr/sbin/usermod -g '%g' '%u'
</pre>
<h4>Partages</h4>
<p>Vu la config au dessus, il faut trois partages: homes netlogon et profiles
Suffit de décommenter. Même si je n'aborde pas ici les imprimantes, je laisse les valeurs par défaut</p>
<pre>
[homes]
comment = Home Directories
browseable = no
read only = no
create mask = 0700
directory mask = 0700
valid users = %S
[netlogon]
comment = Network Logon Service
path = /home/samba/netlogon
guest ok = yes
read only = yes
[profiles]
comment = Users profiles
path = /home/samba/profiles
create mask = 0600
directory mask = 0700
writeable = yes
create mode = 0700
[printers]
comment = All Printers
browseable = no
path = /var/spool/samba
printable = yes
guest ok = no
read only = yes
create mask = 0700
[print$]
comment = Printer Drivers
path = /var/lib/samba/printers
browseable = yes
read only = yes
guest ok = no
</pre>
<h3>Mise en place.</h3>
<p>C'est là que j'ai honte, cette partie est quasiment un copier coller de <a href="http://www.tux-planet.fr/un-controleur-de-domaine-avec-samba/" hreflang="fr">tux-planet</a> (hormis le changement de dossiers, j'ai ajouté un mappage entre les Noms NT des groupes et les groupes unix)</p>
<pre class="brush: bash">#La première étape consiste à créer le compte administrateur.
#le mot de passe SAMBA doit être identique au mot de passe UNIX.
smbpasswd -a root
#La création des groupes servira plus loin, mais pas dans l'immédiat pour un simple partage de dossier
#Création du groupe des administrateurs du domaine
groupadd dom_admin
#Création du groupe des utilisateurs du domaine
groupadd dom_users
#Création du groupe des machines
groupadd -g 515 dom_pc
#Attribuons ensuite les bons RIDs aux trois groupes :
net groupmap add rid=515 unixgroup=dom_pc ntgroup="Domain Computers"
net groupmap set "Domain Admins" dom_admin
net groupmap set "Domain Users" dom_users
#creer les dossiers
mkdir /home/samba/
mkdir /home/samba/profiles
mkdir /home/samba/netlogon
cd /home/samba/
chgrp -R dom_users *
chmod -R 755 netlogon
chmod -R 770 profiles/
#Créer un user:
useradd -G dom_users -m -c "utilisateur test" -s /bin/false test
#Ajout de l'utilisateur à samba
smbpasswd -a test</pre>
<p>Vérifiez la configuration avec la commande:</p>
<pre class="brush: bash">testparmc</pre>
<p>Vérifiez le mapping des groupes par la commande:</p>
<pre class="brush: bash">net groupmap list</pre>
<p>Puis lancez samba:</p>
<pre class="brush: bash">/etc/init.d/samba start</pre>
<h3>Test sous windows:</h3>
<p>Sous Windows XP, c'est passé sans problème.</p>
<p>Pour seven, préalablement. Vous pouvez au choix demander le correctif à microsoft (ils le transmettent par e-mail) <a href="http://support.microsoft.com/kb/2171571" hreflang="fr">http://support.microsoft.com/kb/2171571</a></p>
<p>Ou à la mano, vous ajoutez les valeurs de registres suivantes</p>
<pre>
HKLM\System\CCS\Services\LanmanWorkstation\Parameters
DWORD DomainCompatibilityMode = 1
DWORD DNSNameResolutionRequired = 0
</pre>
<p>En quelques screens, l'ajout d'un ordinateur dans le domaine se fait par les propriétés du poste de travail, puis
Modification du nom de l'ordinateur. Lors de l'ajout, on utilise un compte administrateur (root) qu'on mettra plus loin administrateur de la machine au passage. Par la suite, il sera possible de s'authentifier sur l'ordinateur à partir de n'importe quel compte du domaine. Les droits sur la machine seront ceux d'un utilisateur standard.</p>
<p>En quelques screens
<a href="https://blog-du-grouik.tinad.fr/public/sambaseven/1.jpg" title="1.jpg"><img src="https://blog-du-grouik.tinad.fr/public/sambaseven/.1_m.jpg" alt="1.jpg" style="display:table; margin:0 auto;" title="1.jpg, mar. 2011" /></a></p>
<p><a href="https://blog-du-grouik.tinad.fr/public/sambaseven/2.jpg" title="2.jpg"><img src="https://blog-du-grouik.tinad.fr/public/sambaseven/.2_m.jpg" alt="2.jpg" style="display:table; margin:0 auto;" title="2.jpg, mar. 2011" /></a></p>
<p><a href="https://blog-du-grouik.tinad.fr/public/sambaseven/3.jpg" title="3.jpg"><img src="https://blog-du-grouik.tinad.fr/public/sambaseven/.3_m.jpg" alt="3.jpg" style="display:table; margin:0 auto;" title="3.jpg, mar. 2011" /></a></p>
<p><a href="https://blog-du-grouik.tinad.fr/public/sambaseven/4.jpg" title="4.jpg"><img src="https://blog-du-grouik.tinad.fr/public/sambaseven/.4_m.jpg" alt="4.jpg" style="display:table; margin:0 auto;" title="4.jpg, mar. 2011" /></a></p>
<p><a href="https://blog-du-grouik.tinad.fr/public/sambaseven/5.jpg" title="5.jpg"><img src="https://blog-du-grouik.tinad.fr/public/sambaseven/.5_m.jpg" alt="5.jpg" style="display:table; margin:0 auto;" title="5.jpg, mar. 2011" /></a></p>
<p><a href="https://blog-du-grouik.tinad.fr/public/sambaseven/6.jpg" title="6.jpg"><img src="https://blog-du-grouik.tinad.fr/public/sambaseven/.6_m.jpg" alt="6.jpg" style="display:table; margin:0 auto;" title="6.jpg, mar. 2011" /></a></p>
<p><a href="https://blog-du-grouik.tinad.fr/public/sambaseven/7.jpg" title="7.jpg"><img src="https://blog-du-grouik.tinad.fr/public/sambaseven/.7_m.jpg" alt="7.jpg" style="display:table; margin:0 auto;" title="7.jpg, mar. 2011" /></a></p>
<h3>C'est comment un AD Windows?</h3>
<p>Je me permet une petite digression, explication de ce qu'est un contrôleur de domaine Windows 2003. Le temps d'aller sur la passerelle avec ma clé ssh et de faire une redirection du port rdp sur le serveur du travail. Je fermerai juste après les ports évidemment.
Un active directory, pas obligatoire, mais en général, ce sont tout d'abord des ordinateurs qui sont intégrés dans le domaine.</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.win2003-computers_m.jpg" alt="win2003-computers.jpg" style="display:table; margin:0 auto;" title="win2003-computers.jpg, mar. 2011" /></p>
<p>Ce sont aussi des utilisateurs et des groupes:
<img src="https://blog-du-grouik.tinad.fr/public/.win2003-users_m.jpg" alt="win2003-users.jpg" style="display:table; margin:0 auto;" title="win2003-users.jpg, mar. 2011" /></p>
<p>Pour lesquels, on peut choisir plein de paramètres, là c'est l'utilisateur accueil: le script batch à exécuter au démarrage (montage de répertoires distants principalement) et le dossier dans lequel sera dupliqué son dossier documents and settings (profils itinérants)</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.win2003-profils_m.jpg" alt="win2003-profils.jpg" style="display:table; margin:0 auto;" title="win2003-profils.jpg, mar. 2011" /></p>
<p>Pour cela, un contrôleur de domaine partage plein de trucs en plus des dossiers à partager aux utilisateurs.</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.win2003-localhost_m.jpg" alt="win2003-localhost.jpg" style="display:table; margin:0 auto;" title="win2003-localhost.jpg, mar. 2011" /></p>
<p>Les scripts .bat à l'ouverture et les <a href="http://fr.wikipedia.org/wiki/Strat%C3%A9gies_de_groupe" hreflang="fr">GPO</a> par exemple.
<img src="https://blog-du-grouik.tinad.fr/public/.win2003-sysvol_m.jpg" alt="win2003-sysvol.jpg" style="display:table; margin:0 auto;" title="win2003-sysvol.jpg, mar. 2011" /></p>
<h2>Conclusion</h2>
<p>C'est pas mal, j'ai réussi à remplacer pas mal de fonctions du win2003 déja. Je ferai surement des ajouts à ce billet si je prends le temps de faire quelques tests (impression, DNS couplé à samba etc...)</p>VLC server onlyurn:md5:b656ac93f00c305cfbddbcf5c026b6e42011-03-15T23:34:00+01:002011-03-15T23:35:58+01:00gniearkServeurs http web et autresLogiciel-libreRéseauTutoriel-mémo <p>apt-get install vlc</p>
<p>Diffuser un film sur le net, VLC le permet, et ça fonctionne même avec un serveur sans interface graphique.</p>
<pre class="bash bash" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>vlc<span style="color: #000000; font-weight: bold;">/</span>http<span style="color: #000000; font-weight: bold;">/</span>.hosts</div></li></ol></pre>
<p>Rajoutez votre ip pour pouvoir accéder à la version web.
Pour lancer vlc en mode silencieux (le terminal rend la main):</p>
<pre class="bash bash" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #c20cb9; font-weight: bold;">su</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">"vlc -I http"</span> gnieark <span style="color: #000000; font-weight: bold;">>/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">>/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">&</span></div></li></ol></pre>
<p>pour le lancer normalement (juste le daemon web), de façon à voir les logs:</p>
<pre class="bash bash" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">vlc <span style="color: #660033;">-I</span> http</div></li></ol></pre>
<p>.</p>
<p>Ouvrir son navigateur à l'adresse du serveur sur le port 8080 (paramètre par défaut); genre http://XXX.XXX.XXX.XXX:8080</p>
<p><a href="https://blog-du-grouik.tinad.fr/public/vlc-stream-output.jpg" title="vlc-stream-output.jpg"><img src="https://blog-du-grouik.tinad.fr/public/.vlc-stream-output_m.jpg" alt="vlc-stream-output.jpg" style="display:block; margin:0 auto;" title="vlc-stream-output.jpg, mar. 2011" /></a></p>
<p>Ouvrez un fichier video, puis allez sur le bouton stream output.
<a href="https://blog-du-grouik.tinad.fr/public/vlc-stream2.jpg" title="vlc-stream2.jpg"><img src="https://blog-du-grouik.tinad.fr/public/.vlc-stream2_m.jpg" alt="vlc-stream2.jpg" style="display:block; margin:0 auto;" title="vlc-stream2.jpg, mar. 2011" /></a>
Alors là c'est un peu la galère, choisir le bon encodage (ou non) en fonction de la vidéo source et des greffons installés sur le serveur. Bref, quand vous avez trouvé la bonne solution</p>
<p>"save" au niveau du gui pour les options de diffusion puis play pour diffuser.</p>
<p>En local, dans le player vlc; fichier ouvrir un flux réseau.</p>
<p><a href="https://blog-du-grouik.tinad.fr/public/vlc-final.jpg" title="vlc-final.jpg"><img src="https://blog-du-grouik.tinad.fr/public/.vlc-final_m.jpg" alt="vlc-final.jpg" style="display:block; margin:0 auto;" title="vlc-final.jpg, mar. 2011" /></a></p>
<p>Voila. Un billet facile de ma part, mais qui a le mérite de préciser que c'est possible. Au fait, il y a moyen de gérer des playlists, et ce n'est pas obligatoirement un fichier en entrée. (un autre flux ou un périphérique). Bon dans les essais que j'ai fait, il cassait le flux entre deux titres. Mais je suis presque sur que c'est gérable. Pour une radio amateur par exemple.</p>Creer une application multi Vhosturn:md5:7b4422b49affbc0cf5108d60ba9e85652011-03-10T18:49:00+01:002011-03-14T20:11:54+01:00gniearkdev webApachedotclearPHPTutoriel-mémo <p><img src="https://blog-du-grouik.tinad.fr/public/.php_m.jpg" alt="php.jpg" style="display:block; margin:0 auto;" title="php.jpg, août 2010" />
Quelques mots de conception. Ce n'est pas LA solution, c'est un peu brouillon, mais je vais tenter de d'expliquer ici les idées et principes que j'applique actuellement dans la réécriture de l'application tinaderp en version plateforme.</p>
<p>Beaucoup de concepts que j'utilise proviennent de l'observation de dotclear en version multiblog.</p>
<p>L'idée, c'est que j'ai une application web qui va servir à un groupe d'utilisateurs. Pour qu'elle serve à un autre groupe, depuis un autre VHOST, le plus simple aurait été de faire une base de données nommée autrement et de copier tout le VHOST d'origine dans le nouveau... puis changer les paramètres de connexion mysql.</p>
<p>Oui, mais comme ça, je me taperai les mises à jour sur chaque site, un par un. Et comme beaucoup, je ne supporte pas les taches fastidieuses, quitte à me compliquer la vie pour les éviter.</p>
<p>Voyons rapidement la sécurisation du cross vhost, puis l'organisation des fichiers.</p>
<h2>Quelques définitions</h2>
<p>Oui, il y a quelques termes que j'emploie, peut être à mauvais escient, qui peuvent porter à confusion:</p>
<h4>VHOST:</h4>
<p>C'est un VirtualHost.
Il se définit principalement par son adresse URL et un dossier sur le serveur.
sur ce serveur par exemple, parmis la dizaine de vhost on trouve:</p>
<table border="1">
<tr><th>Dossier sur le serveur</th><th>URL d'acces</th></tr>
<tr><td>/var/www/blog-du-grouik.tinad.fr/</td><td>http://blog-du-grouik.tinad.fr</td></tr>
<tr><td>/var/www/www.tinad.fr/</td><td>http://www.tinad.fr</td></tr>
</table>
<h4>Framework</h4>
<p>C'est le socle de l'application. La partie de code qui gère l'authentification des utilisateurs et les différents modules.</p>
<h4>Module</h4>
<p>Bah c'est un menu quoi</p>
<h2>Configuration serveur</h2>
<h3>Apache en cross Vhost, un user unix par Vhost</h3>
<p>J'organise l'application comme un système d'application: les programmes d'un coté, la "data" des usagers de l'autre. Les utilisateurs pouvant uniquement lire et exécuter les applications. et ne pouvant pas lire la data du voisin.
Pour le test, je vais me faire trois vhost <sup>[<a href="https://blog-du-grouik.tinad.fr/post/2011/03/14/Creer-une-application-multi-Vhost#pnote-856-1" id="rev-pnote-856-1">1</a>]</sup>:</p>
<ul>
<li>vhost.tinad.fr</li>
<li>vhost1.tinad.fr</li>
<li>vhost2.tinad.fr</li>
</ul>
<p>vhost.tinad.fr contient les scripts php
vhost1.tinad.fr et vhost2.tinad.fr contient les fichiers servant séparément aux deux groupes (les documents déposés dans le cas d'une GED par exemple).</p>
<p>Le serveur apache, bien que lancé et configuré par root utilise un compte linux pour l’accès aux fichiers du site internet, généralement www-data. Dans un fichier php, on peut très bien lui demander d'aller chercher (avec un "include" ou autre) dans un fichier qui ne se trouve pas dans le répertoire du vhost. Le daemoon utilise pour ça le compte systeme www-data. Suffit juste que ce dernier ait un accès, on peut aller n'importe où sur le serveur.</p>
<p>Ils ont les fichiers de configuration très basique suivants:</p>
<pre>
<VirtualHost *:80>
ServerName vhost.tinad.fr
DocumentRoot /var/www/vhost.tinad.fr
</VirtualHost>
</pre>
<pre>
<VirtualHost *:80>
ServerName vhost1.tinad.fr
DocumentRoot /var/www/vhost1.tinad.fr
</VirtualHost>
</pre>
<pre>
<VirtualHost *:80>
ServerName vhost2.tinad.fr
DocumentRoot /var/www/vhost2.tinad.fr
</VirtualHost>
</pre>
<p>Juste pour l'explication de ce que j'appelle le cross vhost,
Je créé le fichier /var/www/vhost1.tinad.fr/plop.html suivant:</p>
<pre>[htm]
<h1>plop</h1>
</pre>
<p>Puis le fichier /var/www/vhost2.tinad.fr/index.php suivant:</p>
<pre class="php php" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><p>le site voisin dit:</p></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;"><?php</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #b1b100;">include</span> <span style="color: #009900;">(</span><span style="color: #0000ff;">"../vhost1.tinad.fr/plop.html"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">?></span></div></li></ol></pre>
<p>Résultat:</p>
<p><a href="https://blog-du-grouik.tinad.fr/public/crossvhost.jpg" title="crossvhost.jpg"><img src="https://blog-du-grouik.tinad.fr/public/.crossvhost_m.jpg" alt="crossvhost.jpg" title="crossvhost.jpg, mar. 2011" /></a></p>
<p>Le premier principe de conception va être d'utiliser cette possibilité sans que ce soit une épée de Damocles, permettant à tout script kiddie de pourrir tous les vhost à la moindre faille dans un script php.</p>
<h3>Sécuriser le cross vhost en utilisant la gestion des droits d'accès aux fichiers du noyau linux</h3>
<p>On va créer trois comptes système linux, un par VHOST</p>
<pre class="bash bash" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">#Creer les users (l'option -r signifie compte systeme, ne peut pas se connecter sur la machine)</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">useradd <span style="color: #660033;">-r</span> vhost</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">useradd <span style="color: #660033;">-r</span> vhost1</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">useradd <span style="color: #660033;">-r</span> vhost2</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">#mettre vhost1 et vhost2 dans le groupe vhost (ils auront ainsi un acces lecture et exécution)</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">usermod <span style="color: #660033;">-a</span> <span style="color: #660033;">-G</span> vhost vhost1</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">usermod <span style="color: #660033;">-a</span> <span style="color: #660033;">-G</span> vhost vhost2</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">#leur donner les dossiers</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> vhost:vhost <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>vhost.tinad.fr</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> vhost1:vhost1 <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>vhost1.tinad.fr</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> vhost2:vhost2 <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>vhost2.tinad.fr</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">#Installer un module apache qui permet de définir l'user linux utilisé pour le vhost:</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> apache2-mpm-itk</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">#on autorise le groupe et l'user seulement:</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> <span style="color: #000000;">750</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>vhost<span style="color: #000000; font-weight: bold;">*</span></div></li></ol></pre>
<p>On modifie à nouveau les fichiers de configuration des vhost comme ceci.</p>
<pre>
<VirtualHost *:80>
ServerName vhost2.tinad.fr
DocumentRoot /var/www/vhost2.tinad.fr
<IfModule mpm_itk_module>
AssignUserId vhost2 vhost2
</IfModule>
</VirtualHost>
</pre>
<p>idem pour les 2 autres vhost en remplaçant par le bon user linux, le bon serverName et le bon DocumentRoot.</p>
<p>Résultat:
<a href="https://blog-du-grouik.tinad.fr/public/lesitecoisinfail.jpg" title="lesitecoisinfail.jpg"><img src="https://blog-du-grouik.tinad.fr/public/.lesitecoisinfail_m.jpg" alt="lesitecoisinfail.jpg" style="display:block; margin:0 auto;" title="lesitecoisinfail.jpg, mar. 2011" /></a></p>
<p>Voila, on n'a plus accès aux sites voisins, et un acces en lecture/execution uniquement des exécutables. ça fait plus rigoureux.</p>
<h2>Organisation des fichiers:</h2>
<p>Dans les dossiers des vhost clients, (vhost1.tinad.fr et vhost2.tinad.fr)</p>
<p>je dépose juste un index.php ce cette manière, façon dotclear<sup>[<a href="https://blog-du-grouik.tinad.fr/post/2011/03/14/Creer-une-application-multi-Vhost#pnote-856-2" id="rev-pnote-856-2">2</a>]</sup>:</p>
<pre class="php php" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;"><?php</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #666666; font-style: italic;">//Un identifiant qui permet au programme de savoir à quel site il a à faire </span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">(</span><span style="color: #0000ff;">'intra_id'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'0'</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #666666; font-style: italic;">//On renvoit tout ensuite sur l'application en elle meme</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #b1b100;">require</span> <a href="http://www.php.net/dirname"><span style="color: #990000;">dirname</span></a><span style="color: #009900;">(</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">)</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vhost.tinad.fr/prepend.php'</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">?></span></div></li></ol></pre>
<p>Et ensuite dans le prepend.php, le code du site se déroule normalement. Il va y avoir une petite galère avec ce système. Toutes les URL doivent passer par par index.php. Les css, le js, les images et les validations de formlaires.
CSS et image, perso j'ai ajouté sur chaque vhost fait un lien symbolique en plus de l'index.php.</p>
<p>Pour le js. Je le génère directement dans le code html, pas de link. Le framework en lui même n'a pas de javascript. Par contre les différents modules oui... je présente au navigateur uniquement le JS qui sert au module (la partie de l'application) en cours d'affichage.</p>
<p>Pour la validation des formulaires, Pareil, je pique la méthode dotclear.</p>
<pre class="php php" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;"><?php</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">function</span> xd_check_input<span style="color: #009900;">(</span><span style="color: #000088;">$id</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">)</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #666666; font-style: italic;">/*</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;"> *On génére un hash aléatoire qui sera </span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;"> *ajouté aux formulaires, afin d'ajouter </span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;"> *une vérification supplémentaire</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;"> *lors du traitement de ce dernier</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;"> */</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #b1b100;">if</span><span style="color: #009900;">(</span><span style="color: #339933;">!</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">(</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'xd_check'</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #666666; font-style: italic;">//le générer</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'xd_check'</span><span style="color: #009900;">]</span><span style="color: #339933;">=</span>rand_str<span style="color: #009900;">(</span><span style="color: #cc66cc;">25</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">}</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span><span style="color: #000088;">$id</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">)</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">"<input type=<span style="color: #000099; font-weight: bold;">\"</span>hidden<span style="color: #000099; font-weight: bold;">\"</span> name=<span style="color: #000099; font-weight: bold;">\"</span>xd_check<span style="color: #000099; font-weight: bold;">\"</span> id=<span style="color: #000099; font-weight: bold;">\"</span>xd_check<span style="color: #000099; font-weight: bold;">\"</span> value=<span style="color: #000099; font-weight: bold;">\"</span>"</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'xd_check'</span><span style="color: #009900;">]</span><span style="color: #339933;">.</span><span style="color: #0000ff;">"<span style="color: #000099; font-weight: bold;">\"</span>>"</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">}</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #b1b100;">else</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">"<input type=<span style="color: #000099; font-weight: bold;">\"</span>hidden<span style="color: #000099; font-weight: bold;">\"</span> name=<span style="color: #000099; font-weight: bold;">\"</span>xd_check<span style="color: #000099; font-weight: bold;">\"</span> value=<span style="color: #000099; font-weight: bold;">\"</span>"</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'xd_check'</span><span style="color: #009900;">]</span><span style="color: #339933;">.</span><span style="color: #0000ff;">"<span style="color: #000099; font-weight: bold;">\"</span>>"</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">}</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">}</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">?></span></div></li></ol></pre>
<p>La function précédente me permet de générer facilement un input que je place dans chaque formulaire.</p>
<p>Ainsi, je peux détecter au tout début du code avant même le premier header, si un formulaire est soumis:</p>
<pre class="php php" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">//sousmission d'un formulaire</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">(</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'xd_check'</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #666666; font-style: italic;">//vérifier le numero de formulaire</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span><span style="color: #009900;">(</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'xd_check'</span><span style="color: #009900;">]</span><span style="color: #339933;">!=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'xd_check'</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span> AND <span style="color: #009900;">(</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'xd_check'</span><span style="color: #009900;">]</span> <span style="color: #339933;">!=</span><span style="color: #0000ff;">""</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> erreur <span style="color: #009900;">(</span><span style="color: #0000ff;">'Validation du formulaire incorrecte'</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">}</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #666666; font-style: italic;">//C'est ok, on envoie vers le code qui gere les formulaires</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">(</span><span style="color: #000088;">$modules</span><span style="color: #009900;">[</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'menu'</span><span style="color: #009900;">]</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #b1b100;">require_once</span> <span style="color: #009900;">(</span>engine_path<span style="color: #339933;">.</span><span style="color: #0000ff;">"/"</span><span style="color: #339933;">.</span><span style="color: #000088;">$modules</span><span style="color: #009900;">[</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'menu'</span><span style="color: #009900;">]</span><span style="color: #009900;">]</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'path'</span><span style="color: #009900;">]</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/_act.php'</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">}</span> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">}</span></div></li></ol></pre>
<p>Ce qui est pratique, c'est que du coup, je n'ai pas à gerer de redirection, les modifications engendrées par la validation du formulaire seront prises en compte immédiatement.</p>
<h3>Les données de chaque groupe</h3>
<p>Elles sont soit dans la base de données, soit, si c'est un fichier dans un dossier qui est sur leur propre Vhost. J'avais fait une <a href="https://blog-du-grouik.tinad.fr/post/2010/03/09/envoyer-un-fichier-au-navigateur-en-php">explication de la technique pour les protéger d'un accès direct par leur URL</a>.</p>
<h3>L'organisation en framework</h3>
<p>La racine du vhost principal contient</p>
<ul>
<li>index.php</li>
<li>Un fichier php contrenant la liste des modules, noms, path, état actif ou non.</li>
<li>Un dossier inc pour toutes les functions, images etc... propre au framework et les objets communs à tous les modules</li>
<li>Un dossier par module.</li>
</ul>
<p>Chaque dossier de module contient:</p>
<ul>
<li>_act.php les actions générées suite à la validation des formulaires</li>
<li>_index.php l'affichage utilisateur</li>
<li>_js.js Le code javascript propre au module (il sera placé par le framework dans le header de la page)</li>
<li>_logo.png Bah pour le menu, le logo du module.</li>
</ul>
<h3>Conclusion.</h3>
<p>C'est brouillon hein? Mais je suis reparti de cette manière, je recode tout dans ce principe, c'est fastidieux, mais quand ce sera fini, je serai sur une meilleure base pour tous les développements qui attendent, et pour une version multisite.</p>
<div class="footnotes"><h4>Notes</h4>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2011/03/14/Creer-une-application-multi-Vhost#rev-pnote-856-1" id="pnote-856-1">1</a>] Cherchez pas, je les effacerai avant de publier ce billet.</p>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2011/03/14/Creer-une-application-multi-Vhost#rev-pnote-856-2" id="pnote-856-2">2</a>] Ça sert à ça aussi le logiciel libre, partager des méthodes de codage</p></div>
Créer une passerelle avec les IPtables, puis cache DNS et DHCP Debian lenny et squeezeurn:md5:bc2f49cf5862d82a4b7d9d29643a072e2011-02-06T23:56:00+01:002017-04-10T14:02:20+02:00gniearkServeurs http web et autresdebianDNSLogiciel-libreRéseauserveurTutoriel-mémo <p>Ça fait longtemps que j'ai mis ça en place au travail, rien de bien neuf.</p>
<p>Commençons par lister les intérêts d'installer une passerelle sur un serveur, et non simplement d'utiliser une box ou un rooter avancé:</p>
<ul>
<li>Certains éléments pourront être greffés sur cette passerelle. L'idéal pour un serveur smtp, c'est d'être sur la passerelle, il filtrera comme ça le port 25. Pareil pour un petit serveur web, c'est sa place idéale<sup>[<a href="https://blog-du-grouik.tinad.fr/post/2011/02/26/Cr%C3%A9er-une-passerelle-avec-les-IPtables-Debian-5#wiki-footnote-1" id="rev-wiki-footnote-1">1</a>]</sup></li>
<li>Installer un proxy</li>
<li>Faciliter la supervision des flux. Vous monitorez vos modems et rooters vous? un serveur linux, c'est plus simple</li>
<li>Pouvoir aller plus loin dans les règles de filtrage.</li>
<li>Un accès SSH sur la passerelle avec clé et pas mot de passe, vous donne une porte entièrement sécurisée sur votre LAN de l'extérieur.</li>
<li>Pour le coté geek, et le plaisir du Do It Yourself</li>
</ul>
<p>Pour la rédaction de ce billet, le réseau est virtuel, dans des virtualbox. <a href="https://blog-du-grouik.tinad.fr/post/2011/01/27/Debian-lenny-Activer-une-seconde-carte-r%C3%A9seau.">L'installation du serveur avec deux cartes réseau est expliquée dans le billet précédent</a>.</p>
<p>Voici un schéma de principe:
<img src="https://blog-du-grouik.tinad.fr/public/.lan-avec-passerelle_m.jpg" alt="lan-avec-passerelle.jpg" style="display:table; margin:0 auto;" title="lan-avec-passerelle.jpg, janv. 2011" /></p>
<p>Le modem est en mode router, il a une IP locale: 192.168.0.254</p>
<p>Le serveur passerelle a deux cartes réseau:</p>
<ul>
<li>eth0, qui est reliée au modem a l'adresse IP 192.168.0.1</li>
<li>eth1 qui est relié au LAN a l'adresse IP 192.168.1.1</li>
</ul>
<p>Les équipements du LAN on des IP qui commencent par 192.168.0.</p>
<h2>Configurer les adresses ip de la passerelle:</h2>
<p>Editer /etc/network/interfaces comme ceci:</p>
<pre>
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
#les interfaces démarrées lors du boot du systeme
auto lo eth0 eth1
# The loopback network interface
iface lo inet loopback
#carte dans le LAN
iface eth0 inet static
address 192.168.0.1
netmask 255.255.255.0
gateway 192.168.0.254
#carte vers le modem
iface eth1 inet static
address 192.168.1.1
netmask 255.255.255.0
</pre>
<p>Pour appliquer les changements:</p>
<pre class="brush: bash">/etc/init.d/networking restart</pre>
<p>Dans les réseaux de classe C, les équipements n'écoutent que les communications provenant d'une IP de la même tranche. Ces différentes tranches d'IP constituent des VLANS. Notre passerelle a deux pattes, une dans chaque VLAN, celui constitué par la box et elle même, et celui qui contient les ordinateurs. C'est elle qui permettra de faire le lien, encore faut-il lui dire de le faire.</p>
<h2>Passerelle</h2>
<h3>Un premier script Iptables pour en faire une passerelle (passoire).</h3>
<p>IPtables, en plus de savoir filtrer en entrée ou en sortie des paquets, a aussi des fonctions NAT.</p>
<p>Voici le script de base:</p>
<pre class="brush: bash">#!/bin/bash
# Vider les tables actuelles
iptables -t filter -F
iptables -t filter -X
iptables -t nat -F
iptables -t nat -X
echo - Vidage : [OK]
#activer le forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
#lui demander de transmettre via eth0
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE
echo - Autoriser le forwarding : [OK]</pre>
<p>Enregistrez le dans le fichier /etc/init.d/firewall,</p>
<p>Le rendre exécutable et le lancer.</p>
<pre class="brush: bash">chmod +x /etc/init.d/firewall
/etc/init.d/firewall</pre>
<p>Sur mon petit réseau de virtualbox,
en fond la passerelle et au premier plan une xubuntu ayant le réseau configuré ainsi:</p>
<ul>
<li>Adresse: 192.168.1.3</li>
<li>Masque 255.255.255.0</li>
<li>Passerelle 192.168.1.1 (La passerelle en question)</li>
<li>DNS: 8.8.8.8</li>
</ul>
<p><img src="https://blog-du-grouik.tinad.fr/public/.Capture-30_m.jpg" alt="Capture-30.jpg" style="display:table; margin:0 auto;" title="Capture-30.jpg, fév. 2011" /></p>
<p>ça marche!</p>
<p>Tout passe, on a créé une passerelle, passoire.</p>
<h3>Un peu plus de sécurité, améliorons le script.</h3>
<p>L'objectif est de pouvoir considérer que le LAN sera une zone démilitarisée, pouvoir donc y abaisser tous les pare-feu. La passerelle devient un seul gros pare feu pour tout le LAN. Lorsqu'on a régulièrement à déployer des nouvelles applications réseau, le gain de temps ainsi est énorme.</p>
<p>Je ne vais cependant pas faire un vrai explicatif des IPtables, ce serait super long, et il existe plein de documentation sur cette technologie (pas toute jeune).</p>
<p>Je ne ferai pas mieux que <a href="http://www.gentoo-quebec.org/wiki/index.php/Utilisation_de_Iptables_comme_Firewall/Gateway" hreflang="fr">cet exemple facilement adaptable de script</a></p>
<p>Changez votre fichier firewall par celui proposé dans le lien.</p>
<p>Ajoutez juste:</p>
<pre class="brush: bash">echo 1 > /proc/sys/net/ipv4/ip_forward</pre>
<p>et les variables en début de script, je les ai défini ainsi:</p>
<pre class="brush: bash"># Interface qui est sur Internet (WAN)
WAN_IFACE="eth0"
# Interface Wireless
WLAN_IFACE="wlan0"
# Interface qui est dans votre réseau local (LAN)
LAN_IFACE="eth1"
# Adresse de votre passerelle (Firewall)
LAN_IP="192.168.0.1"
LAN_NET="192.168.1.0/24" #(Sous-réseau avec le masque 255.255.255.0)
LAN_BCAST="192.168.1.255" # (Adresse de broadcast.)</pre>
<p>Voici tel que j'ai mis ce script à cette étape: <a href="https://blog-du-grouik.tinad.fr/public/iptables/firewall.txt">firewall.txt</a></p>
<p>Notre passerelle fait à présent firewall. Pour concurrencer une box, on va ajouter un cache DNS et un serveur DHCP:</p>
<h2>Le serveur de cache DNS</h2>
<h3>Installer bind9</h3>
<pre class="brush: bash">apt-get install bind9</pre>
<h3>Configuration en cache</h3>
<p>Editez le fichier /etc/bind/named.conf.options et décommentez les lignes suivantes, en prenant soin d'y mettre des serveurs DNS (ceux de votre FAI, ou de google par exemple):</p>
<pre>
forwarders {
8.8.8.8;
8.8.4.4;
};
</pre>
<p>Et tant qu'à avoir un serveur de cache, autant en faire profiter le serveur lui meme;
Editez le fichier /etc/resolv.conf et mettez y juste la ligne suivante:</p>
<pre>
nameserver 127.0.0.1
</pre>
<h2>Le serveur DHCP</h2>
<pre class="brush: bash">apt-get install dhcp3-server</pre>
<p>Afin de choisir l'interface sur laquelle il devra écouter, editer le fichier de configuration /etc/default/isc-dhcp-server Et preciser l'interface sur laquelle il doit fonctionner. eth1 dans on cas:</p>
<pre>
INTERFACES="eth1"
</pre>
<p>Editer le fichier de configuration /etc/dhcp/dhcpd.conf
et pour ça <a href="http://doc.ubuntu-fr.org/dhcp3-server" hreflang="fr">l'exemple de ubuntu</a> est tres bien.</p>
<p>Ce qui donne dans mon cas:</p>
<pre>
##### Option generale par defaut #####
### ReSEAU ###
## Nom du serveur DHCP
server-name "debian.lan";
## Mode autoritaire (autoritaire)
authoritative;
## Masque de sous-réseau
### DOMAINE ###
## Nom du domaine
option domain-name "lan";
## Adresse IP du serveur DNS
# a remplacer par l ip de votre serveur dns ou par celle de votre fai
option domain-name-servers 192.168.1.1;
## Type de mise à jour du DNS (aucune)
ddns-update-style none;
### TEMPS DE RENOUVELEMENT DES ADRESSES ###
## par défaut en s (1 h)
default-lease-time 3600;
## maximum (2 h)
max-lease-time 7200;
### Sécurité ###
## refus(deny)/autorise(allow) les clients inconnus (refuse client inconnu)
allow unknown-clients;
## Use this to send dhcp log messages to a different log file (you also
## have to hack syslog.conf to complete the redirection).
log-facility local7;
### PXE ###
## Permet le boot réseau pour TFTP
allow bootp;
allow booting;
##### RéSEAUX #####
# # déclaration sous réseau 192.168.1.1.*
subnet 192.168.1.1 netmask 255.255.255.0 {
authoritative;
# Adresse de diffusion
option broadcast-address 192.168.1.255;
# # routeur par défaut
option routers 192.168.1.1;
# La plage ne contient qu'1 adresse ce qui empèche l'attribution sauf au client dont celle-ci est fixée.
range 192.168.1.111 192.168.1.140;
# Le fichier peut être spécifié dans la section host , il deviendra alors prioritaire sur celui-ci
filename "pxelinux.0";
# exemple de fixage d'une adresse: 68pc
host 68pc {
hardware ethernet 00:1E:58:A6:FD:C4;
fixed-address 192.168.1.122;
}
}
</pre>
<pre class="brush: bash">/etc/init.d/isc-dhcp-server restart</pre>
<h3>:Conclusion:</h3>
<p>Voila, on a les fonctions principales d'une box. Reste à faire mumuse, y ajouter un proxy, un serveur de mail, un ftp public toussa ;)</p>
<div class="footnotes"><h4>Note</h4>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2011/02/26/Cr%C3%A9er-une-passerelle-avec-les-IPtables-Debian-5#rev-wiki-footnote-1" id="wiki-footnote-1">1</a>] Enfin je trouve quand même dangereux de mettre un serveur web et un serveur e-mail sur la même machine car au moindre script PHP ayant une faille, les conséquences peuvent être dramatiques.</p></div>
Créer un flux ATOM en PHP structure encodage et format des datesurn:md5:22b1ba60798b45878254bc70dbaefecd2011-01-28T02:41:00+01:002017-04-19T17:14:07+02:00gniearkdev webPHPserveurTutoriel-mémo <p><img src="https://blog-du-grouik.tinad.fr/public/atom.jpg" alt="atom.jpg" style="float:left; margin: 0 1em 1em 0;" title="atom.jpg, janv. 2011" />Pour coder un flux RSS ou un flux ATOM sur un site, il faut d'abord savoir comment l'organiser.
Ne nous prenons pas la tête dans les normes et standards, spécifications RFC... Dotclear l'a fait. Sous forme d'un fichier de template, c'est plus facile à appréhender. Dans un premier temps j'utilise ces derniers, en ajoutant mes commentaires pour faire ce mémo. Plus loin, j'ai noté la façon de générer les dates au bon format et d'encoder le contenu des éléments du flux.</p>
<h2>Structure</h2>
<h3>l’entête</h3>
<pre class="brush: xml"><?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xml:lang="fr">
<title type="html">__LE TITRE DU FLUX ENCODÉ POUR L'XML__</title>
<subtitle type="html">__LA DESCRIPTION DU SITE ENCODÉ XML__</subtitle>
<link href="__LA PROPRE ADRESSE DE CE FLUX__" rel="self" type="application/atom+xml"/>
<link href="__L'URL DU SITE__" rel="alternate" type="text/html"> title="__LE TITRE DU SITE__"/>
<updated>__LA TOUTE DERNIERE DATE DE MODIFICATION__</updated>
<author>
<name>__L'AUTEUR__</name>
</author>
<id>L URL DU SITE</id>
<generator uri="__BAH HEU L'ADRESSE DE VOTRE SITE__">__SELFMADE__</generator></pre>
<h3>Chaque élément du flux:</h3>
<p>chaque élément du flux commence par <entry> et est cloturé par </entry></p>
<pre class="brush: xml"><entry>
<title>LE TITRE DE LELEMENT</title>
<link href="SON URL" rel="alternate" type="text/html" title="SON TITRE" />
<id>SON URL</id>
<published>DATE DE PUBLICATION</published>
<updated>LA DERNIERE DATE DE MODIFICATION</updated>
<author><name>NOM DE L'AUTEUR</name></author>
<dc:subject>SUJET, LA CHEZ DOTCLEAR ILS METTENT LA CATEGORIE</dc:subject>
<dc:subject>SUJET IDEM, UN TAG PAR EXEMPLE</dc:subject>
<content type="html">LE CONTENU</content>
<link rel="enclosure" href="URL DE L'EVENTUELLE PIECE JOINTE" length="SA TAILLE" type="SON TYPE" />
<wfw:comment>L'URL DES EVENTUELS COMMENTAIRES</wfw:comment>
<wfw:commentRss>LE FLUX DES COMMENTAIRES</wfw:commentRss>
</entry></pre>
<h3>Et on termine notre fichier par:</h3>
<pre class="brush: xml"></feed></pre>
<h2>Headers HTML</h2>
<p>Le fichier Php, apache va l'envoyer avec comme mime type "text/html", il suffit de préciser dès le début du script php:</p>
<pre class="brush: php">header('Content-type: application/atom+xml');</pre>
<h2>Le format des dates.</h2>
<p>C'est le format ATOM, et je n'ai pas trouvé comment faire en sorte que MySQL le fournisse de la bonne manière directement.
Pour récupérer le timestamp UNIX (format différent du timestamp MySQL), on fait la requête de cette manière:</p>
<pre class="brush: sql">SELECT UNIX_TIMESTAMP(createdtime) .....</pre>
<p>createdtime est le nom de la colonne.</p>
<p>En en PHP pour obtenir la date au format ATOM à partir du timestamp unix, c'est simplement comme ça:</p>
<pre class="brush: php">$DateAtom=date(DATE_ATOM, $VariableTimestampUnix);</pre>
<h2>L'encodage de l'HTML</h2>
<p>Bah oui, on fournit des éléments au format html qui est un langage balisé tout comme le XML (l'ATOM est du XML),Pour qu'il n'y ait pas de confusion, il faut modifier ça.</p>
<p>Tout ce qui se trouve dans des balises indiquant type="html" ou type="text/html" doit etre traité préalablement. La function htmlentities de PHP doit être utilisée, avec l'option ENT_QUOTES. de cette manière:</p>
<pre class="brush: xml">htmlentities($string,ENT_QUOTES);</pre>
<h2>Quelques liens:</h2>
<ul>
<li><a href="http://validator.w3.org/feed/" hreflang="fr">Le service de validation des flux du w3c</a></li>
<li>Un tuto sympa et complet, <a href="http://www.blog-nouvelles-technologies.fr/archives/2076/comment-cre%CC%81er-un-flux-atom-en-php-et-pour-quelles-raisons/" hreflang="fr">Comment créer un flux Atom en PHP, et pour quelles raisons</a>. juste dommage que l'auteur l'ait alourdi avec des explications de ce qu'est une base de donnée, et du fonctionnement du serveur LAMP. (j'ai tendance à avoir ce défaut aussi dans la rédaction de billets, vouloir tout expliquer, puis finalement à la relecture, je supprime la moitié du contenu, car en soit... public averti only).</li>
<li><a href="http://www.ietf.org/rfc/rfc4287.txt" hreflang="en">Le standard atom rfc 4287</a></li>
</ul>
<h2>Conclusion</h2>
<p>Si j'ai écrit ce billet c'est parce que j'ai mis un flux ATOM sur un site abandonné (edit de ce post en 2017)</p>
<p>Bon la structure de la base de données n'est pas un secret., voici en exemple le script PHP qui génère le flux ATOM de l'image board. Si ça peut aider de l'avoir sous les yeux.</p>
<pre class="brush: php"><?php
// by Gnieark 01/2011 http://blog-du-grouik.tinad.fr
header('Content-type: application/atom+xml');
echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xml:lang="fr">
<title type="html">Image Board Tinad</title>
<subtitle type="html">Board tinad est un image board, un site de partage de medias, francophone, sans inscription, anonyme</subtitle>
<link href="http://board.tinad.fr/atom.php" rel="self" type="application/atom+xml"/>
<link href="http://board.tinad.fr" rel="alternate" type="text/html" title="Image Board Tinad"/>
<?php
function username($string)
{
if ($string == ''){
return 'Anonyme';
}else{
return ($string);
}
}
function contenu($id,$img,$comment)
{
//je fais le choix de mettre les commentaires dans le cotenu de l'élément sur ce site
$html="<p><a href="http://board.tinad.fr/images/".$img.""><img src="http://board.tinad.fr/images/thumb-".$img."" alt="image"/></a><br />".$comment."</p>";
$rscomment=mysql_query("SELECT createdtime, media_filename, media_fileext,media_hasthumb,titre,commentaire,user_pseudo,id
FROM reponses
WHERE parent='".$id."' ORDER BY createdtime DESC");
while ($rcomment=mysql_fetch_row($rscomment))
{
$html.="<p><b>R&eacute;ponse de ".username($rcomment[6])." ".$rcomment[0]."</b></p><p>";
if ($rcomment[1]!= "")
{
$html.="<a href="http://board.tinad.fr/images/".$rcomment[1].".".$rcomment[2]."">
<img src="http://board.tinad.fr/images/thumb-".$rcomment[1].".".$rcomment[2]."" alt="img" /></a><br />";
}
$html.=$rcomment[5]."</p>";
}
return $html;
}
include ("config.php");
if (!mysql_connect($config['mysql_host'], $config['mysql_user'], $config['mysql_password'])) {
echo 'Impossible de se connecter à MySQL';
exit;
}
mysql_query("USE ".$config['mysql_database']);
//Pour récupérer la date de modification la plus récente:
$rupdtedtime=mysql_query("SELECT UNIX_TIMESTAMP(updatetime) FROM posts ORDER BY updatetime LIMIT 0,1");
$rsupdtedtime=mysql_fetch_row($rupdtedtime);
$updtedtime=$rsupdtedtime[0];
//Requete pour trouver les 20 derniers éléments
$sql="SELECT
UNIX_TIMESTAMP(createdtime), media_filename, media_fileext, titre, commentaire, id,user_pseudo, nbe_reponses, UNIX_TIMESTAMP(updatetime)
FROM
posts
ORDER BY
createdtime DESC
LIMIT 0,20";
$rs=mysql_query($sql);
?>
<updated><?php echo date(DATE_ATOM, $updtedtime);?></updated>
<author>
<name>Gnieark</name>
</author>
<id>http://board.tinad.fr/</id>
<generator uri="http://board.tinad.fr/">SELFMADE</generator>
<?php
while ($r=mysql_fetch_row($rs))
{
//Là commence l'affichage des elements:
?>
<entry>
<title>Post <?php echo $r[5]." Par ".htmlentities(username($r[6])." - ".$r[3],ENT_QUOTES); ?></title>
<link href="http://board.tinad.fr/index.php?post=<?php echo $r[5]; ?>" rel="alternate" type="text/html" title="<?php echo htmlentities($r[3]." Par ".username($r[6]),ENT_QUOTES); ?>" />
<id>http://board.tinad.fr/index.php?post=<?php echo $r[5]; ?></id>
<published><?php echo date(DATE_ATOM, $r[0]);?></published>
<updated><?php echo date(DATE_ATOM, $r[8]);?></updated>
<author><name><?php echo username($r[6]); ?></name></author>
<content type="html"><?php echo htmlentities(contenu($r[5],$r[1].".".$r[2],$r[7]),ENT_QUOTES); ?></content>
</entry>
<?php
}
?>
</feed></pre>Dotclear mot de passe QUE sur le contenu d'un billeturn:md5:c2c861a3a8fe7668231e1d58c048c7dc2010-11-07T21:28:00+01:002012-06-25T09:45:45+02:00gniearkdev webAJAXdotclearPHPTutoriel-mémo <p><img src="https://blog-du-grouik.tinad.fr/public/billet-test-la-cigale-et-l-fourmi.jpg" alt="billet-test-la-cigale-et-l-fourmi.jpg" style="display:block; margin:0 auto;" title="billet-test-la-cigale-et-l-fourmi.jpg, nov. 2010" /></p>
<p>L'image ci dessus explique tout, le désir c'est de protéger des billets par un simple mot de passe. Mais il faut que:</p>
<ul>
<li>Le billet reste listé sur le blog</li>
<li>le titre le content exerp toussa idem</li>
<li>C'est juste le contenu du billet qu'on va remplacer par un formulaire mot de passe.</li>
</ul>
<p>Ce n'est pas pour ce blog, mais pour le site du réseau d'établissement gériatriques. Ils ne souhaitent pas que les comptes rendus de réunion, qui sont mis en billets soient totalement publics. (rien de très confidentiel, au contraire, c'est simplement une crainte d'image négative)</p>
<p>Dotclear propose un système de mots de passes aux billets. Il a pour effet secondaire de faire que le billet n'est plus visible sur la page d'accueil.
Il existe aussi un pluggin <a href="http://lab.dotclear.org/wiki/plugin/prvcat/fr" hreflang="fr">prvcat</a> qui permet de de mettre un mot de passe à des catégories entières. Même effet secondaire.</p>
<p>Wordpress propose à peu près ce que je voudrai mais là c'est dotclear.</p>
<p>Voici un exemple sur le blog d'<a href="http://www.jyreflechis.com" hreflang="fr">Emma</a>:
<img src="https://blog-du-grouik.tinad.fr/public/emma-mot-de-passe.jpg" alt="emma-mot-de-passe.jpg" style="display:block; margin:0 auto;" title="emma-mot-de-passe.jpg, nov. 2010" /></p>
<p>Dans l'ordre, il faudra:</p>
<ul>
<li>Différencier les billets protégés: avec le plugin mymeta</li>
<li>Adapter le template pour que par défaut il affiche le formulaire de mot de passe.</li>
<li>Un chouilla d'ajax pour remplacer ce formulaire par le contenu du billet suite à l'authentification.</li>
<li>Un plugin dotclear made by Gnieark qui sert à n'afficher que le contenu d'un billet (si mot de passe OK)</li>
</ul>
<h2>Différencier les billets à protéger par mot de passe.</h2>
<p>Pour savoir quels billets protéger par mot de passe, j'ai choisi d'utiliser le pluggin <a href="http://www.morefnu.org/category/dc2/plugins/Mymeta" hreflang="fr">Mymeta</a>.</p>
<p>Apres avoir installé le pluggin, j'ajoute une meta de type case à cocher nommée "limited_access".</p>
<p><a href="https://blog-du-grouik.tinad.fr/public/mymeta-case-cocher.jpg" title="mymeta-case-cocher.jpg"><img src="https://blog-du-grouik.tinad.fr/public/.mymeta-case-cocher_s.jpg" alt="mymeta-case-cocher.jpg" title="mymeta-case-cocher.jpg, nov. 2010" /></a><a href="https://blog-du-grouik.tinad.fr/public/mymeta-nouveau.jpg" title="mymeta-nouveau.jpg"><img src="https://blog-du-grouik.tinad.fr/public/.mymeta-nouveau_s.jpg" alt="mymeta-nouveau.jpg" title="mymeta-nouveau.jpg, nov. 2010" /></a></p>
<p>Dans l'interface de modification d'un billet ça se présente comme ça: Une case à cocher en dessous:
<img src="https://blog-du-grouik.tinad.fr/public/.meta-dotclear_m.jpg" alt="meta-dotclear.jpg" style="display:block; margin:0 auto;" title="meta-dotclear.jpg, nov. 2010" /></p>
<h2>Adapter le template</h2>
<p>Lorsqu'un billet a l'attribut mymeta de type limited_access égal à '1', on affiche le résumé, puis une zone de mot de passe.
les fichiers qui vont nous intéresser ce sont:</p>
<ul>
<li>category.html</li>
<li>home.html</li>
<li>post.html</li>
<li>tags.html</li>
</ul>
<p>(tous les fichiers qui affichent des billets en fait).</p>
<p>Tout se fait bien évidemment dans la boucle qui affiche les billets, généralement délimtée par <tpl:Entries> et </tpl:Entries></p>
<p>Ne collez pas le code qui suit, c'est juste pour montrer comment on utilise Mymeta dans le template:</p>
<pre class="xml xml" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:MyMetaIf</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"limited_access"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">/* Inclure ici le code qui affichera la boite de mot de passe*/</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:MyMetaIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:MyMetaIf</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"limited_access"</span> <span style="color: #000066;">defined</span>=<span style="color: #ff0000;">"false"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">/* Inclure ici le code qui affichera le content d'un billet non protégé*/</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:MyMetaIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li></ol></pre>
<h3>Exemple pour post.html</h3>
<p>Ça se passe dans la partie <!\-\- # Entry with an excerpt \-\-> du fichier.
Les identifiants de la div contenu et du champs de mot de passe ont été mis pour le javascript (chapitre qui suit).</p>
<pre class="xml xml" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #808080; font-style: italic;"><!-- # Entry with an excerpt --></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:EntryIf</span> <span style="color: #000066;">extended</span>=<span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"post-excerpt"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:EntryExcerpt}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:EntryIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"post-content"</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"post-content{{tpl:EntryID}}"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:MyMetaIf</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"limited_access"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"formpassword"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><h2<span style="color: #000000; font-weight: bold;">></span></span></span>{{tpl:lang Password needed}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></h2<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><p<span style="color: #000000; font-weight: bold;">></span></span></span>{{tpl:lang You must give a password to access this area.}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></p<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><p<span style="color: #000000; font-weight: bold;">></span></span><span style="color: #000000; font-weight: bold;"><label<span style="color: #000000; font-weight: bold;">></span></span></span>{{tpl:lang Password:}} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"password"</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"password_{{tpl:EntryID}}"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">""</span> <span style="color: #000066;">tabindex</span>=<span style="color: #ff0000;">"1"</span> <span style="color: #000000; font-weight: bold;">/></span><span style="color: #000000; font-weight: bold;"></label<span style="color: #000000; font-weight: bold;">></span></span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"submit"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"ok"</span> <span style="color: #000066;">onclick</span>=<span style="color: #ff0000;">"deverouille('{{tpl:EntryID}}');"</span>;<span style="color: #000000; font-weight: bold;">/></span><span style="color: #000000; font-weight: bold;"></p<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:MyMetaIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:MyMetaIf</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"limited_access"</span> <span style="color: #000066;">defined</span>=<span style="color: #ff0000;">"false"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> {{tpl:EntryContent}}</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:MyMetaIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div<span style="color: #000000; font-weight: bold;">></span></span></span></div></li></ol></pre>
<h3>Exemple pour les autres fichiers</h3>
<p>Dans category.html, home.html, tags.html contrairement à post.html, s'il y a une description, on n'affiche pas le billet en entier juste sa description.</p>
<pre class="xml xml" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"post-content"</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"post-content{{tpl:EntryID}}"</span><span style="color: #000000; font-weight: bold;">></span></span> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #808080; font-style: italic;"><!-- # Entry with an excerpt --></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:EntryIf</span> <span style="color: #000066;">extended</span>=<span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> {{tpl:EntryExcerpt}}</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #808080; font-style: italic;"><!-- # acces limité; limited_access=1 (Mymeta) --></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:MyMetaIf</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"limited_access"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"formpassword"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><h2<span style="color: #000000; font-weight: bold;">></span></span></span>{{tpl:lang Password needed}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></h2<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><p<span style="color: #000000; font-weight: bold;">></span></span></span>{{tpl:lang You must give a password to access this area.}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></p<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><p<span style="color: #000000; font-weight: bold;">></span></span><span style="color: #000000; font-weight: bold;"><label<span style="color: #000000; font-weight: bold;">></span></span></span>{{tpl:lang Password:}} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"password"</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"password_{{tpl:EntryID}}"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">""</span> <span style="color: #000066;">tabindex</span>=<span style="color: #ff0000;">"1"</span> <span style="color: #000000; font-weight: bold;">/></span><span style="color: #000000; font-weight: bold;"></label<span style="color: #000000; font-weight: bold;">></span></span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"submit"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"ok"</span> <span style="color: #000066;">onclick</span>=<span style="color: #ff0000;">"deverouille('{{tpl:EntryID}}');"</span>;<span style="color: #000000; font-weight: bold;">/></span><span style="color: #000000; font-weight: bold;"></p<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:MyMetaIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #808080; font-style: italic;"><!-- # acces llibre; limited_access=0 ou est null (Mymeta) --></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:MyMetaIf</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"limited_access"</span> <span style="color: #000066;">defined</span>=<span style="color: #ff0000;">"false"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><p</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"read-it"</span><span style="color: #000000; font-weight: bold;">></span><span style="color: #000000; font-weight: bold;"><a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">"{{tpl:EntryURL}}"</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">"{{tpl:lang Continue reading}} {{tpl:EntryTitle encode_html="</span>1<span style="color: #ff0000;">"}}"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:lang Continue reading}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></a<span style="color: #000000; font-weight: bold;">></span></span></span>...<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></p<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:MyMetaIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:EntryIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #808080; font-style: italic;"><!-- # Entry without excerpt --></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:EntryIf</span> <span style="color: #000066;">extended</span>=<span style="color: #ff0000;">"0"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #808080; font-style: italic;"><!-- # acces limité; limited_access=1 (Mymeta) --></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:MyMetaIf</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"limited_access"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"formpassword"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><h2<span style="color: #000000; font-weight: bold;">></span></span></span>{{tpl:lang Password needed}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></h2<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><p<span style="color: #000000; font-weight: bold;">></span></span></span>{{tpl:lang You must give a password to access this area.}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></p<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><p<span style="color: #000000; font-weight: bold;">></span></span><span style="color: #000000; font-weight: bold;"><label<span style="color: #000000; font-weight: bold;">></span></span></span>{{tpl:lang Password:}} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"password"</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"password_{{tpl:EntryID}}"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">""</span> <span style="color: #000066;">tabindex</span>=<span style="color: #ff0000;">"1"</span> <span style="color: #000000; font-weight: bold;">/></span><span style="color: #000000; font-weight: bold;"></label<span style="color: #000000; font-weight: bold;">></span></span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"submit"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"ok"</span> <span style="color: #000066;">onclick</span>=<span style="color: #ff0000;">"deverouille('{{tpl:EntryID}}');"</span>;<span style="color: #000000; font-weight: bold;">/></span><span style="color: #000000; font-weight: bold;"></p<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:MyMetaIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #808080; font-style: italic;"><!-- # acces llibre; limited_access=0 ou est null (Mymeta) --></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:MyMetaIf</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"limited_access"</span> <span style="color: #000066;">defined</span>=<span style="color: #ff0000;">"false"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"post-contenu"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:EntryContent}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:MyMetaIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:EntryIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div<span style="color: #000000; font-weight: bold;">></span></span></span></div></li></ol></pre>
<h3>Fichiers de template des flux</h3>
<h4>rss2.xml</h4>
<p>La modification se fait entre les balises <description>et </description></p>
<pre class="xml xml" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><description<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:MyMetaIf</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"limited_access"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #ddbb00;">&lt;</span>p<span style="color: #ddbb00;">&gt;</span>Le contenu de ce billet est protégé par mot de passe. Rendez-vous sur le site pour le lire.<span style="color: #ddbb00;">&lt;</span>/p<span style="color: #ddbb00;">&gt;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:MyMetaIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:MyMetaIf</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"limited_access"</span> <span style="color: #000066;">defined</span>=<span style="color: #ff0000;">"false"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">{{tpl:EntryExcerpt absolute_urls="1" encode_xml="1"}}</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> {{tpl:EntryContent absolute_urls="1" encode_xml="1"}}</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:MyMetaIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></description<span style="color: #000000; font-weight: bold;">></span></span></span></div></li></ol></pre>
<h4>atom.xml</h4>
<p>La modification se fait entre les balises <content type="html">et </content></p>
<pre class="xml xml" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><content</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"html"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:MyMetaIf</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"limited_access"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #ddbb00;">&lt;</span>p<span style="color: #ddbb00;">&gt;</span>Le contenu de ce billet est protégé par mot de passe. Rendez-vous sur le site pour le lire.<span style="color: #ddbb00;">&lt;</span>/p<span style="color: #ddbb00;">&gt;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:MyMetaIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:MyMetaIf</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"limited_access"</span> <span style="color: #000066;">defined</span>=<span style="color: #ff0000;">"false"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> {{tpl:EntryExcerpt absolute_urls="1" encode_xml="1"}}</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> {{tpl:EntryContent absolute_urls="1" encode_xml="1"}}</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:MyMetaIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></content<span style="color: #000000; font-weight: bold;">></span></span></span></div></li></ol></pre>
<p>On est ok pour la partie html du template. En adaptant un peu le CSS, l'aperçu est en en-tête de ce billet.</p>
<h2>Le code javascript qui affichera le "content" du billet protégé</h2>
<p>Une fonction ajax qui appelle un script et rafraichit la div qui contient le contenu du billet.</p>
<p>A la source du dossier de template, je créée un fichier qui s'appelle password.js</p>
<p>Il contient:</p>
<pre class="javascript javascript" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #003366; font-weight: bold;">function</span> Ajx<span style="color: #009900;">(</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #003366; font-weight: bold;">var</span> request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">{</span>request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">(</span><span style="color: #3366CC;">'Msxml2.XMLHTTP'</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span><span style="color: #009900;">}</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">(</span>err2<span style="color: #009900;">)</span><span style="color: #009900;">{</span> <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">{</span>request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">(</span><span style="color: #3366CC;">'Microsoft.XMLHTTP'</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span><span style="color: #009900;">}</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">(</span>err3<span style="color: #009900;">)</span> <span style="color: #009900;">{</span><span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">{</span>request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span><span style="color: #009900;">}</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">(</span>err1<span style="color: #009900;">)</span> <span style="color: #009900;">{</span>request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><span style="color: #009900;">}</span><span style="color: #009900;">}</span><span style="color: #009900;">}</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #000066; font-weight: bold;">return</span> request<span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">}</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #003366; font-weight: bold;">function</span> deverouille<span style="color: #009900;">(</span>postid<span style="color: #009900;">)</span><span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #003366; font-weight: bold;">var</span> xhr <span style="color: #339933;">=</span> Ajx<span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> xhr.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">(</span>xhr.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">)</span><span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">(</span>xhr.<span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">200</span><span style="color: #009900;">)</span><span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">(</span>xhr.<span style="color: #660066;">responseText</span><span style="color: #339933;">==</span><span style="color: #3366CC;">"fail"</span><span style="color: #009900;">)</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">(</span><span style="color: #3366CC;">'post-content'</span> <span style="color: #339933;">+</span> postid<span style="color: #009900;">)</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">(</span><span style="color: #3366CC;">'post-content'</span> <span style="color: #339933;">+</span> postid<span style="color: #009900;">)</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'<p>Erreur de mot de passe</p>'</span><span style="color: #339933;">;</span> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">}</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">(</span><span style="color: #3366CC;">'post-content'</span> <span style="color: #339933;">+</span> postid<span style="color: #009900;">)</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span>xhr.<span style="color: #660066;">responseText</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">}</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">}</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">(</span><span style="color: #3366CC;">'post-content'</span> <span style="color: #339933;">+</span> postid<span style="color: #009900;">)</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">"<font color=<span style="color: #000099; font-weight: bold;">\"</span>#FF0000<span style="color: #000099; font-weight: bold;">\"</span>>Error code "</span> <span style="color: #339933;">+</span> xhr.<span style="color: #000066;">status</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">"</font>"</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">}</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">}</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;">}</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> xhr.<span style="color: #000066;">open</span><span style="color: #009900;">(</span><span style="color: #3366CC;">"POST"</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'./index.php?justunpost/'</span> <span style="color: #339933;">+</span> postid<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> xhr.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">(</span><span style="color: #3366CC;">"Content-Type"</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">"application/x-www-form-urlencoded"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> xhr.<span style="color: #660066;">send</span><span style="color: #009900;">(</span><span style="color: #3366CC;">"pass="</span> <span style="color: #339933;">+</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">(</span><span style="color: #3366CC;">'password_'</span> <span style="color: #339933;">+</span> postid<span style="color: #009900;">)</span>.<span style="color: #660066;">value</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">}</span></div></li></ol></pre>
<p>Dans le fichier de template _head.html, on ajoute le lien vers le nouveau script, juste apres </style>:</p>
<pre class="xml xml" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"text/javascript"</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">"{{tpl:BlogThemeURL}}/password.js"</span><span style="color: #000000; font-weight: bold;">></span><span style="color: #000000; font-weight: bold;"></script<span style="color: #000000; font-weight: bold;">></span></span></span></div></li></ol></pre>
<p>Le script fait la requete suivante pour réupérer le contenu (et uniquement le contenu, pas les header ni rien) :index.php?justunpost/' + postid où posid est l'identifiant du billet. On va donc créer un plugin dotclear qui retourne juste le contenu du billet, à condition que le mot de passe soit vérifié.</p>
<h2>Le plugin justunpost</h2>
<p>Mon premier plugin dotclear :D. Il est tout simple, mais comme je ne sais pas faire les plugins, ça m'a pris pas mal de temps.
Il sert à ce que l'URL http://www.domaine.com/index.php?justunpost/21 retourne le contenu du billet 21, à condition que la variable passée en POST ($_POST['pass']) corresponde au mot de passe.</p>
<p>Installez le tout simplement depuis le menu des extensions de dotclear.
<a href="https://blog-du-grouik.tinad.fr/public/justunpost.zip" hreflang="fr">Télécharger justunpost.zip</a></p>
<p>Il doit s'afficher dans la liste des extensions du panneau d'administration de dotclear. Allez y, pour définir un mot de passe.</p>
<p>C'est le mot de passe qu'il faudra rentrer au niveau du billet dans la partie publique du blog pour lire son contenu.</p>
<h2>Conclusion</h2>
<p>Normalement ça marche, je vais pouvoir lire la suite de l'histoire de la cigale et la fourmi.</p>
<h2>Limite de la méthode</h2>
<p>Comme le signale @PhilippeVay
Les ressources liées (photos etc....) ne sont pas protégées, on peut toujours y accéder directement par leur URL. Il n'y en aura pas sur le site en question, c'est pour ça que je le fais de cette façon.</p>
<p>Ps le site en <a href="http://rg2.tinad.fr" hreflang="fr">question est là</a></p>Diaspora: test et tutoriel d'installationurn:md5:616c324ebb610f8b1be0dfb299f05cb22010-09-26T22:40:00+02:002010-09-27T11:36:09+02:00gniearkdev webBig-BrotherdebiandiasporafacebookLogiciel-libreserveurTutoriel-mémo <p><img src="https://blog-du-grouik.tinad.fr/public/.150919-diaspora-img-jpg_55323_m.jpg" alt="diaspora" style="display:block; margin:0 auto;" title="diaspora, sept. 2010" /></p>
<p>Diaspora est un développement de 3 ou 4 étudiants informatiques qui a la prétention de corriger certains défauts de facebook dont:</p>
<ul>
<li>La maîtrise de la vie privée.</li>
<li>L'emprisonnement de vos données sur la plate forme facebook, Bah oui ils s'orientent vers un logiciel libre. chacun pourra choisir sa plate forme (le serveur l'hébergeant) Ces dernières pouvant communiquer entre elles. Il est envisageable avec ce système interopérable, des versions différentes pour s'adapter aux blogs par exemple.</li>
</ul>
<p>Depuis 10 jours un "premier jet" du code source a été publié. pas mal de bugs et de failles. Mais ils ont réussi leur coup de buzz. Et grâce à la magie de l'open source, ils vont avoir plein d'aides pour corriger tout ça.
Sur le code source que j'ai survolé vite fait (et je suis loin d'avoir la prétention de pouvoir juger):
Ils développent en ruby. D'ailleurs (vous verrez si vous tentez l'install) Ils font le choix de certaines dépendances qui sont encore béta.</p>
<p>Je me suis pris quelques notes lors de l'installation. Je les mettrai en seconde partie de ce billet. Tout d'abord quelques screens:</p>
<h2>Test de Diaspora</h2>
<p>Tout d'abord le loggin et l'inscription. On est prévenu que c'est une version test:
<a href="https://blog-du-grouik.tinad.fr/public/diaspora/disapora1.jpg" title="disapora1.jpg"><img src="https://blog-du-grouik.tinad.fr/public/diaspora/.disapora1_s.jpg" alt="disapora1.jpg" style="display:block; margin:0 auto;" title="disapora1.jpg, sept. 2010" /></a>
L'inscription ne demande pas beaucoup e renseignements. ça plait à un troll comme moi:
<a href="https://blog-du-grouik.tinad.fr/public/diaspora/diaspora-2.jpg" title="diaspora-2.jpg"><img src="https://blog-du-grouik.tinad.fr/public/diaspora/.diaspora-2_s.jpg" alt="diaspora-2.jpg" style="display:block; margin:0 auto;" title="diaspora-2.jpg, sept. 2010" /></a>
Une fois sur son compte: allez, je créée un album photo:
<a href="https://blog-du-grouik.tinad.fr/public/diaspora/diaspora-3.jpg" title="diaspora-3.jpg"><img src="https://blog-du-grouik.tinad.fr/public/diaspora/.diaspora-3_s.jpg" alt="diaspora-3.jpg" style="display:block; margin:0 auto;" title="diaspora-3.jpg, sept. 2010" /></a>
et mon mur ressemble à ça
<a href="https://blog-du-grouik.tinad.fr/public/diaspora/diaspora-4.jpg" title="diaspora-4.jpg"><img src="https://blog-du-grouik.tinad.fr/public/diaspora/.diaspora-4_s.jpg" alt="diaspora-4.jpg" style="display:block; margin:0 auto;" title="diaspora-4.jpg, sept. 2010" /></a>
Ce qui me permet de choisir mon avatar dans mes photographies:
<a href="https://blog-du-grouik.tinad.fr/public/diaspora/diaspora-5.jpg" title="diaspora-5.jpg"><img src="https://blog-du-grouik.tinad.fr/public/diaspora/.diaspora-5_s.jpg" alt="diaspora-5.jpg" style="display:block; margin:0 auto;" title="diaspora-5.jpg, sept. 2010" /></a>
Les contacts à ajouter sont sous la forme pseudo@serveur.com Bah oui, Diaspora a vocation à etre installé sur différents serveurs pouvant communiquer entre eux.</p>
<p><a "href="https://blog-du-grouik.tinad.fr/post/2010/09/25/60s-de-gnieark-et-francesca">francesca</a> m'a invité en ami.... son image est dans les "request" et par un glisser déposer je choisis où la mettre, "amis", "contacts professionnels", "ignorer". Ça c'est le truc génial on peut séparer le perso du pro (ce pourquoi j'avais lâché facebook)
<a href="https://blog-du-grouik.tinad.fr/public/diaspora/diaspora-6.jpg" title="diaspora-6.jpg"><img src="https://blog-du-grouik.tinad.fr/public/diaspora/.diaspora-6_s.jpg" alt="diaspora-6.jpg" style="display:block; margin:0 auto;" title="diaspora-6.jpg, sept. 2010" /></a></p>
<h2>Installation de la version test de diaspora</h2>
<p>Un tutoriel est là <a href="http://github.com/diaspora/diaspora/wiki/Installing-and-Running-Diaspora" hreflang="en">http://github.com/diaspora/diaspora/wiki/Installing-and-Running-Diaspora</a></p>
<h3>Prérequis</h3>
<h4>Build Tools</h4>
<p>Il était déja installé de mon coté sinon sur débian:</p>
<pre class="bash">apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> build-essential</pre>
<h4>Ruby</h4>
<pre class="bash">apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> ruby-full</pre>
<h4>Rubygems</h4>
<p>La version de rubygems dans les paquets de debian Lenny n'est pas la bonne pour Diaspora;
L'installer à partir des sources:</p>
<pre class="bash"><span style="color: #7a0874; font-weight: bold;">cd</span> ~
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>rubyforge.org<span style="color: #000000; font-weight: bold;">/</span>frs<span style="color: #000000; font-weight: bold;">/</span>download.php<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">70696</span><span style="color: #000000; font-weight: bold;">/</span>rubygems<span style="color: #000000;">-1.3</span><span style="color: #000000;">.7</span>.tgz
<span style="color: #c20cb9; font-weight: bold;">tar</span> -zxvf rubygems<span style="color: #000000;">-1.3</span><span style="color: #000000;">.7</span>.tgz
<span style="color: #7a0874; font-weight: bold;">cd</span> rubygems<span style="color: #000000;">-1.3</span><span style="color: #000000;">.7</span>
ruby setup.rb
<span style="color: #808080; font-style: italic;">#creer un lien </span>
<span style="color: #c20cb9; font-weight: bold;">ln</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>gem1<span style="color: #000000;">.8</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>gem
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <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>gem</pre>
<h4>MongoDB</h4>
<p>Il faut ajouter un dépôt suivant dans le fichier /etc/apt/sources.list pour avoir une version à jour:</p>
<pre>
deb http://downloads.mongodb.org/distros/debian 5.0 10gen
</pre>
<p>Puis l'installer:</p>
<pre class="bash">apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
apt-get update
apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> mongodb-stable</pre>
<h4>OpenSSL</h4>
<p>Il doit etre déja installé?</p>
<h4>ImageMagick</h4>
<pre class="bash">apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> imagemagick</pre>
<h4>Git</h4>
<pre class="bash">apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> git-core</pre>
<h4>Et pas mal de "librairies gem"</h4>
<p>pour Nokogiri</p>
<pre class="bash">apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> libxslt-dev libxml2-dev</pre>
<p>Les gems:<br />
Un peu plus loin dans le lancement du serveur il met un message d'erreur s'il manque une gem ou si ce n'est pas la bonne version. Pour les trouver le plus simple est d'utiliser le site <a href="http://rubygems.org/" hreflang="en">gemsruby</a></p>
<pre class="bash">gem <span style="color: #c20cb9; font-weight: bold;">install</span> pubsubhubbub
gem <span style="color: #c20cb9; font-weight: bold;">install</span> rest-client
gem redgreen
gem <span style="color: #c20cb9; font-weight: bold;">install</span> rspec-core --pre
gem <span style="color: #c20cb9; font-weight: bold;">install</span> rspec-expectations --pre
gem <span style="color: #c20cb9; font-weight: bold;">install</span> rspec-mocks --pre
gem <span style="color: #c20cb9; font-weight: bold;">install</span> rspec --pre
gem <span style="color: #c20cb9; font-weight: bold;">install</span> webrat --pre
gem <span style="color: #c20cb9; font-weight: bold;">install</span> rspec-rails -v <span style="color: #000000;">2.0</span><span style="color: #000000;">.0</span>.beta<span style="color: #000000;">.17</span> --pre
gem <span style="color: #c20cb9; font-weight: bold;">install</span> ruby-debug-base
gem <span style="color: #c20cb9; font-weight: bold;">install</span> selenium-client
gem <span style="color: #c20cb9; font-weight: bold;">install</span> saucelabs-adapter -v <span style="color: #000000;">0.8</span><span style="color: #000000;">.12</span>
gem <span style="color: #c20cb9; font-weight: bold;">install</span> selenium-rc
gem <span style="color: #c20cb9; font-weight: bold;">install</span> thin
gem <span style="color: #c20cb9; font-weight: bold;">install</span> webmock
gem <span style="color: #c20cb9; font-weight: bold;">install</span> will_paginate --pre
gem <span style="color: #c20cb9; font-weight: bold;">install</span> bundler</pre>
<h3>Installer Diaspora</h3>
<p>Se placer dans le repertoire qu'on veut puis télécharger les sources:</p>
<pre class="bash">git clone http:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>diaspora<span style="color: #000000; font-weight: bold;">/</span>diaspora.git
<span style="color: #7a0874; font-weight: bold;">cd</span> diaspora
bundle <span style="color: #c20cb9; font-weight: bold;">install</span></pre>
<p>Creer un fichier de configuration</p>
<pre class="bash"><span style="color: #c20cb9; font-weight: bold;">cp</span> config<span style="color: #000000; font-weight: bold;">/</span>app_config.yml.example config<span style="color: #000000; font-weight: bold;">/</span>app_config.yml</pre>
<p>Editer config/app_config.yml et y adapter les url et les ports à utiliser.
Puis lancer dispora de cette maniere:</p>
<pre class="bash">.<span style="color: #000000; font-weight: bold;">/</span>script<span style="color: #000000; font-weight: bold;">/</span>server</pre>
<p>Et s'y connecter avec un navigateur.</p>
<p>Mon installation là: http://www.tinad.fr:3000, je fermerai le port 3000 dès que j'aurai fini le test.</p>Modifier un élément HTML au fur et à mesure de la saisie de l'utilisateur dans un inputurn:md5:3cdf4e659c5f1e3fe18f9de48e5743b92010-09-12T17:37:00+02:002010-10-19T22:25:42+02:00gniearkdev webAJAXApachejavascriptPHPTutoriel-mémo <p>Comment faire pour adapter les options d'un select au fur et à mesure de la saisie de l'utilisateur dans un champs texte?</p>
<p>L'exemple le plus classique est le champs où on entre son code postal, et il affine la liste des villes à coté au fur et à mesure qu'on tape.<br />
On va faire ça:</p>
<iframe src="http://blog-du-grouik.tinad.fr/codespostauxtest/index.html" style="width: 100%;" scrolling=auto frameborder=1 > </iframe>
<p>Ma table codes postaux se présente de la manière suivante (<a href="https://blog-du-grouik.tinad.fr/public/codespostaux.sql" hreflang="fr">téléchargeable là</a>):</p>
<pre>
html
<table id="table_results" class="data">
<thead><tr>
<th>Field
</th><th>Type
</th><th>Null
</th><th>Key
</th><th>Default
</th><th>Extra
</th></tr>
</thead>
<tbody>
<tr class="odd">
<td class="">numero</td>
<td class="">bigint(20)</td>
<td class="">NO</td>
<td class="">PRI</td>
<td class=""><i>NULL</i></td>
<td class="">auto_increment</td>
</tr>
<tr class="even">
<td class="">cp</td>
<td class="">text</td>
<td class="">NO</td>
<td class="">&nbsp;</td>
<td class=""><i>NULL</i></td>
<td class="">&nbsp;</td>
</tr>
<tr class="odd">
<td class="">ville</td>
<td class="">text</td>
<td class="">NO</td>
<td class="">&nbsp;</td>
<td class=""><i>NULL</i></td>
<td class="">&nbsp;</td>
</tr>
</tbody>
</table>
</pre>
<p>Je souhaite que lorsque j'aurai rentré les premiers chiffres de mon code postal, il m'indique la liste des villes correspondant dans le select d'à coté.</p>
<h3>La solution c'est de l'ajax :D</h3>
<pre>[HTML]
<input type="texte" name="codepostal" id="codepostal" onkeyup="selectcp();">
<select name="ville" id="ville">
</select>
</pre>
<p>onkeyup="selectcp();" pour lui dire d'appeler cette fonction lorsque l'utilisateur lève le doigt.</p>
<p>On ajoute un script AJAX dans la page qui va lui demander de remplacer le contenu de <select name="ville" id="ville"> </select> par ce que va retourner le script php function.php. Dans l'exemple là, je lui précise une variable de type get qui correspond à ce que l'utilisateur a tapé.</p>
<ul>
<li>la fonction Ajx() sert à initier la connection ajax. elle est appelée par la function getphpelementid.</li>
<li>getphpelementid va mofifier le contenu de l'élément dont l'ID est en parametres a partir du script php indiqué dans l'url.</li>
<li>selectcp() fait juste une vérification avant d'appeller getphpelementid</li>
</ul>
<pre>[XML]
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>exemple codes postaux</title>
<script type="text/javascript">
function Ajx()
{
var request = false;
try
{request = new ActiveXObject('Msxml2.XMLHTTP');}
catch (err2)
{ try { request = new ActiveXObject('Microsoft.XMLHTTP');}
catch (err3) {
try {request = new XMLHttpRequest();}
catch (err1) {request = false;}
}
}
return request;
}
function getphpelementid(elementid,url,endvar)
{
var xhr = Ajx();
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{
if(xhr.status == 200) {
if(xhr.responseText == "deco"){
deco();
}else{
document.getElementById(elementid).innerHTML = xhr.responseText;
}
}else{
document.getElementById(elementid).innerHTML = "<font color=\"#FF0000\">Error code " + xhr.status + "</font>";
}
}
};
xhr.open("GET", url + endvar, true);
xhr.send(null);
}
function selectcp()
{
//alert('plop');
var cp = document.getElementById('codepostal').value;
//on ne teste qu'à partir de deux caracteres
if (cp.length > 1)
{
getphpelementid("ville","function.php?cp=",cp);
}
}
</script>
<body>
<h1> C'est un exemple de remplissage &agrave; la vol&eacute;e des options d'un select en HTML &agrave; partir des premiers caract&egrave;res tap&eacute; dans un champs texte.</h1>
<p>
<input type="texte" name="codepostal" id="codepostal" onkeyup="selectcp();">
<select name="ville" id="ville">
</select>
</p>
</body>
</pre>
<p>Le script php est tout simple:<br />
Modifiez les variables de connexions sql et éventuellement le nom des champs dans a requête pour l'adapter.</p>
<pre class="php php" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;"><?php</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">//connexion mysql</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$mysql_host</span><span style="color: #339933;">=</span><span style="color: #0000ff;">""</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$mysql_database</span><span style="color: #339933;">=</span><span style="color: #0000ff;">""</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$mysql_user</span><span style="color: #339933;">=</span><span style="color: #0000ff;">""</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$mysql_password</span><span style="color: #339933;">=</span><span style="color: #0000ff;">""</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span><span style="color: #339933;">!</span><a href="http://www.php.net/mysql_connect"><span style="color: #990000;">mysql_connect</span></a><span style="color: #009900;">(</span><span style="color: #000088;">$mysql_host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_password</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Impossible de se connecter à MySQL'</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">}</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">(</span><span style="color: #0000ff;">"USE "</span><span style="color: #339933;">.</span><span style="color: #000088;">$mysql_database</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$result</span><span style="color: #339933;">=</span><a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">(</span><span style="color: #0000ff;">"SELECT numero, ville FROM codespostaux WHERE cp LIKE '"</span><span style="color: #339933;">.</span><a href="http://www.php.net/mysql_real_escape_string"><span style="color: #990000;">mysql_real_escape_string</span></a><span style="color: #009900;">(</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'cp'</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span><span style="color: #339933;">.</span><span style="color: #0000ff;">"%' ORDER BY ville"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #b1b100;">while</span> <span style="color: #009900;">(</span><span style="color: #000088;">$row</span><span style="color: #339933;">=</span><a href="http://www.php.net/mysql_fetch_row"><span style="color: #990000;">mysql_fetch_row</span></a><span style="color: #009900;">(</span><span style="color: #000088;">$result</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">{</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">"<span style="color: #000099; font-weight: bold;">\n</span><option value=<span style="color: #000099; font-weight: bold;">\"</span>"</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">[</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">.</span><span style="color: #0000ff;">"<span style="color: #000099; font-weight: bold;">\"</span>>"</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">[</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">]</span><span style="color: #339933;">.</span><span style="color: #0000ff;">"</option>"</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">}</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">?></span></div></li></ol></pre>Installation red5 depuis les sourcesurn:md5:1223a66eb3929b4bbc605e90db7f8c262010-09-02T18:18:00+02:002017-06-06T12:32:41+02:00gniearkServeurs http web et autresApachedebianjavascriptRéseauserveurstreamingTutoriel-mémo <h2>Mise à jour le 01-12-2011</h2>
<p>Script de démarrage adapté aux nouvelles contraintes de débian squeeze lur les LSB (les entetes descriptives des scripts). Merci à <a href="http://www.cannibalcaniche.com/" hreflang="fr">pilami</a> pour les tests sur son serveur red5.</p>
<h2>Mise à jour le 02-09-2010</h2>
<p>Ellny souhaite créer un tchat avec webcam. L'utilisation de la webcam s'assimile à du streaming. L'idée est d'utiliser un serveur red5. Je lui piquerai son chat pour un module optionnel de tinaderp (tjs en cours de développement).
Je ne sais pas l'utiliser mais de toutes façon avant ça faut l'installer.</p>
<p>Je préférais faire un test avant dans une virtual box<sup>[<a href="https://blog-du-grouik.tinad.fr/post/2010/05/21/Installation-red5#wiki-footnote-1" id="rev-wiki-footnote-1">1</a>]</sup>, afin de déja bien voir comment ça s'utilise et se parametre.</p>
<p>Le projet red5 m'a l'air pas mal actif, du coup je n'ai pas trouvé de doc bien à jour et listant toutes les dépendances (hormis java). Preums :p</p>
<p>Je pars d'une débian 5 toute propre.</p>
<h3>Vite fait, pour le test ultérieur, installation d'un LAMP:</h3>
<p>Le red5, si je retiens cette solution, sera sur le serveur tinad qui a déja une solution LAMP bien propre.
Installer serveur Appache Mysql Php:</p>
<pre class="brush: bash">#LAMP
#metre un mot de passe root mysql
apt-get install apache2 apache2-doc mysql-server php5 libapache2-mod-php5 php5-mysql libapache2-mod-auth-mysql
#redémarrer apache (pour qu'il prenne en compte PHP qui a été installé apres):
/etc/init.d/apache2 restart</pre>
<p>Pour le moment j'en ai fini avec le serveur http, on l'utilisera plus tard lors des tests de red5.</p>
<h3>Installer red5</h3>
<h4>installation des prérequis (notamment subversion, apache ANT et une java runtime environnement)</h4>
<p>Il faut avoir les paquets non-free de débian dans la liste des sources. Si ce n'est pas le cas ajoutez les lignes suivantes dans le fichier /etc/apt/sources.list.</p>
<pre>
deb http://ftp.fr.debian.org/debian/ lenny non-free
deb-src http://ftp.fr.debian.org/debian/ lenny non-free
</pre>
<p>Puis rafraichissez la liste des paquets:</p>
<pre class="brush: bash">apt-get update</pre>
<h4>subversion, apache ANT et une java runtime environnement</h4>
<p>Je conseille le java de Sun, J'avais tenté avec open-jdk à la place de sun-java, histoire de limiter les programmes propriétaires mais ça marche mal.</p>
<pre class="brush: bash">#avec les dépendances, ça fait 449 MO de binaires supplémentares sur le disque:
apt-get install subversion dpkg-dev debhelper dh-make devscripts fakeroot sun-java6-jdk sun-java6-bin sun-java6-jre ant</pre>
<p>Bon le temps que ça installe je fais un premier tour à la cuisine, pour me chercher un café</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.Moka_steamg_t.jpg" alt="Moka_steamg.png" style="float:left; margin: 0 1em 1em 0;" title="Moka_steamg.png, mai 2010" />J'utilise une cafetière Moka d'ailleurs, le nesspresso me revenait trop cher pour ma paie de fonctionnaire cat B.</p>
<p>Bon allez, c'est fini, la suite:<br /></p>
<h3>Installer la dernière version de Red5 depuis les sources:</h3>
<pre class="brush: bash">svn co http://red5.googlecode.com/svn/java/server/tags/0_9_1 red5-0.9.1</pre>
<p>Un repertoire red5-0.9.1/ a été créé dans le repertoire courant.<br /></p>
<h4>Compiler le bouzin</h4>
<pre class="brush: bash">cd red5-0.9.1
make
make install</pre>
<h4>démarrer red5</h4>
<pre class="brush: bash">#il faut se placer dans son dossier sinon ça ne marche pas
cd /usr/lib/red5/
./red5.sh</pre>
<p>On teste à présent en se connectant au serveur sur le port 5080 (entrez dans le navigateur une adresse du genre http://XXX.XXX.XXX:5080 où XXX.XXX.XXX est l'adresse IP).
Si vous voyez la vidéo, ça marche:
<img src="https://blog-du-grouik.tinad.fr/public/.red5_m.jpg" alt="red5.jpg" style="display:table; margin:0 auto;" title="red5.jpg, mai 2010" /></p>
<p>Pour vraiment tester, allez sur "install a ready made application"</p>
<p>Puis installez oflademo par exemple. On revient sur les démos, et si vous n'êtes pas en local Remplacez "locahost" par l'IP su serveur.
wahou un extrait de toystory</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.red5-oflademo_m.jpg" alt="red5-oflademo.jpg" style="display:table; margin:0 auto;" title="red5-oflademo.jpg, sept. 2010" />
Bah c'est cool, sauf qu'il faudrait que ça marche en tache de fond. Car là des qu'on ferme le terminal ssh ou la session, red5 s'arrête.</p>
<h3>Inscrire red5 en service au démarrage:</h3>
<p>Je me base sur<a href="http://wiki.red5.org/wiki/AppServer/Startup%20Scripts" hreflang="fr"> ce script</a>, juste en modifiant le chemin de red5, et en précisant dans quel fichier il doit causer.</p>
<h4>Créer un fichier /etc/init.d/red5</h4>
<pre class="brush: bash">vi /etc/init.d/red5</pre>
<p>y coller le script suivant:</p>
<pre>
#! /bin/sh
### BEGIN INIT INFO
# Provides: red5
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: red5 server
# Description:
### END INIT INFO
# Modification Gnieark http://blog-du-grouik.tinad.fr/ mai 2010
# Send red5's verbose on a log file
#
# Author: Jake Hilton <red5@jakehilton.com>
# /etc/init.d/red5
#
# Check for missing file
RED5_DIR=/usr/lib/red5
test -x $RED5_DIR/red5.sh || exit 5
case "$1" in
start)
echo -n "Starting Red5 Service"
echo -n " "
cd $RED5_DIR
su -s /bin/bash -c "$RED5_DIR/red5.sh &" red5 >>/var/log/red5.log
sleep 2
;;
stop)
echo -n "Shutting down red5"
echo -n " "
cd $RED5_DIR
su -s /bin/bash -c "$RED5_DIR/red5-shutdown.sh &" red5 >>/var/log/red5.log
sleep 2
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
$0 start
;;
esac
</pre>
<p>Le rendre exécutable et créer un user red5 (dans le script ci dessus, red5 fonctionne avec cet user)</p>
<pre class="brush: bash">chmod +x /etc/init.d/red5
useradd red5</pre>
<p>le script s'utilise des manières suivantes:</p>
<ul>
<li>/etc/init.d/red5 start</li>
<li>/etc/init.d/red5 stop</li>
<li>/etc/init.d/red5 restart</li>
</ul>
<p>Dans mon cas, lors de la compilation il a "oublié" de copier le fichier red5-shutdown.sh qui est appelé lors d'un "/etc/init.d/red5 stop", on va le mettre:</p>
<pre class="brush: bash">cd ~/red5-0.9.1/
cp red5-shutdown.sh /usr/lib/red5/
chmod +x /usr/lib/red5/red5-shutdown.sh</pre>
<h4>Reste plus qu'à mettre un "/etc/init.d/red5 start" au démarrage:</h4>
<pre class="brush: bash">cd /etc/init.d
update-rc.d red5 defaults</pre>
<p>Voilou voila.</p>
<p>Pour les essais, j'en suis juste à tester les applications demo.
<img src="https://blog-du-grouik.tinad.fr/public/.P1010151_m.jpg" alt="P1010151.JPG" style="display:table; margin:0 auto;" title="P1010151.JPG, sept. 2010" />
waoh trop classe j'arrive à voir la webcam du pc juste à coté. :hem:
Je vais refaire du café. Y'a plus qu'à comprendre comment l'utiliser. ça sera peut être l'objet d'un prochain billet.</p>
<div class="footnotes"><h4>Note</h4>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2010/05/21/Installation-red5#rev-wiki-footnote-1" id="wiki-footnote-1">1</a>] Je ne regrette pas (troisième essai)</p></div>
Sauvegarde sur un pc distant éteind avec Backup-managerurn:md5:438a9f46a59b95f5d1d4cee288388c002010-08-01T02:48:00+02:002010-08-01T01:50:17+02:00gniearkServeurs http web et autresfedoraLogiciel-libreRéseauserveurTutoriel-mémo <p><img src="https://blog-du-grouik.tinad.fr/public/.logoback-up-mnager_m.jpg" alt="logoback-up-mnager.png" style="float:left; margin: 0 1em 1em 0;" title="logoback-up-mnager.png, août 2010" />Le but est de sauvegarder un serveur distant sur un pc qui n'a pas vocation à être allumé en permanence. L'autre objectif est aussi de se passer de la location d'un espace ftp pour entreposer des sauvegardes. l'inconvénient est le temps d'upload qui sera beaucoup plus long en cas de restauration.</p>
<p>On va faire mumuse, avec le wake on lan, openssh et backup-manager.</p>
<p>Backup-manager est composé d'un ensemble de scripts qui sous-traitent à des programmes bien communs et rodés (tar, scp, etc... etc...) C'est notamment pour ça que je l'apprécie, pas de mauvaise surprise. Il me sert depuis 2 ou 3 ans pour les serveurs linux du travail et depuis moins de temps pour le serveur qui héberge ce blog.</p>
<h2>Petit schéma de l'installation.</h2>
<p>Il alourdit la lecture de ce billet, mais ça me fait mal au cœur de l'effacer.</p>
<pre>
________
|Dedibox|
|débian |
________|
|eth 0
|IP publique:111.111.111.111
|
|
|
|IP publique:222.222.222.222
___|___
/Freebox/
--------
|
|IP locale: 192.168.0.254
|_______________________
| |ip locale 192.168.0.253 adresse mac:
| ____|___________ XX:XX:XX:XX:XX
|-------| |PC (Fédora13) |
|PC 1 | |sauvegardes |
| | |---------------|
---------
</pre>
<ul>
<li>Le serveur à sauvegarder IP notée 111.111.111.111</li>
<li>L'adresse publique du modem 222.222.222.222</li>
<li>L'IP locale du PC qui servira aux sauvegardes: 192.168.0.253 adresse mac notée: XX:XX:XX:XX:XX<sup>[<a href="https://blog-du-grouik.tinad.fr/post/2010/07/28/WOL-wake-on-lan-fedora#pnote-622-1" id="rev-pnote-622-1">1</a>]</sup></li>
</ul>
<p>Le PC1 est là juste pour faire joli et quelques tests</p>
<h2>Backup-manager</h2>
<h3>L'installer</h3>
<pre class="bash">apt-bet <span style="color: #c20cb9; font-weight: bold;">install</span> backup-manager</pre>
<h3>Configurer backup-manager</h3>
<p>Tout se passe dans le fichier <strong>/etc/backup-manager.conf</strong>. Si la lecture de l'anglais technique fait partie de vos compétences, le paramétrage ne devrait pas vous poser de soucis, car le fichier de configuration est bien documenté.<br />
On va le configurer directement, dans sa version finale. Il faudra paramétrer le wake on lan et le ssh après.</p>
<h4>Repository</h4>
<p>J'ai tout laissé par défaut. La copie locale sera mise dans /var/archives</p>
<h5>export BM_REPOSITORY_ROOT="/var/archives"</h5>
<h4>Archives</h4>
<h5>export BM_ARCHIVE_TTL</h5>
<p>Indique le "time to live"
Soit le nombre de jours dont les archives sont gardées. <sup>[<a href="https://blog-du-grouik.tinad.fr/post/2010/07/28/WOL-wake-on-lan-fedora#pnote-622-2" id="rev-pnote-622-2">2</a>]</sup>.</p>
<h5>export BM_ARCHIVE_METHOD="tarball-incremental mysql"</h5>
<p>Ce sont les méthodes de sauvegardes que j'ai choisi.</p>
<p>Un petit mot sur les avantages/inconvenants de l'incrémentiel:
Dans une stratégie de sauvegardes incrémentielles, Des sauvegardes totales (tous les fichiers) sont effectuées à une périodicité assez éloignée. Entre deux, on effectue des sauvegardes incrémentielles, qui ne prennent que les fichiers qui ont été créés ou modifiés depuis la sauvegarde précédente.</p>
<p>L'avantage de l'incrémentiel est de prendre moins de place, et par effet de cause d'être plus rapide, et donc par exemple (ce n'est pas le cas dans ce tuto) d'aller changer la bande de sauvegarde moins souvent. L'inconvénient c'est que si jamais il y aura besoin de faire une restauration, ça se passera comme ça:<br />
Restauration de la dernière sauvegarde totale puis restauration de toutes les sauvegardes incrémentielles une par une en écrasant les fichiers mois récent.
Deux inconvénients:</p>
<ul>
<li>S'il y a beaucoup d'incrémentielles, ce sera long.</li>
<li>Les fichiers qui ont été volontairement supprimés depuis la sauvegarde totale seront restaurés. ça peut paraitre bête, mais lors d'une des rare restaurations, la secrétaire de direction avait la veille passé quelques heures à faire du tri dans ses dossiers et ses fichiers. Elle a halluciné de voir tout revenir.</li>
</ul>
<h4>Encryption</h4>
<p>Je ne chiffre pas les sauvegardes, je fais simplement attention à ce qu'elles soient suffisamment protégées et laisse ce chapitre par défaut. C'est un coup à les rendre inutilisables et à perdre du temps précieux lors d'une éventuelle restauration.</p>
<h4>Backup method: tarball</h4>
<p>Même si on a mis tarball-incremental incrémental ci dessus, cette partie nous intéresse.</p>
<p>Les directives qui m'intéressent dans cette partie sont notamment:</p>
<h5>export BM_TARBALL_DIRECTORIES="/etc /home /var"</h5>
<p>Ce sont les répertoires à sauver</p>
<h5>export BM_TARBALL_BLACKLIST="/var/archives"</h5>
<p>Ce sont les répertoires à exclure.</p>
<h4>tarball-incremental</h4>
<p>ici on définie la périodicité incrémentielles/totales
J'ai laissé par défaut</p>
<h4>Backup method: MYSQL</h4>
<pre>
export BM_MYSQL_DATABASES="__ALL__"
</pre>
<p>listez ici les bases à sauver. faites comme ci dessus pour toutes les sauver.</p>
<p>Quand aux paramètres de coonnection, là j'ai eu la négligence de laisser root. mais créer un user nommé backup-manager ayant les droits en lecture seulement (suffisant pour la sauvegarde) sur toutes les tables ça donne:</p>
<pre class="sql"><span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">DATABASES</span>,<span style="color: #993333; font-weight: bold;">SELECT</span>,<span style="color: #993333; font-weight: bold;">LOCK</span> <span style="color: #993333; font-weight: bold;">TABLES</span> <span style="color: #993333; font-weight: bold;">ON</span> *.* <span style="color: #993333; font-weight: bold;">TO</span> <span style="color: #ff0000;">'backupmanager'</span>@<span style="color: #ff0000;">'localhost'</span> <span style="color: #993333; font-weight: bold;">IDENTIFIED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'secret'</span>;</pre>
<h4>Backup method: svn</h4>
<p>Non concerné</p>
<h4>Backup method: pipe</h4>
<p>Non concerné</p>
<h4>Section "UPLOAD"</h4>
<h5>export BM_UPLOAD_METHOD="scp":</h5>
<p>La méthode choisie</p>
<h5>export BM_UPLOAD_HOSTS="222.222.222.222"</h5>
<p>L'ip du serveur qui recevra les sauvegardes</p>
<h5>export BM_UPLOAD_DESTINATION="/media/dd2/saves"</h5>
<p>Le repertoire de dépot des sauvegardes sur le pc distant. Dans mon cas, c'est un disque dur dédié à ça.</p>
<h4>The SSH method</h4>
<h5>export BM_UPLOAD_SSH_USER="sauveur"</h5>
<p>l'user ssh à annoncer. on le créera plus loin</p>
<h5>export BM_UPLOAD_SSH_KEY="/root/.ssh/id_dsa"</h5>
<p>Il n'arrive pas à prendre la clé par défaut d'apres mes esais, faut lui indiquer. On la créera plus loin dans ce tuto.</p>
<h5>export BM_UPLOAD_SSH_HOSTS="222.222.222.222"</h5>
<p>L'IP publique de la freebox. Le mappage des ports sur l'interface freebox sera vue plus loin.</p>
<h5>export BM_UPLOAD_SSH_PORT="22"
export BM_UPLOAD_SSH_DESTINATION="/media/dd2/saves"</h5>
<p>dossier destinataire</p>
<h5>export BM_UPLOAD_SSH_PURGE="true"
export BM_UPLOAD_SSH_TTL="15"</h5>
<p>durée de vie des sauvegardes (je mets 15 j là dessus.)</p>
<h4>on ne s'occupe pas des méthodes suivantes</h4>
<h4>Advanced settings, use this with care.</h4>
<h5>export BM_PRE_BACKUP_COMMAND="wakeonlan -i 222.222.222.22 xx:xx:xx:xx:xx"</h5>
<p>On réveille l'ordinateur distant au démarrage de la sauvegarde.. Pas besoin de rajouter un délai. dès qu'il aura lancé la demande de wakeonlan, il compressera les donner à sauvegarder en local, avant de les envoyer. La première étape laisse le temps au pc de s'allumer tranquilou.</p>
<h5>export BM_POST_BACKUP_COMMAND="ssh sauveur@222.222.222.222 -i /root/.ssh/id_dsa halt"</h5>
<p>Eteindre la machine quand c'est fini. En théorie un simple user linux n'a pas le droit de le faire. On verra plus loin.</p>
<h2>Paramétrer la freebox pour le ssh et le wakeonlan</h2>
<ul>
<li>Cocher le "Proxy wol"</li>
<li>ajoutez une redirection du port 22 vers l'adresse IP locale du PC qui recevra les sauvegardes.</li>
</ul>
<p>Comme dans le screen ci dessous (il y a en plus le port 80 là).
<img src="https://blog-du-grouik.tinad.fr/public/.rooterfreebox_m.jpg" alt="interface paramétrage routeur freebox" style="display:block; margin:0 auto;" title="interface paramétrage rooter freebox, août 2010" /></p>
<h2>Installer wake on lan</h2>
<p>Le PC n'a pas vocation à être allumé en permanence, il faudra que le serveur l'allume lorsqu'il souhaite faire sa sauvegarde. Il n'y a pas grand chose à faire pour le wol.</p>
<h3>Pour vérifier que le pc est compatible wol</h3>
<p>Les cartes mères récentes permettent le wol. pour vérifier, le mieux est d'installer un petit tool:</p>
<pre class="bash">yum <span style="color: #c20cb9; font-weight: bold;">install</span> ethtool</pre>
<p>et lancer la commande:</p>
<pre class="bash">ethtool eth0</pre>
<p>Si on lit ce genre de trucs c'est ok:</p>
<pre>
Supports Wake-on: pumbg
Wake-on: g
</pre>
<p>Sinon, il faut aller farfouiner dans le bios pour l'activer.
Pour utiliser le wakeonlan il nous faut l'adresse mac du PC à allumer. La commande "ifconfig" (en root) vous donnera ce renseignement. Je la note XX:XX:XX:XX:XX.</p>
<h3>Test du wol en local</h3>
<p>Le pc 1 est un ubuntu.
Installer un script qui permet d'envoyer le signal magique wakeonlan</p>
<pre class="bash"><span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> wakeonlan</pre>
<p>Puis on éteind le pc fedora et on l'allume depuis PC1 en tapant :</p>
<pre class="bash">wakeonlan XX:XX:XX:XX:XX</pre>
<p>Et ça marche (le cas contraire n'est pas évoqué dans ce tuto).</p>
<h3>Le wol depuis internet</h3>
<p>Depuis la dédibox (en ssh) on tente apres avoir installé le paquet wakeonlan:</p>
<pre class="bash">wakeonlan -i <span style="color: #000000;">222.222</span><span style="color: #000000;">.222</span><span style="color: #000000;">.222</span> XX:XX:XX:XX</pre>
<p>Et ça marche (le cas contraire n'est pas évoqué dans ce tuto).</p>
<p>A ce niveau là on sait que le serveur pourra allumer le pc distant. Passons maintenant à la mise en place d'un espace de stockage sur ce pc pour y déposer les sauvegardes.</p>
<h2>openssh avec clés</h2>
<p><img src="https://blog-du-grouik.tinad.fr/public/logo_openssh.png" alt="logo_openssh.png" style="float:left; margin: 0 1em 1em 0;" title="logo_openssh.png, juil. 2010" /></p>
<h3>Créer un user unix qui sera utilisé pour les sauvegardes (sur le PC qui recevra les sauvegardes)</h3>
<p>En tant que root sur le pc qui recevra les sauvegardes:<br />
Je le nomme sauveur</p>
<pre class="bash">useradd -m -G <span style="color: #c20cb9; font-weight: bold;">users</span> -s <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>bash sauveur
<span style="color: #c20cb9; font-weight: bold;">passwd</span> sauveur</pre>
<h3>Installation et paramétrage openssh</h3>
<p>Sur l'ordinateur qui recevra les sauvegardes</p>
<pre class="bash">yum <span style="color: #c20cb9; font-weight: bold;">install</span> openssh-server</pre>
<p>éditer le fichier de configuration</p>
<pre class="bash">vi <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ssh</span><span style="color: #000000; font-weight: bold;">/</span>sshd_config</pre>
<p>Temporairement on laisse "yes" à la directive PasswordAuthentication mais "no" pour PermitRootLogin</p>
<pre>
PasswordAuthentication yes
PermitRootLogin no
</pre>
<p>Et on ajoute à la fin:</p>
<pre>
AllowUsers sauveur
</pre>
<p>Relancer le daemon ssh:</p>
<pre class="bash"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>sshd restart</pre>
<h3>Générer des clés ssh pour se connecter au compte sauveur:</h3>
<p>Sur le serveur qu'on veut sauvegarder (la dédibox), en root</p>
<pre class="bash"><span style="color: #7a0874; font-weight: bold;">cd</span> ~
<span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> -t dsa
<span style="color: #7a0874; font-weight: bold;">exit</span></pre>
<p>Laissez les valeurs par défaut quand il demande où enregistrer les fichiers. je ne mets pas de passphrase.</p>
<p>Placer la clé publique générée dans la listes de celles autorisées par "sauveur" sur le PC qui reçoit les sauvegardes.
Toujours depuis le serveur à sauvegarder:</p>
<pre class="bash">ssh-copy-<span style="color: #c20cb9; font-weight: bold;">id</span> -i ~<span style="color: #000000; font-weight: bold;">/</span>.<span style="color: #c20cb9; font-weight: bold;">ssh</span><span style="color: #000000; font-weight: bold;">/</span>id_dsa.pub sauveur<span style="color: #000000; font-weight: bold;">@</span><span style="color: #000000;">222.222</span><span style="color: #000000;">.222</span><span style="color: #000000;">.222</span></pre>
<p>Revenir sur le PC qui reçoit les sauvegardes et éditer la configuration de sshd</p>
<pre class="bash">vi <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ssh</span><span style="color: #000000; font-weight: bold;">/</span>sshd_config</pre>
<p>et mettre "no" à la directive PasswordAuthentication
Relancer le daemon ssh:</p>
<pre class="bash"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>sshd restart</pre>
<h2>Permettre au compte "sauveur" d'utiliser la commande halt</h2>
<p>J'ai fait un petit appel au secours sur<a href="http://forums.fedora-fr.org/viewtopic.php?id=49017" hreflang="fr"> le forum de fedora</a> à ce sujet. Un utilisateur utiisant l'interface graphique (et donc présent localement devant le PC?) aurait plus de droit qu'un utilisateur distant (du moins pour l'extinction).</p>
<p>En root sur le pc qui recevra les sauvegardes:</p>
<pre class="bash"><span style="color: #c20cb9; font-weight: bold;">chmod</span> u+s <span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>halt</pre>
<h2>Finaliser</h2>
<p>Il reste juste à créer les dossiers qui recevront les sauvegardes et y donner les droits au compte sauveur.
Puis il faut tester:</p>
<pre class="bash">backup-manager</pre>
<h2>Conclusion</h2>
<p>L'écriture de ce billet m'a un peu gonflé en fait. fastidieux, dur à présenter, il faut que je me trouve un plugin dotclear "sommaire" dans un billet.... boaf, allez, plus que l'introduction à refaire, chasser les fautes et publier. :D</p>
<div class="footnotes"><h4>Notes</h4>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2010/07/28/WOL-wake-on-lan-fedora#rev-pnote-622-1" id="pnote-622-1">1</a>] Je pense que si je mettais mon adresse IP et l'adresse mac ici, certains petits malins mettraient en place un script pour allumer mon pc toutes les nuits à 3h du matin.</p>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2010/07/28/WOL-wake-on-lan-fedora#rev-pnote-622-2" id="pnote-622-2">2</a>] Ici il est assez faible, 5 j seulement. Dans le centre hospitalier pour lequel je travaille, c'est 6 mois d'archives (sur bandes), car mes boulets d'utilisateurs sont capables de se rendre compte de fichiers disparus des mois après</p></div>