134 lines
3.4 KiB
PHP
134 lines
3.4 KiB
PHP
<?php
|
|
|
|
function checkDNS($domain, $ip4 = '138.201.86.17', $ip6 = '2a01:4f8:172:21c9::2') {
|
|
if (!preg_match('/(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)/', strtolower($domain))) {
|
|
return ['error' => 'Not valid domain.'];
|
|
}
|
|
$currentip = dns_get_record($domain, DNS_A + DNS_AAAA);
|
|
if ($currentip[0]['ip'] !== $ip4) {
|
|
return ['error' => 'The current ip v4 address of '.$domain.' is '.$currentip[0]['ip'].'. it should be '.$ip4];
|
|
}
|
|
if ($currentip[1]['ipv6'] !== $ip6) {
|
|
return ['error' => 'The current ip v6 address of '.$domain.' is '.$currentip[1]['ipv6'].'. it should be '.$ip6];
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function checkIfInstalled($domain) {
|
|
return true;
|
|
}
|
|
|
|
function checkIfUserExist($user) {
|
|
return true;
|
|
}
|
|
|
|
function generateUserFromDomain($domain, $recursive = null) {
|
|
$user = 'toto';
|
|
return $user;
|
|
}
|
|
|
|
function generatePassword($length = 32, $add_dashes = false, $available_sets = 'luds') {
|
|
$sets = array();
|
|
if(strpos($available_sets, 'l') !== false)
|
|
$sets[] = 'abcdefghjkmnpqrstuvwxyz';
|
|
if(strpos($available_sets, 'u') !== false)
|
|
$sets[] = 'ABCDEFGHJKMNPQRSTUVWXYZ';
|
|
if(strpos($available_sets, 'd') !== false)
|
|
$sets[] = '23456789';
|
|
if(strpos($available_sets, 's') !== false)
|
|
$sets[] = '!@#$%&*?';
|
|
|
|
$all = '';
|
|
$password = '';
|
|
foreach($sets as $set)
|
|
{
|
|
$password .= $set[array_rand(str_split($set))];
|
|
$all .= $set;
|
|
}
|
|
|
|
$all = str_split($all);
|
|
for($i = 0; $i < $length - count($sets); $i++)
|
|
$password .= $all[array_rand($all)];
|
|
|
|
$password = str_shuffle($password);
|
|
|
|
if(!$add_dashes)
|
|
return $password;
|
|
|
|
$dash_len = floor(sqrt($length));
|
|
$dash_str = '';
|
|
while(strlen($password) > $dash_len)
|
|
{
|
|
$dash_str .= substr($password, 0, $dash_len) . '-';
|
|
$password = substr($password, $dash_len);
|
|
}
|
|
$dash_str .= $password;
|
|
return $dash_str;
|
|
}
|
|
|
|
function createSQLUserAndDatabase($user) {
|
|
$pass = generatePassword();
|
|
return ['database' => 'dbtata', 'user' => 'dbtata', 'password' => $pass];
|
|
}
|
|
|
|
function createUnixUserWithQuota($user, $quota) {
|
|
$pass = generatePassword();
|
|
return ['user' => 'toto', 'password' => $pass, 'quota' => $quota];
|
|
}
|
|
|
|
function createNginxConfig($domain, $user) {
|
|
|
|
}
|
|
|
|
function createPhpFpmConfig($user) {
|
|
|
|
}
|
|
|
|
function copyYesWikiFiles($domain, $user) {
|
|
|
|
}
|
|
|
|
function copyYesWikiDatabase($databaseModel) {
|
|
|
|
}
|
|
|
|
function addHerse($id, $pass) {
|
|
return ['user' => $id, 'password' => $pass];
|
|
}
|
|
|
|
function installYesWiki($domain, $quota, $type) {
|
|
$res = checkDNS($domain);
|
|
if (!empty($res['error'])) {
|
|
return $res;
|
|
}
|
|
$res = checkIfInstalled($domain);
|
|
if (!empty($res['error'])) {
|
|
return $res;
|
|
}
|
|
$user = generateUserFromDomain($domain);
|
|
$unixUser = createUnixUserWithQuota($user, $quota);
|
|
$dbUser = createSQLUserAndDatabase($user);
|
|
createNginxConfig($domain, $user);
|
|
createPhpFpmConfig($user);
|
|
copyYesWikiFiles($domain, $user);
|
|
$databaseModel = ($type === 'solo') ? 'modelesolo' : 'modeleferme' ;
|
|
copyYesWikiDatabase($databaseModel);
|
|
|
|
$herseUser = [];
|
|
if (!empty($herseId) && !empty($hersePass)) {
|
|
$herseUser = addHerse($herseId, $hersePass);
|
|
}
|
|
return [
|
|
'domain'=> $domain,
|
|
'type' => $type,
|
|
'user' => $unixUser,
|
|
'db' => $dbUser,
|
|
'herse' => $herseUser
|
|
];
|
|
}
|
|
|
|
function removeYesWiki($domain, $user) {
|
|
// enlever la db et le user sql
|
|
// enlever la config nginx et la conf php-fpm
|
|
// enlever le user unix et son home
|
|
}
|