Skip to content

Commit

Permalink
🚧 Getting vhost file parsing it to find vars to replace starting to r…
Browse files Browse the repository at this point in the history
…eplace with values
  • Loading branch information
tchartron committed Jan 29, 2019
1 parent 0d74f6d commit af9f82d
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 17 deletions.
11 changes: 7 additions & 4 deletions config/project.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
APP_NAME=example-app
APP_WEBSERVER=apache2
USER_FOLDER=/home/thomas
VHOST_FILENAME=005-example-app.conf
LOCAL_ADDRESS=example-app.work
DOCUMENT_ROOT=/var/www/example-app/public
APP_FOLDER=/home/thomas/www/example-app
APP_FOLDER_OWNER=thomas
APP_FOLDER_GROUP=thomas
APP_WEBSERVER=apache2
VHOST_FILENAME=005-example-app.conf
[email protected]
VHOST_LOCAL_ADDRESS=example-app.work
VHOST_DOCUMENT_ROOT=/var/www/example-app/public
VHOST_ERROR_LOG=/var/www/example-app/public
VHOST_ACCESS_LOG=/var/www/example-app/public

14 changes: 7 additions & 7 deletions config/vhost/apache2/vhost-basic
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# /etc/apache2/sites-available/websitename.conf
<VirtualHost *:80>
ServerAdmin [email protected]
ServerAdmin {{ VHOST_SERVERADMIN }}

# Domaines gérés par ce virtualhost
ServerName uwithi.work
ServerAlias *.uwithi.work
ServerName {{ VHOST_LOCAL_ADDRESS }}
ServerAlias *.{{ VHOST_LOCAL_ADDRESS }}

# Racine Web
DocumentRoot /var/www/uwithi/public
DocumentRoot {{ VHOST_DOCUMENT_ROOT }}

# Règles spécifiques s&apos;appliquant à ce dossier
<Directory /var/www/uwithi/public>
<Directory {{ VHOST_DOCUMENT_ROOT }}>
Options +Indexes +FollowSymLinks
AllowOverride All
</Directory>
# Où placer les logs pour cette hôte
ErrorLog /home/thomas/dev/logs/www/uwithi-error.log
CustomLog /home/thomas/dev/logs/www/uwithi-access.log combined
ErrorLog {{ VHOST_ERROR_LOG }}
CustomLog {{ VHOST_ACCESS_LOG }} combined
</VirtualHost>
2 changes: 2 additions & 0 deletions scripts/make-webapp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ require_once('../vendor/autoload.php');
use League\CLImate\CLImate;
use WebAppMaker\Configuration\Config;
$climate = new CLImate;

// define('TEST', '/test'); // TODO DEFINE ROOT PATH IT WILL BE AVAILABLE IN CLASSES
//Args
$climate->arguments->add([
'config' => [
Expand Down
88 changes: 82 additions & 6 deletions src/WebAppMaker/Configuration/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ public function buildAppConfiguration($values) : bool
}

//Step by step instead of loop through parameters values
//Create app dev folder
// die($values['USER_FOLDER']);
// die(var_dump(file_exists($values['USER_FOLDER'])));
// die(var_dump(is_dir(trim($values['USER_FOLDER']))));
//Create app dev folder APP_FOLDER
//set owner and groups to APP_FOLDER_OWNER:APP_FOLDER_GROUP
//check APP_WEBSERVER
//create vhost VHOST_FILENAME
//fill VHOST_FILENAME
//
/**
* IMPORTANT NOTE :
* Trim values is very important as it appear to have a CLRF/LF or a space and is_dir does not like this
Expand All @@ -85,11 +87,85 @@ public function buildAppConfiguration($values) : bool
} else {
$this->climateInstance->bold()->red()->out($values['USER_FOLDER'].' USER_FOLDER Incorrect value or not a directory');
}
//Create vhost
//Fill vhost

/////////////////////////////////////////
//WEB SERVER SPECIFIQUE CONFIGURATIONS //
/////////////////////////////////////////
if($this->noValueCheck($values['APP_WEBSERVER'])) {
switch(trim($values['APP_WEBSERVER'])) {
case 'apache2':
//Create vhost file
if($this->noValueCheck($values['VHOST_FILENAME'])) {
$this->climateInstance->backgroundLightGreen()->bold()->black()->out('Creating vhost file : '.$values['VHOST_FILENAME'].' in /etc/apache2/sites-available/');
$this->execOrFail("touch /etc/apache2/sites-available/".trim($values['VHOST_FILENAME']));
}
//Fill vhost
//trim trailing slash
// die(var_dump(TEST)); //Access constant
$vhostPath = realpath(__DIR__."/../../../config/vhost/apache2");
// $this->climateInstance->bold()->red()->out($vhostPath);
// die(var_dump($vhostPath));
$vhostPath = rtrim($vhostPath, "/");
// $brace = "{".implode(",", $this->allowedExtension)."}"; //{jpg,gif,png}
// die(realpath(__DIR__."../../config/vhost/apache2/"));
$files = glob($vhostPath."/*");
// $this->climateInstance->backgroundLightGreen()->bold()->black()->out("$vhostPath/*.$brace");
if(empty($files)) {
$this->climateInstance->bold()->red()->out("No config files found in ".$vhostPath);
exit();
}
$input = $this->climateInstance->radio('Please send me one of the following:', $files);
$vhostFile = $input->prompt();
if(file_exists($vhostFile)) {
$vhostContent = file_get_contents($vhostFile);
//Replace vars in template
//MAKE THIS A METHOD
preg_match_all("/{{[a-zA-Z_\s]+}}/", $vhostContent, $matches);
// die(var_dump($matches));
/*
*array(1) {
[0]=>
array(7) {
[0]=>
string(23) "{{ VHOST_SERVERADMIN }}"
[1]=>
string(25) "{{ VHOST_LOCAL_ADDRESS }}"
[2]=>
string(25) "{{ VHOST_LOCAL_ADDRESS }}"
[3]=>
string(25) "{{ VHOST_DOCUMENT_ROOT }}"
[4]=>
string(25) "{{ VHOST_DOCUMENT_ROOT }}"
[5]=>
string(21) "{{ VHOST_ERROR_LOG }}"
[6]=>
string(22) "{{ VHOST_ACCESS_LOG }}"
}
}
*/
if(is_array($matches)) {
foreach ($matches as $value) {

}
}
}
// return $response;
// die($vhostFile);
break;
case 'nginx':
break;
default:
$this->climateInstance->bold()->red()->out('Web server : '.$values['APP_WEBSERVER'].' not known');
break;
}
}


//Edit /etc/hosts
//a2ensite
//symlink dev folder and apache RootDirectory folder /var/www/uwithi/public
//reload apache

return false;
}
Expand Down

0 comments on commit af9f82d

Please sign in to comment.