-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatch_files.php
171 lines (158 loc) · 6.76 KB
/
patch_files.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
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
<?php
/**
* Patch Hesta Control Panel files to support plugins. Also invoke any plugins that
* wish to intercept the patch and post_install hook.
*
* @version 1.0.0
* @license GPL-3.0
* @link https://github.com/virtuosoft-dev/hestiacp-pluginable
*
*/
// Copy pluginable.php to /usr/local/hestia/web/pluginable.php
copy( '/etc/hestiacp/hooks/pluginable.php', '/usr/local/hestia/web/pluginable.php' );
shell_exec( __DIR__ . '/install_hcpp_reboot.sh && cd /usr/local/hestia/web/js/dist && wget -O jquery-3.7.0.min.js https://code.jquery.com/jquery-3.7.0.min.js' );
// Ensure log is present and writable when needed
if ( ! file_exists( '/tmp/hcpp.log' ) ) {
touch( '/tmp/hcpp.log' );
chmod( '/tmp/hcpp.log', 0666 );
}
// Copy prepend/append/pluginable system to /usr/local/hestia/data/hcpp
if ( !is_dir( '/usr/local/hestia/data/hcpp/installed' ) ) {
mkdir( '/usr/local/hestia/data/hcpp/installed', 0755, true );
}
if ( !is_dir( '/usr/local/hestia/data/hcpp/uninstallers' ) ) {
mkdir( '/usr/local/hestia/data/hcpp/uninstallers', 0755, true );
}
copy( '/etc/hestiacp/hooks/prepend.php', '/usr/local/hestia/data/hcpp/prepend.php' );
copy( '/etc/hestiacp/hooks/append.php', '/usr/local/hestia/data/hcpp/append.php' );
// Copy v-invoke-plugin to /usr/local/hestia/bin to allow invocation from API
copy( '/etc/hestiacp/hooks/v-invoke-plugin', '/usr/local/hestia/bin/v-invoke-plugin' );
chmod( '/usr/local/hestia/bin/v-invoke-plugin', 0755 );
require_once( '/usr/local/hestia/web/pluginable.php' );
global $hcpp;
$hcpp->do_action( 'hcpp_pre_patch' );
// Patch Hestia templates php-fpm templates ..templates/web/php-fpm/*.tpl
$folderPath = "/usr/local/hestia/data/templates/web/php-fpm";
$files = glob( "$folderPath/*.tpl" );
foreach( $files as $file ) {
if ( strpos( $file, 'no-php.tpl' ) !== false ) {
continue;
}
// Patch php-fpm templates open_basedir to include /usr/local/hestia/plugins and /usr/local/hestia/data/hcpp
$hcpp->patch_file(
$file,
"\nphp_admin_value[open_basedir] =",
"\nphp_admin_value[open_basedir] = /home/%user%/.composer:/home/%user%/web/%domain%/public_html:/home/%user%/web/%domain%/private:/home/%user%/web/%domain%/public_shtml:/home/%user%/tmp:/tmp:/var/www/html:/bin:/usr/bin:/usr/local/bin:/usr/share:/opt:/usr/local/hestia/plugins:/usr/local/hestia/data/hcpp\n;php_admin_value[open_basedir] ="
);
// Patch php-fpm templates to support plugins prepend/append system
$hcpp->patch_file(
$file,
"\nphp_admin_value[open_basedir] =",
"\nphp_admin_value[auto_prepend_file] = /usr/local/hestia/data/hcpp/prepend.php\n\nphp_admin_value[auto_append_file] = /usr/local/hestia/data/hcpp/append.php\nphp_admin_value[open_basedir] ="
);
}
// domain.sh
$hcpp->patch_file(
'/usr/local/hestia/func/domain.sh',
'if [[ $backend_template =~ ^.*PHP-([0-9])\_([0-9])$ ]]; then',
'if [[ $backend_template =~ ^.*PHP-([0-9])\_([0-9])(.*)$ ]]; then'
);
$hcpp->patch_file(
'/usr/local/hestia/func/domain.sh',
'${BASH_REMATCH[1]}.${BASH_REMATCH[2]}',
'${BASH_REMATCH[1]}.${BASH_REMATCH[2]}${BASH_REMATCH[3]}'
);
// func/main.sh
$hcpp->patch_file(
'/usr/local/hestia/func/main.sh',
'BIN=$HESTIA/bin',
'BIN="/etc/hestiacp/hooks/bin_actions "'
);
$hcpp->patch_file(
'/usr/local/hestia/func/main.sh',
'# Internal variables',
"# Internal variables\nPARENT=\$(tr '\\0' '\n' < \"/proc/\$PPID/cmdline\" | sed 's/.*/\"&\"/');\nPARENT=\${PARENT//\$'\\n'/ };\nif [[ \$PARENT == *sudo* ]]; then\n PARENT=\"/etc/hestiacp/hooks/priv_actions \$PARENT\";\n eval_out=\$(eval \"\$PARENT\");\n eval \"\$eval_out\";\nfi"
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
'define("HESTIA_CMD", "/usr/bin/sudo /usr/local/hestia/bin/");',
'define("HESTIA_CMD", "/etc/hestiacp/hooks/bin_actions sudo ");'
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
"require_once dirname(__FILE__) . \"/helpers.php\";",
"require_once dirname(__FILE__) . \"/helpers.php\";\nrequire_once(\"/usr/local/hestia/web/pluginable.php\");"
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
"// Header",
"// Header\n\tglobal \$hcpp;\n\tob_start();\n"
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
'include $__template_dir . "header.php";',
"include \$__template_dir . \"header.php\";\n\t\$args = [ 'TAB' => \$TAB, 'page' => \$page, 'user' => \$user, 'content' => ob_get_clean() ];\n echo \$hcpp->do_action('hcpp_render_header', \$args)['content'];\n"
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
"// Panel",
"// Panel\n\tob_start();\n"
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
"// Policies controller",
"\t\$args['content'] = ob_get_clean();\n\techo \$hcpp->do_action('hcpp_render_panel', \$args)['content'];\n\n\t// Policies controller"
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
"// Body",
"// Body\n\tob_start();\n"
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
"// Footer",
"\t\$args['content'] = ob_get_clean();\n\techo \$hcpp->do_action('hcpp_render_body', \$args)['content'];\n\n\t// Footer"
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
"// Footer",
"// Footer\n\tob_start();\n"
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
'include $__template_dir . "footer.php";',
"include \$__template_dir . \"footer.php\";\n\t\$args['content'] = ob_get_clean();\n\techo \$hcpp->do_action('hcpp_render_footer', \$args)['content'];\n"
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
"\t} else {\n\t\treturn true;\n\t}",
"\t} else {\n\t\tglobal \$hcpp;\n\t\t\$hcpp->do_action('hcpp_csrf_verified');\n\t\treturn true;\n\t}"
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
"function show_alert_message(\$data) {",
"function show_alert_message(\$data) {\n\tglobal \$hcpp;\n\tob_start();\n"
);
$hcpp->patch_file(
'/usr/local/hestia/web/inc/main.php',
"\t\t\t\$msgText,\n\t\t);\n\t}\n",
"\t\t\t\$msgText,\n\t\t);\n\t}\n\t\$args['content'] = ob_get_clean();\n\techo \$hcpp->do_action('hcpp_show_alert_message', \$args)['content'];\n",
);
// api/index.php
$hcpp->patch_file(
'/usr/local/hestia/web/api/index.php',
'define("HESTIA_CMD", "/usr/bin/sudo /usr/local/hestia/bin/");',
'define("HESTIA_CMD", "/etc/hestiacp/hooks/bin_actions sudo ");'
);
// web/templates/header.php
$hcpp->patch_file(
'/usr/local/hestia/web/templates/header.php',
"<head>\n<?php\n",
"<head>\n<?php\nglobal \$hcpp;\nob_start();\n"
);
$hcpp->patch_file(
'/usr/local/hestia/web/templates/header.php',
"?>\n</head>\n",
"\$args['content'] = ob_get_clean();\necho \$hcpp->do_action('hcpp_head', \$args)['content'];\n?>\n</head>"
);
$hcpp->do_action( 'hcpp_post_install' );