-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall.php
More file actions
156 lines (113 loc) · 4.06 KB
/
install.php
File metadata and controls
156 lines (113 loc) · 4.06 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
<?php
$path = $_SERVER["SCRIPT_FILENAME"];
$path = str_replace("install.php", "", $path);
$os = $_SERVER["OS"];
echo "\n\n\n";
//print_r($_SERVER);
echo "\n\n\n/*****************************************************************/\n
Welcome to the CalaAPI Installer V0.1 \n
/*****************************************************************/\n\n\n";
echo "The CalaAPI, for security reasons it has to be installed in two different areas. \n
The www MUST be installed into a public area, for example public_html/www or htdocs. \n \n
The second part wich is the api file MUST be installed into a non public area, such as /var/subs \n\n";
$wwwDone = false;
$apiDone = false;
$wwwPath = "";
$apiPath = "";
$allDone = false;
while(!$wwwDone){
echo "So, where do you want to locate the www folder?: ";
$line = trim(fgets(STDIN));
echo "\nIs this the right path for www folder? (Y/N): $line\n";
$wwwPath = $line;
$line = trim(fgets(STDIN));
$wwwDone = $line == "Y";
}
echo "\n\nNice! Lets keep on rocking! \n\n\n";
while(!$apiDone){
echo "So, where do you want to locate the api folder?: ";
$handle = fopen ("php://stdin","r");
$line = trim(fgets(STDIN));
echo "\nIs this the right path for api folder? (Y/N): $line\n";
$apiPath = $line;
$line = trim(fgets(STDIN));
$apiDone = $line == "Y";
}
echo "\n\n So we will going to install \n\nwww:$wwwPath \napi:$apiPath \n\n\n\n\n\n";
$www = $path . "www";
if(rCopy($www, $wwwPath, $os, "www")){
echo "\n[OK] >> www";
$allDone = true;
}else{
echo "\n[ERROR] >> www";
$allDone = false;
}
$api = $path . "api";
if($allDone && rCopy($api, $apiPath, $os, "api")){
echo "\n[OK] >> api";
$allDone = true;
}else{
echo "\n[ERROR] >> api";
$allDone = false;
}
/*********************************************************************/
/* DB conf */
/*********************************************************************/
$dbName = "";
$dbPss = "";
$dbUser = "";
$dbHost = "";
$dbCorrect = false;
if($allDone){
while(!$dbCorrect){
echo "\n\nIt seems all is working well. Lets configure the DB info\n\n";
echo "\nDB Name:";
$line = trim(fgets(STDIN));
$dbName = $line;
echo "\nDB User:";
$line = trim(fgets(STDIN));
$dbUser = $line;
echo "\nDB Pass:";
$line = trim(fgets(STDIN));
$dbPss = $line;
echo "\nDB Host:";
$line = trim(fgets(STDIN));
$dbHost = $line;
echo "\n Is all correct? \nDB Name:$dbName \nDB User:$dbUser \nDB Pass:$dbPss \nDB Host:$dbHost \n\n(Y / N):";
$line = trim(fgets(STDIN));
$dbCorrect = $line == "Y";
}
$key = md5($dbName . $dbHost . $dbPss . $dbUser);
$tpl = "";
if(strpos($os, "Windows") !== false){
$tpl = file_get_contents("$wwwPath\www\settings.tpl.php");
}else{
$tpl = file_get_contents("$wwwPath/www/settings.tpl.php");
}
$tpl = str_replace("{dbName}", $dbName, $tpl);
$tpl = str_replace("{dbPss}", $dbPss, $tpl);
$tpl = str_replace("{dbUser}", $dbUser, $tpl);
$tpl = str_replace("{dbHost}", $dbHost, $tpl);
$tpl = str_replace("{cryptoKey}", $key, $tpl);
$realPath = str_replace("\\", "/", $apiPath);
$tpl = str_replace("{apiPath}", "$realPath/api/", $tpl);
$file = fopen("$wwwPath/www/settings.php", "w");
if(fwrite($file, $tpl)){
echo "DONE";
}
}
function rCopy($dir, $dest, $os, $f){
if(strpos($os, "Windows") !== false){
mkdir("$dest\\$f");
$cmd = "xcopy $dir $dest\\$f\\ /E";
echo "\n\n$cmd\n\n";
return exec($cmd);
}else{
mkdir("$dest/$f");
$cmd = "cp -r $dir/* $dest/$f";
echo "\n\n$cmd\n\n";
$res = exec($cmd);
echo $res . "<<<<<<<<<";
return true;
}
}