feat : add updater that can only list wikis

This commit is contained in:
Florian Schmitt 2024-01-09 15:40:28 +03:00
parent d9c9096d8c
commit b25aa91743
3 changed files with 367 additions and 253 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
.env .env
/vendor/* /vendor/*
yeswiki-list.csv

View file

@ -5,52 +5,52 @@ require 'vendor/autoload.php';
function checkIP($domain, $withWww = false, $noip6 = false) function checkIP($domain, $withWww = false, $noip6 = false)
{ {
if (!preg_match('/(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)/', strtolower($domain))) { if (!preg_match('/(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)/', strtolower($domain))) {
throw new Exception('not valid domain : "'.$domain.'".'); throw new Exception('not valid domain : "' . $domain . '".');
} }
$output = shell_exec('ping -c1 -4 '.$domain); $output = shell_exec('ping -c1 -4 ' . $domain);
preg_match_all('/PING.*\(.*((\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}).*\)/m', $output, $matches, PREG_SET_ORDER, 0); preg_match_all('/PING.*\(.*((\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}).*\)/m', $output, $matches, PREG_SET_ORDER, 0);
$currentip = $matches[0][1] ?? null; $currentip = $matches[0][1] ?? null;
if (empty($currentip)) { if (empty($currentip)) {
throw new Exception('the domain '.$domain.' has no ip v4.'); throw new Exception('the domain ' . $domain . ' has no ip v4.');
} }
if ($currentip !== $_SERVER['ip4']) { if ($currentip !== $_SERVER['ip4']) {
throw new Exception('the current ip v4 address of '.$domain.' is '.$currentip.'. it should be '.$_SERVER['ip4']); throw new Exception('the current ip v4 address of ' . $domain . ' is ' . $currentip . '. it should be ' . $_SERVER['ip4']);
} }
if (!$noip6) { if (!$noip6) {
$output = shell_exec('ping -c1 -6 '.$domain); $output = shell_exec('ping -c1 -6 ' . $domain);
preg_match_all('/PING.*\((([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\)/m', $output, $matches, PREG_SET_ORDER, 0); preg_match_all('/PING.*\((([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\)/m', $output, $matches, PREG_SET_ORDER, 0);
$currentip6 = $matches[0][1] ?? null; $currentip6 = $matches[0][1] ?? null;
if (empty($currentip6)) { if (empty($currentip6)) {
throw new Exception('the domain '.$domain.' has no ip v6.'); throw new Exception('the domain ' . $domain . ' has no ip v6.');
} }
if ($currentip6 !== $_SERVER['ip6']) { if ($currentip6 !== $_SERVER['ip6']) {
throw new Exception('the current ip v6 address of '.$domain.' is '.$currentip6.'. it should be '.$_SERVER['ip6']); throw new Exception('the current ip v6 address of ' . $domain . ' is ' . $currentip6 . '. it should be ' . $_SERVER['ip6']);
} }
} }
if ($withWww) { if ($withWww) {
$dnsentries = dns_get_record('www.'.$domain, DNS_A + DNS_AAAA + DNS_CNAME); $dnsentries = dns_get_record('www.' . $domain, DNS_A + DNS_AAAA + DNS_CNAME);
$foundCnameEntry = false; $foundCnameEntry = false;
$foundIp4 = false; $foundIp4 = false;
$foundIp6 = false; $foundIp6 = false;
foreach($dnsentries as $key => $row) { foreach ($dnsentries as $key => $row) {
if ($row['host'] == 'www.'.$domain && $row['type']=='CNAME' && $row['target'] == $domain) { if ($row['host'] == 'www.' . $domain && $row['type'] == 'CNAME' && $row['target'] == $domain) {
$foundCnameEntry = true; $foundCnameEntry = true;
} }
if ($row['host'] == 'www.'.$domain && $row['type']=='A' && $row['ip'] == $_SERVER['ip4']) { if ($row['host'] == 'www.' . $domain && $row['type'] == 'A' && $row['ip'] == $_SERVER['ip4']) {
$foundIp4 = true; $foundIp4 = true;
} }
if (!$noip6) { if (!$noip6) {
if ($row['host'] == 'www.'.$domain && $row['type']=='AAAA' && $row['ipv6'] == $_SERVER['ip6']) { if ($row['host'] == 'www.' . $domain && $row['type'] == 'AAAA' && $row['ipv6'] == $_SERVER['ip6']) {
$foundIp6 = true; $foundIp6 = true;
} }
} }
} }
if (!$foundCnameEntry) { if (!$foundCnameEntry) {
if (!$foundIp4) { if (!$foundIp4) {
throw new Exception('the domain www.'.$domain.' was not found in DNS record as a CNAME targeting '.$domain."\n".' or A entry to '.$_SERVER['ip4']); throw new Exception('the domain www.' . $domain . ' was not found in DNS record as a CNAME targeting ' . $domain . "\n" . ' or A entry to ' . $_SERVER['ip4']);
} }
if (!$noip6 && !$foundIp6) { if (!$noip6 && !$foundIp6) {
throw new Exception('the domain www.'.$domain.' was not found in DNS record as a CNAME targeting '.$domain."\n".' or AAAA entry to '.$_SERVER['ip6'].'.'); throw new Exception('the domain www.' . $domain . ' was not found in DNS record as a CNAME targeting ' . $domain . "\n" . ' or AAAA entry to ' . $_SERVER['ip6'] . '.');
} }
} }
} }
@ -59,24 +59,24 @@ function checkIP($domain, $withWww = false, $noip6 = false)
function checkIfInstalled($domain) function checkIfInstalled($domain)
{ {
exec('find /home/* -maxdepth 1 -type d | grep '.$domain, $output); exec('find /home/* -maxdepth 1 -type d | grep ' . $domain, $output);
if (!empty($output)) { if (!empty($output)) {
throw new Exception('the domain '.$domain.' was already found on the server.'); throw new Exception('the domain ' . $domain . ' was already found on the server.');
} }
} }
function checkIfUserExist($user) function checkIfUserExist($user)
{ {
exec('cut -d: -f1 /etc/passwd | grep '.$user, $output); exec('cut -d: -f1 /etc/passwd | grep ' . $user, $output);
return !empty($output); return !empty($output);
} }
function generateUserFromDomain($domain, $recursive = null) function generateUserFromDomain($domain, $recursive = null)
{ {
if ($recursive == 100) { if ($recursive == 100) {
throw new Exception('Too much users found, 100 that is too much for '.$domain); throw new Exception('Too much users found, 100 that is too much for ' . $domain);
} }
$user = str_split(str_replace([$_SERVER['maindomain'], '-', '.'], '', $domain), 30)[0].$recursive; $user = str_split(str_replace([$_SERVER['maindomain'], '-', '.'], '', $domain), 30)[0] . $recursive;
// try anthor username if user exists or if reserved name // try anthor username if user exists or if reserved name
if (checkIfUserExist($user) || in_array($user, explode(',', $_SERVER['reservedsubdomains']))) { if (checkIfUserExist($user) || in_array($user, explode(',', $_SERVER['reservedsubdomains']))) {
if ($recursive === null) { if ($recursive === null) {
@ -89,11 +89,11 @@ function generateUserFromDomain($domain, $recursive = null)
function findUserFromExistingDomain($domain) function findUserFromExistingDomain($domain)
{ {
exec('find /home/* -maxdepth 1 -type d | grep '.$domain, $output); exec('find /home/* -maxdepth 1 -type d | grep ' . $domain, $output);
if (empty($output)) { if (empty($output)) {
throw new Exception('the domain '.$domain.' was not found on the server.'); throw new Exception('the domain ' . $domain . ' was not found on the server.');
} else { } else {
return str_replace(['/home/', '/'.$domain], '', $output[0]); return str_replace(['/home/', '/' . $domain], '', $output[0]);
} }
} }
@ -144,36 +144,36 @@ function generatePassword($length = 32, $add_dashes = false, $available_sets = '
function createSQLUserAndDatabase($user, $type) function createSQLUserAndDatabase($user, $type)
{ {
$pass = generatePassword(); $pass = generatePassword();
exec('mysql -u '.$_SERVER['mysqluser'].' -p\''.$_SERVER['mysqlpassword'].'\' -e \'CREATE DATABASE IF NOT EXISTS '.$user.';\'', $output); exec('mysql -u ' . $_SERVER['mysqluser'] . ' -p\'' . $_SERVER['mysqlpassword'] . '\' -e \'CREATE DATABASE IF NOT EXISTS ' . $user . ';\'', $output);
exec('mysql -u '.$_SERVER['mysqluser'].' -p\''.$_SERVER['mysqlpassword'].'\' -e "CREATE USER IF NOT EXISTS \''.$user.'\'@\'localhost\' IDENTIFIED BY \''.$pass.'\';"', $output); exec('mysql -u ' . $_SERVER['mysqluser'] . ' -p\'' . $_SERVER['mysqlpassword'] . '\' -e "CREATE USER IF NOT EXISTS \'' . $user . '\'@\'localhost\' IDENTIFIED BY \'' . $pass . '\';"', $output);
exec('mysql -u '.$_SERVER['mysqluser'].' -p\''.$_SERVER['mysqlpassword'].'\' -e "GRANT ALL PRIVILEGES ON '.$user.'.* TO \''.$user.'\'@\'localhost\';"', $output); exec('mysql -u ' . $_SERVER['mysqluser'] . ' -p\'' . $_SERVER['mysqlpassword'] . '\' -e "GRANT ALL PRIVILEGES ON ' . $user . '.* TO \'' . $user . '\'@\'localhost\';"', $output);
exec('mysql -u '.$_SERVER['mysqluser'].' -p\''.$_SERVER['mysqlpassword'].'\' -e "FLUSH PRIVILEGES;"', $output); exec('mysql -u ' . $_SERVER['mysqluser'] . ' -p\'' . $_SERVER['mysqlpassword'] . '\' -e "FLUSH PRIVILEGES;"', $output);
$databaseModel = ($type === 'solo') ? $_SERVER['solomodel'] : $_SERVER['fermemodel']; $databaseModel = ($type === 'solo') ? $_SERVER['solomodel'] : $_SERVER['fermemodel'];
exec('mysqldump -u '.$_SERVER['mysqluser'].' -p\''.$_SERVER['mysqlpassword'].'\' -v '.$databaseModel.' | mysql -u '.$user.' -p\''.$pass.'\' -D '.$user, $output); exec('mysqldump -u ' . $_SERVER['mysqluser'] . ' -p\'' . $_SERVER['mysqlpassword'] . '\' -v ' . $databaseModel . ' | mysql -u ' . $user . ' -p\'' . $pass . '\' -D ' . $user, $output);
// TODO: add first user and make him admin // TODO: add first user and make him admin
return ['database' => $user, 'user' => $user, 'password' => $pass]; return ['database' => $user, 'user' => $user, 'password' => $pass];
} }
function removeMySQLUserAndDatabase($user) function removeMySQLUserAndDatabase($user)
{ {
exec('mysql -u '.$_SERVER['mysqluser'].' -p\''.$_SERVER['mysqlpassword'].'\' -e \'DROP DATABASE IF EXISTS '.$user.';\'', $output); exec('mysql -u ' . $_SERVER['mysqluser'] . ' -p\'' . $_SERVER['mysqlpassword'] . '\' -e \'DROP DATABASE IF EXISTS ' . $user . ';\'', $output);
exec('mysql -u '.$_SERVER['mysqluser'].' -p\''.$_SERVER['mysqlpassword'].'\' -e "DROP USER IF EXISTS \''.$user.'\'@\'localhost\';"', $output); exec('mysql -u ' . $_SERVER['mysqluser'] . ' -p\'' . $_SERVER['mysqlpassword'] . '\' -e "DROP USER IF EXISTS \'' . $user . '\'@\'localhost\';"', $output);
exec('mysql -u '.$_SERVER['mysqluser'].' -p\''.$_SERVER['mysqlpassword'].'\' -e "FLUSH PRIVILEGES;"', $output); exec('mysql -u ' . $_SERVER['mysqluser'] . ' -p\'' . $_SERVER['mysqlpassword'] . '\' -e "FLUSH PRIVILEGES;"', $output);
return; return;
} }
function createUnixUserWithQuota($user, $quota) function createUnixUserWithQuota($user, $quota)
{ {
$pass = generatePassword(); $pass = generatePassword();
exec('useradd -m -p "'.$pass.'" '.$user, $output); exec('useradd -m -p "' . $pass . '" ' . $user, $output);
exec('setquota -u '.$user.' '.$quota.' '.$quota.' 0 0 -a /dev/loop0', $output); exec('setquota -u ' . $user . ' ' . $quota . ' ' . $quota . ' 0 0 -a /dev/loop0', $output);
// TODO : handle errors // TODO : handle errors
return ['user' => $user, 'password' => $pass, 'quota' => $quota]; return ['user' => $user, 'password' => $pass, 'quota' => $quota];
} }
function removeUnixUser($user) function removeUnixUser($user)
{ {
exec('deluser --remove-home '.$user, $output); exec('deluser --remove-home ' . $user, $output);
// TODO : handle errors // TODO : handle errors
return; return;
} }
@ -181,9 +181,9 @@ function removeUnixUser($user)
function createNginxConfig($domain, $user, $herseUser, $hersePass, $nossl) function createNginxConfig($domain, $user, $herseUser, $hersePass, $nossl)
{ {
// create folder if not exists // create folder if not exists
exec('sudo -u '.$user.' mkdir -p /home'.'/'.$user.'/'.$domain); exec('sudo -u ' . $user . ' mkdir -p /home' . '/' . $user . '/' . $domain);
$nginxFile = '/etc/nginx/conf.d/'.$domain.'.conf'; $nginxFile = '/etc/nginx/conf.d/' . $domain . '.conf';
if (empty($herseUser) && empty($hersePass)) { if (empty($herseUser) && empty($hersePass)) {
// no herse needed // no herse needed
} elseif (empty($herseUser) || empty($hersePass)) { } elseif (empty($herseUser) || empty($hersePass)) {
@ -191,12 +191,12 @@ function createNginxConfig($domain, $user, $herseUser, $hersePass, $nossl)
} else { } else {
// add password file to domain // add password file to domain
file_put_contents( file_put_contents(
'/home'.'/'.$user.'/'.$domain.'/.htpasswd', '/home' . '/' . $user . '/' . $domain . '/.htpasswd',
$herseUser.':'.password_hash($hersePass, PASSWORD_BCRYPT) $herseUser . ':' . password_hash($hersePass, PASSWORD_BCRYPT)
); );
} }
$templates = new League\Plates\Engine(dirname(__FILE__).'/templates'); $templates = new League\Plates\Engine(dirname(__FILE__) . '/templates');
$subDomain = preg_match('/.'.$_SERVER['maindomain'].'$/isU', $domain, $matches, PREG_OFFSET_CAPTURE, 0); $subDomain = preg_match('/.' . $_SERVER['maindomain'] . '$/isU', $domain, $matches, PREG_OFFSET_CAPTURE, 0);
$isFullDomain = !preg_match('/^([a-zA-Z0-9]([-a-zA-Z0-9]{0,61}[a-zA-Z0-9])\.)([a-zA-Z0-9]{1,2}([-a-zA-Z0-9]{0,252}[a-zA-Z0-9])?)\.([a-zA-Z]{2,63})$/isU', $domain, $matches, PREG_OFFSET_CAPTURE, 0); $isFullDomain = !preg_match('/^([a-zA-Z0-9]([-a-zA-Z0-9]{0,61}[a-zA-Z0-9])\.)([a-zA-Z0-9]{1,2}([-a-zA-Z0-9]{0,252}[a-zA-Z0-9])?)\.([a-zA-Z]{2,63})$/isU', $domain, $matches, PREG_OFFSET_CAPTURE, 0);
if (!$nossl) { if (!$nossl) {
if (!$subDomain) { if (!$subDomain) {
@ -212,16 +212,16 @@ function createNginxConfig($domain, $user, $herseUser, $hersePass, $nossl)
); );
exec('service nginx force-reload', $output); exec('service nginx force-reload', $output);
if ($isFullDomain) { if ($isFullDomain) {
exec('/root/.acme.sh/acme.sh --issue -d '.$domain.' -d www.'.$domain.' -k ec-384 -w /home/'.$user.'/'.$domain.'/', $output); exec('/root/.acme.sh/acme.sh --issue -d ' . $domain . ' -d www.' . $domain . ' -k ec-384 -w /home/' . $user . '/' . $domain . '/', $output);
} else { } else {
exec('/root/.acme.sh/acme.sh --issue -d '.$domain.' -k ec-384 -w /home/'.$user.'/'.$domain.'/', $output); exec('/root/.acme.sh/acme.sh --issue -d ' . $domain . ' -k ec-384 -w /home/' . $user . '/' . $domain . '/', $output);
} }
exec('mkdir -p /etc/letsencrypt/live/'.$domain, $output); exec('mkdir -p /etc/letsencrypt/live/' . $domain, $output);
exec('/root/.acme.sh/acme.sh --install-cert -d '.$domain.' --ecc \ exec('/root/.acme.sh/acme.sh --install-cert -d ' . $domain . ' --ecc \
--cert-file /etc/letsencrypt/live/'.$domain.'/cert.pem \ --cert-file /etc/letsencrypt/live/' . $domain . '/cert.pem \
--key-file /etc/letsencrypt/live/'.$domain.'/key.pem \ --key-file /etc/letsencrypt/live/' . $domain . '/key.pem \
--fullchain-file /etc/letsencrypt/live/'.$domain.'/fullchain.pem \ --fullchain-file /etc/letsencrypt/live/' . $domain . '/fullchain.pem \
--ca-file /etc/letsencrypt/live/'.$domain.'/ca.pem \ --ca-file /etc/letsencrypt/live/' . $domain . '/ca.pem \
--reloadcmd "systemctl restart nginx.service"', $output); --reloadcmd "systemctl restart nginx.service"', $output);
} }
file_put_contents( file_put_contents(
@ -257,7 +257,7 @@ function createNginxConfig($domain, $user, $herseUser, $hersePass, $nossl)
function removeNginxConfig($domain) function removeNginxConfig($domain)
{ {
$nginxFile = '/etc/nginx/conf.d/'.$domain.'.conf'; $nginxFile = '/etc/nginx/conf.d/' . $domain . '.conf';
unlink($nginxFile); unlink($nginxFile);
exec('service nginx force-reload', $output); exec('service nginx force-reload', $output);
} }
@ -265,40 +265,40 @@ function removeNginxConfig($domain)
function createPhpFpmConfig($user) function createPhpFpmConfig($user)
{ {
$phpVersion = str_replace(['php', '-fpm'], '', $_SERVER['phpservice']); $phpVersion = str_replace(['php', '-fpm'], '', $_SERVER['phpservice']);
$phpConfFile = '/etc/php/'.$phpVersion.'/fpm/pool.d/'.$user.'.conf'; $phpConfFile = '/etc/php/' . $phpVersion . '/fpm/pool.d/' . $user . '.conf';
$templates = new League\Plates\Engine(dirname(__FILE__).'/templates'); $templates = new League\Plates\Engine(dirname(__FILE__) . '/templates');
file_put_contents($phpConfFile, $templates->render('php-fpm', ['user' => $user])); file_put_contents($phpConfFile, $templates->render('php-fpm', ['user' => $user]));
exec('service '.$_SERVER['phpservice'].' reload', $output); exec('service ' . $_SERVER['phpservice'] . ' reload', $output);
} }
function removePhpFpmConfig($user) function removePhpFpmConfig($user)
{ {
$phpVersion = str_replace(['php', '-fpm'], '', $_SERVER['phpservice']); $phpVersion = str_replace(['php', '-fpm'], '', $_SERVER['phpservice']);
$phpConfFile = '/etc/php/'.$phpVersion.'/fpm/pool.d/'.$user.'.conf'; $phpConfFile = '/etc/php/' . $phpVersion . '/fpm/pool.d/' . $user . '.conf';
unlink($phpConfFile); unlink($phpConfFile);
exec('service '.$_SERVER['phpservice'].' reload', $output); exec('service ' . $_SERVER['phpservice'] . ' reload', $output);
} }
function copyYesWikiFiles($domain, $user, $dbUser, $herseUser = null, $hersePass = null, $nossl = null) function copyYesWikiFiles($domain, $user, $dbUser, $herseUser = null, $hersePass = null, $nossl = null)
{ {
$tmpFile = '/tmp/yeswiki.zip'; $tmpFile = '/tmp/yeswiki.zip';
$destDir = '/home'.'/'.$user.'/'.$domain; $destDir = '/home' . '/' . $user . '/' . $domain;
$sudo = 'sudo -u '.$user.' '; $sudo = 'sudo -u ' . $user . ' ';
exec($sudo.' mkdir -p '.$destDir, $output); exec($sudo . ' mkdir -p ' . $destDir, $output);
exec($sudo.' chown '.$user.':'.$user.' -R '.$destDir, $output); exec($sudo . ' chown ' . $user . ':' . $user . ' -R ' . $destDir, $output);
if (file_exists($tmpFile)) { if (file_exists($tmpFile)) {
unlink($tmpFile); unlink($tmpFile);
} }
exec($sudo.'curl --insecure -o '.$tmpFile.' '.$_SERVER['source_archive_url']); exec($sudo . 'curl --insecure -o ' . $tmpFile . ' ' . $_SERVER['source_archive_url']);
exec($sudo.'unzip '.$tmpFile.' "doryphore/*" -d '.$destDir); exec($sudo . 'unzip ' . $tmpFile . ' "doryphore/*" -d ' . $destDir);
exec($sudo.'mv '.$destDir.'/doryphore/* '.$destDir.'/'); exec($sudo . 'mv ' . $destDir . '/doryphore/* ' . $destDir . '/');
exec($sudo.'rm -rf '.$destDir.'/doryphore'); exec($sudo . 'rm -rf ' . $destDir . '/doryphore');
unlink($tmpFile); unlink($tmpFile);
$herse = ''; $herse = '';
if (!empty($herseUser) && !empty($hersePass)) { if (!empty($herseUser) && !empty($hersePass)) {
$herse = $herseUser.':'.$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\' \'http'.($nossl ? '' : 's').'://'.$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 = []; $output = [];
exec($curl, $output); exec($curl, $output);
//echo implode("\n", $output); //echo implode("\n", $output);
@ -315,7 +315,8 @@ function checkHerse($herseUser, $hersePass)
return true; // herse needed return true; // herse needed
} }
function editConfigFile() { function editConfigFile()
{
// change fuseau horaire // change fuseau horaire
// 'contact_mail_func' => 'smtp', // 'contact_mail_func' => 'smtp',
// 'contact_smtp_host' => 'ssl://mail.gandi.net', // 'contact_smtp_host' => 'ssl://mail.gandi.net',
@ -326,12 +327,48 @@ function editConfigFile() {
} }
function addExtensions() { function addExtensions()
{
// ferme pour l'option ferme // ferme pour l'option ferme
} }
function addStatistics() { function addStatistics()
{
// requete SQL // requete SQL
// INSERT INTO `matomo_site` (`idsite`, `name`, `main_url`, `ts_created`, `ecommerce`, `sitesearch`, `sitesearch_keyword_parameters`, `sitesearch_category_parameters`, `timezone`, `currency`, `exclude_unknown_urls`, `excluded_ips`, `excluded_parameters`, `excluded_user_agents`, `excluded_referrers`, `group`, `type`, `keep_url_fragment`, `creator_login`) VALUES (NULL, 'Partage ton outil', 'https://partagetonoutil.fr', '2023-02-01 00:00:00', '0', '1', '', '', 'Europe/Paris', 'EUR', '0', '', '', '', '', '', 'website', '0', 'superadmin'); // INSERT INTO `matomo_site` (`idsite`, `name`, `main_url`, `ts_created`, `ecommerce`, `sitesearch`, `sitesearch_keyword_parameters`, `sitesearch_category_parameters`, `timezone`, `currency`, `exclude_unknown_urls`, `excluded_ips`, `excluded_parameters`, `excluded_user_agents`, `excluded_referrers`, `group`, `type`, `keep_url_fragment`, `creator_login`) VALUES (NULL, 'Partage ton outil', 'https://partagetonoutil.fr', '2023-02-01 00:00:00', '0', '1', '', '', 'Europe/Paris', 'EUR', '0', '', '', '', '', '', 'website', '0', 'superadmin');
} }
function searchWikis($path, $pattern)
{
$it = new RecursiveDirectoryIterator($path);
$list = array();
foreach (new RecursiveIteratorIterator($it) as $file) {
if (preg_match('/' . preg_quote($pattern) . '$/i', $file)) {
$wakkaConfig = [];
include_once($file);
$list[] = [
'URL' => $wakkaConfig['base_url'] ?? 'KO',
'VERSION' => $wakkaConfig['yeswiki_version'] ?? 'KO',
'RELEASE' => $wakkaConfig['yeswiki_release'] ?? 'KO',
];
}
}
return $list;
}

76
yeswiki-updater.php Executable file
View file

@ -0,0 +1,76 @@
#!/usr/bin/php
<?php
require_once('vendor/autoload.php');
require_once('utils.inc.php');
use DevCoder\DotEnv;
$climate = new League\CLImate\CLImate();
$climate->description('yeswiki-updater, find and update YesWiki like a professionnal 🌈🦄');
if (0 == posix_getuid()) {
$absolutePathToEnvFile = __DIR__ . '/.env';
if (file_exists($absolutePathToEnvFile)) {
(new DotEnv($absolutePathToEnvFile))->load();
} else {
$climate->error('ERROR : No .env file found.');
exit;
}
$climate->arguments->add([
'path' => [
'prefix' => 'p',
'longPrefix' => 'path',
'description' => 'Path to scan for wikis',
'required' => true,
'defaultValue' => '/var/www/html'
],
'output' => [
'prefix' => 'o',
'longPrefix' => 'output',
'description' => 'Output results in table format, json or csv',
'defaultValue' => 'table'
],
'update' => [
'prefix' => 'u',
'longPrefix' => 'update',
'description' => 'Update to latest version of stable yeswiki',
'defaultValue' => '0'
],
]);
$climate->arguments->parse();
$path = $climate->arguments->get('path');
if (!empty($path) && is_dir($path)) {
try {
$update = $climate->arguments->get('update');
$output = $climate->arguments->get('output');
$matches = searchWikis($path, 'wakka.config.php');
switch ($output) {
case 'table':
$climate->table($matches);
break;
case 'json':
$climate->json($matches);
break;
case 'csv':
$fileName = 'yeswiki-list.csv';
$file = fopen($fileName, "w");
foreach ($matches as $line) {
fputcsv($file, $line);
}
$climate->info($fileName . ' was created.');
break;
}
} catch (Exception $e) {
$climate->error('ERROR : ' . $e->getMessage());
}
} else {
$climate->usage();
}
} else {
$climate->error('ERROR : this script needs root privilege to run.');
exit;
}