forked from hsb4995/Apachange
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapachange.php
executable file
·87 lines (76 loc) · 1.9 KB
/
apachange.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
$num=shell_exec('tput cols');
for ($i=0;$i<$num;++$i) {
echo"_";
}
for ($i=0;$i<$num;++$i) {
echo" ";
}
for ($i=0;$i<$num;++$i) {
echo" ";
}
echo" Apachange \n";
for ($i=0;$i<$num;++$i) {
echo"_";
}
if (isset($argv[1])) {
$argument1=$argv[1];
} else {
$argument1='a';
}
if ($argument1 == '-c') {
$path = system('pwd');
echo "Setting " . $path . " as new Root for Apache \n";
} elseif ($argument1 == '-r') {
$local_path = null;
exec('pwd', $local_path);
exec('cd /var/www/html; sudo apachange -c');
exec('cd ' . $local_path[0]);
echo"Restored the default Root for Apache settings\n";
die();
} else {
$invalid = false;
$path = readline("Enter the directory to change Root for Apache \n");
while ($invalid = ($path == '.')) {
if ($invalid) {
echo "Invalid path! Single dot is not allowed.\n";
}
$path = readline("Enter the directory to change Root for Apache \n");
}
}
if ($path == '~') {
echo "Username: \n";
$user = system('echo $USER');
$path = "/home/" . $user;
}
$str = 'No Such Path';
$op = shell_exec("if [ ! -d '" . $path . "' ]; then echo '" . $str . "'; fi");
echo $op;
if (strcmp($op, "No Such Path\n") == 0) {
die();
} else {
$apache = "/etc/apache2/sites-available/000-default.conf";
$file = file_get_contents($apache);
$pattern = "/DocumentRoot/";
//preg_match($pattern,$file,$matches,PREG_OFFSET_CAPTURE);
$patt = "DocumentRoot";
$pos = strpos($file,$patt);
$pathy = $pos+13;
for ($y = 0; $y < 50; $y++) {
$string = $file[$pathy + $y];
if (strstr($file[$pathy + $y], PHP_EOL)) {
$posi = $pathy + $y;
}
}
echo "Current root for Apache: \n";
$string = '';
for ($i = $pathy; $i < $posi; $i++) {
echo $file[$i];
$string .= $file[$i];
}
$file1 = str_replace($string, $path, $file);
file_put_contents($apache,$file1);
echo "\n";
$cmd = shell_exec("sudo service apache2 restart &");
echo "\n";
}