Hodei Core for Wordpress

Répertoire plugins/hdicore

create.c

#include <stdio.h>
 
int main(int argc, char *argv[])
{
     char cmd[1024];
     sprintf(cmd, "create_instance.sh", argv[1], argv[2]);
     system(cmd);
}

create_instance.sh

#!/bin/bash
#create_instance.sh
#Benjamin PERRIN
#parametre 1: instance nom du site
#Script call by appache
NORMAL="\\033[0;39m"
BLEU="\\033[1;34m"
ROUGE="\\033[1;31m"
if test -z "$1"; then
	echo -e Pas de parametre, arret du script
	exit
fi
instance=$1
version=$2
HostProd="aditu.hodei.net"
DirVirtualHost="/etc/apache2/sites-available"
FileBind="/etc/bind/db.hodei.net"
DirNimboProd="/var/www/nimboprod"
DirInstance="/$instance"
DirProd=$DirNimboProd$DirInstance
MountSshfs="/mnt"
MountInstance=$MountSshfs$DirInstance
FileConfProd="$DirProd/erp/htdocs/conf/conf.php"
#####################################
####CREATION DOSSIER######
echo "Montage reseau pour creer dossier d'instance $DirProd"
sshfs -o allow_root,default_permissions root@$HostProd:$DirNimboProd $MountSshfs >>/dev/null
if [ $? -eq 0 ]; then
	echo "Mount DirNimboProd OK"
elif [ $? -eq 1 ]; then
	echo "erreur de sshfs"
	exit
fi
if [ -d "$MountInstance" ]; then
	echo "Repertoire de l'instance deja present"
	umount $MountSshfs
	exit
else
	mkdir -p "$MountInstance" &> /dev/null
	if [ $? -eq 0 ]; then
		echo "Creation du repertoire $MountInstance"
	elif [ $? -eq 1 ]; then
		echo "Impossible de creer le repertoire $MountInstance"
		umount $MountSshfs
		exit
	fi
fi
umount $MountSshfs
echo "Copie de $version.tgz vers le serveur de prod"
scp "/var/www/nimboffice2/source/dolibarr/$version.tgz" "root@$HostProd:$DirProd"
echo "Creation du dossier erp /Extration de $version.tgz vers erp / suppression de $version.tgz"
ssh -n root@$HostProd "mkdir $DirProd/erp && touch $DirProd/index.php && tar -C $DirProd/erp -xzf $DirProd/$version.tgz $version/htdocs $version/robots.txt --strip-components=1 && rm $DirProd/$version.tgz"
######CREATION HOSTING#######"
echo "Creation du fichier de virtual host"
ssh -n root@$HostProd "cp $DirVirtualHost/example $DirVirtualHost/$instance"
ssh -n root@$HostProd <<< bash "sed -i -e 's#example#$instance#g' $DirVirtualHost/$instance "
echo "Creation de l'alias ERP"
ssh -n root@$HostProd <<< bash "sed -i '/\/VirtualHost/i\\\tALIAS /erp $DirProd/erp/htdocs' $DirVirtualHost/$instance"
echo "Activation du Vhost et rechargement d'apache"
ssh -n root@$HostProd "a2ensite $instance && /etc/init.d/apache2 reload"
######CREATION DNS#######
echo  "CREATION DU DNS" 
CheckDns=$(nslookup $instance.hodei.net | grep Name |sed -e "s/.*:\t//")
if [ "nimbo.hodei.net"=$CheckDns ]; then
	echo Entree DNS deja existante
fi
DnsSerial=$(nslookup -type=SOA hodei.net. |grep serial | sed -e "s/.*= //")
echo  "Version du fichier DNS: $DnsSerial" 
Increment=$((${DnsSerial: -2}+1))
CountIncrement=$(echo $Increment |wc -L)
if [ $CountIncrement -eq 1 ]; then
	Increment="0$Increment"
elif [ $CountIncrement -eq 3 ]; then
	Increment="01"
fi
DnsNewSerial=$(date '+%Y%m%d'$Increment)
echo  "Nouvelle version de zone: $DnsNewSerial" 
ssh -n root@$HostProd <<< bash "sed -i -e s#'$DnsSerial'#'$DnsNewSerial'#g /etc/bind/db.hodei.net"
ssh -n root@$HostProd <<< bash "echo -e '$instance\\t\\tIN\\tCNAME\\tnimbo;' >> /etc/bind/db.hodei.net"
ssh -n root@$HostProd "/etc/init.d/bind9 reload"
######DOLIBARR#########
echo  "Configuration dolibarr" 
echo  "Application des droits" 
ssh -n root@$HostProd "chown -R atmail:hodei $DirProd && chmod -R g+w $DirProd"
echo "fin de l'installation"
echo "http://$instance.hodei.net/erp"
exit

create_sandbox.sh

