Evoadmin-web is now a "public project".
This commit is contained in:
commit
48eb1c16b1
55 changed files with 10530 additions and 0 deletions
3
INSTALL
Normal file
3
INSTALL
Normal file
|
@ -0,0 +1,3 @@
|
|||
* Ajouter l'utilisateur qui fait tourner l'application dans le groupe shadow
|
||||
* Ajouter les autorisations sudo nécessaires
|
||||
* Désactiver les magic quotes de PHP
|
339
LICENSE
Normal file
339
LICENSE
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
|
||||
Copyright (C) 2013 Benoît.S
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
{signature of Ty Coon}, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
72
README-CLUSTER.md
Normal file
72
README-CLUSTER.md
Normal file
|
@ -0,0 +1,72 @@
|
|||
INSTALLATION & CONFIGURATION EVOADMIN EN MODE CLUSTER
|
||||
=====================================================
|
||||
|
||||
|
||||
1. Infra type à mettre en place
|
||||
-------------------------------
|
||||
|
||||
.---.
|
||||
| | adm
|
||||
'-.-'
|
||||
.------------+------------.
|
||||
v v v
|
||||
.---. .---. .---.
|
||||
| | www00 | | www01 | | wwwnn
|
||||
'---' '---' '---'
|
||||
|
||||
* adm : machine hébergeant evoadmin-cluster. Doit pouvoir se connecter en
|
||||
root sur tous les frontaux ;
|
||||
|
||||
* wwwXX : frontaux configurés en tant que pack-web/pack-mail.
|
||||
|
||||
|
||||
2. Configuration sur la machine d'admin
|
||||
---------------------------------------
|
||||
|
||||
* Récupérer le code ;
|
||||
* Créer le virtual host pointant dans htdocs/ ;
|
||||
* Initialiser la base de données SQLite :
|
||||
* copier le contenu de scripts/ du dépôt dans /usr/share/scripts/evoadmin/.
|
||||
|
||||
3. Configuration des frontaux
|
||||
-----------------------------
|
||||
|
||||
* Configurer un pack-web et pack-mail+evoadmin-mail classique ;
|
||||
* ouvrir l'accès SSH entre tous les frontaux (nécessaire pour les
|
||||
réplications) ;
|
||||
* Ouvrir l'accès SSH en root depuis la machine d'admin vers chaque frontal ;
|
||||
* Copier les scripts scripts/sync-master-to-slave* du dépôt dans
|
||||
/opt/evocluster/, puis `chmod -R 755 /opt/evocluster/`.
|
||||
|
||||
Cas de la réplication MySQL :
|
||||
* Configurer la réplication MySQL de manière standard (comme décrit ici [1]) ;
|
||||
* Rajouter sur la machine slave dans le my.cnf la directive replicate-do-db,
|
||||
qui contiendra la liste des bases des comptes à répliquer.
|
||||
|
||||
[1] http://trac.evolix.net/infogerance/wiki/HowtoMySQL#R%C3%A9plicationMySQL
|
||||
|
||||
4. Configuration d'Evoadmin
|
||||
---------------------------
|
||||
|
||||
Afin d'activer Evoadmin en mode Cluster, remplir les variables suivantes dans
|
||||
/home/evoadmin/www/conf/config.local.php :
|
||||
|
||||
$localconf['cluster'] = TRUE;
|
||||
$localconf['cache'] = '/home/evoadmin/www/cache.sqlite'; // cache sqlite
|
||||
$localconf['servers'] = array('www00', 'www01', ..., 'wwwnn');
|
||||
|
||||
Créer le cache après avoir renseigner le fichier de conf :
|
||||
# cd /home/evoadmin/www/bin && php init_cache.php
|
||||
www00 added in cache
|
||||
[...]
|
||||
Cache initialisé
|
||||
# chown www-evoadmin:evoadmin /home/evoadmin/www/cache.sqlite
|
||||
# chmod ug+rx /home/evoadmin/www/cache.sqlite
|
||||
|
||||
S'assurer que /home/evoadmin/www appartient bien à www-evoadmin:evoadmin.
|
||||
|
||||
Il est possible de dumper le cache grâce à au script list_domain.php et de
|
||||
rajouter des serveurs dans le cache grâce au script add_server.php :
|
||||
# php add_server.php www42
|
||||
|
||||
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
evoadmin-web
|
||||
============
|
||||
Panel d'administration de serveur web.
|
7
TODO
Normal file
7
TODO
Normal file
|
@ -0,0 +1,7 @@
|
|||
* Verification des paramètres passés dans le script ftpadmin.sh
|
||||
* Vérifier lors de la suppression que c'est bien la personne a qui appartient le compte qui lance la commande
|
||||
* Tableau "sortable" (TableKit ?)
|
||||
* Mettre en place EvoLog et logger la sortie des scripts
|
||||
* Validation plus (très) stricte sur les entrées de formulaire
|
||||
* Listage des comptes utilisateurs
|
||||
* Total espace disque FTP
|
34
bin/add_server.php
Normal file
34
bin/add_server.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
require '../lib/bdd.php';
|
||||
require_once '../conf/config.php';
|
||||
require_once '../conf/config.local.php';
|
||||
|
||||
|
||||
if ($argc==1) {
|
||||
echo "Specify a server name";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$conf = array_merge($oriconf, $localconf);
|
||||
|
||||
$bdd = new bdd();
|
||||
|
||||
$file=$conf['cache'];
|
||||
|
||||
if (!file_exists($file)) {
|
||||
echo "$file doesn't exist\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$bdd->open($file);
|
||||
|
||||
$server = array("name" => $argv[1]);
|
||||
|
||||
$bdd->add_server(array("name" => "$server"));
|
||||
exec('ssh -o "UserKnownHostsFile '.$conf['known_host'].'" '.$argv[1].' /bin/true');
|
||||
|
||||
echo "$server added in cache\n";
|
||||
exit(0);
|
||||
?>
|
||||
|
28
bin/init_cache.php
Normal file
28
bin/init_cache.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
require '../lib/bdd.php';
|
||||
require_once '../conf/config.php';
|
||||
require_once '../conf/config.local.php';
|
||||
|
||||
$conf = array_merge($oriconf, $localconf);
|
||||
|
||||
|
||||
$bdd = new bdd();
|
||||
|
||||
$file=$conf['cache'];
|
||||
|
||||
if (!file_exists($file))
|
||||
$bdd->create($file);
|
||||
else {
|
||||
echo "$file is already created";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
foreach ($conf['servers'] as $server) {
|
||||
echo "$server added in cache\n";
|
||||
$bdd->add_server(array("name" => "$server"));
|
||||
}
|
||||
|
||||
echo "Cache initialisé\n";
|
||||
exit(0);
|
||||
?>
|
26
bin/list_domains.php
Normal file
26
bin/list_domains.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
require '../lib/bdd.php';
|
||||
require_once '../conf/config.php';
|
||||
require_once '../conf/config.local.php';
|
||||
|
||||
$conf = array_merge($oriconf, $localconf);
|
||||
|
||||
|
||||
$bdd = new bdd();
|
||||
|
||||
$file=$conf['cache'];
|
||||
|
||||
if (!file_exists($file)) {
|
||||
echo "$file is not created\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$bdd->open($file);
|
||||
|
||||
$domains = $bdd->list_domains();
|
||||
print_r($domains);
|
||||
|
||||
exit(0);
|
||||
|
||||
?>
|
18
bin/prod
Executable file
18
bin/prod
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Pré-requis pour utiliser ce script :
|
||||
# * Evoadmin-web est installé dans /home/evoadmin/www
|
||||
# * Etre loggué avec le compte evoadmin (sudo su evoadmin)
|
||||
|
||||
# Note : Ce script utilise une connexion SVN anonyme pour récupérer le code source
|
||||
# Note : Ce script ne met *pas* en prod les scripts dans /usr/share/scripts
|
||||
|
||||
SVNREPO="svn://svn.evolix.org/svn/packweb/trunk/evoadmin"
|
||||
|
||||
tmpdir=`mktemp -d $HOME/tmp.XXXXXX`
|
||||
svn export --force $SVNREPO $tmpdir
|
||||
svn info $SVNREPO >$tmpdir/svn.txt
|
||||
rsync -rlvt --delete --exclude config.local.php $tmpdir/ /home/evoadmin/www
|
||||
rm -rf $tmpdir
|
||||
svn info $SVNREPO | mail -s "Mise en prod Evoadmin ($HOSTNAME)" root
|
||||
|
45
conf/config.php
Normal file
45
conf/config.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Configuration page
|
||||
*
|
||||
* Copyright (c) 2009 Evolix - Tous droits reserves
|
||||
*
|
||||
* $Id: config.php 273 2009-05-12 13:54:50Z tmartin $
|
||||
* vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2
|
||||
*
|
||||
* @author Gregory Colpart <reg@evolix.fr>
|
||||
* @author Thomas Martin <tmartin@evolix.fr>
|
||||
* @author Sebastien Palma <spalma@evolix.fr>
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
|
||||
// Email pour les notifications
|
||||
$oriconf['admin']['mail'] = 'admin@example.com';
|
||||
$oriconf['techmail'] = 'jdoe@example.com';
|
||||
$oriconf['debug'] = FALSE;
|
||||
$oriconf['superadmin'] = array('superadmin');
|
||||
$oriconf['script_path'] = '/usr/share/scripts/evoadmin';
|
||||
$oriconf['cluster'] = FALSE;
|
||||
$oriconf['servers'] = array('servers');
|
||||
$oriconf['cache'] = '/home/evoadmin/www/cache.sqlite';
|
||||
$localconf['known_host'] = '/home/evoadmin/www/known_host';
|
||||
$oriconf['ftpadmin'] = TRUE;
|
||||
|
||||
/* cluster mode
|
||||
* $oriconf['noreplication'] = array('www00');
|
||||
* $oriconf['postponedreplication'] = array('www00', 'www01');
|
||||
* $oriconf['immediatereplication'] = array('www00', 'www01');
|
||||
* $oriconf['postponedreplication_mode'] = array('3 fois/jour', '1 fois/jour', '1 fois/heure');
|
||||
*/
|
||||
|
||||
/* Il est possible de définir pour chaque mode de
|
||||
* postponedreplication_mode une liste de serveurs,
|
||||
* qui seront utilisés à la place des serveurs du
|
||||
* tableau postponedreplication.
|
||||
*
|
||||
* $localconf['1 fois/jour'] = array('www00', 'www01');
|
||||
* $localconf['1 fois/heure'] = array('www01', 'www00');
|
||||
*/
|
||||
|
19
conf/connect.php
Normal file
19
conf/connect.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Secrete parameters
|
||||
*
|
||||
* Copyright (c) 2009 Evolix - Tous droits reserves
|
||||
*
|
||||
* vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2
|
||||
*
|
||||
* @author Gregory Colpart <reg@evolix.fr>
|
||||
* @author Thomas Martin <tmartin@evolix.fr>
|
||||
* @author Sebastien Palma <spalma@evolix.fr>
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
define("SUDOBIN","/usr/bin/sudo");
|
||||
define("SUDOSCRIPT","/usr/share/scripts/evoadmin.sh");
|
||||
define("SUDOPASS","xxxxxx");
|
||||
|
998
evolibs/Form.php
Normal file
998
evolibs/Form.php
Normal file
|
@ -0,0 +1,998 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Bibliotheques FORM (PHP5)
|
||||
*
|
||||
* Copyright (c) 2004-2009 Evolix - Tous droits reserves
|
||||
*
|
||||
* $Id: Form.php 168 2009-08-14 14:41:42Z tmartin $
|
||||
* vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2
|
||||
*
|
||||
* @author Gregory Colpart <reg@evolix.fr>
|
||||
* @author Thomas Martin <tmartin@evolix.fr>
|
||||
* @author Sebastien Palma <spalma@evolix.fr>
|
||||
*
|
||||
* Fonctions utiles pour la creation de formulaires
|
||||
*
|
||||
* v 1.0
|
||||
*/
|
||||
|
||||
class FormPageController {
|
||||
private $pages = array();
|
||||
private $current_page = NULL;
|
||||
|
||||
/* Affiche la page de formulaire in-line */
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
$out = $this->pages[$this->current_page];
|
||||
$out .= "\n\n";
|
||||
return $out;
|
||||
}
|
||||
|
||||
/* Vérifie les champs et redirige vers la dernière page valide.
|
||||
Retourne TRUE si le formulaire est entièrement valide.
|
||||
Retourne FALSE en cas d'erreur sur la page courante. */
|
||||
public function verify($set_error=TRUE) {
|
||||
$valid = TRUE;
|
||||
foreach($this->pages as $pagenum => $page) {
|
||||
if(!$page->verify($set_error)) {
|
||||
$valid = FALSE;
|
||||
}
|
||||
}
|
||||
if($valid) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
public function setCurrentPage($current_page) {
|
||||
$this->current_page = $current_page;
|
||||
$this->pages[$current_page]->isCurrentPage(TRUE);
|
||||
}
|
||||
|
||||
public function getCurrentPage() {
|
||||
return $this->pages[$this->current_page];
|
||||
}
|
||||
|
||||
public function addPage($pagenum, $obj) {
|
||||
$this->pages[$pagenum] = $obj;
|
||||
}
|
||||
|
||||
/* Doit être appelé après les addField() */
|
||||
public function init() {
|
||||
foreach($this->pages as $pagenum=>$page) {
|
||||
$page->initFields();
|
||||
}
|
||||
}
|
||||
|
||||
/* Retourne le numéro de page suivant, ou FALSE si on est à la fin */
|
||||
public function getNextPage() {
|
||||
$numpage = count($this->pages);
|
||||
if($this->current_page == $numpage) {
|
||||
return FALSE;
|
||||
} else {
|
||||
return $this->current_page+1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Retourne des infos sur les pages du formulaire, pour construire un fil
|
||||
d'ariane par exemple */
|
||||
public function getPagesList() {
|
||||
return $this->pages;
|
||||
}
|
||||
|
||||
public function getPage($num = null) {
|
||||
if($num) {
|
||||
return $this->pages[$num];
|
||||
} else {
|
||||
return $this->pages[$this->current_page];
|
||||
}
|
||||
}
|
||||
|
||||
/* Renvoie une collection d'objets "Field" */
|
||||
public function getFieldsList() {
|
||||
$fields = array();
|
||||
foreach($this->pages as $page) {
|
||||
foreach($page->getFieldsList() as $field) {
|
||||
$fields[$field[0]] = $field[1];
|
||||
}
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/* Renvoie une structure de données injectable dans ldap_add() ou
|
||||
ldap_modify() */
|
||||
public function toLDAP() {
|
||||
|
||||
$info = array();
|
||||
|
||||
foreach($this->getFieldsList() as $name=>$obj) {
|
||||
if(is_array($obj->getValue()) && count($obj->getValue()) == 1) {
|
||||
$tmp = $obj->getValue();
|
||||
$value = $tmp[0];
|
||||
} else {
|
||||
$value = $obj->getValue();
|
||||
}
|
||||
|
||||
if(!empty($value)) {
|
||||
$info[strtolower($name)] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/* Permet de définir à posteriori une liste de champs obligatoires */
|
||||
public function setMandatoryFields($list) {
|
||||
foreach($this->getFieldsList() as $fname=>$fobj) {
|
||||
if(in_array($fname, $list)) {
|
||||
$fobj->setMandatory(TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Permet d'utiliser un stockage différent de celui par défaut
|
||||
* ($_SESSION) pour tous les FormFields déjà ajouté au controlleur. Prend
|
||||
* en paramètre la référence d'un tableau
|
||||
*/
|
||||
public function setSessionStorage(& $storage) {
|
||||
foreach($this->getFieldsList() as $fname=>$fobj) {
|
||||
$fobj->setSessionStorage($storage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FormPage {
|
||||
private $fields = array();
|
||||
private $label = NULL;
|
||||
private $is_current_page = FALSE;
|
||||
private $use_session = NULL;
|
||||
|
||||
public function __construct($label, $use_session=TRUE) {
|
||||
$this->label = $label;
|
||||
$this->use_session = $use_session;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
foreach($this->fields as $field) {
|
||||
$obj = $field[1];
|
||||
$out .= "$obj\n\n";
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function getLabel() {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
$num_error = 0;
|
||||
|
||||
foreach($this->fields as $field) {
|
||||
$obj = $field[1];
|
||||
if($obj->verify($set_error)) {
|
||||
$this->use_session && $obj->storeSession();
|
||||
} else {
|
||||
$num_error++;
|
||||
$this->use_session && $obj->deleteSession();
|
||||
}
|
||||
}
|
||||
|
||||
if($num_error > 0) {
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
public function addField($name, $obj) {
|
||||
$obj->setName($name);
|
||||
array_push($this->fields, array($name, $obj));
|
||||
}
|
||||
|
||||
public function addFieldsArray($array) {
|
||||
foreach($array as $name=>$obj) {
|
||||
$this->addField($name, $obj);
|
||||
}
|
||||
}
|
||||
|
||||
/* Petit hack : la page doit savoir si c'est elle qui est affiché, pour
|
||||
gérer le cas des checkbox */
|
||||
public function initFields($is_current_page=FALSE) {
|
||||
foreach($this->fields as $field) {
|
||||
$name = $field[0];
|
||||
$obj = $field[1];
|
||||
|
||||
if((is_a($obj, 'CheckBoxInputFormField')
|
||||
|| is_a($obj, 'MultipleCheckBoxInputFormField'))
|
||||
&& $this->is_current_page
|
||||
&& !empty($_POST) && !array_key_exists($name, $_POST)) {
|
||||
$obj->setValue(0);
|
||||
} else if(is_a($obj, 'UploadFileInputFormField')
|
||||
&& $this->is_current_page
|
||||
&& array_key_exists($name, $_FILES) && $_FILES[$name]['error']==0) {
|
||||
$obj->saveTmpFile($_FILES[$name]);
|
||||
} else if(array_key_exists($name, $_POST)) {
|
||||
$obj->setValue($_POST[$name]);
|
||||
} else if($this->use_session && $obj->sessionKeyExist($name)) {
|
||||
$obj->setSessionValue($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function isCurrentPage($is=NULL) {
|
||||
if(is_bool($is)) {
|
||||
$this->is_current_page = $is;
|
||||
}
|
||||
return $this->is_current_page;
|
||||
}
|
||||
|
||||
|
||||
/* Renvoie la liste des objets Fields de la page */
|
||||
public function getFieldsList() {
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
/* Renvoie la liste des objets Fields de la page */
|
||||
public function getFieldsName() {
|
||||
$ret = array();
|
||||
foreach($this->fields as $field) {
|
||||
$ret[] = $field[0];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function getField($name) {
|
||||
foreach($this->fields as $f) {
|
||||
if($f[0] == $name) {
|
||||
return $f[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FormField {
|
||||
protected $value = null;
|
||||
protected $error = null;
|
||||
protected $label = null;
|
||||
protected $name = null;
|
||||
protected $css_class = null;
|
||||
protected $read_only = null;
|
||||
protected $disabled = null;
|
||||
private $storage = NULL;
|
||||
|
||||
protected function __construct($label) {
|
||||
$this->storage = & $_SESSION;
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
public function storeSession() {
|
||||
if(strlen($this->value) > 0) {
|
||||
$this->storage[$this->name] = $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteSession() {
|
||||
unset($this->storage[$this->name]);
|
||||
}
|
||||
|
||||
public function setSessionValue($name) {
|
||||
$this->setValue($this->storage[$name]);
|
||||
}
|
||||
|
||||
public function sessionKeyExist($name) {
|
||||
#echo "$name ".$this->storage[$name]." ";
|
||||
return array_key_exists($name, $this->storage);
|
||||
}
|
||||
|
||||
public function setSessionStorage(& $storage) {
|
||||
$this->storage = & $storage;
|
||||
}
|
||||
|
||||
protected function verify($set_error) {
|
||||
if(empty($this->error)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
public function getError() {
|
||||
if(isset($this->value) && !$this->verify(FALSE)) {
|
||||
return $this->error;
|
||||
}
|
||||
}
|
||||
|
||||
public function getErrorHTML() {
|
||||
return '<span class="form-error">'.$this->error.'</span>';
|
||||
}
|
||||
|
||||
public function setError($error) {
|
||||
$this->error = $error;
|
||||
}
|
||||
|
||||
public function getLabel() {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setValue($value) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getReadableValue() {
|
||||
return $this->getValue();
|
||||
}
|
||||
|
||||
public function getLabelHTML() {
|
||||
$label = '';
|
||||
$label .= '<label for="'.$this->name.'">';
|
||||
$label .= $this->label.' ';
|
||||
if ($this->mandatory) {
|
||||
if($this->verify(false)) {
|
||||
$label .= '<span class="form-mandatory-ok">[*]</span> ';
|
||||
} else {
|
||||
$label .= '<span class="form-mandatory">[*]</span> ';
|
||||
}
|
||||
}
|
||||
$label .= ': ';
|
||||
$label .= "</label>\n";
|
||||
return $label;
|
||||
}
|
||||
|
||||
public function setCSSClass($name) {
|
||||
$this->css_class = $name;
|
||||
}
|
||||
|
||||
public function setReadOnly() {
|
||||
$this->read_only = true;
|
||||
}
|
||||
|
||||
public function setDisabled($state = TRUE) {
|
||||
$this->disabled = $state;
|
||||
}
|
||||
|
||||
public function setMandatory($bool) {
|
||||
$this->mandatory = $bool;
|
||||
}
|
||||
}
|
||||
|
||||
/* $textsize = array( size, maxlength ) */
|
||||
class TextInputFormField extends FormField {
|
||||
protected $mandatory = NULL;
|
||||
protected $textsize = NULL;
|
||||
|
||||
public function __construct($label, $mandatory=TRUE, $textsize=array(20, 40)) {
|
||||
parent::__construct($label);
|
||||
$this->mandatory = $mandatory;
|
||||
$this->textsize = $textsize;
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
if($this->mandatory && (!strlen($this->value))) {
|
||||
if($set_error) $this->error = 'Champ obligatoire';
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function getInputHTML() {
|
||||
$input = '';
|
||||
$input .= '<input type="text" id="'.$this->name.'"';
|
||||
$input .= ' name="'.$this->name.'" value="'.htmlspecialchars($this->value,ENT_QUOTES).'"';
|
||||
#$input .= sprintf(' name="%s" value="%s"', $this->name, htmlspecialchars($this->value, ENT_QUOTES));
|
||||
$input .= ' maxlength="'.$this->textsize[1].'" size="'.$this->textsize[0].'" ';
|
||||
if($this->read_only) { $input .= 'readonly="readonly="'; }
|
||||
if($this->disabled) { $input .= 'disabled="disabled="'; }
|
||||
$input .= '/>';
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
$out .= "<p>\n";
|
||||
$out .= $this->getLabelHTML();
|
||||
$out .= $this->getInputHTML();
|
||||
$out .= $this->getErrorHTML();
|
||||
$out .= "</p>\n\n";
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
class DateInputFormField extends TextInputFormField {
|
||||
public function __construct($label, $mandatory=TRUE) {
|
||||
parent::__construct($label, $mandatory, array(7, 10));
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
if(!parent::verify($set_error)) return FALSE;
|
||||
if(!empty($this->value) &&
|
||||
!preg_match('#^\d{2}/\d{2}/\d{4}$#', $this->value)) {
|
||||
if($set_error) $this->error = 'Format de date non valide';
|
||||
return FALSE;
|
||||
}
|
||||
$arr_date = split('/', $this->value);
|
||||
if(!empty($this->value) &&
|
||||
!checkdate($arr_date[1],$arr_date[0],$arr_date[2])) {
|
||||
if($set_error) $this->error = "La date saisie n'existe pas";
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
class YearDateInputFormField extends TextInputFormField {
|
||||
public function __construct($label, $mandatory=TRUE) {
|
||||
parent::__construct($label, $mandatory, array(4, 4));
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
if(!parent::verify($set_error)) return FALSE;
|
||||
if(!empty($this->value) && (!ctype_digit($this->value) || $this->value < 1900)) {
|
||||
if($set_error) $this->error = 'Vous devez saisir une année valide';
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
class TelephoneInputFormField extends TextInputFormField {
|
||||
public function setValue($value) {
|
||||
$value = preg_replace('/[^\d -\.\(\)\+]/', '-', $value);
|
||||
parent::setValue($value);
|
||||
}
|
||||
}
|
||||
|
||||
class IntegerInputFormField extends TextInputFormField {
|
||||
public function verify($set_error) {
|
||||
if(!parent::verify($set_error)) return FALSE;
|
||||
if(!empty($this->value) && !is_numeric($this->value)) {
|
||||
if($set_error) $this->error = 'Vous devez saisir un chiffre';
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
class FloatInputFormField extends TextInputFormField {
|
||||
public function verify($set_error) {
|
||||
if(!parent::verify($set_error)) return FALSE;
|
||||
if(!empty($this->value) && !is_numeric($this->value)) {
|
||||
if($set_error) $this->error = 'Vous devez saisir un chiffre';
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
class EmailInputFormField extends TextInputFormField {
|
||||
|
||||
public function verify($set_error) {
|
||||
if(!parent::verify($set_error)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(!empty($this->value) && !eregi('^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$',$this->value)){
|
||||
if($set_error) $this->error = 'Adresse email invalide';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
class TextareaFormField extends FormField {
|
||||
protected $mandatory = NULL;
|
||||
protected $cols = NULL;
|
||||
protected $rows = NULL;
|
||||
|
||||
public function __construct($label, $mandatory=TRUE, $cols=45, $rows=5) {
|
||||
parent::__construct($label);
|
||||
$this->mandatory = $mandatory;
|
||||
$this->rows = $rows;
|
||||
$this->cols = $cols;
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
if($this->mandatory && empty($this->value)) {
|
||||
if($set_error) $this->error = 'Champ obligatoire';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function getInputHTML() {
|
||||
$input = '';
|
||||
$input .= '<textarea cols="'.$this->cols.'" rows="'.$this->rows.'" id="'.$this->name.'"';
|
||||
$input .= ' name="'.$this->name.'">'.htmlspecialchars($this->value,ENT_QUOTES).'</textarea>';
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
$out .= "<p class='form-textarea'>\n";
|
||||
$out .= $this->getLabelHTML();
|
||||
$out .= $this->getInputHTML();
|
||||
$out .= $this->getErrorHTML();
|
||||
$out .= "</p>\n\n";
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class PasswordInputFormField extends FormField {
|
||||
protected $mandatory = NULL;
|
||||
|
||||
public function __construct($label, $mandatory=TRUE) {
|
||||
parent::__construct($label);
|
||||
$this->mandatory = $mandatory;
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
if(empty($this->value)) {
|
||||
if($this->mandatory) {
|
||||
if($set_error) $this->error = 'Champ obligatoire';
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if(strlen($this->value) < 8) {
|
||||
if($set_error) $this->error = '8 caracteres minimum';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if(preg_match('#.*[A-Z]+.*$#',$this->value)==0){
|
||||
# if($set_error) $this->error = 'Votre mot de passe doit contenir au moins une majuscule';
|
||||
# return FALSE;
|
||||
# }
|
||||
|
||||
if(preg_match('#.*[0-9]+.*#',$this->value)==0){
|
||||
if($set_error) $this->error = 'Votre mot de passe doit contenir au moins un chiffre';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
public function getInputHTML() {
|
||||
$input = sprintf('<input type="password" id="%s" name="%s" value="%s"',
|
||||
$this->name, $this->name,
|
||||
htmlspecialchars($this->value, ENT_QUOTES));
|
||||
if($this->read_only) $input .= ' readonly="readonly"';
|
||||
if($this->disabled) { $input .= 'disabled="disabled="'; }
|
||||
$input .= '/>';
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
$out .= "<p>\n";
|
||||
$out .= $this->getLabelHTML();
|
||||
$out .= $this->getInputHTML();
|
||||
$out .= $this->getErrorHTML();
|
||||
$out .= "</p>\n\n";
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CheckBoxInputFormField extends FormField {
|
||||
protected $mandatory = NULL;
|
||||
|
||||
public function __construct($label, $mandatory=TRUE) {
|
||||
parent::__construct($label);
|
||||
$this->mandatory = $mandatory;
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
if(!parent::verify($set_error)) return FALSE;
|
||||
if($this->mandatory && empty($this->value)) {
|
||||
if($set_error) $this->error = 'Champ obligatoire';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
public function getInputHTML() {
|
||||
$input = sprintf('<input type="checkbox" id="%s" name="%s"',
|
||||
$this->name, $this->name);
|
||||
if($this->value) $input .= ' checked="checked"';
|
||||
if($this->disabled) $input .= ' disabled="disabled"';
|
||||
$input .= ' value="1" />';
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
$out .= "<p>\n";
|
||||
$out .= $this->getLabelHTML();
|
||||
$out .= $this->getInputHTML();
|
||||
$out .= $this->getErrorHTML();
|
||||
$out .= "</p>\n\n";
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
class MultipleCheckBoxInputFormField extends FormField {
|
||||
protected $mandatory = NULL;
|
||||
protected $list = array();
|
||||
|
||||
public function __construct($label, $mandatory=TRUE, $list) {
|
||||
parent::__construct($label);
|
||||
$this->mandatory = $mandatory;
|
||||
$this->list = $list;
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
if($this->mandatory && empty($this->value)) {
|
||||
if($set_error) $this->error = 'Vous devez faire au moins un choix';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function getInputHTML() {
|
||||
$input = '';
|
||||
$n = 0;
|
||||
foreach ($this->list as $value => $label) {
|
||||
$input .= '<input type="checkbox" name="'.$this->name.'[]" value="'.htmlspecialchars($value,ENT_QUOTES).'"';
|
||||
if (is_array($this->value) && in_array($value, $this->value)) {
|
||||
$input.=' checked="checked"';
|
||||
}
|
||||
if($this->read_only) { $input .= 'readonly="readonly="'; }
|
||||
$input .= "/>$label";
|
||||
$n++;
|
||||
if($n < count($this->list)) $input .= "<br/>\n";
|
||||
}
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function getErrorHTML() {
|
||||
if($this->error) {
|
||||
return "<br/><span class='form-error form-incolumn-error'>{$this->error}</span>";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
$out .= "<p>\n";
|
||||
$out .= $this->getLabelHTML();
|
||||
$out .= $this->getInputHTML();
|
||||
$out .= $this->getErrorHTML();
|
||||
$out .= "</p>\n\n";
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
$out = array();
|
||||
foreach($this->value as $index) {
|
||||
#$out[] = $this->list[$index];
|
||||
$out[] = $index;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function getReadableValue() {
|
||||
$n = 1;
|
||||
$out = '';
|
||||
foreach($this->value as $index) {
|
||||
$out .= $this->list[$index];
|
||||
if($n < count($this->value)) $out .= ', ';
|
||||
$n++;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function setValue($value) {
|
||||
if(!is_array($value)) {
|
||||
$this->value = array($value);
|
||||
} else {
|
||||
parent::setValue($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SelectFormField extends FormField {
|
||||
protected $mandatory = NULL;
|
||||
protected $list = array();
|
||||
|
||||
public function __construct($label, $mandatory=TRUE, $list) {
|
||||
parent::__construct($label);
|
||||
$this->mandatory = $mandatory;
|
||||
$this->list = $list;
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
if($this->mandatory && empty($this->value)) {
|
||||
if($set_error) $this->error = 'Champ obligatoire';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
public function getInputHTML() {
|
||||
$input = '';
|
||||
$input .= '<select id="'.$this->name.'" name="'.$this->name.'">'."\n";
|
||||
$input .= ' <option value="">-- Choisissez --</option>'."\n";
|
||||
foreach ($this->list as $value => $label) {
|
||||
$input .= ' <option value="'.htmlspecialchars($value,ENT_QUOTES).'"';
|
||||
if ($this->value == $value) $input.=' selected="selected"';
|
||||
$input .= '>'.$label.'</option>'."\n";
|
||||
}
|
||||
$input .= "</select>\n";
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
$out .= "<p>\n";
|
||||
$out .= $this->getLabelHTML();
|
||||
$out .= $this->getInputHTML();
|
||||
$out .= $this->getErrorHTML();
|
||||
$out .= "</p>\n\n";
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getReadableValue() {
|
||||
if(array_key_exists($this->value, $this->list)) {
|
||||
return $this->list[$this->value];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RadioFormField extends FormField {
|
||||
protected $mandatory = NULL;
|
||||
protected $list = array();
|
||||
|
||||
public function __construct($label, $mandatory=TRUE, $list, $default = null) {
|
||||
parent::__construct($label);
|
||||
$this->mandatory = $mandatory;
|
||||
$this->list = $list;
|
||||
if($default) {
|
||||
$this->value = $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
if($this->mandatory && empty($this->value)) {
|
||||
if($set_error) $this->error = 'Champ obligatoire';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function getInputHTML() {
|
||||
$input = '';
|
||||
$input .= '<span class="form-radio">';
|
||||
foreach ($this->list as $value => $label) {
|
||||
$input .= '<input type="radio" name="'.$this->name.'" value="'.htmlspecialchars($value,ENT_QUOTES).'"';
|
||||
if ($this->value == $value) $input.=' checked="checked"';
|
||||
$input .= "/>$label<br/>";
|
||||
}
|
||||
$input .= '</span>';
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function getErrorHTML() {
|
||||
return "<span class='form-error form-incolumn-error'>{$this->error}</span>";
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
$out .= "<p>\n";
|
||||
$out .= $this->getLabelHTML();
|
||||
$out .= $this->getInputHTML();
|
||||
$out .= $this->getErrorHTML();
|
||||
$out .= "</p>\n\n";
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getReadableValue() {
|
||||
if(array_key_exists($this->value, $this->list)) {
|
||||
return $this->list[$this->value];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ButtonInputFormField extends FormField {
|
||||
protected $mandatory = NULL;
|
||||
protected $event = NULL;
|
||||
protected $action = NULL;
|
||||
|
||||
public function __construct($label,$mandatory=FALSE, $event, $action) {
|
||||
parent::__construct($label);
|
||||
$this->mandatory = $mandatory;
|
||||
$this->event = $event;
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
public function getInputHTML() {
|
||||
$input = '';
|
||||
$input .= '<input type="button" name="'.$this->name.'" ';
|
||||
if (!empty($this->event) && !empty($this->action)) {
|
||||
$input .= $this->event.'='.$this->action.' ';
|
||||
}
|
||||
$input .= 'value="'.htmlspecialchars($this->label,ENT_QUOTES).'" />';
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
$out .= "<p>\n";
|
||||
$out .= $this->getInputHTML();
|
||||
$out .= $this->getErrorHTML();
|
||||
$out .= "</p>\n\n";
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SubmitInputFormField extends FormField {
|
||||
protected $mandatory = NULL;
|
||||
protected $event = NULL;
|
||||
protected $action = NULL;
|
||||
|
||||
public function __construct($label,$mandatory=FALSE) {
|
||||
parent::__construct($label);
|
||||
$this->mandatory = $mandatory;
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
public function getInputHTML() {
|
||||
$input = '';
|
||||
$input .= '<input type="submit" name="'.$this->name.'" ';
|
||||
$input .= 'class="'.$this->css_class.'" value="'.htmlspecialchars($this->label,ENT_QUOTES).'" />';
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
$out .= "<p>\n";
|
||||
$out .= $this->getInputHTML();
|
||||
$out .= $this->getErrorHTML();
|
||||
$out .= "</p>\n\n";
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
class UploadFileInputFormField extends FormField {
|
||||
protected $mandatory = NULL;
|
||||
protected $delete_url = NULL;
|
||||
|
||||
public function __construct($label,$mandatory=FALSE) {
|
||||
parent::__construct($label);
|
||||
$this->mandatory = $mandatory;
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function setDeleteUrl($url) {
|
||||
$this->delete_url = $url;
|
||||
}
|
||||
|
||||
|
||||
public function deleteUploadedFile() {
|
||||
if(!is_array($this->value)) {
|
||||
return "Value is not an array";
|
||||
}
|
||||
|
||||
if(file_exists('/tmp/'.$this->value['tempname'])) {
|
||||
unlink('/tmp/'.$this->value['tempname']);
|
||||
}
|
||||
|
||||
$this->value = NULL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function saveTmpFile($upload_array) {
|
||||
$this->value['filename'] = $upload_array['name'];
|
||||
$this->value['file_ext'] = end(explode(".", $this->value['filename']));
|
||||
$this->value['tempname'] = 'tmp_'.time().'.'.$this->value['file_ext'];
|
||||
$up_filename = $upload_array['tmp_name'];
|
||||
|
||||
if(!move_uploaded_file($up_filename, '/tmp/'.$this->value['tempname'])) {
|
||||
$this->error = $this->value['error'];
|
||||
}
|
||||
}
|
||||
|
||||
public function moveTmpFile($filename, $dest_path) {
|
||||
$this->value['filename'] = $filename.'.'.$this->value['file_ext'];
|
||||
|
||||
if(!file_exists('/tmp/'.$this->value['tempname'])) {
|
||||
$this->error = "Impossible de trouver le fichier /tmp/{$this->value['tempname']}";
|
||||
return "";
|
||||
}
|
||||
|
||||
if((rename('/tmp/'.$this->value['tempname'],$dest_path.$this->value['filename']))===FALSE) {
|
||||