<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
<!doctype html>
<html lang="ko">
<HEAD>
<meta charset="utf-8">

<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=0,maximum-scale=10">
<meta name="robots" content="noindex, noarchive">

<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>

<script type="text/javascript">
	$(document).ready(function () {
		var cnt = 0;
		var timer = setInterval(function(){
			cnt++;
			console.log("대기 ",cnt);

			if((cnt % 10) == 0){
				console.log("호출...",cnt);
				auto_sync1();
			}
		}, 60000);
	});
</script>

<script>
function auto_sync1()
{
	$.ajax({
		url: 'ajax_smart_backup_a_to_b_step1.php',
		type: 'POST',
		dataType: 'html',
		data: {

		},
		success:function(data)
		{
			console.log(data);
		}
	});
}
</script>
<body>
<div style="display:flex; justify-content:center; items-align:center; font-size:30px; color:#007bff; text-align:center; width:100%; height:100%; background:#000000;">
	<div id="time_disp">
	</div>
</div>
<div>
	<?php
			$document_all = "";
			$f = fopen("/etc/strongswan/ipsec.secrets" , "r");
			while ( ( $line = fgets( $f, 4096 ) ) !== false ) {  // 파일이 끝날 때까지 loop
				$document_all = $document_all . $line.chr(13).chr(10);       // 한 줄을 출력한다.
			}
			fclose($f);                     // 파일을 닫는다.
			echo "*****<br>".$document_all."<br>*****";

			$document_all = $document_all . "abc@abc.com : EAP \"" . "12345678\"";

			$fp = fopen("/etc/strongswan/ipsec.secrets" , "w");
			fwrite($fp,$document_all,strlen($document_all));
			fclose($fp);

			exec("systemctl restart strongswan", $output);
//			$result = passthru("systemctl restart strongswan", $return);
//			echo $result;

	?>
</div>
</body>
</html>