Subversion Repositories ALCASAR

Rev

Rev 3319 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3319 Rev 3320
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
// written by Alexandre BOUIJOUX
3
// written by Alexandre BOUIJOUX (mainly) & Rexy
4
 
4
 
5
/*******************
5
/*******************
6
 * READ CONF FILES *
6
 * READ CONF FILES *
7
 ******************/
7
 ******************/
8
define('CONF_FILE', '/usr/local/etc/alcasar.conf');
8
define('CONF_FILE', '/usr/local/etc/alcasar.conf');
Line 70... Line 70...
70
	$l_delete		= "Supprimer";
70
	$l_delete		= "Supprimer";
71
	$l_error_details	= "Détails des erreurs";
71
	$l_error_details	= "Détails des erreurs";
72
	$l_field		= "Champ";
72
	$l_field		= "Champ";
73
	$l_go_network_conf_page	= "Allez sur la page de configuration réseau.";
73
	$l_go_network_conf_page	= "Allez sur la page de configuration réseau.";
74
	$l_host_name		= "Nom d'hôte";
74
	$l_host_name		= "Nom d'hôte";
75
	$l_hosts_settings	= "Paramètres de réplication des hôtes";
75
	$l_hosts_settings	= "Paramètres de réplication des hôtes distants";
76
	$l_import_ssh_key	= "Si cet ALCASAR est primaire, importez ici les clés publiques des secondaires";
76
	$l_import_ssh_key	= "Si cet ALCASAR est primaire, importez ici les clés publiques des secondaires";
77
	$l_install_repl		= "Installer la fédération";
77
	$l_install_repl		= "Installer la fédération";
-
 
78
	$l_remote_hosts		= "Hôtes distants";
78
	$l_ip_address		= "Adresse IP";
79
	$l_ip_address		= "Adresse IP";
79
	$l_no_host_connected = "Aucun hote connecté";
80
	$l_no_host_connected = "Aucun hote connecté";
80
	$l_no_ssh_key		= "Aucune clé SSH importée.";
81
	$l_no_ssh_key		= "Aucune clé SSH importée.";
81
	$l_not_connected	= "Non connecté";
82
	$l_not_connected	= "Non connecté";
82
	$l_pubkey_to_deploy	= "Si cet ALCASAR est secondaire, copiez la clé publique ci-dessous pour l'importez dans le primaire.";
83
	$l_pubkey_to_deploy	= "Si cet ALCASAR est secondaire, copiez la clé publique ci-dessous pour l'importez dans le primaire.";
Line 86... Line 87...
86
	$l_started		= "Démarré";
87
	$l_started		= "Démarré";
87
	$l_stopped		= "Arrêté";
88
	$l_stopped		= "Arrêté";
88
	$l_in_progress		= "En cours ...";
89
	$l_in_progress		= "En cours ...";
89
	$l_replication_install	= "Installer la Fédération";
90
	$l_replication_install	= "Installer la Fédération";
90
	$l_replication_title	= "Fédération";
91
	$l_replication_title	= "Fédération";
-
 
92
	$l_role			= "Rôle";
91
	$l_role_primary		= "Primaire";
93
	$l_role_primary		= "Primaire";
92
	$l_role_secondary	= "Secondaire";
94
	$l_role_secondary	= "Secondaire";
93
	$l_ssh_keys_for_primary	= "Liste des secondaires autorisées à se connecter";
95
	$l_ssh_keys_for_primary	= "Liste des secondaires autorisées à se connecter";
94
	$l_ssh_port		= "Port SSH";
96
	$l_ssh_port		= "Port SSH";
95
	$l_ssh_user		= "Utilisateur SSH";
97
	$l_ssh_user		= "Utilisateur SSH";
Line 113... Line 115...
113
	$l_delete		= "Eliminar";
115
	$l_delete		= "Eliminar";
114
	$l_error_details	= "Detalles de los errores";
116
	$l_error_details	= "Detalles de los errores";
115
	$l_field		= "campo";
117
	$l_field		= "campo";
116
	$l_go_network_conf_page	= "Vaya a la página de configuración de red";
118
	$l_go_network_conf_page	= "Vaya a la página de configuración de red";
117
	$l_host_name		= "Nombre de host";
119
	$l_host_name		= "Nombre de host";
118
	$l_hosts_settings	= "Parámetros de replicación de los hosts";
120
	$l_hosts_settings	= "Configuración de replicación de hosts remotos";
119
	$l_import_ssh_key	= "Importar una clave SSH";
121
	$l_import_ssh_key	= "Importar una clave SSH";
120
	$l_install_repl		= "Creación de la federación";