create_instance se base sur ce fichier :

#!/bin/bash
#duplicateprod2recette.sh
#Benjamin PERRIN
#parametre 1: instance nom du site
#Script call by appache
NORMAL="\\033[0;39m"
BLEU="\\033[1;34m"
ROUGE="\\033[1;31m"
if test -z "$1"; then
	echo -e Pas de parametre, arret du script
	exit
fi
instance=$1
SandboxHost="aditu-preprod.hodei.lan"
InstanceRecette=$instance"recette"
DirProd="/volume2/Hodei/aditu.hodei.net/var/www/nimboprod/$instance/"
if [ -d "$DirProd/erp" ]; then
	echo "repertoire erp present"
	DirProd="/volume2/Hodei/aditu.hodei.net/var/www/nimboprod/$instance/erp/"
fi
echo $DirProd
DirRecette="/var/www/$instance"
FileConfProd="$DirProd/htdocs/conf/conf.php"
SqlHost=localhost
SqlUser="root"
SqlPassword="Dolimysql!"
SqlDatabaseProd=$(sed -n "/main_db_name/ s/.*'\([^']*\)'.*/\1/p" $FileConfProd)
SqlUserProd=$(sed -n "/main_db_user/ s/.*'\([^']*\)'.*/\1/p" "$FileConfProd")
SqlPassProd=$(sed -n "/main_db_pass/ s/.*'\([^']*\)'.*/\1/p" "$FileConfProd")
UrlProd=$(sed -n "/main_url_root/ s/.*'\([^']*\)'.*/\1/p" "$FileConfProd")
UrlProd=$(echo $UrlProd |awk '{print $1}' )
UrlRecette="http://aditu-preprod.hodei.lan/$instance/htdocs/"
FileConf="$DirRecette/htdocs/conf/conf.php"
SearchDocRoot=$(sed -n "/main_document_root/ s/.*'\([^']*\)'.*/\1/p" "$FileConfProd")
SearchDocRoot=$(echo $SearchDocRoot|awk '{print $1}')
ChangeDocRoot="/var/www/$instance/htdocs"
SearchDataRoot=$(sed -n "/main_data_root/ s/.*'\([^']*\)'.*/\1/p" "$FileConfProd")
SearchDataRoot=$(echo $SearchDataRoot|awk '{print $1}')
ChangeDataRoot="/var/www/$instance/documents"
 
###### GESTION FICHIER ####
#echo "Creation du repertoire racine: $instance "
#mkdir "$DirRecette";
echo "Copie du backup de $instance vers aditu-preprod"
#scp -qr $DirProd root@aditu-preprod.hodei.lan:/var/www/$instance
rsync -e ssh -az --delete-after $DirProd root@aditu-preprod.hodei.lan:/var/www/$instance/
SqlDatabaseProd=$(sed -n "/main_db_name/ s/.*'\([^']*\)'.*/\1/p" $FileConfProd)
echo "import de la base de donnees: $SqlDatabaseProd"
bunzip2 < /volume2/Hodei/aditu.hodei.net/MysqlDump-aditu.hodei.net-$SqlDatabaseProd.bz2 | mysql -u root -pDolimysql! -h aditu-preprod.hodei.lan
mysql -u root -pDolimysql! -h aditu-preprod.hodei.lan --execute="GRANT ALL PRIVILEGES ON $SqlDatabaseProd.* TO $SqlUserProd@localhost IDENTIFIED BY 'Sandbox' WITH GRANT OPTION;FLUSH PRIVILEGES";
echo "Mise en place des droits"
ssh -nC root@aditu-preprod.hodei.lan "chown -R hodei:www-data /var/www/$instance"
ssh -nC root@aditu-preprod.hodei.lan "chmod -R g+w /var/www/$instance"
#ssh -nC root@aditu-preprod.hodei.lan "chmod -R g+w /var/www/$instance"
####### GESTION Fichier de configuration###############
echo "Mise a jour du fichier de configuration $FileConf"
#echo "sed -i -e 's#$UrlProd#$UrlRecette#g' $FileConf" | ssh -nC root@aditu-preprod.hodei.lan bash
ssh -n root@aditu-preprod.hodei.lan <<< bash "sed -i -e 's#$UrlProd#$UrlRecette#g' $FileConf"
ssh -n root@aditu-preprod.hodei.lan <<< bash "sed -i -e 's#$SearchDocRoot#$ChangeDocRoot#g' $FileConf"
ssh -n root@aditu-preprod.hodei.lan <<< bash "sed -i -e 's#$SearchDataRoot#$ChangeDataRoot#g' $FileConf"
ssh -n root@aditu-preprod.hodei.lan <<< bash "sed -i -e 's#$SqlPassProd#Sandbox#g' $FileConf"
exit

hdi_customplugins.php

