prod_cron.php 6.54 KB
Newer Older
Ayolo's avatar
Ayolo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<?php

/* Copyright 2007
 * - Julien Etelain < julien at pmad dot net >
 *
 * Ce fichier fait partie du site de l'Association des Étudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
define("PROD_CRON", "/var/www/cron_update.sh");
Ayolo's avatar
bleh  
Ayolo committed
25
define("PROD_SCRIPT", "/var/www/update-official-www.sh");
Skia's avatar
Skia committed
26 27
define("POST_COMMIT_SCRIPT", "/data/svn/ae2/hooks/post-commit");
define("REFRESH_TAISTE", "/var/www/refresh-taiste-database.sh");
Ayolo's avatar
Ayolo committed
28 29 30 31 32 33 34 35
$topdir="../";

require_once($topdir. "include/site.inc.php");

$site = new site ();

if ( !$site->user->is_in_group("root") )
  $site->error_forbidden("none","group",7);
36

Ayolo's avatar
Ayolo committed
37
$site->start_page("none","Administration / passage en prod");
Ayolo's avatar
Ayolo committed
38
$cts = new contents("<a href=\"./\">Administration</a> / Passage en production");
Ayolo's avatar
bleh  
Ayolo committed
39
$tabs = array(array("","rootplace/prod_cron.php","Passage en prod"),
Skia's avatar
Skia committed
40
              array("","rootplace/prod_cron.php?view=refreshdb","Rafraichir taiste"),
Ayolo's avatar
bleh  
Ayolo committed
41
              array("script","rootplace/prod_cron.php?view=script","Script de passage en prod"),
Skia's avatar
Skia committed
42 43
              array("commit","rootplace/prod_cron.php?view=commit","Script de post commit"),
              array("clone","rootplace/prod_cron.php?view=refreshdbscript","Script de refresh de taiste"));
Ayolo's avatar
Ayolo committed
44 45 46

if ( $_REQUEST["action"] == "passprod" && $GLOBALS["svalid_call"] )
{
Ayolo's avatar
Ayolo committed
47
  if ( $site->is_sure ( "","Passage en production",null, 2 ) )
Colonel's avatar
Colonel committed
48
    @exec(escapeshellcmd(PROD_CRON));
Ayolo's avatar
Ayolo committed
49 50
  $Ok=true;
}
Skia's avatar
Skia committed
51 52 53 54 55 56
if ( $_REQUEST["action"] == "refreshdb" && $GLOBALS["svalid_call"] )
{
  if ( $site->is_sure ( "","Rafraichir taiste",null, 2 ) )
    @exec(escapeshellcmd(REFRESH_TAISTE));
  $Ok=true;
}
Ayolo's avatar
bleh  
Ayolo committed
57 58 59 60 61 62 63 64
if ( $_REQUEST["action"] == "scriptprod" && $GLOBALS["svalid_call"] )
{
  if ( $site->is_sure ( "","Modification du script de passage en production",null, 2 ) )
  {
    if(!$handle = @fopen(PROD_SCRIPT, "w"))
      $Ok=false;
    else
    {
Ayolo's avatar
bleh  
Ayolo committed
65
      $content = preg_replace("/\r\n/","\n",htmlspecialchars_decode($_REQUEST["__script__"]));
Ayolo's avatar
bleh  
Ayolo committed
66
      @fwrite($handle,$content);
Ayolo's avatar
bleh  
Ayolo committed
67
      @fclose ($handle);
Ayolo's avatar
bleh  
Ayolo committed
68
      $_REQUEST["view"]="script";
Ayolo's avatar
bleh  
Ayolo committed
69 70 71 72
      $Ok=true;
    }
  }
}
Ayolo's avatar
bleh  
Ayolo committed
73 74 75 76 77 78 79 80 81 82 83
if ( $_REQUEST["action"] == "scriptpostcommit" && $GLOBALS["svalid_call"] )
{
  if ( $site->is_sure ( "","Modification du script de post-commit",null, 2 ) )
  {
    if(!$handle = @fopen(POST_COMMIT_SCRIPT, "w"))
      $Ok=false;
    else
    {
      $content = preg_replace("/\r\n/","\n",htmlspecialchars_decode($_REQUEST["__script__"]));
      @fwrite($handle,$content);
      @fclose ($handle);
Ayolo's avatar
bleh  
Ayolo committed
84
      $_REQUEST["view"]="commit";
Ayolo's avatar
bleh  
Ayolo committed
85 86 87 88
      $Ok=true;
    }
  }
}
Skia's avatar
Skia committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
if ( $_REQUEST["action"] == "refreshdbscript" && $GLOBALS["svalid_call"] )
{
  if ( $site->is_sure ( "","Modification du script de refresh de taiste",null, 2 ) )
  {
    if(!$handle = @fopen(REFRESH_TAISTE, "w"))
      $Ok=false;
    else
    {
      $content = preg_replace("/\r\n/","\n",htmlspecialchars_decode($_REQUEST["__script__"]));
      @fwrite($handle,$content);
      @fclose ($handle);
      $_REQUEST["view"]="script";
      $Ok=true;
    }
  }
}
Ayolo's avatar
Ayolo committed
105

Ayolo's avatar
bleh  
Ayolo committed
106 107 108
$cts->add(new tabshead($tabs,$_REQUEST["view"]));
$cts->add_paragraph("Révision en production : ".get_rev());

Ayolo's avatar
Ayolo committed
109
if ( $Ok )
Ayolo's avatar
bleh  
Ayolo committed
110
{
Antoine Tenart's avatar
Antoine Tenart committed
111
  if ( $_REQUEST["action"] == "scriptprod" )
Ayolo's avatar
bleh  
Ayolo committed
112
    $cts->add_paragraph("Script de passage en prod modifié");
Ayolo's avatar
bleh  
Ayolo committed
113 114
  elseif( $_REQUEST["action"] == "commit" )
    $cts->add_paragraph("Script de post commit modifié");
Skia's avatar
Skia committed
115 116
  elseif( $_REQUEST["action"] == "refreshdbscript" )
    $cts->add_paragraph("Script de refresh modifié");
Ayolo's avatar
bleh  
Ayolo committed
117
}
Ayolo's avatar
Ayolo committed
118

Ayolo's avatar
bleh  
Ayolo committed
119 120 121 122 123 124 125 126 127 128
if($_REQUEST["view"]=="script")
{
  if(!$handle = @fopen(PROD_SCRIPT, "r"))
    $cts->add_paragraph("Impossible d'ouvrir le script de passage en prod !");
  else
  {
    $script = @fread($handle, @filesize(PROD_SCRIPT));
    $frm = new form("passageenprod", "prod_cron.php", false, "POST", "Editer le script de passage en production");
    $frm->allow_only_one_usage();
    $frm->add_hidden("action","scriptprod");
Ayolo's avatar
bleh  
Ayolo committed
129 130 131 132 133
    $frm->add_text_area("__script__", "Script : ",$script,80,40);
    $frm->add_submit("valid","Valider");
    $cts->add($frm,true);
  }
}
Skia's avatar
Skia committed
134
else if($_REQUEST["view"]=="commit")
Ayolo's avatar
bleh  
Ayolo committed
135 136
{
  if(!$handle = @fopen(POST_COMMIT_SCRIPT, "r"))
Ayolo's avatar
bleh  
Ayolo committed
137
    $cts->add_paragraph("Impossible d'ouvrir le script de post commit !");
Ayolo's avatar
bleh  
Ayolo committed
138 139 140
  else
  {
    $script = @fread($handle, @filesize(POST_COMMIT_SCRIPT));
Ayolo's avatar
bleh  
Ayolo committed
141
    $frm = new form("postcommit", "prod_cron.php", false, "POST", "Editer le script de post commit");
Ayolo's avatar
bleh  
Ayolo committed
142 143 144
    $frm->allow_only_one_usage();
    $frm->add_hidden("action","scriptpostcommit");
    $frm->add_text_area("__script__", "Script : ",$script,80,40);
Ayolo's avatar
bleh  
Ayolo committed
145 146 147 148
    $frm->add_submit("valid","Valider");
    $cts->add($frm,true);
  }
}
Skia's avatar
Skia committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
else if($_REQUEST["view"]=="refreshdbscript")
{
  if(!$handle = @fopen(REFRESH_TAISTE, "r"))
    $cts->add_paragraph("Impossible d'ouvrir le script de rafraichissement !");
  else
  {
    $script = @fread($handle, @filesize(REFRESH_TAISTE));
    $frm = new form("refreshdbscript", "prod_cron.php", false, "POST", "Editer le script de refresh de taiste");
    $frm->allow_only_one_usage();
    $frm->add_hidden("action","refreshdbscript");
    $frm->add_text_area("__script__", "Script : ",$script,80,40);
    $frm->add_submit("valid","Valider");
    $cts->add($frm,true);
  }
}
else if ($_REQUEST["view"] == "refreshdb")
{
  if ($_REQUEST["action"] == "refreshdb" && $Ok) {
    $cts->add_paragraph("<b>Fafraichissement programmé dans les deux minutes à venir.</b>");
  } else {
    $frm = new form("refreshdb", "prod_cron.php", false, "POST", "Rafraichir la BDD de taiste");
    $frm->allow_only_one_usage();
    $frm->add_hidden("action","refreshdb");
    $frm->add_submit("valid","Valider");
    $cts->add($frm,true);
  }
}
Ayolo's avatar
bleh  
Ayolo committed
176 177
else
{
Antoine Tenart's avatar
Antoine Tenart committed
178
  if ($_REQUEST["action"] == "passprod" && $Ok) {
Antoine Tenart's avatar
Antoine Tenart committed
179
    $cts->add_paragraph("<b>Passage en prod programmé dans les deux minutes à venir.</b>");
Antoine Tenart's avatar
Antoine Tenart committed
180 181 182 183 184 185 186
  } else {
    $frm = new form("passageenprod", "prod_cron.php", false, "POST", "Passer en production");
    $frm->allow_only_one_usage();
    $frm->add_hidden("action","passprod");
    $frm->add_submit("valid","Valider");
    $cts->add($frm,true);
  }
Ayolo's avatar
bleh  
Ayolo committed
187 188
}

Ayolo's avatar
Ayolo committed
189 190 191 192 193
$site->add_contents($cts);

$site->end_page();

?>