--- /dev/null
+[{"id":"dummy","time":0,"action":"none","data":""}]
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta name='robots' content='noindex'>
+ <meta charset='utf-8'>
+ <title>Controller</title>
+ <style>
+ body{
+ color:#FFF;
+ background:#333;
+ }
+ .btn{
+ display:block;
+ width:90%;
+ background:#555;
+ font-size:20px;
+ margin:10px;
+ padding:15px;
+ border:none;
+ }
+ </style>
+ <script>
+ function send(action,data){
+ var req=new XMLHttpRequest();
+ req.open('POST','receiver.php',true);
+ req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
+ var id="";
+ for(var i=0;i<5;i++){
+ id+="abcdefghijklmnopqrstuvwxyz".charAt(Math.floor(Math.random()*26));
+ }
+ req.onload=function(){
+ document.getElementById('msg').innerHTML=req.response;
+ setTimeout(function(){
+ document.getElementById('msg').innerHTML="";
+ },2000);
+ };
+ req.onerror=function(){
+ document.getElementById('msg').innerHTML="CONNECT ERROR";
+ setTimeout(function(){
+ document.getElementById('msg').innerHTML="";
+ },2000);
+ };
+ req.send('cmd='+JSON.stringify({
+ action:action,
+ data:data,
+ id:id
+ }));
+ }
+ </script>
+ </head>
+ <body>
+ <input type='button' value='reload' class="btn" onclick="send('reload','')">
+ <input type='button' value='jump' class="btn" onclick="send('jump',prompt('ジャンプ先の選択',''))">
+ <div id="msg"></div>
+ </body>
+</html>
\ No newline at end of file
--- /dev/null
+//プログラム リモート コントローラー
+//プログラムの作成中に複数台の端末を一斉に制御し、更新やページ移動を簡単にできるようにしています。
+//plugin.js - 実際に制御されるプログラムに埋め込んでおきます。他のスクリプトには影響を与えません。
+window.addEventListener('load',function(){
+ //イベントストリームでserver.phpに接続
+ var stream=new EventSource('http://'+location.hostname+'/control/server.php');
+ //再読み込み
+ stream.addEventListener('reload',function(e){
+ if(localStorage.sshCtrlCmdId==JSON.parse(e.data).id){
+ return false;
+ }
+ localStorage.sshCtrlCmdId=JSON.parse(e.data).id;
+ location.reload();
+ });
+ //ページジャンプ
+ stream.addEventListener('jump',function(e){
+ if(localStorage.sshCtrlCmdId==JSON.parse(e.data).id){
+ return false;
+ }
+ localStorage.sshCtrlCmdId=JSON.parse(e.data).id;
+ location.href=JSON.parse(e.data).data;
+ });
+});
\ No newline at end of file
--- /dev/null
+<?php
+$d=json_decode($_POST['cmd'],true);
+$d['time']=time();
+$f=json_decode(file_get_contents('commands.json'));
+$f[]=$d;
+file_put_contents('commands.json',json_encode($f));
+echo 'SUCCESS!YOUR COMMAND WAS SENDED';
+?>
\ No newline at end of file
--- /dev/null
+<?php
+//プログラム リモート コントローラー
+//プログラムの作成中に複数台の端末を一斉に制御し、更新やページ移動を簡単にできるようにしています。
+//server.php - 遠隔操作の指令を配信するサーバーサイドプログラムです。
+header("Content-Type:text/event-stream\n\n");
+$last_id='dummy';
+while(1){
+ echo ":\n\n";
+ $p=json_decode(file_get_contents('commands.json'),true);
+ $current_cmd=$p[count($p)-1];
+ if($current_cmd['id']!=$last_id&&$current_cmd['time']>=time()-30){
+ echo 'event:'.$current_cmd['action']."\n";
+ echo 'data:'.json_encode($current_cmd)."\n\n";
+ $last_id=$current_cmd['id'];
+ }else if($current_cmd['id']!='dummy'&&$current_cmd['time']<time()-30){
+ array_pop($p);
+ file_put_contents('commands.json',json_encode($p));
+ }
+ ob_flush();
+ flush();
+ sleep(1);
+}
+?>
\ No newline at end of file