Commit 92645b88 authored by Sebastien Carrere's avatar Sebastien Carrere

Scripts Docker

Authentification Multiple
parent 1391b1ec
FROM ubuntu:16.04
MAINTAINER Sebastien.Carrere@toulouse.inra.fr
RUN apt-get -q update && \
DEBIAN_FRONTEND=noninteractive apt-get -yq --no-install-recommends install \
hardinfo wget patch vim gawk unzip apache2 zlib1g-dev libpng-dev libgd2-noxpm-dev build-essential && \
apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /var/www/
ENV ROOTDIR=/var/www/orthomcl-companion
COPY . $ROOTDIR
WORKDIR $ROOTDIR
#Install
RUN chown -R www-data.www-data $ROOTDIR
RUN a2enmod rewrite
RUN a2enmod cgi
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
RUN cp $ROOTDIR/site/cfg/site-docker.cfg $ROOTDIR/site/cfg/site.cfg
RUN cp $ROOTDIR/site/cfg/authentication-docker.cfg $ROOTDIR/site/cfg/authentication.cfg
RUN apt-get -q update && apt-get install -yq liberror-perl
RUN export USER=root && ./bin/int/admin_install.pl --docker
RUN cp $ROOTDIR/site/cfg/apache-docker.conf /etc/apache2/sites-available/000-default.conf
WORKDIR $ROOTDIR/site
CMD ["sh","-c","service apache2 start && /bin/bash && export USER=root"]
# README #
Outil d'aide à l'interprétation de résultats OrthoMCL
### INSTALL ###
* Dependencies
Shibboleth
blast+
FastTree
mafft
biosquid
python 2.7
mcl
scipy library (python-scipy)
#Inchlib
python-sklearn
python-numpy
python-fastcluster
* Configuration
WEBAPP: Fichier site/cfg/site.cfg
mkdir site/tmp site/data/store
sudo chown -R www-data.www-data site/tmp site/data/store
APACHE: INSTALL_DIR et HTTP_ROOT contiennent la racine du repertoire orthomcl-companion
ScriptAlias "<HTTP_ROOT>/cgi" "<INSTALL_DIR>/cgi"
RedirectMatch "^<HTTP_ROOT>-debug/*$" "https://<WEB_SERVER>/<HTTP_ROOT>/web/index_debug.html"
RedirectMatch "^<HTTP_ROOT>/*$" "https://<WEB_SERVER>/<HTTP_ROOT>/web/index.html"
#WS ORTHOMCL-COMPANION
RewriteRule ^/<HTTP_ROOT>/ws/(\w+)$ https://<WEB_SERVER>/<HTTP_ROOT>/cgi/index.cgi?$1=1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/<HTTP_ROOT>/ws/(\w+)/(\w+)/(\w+) https://<WEB_SERVER>/<HTTP_ROOT>/cgi/index.cgi?__wb_function=WebService&analysis=$1&method=$2&resource=$3&%1 [T=application/x-httpd-cgi,R=307]
<Directory "<INSTALL_DIR>">
Options +Indexes
</Directory>
<Directory "<INSTALL_DIR>/cgi">
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
</Directory>
<LocationMatch ".+/(etc|cfg|lib|bin)/">
Deny From All
Satisfy All
</LocationMatch>
* How to run tests
TESTER LE CLI-A
./bin/int/bbric_orthomcl-companion.pl --outdir test --analysis_cfg test/analysis.json --verbose
### API ###
[![Run in Postman](https://s3.amazonaws.com/postman-static/run-button.png)](https://www.getpostman.com/run-collection/f7a2fc148b2c38cc974d)
### AUTEURS ###
* sebastien.carrere@toulouse.inra.fr
* ludovic.cottret@toulouse.inra.fr
* martial.briand@angers.inra.fr
* corinne.rancurel@sophia.inra.fr
# BBRIC::OrthoMCL-Companion #
<p><div class="toc">
<ul>
<li><a href="#orthomcl-companion">BBRIC::OrthoMCL-Companion</a><ul>
<li><a href="#about">ABOUT</a></li>
<li><a href="#quickstart-with-docker">QUICKSTART WITH DOCKER</a><ul>
<li><a href="#build">BUILD</a></li>
<li><a href="#configure">CONFIGURE</a></li>
<li><a href="#create-admin-user">CREATE ADMIN USER</a></li>
<li><a href="#run-app">RUN APP</a></li>
<li><a href="#stop-app">STOP APP</a></li>
</ul>
</li>
<li><a href="#screencasts">SCREENCASTS</a></li>
<li><a href="#authors">AUTHORS</a></li>
</ul>
</li>
</ul>
</div>
</p>
## ABOUT ##
Perform OrthoMCL analyses, browse, visualise and share the results!
Nowadays, comparative genomics is a classical tool for biologists to address various scientific questions such as pathogeny determinism, bacteria host specificity, duplication and gene family expansion in a species.
The large number of available finished or draft genome sequences associated with the full automatisation of structural annotation pipelines leads to an era of high throughput comparative genomics.
Tools like OrthoMCL provide an easy way to compare tens of species at a time and build homologous gene families.
However, output results, classically a matrix with groups as lines and genes as columns, remains too raw to be interpreted by an end user without programming skills.
In order to help users in the post process of these data, we developed a web user interface that automatically extract frequently asked datasets such as core and pan proteomes, specific proteins, abundance and presence/absence matrix (aka. phylogenetic profiles).
Providing optional InterPro annotation will also lead to build tables and charts representing terms (eg : PFAM, GO) count in each previously described datasets.
Our tool uses standard formats as input and outputs to ease post-process analyses.
## QUICKSTART (Docker install)##
### PREREQUISITES ###
Install :
docker-engine (see: https://docs.docker.com/engine/installation/)
git
Apache::Htpasswd perl module
### BUILD ###
sudo bash
git clone https://framagit.org/BBRIC/orthomcl-companion.git
cd orthomcl-companion
export OC=$PWD
$OC/build.sh
### CONFIGURE ###
Persistence directory
export OC_DIR=/local/path/to/persistant/directory
Admin email adress
export OC_ADMIN=john.doe@somwhere.org
App hostname and port
export OC_HOSTNAME=myWebServer.org
export OC_PORT=3232
SMTP Config
export OC_SMTP=smtp.server.org:port
optionnal
export OC_SMTP_LOGIN=requiredlogin
export OC_SMTP_PASSWD=requiredpasswd
Run configuration shell script (will create dir/config files)
$OC/configure.sh
### CREATE ADMIN USER ###
$OC/bin/int/admin_addUser.pl --email=$OC_ADMIN --password=<azekaze-aze> --common_name='Jon Doe' --outdir=$OC_DIR/etc
### RUN APP ###
$OC/run.sh
### STOP APP ###
$OC/stop.sh
## EXPERT INSTALL ##
cd /path/to/install/directory/
git clone https://framagit.org/BBRIC/orthomcl-companion.git
cd orthomcl-companion
export OC=$PWD
cp $OC/site/cfg/site.cfg.template $OC/site/cfg/site.cfg
vi $OC/site/cfg/site.cfg
sudo bash
INFO:
Authentication
authentication_mode=file|ldap|shibboleth
> - file use htaccess file authentication : simpliest way to use orthomcl-companion
>
> - ldap and shibboleth require strong admin skills
Paths
portal_http_root=/apache/root/access/to/orthomcl-companion
portal_install_dir=/file/system/root/access/to/orthomcl-companion
portal_web_server=http://localhost
Run install
$OC/bin/int/admin_install.pl
Edit your Apache config file using $OC/site/cfg/apache.conf as a template
vi /etc/apache2/sites-available/000-default.conf
Configure SMTP server
cp $OC/site/cfg/ssmtp.cfg.template $OC/data/cfg/ssmtp.conf
vi $OC/data/cfg/ssmtp.conf
Restart Apache
service apache2 reload
Open a web browser "http://\$portal_web_server/\$portal_http_root"
## SCREENCASTS ##
[Youtube Channel](https://www.youtube.com/embed/videoseries?list=PLzmSZ1FMczfYTTeVXpEXq2t1P4zrQc_0H)
### API ###
[![Run in Postman](https://s3.amazonaws.com/postman-static/run-button.png)](https://www.getpostman.com/run-collection/f7a2fc148b2c38cc974d)
## AUTHORS ##
* sebastien.carrere@toulouse.inra.fr
* ludovic.cottret@toulouse.inra.fr
* martial.briand@angers.inra.fr
* corinne.rancurel@sophia.inra.fr
* bbric.contact@toulouse.inra.fr - [ <a href="https://bbric.toulouse.inra.fr">BBRIC Network</a> ]
File added
#!/usr/bin/perl
use strict;
use FindBin;
use lib "$FindBin::RealBin/../../lib/int/";
use lib "$FindBin::RealBin/../../lib/ext/lipmutils";
use General;
use ParamParser;
use File::Basename;
use Apache::Htpasswd;
use File::Temp;
use Data::Dumper;
require 'common.pl';
our $O_CONF;
MAIN:
{
my $user = $ENV{'USER'};
if (!defined $ENV{'USER'} && defined $ENV{'SERVER_SOFTWARE'})
{
$user = 'www-data';
}
if ($user !~ /root|www-data/)
{
die("ERROR - Must be run as root (or sudo) or www-data user\n<pre>");
}
my $o_param = New ParamParser('GETOPTLONG', \&Usage, 'email=s', 'password=s', 'common_name=s', 'outdir=s','sendmail');
$O_CONF = New ParamParser('INIT');
$O_CONF->SetBehaviour('use_substitution_table');
$O_CONF->Update("$FindBin::RealBin/../../site/cfg/site.cfg", 'O');
$O_CONF->SetSubstitution('%S', \$O_CONF->Get('portal_web_server'));
$O_CONF->SetSubstitution('%I', \$O_CONF->Get('portal_install_dir'));
$O_CONF->SetSubstitution('%H', \$O_CONF->Get('portal_http_root'));
$O_CONF->Update("$FindBin::RealBin/../../site/cfg/site.cfg", 'O');
$O_CONF->Update("$FindBin::RealBin/../../site/cfg/authentication.cfg", 'O');
my $local_cfg = undef;
$local_cfg = "$FindBin::RealBin/../../data/cfg/local.cfg" if (-e "$FindBin::RealBin/../../data/cfg/local.cfg");
$O_CONF->Update($local_cfg, 'O') if defined "$local_cfg";
$local_cfg = $ENV{'OC_DIR'} . '/data/cfg/local.cfg' if (defined $ENV{'OC_DIR'} && -e $ENV{'OC_DIR'} . '/data/cfg/local.cfg');
$O_CONF->Update($local_cfg, 'O') if defined "$local_cfg";
$local_cfg = $ENV{'OC_DIR'} . '/data/cfg/env.cfg' if (defined $ENV{'OC_DIR'} && -e $ENV{'OC_DIR'} . '/data/cfg/env.cfg');
$O_CONF->Update($local_cfg, 'O') if defined "$local_cfg";
&Sanitize();
my $file = $O_CONF->Get('authentic_file');
my $htpasswd_file = $O_CONF->Get('authentic_htpasswd_file');
my $file_basename = basename($file);
my $htpasswd_file_basename = basename($htpasswd_file);
my $file_dir = dirname($file);
if ($o_param->IsDefined('outdir'))
{
$o_param->AssertDirExists('outdir');
$file_dir = $o_param->Get('outdir');
$file = "$file_dir/$file_basename";
$htpasswd_file = "$file_dir/$htpasswd_file_basename";
}
print STDOUT "[INFO] Outfiles: $file | $htpasswd_file\n";
mkdir $file_dir unless -d $file_dir;
$o_param->AssertDefined('email');
$o_param->AssertDefined('password');
$o_param->AssertDefined('common_name');
my $email = lc($o_param->Get('email'));
if (! IsEmailValid($email))
{
die "[ERROR] - $email is not a valid email address";
}
my $password = $o_param->Get('password');
my $common_name = $o_param->Get('common_name');
my @a_users = ();
@a_users = `cut -d ':' -f1 $file` if (-s $file);
chomp @a_users;
if (grep (/^$email$/, @a_users))
{
die("\nERROR - USER $email already exists - edit $file first\n");
}
system("touch $htpasswd_file") if (!-e $htpasswd_file);
my $o_htpasswsd = new Apache::Htpasswd($htpasswd_file);
$o_htpasswsd->htpasswd($email, $password);
my $encrypted_password = $o_htpasswsd->fetchPass($email);
my $fh_out = &GetStreamOut(">$file");
print $fh_out "$email:$encrypted_password:$common_name:user:$email:/dev/null\n";
$fh_out->close;
system("chown www-data.www-data $htpasswd_file");
#
# Envoi de mail
#
my $url = __GetPublicUrl();
if ($o_param->IsDefined('sendmail'))
{
my $admin_mail = $O_CONF->Get('admin_mail');
my ($fh_mail, $mail_filename) = File::Temp::tempfile();
print $fh_mail <<END;
Subject: [OrthoMCL-Companion] New user account - $common_name
From: $admin_mail
To: $email
Cc: $admin_mail
Here are the credentials to access OrthoMCL-Companion @ $url
Login: $email
Passwd: $password
Url: $url
END
$fh_mail->close;
my $ssmtp_conf = "$FindBin::RealBin/../../data/cfg/ssmtp.conf" ;
$ssmtp_conf = $ENV{'OC_DIR'} . '/data/cfg/ssmtp.conf' if (defined $ENV{'OC_DIR'} && -e $ENV{'OC_DIR'} . '/data/cfg/ssmtp.conf');
if (-e $ssmtp_conf)
{
my $mail_cmd = "sendmail -C $ssmtp_conf -t < $mail_filename";
my $ret = system $mail_cmd;
if ($ret ne 0)
{
die("ERROR - Send mail failed");
}
}
else
{
print STDOUT "[WARNING] CAN NOT SEND EMAIL (>$ssmtp_conf< not found)\n";
print STDOUT '[MAIL CONTENT]' . `cat $mail_filename`;
}
}
else
{
print STDOUT <<END;
-------------------------------------------------------------
Here are the credentials to access OrthoMCL-Companion @ $url
Login: $email
Passwd: $password
Url: $url
-------------------------------------------------------------
END
}
exit 0;
}
sub Usage
{
print <<END;
$0 --email=<jon.doe\@somewhere.else> --password=<azekaze-aze> --common_name='Jon Doe'
END
}
#!/usr/bin/perl
use strict;
use FindBin;
use lib $FindBin::RealBin . '/../../lib/ext/lipmutils';
use ParamParser;
use General;
my $O_CONF;
my $DOCKER_INSTALL = &FALSE;
MAIN:
{
my $o_param = New ParamParser('GETOPTLONG', \&Usage, 'docker');
$DOCKER_INSTALL = &TRUE if ($o_param->IsDefined('docker'));
my $user = $ENV{'USER'};
if ($user !~ /root|www-data/)
{
die("ERROR - Install must be done as root or www-data user [$user]\n");
}
my $conf_file = $FindBin::RealBin . '/../../site/cfg/site.cfg';
die("ERROR - $conf_file not found - USE $conf_file.template to build it\n") if (!-e $conf_file);
$O_CONF = New ParamParser('INIT');
$O_CONF->SetBehaviour('use_substitution_table');
$O_CONF->Update($conf_file, 'O');
$O_CONF->SetSubstitution('%S', \$O_CONF->Get('portal_web_server'));
$O_CONF->SetSubstitution('%I', \$O_CONF->Get('portal_install_dir'));
$O_CONF->SetSubstitution('%H', \$O_CONF->Get('portal_http_root'));
$O_CONF->Update($conf_file, 'O');
my @a_install_files = `find $FindBin::RealBin/../../ -name '*.mask'`;
chomp @a_install_files;
foreach my $file (@a_install_files)
{
&Unmask($file);
}
#CRONTAB
my $crontab_file = $O_CONF->Get('portal_install_dir') . '/site/cfg/crontab.cfg';
if (-e $crontab_file)
{
system ("crontab $crontab_file");
}
#MKDIRS
my @a_dirs = (
$O_CONF->Get('datarootdir'),
$O_CONF->Get('datarootdir') . '/cfg',
$O_CONF->Get('portal_install_dir') . '/site/tmp',
$O_CONF->Get('portal_install_dir') . '/etc'
);
foreach my $dir (@a_dirs)
{
&Mkdir($dir);
}
my $fh_out = &GetStreamOut($O_CONF->Get('portal_install_dir') . '/etc/.htaccess');
print $fh_out "Require all denied\n";
$fh_out->close();
$fh_out = &GetStreamOut($O_CONF->Get('datarootdir') . '/cfg/.htaccess');
print $fh_out "Require all denied\n";
$fh_out->close();
&Dependencies($DOCKER_INSTALL);
exit 0;
}
sub Usage
{
print STDERR <<END;
$0 [--docker]
If --docker:
Automatically install dependencies
Else
Show you dependencies
END
}
sub Dependencies
{
my @a_cmd =
(
"apt-get -q update && apt-get install -yq cron at libtree-simple-perl libbio-perl-perl ncbi-blast+ sqlite liberror-perl libswitch-perl libxml-simple-perl libjson-perl libapache-session-perl libnet-ldap-perl libapache-htpasswd-perl ssmtp fasttree mafft biosquid python2.7 python-scipy python-sklearn python-numpy python-fastcluster mcl"
);
my $at_allow_cmd = 'cp /etc/at.deny /etc/at.deny.ori && grep -v "www-data" /etc/at.deny.ori > /etc/at.deny';
if ($DOCKER_INSTALL == &TRUE)
{
foreach my $cmd (@a_cmd)
{
system($cmd);
}
if (-e "/etc/at.deny")
{
system ($at_allow_cmd);
}
}
else
{
foreach my $cmd (@a_cmd)
{
print STDOUT "[DEPENDENCY] Run $cmd\n";
print STDOUT "[CONFIG] allow www-data to lauch at cmd $at_allow_cmd\n";
}
}
return;
}
sub Mkdir
{
my $dir = shift;
if (!-d $dir)
{
print "[INFO] - Create www-data directory $dir\n";
system("mkdir $dir; chown www-data.www-data -R $dir");
}
return;
}
sub Unmask
{
my $file = shift;
print "[INFO] - Load $file\n";
my $target_file = $file;
$target_file =~ s/\.mask//;
my $fh_in = &GetStreamIn($file);
my $fh_out = &GetStreamOut($target_file);
while (my $line = <$fh_in>)
{
chomp $line;
while ($line =~ /#(\w+)#/)
{
my $key = $1;
die("ERROR - $key not found in config file\n") if (!$O_CONF->IsDefined($key));
my $value = $O_CONF->Get($key);
$line =~ s/#$key#/$value/;
}
print $fh_out "$line\n";
}
$fh_in->close;
$fh_out->close;
print "[INFO] - Write $target_file\n";
return;
}
#!/bin/bash
git pull
docker version
if [ $? -eq 0 ]; then
docker build --rm=true -t bbric/orthomcl-companion .
else
echo "FAIL: docker seems not to be correctly installed - Please check the PREREQUISITES section"
fi
......@@ -3,54 +3,58 @@
use strict;
use FindBin;
use lib "$FindBin::RealBin/../lib/ext/lipmutils";
use lib "$FindBin::RealBin/../lib/int";
use Digest::MD5 qw(md5 md5_hex md5_base64);
package main;
use ParamParser;
use WebBuilder;
use General;
use GeneralBioinfo;
use Runner;
use Error qw( :try );
use LipmError;
use Data::Dumper;
use JSON;
use URI::Escape;
use File::Temp qw/ tempfile tempdir /;
use CGI;
use Data::Dumper;
use File::Basename;
use File::Copy;
use File::Temp qw/ tempfile tempdir /;
use File::Path qw(make_path);
use Digest::MD5 qw(md5_hex);
use JSON;
use DBI;
use Array::Utils;
use URI::Encode;
use Authentic;
use Authentic::ShibLdap;
use Authentic::EtcPasswd;
use Authentic::Ldap;
use Net::LDAP;
use URI::Encode;
use Apache::Htpasswd;
my $RUNNER_STDOUT = '';
my $RUNNER_STDERR = '';
my $RUNNER_LOG = '';
our $TITLE = 'orthomcl-companion';
our $ERROR_MESSAGE;
our $DEMO_URL;
our $SOURCECODE_URL;
require 'WebApp.pl';
require 'OrthomclCompanion/Utils.pl';
require 'common.pl';
use constant DEBUG => &FALSE;
use constant DEBUGWS => &TRUE;
use constant LOCALPASSWORD => &FALSE;
use constant DESC_FILE => "$FindBin::RealBin/../web/xml/portal.xml";
use constant DEBUG => &TRUE;
use constant OFFLINE_MODE => &FALSE;
use constant GENERATE_NAMES => &TRUE;
use constant COMPRESS => &FALSE;
use constant DESC_FILE => "$FindBin::RealBin/../web/xml/portal.xml";
our $O_CONF;
# Set to 0 in production
use constant MODE_TEST => 0;
our $TMPDIR = '/tmp';
MAIN:
{
......@@ -68,7 +72,7 @@ MAIN:
$o_param->Set('__wb_function', 'WSAPI') if ($o_param->IsDefined('api'));
$o_param->Set('__wb_function', 'WebService') if ($o_param->IsDefined('blastmethod'));
$o_param->Set('__wb_function', 'GetAuthentication') if ($o_param->IsDefined('authentication'));
$o_param->Set('__wb_function', 'AskAccount') if ($o_param->IsDefined('account'));
$o_param->Set('__wb_function', 'ListAnalyses') if ($o_param->IsDefined('view'));
$o_param->Set('__wb_function', 'Publish') if ($o_param->IsDefined('publish'));
$o_param->Set('__wb_function', 'Delete') if ($o_param->IsDefined('delete'));
......@@ -99,37 +103,92 @@ sub Main
{
my ($o_webparam) = @_;
$O_CONF = New ParamParser("$FindBin::RealBin/../site/cfg/site.cfg");
$O_CONF->SetBehaviour('use_substitution_table');
$O_CONF->SetSubstitution('%S', \$O_CONF->Get('portal_web_server'));