PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/php/so/propeller/rollback.php

http://timoseven.googlecode.com/
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
  1. <?php
  2. include("header.php");
  3. ?>
  4. <h2 align="center" class="title2">??nginx????</h2>
  5. <form id="rollback" method="post" action="<? $_SERVER['PHP_SELF']?>">
  6. <center>
  7. <table name="roll">
  8. <tr>
  9. <th scope="col">???<br>
  10. <select name="group_name" id="group_name" onclick="showtest(this.value)">
  11. <?php
  12. $sql="select distinct group_name from group_ip_map;";
  13. $result = mysql_query($sql);
  14. while($record = mysql_fetch_array($result)) {
  15. echo "<option value=\"$record[group_name]\">$record[group_name]</option>";
  16. }
  17. ?>
  18. </select>
  19. </th>
  20. <th scope="col">????</th>
  21. <th scope="col">????</th>
  22. </tr>
  23. <tr id="nginx_time">
  24. </tr>
  25. <tr id="nginx_time2">
  26. </tr>
  27. </table>
  28. <p><input type="submit" name="save" value="???????" onclick="javascript:return confirm('?????????');"></p>
  29. <?php
  30. function testNginx()
  31. {
  32. $testnginx = exec("md5sum /tmp/nginx.conf > /tmp/nginx.md5 && sudo /usr/local/nginx/sbin/nginx -t -c /tmp/nginx.conf 2>&1");
  33. return $testnginx;
  34. }
  35. function sendNginx($ipaddress)
  36. {
  37. $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'");
  38. return $sendnginx;
  39. }
  40. function reloadNginx($ipaddress)
  41. {
  42. $reloadnginx = exec("sudo ssh root@$ipaddress '/etc/init.d/nginx reload' 2>&1");
  43. return $reloadnginx;
  44. }
  45. if( isset($_POST['save']) ){
  46. $file = $_POST['file'];
  47. if ($file=="check1"){
  48. $content=$_POST['nginx1'];
  49. }
  50. if ($file=="check2"){
  51. $content=$_POST['nginx2'];
  52. }
  53. $group=$_REQUEST['group_name'];
  54. $ip = $_SERVER['REMOTE_ADDR'];
  55. $newcontent=addslashes($content);
  56. $file=fopen("/tmp/nginx.conf","w");
  57. fwrite($file,$content);
  58. fclose($file);
  59. $resultnginx = testNginx();
  60. $testf="failed";
  61. $con = explode($testf,$resultnginx);
  62. if (count($con)>1){
  63. echo "<SCRIPT LANGUGE=\"JavaScript\">";
  64. echo "alert('nginx???????')";
  65. echo "</SCRIPT>";
  66. }
  67. else {
  68. $insertsql = "insert into `conf_file` (`group_name`,`nginx_file`,`admin_ip`) values ('".$group."','".$newcontent."','".$ip."')";
  69. mysql_query($insertsql);
  70. $ipsql="select ip_addr from group_ip_map where group_name='$group'";
  71. $result=mysql_query($ipsql);
  72. while($record = mysql_fetch_array($result)){
  73. $ipaddress=$record[ip_addr];
  74. $sendresult = sendNginx($ipaddress);
  75. $testsend = "OK";
  76. $testsend1 = "??";
  77. $sendtest = explode($testsend,$sendresult);
  78. $sendtest1 = explode($testsend1,$sendresult);
  79. if (count($sendtest)>1 || count($sendtest1)>1){
  80. echo "$ipaddress scp is ok <br>";
  81. $reloadnginx = reloadNginx($ipaddress);
  82. $reloadtest = explode($testf,$reloadnginx);
  83. if (count($reloadtest)>1){
  84. echo "$ipaddress reload is failed<br>";
  85. }
  86. else{
  87. echo "$ipaddress reload is ok<br>";
  88. }
  89. }
  90. else{
  91. echo "$ipaddress scp is failed <br>";
  92. }
  93. }
  94. }
  95. }
  96. ?>
  97. </center>
  98. </form>
  99. <?php
  100. include("footer.php");
  101. ?>