-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b544920
Showing
940 changed files
with
98,667 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Created by https://www.gitignore.io | ||
|
||
### PhpStorm ### | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm | ||
|
||
*.iml | ||
|
||
## Directory-based project format: | ||
.idea/ | ||
# if you remove the above rule, at least ignore the following: | ||
|
||
# User-specific stuff: | ||
# .idea/workspace.xml | ||
# .idea/tasks.xml | ||
# .idea/dictionaries | ||
|
||
# Sensitive or high-churn files: | ||
# .idea/dataSources.ids | ||
# .idea/dataSources.xml | ||
# .idea/sqlDataSources.xml | ||
# .idea/dynamic.xml | ||
# .idea/uiDesigner.xml | ||
|
||
# Gradle: | ||
# .idea/gradle.xml | ||
# .idea/libraries | ||
|
||
# Mongo Explorer plugin: | ||
# .idea/mongoSettings.xml | ||
|
||
## File-based project format: | ||
*.ipr | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php namespace Vhost; | ||
|
||
|
||
/** | ||
* @file | ||
* @author Kevin Coyle | ||
* Contains the VHost Class. | ||
*/ | ||
|
||
class Vhost { | ||
private $name; | ||
private $vHostDir; | ||
private $domain; | ||
private $hostDir; | ||
/** | ||
* @return mixed | ||
*/ | ||
public function getDomain() | ||
{ | ||
return $this->domain; | ||
} | ||
|
||
public function __construct($name, $vHostDir, $hostDir) { | ||
$name = preg_replace('/\s+/', '', $name); | ||
$this->name = htmlspecialchars(strtolower($name)); | ||
$this->vHostDir = self::setVhostDir($vHostDir); | ||
$this->hostDir = $hostDir; | ||
} | ||
|
||
/** | ||
* Sets the Virtual Host Directory. | ||
* @param $vHostDir | ||
* @return mixed | ||
*/ | ||
private function setVhostDir($vHostDir) { | ||
if(file_exists($vHostDir)) { | ||
return $vHostDir; | ||
} | ||
throw new Exception('VHost Directory Does Not Exist'); | ||
} | ||
|
||
/** | ||
* Lists all Vhost conf files that have been created. | ||
* @param string $VhostDir | ||
* @return array | ||
*/ | ||
public function listVhosts() { | ||
$vHostDir = $this->vHostDir; | ||
if (!file_exists($vHostDir)) { | ||
throw new Exception('VHost Directory Does Not Exist'); | ||
} | ||
$files = array_diff(scandir($vHostDir), array('.', '..')); | ||
return $files; | ||
} | ||
|
||
/** | ||
* Creates the VHost File. | ||
* @param $name | ||
* @param $vHostDir | ||
*/ | ||
public function createVhostFile($name, $vHostDir) { | ||
$uniqueDomain = $this->generateUniqueDomain($name); | ||
$hostDir = $this->hostDir; | ||
$domain = $this->getDomain(); | ||
$output = <<<EOD | ||
<VirtualHost *:80> | ||
ServerName {$domain} | ||
ServerAdmin [email protected] | ||
ErrorLog /var/log/httpd/{$name}.err | ||
CustomLog /var/log/httpd/{$name}.log combined | ||
DocumentRoot {$hostDir}/{$name} | ||
<Directory "{$hostDir}/{$name}"> | ||
Order allow,deny | ||
Allow from all | ||
</Directory> | ||
</VirtualHost> | ||
EOD; | ||
file_put_contents("{$vHostDir}/{$name}.conf", $output . PHP_EOL); | ||
} | ||
|
||
/** | ||
* Generates a unique name that can be used for the domain name. | ||
* @return string | ||
*/ | ||
private function generateUniqueDomain($name) { | ||
$this->domain = uniqid($name . '-') . '.192.168.99.56.xip.io'; | ||
return $this->domain; | ||
} | ||
/** | ||
* Returns the contents of a VHost file. | ||
* @return string | ||
*/ | ||
public function getVhost() { | ||
$name = $this->name; | ||
$vHostDir = $this->vHostDir; | ||
$vHostFileName = $vHostDir . '/' . $name . '.conf'; | ||
if (!file_exists($vHostFileName)) { | ||
throw new Exception('VHost File Does Not Exist'); | ||
} | ||
return file_get_contents($vHostDir . '/' . $name . '.conf'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "coyledesign/centos-vhost-generator", | ||
"description": "Creates a new vhost on centos", | ||
"require-dev": { | ||
"phpunit/phpunit": "~4.4" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "kevincoyle", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": {} | ||
} |
Oops, something went wrong.