Advertisement
arxcorp

change hostname arX box

Apr 30th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php
  2.  
  3. require_once('auth.php');
  4.  
  5. $hostname = $_POST['HOSTNAME'];
  6.  
  7. echo $hostname;
  8.  
  9. $file = "#This file was created by arX box configuration script
  10. 127.0.0.1 localhost $hostname
  11. ::1 localhost ip6-localhost ip6-loopback
  12. fe00::0 ip6-localnet
  13. ff00::0 ip6-mcastprefix
  14. ff02::1 ip6-allnodes
  15. ff02::2 ip6-allrouters";
  16.  
  17. $file_hostname = "/tmp/hostname";
  18. $filename = "/tmp/hosts";
  19.  
  20. echo exec('sudo cp /etc/hostname /etc/hostname.backup-`date +%m-%d-%Y_%T`');
  21. echo exec('sudo cp /etc/hosts /etc/hosts.backup-`date +%m-%d-%Y_%T`');
  22.  
  23. $fp = fopen ($filename, "w");
  24. if ($fp) {
  25. fwrite ($fp, $file);
  26. fclose ($fp);
  27. echo ("New hosts file written");
  28. }
  29. else {
  30. echo ("File was not written");
  31. }
  32.  
  33. $fp = fopen ($file_hostname, "w");
  34. if ($fp) {
  35. fwrite ($fp, $hostname);
  36. fclose ($fp);
  37. echo ("New hosts file written");
  38. }
  39. else {
  40. echo ("File was not written");
  41. }
  42.  
  43. echo exec('sudo mv /tmp/hostname /etc/hostname');
  44. echo exec('sudo mv /tmp/hosts /etc/hosts');
  45.  
  46. echo ("hostname has been updated<br />");
  47.  
  48. shell_exec("sleep 10");
  49. echo $hostname;
  50. echo exec('sudo /bin/hostname <?php echo $hostname; ?>');
  51. print ("<script>window.opener.location.reload();
  52. //self.close();</script>");
  53.  
  54.  
  55. echo '<input type="submit" value="Close" onclick="window.close()" />';
  56.  
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement