forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseSetup.php
More file actions
76 lines (57 loc) · 2.06 KB
/
Copy pathBaseSetup.php
File metadata and controls
76 lines (57 loc) · 2.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
<?php
function join_paths() {
$paths = array();
foreach (func_get_args() as $arg) {
if ($arg !== '') { $paths[] = $arg; }
}
return preg_replace('#/+#','/',join('/', $paths));
}
function generate_string(int $length = 16) {
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@|#[]$%^&*() _-=+{}:;<>?,./';
$random_string = '';
for($i = 0; $i < $length; $i++) {
$random_string .= $chars[random_int(0, strlen($chars) - 1)];
}
return $random_string;
}
abstract class BaseSetup {
protected $domain;
protected $extractsubdir;
public function __construct($domain, HestiaApp $appcontext) {
if(filter_var($domain, FILTER_VALIDATE_DOMAIN) === false) {
throw new Exception("Invalid domain name");
}
$this->domain = $domain;
$this->appcontext = $appcontext;
}
public function getConfig($section=null) {
return (!empty($section))? $this->config[$section] : $this->config;
}
public function getOptions() {
return $this->getConfig('form');
}
public function withDatabase() : bool {
return ($this->getConfig('database') === true);
}
public function getDocRoot($docrelative=null) : string {
$domain_path = $this->appcontext->getWebDomainPath($this->domain);
if(empty($domain_path) || ! is_dir($domain_path)) {
throw new Exception("Error finding domain folder ($domain_path)");
}
return join_paths($domain_path, "public_html", $docrelative);
}
public function retrieveResources() {
return $this->appcontext->archiveExtract(
$this->getConfig('url'),
$this->getDocRoot($this->extractsubdir), 1);
}
public function install($options) {
return $this->retrieveResources();
}
public function cleanup() {
// Remove temporary folder
if(!empty($this->extractsubdir)) {
$this->appcontext->runUser('v-delete-fs-directory',[$this->getDocRoot($this->extractsubdir)], $result);
}
}
}