/*
Plugin Name: Hodei Core for Wordpress
Plugin URI: http://www.hodei.net/fr
Description: Ce plufgins redefinis les fonctions de wp-includes/pluggable.php
Author: Francis MILHAU
Version: 1.0
Author URI: http://www.hodei.net/fr
*/
 
/*
 ==============================================================================
Nom              : hdi_customplugins.php
Langage          : PHP 5.3
Auteur           : dev@hodei.net
Date de creation : 2015-05-17
Description      : Plugin wordpress generique
------------------------------------------------------------------------------
Modification    : FS#471 - 2015-05-17 - dev@hodei.net : Création du plugin
 
==============================================================================
*/
 
// --------------------------------------------------------------------------------------
//  Redefinir la fonction wp_new_user_notification
// --------------------------------------------------------------------------------------
// Redefine user notification function
if ( !function_exists('wp_new_user_notification') )
{
	function wp_new_user_notification( $parameter, $plaintext_pass = '' )
	{
		//echo "<br>".$parameter;
		//$user = new WP_User( $parameter );
 
		//$user_login = stripslashes( $user->user_login );
		//$user_email = stripslashes( $user->user_email );
 
		$other = explode(";",$parameter); 
		$user_login = $other[0]; 
		$user_prenom = $other[1];
		$user_email = stripslashes($other[2]);   
		$user_company = $other[3];
		$user_instance = $other[4];
		$user_passwd = $other[5];
 
//echo "<br>**".$user_email."**";
		$message  = sprintf( __('Nouvelle inscription on %s:'), get_option('blogname') ) . "\r\n\r\n";
		$message .= sprintf( __('Username: %s'), $user_login ) . "\r\n\r\n";
		$message .= sprintf( __('E-mail: %s'), $user_email ) . "\r\n";
 
		$headers = array('Content-Type: text/html; charset=UTF-8');
		//$cr = "\r\n";
		$cr = "<br>";
 
		@wp_mail(get_option('admin_email'),
				 sprintf(__('[%s] Nouvelle inscription'), get_option('blogname') ),
				 $message);
//echo "<br>".get_option('admin_email');
		if ( empty( $plaintext_pass ) )
			return;
 
		$link = "support@hodei.net";
		$url = "http://" . $user_instance . ".hodei.net/erp";
 
		$message  = sprintf( __("Bonjour %s %s,"), $user_prenom, $user_login ) . $cr.$cr;
		$message .= sprintf( __("Bienvenue dans le cloud d'<b>Hodei</b>.")) . $cr;
		$message .= sprintf( __("Nous vous proposons un service en ligne de l'application Dolibarr pendant 15 jours.")) . $cr;
		$message .= sprintf( __("Voici le détail des informations pour y accéder")) .  $cr.$cr;
 
		$message .= sprintf( __("<b>Votre application Dolibarr</b>")) . $cr;
		$message .= sprintf( __("<ul>"));
		$message .= sprintf( __("<li>Url : %s</li>"), $url );
		$message .= sprintf( __("<li>Username : %s</li>"), $user_login );
		$message .= sprintf( __("<li>Password : %s</li>"), $user_passwd );
		$message .= sprintf( __("</ul>"));
		$message .= $cr;
 
		$message .= sprintf( __("<b>Votre compte hodei</b>")) . "\r\n\r\n";
		$message .= sprintf( __("<ul>"));
		$message .= sprintf( __("<li>Url : %s</li>"), "http://hodei.hodei.net/erp" );
		$message .= sprintf( __("<li>Username : %s</li>"), $user_email );
		$message .= sprintf( __("<li>Password : %s</li>"), $plaintext_pass );
		$message .= sprintf( __("</ul>"));
		$message .= $cr;
 
		$message .= sprintf( __("Si vous avez des problèmes pour vous connecter, contactez-nous à l'adresse %s."), $link );
		$message .= $cr.$cr;
 
		$message .= sprintf(__("Cordialement")) . $cr;
		$message .= sprintf(__("L'équipe d'Hodei")) . $cr;
 
		$bool = wp_mail($user_email,
						sprintf( __("Bienvenue sur dolibarr dans le cloud d'Hodei")),
						$message,
						$headers);
 
//echo "<br>".$bool;
	}
}
 
/*
 function custom_login()
 {
$creds = array();
$creds['user_login'] = 'example';
$creds['user_password'] = 'plaintextpw';
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) )
	echo $user->get_error_message();
}
 
// run it before the headers and cookies are sent
add_action( 'after_setup_theme', 'custom_login' );
*/

hdi_inscription.js

/*
Vous remarquerez au passage qu’il n’y a pas de champ de validation de mot de passe. 
J’utilise un autre technique qui consiste à pouvoir afficher le mot de passe si l’utilisateur 
souhaite le vérifier. Cette petite astuce à également besoin de javascript pour switcher le type 
de l’input entre password et text.
*/
 
