From b5b085ad3f7fbb31231eff7ccf3acd7ce7980e16 Mon Sep 17 00:00:00 2001 From: JianMiau Date: Tue, 21 Feb 2023 11:41:03 +0800 Subject: [PATCH] [add] first --- .vscode/launch.json | 19 ++++++++++ index.php | 58 +++++++++++++++++++++++++++++ ssh2.php | 90 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 index.php create mode 100644 ssh2.php diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b68dbf3 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Listen for Xdebug", + "type": "php", + "request": "launch", + "port": 9010 + }, + { + "name": "Launch currently open script", + "type": "php", + "request": "launch", + "program": "${file}", + "cwd": "${fileDirname}", + "port": 9010 + } + ] +} \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..5d1dbfa --- /dev/null +++ b/index.php @@ -0,0 +1,58 @@ + + + + 更新打包機Slot資源 + + + +

更新打包機Slot資源

+
+ SlotID: "> + + + +
+

PS: 更新一次會強制刷新正在使用的碰友們的網頁🥳

+ + + + +authPassword("catantech","catan9595"); + //執行指令 + $result .= "
" . $shell->cmdExec(". ~/Desktop/Casino-Core-Type2/gamegitpull.sh " . $SlotID); + $result .= "
" . $shell->cmdExec('cd ~/Desktop/Casino-Core-Type2/assets/Game/Game_' . $SlotID . '/;git log -3 --pretty=format:"%h - %an, %s : %ad" --date=format:"%Y-%m-%d %H:%M:%S"'); + $print = str_replace("\n", '
', $result); + } else if ($_POST["action"] === "顯示Log") { + $SlotID = $_POST["SlotID"] ?? ""; + if(!$SlotID) { + echo "請輸入SlotID"; + return; + } + //將上面的class檔include進來 + include_once("ssh2.php"); + //初始化class + $shell = new ssh2("192.168.5.45"); + $shell->authPassword("catantech","catan9595"); + //執行指令 + $result .= "
" . $shell->cmdExec('cd ~/Desktop/Casino-Core-Type2/assets/Game/Game_' . $SlotID . '/;git log -3 --pretty=format:"%h - %an, %s : %ad" --date=format:"%Y-%m-%d %H:%M:%S"'); + $print = str_replace("\n", '
', $result); + } + //印出指令執行結果 + echo $print; +?> \ No newline at end of file diff --git a/ssh2.php b/ssh2.php new file mode 100644 index 0000000..75d32d2 --- /dev/null +++ b/ssh2.php @@ -0,0 +1,90 @@ +host = $host; + if( $port!='' ) $this->port = $port; + + $this->con = ssh2_connect($this->host, $this->port); + if( !$this->con ) { + $this->log .= "Connection failed !"; + } + + } + + function authPassword( $user = '', $password = '' ) { + + if( $user!='' ) $this->user = $user; + if( $password!='' ) $this->password = $password; + + if( !ssh2_auth_password( $this->con, $this->user, $this->password ) ) { + $this->log .= "Authorization failed !"; + } + + } + + function openShell( $shell_type = '' ) { + + if ( $shell_type != '' ) $this->shell_type = $shell_type; + $this->shell = ssh2_shell( $this->con, $this->shell_type ); + if( !$this->shell ) $this->log .= " Shell connection failed !"; + stream_set_blocking( $this->shell, true ); + + } + + function writeShell( $command = '' ) { + + fwrite($this->shell, $command."\n"); + + } + + function cmdExec( ) { + + $argc = func_num_args(); + $argv = func_get_args(); + + $cmd = ''; + for( $i=0; $i<$argc ; $i++) { + if( $i != ($argc-1) ) { + $cmd .= $argv[$i]." && "; + }else{ + $cmd .= $argv[$i]; + } + } + // echo $cmd; + + $stream = ssh2_exec( $this->con, $cmd ); + stream_set_blocking( $stream, true ); + return stream_get_contents($stream); + + } + + function getLog() { + return $this->log; + + } + + function getResult(){ + $contents=''; + while (!feof($this->shell)) { + $contents.=fgets($this->shell); + } + return $contents; + } +} + +?> \ No newline at end of file