-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvh.php
More file actions
175 lines (150 loc) · 4.38 KB
/
vh.php
File metadata and controls
175 lines (150 loc) · 4.38 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
$uLine = "\e[4m";
$cyan = "\e[36m";
$lCyan = "\e[96m";
$green = "\e[32m";
$lGreen = "\e[92m";
$lBlue = "\e[94m"; // !
$yellow = "\e[33m";
$lYellow = "\e[93m";
$lRed = "\e[91m";
$default = "\e[39m";
$norm = "\e[24m";
$lang = null;
function printString($value = '', $color = null): void
{
echo $color . $value . "\e[0m" . PHP_EOL;
}
// C:\Windows\System32\drivers\etc\hosts
// 127.0.0.1 $value
// 127.0.0.1 www.$value
function getHostsData($value)
{
$data = <<<EOT
127.0.0.1 $value
127.0.0.1 www.$value
EOT;
return $data;
}
// WINDOWS 8.1 +
function getXamppHostData($value)
{
$xamppPath = realpath('./htdocs') ?? null;
if (isset($xamppPath)) {
$data = <<<EOT
<VirtualHost *:80>
ServerAdmin webmaster@$value
DocumentRoot "$xamppPath/$value"
ServerName $value
ServerAlias www.$value
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
EOT;
return $data;
}
}
$getStart = <<<EOT
$lCyan
Plugin for adding a new virtual host
for a local XAMPP server$default
-------------------------------------
______ ___ ___
| __ \ \ \/ /
| |__| | \ \ /
| / /\ \
| __ \ / \ \
| |__| | __ / / \ \ __
|________/ / /__/ \__\ / \e[93m 0.2.0
$lCyan
Плагин добавления нового виртуального хоста
для локального сервера XAMPP$default
-------------------------------------
EOT;
function setLang()
{
global $lang;
$language = readline('Русский - 1 | English - 2 : ');
$lang = $language ?? null;
}
echo $getStart;
setLang();
// echo $lang;
function checkPathXampp()
{
global $lang;
if (!isset($lang) || $lang > 2) {
setLang();
}
if ($lang == 1) {
if (!is_dir('apache/conf/extra')) {
printString("\e[91mПереместите файл vh.php в папку XAMPP и запустите его оттуда");
exit;
} else {
return true;
}
} elseif($lang == 2) {
if (!is_dir('apache/conf/extra')) {
printString("\e[91mMove the file vh.php to the XAMPP folder and run it there");
exit;
} else {
return true;
}
} else {
exit();
}
}
function getXamppData()
{
if (checkPathXampp()) {
$xVhost = 'apache/conf/extra/httpd-vhosts.conf';
return $xVhost;
}
}
function setNewHost($color, $xVhost, $color2, $color3)
{
global $lang;
if ($lang == 1) {
$host = readline('Введите название локального сайта, который создаёте: ');
printString('------------------------');
$newDir = readline('Создать папку для нового проекта? Да - 1 | Нет - 2 : ');
printString('------------------------');
if ($host) {
if ($newDir == 1) {
mkdir("htdocs/$host");
}
file_put_contents('C:\Windows\System32\drivers\etc\hosts', getHostsData($host), FILE_APPEND);
file_put_contents($xVhost, getXamppHostData($host), FILE_APPEND);
printString('Добавление данных в hosts...', $color3);
sleep(1);
printString('Добавление данных для локального сервера...', $color3);
sleep(1);
printString('Данные нового виртуального хоста добавлены', $color2);
} else {
printString('Название не указано...', $color);
setNewHost($color, $xVhost, $color2, $color3);
}
} else {
$host = readline('Enter the name of the local site: ');
printString('------------------------');
$newDir = readline('Create a folder for a new project? Yes - 1 | No - 2 : ');
printString('------------------------');
if ($host) {
if ($newDir == 1) {
mkdir("htdocs/$host");
}
file_put_contents('C:\Windows\System32\drivers\etc\hosts', getHostsData($host), FILE_APPEND);
file_put_contents($xVhost, getXamppHostData($host), FILE_APPEND);
printString('Adding data to the hosts file...', $color3);
sleep(1);
printString('Adding data for the local server...', $color3);
sleep(1);
printString('The data of the new virtual host has been added', $color2);
} else {
printString('The name is not specified...', $color);
setNewHost($color, $xVhost, $color2, $color3);
}
}
}
$xamppVhost = getXamppData();
setNewHost($lYellow, $xamppVhost, $lBlue, $lCyan);