122
	$l_install_repl		= "Creación de la federación";
-
 
123
	$l_remote_hosts		= "Hosts remotos";
121
	$l_ip_address		= "dirección IP";
124
	$l_ip_address		= "dirección IP";
122
	$l_no_host_connected = "No hay ningún host conectado.";
125
	$l_no_host_connected = "No hay ningún host conectado.";
123
	$l_no_ssh_key		= "No se ha importado ninguna clave SSH.";
126
	$l_no_ssh_key		= "No se ha importado ninguna clave SSH.";
124
	$l_not_connected	= "No conectado";
127
	$l_not_connected	= "No conectado";
125
	$l_pubkey_to_deploy	= "La clave debe implementarse en los servidores primarios.";
128
	$l_pubkey_to_deploy	= "La clave debe implementarse en los servidores primarios.";
Line 129... Line 132...
129
	$l_started		= "Iniciado";
132
	$l_started		= "Iniciado";
130
	$l_stopped		= "Decreto";
133
	$l_stopped		= "Decreto";
131
	$l_in_progress		= "En curso ...";
134
	$l_in_progress		= "En curso ...";
132
	$l_replication_install	= "Creación de la federación";
135
	$l_replication_install	= "Creación de la federación";
133
	$l_replication_title	= "Federación";
136
	$l_replication_title	= "Federación";
-
 
137
	$l_role			= "Papel";
134
	$l_role_primary		= "Primaria";
138
	$l_role_primary		= "Primaria";
135
	$l_role_secondary	= "Secundaria";
139
	$l_role_secondary	= "Secundaria";
136
	$l_ssh_keys_for_primary	= "Lista de claves autorizadas para conectarse al usuario local «replication».";
140
	$l_ssh_keys_for_primary	= "Lista de claves autorizadas para conectarse al usuario local «replication».";
137
	$l_ssh_port		= "Puerto SSH";
141
	$l_ssh_port		= "Puerto SSH";
138
	$l_ssh_user		= "Usuario SSH";
142
	$l_ssh_user		= "Usuario SSH";
Line 156... Line 160...
156
	$l_delete		= "Delete";
160
	$l_delete		= "Delete";
157
	$l_error_details	= "Error details";
161
	$l_error_details	= "Error details";
158
	$l_field		= "Field";
162
	$l_field		= "Field";
159
	$l_go_network_conf_page	= "Go to network config page.";
163
	$l_go_network_conf_page	= "Go to network config page.";
160
	$l_host_name		= "Host name";
164
	$l_host_name		= "Host name";
161
	$l_hosts_settings	= "Replicated hosts settings";
165
	$l_hosts_settings	= "Remote replicated hosts settings";
162
	$l_import_ssh_key	= "Import a SSH key";
166
	$l_import_ssh_key	= "Import a SSH key";
163
	$l_install_repl		= "Setting up the federation";
167
	$l_install_repl		= "Setting up the federation";
-
 
168
	$l_remote_hosts		= "Remote hosts";
164
	$l_ip_address		= "IP address";
169
	$l_ip_address		= "IP address";
165
	$l_no_host_connected = "No host connected";
170
	$l_no_host_connected = "No host connected";
166
	$l_no_ssh_key		= "No SSH key imported.";
171
	$l_no_ssh_key		= "No SSH key imported.";
167
	$l_not_connected	= "Not connected";
172
	$l_not_connected	= "Not connected";
168
	$l_pubkey_to_deploy	= "The following public key has to be deployed on remote primary servers.";
173
	$l_pubkey_to_deploy	= "The following public key has to be deployed on remote primary servers.";
Line 172... Line 177...
172
	$l_started		= "Started";
177
	$l_started		= "Started";
173
	$l_stopped		= "Stopped";
178
	$l_stopped		= "Stopped";
174
	$l_in_progress		= "In progress...";
179
	$l_in_progress		= "In progress...";
175
	$l_replication_install	= "Setting up the federation";
180
	$l_replication_install	= "Setting up the federation";
176
	$l_replication_title	= "Federation";
181
	$l_replication_title	= "Federation";
-
 
182
	$l_role			= "Role";
177
	$l_role_primary		= "Primary";
183
	$l_role_primary		= "Primary";
178
	$l_role_secondary	= "Secondary";
184
	$l_role_secondary	= "Secondary";
179
	$l_ssh_keys_for_primary	= "List of keys allowed to connect to local 'replication' user.";
185
	$l_ssh_keys_for_primary	= "List of keys allowed to connect to local 'replication' user.";
180
	$l_ssh_port		= "SSH port";
