/php/so/propeller/rollback.php
PHP | 106 lines | 101 code | 5 blank | 0 comment | 10 complexity | 54455c0eeb2cc5e26298f00649638d25 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-3.0, AGPL-1.0
- <?php
- include("header.php");
- ?>
- <h2 align="center" class="title2">??nginx????</h2>
- <form id="rollback" method="post" action="<? $_SERVER['PHP_SELF']?>">
- <center>
- <table name="roll">
- <tr>
- <th scope="col">???<br>
- <select name="group_name" id="group_name" onclick="showtest(this.value)">
- <?php
- $sql="select distinct group_name from group_ip_map;";
- $result = mysql_query($sql);
- while($record = mysql_fetch_array($result)) {
- echo "<option value=\"$record[group_name]\">$record[group_name]</option>";
- }
- ?>
- </select>
- </th>
- <th scope="col">????</th>
- <th scope="col">????</th>
- </tr>
- <tr id="nginx_time">
- </tr>
- <tr id="nginx_time2">
- </tr>
- </table>
- <p><input type="submit" name="save" value="???????" onclick="javascript:return confirm('?????????');"></p>
- <?php
- function testNginx()
- {
- $testnginx = exec("md5sum /tmp/nginx.conf > /tmp/nginx.md5 && sudo /usr/local/nginx/sbin/nginx -t -c /tmp/nginx.conf 2>&1");
- return $testnginx;
- }
- function sendNginx($ipaddress)
- {
- $sendnginx = exec("sudo scp /tmp/nginx.conf /tmp/nginx.md5 root@$ipaddress:/usr/local/nginx/conf/ && ssh root@$ipaddress 'cd /usr/local/nginx/conf/ && /usr/bin/md5sum -c nginx.md5 2>&1'");
- return $sendnginx;
- }
- function reloadNginx($ipaddress)
- {
- $reloadnginx = exec("sudo ssh root@$ipaddress '/etc/init.d/nginx reload' 2>&1");
- return $reloadnginx;
- }
- if( isset($_POST['save']) ){
- $file = $_POST['file'];
- if ($file=="check1"){
- $content=$_POST['nginx1'];
- }
- if ($file=="check2"){
- $content=$_POST['nginx2'];
- }
- $group=$_REQUEST['group_name'];
- $ip = $_SERVER['REMOTE_ADDR'];
- $newcontent=addslashes($content);
- $file=fopen("/tmp/nginx.conf","w");
- fwrite($file,$content);
- fclose($file);
- $resultnginx = testNginx();
- $testf="failed";
- $con = explode($testf,$resultnginx);
- if (count($con)>1){
- echo "<SCRIPT LANGUGE=\"JavaScript\">";
- echo "alert('nginx???????')";
- echo "</SCRIPT>";
- }
- else {
- $insertsql = "insert into `conf_file` (`group_name`,`nginx_file`,`admin_ip`) values ('".$group."','".$newcontent."','".$ip."')";
- mysql_query($insertsql);
- $ipsql="select ip_addr from group_ip_map where group_name='$group'";
- $result=mysql_query($ipsql);
- while($record = mysql_fetch_array($result)){
- $ipaddress=$record[ip_addr];
- $sendresult = sendNginx($ipaddress);
- $testsend = "OK";
- $testsend1 = "??";
- $sendtest = explode($testsend,$sendresult);
- $sendtest1 = explode($testsend1,$sendresult);
- if (count($sendtest)>1 || count($sendtest1)>1){
- echo "$ipaddress scp is ok <br>";
- $reloadnginx = reloadNginx($ipaddress);
- $reloadtest = explode($testf,$reloadnginx);
- if (count($reloadtest)>1){
- echo "$ipaddress reload is failed<br>";
- }
- else{
- echo "$ipaddress reload is ok<br>";
- }
- }
- else{
- echo "$ipaddress scp is failed <br>";
- }
- }
- }
- }
- ?>
- </center>
- </form>
- <?php
- include("footer.php");
- ?>