標籤:web php html 可視化控制shell指令碼
1)查看php運行使用者:
<?php
system(‘id -a‘);
?>
一般php運行使用者是apache
2)給apache使用者做密鑰信任:
2.1)
先看看apache使用者的資訊:
# su - apache
This account is currently not available.
# cat /etc/passwd|grep apache
apache:x:48:48:Apache:/var/www:/sbin/nologin
改為:
apache:x:48:48:Apache:/var/www:/bin/bash
2.2)
root使用者上操作:
mkdir /var/www/.ssh
chown apache. /var/www/.ssh
2.3)
然後再切換到apache使用者:
su - apache
ssh-keygen -t rsa
2.4)
root使用者上操作,最後改回nologin:
apache:x:48:48:Apache:/var/www:/sbin/nologin
3)頁面寫法:
3.1)
cat /var/www/html/function/restart.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>重啟服務</title>
</head>
<body>
<p>
<script language="javascript">
function checkyes() {
if (!confirm("確認要重啟?")) {
window.event.returnValue = false;
}
}
</script>
<form action="restart.php" target="_blank" method="get">
<input name="" type="submit" value="重啟服務" onClick="checkyes()" /></form>
</p>
</body>
</html>
3.2)
cat/var/www/html/function/restart.php
<?php
system("ssh [email protected] /root/scripts/test.sh");
?>
3.3)
apache配置裡加密碼驗證:
<Directory /var/www/html/function/>
AuthType Basic
AuthName sys
AuthUserFile /var/www/html/function/.htpasswd
require user sys
</Directory>
htpasswd -bc /var/www/html/function/.htpasswd sys 123456
3.4)
做個超連結嵌入其他頁面
<a href="http://x.x.x.x/function/restart.html" target="_blank">重啟</a>
簡單的web控制shell指令碼方法