jQuery( document ).ready( function($) 
{
	$( '#register-user' ).on( 'submit', function(e) 
		{
 
		$( this ).find( 'input:required' ).each( function() 
		{
			// On vérifie si les input requis sont remplis
			if ( $( this ).val().trim() == '' ) 
			{
				e.preventDefault();
				$( this ).addClass( 'error' );
			}
		} );
 
		$( this ).find( 'input[type="email"]' ).each( function() 
		{
			// Regex pour vérifier le champ email
			var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
			if ( ! pattern.test( $( this ).val() ) ) 
			{
				e.preventDefault();
				$( this ).addClass( 'error' );
			}
		} );
 
	} );
 
	// Toggle hidden password
	$('#show-password').on('change', function() 
	{
		if ($(this).is(':checked')) 
		{
			changeType( $( '#pass-user' ), 'text' );
		} 
		else 
		{
			changeType( $( '#pass-user' ), 'password' );
		}
	} );
 
	// Cette fonction met à jour 'instance' a partir de 'societe'
	$('#company-user').on('change', function() 
	{
		//$(this).attr({value : $('#company-user').val});
		var valeur = $('#company-user').val();
		//alert(valeur);
		$('#instance-user').val(valeur);  
	} );
 
	// Cette fonction permet de changer un type text et type password
	// Se referer à http://codepen.io/CreativeJuiz/pen/cvyEi/
	// ... et https://gist.github.com/3559343 pour comprendre
	function changeType(x, type) 
	{
		if(x.prop('type') == type)
			return x;
		try 
		{
			return x.prop('type', type);
		} 
		catch(e) 
		{
			var html = $("<div>").append(x.clone()).html();
			var regex = '/type=(\")?([^\"\s]+)(\")?/';
			var tmp = $(html.match(regex) == null ?
				html.replace(">", ' type="' + type + '">') :
				html.replace(regex, 'type="' + type + '"') );
			tmp.data('type', x.data('type') );
			var events = x.data('events');
			var cb = function(events) 
			{
				return function() 
				{
					for(i in events)
					{
						var y = events[i];
						for(j in y)
							tmp.bind(i, y[j].handler);
					}
				}
			}(events);
			x.replaceWith(tmp);
			setTimeout(cb, 10);
			return tmp;
		}
	}
} );

hdi_inscription2.js

/*
 Ce fichier permet de gérer la modification du profil qd le user n'a pas accer au front office
 
 Ici nous allons réutiliser le même javascript qu’à l’inscription 
 (les fonctions sont identiques, autant les reprendre). Il suffit donc d’ajouter l’écouteur d’évènement sur 
 l’id de ce nouveau formulaire, et s’assurer qu’il soit également enqueue dans la fonction. 
*/
jQuery( document ).ready( function($) 
{
	$( '#register-user, #update-utilisateur' ).on( 'submit', function(e) {
 
		$( this ).find( 'input:required' ).each( function() {
			// On vérifie si les input requis sont remplis
			if ( $( this ).val().trim() == '' ) {
				e.preventDefault();
				$( this ).addClass( 'error' );
			}
		} );
 
		$( this ).find( 'input[type="email"]' ).each( function() {
			// Regex pour vérifier le champ email
			var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
			if ( ! pattern.test( $( this ).val() ) ) {
				e.preventDefault();
				$( this ).addClass( 'error' );
			}
		} );
 
	} );
 
	// Toggle hidden password
	$( '#show-password' ).on( 'change', function() {
		if ( $( this ).is( ':checked' ) ) {
			$( '#pass-user' ).attr( 'type', 'text' );
		} else {
			$( '#pass-user' ).attr( 'type', 'password' );
		}
	} );
} );

hdi_message.js

jQuery( document ).ready( function($)
{
	if ( $( '.message' ).length > 0 ) 
	{
		setTimeout( function() 
		{
			$( '.message' ).remove();
		}, 6000 );
	}
 
} );

hdi_style.css

.message
{
	position:fixed;
	top:20%;
	left:10%;
	width:80%;
	background-color:#FFF;
	color:#000;
	padding:1em;
	-webkit-box-sizing:border-box;
	-moz-box-sizing:border-box;
	box-sizing:border-box;
}
 
/*  */
 
table.tableau 
{
	border: 0;
	/*border-collapse:collapse;*/
	/*background:#EFF4FB url(http://www.roscripts.com/images/teaser.gif) repeat-x;*/
	/*border-left:1px solid #686868;*/
	/*border-right:1px solid #686868;*/
	font:0.8em/145% arial,verdana;
	color: #333;
}
 
td.tableau, tr.tableau 
{
 
}

Navigation

QR Code
QR Code systeme_informatique:site_web:widget:hdi_core (generated for current page)