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 require valid-user "; $cryptpass = crypt($apachepass); $file_htpass = "$apacheuser:$cryptpass"; $this->CreateFile('.git/.htaccess', $file_htaccess); $this->CreateFile('.git/.htpasswd', $file_htpass); } function create_gitIgnoreFile($Content = 'default') { if ($this->exists_gitIgnoreFile()){ $this->Errors[] = '.gitignore file already exists, please edit or delete to create a new one.'; } else { if ($Content == 'default') { $Content = " #Default .gitignore files for gitmysite. #Created by gitmysite.php https://github.com/tobya/gitmysite #Specify your own .gitignore file *.exe *.jpg *.png *.bmp *.gif "; } $this->CreateFile($this->ignoreFileName, $Content); } } function CreateFile($FileName, $Content) { $myFile = $FileName; $fh = fopen($myFile, 'w') or die("can't open file"); $size = fwrite($fh, $Content); fclose($fh); return $size; } function get_gitIgnoreFile() { if (!$this->exists_gitIgnoreFile()) { $this->Errors[] = '.gitignore file does not exist.'; return false; } $this->file_gitignore = file_get_contents($this->ignoreFileName); return true; } function exists_gitIgnoreFile() { return file_exists( $this->ignoreFileName); } function exists_gitmysiteConfig() { return file_exists('.git/gitmysite.config'); } function update_gitIgnoreFile($file_content) { $this->CreateFile($this->ignoreFileName, $file_content); return true; } /* I'm sure there is a better way to do this, just can see it now. */ function ensure_finalslash($path) { if (strrpos($path, "/") == (strlen($path) -1)) { return $path; } else { return $path . '/'; } } function gitDirectorySecured() { return file_exists('.git/.htaccess'); } function ToDo() { $Issues[] = ""; return $Issues; } function Version() { return '0.4.8'; } function GitRepoExists() { return file_exists('.git'); } function GitRepoRoot() { $ScriptFile = $_SERVER['PHP_SELF']; $info = pathinfo($ScriptFile); return $_SERVER['SERVER_NAME'] . $info['dirname']; } function InSetupMode(){ $Result = true; if ($this->exists_gitIgnoreFile()) { if ($this->GitRepoExists()){ $Result = false; } } return $Result; } } function CheckLogin(&$GitMySite) { global $IsLoggedIn; global $PASS; global $PasswordIsDefault; $DefaultPassword = 'password'; //dont change; $PasswordIsDefault = false; session_start(); if (@$_POST['Password'] == $PASS) { $IsLoggedIn = True; $_SESSION['pass'] = $_POST['Password']; $IsLoggedIn = True; } else if (@$_SESSION['pass'] == $PASS) { $IsLoggedIn = True; } else { $IsLoggedIn = false; $GitMySite->Errors[] = 'Login Failed'; } //for security check whether password has been updated. if ($DefaultPassword == $PASS) { $PasswordIsDefault = true; } } ?> Git my Site

Git My Site Version() .': ' ; echo $mySite->GitRepoRoot(); ?>

Errors as $Error) { echo "

$Error

"; } ?>

Please change Default Password: '$PASS' in gitmysite.php script

" ; } ?>
GitRepoExists()){ ?>

Create a New Repository in this Directory

Create git Repository -

gitDirectorySecured()) { ?>

Directory Security

Your .git directory is secured with basic Auth. If you need to update the password, please delete the .htaccess and .htpasswd files from the .git directory first.

Secure the Directory

Provide a username and password to secure your .git directory. You can also use this username and password when you clone your repo to your local machine. Note: Clicking Submit will not overwrite any existing .htaccess and .htpasswd file you have in the .git folder. Please delete first or edit manually
Username:
Password:
exists_gitmysiteConfig()){?>

Set User Config Details

User Details:

Username:

Email:

Create and Edit Git Ignore File

file_gitignore > '') { ?>

exists_gitIgnoreFile()) {?>

Create .gitignore

A .gitignore file exists. Please click below to edit it.

Edit .gitignore

Add New Files if Any (Preview)

Command Results

gitOutput as $line) { echo "
$line "; } } ?>
Add Modified Files and Commit

Commit Comment

- Status - Log -

Command Results

gitOutput as $line) { echo "
$line "; } } ?>