Add PHP7.3 support and let setup.php write initial config files
This commit is contained in:
@ -4,7 +4,7 @@ const DBUSER='hosting'; // Database user
|
||||
const DBPASS='MY_PASSWORD'; // Database password
|
||||
const DBNAME='hosting'; // Database
|
||||
const PERSISTENT=true; // Use persistent database conection true/false
|
||||
const DBVERSION=7; //database layout version
|
||||
const DBVERSION=8; //database layout version
|
||||
const CAPTCHA=0; // Captcha difficulty (0=off, 1=simple, 2=moderate, 3=extreme)
|
||||
const ADDRESS='dhosting4okcs22v.onion'; // our own address
|
||||
const SERVERS=[ //servers and ports we are running on
|
||||
@ -18,6 +18,29 @@ const INDEX_MD5S=[ //MD5 sums of index.hosting.html files that should be considd
|
||||
];
|
||||
const REQUIRE_APPROVAL=false; //require admin approval of new sites? true/false
|
||||
const ADMIN_PASSWORD='MY_PASSWORD'; //password for admin interface
|
||||
const SERVICE_INSTANCES=['2', '3', '4', '5', '6', '7', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
|
||||
const PHP_VERSIONS=[1 => '7.0', 2 => '7.1', 3 => '7.2', 4 => '7.3'];
|
||||
const PHP_CONFIG='memory_limit = 256M
|
||||
error_reporting = E_ALL
|
||||
post_max_size = 10G
|
||||
upload_max_filesize = 10G
|
||||
max_file_uploads = 100
|
||||
date.timezone = UTC
|
||||
pdo_odbc.connection_pooling=off
|
||||
odbc.allow_persistent = Off
|
||||
ibase.allow_persistent = 0
|
||||
mysqli.allow_persistent = Off
|
||||
pgsql.allow_persistent = Off
|
||||
opcache.enable=1
|
||||
opcache.interned_strings_buffer=8
|
||||
opcache.max_accelerated_files=20000
|
||||
opcache.use_cwd=1
|
||||
opcache.validate_timestamps=1
|
||||
opcache.revalidate_freq=2
|
||||
opcache.revalidate_path=1
|
||||
opcache.save_comments=1
|
||||
opcache.optimization_level=0xffffffff
|
||||
opcache.validate_permission=1';
|
||||
|
||||
function get_onion($pkey){
|
||||
$keyData = openssl_pkey_get_details($pkey);
|
||||
|
@ -10,7 +10,7 @@ try{
|
||||
$reload=[];
|
||||
$stmt=$db->query('SELECT id FROM service_instances WHERE reload=1;');
|
||||
while($tmp=$stmt->fetch(PDO::FETCH_NUM)){
|
||||
$reload[$tmp[0]]=true;
|
||||
$reload[$tmp[0]]=true;
|
||||
}
|
||||
$db->query('UPDATE service_instances SET reload=0 WHERE reload=1;');
|
||||
|
||||
@ -103,12 +103,11 @@ php_admin_value[session.save_path] = /home/$system_account/tmp
|
||||
|
||||
//save configuration files
|
||||
file_put_contents("/etc/nginx/sites-enabled/$system_account", $nginx);
|
||||
if($id[4]==1){
|
||||
file_put_contents("/etc/php/7.0/fpm/pool.d/$firstchar/$system_account.conf", $php);
|
||||
}elseif($id[4]==2){
|
||||
file_put_contents("/etc/php/7.1/fpm/pool.d/$firstchar/$system_account.conf", $php);
|
||||
}elseif($id[4]==3){
|
||||
file_put_contents("/etc/php/7.2/fpm/pool.d/$firstchar/$system_account.conf", $php);
|
||||
foreach(PHP_VERSIONS as $key=>$version){
|
||||
if($id[4]==$key){
|
||||
file_put_contents("/etc/php/$version/fpm/pool.d/$firstchar/$system_account.conf", $php);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//save hidden service
|
||||
mkdir("/var/lib/tor-instances/$firstchar/hidden_service_$onion.onion", 0700);
|
||||
@ -136,7 +135,7 @@ foreach($onions as $onion){
|
||||
$firstchar=substr($onion[0], 0, 1);
|
||||
$reload[$firstchar]=true;
|
||||
//delete config files
|
||||
foreach(['7.0', '7.1', '7.2'] as $v){
|
||||
foreach(PHP_VERSIONS as $v){
|
||||
// new naming schema
|
||||
if(file_exists("/etc/php/$v/fpm/pool.d/$firstchar/$onion[0].conf")){
|
||||
unlink("/etc/php/$v/fpm/pool.d/$firstchar/$onion[0].conf");
|
||||
@ -166,9 +165,9 @@ if(!empty($reload)){
|
||||
exec('service nginx reload');
|
||||
}
|
||||
foreach($reload as $key => $val){
|
||||
exec("service php7.0-fpm@$key restart");
|
||||
exec("service php7.1-fpm@$key restart");
|
||||
exec("service php7.2-fpm@$key restart");
|
||||
foreach(PHP_VERSIONS as $version){
|
||||
exec("service php$version-fpm@$key restart");
|
||||
}
|
||||
rewrite_torrc($db, $key);
|
||||
}
|
||||
|
||||
|
@ -87,8 +87,13 @@ if($_SERVER['REQUEST_METHOD']==='POST'){
|
||||
if(isset($_POST['public']) && $_POST['public']==1){
|
||||
$public=1;
|
||||
}
|
||||
if(isset($_POST['php']) && in_array($_POST['php'], [1, 2, 3])){
|
||||
$php=$_POST['php'];
|
||||
if(isset($_POST['php'])){
|
||||
foreach(PHP_VERSIONS as $key=>$version){
|
||||
if($_POST['php']===$version){
|
||||
$php=$key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($_POST['autoindex']) && $_POST['autoindex']==1){
|
||||
$autoindex=1;
|
||||
@ -144,20 +149,17 @@ if(isset($_POST['autoindex']) && $_POST['autoindex']==1){
|
||||
}else{
|
||||
$autoindex='';
|
||||
}
|
||||
$nophp='';
|
||||
$php70='';
|
||||
$php71='';
|
||||
$php72='';
|
||||
if(isset($_POST['php']) && $_POST['php']==0){
|
||||
$nophp=' selected';
|
||||
}elseif(isset($_POST['php']) && $_POST['php']==1){
|
||||
$php70=' selected';
|
||||
}elseif(isset($_POST['php']) && $_POST['php']==2){
|
||||
$php71=' selected';
|
||||
}else{
|
||||
$php72=' selected';
|
||||
echo '<tr><td>PHP version</td><td><select name="php">
|
||||
<option value="0"';
|
||||
echo (isset($_POST['php']) && $_POST['php']==0) ? ' selected' : '';
|
||||
echo '>None</option>';
|
||||
$default_version='7.2';
|
||||
foreach(PHP_VERSIONS as $version){
|
||||
echo "<option value=\"$version\"";
|
||||
echo (isset($_POST['php']) && $_POST['php']===$version || (!isset($_POST['php']) && $version===$default_version)) ? ' selected' : '';
|
||||
echo ">PHP $version</option>";
|
||||
}
|
||||
echo '<tr><td>PHP version</td><td><select name="php"><option value="0"'.$nophp.'>None</option><option value="1" '.$php70.'>PHP 7.0</option><option value="2"'.$php71.'>PHP 7.1</option><option value="3"'.$php72.'>PHP 7.2</option></select></td></tr>';
|
||||
echo '</select></td></tr>';
|
||||
echo '<tr><td colspan=2><label><input type="checkbox" name="public" value="1"'.$public.'>Publish site on list of hosted sites</label></td></tr>';
|
||||
echo '<tr><td colspan=2><label><input type="checkbox" name="autoindex" value="1"'.$autoindex.'>Enable autoindex (listing of files)</label></td></tr>';
|
||||
echo '<tr><td>Custom private key<br>(optional)</td><td><textarea name="private_key" rows="5" cols="28">';
|
||||
|
@ -29,13 +29,69 @@ if(!@$version=$db->query("SELECT value FROM settings WHERE setting='version';"))
|
||||
$db->exec("CREATE TABLE onions (user_id int(11) NOT NULL, onion varchar(56) COLLATE latin1_bin NOT NULL PRIMARY KEY, private_key varchar(1000) COLLATE latin1_bin NOT NULL, version tinyint(1) NOT NULL, enabled tinyint(1) NOT NULL DEFAULT '1', num_intros tinyint(3) NOT NULL DEFAULT '3', enable_smtp tinyint(1) NOT NULL DEFAULT '1', max_streams tinyint(3) unsigned NOT NULL DEFAULT '20', KEY user_id (user_id), KEY enabled (enabled), CONSTRAINT onions_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;");
|
||||
$db->exec("CREATE TABLE service_instances (id char(1) NOT NULL PRIMARY KEY, reload tinyint(1) UNSIGNED NOT NULL DEFAULT '0', KEY reload (reload)) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;");
|
||||
$stmt=$db->prepare('INSERT INTO service_instances (id) VALUES (?);');
|
||||
foreach(['2', '3', '4', '5', '6', '7', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] as $key){
|
||||
foreach(SERVICE_INSTANCES as $key){
|
||||
$stmt->execute([$key]);
|
||||
}
|
||||
$db->exec('CREATE TABLE settings (setting varchar(50) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL PRIMARY KEY, value text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;');
|
||||
$stmt=$db->prepare("INSERT INTO settings (setting, value) VALUES ('version', ?);");
|
||||
$stmt->execute([DBVERSION]);
|
||||
echo "Database has successfully been set up\n";
|
||||
foreach(PHP_VERSIONS as $version){
|
||||
if(!file_exists("/etc/php/$version/fpm/conf.d/")){
|
||||
mkdir("/etc/php/$version/fpm/conf.d/", 0755, true);
|
||||
}
|
||||
file_put_contents("/etc/php/$version/fpm/conf.d/99-hosting.conf", PHP_CONFIG);
|
||||
if(!file_exists("/etc/php/$version/cli/conf.d/")){
|
||||
mkdir("/etc/php/$version/cli/conf.d/", 0755, true);
|
||||
}
|
||||
file_put_contents("/etc/php/$version/cli/conf.d/99-hosting.conf", PHP_CONFIG);
|
||||
$fpm_config = "[global]
|
||||
pid = /run/php/php$version-fpm.pid
|
||||
error_log = /var/log/php$version-fpm.log
|
||||
process_control_timeout = 10
|
||||
include=/etc/php/$version/fpm/pool.d/*.conf
|
||||
";
|
||||
file_put_contents("/etc/php/$version/fpm/php-fpm.conf", $fpm_config);
|
||||
$pool_config = "[www]
|
||||
user = www-data
|
||||
group = www-data
|
||||
listen = /run/php/php$version-fpm.sock
|
||||
listen.owner = www-data
|
||||
listen.group = www-data
|
||||
pm = dynamic
|
||||
pm.max_children = 25
|
||||
pm.start_servers = 2
|
||||
pm.min_spare_servers = 1
|
||||
pm.max_spare_servers = 3
|
||||
php_admin_value[mysqli.allow_persistent] = On
|
||||
";
|
||||
if(!file_exists("/etc/php/$version/fpm/pool.d/")){
|
||||
mkdir("/etc/php/$version/fpm/pool.d/", 0755, true);
|
||||
}
|
||||
file_put_contents("/etc/php/$version/fpm/pool.d/www.conf", $pool_config);
|
||||
foreach(SERVICE_INSTANCES as $instance){
|
||||
$fpm_config = "[global]
|
||||
pid = /run/php/php$version-fpm-$instance.pid
|
||||
error_log = /var/log/php$version-fpm-$instance.log
|
||||
process_control_timeout = 10
|
||||
include=/etc/php/$version/fpm/pool.d/$instance/*.conf
|
||||
";
|
||||
file_put_contents("/etc/php/$version/fpm/php-fpm-$instance.conf", $fpm_config);
|
||||
$pool_config = "[www]
|
||||
user = www-data
|
||||
group = www-data
|
||||
listen = /run/php/$version-$instance
|
||||
listen.owner = www-data
|
||||
listen.group = www-data
|
||||
pm = ondemand
|
||||
pm.max_children = 8
|
||||
";
|
||||
if(!file_exists("/etc/php/$version/fpm/pool.d/$instance/")){
|
||||
mkdir("/etc/php/$version/fpm/pool.d/$instance/", 0755, true);
|
||||
}
|
||||
file_put_contents("/etc/php/$version/fpm/pool.d/$instance/www.conf", $pool_config);
|
||||
}
|
||||
}
|
||||
echo "Database and files have successfully been set up\n";
|
||||
}else{
|
||||
$version=$version->fetch(PDO::FETCH_NUM)[0];
|
||||
if($version<2){
|
||||
@ -84,15 +140,73 @@ if(!@$version=$db->query("SELECT value FROM settings WHERE setting='version';"))
|
||||
$db->exec("ALTER TABLE onions ADD max_streams tinyint(3) unsigned NOT NULL DEFAULT '20';");
|
||||
$db->exec("CREATE TABLE service_instances (id char(1) NOT NULL PRIMARY KEY, reload tinyint(1) UNSIGNED NOT NULL DEFAULT '0', KEY reload (reload)) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;");
|
||||
$stmt=$db->prepare('INSERT INTO service_instances (id, reload) VALUES (?, 1)');
|
||||
foreach(['2', '3', '4', '5', '6', '7', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] as $key){
|
||||
foreach(SERVICE_INSTANCES as $key){
|
||||
$stmt->execute([$key]);
|
||||
}
|
||||
}
|
||||
if($version<8){
|
||||
foreach(PHP_VERSIONS as $version){
|
||||
if(!file_exists("/etc/php/$version/fpm/conf.d/")){
|
||||
mkdir("/etc/php/$version/fpm/conf.d/", 0755, true);
|
||||
}
|
||||
file_put_contents("/etc/php/$version/fpm/conf.d/99-hosting.conf", PHP_CONFIG);
|
||||
if(!file_exists("/etc/php/$version/cli/conf.d/")){
|
||||
mkdir("/etc/php/$version/cli/conf.d/", 0755, true);
|
||||
}
|
||||
file_put_contents("/etc/php/$version/cli/conf.d/99-hosting.conf", PHP_CONFIG);
|
||||
$fpm_config = "[global]
|
||||
pid = /run/php/php$version-fpm.pid
|
||||
error_log = /var/log/php$version-fpm.log
|
||||
process_control_timeout = 10
|
||||
include=/etc/php/$version/fpm/pool.d/*.conf
|
||||
";
|
||||
file_put_contents("/etc/php/$version/fpm/php-fpm.conf", $fpm_config);
|
||||
$pool_config = "[www]
|
||||
user = www-data
|
||||
group = www-data
|
||||
listen = /run/php/php$version-fpm.sock
|
||||
listen.owner = www-data
|
||||
listen.group = www-data
|
||||
pm = dynamic
|
||||
pm.max_children = 25
|
||||
pm.start_servers = 2
|
||||
pm.min_spare_servers = 1
|
||||
pm.max_spare_servers = 3
|
||||
php_admin_value[mysqli.allow_persistent] = On
|
||||
";
|
||||
if(!file_exists("/etc/php/$version/fpm/pool.d/")){
|
||||
mkdir("/etc/php/$version/fpm/pool.d/", 0755, true);
|
||||
}
|
||||
file_put_contents("/etc/php/$version/fpm/pool.d/www.conf", $pool_config);
|
||||
foreach(SERVICE_INSTANCES as $instance){
|
||||
$fpm_config = "[global]
|
||||
pid = /run/php/php$version-fpm-$instance.pid
|
||||
error_log = /var/log/php$version-fpm-$instance.log
|
||||
process_control_timeout = 10
|
||||
include=/etc/php/$version/fpm/pool.d/$instance/*.conf
|
||||
";
|
||||
file_put_contents("/etc/php/$version/fpm/php-fpm-$instance.conf", $fpm_config);
|
||||
$pool_config = "[www]
|
||||
user = www-data
|
||||
group = www-data
|
||||
listen = /run/php/$version-$instance
|
||||
listen.owner = www-data
|
||||
listen.group = www-data
|
||||
pm = ondemand
|
||||
pm.max_children = 8
|
||||
";
|
||||
if(!file_exists("/etc/php/$version/fpm/pool.d/$instance/")){
|
||||
mkdir("/etc/php/$version/fpm/pool.d/$instance/", 0755, true);
|
||||
}
|
||||
file_put_contents("/etc/php/$version/fpm/pool.d/$instance/www.conf", $pool_config);
|
||||
}
|
||||
}
|
||||
}
|
||||
$stmt=$db->prepare("UPDATE settings SET value=? WHERE setting='version';");
|
||||
$stmt->execute([DBVERSION]);
|
||||
if(DBVERSION!=$version){
|
||||
echo "Database has successfully been updated to the latest version\n";
|
||||
echo "Database and files have successfully been updated to the latest version\n";
|
||||
}else{
|
||||
echo "Database already up-to-date\n";
|
||||
echo "Database and files already up-to-date\n";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user