exec(@$_REQUEST['action'], $_REQUEST);
class gitmysite
{
private $allowed_actions = 'status add add-preview commit addcommit update-server-info creategitignore editgitignore showgitignore status init username log apache_secure diff sitelogin';
private $QueryVars = array();
private $gitCommand = '';
private $ignoreFileName = '.gitignore';
public $gitOutput = array();
public $file_gitignore = '';
public $Errors = array();
function gitmysite()
{
//Does anything need to be done on creation?
}
function exec($usercmd, $QueryVars)
{
if ($usercmd == '') {return;}
$this->QueryVars = $QueryVars;
// $this->getgitIgnoreFile();
//Defaults
$Require_Execute = true;
$this->gitOutput = array();
//Check if gitcommand is allowed.
if (strpos($this->allowed_actions, $usercmd) !== false)
{
$git_action = $usercmd;
switch ($git_action)
{
case 'add':
$gitexec[] = ' add -A';
$gitexec[] = ' status'; //print out status after
break;
case 'add-preview' :
$gitexec[] = ' add -A --dry-run';
break;
case 'commit':
$Comment = isset($QueryVars['commit_comment']) ? $QueryVars['commit_comment'] : 'an update';
$gitexec[] = " commit -m \"$Comment\" ";
break;
case 'addcommit':
$Comment = isset($QueryVars['commit_comment']) ? $QueryVars['commit_comment'] : 'an update';
$gitexec[] = " add -A "; //Add all files modified and new files first. git commit -a wont do as it does not add new files.
$gitexec[] = " commit -m \"$Comment\" ";
break;
case 'creategitignore':
$this->create_gitIgnoreFile();
$Require_Execute = false;
break;
case 'showgitignore':
$this->get_gitIgnoreFile();
$Require_Execute = false;
break;
case 'editgitignore':
$this->update_gitIgnoreFile($QueryVars['content_gitignore']);
$Require_Execute = false;
break;
case 'apache_secure':
if ($this->gitDirectorySecured() == false)
{
$this->createApacheSecurityFiles($this->QueryVars['apache_username'],$this->QueryVars['apache_pass']);
}
else
{
$this->Errors[] = 'Directory already contains .htaccess file, please delete via ftp or modify manually';
}
$Require_Execute = false;
break;
case 'username':
$ConfigInfo = json_encode(array('config' => array('user.name' => $this->QueryVars['username'])));
$this->CreateFile('.git/gitmysite.config',$ConfigInfo);
$gitexec[] = " config --local user.name \"$this->QueryVars[username]\" ";
$gitexec[] = " config --local user.email $this->QueryVars[email] ";
break;
default :
$gitexec[] = $git_action;
}
if ($Require_Execute)
{
$output = array();
$this->gitCommand = implode(';', $gitexec);
foreach ($gitexec as $cmd)
{
exec("git " . $cmd, $this->gitOutput);
}
//because we are a dumb server, call serverupdate after each time we execute commands.
exec("git update-server-info", $this->gitOutput);
}
}
else
{
$this->Errors[] = $usercmd . ' is not an allowable command';
}
}
function createApacheSecurityFiles($apacheuser, $apachepass)
{
$rootpath = $this->ensure_finalslash($_SERVER['DOCUMENT_ROOT']);
$file_htaccess = "AuthUserFile $rootpath.git/.htpasswd
AuthGroupFile /dev/null
AuthName \"Secured Directory\"
AuthType Basic
$Error
Please change Default Password: '$PASS' in gitmysite.php script
Create a New Repository in this Directory
gitDirectorySecured()) { ?>Directory Security
Secure the Directory
Create and Edit Git Ignore File
file_gitignore > '') { ?> exists_gitIgnoreFile()) {?>
Command Results