feat(yeswiki-installer) : nossl option
This commit is contained in:
parent
2b76cdc7e6
commit
792e4489ff
3 changed files with 99 additions and 32 deletions
42
templates/nginx-nossl.php
Normal file
42
templates/nginx-nossl.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
# ----------------------------------------------------------------------
|
||||
# | Config file for <?=$this->e($domain)?> host |
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
server {
|
||||
listen [::]:80;
|
||||
listen 80;
|
||||
server_name <?php if (!$subDomain) : ?>www.<?=$this->e($domain)?> <?php endif ?><?=$this->e($domain)?>;
|
||||
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
root /home/<?=$this->e($user)?>/<?=$this->e($domain)?>;
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# Path for static files
|
||||
root /home/<?=$this->e($user)?>/<?=$this->e($domain)?>;
|
||||
|
||||
# Custom error pages
|
||||
include h5bp/errors/custom_errors.conf;
|
||||
|
||||
# Include the basic h5bp config set
|
||||
include h5bp/basic.conf;
|
||||
|
||||
access_log /var/log/nginx/<?=$this->e($domain)?>-access.log;
|
||||
error_log /var/log/nginx/<?=$this->e($domain)?>-error.log error;
|
||||
index index.php index.html index.htm;
|
||||
|
||||
location / {
|
||||
<?php if (!empty($herseUser) && !empty($hersePass)) : ?>
|
||||
auth_basic "Accès restreint";
|
||||
auth_basic_user_file /home/<?=$this->e($user)?>/<?=$this->e($domain)?>/.htpasswd;
|
||||
<?php endif ?>
|
||||
try_files $uri $uri/ /index.php$is_args$args;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
fastcgi_pass unix:/var/run/php-fpm-<?=$this->e($user)?>.sock;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi.conf;
|
||||
}
|
||||
}
|
|
@ -163,7 +163,7 @@ function removeUnixUser($user)
|
|||
return;
|
||||
}
|
||||
|
||||
function createNginxConfig($domain, $user, $herseUser, $hersePass)
|
||||
function createNginxConfig($domain, $user, $herseUser, $hersePass, $nossl)
|
||||
{
|
||||
// create folder if not exists
|
||||
exec('sudo -u '.$user.' mkdir -p /home'.'/'.$user.'/'.$domain);
|
||||
|
@ -182,6 +182,7 @@ function createNginxConfig($domain, $user, $herseUser, $hersePass)
|
|||
}
|
||||
$templates = new League\Plates\Engine(dirname(__FILE__).'/templates');
|
||||
$subDomain = preg_match('/.'.$_SERVER['maindomain'].'$/isU', $domain, $matches, PREG_OFFSET_CAPTURE, 0);
|
||||
if (!$nossl) {
|
||||
if (!$subDomain) {
|
||||
file_put_contents(
|
||||
$nginxFile,
|
||||
|
@ -216,6 +217,21 @@ function createNginxConfig($domain, $user, $herseUser, $hersePass)
|
|||
]
|
||||
)
|
||||
);
|
||||
} else {
|
||||
file_put_contents(
|
||||
$nginxFile,
|
||||
$templates->render(
|
||||
'nginx-nossl',
|
||||
[
|
||||
'domain' => $domain,
|
||||
'user' => $user,
|
||||
'herseUser' => $herseUser,
|
||||
'hersePass' => $hersePass,
|
||||
'subDomain' => $subDomain,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
exec('service nginx force-reload', $output);
|
||||
}
|
||||
|
||||
|
@ -243,7 +259,7 @@ function removePhpFpmConfig($user)
|
|||
exec('service '.$_SERVER['phpservice'].' reload', $output);
|
||||
}
|
||||
|
||||
function copyYesWikiFiles($domain, $user, $dbUser, $herseUser = null, $hersePass = null)
|
||||
function copyYesWikiFiles($domain, $user, $dbUser, $herseUser = null, $hersePass = null, $nossl = null)
|
||||
{
|
||||
$tmpFile = '/tmp/yeswiki.zip';
|
||||
$destDir = '/home'.'/'.$user.'/'.$domain;
|
||||
|
@ -262,7 +278,7 @@ function copyYesWikiFiles($domain, $user, $dbUser, $herseUser = null, $hersePass
|
|||
if (!empty($herseUser) && !empty($hersePass)) {
|
||||
$herse = $herseUser.':'.$hersePass.'@';
|
||||
}
|
||||
$curl = 'curl -X POST --insecure --data-urlencode \'config[default_language]=fr\' --data-urlencode \'config[wakka_name]='.$domain.'\' --data-urlencode \'config[root_page]=PagePrincipale\' --data-urlencode \'config[mysql_host]=localhost\' --data-urlencode \'config[mysql_database]='.$dbUser['database'].'\' --data-urlencode \'config[mysql_user]='.$dbUser['user'].'\' --data-urlencode \'config[mysql_password]='.$dbUser['password'].'\' --data-urlencode \'config[table_prefix]=yeswiki_\' --data-urlencode \'admin_name='.$_SERVER['admin_id'].'\' --data-urlencode \'admin_password='.$_SERVER['admin_password'].'\' --data-urlencode \'admin_password_conf='.$_SERVER['admin_password'].'\' --data-urlencode \'admin_email='.$_SERVER['admin_email'].'\' --data-urlencode \'config[rewrite_mode]=0\' --data-urlencode \'config[allow_raw_html]=1\' --data-urlencode \'config[allow_robots]=1\' --data-urlencode \'submit=Continue\' \'https://'.$herse.$domain.'/?PagePrincipale&installAction=install\' 2>&1';
|
||||
$curl = 'curl -X POST --insecure --data-urlencode \'config[default_language]=fr\' --data-urlencode \'config[wakka_name]='.$domain.'\' --data-urlencode \'config[root_page]=PagePrincipale\' --data-urlencode \'config[mysql_host]=localhost\' --data-urlencode \'config[mysql_database]='.$dbUser['database'].'\' --data-urlencode \'config[mysql_user]='.$dbUser['user'].'\' --data-urlencode \'config[mysql_password]='.$dbUser['password'].'\' --data-urlencode \'config[table_prefix]=yeswiki_\' --data-urlencode \'admin_name='.$_SERVER['admin_id'].'\' --data-urlencode \'admin_password='.$_SERVER['admin_password'].'\' --data-urlencode \'admin_password_conf='.$_SERVER['admin_password'].'\' --data-urlencode \'admin_email='.$_SERVER['admin_email'].'\' --data-urlencode \'config[rewrite_mode]=0\' --data-urlencode \'config[allow_raw_html]=1\' --data-urlencode \'config[allow_robots]=1\' --data-urlencode \'submit=Continue\' \'http'.($nossl ? '' : 's').'://'.$herse.$domain.'/?PagePrincipale&installAction=install\' 2>&1';
|
||||
$output = [];
|
||||
exec($curl, $output);
|
||||
//echo implode("\n", $output);
|
||||
|
|
|
@ -56,6 +56,12 @@ if (0 == posix_getuid()) {
|
|||
'description' => 'Say yes to every confirmation check (no prompt)',
|
||||
'noValue' => true,
|
||||
],
|
||||
'nossl' => [
|
||||
'prefix' => 'nossl',
|
||||
'longPrefix' => 'no-ssl-certificate',
|
||||
'description' => 'No SSL certificate and no DNS check',
|
||||
'noValue' => true,
|
||||
],
|
||||
]);
|
||||
$climate->arguments->parse();
|
||||
$domain = $climate->arguments->get('domain');
|
||||
|
@ -64,10 +70,13 @@ if (0 == posix_getuid()) {
|
|||
$quota = $climate->arguments->get('quota');
|
||||
$type = $climate->arguments->get('type');
|
||||
$confirm = $climate->arguments->get('confirm');
|
||||
$nossl = $climate->arguments->get('nossl');
|
||||
$herseUser = $climate->arguments->get('herseuser');
|
||||
$hersePass = $climate->arguments->get('hersepass');
|
||||
$isFullDomain = !preg_match('/.'.$_SERVER['maindomain'].'$/isU', $domain, $matches, PREG_OFFSET_CAPTURE, 0);
|
||||
if (!$nossl) {
|
||||
checkDNS($domain, $isFullDomain);
|
||||
}
|
||||
checkIfInstalled($domain);
|
||||
$needHerse = checkHerse($herseUser, $hersePass);
|
||||
$user = generateUserFromDomain($domain);
|
||||
|
@ -77,15 +86,15 @@ if (0 == posix_getuid()) {
|
|||
if ($confirm || $input->confirmed()) {
|
||||
$unixUser = createUnixUserWithQuota($user, $quota);
|
||||
$dbUser = createSQLUserAndDatabase($user, $type);
|
||||
createNginxConfig($domain, $user, $herseUser, $hersePass);
|
||||
createNginxConfig($domain, $user, $herseUser, $hersePass, $nossl);
|
||||
createPhpFpmConfig($user);
|
||||
if ($needHerse) {
|
||||
copyYesWikiFiles($domain, $user, $dbUser, $herseUser, $hersePass);
|
||||
copyYesWikiFiles($domain, $user, $dbUser, $herseUser, $hersePass, $nossl);
|
||||
} else {
|
||||
copyYesWikiFiles($domain, $user, $dbUser);
|
||||
copyYesWikiFiles($domain, $user, $dbUser, null, null, $nossl);
|
||||
}
|
||||
$climate->shout(
|
||||
'The yeswiki was successfully installed on <bold>https://'.$domain.'</bold>, congrats ! 🎉'."\n"
|
||||
'The yeswiki was successfully installed on <bold>http'.($nossl ? '' : 's').'://'.$domain.'</bold>, congrats ! 🎉'."\n"
|
||||
.' Unix user : <bold>'.$unixUser['user'].'</bold> with password : <bold>'.$unixUser['password'].'</bold> was created.'."\n"
|
||||
.'MySQL user : <bold>'.$dbUser['user'].'</bold> with password : <bold>'.$dbUser['password'].'</bold> was created for database <bold>'.$dbUser['database'].'</bold>.'."\n"
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue