码迷,mamicode.com
首页 > Web开发 > 详细

简单的web控制shell脚本方法

时间:2016-12-11 18:49:09      阅读:222      评论:0      收藏:0      [点我收藏+]

标签: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 root@x.x.x.x /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脚本方法

标签:web php html 可视化控制shell脚本

原文地址:http://leomars.blog.51cto.com/683246/1881668

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!