186
	$l_ssh_port		= "SSH port";
181
	$l_ssh_user		= "SSH user";
187
	$l_ssh_user		= "SSH user";
Line 217... Line 223...
217
	case 'add_replica':
223
	case 'add_replica':
218
		$role = trim($_POST['role'] ?? "");
224
		$role = trim($_POST['role'] ?? "");
219
		$name = trim($_POST['name'] ?? "");
225
		$name = trim($_POST['name'] ?? "");
220
		$ip = trim($_POST['ip'] ?? "");
226
		$ip = trim($_POST['ip'] ?? "");
221
		$port = trim($_POST['port'] ?? "");
227
		$port = trim($_POST['port'] ?? "");
222
		// we fix ssh user name to simplify ACC
228
		// we fix ssh_user, db_user to simplify ACC
223
		// $user = trim($_POST['user'] ?? "");
229
		// $user = trim($_POST['user'] ?? "");
224
		$user = "replication" ;
-
 
225
		// we fix db user name to simplify ACC
-
 
226
		// $db_user = trim($_POST['db_user'] ?? "");
230
		// $db_user = trim($_POST['db_user'] ?? "");
-
 
231
		$user = "replication" ;
227
		$db_user = "db_replication";
232
		$db_user = "db_replication";
-
 
233
		// we retrieve db_pwd via SSH to simplify ACC
228
		$db_pwd = trim($_POST['db_pwd'] ?? "");
234
		//$db_pwd = trim($_POST['db_pwd'] ?? "");
-
 
235
		$db_pwd = "no more used : set via ssh";
229
		$bind_port = trim($_POST['bind_port'] ?? "");
236
		$bind_port = trim($_POST['bind_port'] ?? "");
230
		$stdout = [];
237
		$stdout = [];
231
		$return = 0;
238
		$return = 0;
