index.php 13.8 KB
Newer Older
root's avatar
root 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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
<?php
if (isset($_POST['form_id'])) {
	$action=$_POST['form_id'];

	if ($action == "create")  {
		$nom_instance=escapeshellarg($_POST['rep_nom_instance']);
		$rep_ndd=escapeshellarg($_POST['rep_ndd']);
		$rep_group_name=escapeshellarg($_POST['rep_group_name']);
		$rep_coord_name=escapeshellarg($_POST['rep_coord_name']);
		$rep_coord_mail=escapeshellarg($_POST['rep_coord_mail']);
		$rep_coord_tel=escapeshellarg($_POST['rep_coord_tel']);
		$rep_login_admin=escapeshellarg($_POST['rep_login_admin']);
		$rep_mail_admin=escapeshellarg($_POST['rep_mail_admin']);
		$rep_pwd_admin=escapeshellarg($_POST['rep_pwd_admin']);
		exec("sudo scripts/repaniers_create.sh $nom_instance $rep_ndd $rep_group_name $rep_coord_name $rep_coord_mail $rep_coord_tel $rep_login_admin $rep_mail_admin $rep_pwd_admin", $output, $ret_code);

		$rep_ndd = $_POST['rep_ndd'];
	} else {
		$choice=$_POST['choice'];
		$arr_data=preg_split("/\|/", $choice);
		$env=$arr_data[0];
		$instance=$arr_data['1'];
		$rep_ndd = "https://".$arr_data['2'];

		if ($action == "update") {
			exec("sudo scripts/repaniers_update.sh $env $instance", $output, $ret_code);
		} else if ($action == "restore")  {
			exec("sudo scripts/repaniers_restore.sh $env $instance", $output, $ret_code);
		} else if ($action == "delete")  {
			exec("sudo scripts/repaniers_delete.sh $env $instance", $output, $ret_code);
		}
	}

} else {
	$output = shell_exec("sudo scripts/repaniers_get_infos.sh");
	$arr_projets=preg_split("/[\s]+/", $output);
	$arr_all_list=array();
	$arr_all_updates=array();
	$arr_all_restore=array();
	$arr_all_delete=array();
	$arr_temp=array();

	for ($i = 0; $i < count($arr_projets); $i++) {
		$projet=$arr_projets[$i];

		if (empty($projet)) continue;

		$infos=preg_split("/\|/", $projet);
		$infos_commit=preg_split("/_/", $infos[1]);
		$commit="(commit ".$infos_commit[0]." du ".preg_replace("/-/", " ", $infos_commit[1]).")";
		$rep_ndd=$infos[4];

		$arr_action=preg_split("/_/", $infos[3]);
		$what=$arr_action[0];
		if ($what == "update") {
			$arr_all_updates[$infos[0]]["commit"]=$commit;
			$arr_all_updates[$infos[0]][]=$infos[2]."|".$rep_ndd;
		} else {
	        $arr_all_restore[$infos[0]]["commit"]=$commit;
	        $arr_all_restore[$infos[0]][]=array($infos[2]."|".$rep_ndd, $arr_action[1]);
		}
		if (! in_array($infos[2], $arr_temp)) {
			$arr_all_list[$infos[0]."|".$infos[2]]=$rep_ndd;
			$arr_temp[]=$infos[2];
		}
		$arr_all_delete[$infos[0]]["commit"]=$commit;
		$arr_all_delete[$infos[0]][]=$infos[2]."|".$rep_ndd;
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Gestion des instances repaniers</title>
  <link rel="stylesheet" type="text/css" href="css/view.css" media="all">
  <script type="text/javascript" src="js/view.js"></script>
  <script type="text/javascript" src="js/tabs.js"></script>
</head>
<body id="main_body" >
	
	<img id="top" src="images/top.png" alt="">
	<div id="form_container">
		<h1>Gestion repanier</h1>
		<?php
		if (isset($action)) {
		?>
		<div style="width:100%;">
			<?php
				if ($ret_code > 0) {
					$style="color:red;";
					$msg="ECHEC";
				} else {
					$style="color:green;";
					$msg_lien="";
					if ($action != "delete") $msg_lien="<br />Acc&egrave;s: <a href=\"$rep_ndd\" target='_blank'>$rep_ndd</a>";

					$msg="SUCC&Egrave;S".$msg_lien;
				}
			?>
			<div style="font-weight:bold;width:90%; margin:0 auto;margin-top:1em;font-size:16px;text-align:center;<?php echo $style; ?>">
				<?php echo $msg; ?>
			</div>
			<div style="font-weight:bold;width:90%; margin:0 auto;margin-top:1em">Logs:</div>
			<div style="max-height:300px; width:90%; margin:0 auto 1em auto; padding:0.3em; border:1px solid black; text-align:left; overflow-y: scroll;">
				<?php
				$saut="";
				foreach ($output as $k => $v) {
					if ($v == "</pre>") $saut="";
					echo $v.$saut;
					if ($v == "<pre>") $saut="<br />";
				}
				?>
			</div>
		</div>
		<form class="appnitro"  method="post" action="">
			<div class="form_description">
				<ul >
					<li class="buttons">
						<input class="button_text" type="submit" name="submit" onclick="location.href = '/gestion/index.php?<?php echo time();?>';" value="Retour" />
					</li>
				</ul>
			</div>
		</form>
		<?php
		} else {
		?>
		<div class="tab">
          <button class="tablinks" onclick="opentab(event, 'repanier_list')" id="defaultOpen">Liste</button>
          <button class="tablinks" onclick="opentab(event, 'repanier_create')" >Cr&eacute;er</button>
          <button class="tablinks" onclick="opentab(event, 'repanier_update')">Mise &agrave; jour</button>
          <button class="tablinks" onclick="opentab(event, 'repanier_restore')">Restaurer</button>
          <button class="tablinks" onclick="opentab(event, 'repanier_delete')">Suppression</button>
		</div>

		<div id="repanier_list" class="tabcontent">
			<div style="max-height:300px; width:90%; margin:0 auto 1em auto; padding:0.3em; border:1px solid black; text-align:left; overflow-y: scroll;">
				<?php
				$prd="";
				echo "<ul>";
				foreach ($arr_all_list as $k => $v) {
					$arr_infos=preg_split("/\|/", $k);
					if ($prd != $arr_infos[0]) {
						echo "</ul><ul style='padding-left:1em;'><b>".$arr_infos[0]."</b>";
						$prd=$arr_infos[0];
					}

					echo "<li style='margin-left:2em;'>".$arr_infos[1]." -> <a href='https://".$v."' target='_blank'>https://".$v."</a></li>";
				}
				?>
			</div>
		</div>

		<div id="repanier_create" class="tabcontent">
		  <form id="rep_form_create" class="appnitro"  method="post" action="">
			<ul >
				<li id="li_1" >
					<label class="description" for="rep_nom_instance">Nom de l'instance </label>
					<div>
						<input id="rep_nom_instance" name="rep_nom_instance" class="element text medium" type="text" maxlength="20" required value="" title="Min 3 caract&egrave;res + voir description  &agrave; droite" pattern="[A-Za-z0-9_]{3,30}" autofocus/> 
					</div>
					<p class="guidelines" id="guide_1"><small>Se limiter aux caract&eagrave;res classiques, pas d'espace (mettre un '_' &agrave; la place), pas de caract&eagrave;res accentu&eacute;s et pas de - (tiret)</small></p> 
				</li>
				<li id="li_2" >
					<label class="description" for="rep_ndd">Nom de domaine </label>
					<div>
						<input id="rep_ndd" name="rep_ndd" class="element text medium" type="url" maxlength="75" required value="" title="Ex: https://repanier.gasap.be" pattern="^(https?://)([a-zA-Z0-9]([a-zA-Z-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$"/> 
					</div>
					<p class="guidelines" id="guide_2"><small>Le nom de domaine doit d&eacute;j&agrave; pointer vers le serveur.</small></p> 
				</li>
				<li class="section_break"></li>
				<li id="li_4" >
					<label class="description" for="rep_group_name">Nom du groupe </label>
					<div>
						<input id="rep_group_name" name="rep_group_name" class="element text medium" type="text" maxlength="30" required value="" title="3 caract&egrave;res min. et pas d'accents ni caract&egrave;res sp&eacute;ciaux" pattern="[A-Za-z0-9_ \-\.]{3,30}"/> 
					</div> 
				</li>
				<li id="li_5" >
					<label class="description" for="rep_coord_name">Nom du coordinateur </label>
					<div>
						<input id="rep_coord_name" name="rep_coord_name" class="element text medium" type="text" maxlength="30" required value=""/> 
					</div>
				</li>
				<li id="li_6" >
					<label class="description" for="rep_coord_mail">Mail du coordinateur </label>
					<div>
						<input id="rep_coord_mail" name="rep_coord_mail" class="element text medium" type="email" maxlength="30" required value="" title="Ex: qqun@qqpart.world"/> 
					</div> 
				</li>
				<li id="li_7" >
					<label class="description" for="rep_coord_tel">T&eacute;l&eacute;phone du coordinateur </label>
					<div>
						<input id="rep_coord_tel" name="rep_coord_tel" class="element text medium" type="text" maxlength="20" required value="" title="Ex: 0495/32.67.12 ou 32(0)495 32 67 12" pattern="[0-9 \/\.\-\(\)]{6,20}"/> 
					</div> 
				</li>
				<li class="section_break"></li>
				<li id="li_8" >
					<label class="description" for="rep_login_admin">Login de l'admin </label>
					<div>
						<input id="rep_login_admin" name="rep_login_admin" class="element text medium" type="text" maxlength="20" required value="" title="Min 3 caract&egrave;res + voir description  &agrave; droite" pattern="[A-Za-z0-9_-]{3,30}" autofocus/> 
					</div>
					<p class="guidelines" id="guide_8"><small>Se limiter aux caract&eagrave;res classiques, pas d'espace (mettre un '_' &agrave; la place), pas de caract&eagrave;res accentu&eacute;s</small></p> 
				</li>
				<li id="li_9" >
					<label class="description" for="rep_mail_admin">Mail de l'admin </label>
					<div>
						<input id="rep_mail_admin" name="rep_mail_admin" class="element text medium" type="email" maxlength="30" required value="" title="Ex: qqun@qqpart.world"/> 
					</div> 
				</li>
				<li id="li_10" >
					<label class="description" for="rep_pwd_admin">Mot de passe de l'admin </label>
					<div>
						<input id="rep_pwd_admin" name="rep_pwd_admin" class="element text medium" type="password" maxlength="25" required value="" title="Le mot de passe est requis et doit avoir min 6 caract&egrave;res" pattern=".{6,}"> 
					</div> 
				</li>
			
				<li class="buttons">
					<input type="hidden" name="form_id" value="create" />
					<input id="saveForm" class="button_text" type="submit" name="submit" value="D&eacute;marrer la cr&eacute;ation de l'instance" />
				</li>
			</ul>
		  </form>
		</div>

		<div id="repanier_update" class="tabcontent">
		  <form class="appnitro"  method="post" action="">
			<div class="form_description">
				<ul>
					<li style="width:100%;">
						<label class="description" for="rep_select_update">Choisir l'instance &agrave; mettre &agrave; jour: </label>
							<div>
								<select class="element select medium" id="rep_select_update" name="choice" size="8" style="width:100%;">
									<?php
									$optgroup = "";
									$count = 0;
									foreach ($arr_all_updates as $k => $v) {
										if ($optgroup != $k) {
											if ($count == 0) echo "</optgroup>";

											echo "<optgroup label=\"$k ".$v['commit']."\">";
											$optgroup = $k;
										}

										unset($v['commit']);

										foreach ($v as $k2 => $v2) {
											echo "<option value=\"$k|$v2\" >$v2</option>";
										}
									}
									echo "</optgroup>";
									?>
								</select>
							</div>
					</li>
					<li class="buttons">
					    <input type="hidden" name="form_id" value="update" />
						<input id="submit_update" class="button_text" type="submit" name="submit" onclick="return confirmation('mettre &agrave; jour');" disabled=disabled value="Mettre &agrave; jour" />
					</li>
				</ul>
			</div>
		  </form>
		</div>

		<div id="repanier_restore" class="tabcontent">
		  <form class="appnitro"  method="post" action="">
			<div class="form_description">
				<ul>
					<li style="width:100%;">
						<label class="description" for="rep_select_restore">Choisir l'instance &agrave; restaurer: </label>
							<div>
								<select class="element select medium" id="rep_select_restore" name="choice" size="8" style="width:100%;"> 
									<?php
									$optgroup = "";
									$count = 0;
									foreach ($arr_all_restore as $k => $v) {
										if ($optgroup != $k) {
											if ($count == 0) echo "</optgroup>";

											echo "<optgroup label=\"$k ".$v['commit']."\">";
											$optgroup = $k;
										}

										unset($v['commit']);

										foreach ($v as $k2 => $v2) {
											$disable="";
											if ($v2[1] == "disabled") $disable="disabled=disabled"; 

											echo "<option value=\"$k|$v2[0]\" $disable >$v2[0]</option>";
										}
									}
									echo "</optgroup>";
									?>
								</select>
							</div>
					</li>
		
					<li class="buttons">
					    <input type="hidden" name="form_id" value="restore" />
						<input id="submit_restore" class="button_text" type="submit" name="submit" onclick="return confirmation('restaurer');" disabled=disabled value="Restaurer" />
					</li>
				</ul>
			</div>
		  </form>
		</div>

		<div id="repanier_delete" class="tabcontent">
		  <form class="appnitro"  method="post" action="">
			<div class="form_description">
				<ul >
					<li style="width:100%;">
						<label class="description" for="rep_select_del">Choisir l'instance &agrave; supprimer: </label>
							<div>
								<select class="element select medium" id="rep_select_del" name="choice" size="8" style="width:100%;"> 
									<?php
									$optgroup = "";
									$count = 0;
									foreach ($arr_all_delete as $k => $v) {
										if ($optgroup != $k) {
											if ($count == 0) echo "</optgroup>";

											echo "<optgroup label=\"$k ".$v['commit']."\">";
											$optgroup = $k;
										}

										unset($v['commit']);

										foreach ($v as $k2 => $v2) {
											echo "<option value=\"$k|$v2\" >$v2</option>";
										}
									}
									echo "</optgroup>";
									?>
								</select>
							</div>
					</li>
		
					<li class="buttons">
					    <input type="hidden" name="form_id" value="delete" />
						<input id="submit_delete" class="button_text" type="submit" name="submit" onclick="return confirmation('supprimer');" disabled=disabled value="Supprimer" />
					</li>
				</ul>
			</div>
		  </form>
		</div>
		<?php
		}
		?>
	</div>
	<div id="overlay">
		<div id="overlay_text"><img  src="images/loader.gif" /><br />patience</div>
	</div> 
	<img id="bottom" src="images/bottom.png" alt="">
<script>
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click(); 

function confirmation(txt) {
	msg="Es-tu sur vouloir "+txt+" cette instance?"
    if (txt == "supprimer") {
		msg=msg+"\n\n ATTENTION\nToutes les versions de cette instance seront supprimees"
	}

	if (confirm(msg)) {
		document.getElementById("overlay").style.display = "block";
		return true;
	} else {
		return false;
	}
}
</script>
</body>
</html>