From af9f82d25c6d0100eade95cef23468fdf6449e38 Mon Sep 17 00:00:00 2001 From: Thomas Chartron Date: Tue, 29 Jan 2019 23:28:41 +0100 Subject: [PATCH] :construction: Getting vhost file parsing it to find vars to replace starting to replace with values --- config/project.conf | 11 +-- config/vhost/apache2/vhost-basic | 14 ++-- scripts/make-webapp | 2 + src/WebAppMaker/Configuration/Config.php | 88 ++++++++++++++++++++++-- 4 files changed, 98 insertions(+), 17 deletions(-) diff --git a/config/project.conf b/config/project.conf index 6a8d638..79f7243 100644 --- a/config/project.conf +++ b/config/project.conf @@ -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 +VHOST_SERVERADMIN=thomas.chartron@gmail.com +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 diff --git a/config/vhost/apache2/vhost-basic b/config/vhost/apache2/vhost-basic index d52d963..8b39b1a 100644 --- a/config/vhost/apache2/vhost-basic +++ b/config/vhost/apache2/vhost-basic @@ -1,20 +1,20 @@ # /etc/apache2/sites-available/websitename.conf -ServerAdmin thomas.chartron@gmail.com +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'appliquant à ce dossier - + Options +Indexes +FollowSymLinks AllowOverride All # 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 diff --git a/scripts/make-webapp b/scripts/make-webapp index 37c2a5b..95a07dc 100755 --- a/scripts/make-webapp +++ b/scripts/make-webapp @@ -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' => [ diff --git a/src/WebAppMaker/Configuration/Config.php b/src/WebAppMaker/Configuration/Config.php index 4639dbc..d8c0eee 100644 --- a/src/WebAppMaker/Configuration/Config.php +++ b/src/WebAppMaker/Configuration/Config.php @@ -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 @@ -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; }