232
		switch ($role) {
239
		switch ($role) {
233
			case 'primary':
240
			case 'primary':
Line 340... Line 347...
340
	<title><?= $l_replication_title ?></title>
347
	<title><?= $l_replication_title ?></title>
341
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
348
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
342
	<script src="/js/jquery.min.js"></script>
349
	<script src="/js/jquery.min.js"></script>
343
	<script src="/js/jquery.connections.js"></script>
350
	<script src="/js/jquery.connections.js"></script>
344
	<script type="text/javascript">
351
	<script type="text/javascript">
-
 
352
		// listener to enable submitbutton only when forms are completed
-
 
353
		document.addEventListener('DOMContentLoaded', function() {
-
 
354
			const rolePrimaryRadio = document.getElementById('role_primary');
-
 
355
			const roleSecondaryRadio = document.getElementById('role_secondary');
-
 
356
			const nameInput = document.getElementById('input_name');
-
 
357
			const ipInput = document.getElementById('input_ip');
-
 
358
			const bindPortInput = document.getElementById('input_bind_port');
-
 
359
			const portInput = document.getElementById('input_port');
-
 
360
			const submitButton = document.getElementById('apply_add_remote');
-
 
361
			// madatory fields in relation to role
-
 
362
			function checkRequiredFields() {
-
 
363
				let allFilled = false;
-
 
364
				if (rolePrimaryRadio.checked) {
-
 
365
			// primary : name, ip, port
-
 
366
				allFilled = nameInput.value.trim() !== '' &&
-
 
367
					ipInput.value.trim() !== '' &&
-
 
368
					portInput.value.trim() !== '';
-
 
369
				} else if (roleSecondaryRadio.checked) {
-
 
370
			// secondary : name, bind_port
-
 
371
				allFilled = nameInput.value.trim() !== '' &&
-
 
372
				bindPortInput.value.trim() !== '';
-
 
373
				}
-
 
374
			submitButton.disabled = !allFilled;
-
 
375
			}
-
 
376
			// Events listening
-
 
377
			nameInput.addEventListener('input', checkRequiredFields);
-
 
378
			ipInput.addEventListener('input', checkRequiredFields);
-
 
379
			bindPortInput.addEventListener('input', checkRequiredFields);
-
 
380
			portInput.addEventListener('input', checkRequiredFields);
-
 
381
			// disable on load
-
 
382
			submitButton.disabled = true;
-
 
383
		});
345
		window.onload = main;
384
		window.onload = main;
346
		function main() {
385
		function main() {
347
			show_fields_for_new_primary();
386
			show_fields_for_new_primary();
348
			set_required_on_common_fields();
387
			set_required_on_common_fields();
349
			enable_apply_btn_if_selected_primary_action();
388
			enable_apply_btn_if_selected_remote_action();
350
			enable_apply_btn_if_selected_ssh_key_action();
389
			enable_apply_btn_if_selected_ssh_key_action();
351
		}
390
		}
352
		// Set 'required' attribute on fields needed by both primary and secondary
391
		// Set 'required' attribute on fields needed by both primary and secondary
353
		function set_required_on_common_fields() {
392
		function set_required_on_common_fields() {
354
			document.querySelectorAll(".role_primary.role_secondary").forEach((input) => {
393
			document.querySelectorAll(".role_primary.role_secondary").forEach((input) => {
Line 377... Line 416...
377
				input.setAttribute("required", "");
416
				input.setAttribute("required", "");
378
				input.removeAttribute("disabled");
417
				input.removeAttribute("disabled");
379
			});
418
			});
380
		}
419
		}
381
		// Enable the remote's list Apply button if there are any pending actions
420
		// Enable the remote's list Apply button if there are any pending actions
382
		function enable_apply_btn_if_selected_primary_action() {
421
		function enable_apply_btn_if_selected_remote_action() {
383
			let btn = document.querySelector("#apply_changes_primary_btn");
422
			let btn = document.querySelector("#apply_changes_remote_btn");
384
			if (!btn) {
423
			if (!btn) {
385
				return;}
424
				return;}
386
			let change_to_apply = false;
425
			let change_to_apply = false;
387
			// Check for any pending change
426
			// Check for any pending change
388
			document.querySelectorAll(".primary_action_select").forEach((element) => {
427
			document.querySelectorAll(".primary_action_select").forEach((element) => {
Line 430... Line 469...
430
	<tr>
469
	<tr>
431
		<td width="50%" align="center">
470
		<td width="50%" align="center">
432
			<?php $section = "change_replicas_state" ?>
471
			<?php $section = "change_replicas_state" ?>
433
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
472
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
434
			<input type="hidden" name="choice" value="<?= $section ?>">
473
			<input type="hidden" name="choice" value="<?= $section ?>">
-
 
474
			<center><?= $l_remote_hosts ?></center>
435
			<table cellspacing="2" cellpadding="3" border="1" style="table-layout: auto; min-width: 10em;">
475
			<table cellspacing="2" cellpadding="3" border="1" style="table-layout: auto; min-width: 10em;">
436
				<tr>
476
				<tr>
437
					<th><?= $l_ip_address ?></th>
477
					<th><?= $l_ip_address ?></th>
438
					<th><?= $l_host_name ?></th>
478
					<th><?= $l_host_name ?></th>
-
 
479
					<th><?= $l_role ?></th>
439
					<th><?= $l_repl_io_running ?></th>
480
					<th><?= $l_repl_io_running ?></th>
440
					<th><?= $l_bind_port ?></th>
481
					<th><?= $l_bind_port ?></th>
441
					<th><?= $l_action ?></th>
482
					<th><?= $l_action ?></th>
442
				</tr>
483
				</tr>
443
				<?php
484
				<?php
Line 488... Line 529...
488
								} else {
529
								} else {
489
									echo "$l_not_connected";
530
									echo "$l_not_connected";
490
								}
531
								}
491
							?></td>
532
							?></td>
492
							<td><?= $prim["Connection_name"] ?></td>
533
							<td><?= $prim["Connection_name"] ?></td>
-
 
534
							<td><?php
-
 
535
								if ($conf['REPLICATION_TO'] == "") { echo "$l_role_secondary"; }
-
 
536
									else { echo "$l_role_primary"; }
-
 
537
								?></td>
493
							<td>
538
							<td>
494
							<? if ($prim["Slave_IO_Running"] == "Yes") { echo "$l_started"; }
539
							<? if ($prim["Slave_IO_Running"] == "Yes") { echo "$l_started"; }
495
							   if ($prim["Slave_IO_Running"] == "No") { echo "$l_stopped"; }
540
							   if ($prim["Slave_IO_Running"] == "No") { echo "$l_stopped"; }
496
							   if ($prim["Slave_IO_Running"] == "Connecting") { echo "$l_in_progress"; }
541
							   if ($prim["Slave_IO_Running"] == "Connecting") { echo "$l_in_progress"; }
497
							?>
542
							?>
498
							</td>
543
							</td>
499
							<td><?= $prim["Master_Port"] ?></td>
544
							<td><?= $prim["Master_Port"] ?></td>
500
							<td>
545
							<td>
501
								<select name="action_primary_<?= $prim["Connection_name"] ?>" class="primary_action_select" onchange="enable_apply_btn_if_selected_primary_action()">
546
								<select name="action_primary_<?= $prim["Connection_name"] ?>" class="primary_action_select" onchange="enable_apply_btn_if_selected_remote_action()">
502
									<option value=""></option>
547
									<option value=""></option>
503
									<?php
548
									<?php
504
										// Actions available on all remotes
549
										// Actions available on all remotes
505
										$options = array(
550
										$options = array(
506
											"start" => "$l_start",
551
											"start" => "$l_start",
Line 528... Line 573...
528
								</select>
573
								</select>
529
							</td>
574
							</td>
530
						</tr>
575
						</tr>
531
					<?php }
576
					<?php }
532
					// Show submit button if there are primary servers connected
577
					// Show submit button if there are primary servers connected
533
					echo "<tr><td colspan=5 valign='middle' align='center'>";
578
					echo "<tr><td colspan=6 valign='middle' align='center'>";
534
					if (sizeof($connected_prims)) { ?>
579
					if (sizeof($connected_prims)) { ?>
535
						<input type="submit" id="apply_changes_primary_btn" value="<?= $l_apply ?>" onClick="document.getElementById('ldoverlay').style.display='block';">
580
						<input type="submit" id="apply_changes_remote_btn" value="<?= $l_apply ?>" onClick="document.getElementById('ldoverlay').style.display='block';">
536
					<?php } else { ?>
581
					<?php } else { ?>
537
						<p><?= $l_no_host_connected ?></p>
582
						<p><?= $l_no_host_connected ?></p>
538
					<?php }
583
					<?php }
539
					echo "</td></tr>";
584
					echo "</td></tr>";
540
				} ?>
585
				} ?>
Line 547... Line 592...
547
				</details>
592
				</details>
548
			<?php } ?>
593
			<?php } ?>
549
		</td>
594
		</td>
550
		<td width="50%" valign="middle" align="center">
595
		<td width="50%" valign="middle" align="center">
551
			<?php $section = "add_replica" ?>
596
			<?php $section = "add_replica" ?>
552
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
597
			<form id="form_add_remote" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
553
			<input type="hidden" name="choice" value="<?= $section ?>">
598
			<input type="hidden" name="choice" value="<?= $section ?>">
554
				<table cellspacing="2" cellpadding="3" border="1">
599
				<table cellspacing="2" cellpadding="3" border="1">
555
					<tr>
600
					<tr>
556
						<th><?= $l_field ?></th>
601
						<th><?= $l_field ?></th>
557
						<th><?= $l_value ?></th>
602
						<th><?= $l_value ?></th>
Line 584... Line 629...
584
					</tr>
629
					</tr>
585
					<tr>
630
					<tr>
586
						<td><label for="input_port"><?= $l_ssh_port ?></label></td>
631
						<td><label for="input_port"><?= $l_ssh_port ?></label></td>
587
						<td><input type="number" id="input_port" name="port" min="0" max="65535" class="role_primary" pattern="<?= $reg_ip_port ?>"></td>
632
						<td><input type="number" id="input_port" name="port" min="0" max="65535" class="role_primary" pattern="<?= $reg_ip_port ?>"></td>
588
					</tr>
633
					</tr>
-
 
634
<!--					<tr>
-
 
635
						<td><label for="input_db_user"><?= $l_db_user ?></label></td>
-
 
636
						<td><input type="text" id="input_db_user" name="db_user" class="role_primary role_secondary" pattern="<?= $reg_mariadb_user ?>"></td>
-
 
637
					</tr>
589
					<tr>
638
					<tr>
590
					<td><label for="input_db_pwd"><?= $l_db_pwd ?></label></td>
639
					<td><label for="input_db_pwd"><?= $l_db_pwd ?></label></td>
591
						<td><input type="password" id="input_db_pwd" name="db_pwd" class="role_primary role_secondary"></td>
640
						<td><input type="password" id="input_db_pwd" name="db_pwd" class="role_primary role_secondary"></td>
592
					</tr>
641
					</tr> -->
593
					<tr>
642
					<tr>
594
						<td colspan=2 valign="middle" align="center">
643
						<td colspan=2 valign="middle" align="center">
595
							<input type="submit" class="button" value="<?= $l_add_to_list ?>">
644
							<input type="submit" id="apply_add_remote" class="button" value="<?= $l_add_to_list ?>" onClick="document.getElementById('ldoverlay').style.display='block';">
596
						</td>
645
						</td>
597
					</tr>
646
					</tr>
598
				</table>
647
				</table>
599
			</form>
648
			</form>
600
			<?php if (isset($errors_msg[$section."_error"])) { ?>
649
			<?php if (isset($errors_msg[$section."_error"])) { ?>