noalyss Version-9
backup.inc.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19/*!\file
20 * \brief Make and restore backup
21 */
22if ( !defined("ALLOWED")) { die (_("Non autorisé")); }
23
25
26// Copyright Author Dany De Bontridder danydb@aevalys.eu
27 try {
28 $dossier_number=$http->request("d", "number");
29 } catch (Exception $e){
30 echo span(_("Dossier invalide")," class=\"error\" ");
31 exit();
32 }
33if ( isset ($_REQUEST['sa']) )
34{
35 if ( defined ('PG_PATH') )
36 putenv("PATH=".PG_PATH);
37
38
39 if ( ! isset($_REQUEST['t']))
40 {
41 echo _("Erreur : paramètre manquant ");
42 exit();
43 }
44
45 $sa=$http->request("sa");
46 // backup
47 if ( $sa=='b')
48 {
49 $cmd=escapeshellcmd (PG_DUMP);
50 if ( defined ("noalyss_user"))
51 {
52 putenv("PGPASSWORD=".noalyss_password);
53 putenv("PGUSER=".noalyss_user);
54 putenv("PGHOST=".noalyss_psql_host);
55 putenv("PGPORT=".noalyss_psql_port);
56 }else if (defined ("phpcompta_user"))
57 {
58 putenv("PGPASSWORD=".phpcompta_password);
59 putenv("PGUSER=".phpcompta_user);
60 putenv("PGHOST=".phpcompta_psql_host);
61 putenv("PGPORT=".phpcompta_psql_port);
62 } else {
63 die ('Aucune connection');
64 }
65 $repo=new Database(0);
66 // compute file name with date
67 if ( $_REQUEST['t'] == 'd' )
68 {
69 // get folder name
70 $name = $repo->get_value("select dos_name from ac_dossier where dos_id=$1",
71 array($dossier_number));
72
73 $database=domaine."dossier".$dossier_number;
74 $filename= str_replace(array('/','\\' ,'<','>','"','[',']',':','*',' ','{','}','&'),'_', $name);
75 $filename= str_replace("__", "_", $filename);
76 $filename=str_replace(PHP_EOL,'',$filename);
77 $filename.="-".date('Ymd');
78 $args= " -Fc -Z9 --no-owner -h ".getenv("PGHOST")." -p ".getenv("PGPORT")." ".$database;
79 header('Content-type: application/octet');
80 header('Content-Disposition:attachment;filename="'.$filename.'.bin"',FALSE);
81
82 passthru ($cmd.$args,$a);
83
84 }
85
86 if ( $_REQUEST['t'] == 'm' )
87 {
88 // get template name
89 $name = $repo->get_value("select mod_name from modeledef where mod_id=$1",
90 array($dossier_number));
91 $database=domaine."mod".$dossier_number;
92 $filename= str_replace(array('/','\\' ,'<','>','"','[',']',':','*',' ','{','}','&'),'_', $name);
93 $filename= str_replace("__", "_", $filename);
94 $filename=str_replace(PHP_EOL,'',$filename);
95 $filename.="-".date('Ymd');
96 $args= " -Fc -Z9 --no-owner -h ".getenv("PGHOST")." -p ".getenv("PGPORT")." ".$database;
97 header('Content-type: bin/x-application');
98 header('Content-Disposition: attachment;filename="'.$filename.'.bin"',FALSE);
99 $a=passthru ($cmd.$args);
100 }
101 }
102}
103
span($p_string, $p_extra='')
Definition: ac_common.php:43
if(isset($_REQUEST['gDossier']) && $http->request("gDossier","number", 0) !=0) $repo
$_REQUEST['ac']
if(!defined("ALLOWED")) $http
Definition: backup.inc.php:24
contains the class for connecting to Noalyss
manage the http input (get , post, request) and extract from an array
for($e=0; $e< count($afiche); $e++) exit
domaine
Definition: install.php:370