Browse Source

Removed unused Gitolite files, Added git key update to update profile script.

tags/v1.1
Teknikode 5 years ago
parent
commit
cd14879ba9

+ 0
- 203
includes/Gitolite/Acl.php View File

@@ -1,203 +0,0 @@
<?php

namespace Gitolite;

/**
* Gitolite ACL Class
*
* Project: gitolite-php
* File: src/Gitolite/Acl.php
*
* Copyright (C) 2012 Rafael Goulart
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* @author Rafael Goulart <rafaelgou@gmail.com>
* @license GNU Lesser General Public License
* @link https://github.com/rafaelgou/gitolite-php
* see CHANGELOG
*/
class Acl
{
private $allowedPermissions = array(
'R', 'RW', 'RW+', '-', 'RWC', 'RW+C', 'RWD', 'RW+D', 'RWCD', 'RW+CD', 'RWDC', 'RW+DC',
);
protected $permission = null;
protected $refexes = '';
protected $users = array();
protected $teams = array();

/**
* Set Permission
*
* Valids: R, RW, RW+, -, RWC, RW+C, RWD, RW+D, RWCD, RW+CD, RWDC, RW+DC
*
* @param string $permission A permission
*
* @return Gitolite\Acl
*/
public function setPermission($permission)
{
$permission = (string) $permission;
if (!in_array($permission, $this->allowedPermissions)) {
throw new \Exception("Unknow permission '{$permission}'");
}
$this->permission = $permission;
return $this;
}

/**
* Get Permission
*
* @return string
*/
public function getPermission()
{
return $this->permission;
}

/**
* Set Refexes
*
* @param string $refexes A refex
*
* @return Gitolite\Acl
*/
public function setRefexes($refexes)
{
$this->refexes = $refexes;
return $this;
}

/**
* Get Refexes
*
* @return string
*/
public function getRefexes()
{
return $this->refexes;
}


/**
* Set Users
*
* @param array $users An array of user objects
*
* @return Gitolite\Acl
*/
public function setUsers(array $users)
{
$this->users = array();
foreach ($users as $user) {
$this->addUser($user);
}
return $this;
}

/**
* Get Users
*
* @return array of Users
*/
public function getUsers()
{
return $this->users;
}

/**
* Add user
*
* @param User $user A user object
*
* @return Gitolite\Acl
*/
public function addUser(User $user)
{
$this->users[] = $user;
return $this;
}

/**
* Set Teams
*
* @param array $teams An array of team objects
*
* @return Gitolite\Acl
*/
public function setTeams(array $teams)
{
$this->teams = array();
foreach ($teams as $team) {
$this->addTeam($team);
}
return $this;
}

/**
* Get Teams
*
* @return array of Teams
*/
public function getTeams()
{
return $this->teams;
}

/**
* Add Team
*
* @param Team $team A team object
*
* @return Gitolite\Acl
*/
public function addTeam(Team $team)
{
$this->teams[] = $team;
return $this;
}

/**
* Returns acl line
*
* Format: <permission> <zero or more refexes> = <one or more users/user teams>
*
* @param string $nl Include a new line (default true)
*
* @return string
*/
public function render($nl=true)
{
if (null === $this->permission) {
throw new \Exception("Permission not defined");
}

if (count($this->teams) == 0 && count($this->users) == 0) {
throw new \Exception("No users neither teams defined");
}

$teams = array();
foreach ($this->getTeams() as $team) {
$teams[] = $team->getFormatedName();
}

$users = array();
foreach ($this->getUsers() as $user) {
$users[] = $user->getUsername();
}

$refexes = ( ! empty($this->refexes)) ? $this->refexes . ' ' : '';

return $this->permission . ' '
. $refexes
. '= '
. implode(' ', $users) . ' '
. implode(' ', $teams)
. ($nl ? PHP_EOL : '');
}

}

+ 0
- 726
includes/Gitolite/Gitolite.php View File

@@ -1,726 +0,0 @@
<?php

namespace Gitolite;

/**
* Gitolite Class
*
* Project: gitolite-php
* File: src/Gitolite/Gitolite.php
*
* Copyright (C) 2012 Rafael Goulart
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* @author Rafael Goulart <rafaelgou@gmail.com>
* @license GNU Lesser General Public License
* @link https://github.com/rafaelgou/gitolite-php
* see CHANGELOG
*/
class Gitolite
{
protected $gitRemoteRepositoryURL = null;
protected $gitLocalRepositoryPath = null;
protected $gitEmail = null;
protected $gitUsername = null;
protected $gitServerName = null;
/**
* @var PHPGit_Repository
*/
protected $gitoliteRepository = null;

protected $users = array();
protected $teams = array();
protected $repos = array();

protected $log = array();

const GITOLITE_CONF_FILE = 'gitolite.conf';
const GITOLITE_CONF_DIR = 'conf/';
const GITOLITE_KEY_DIR = 'keydir/';
const GITOLITE_REPO_DIR = 'conf/repos/';

/**
* Set GitRemoteRepositoryURL
*
* @param string $gitRemoteRepositoryURL The remote repository URL
*
* @return Gitolite\Gitolite
*/
public function setGitRemoteRepositoryURL($gitRemoteRepositoryURL)
{
$this->gitRemoteRepositoryURL = (string) $gitRemoteRepositoryURL;
return $this;
}

/**
* Get GitRemoteRepositoryURL
*
* @return string
*/
public function getGitRemoteRepositoryURL()
{
return $this->gitRemoteRepositoryURL;
}

/**
* Set GitLocalRepositoryPath
*
* @param string $gitLocalRepositoryPath The git local repository Path
*
* @return Gitolite\Gitolite
*/
public function setGitLocalRepositoryPath($gitLocalRepositoryPath)
{
$this->gitLocalRepositoryPath = (string) $gitLocalRepositoryPath;
return $this;
}

/**
* Get GitLocalRepositoryPath
*
* @return string
*/
public function getGitLocalRepositoryPath()
{
return $this->gitLocalRepositoryPath;
}

/**
* Set GitEmail
*
* @param string $gitEmail The git user email
*
* @return Gitolite\Gitolite
*/
public function setGitEmail($gitEmail)
{
$this->gitEmail = (string) $gitEmail;
return $this;
}

/**
* Get GitEmail
*
* @return string
*/
public function getGitEmail()
{
return $this->gitEmail;
}

/**
* Set GitUsername
*
* @param string $gitUsername The git user name
*
* @return Gitolite\User
*/
public function setGitUsername($gitUsername)
{
$this->gitUsername = (string) $gitUsername;
return $this;
}

/**
* Get GitUsername
*
* @return string
*/
public function getGitUsername()
{
return $this->gitUsername;
}
/**
* Set GitServername
*
* @param string $gitServername The git server name
*
* @return Gitolite\Gitolite
*/
public function setGitServerName($gitServerName)
{
$this->gitServerName = (string) $gitServerName;
return $this;
}

/**
* Get GitServername
*
* @return string
*/
public function getGitServerName()
{
return $this->gitServerName;
}

/**
* Set Repos
*
* @param array $repos An array of repositories
*
* @return Gitolite\Acl
*/
public function setRepos(array $repos)
{
$this->$repos = $repos;
return $this;
}

/**
* Get Repos
*
* @return array of Repos
*/
public function getRepos()
{
return $this->repos;
}
/**
* Get Repo
*
* @param string repo name
*
* @return mixed object of Repo or false
*/
public function getRepo($name)
{
return (isset($this->repos[$name])) ? $this->repos[$name] : false;
}
/**
* Add repo
*
* @param string $repo A repository object
*
* @return Gitolite\Acl
*/
public function addRepo(Repo $repo)
{
$name = $repo->getName();
$this->repos[$name] = $repo;
return $this;
}
/**
* Delete repo
*
* @param string repo name
*
*/
public function delRepo($name)
{
unset($this->repos[$name]);
}

/**
* Set Users
*
* @param array $users An array of user objects
*
* @return Gitolite\Acl
*/
public function setUsers(array $users)
{
$this->users = array();
foreach ($users as $user) {
$this->addUser($user);
}
return $this;
}

/**
* Get Users
*
* @return array of Users
*/
public function getUsers()
{
return $this->users;
}
/**
* Get User
*
* @param string username
*
* @return mixed object of User or false
*/
public function getUser($username)
{
return (isset($this->users[$username])) ? $this->users[$username] : false;
}

/**
* Add user
*
* @param string $user A user object
*
* @return Gitolite\Acl
*/
public function addUser(User $user)
{
$username = $user->getUsername();
$this->users[$username] = $user;
return $this;
}

/**
* Set Teams
*
* @param array $teams An array of team objects
*
* @return Gitolite\Acl
*/
public function setTeams(array $teams)
{
$this->teams = array();
foreach ($teams as $team) {
$this->addTeam($team);
}
return $this;
}

/**
* Get Teams
*
* @return array of Teams
*/
public function getTeams()
{
return $this->teams;
}

/**
* Get Team
*
* @param string team name
*
* @return mixed object of Team or false
*/
public function getTeam($name)
{
return (isset($this->teams[$name])) ? $this->teams[$name] : false;
}

/**
* Add Team
*
* @param string $team A team object
*
* @return Gitolite\Acl
*/
public function addTeam(Team $team)
{
$name = $team->getName();
$this->teams[$name] = $team;
return $this;
}
/**
* Import gitolite.conf
*
*/
public function import()
{
$file = file($this->getGitLocalRepositoryPath() . DIRECTORY_SEPARATOR . self::GITOLITE_CONF_DIR . DIRECTORY_SEPARATOR . self::GITOLITE_CONF_FILE);
foreach($file as $line)
{
$line = trim($line);
if($line == '') continue;
if(preg_match('/^[@]/', $line))
{
$line_split = preg_split("/[=]+/", $line, 2);
if(count($line_split) != 2) throw new \Exception('Invalid team def.');
$team_name = substr(trim($line_split[0]), 1);
$team = new Team();
$team->setName($team_name);
$usr = preg_split("/[\s\t]+/", trim($line_split[1]));
foreach($usr as $u)
{
// is team
if(substr($u, 0, 1) == '@')
{
$u = substr($u, 1);
if( ! isset($this->teams[$u])) throw new \Exception('Undef team.');
$team->addTeam($this->teams[$u]);
}
// is user
else
{
if(isset($this->users[$u]))
{
$team->addUser($this->users[$u]);
}
else
{
$user = new User();
$user->setUsername($u);
$key = $this->getGitLocalRepositoryPath() . DIRECTORY_SEPARATOR . self::GITOLITE_KEY_DIR . DIRECTORY_SEPARATOR . $user->renderKeyFileName();
if(file_exists($key)) $user->addKey(file_get_contents($key));
$this->users[$u] = $user;
$team->addUser($user);
}
}
}
$this->teams[$team_name] = $team;
}
elseif(preg_match('/^repo/', $line))
{
$line_split = preg_split("/[\s\t]+/", $line, 2);
if(count($line_split) != 2) throw new \Exception('Invalid repository def.');
$repo = new Repo();
$repo->setName(trim($line_split[1]));
}
elseif(preg_match('/^(R|RW|RW\+|\-|RWC|RW\+C|RWD|RW\+D|RWCD|RW\+CD|RWDC|RW\+DC)/', $line))
{
$teams = array();
$users = array();
$line_split = preg_split("/[=]+/", $line, 2);
if(count($line_split) != 2) throw new \FuelException('Invalid rule.');
$acl_split = preg_split("/[\s\t]+/", trim($line_split[0]), 2);
$refexes = (isset($acl_split[1])) ? $acl_split[1] : false;
$acl = new Acl();
$acl->setPermission($acl_split[0]);
if($refexes) $acl->setRefexes($refexes);
$usr = preg_split("/[\s\t]+/", trim($line_split[1]));
foreach($usr as $u)
{
// is team
if(substr($u, 0, 1) == '@')
{
$u = substr($u, 1);
if( ! isset($this->teams[$u])) throw new \Exception('Undef. team');
$acl->addTeam($this->teams[$u]);
}
// is user
else
{
if( ! isset($this->users[$u]))
{
$this->users[$u] = new User();
$this->users[$u]->setUsername($u);
$key = $this->getGitLocalRepositoryPath() . DIRECTORY_SEPARATOR . self::GITOLITE_KEY_DIR . DIRECTORY_SEPARATOR . $this->users[$u]->renderKeyFileName();
if(file_exists($key)) $this->users[$u]->addKey(file_get_contents($key));
}
$acl->addUser($this->users[$u]);
}
}
$repo->addAcl($acl);
$this->repos[$repo->getName()] = $repo;
}
}
}

/**
* Get PHPGit_Repository
*
* @return PHPGit_Repository
*/
protected function getGitoliteRepository()
{
if (null === $this->gitoliteRepository) {
if (null === $this->getGitLocalRepositoryPath()) {
throw new \Exception('Git local repository path not defined');
}
try {
$this->gitoliteRepository = new \PHPGit_Repository($this->getGitLocalRepositoryPath());
} catch (\Exception $exc) {

if (file_exists($this->getGitLocalRepositoryPath())) {
throw new \Exception("Directory {$this->getGitLocalRepositoryPath()} already exists, impossible to create repository");
} else {
if (mkdir($this->getGitLocalRepositoryPath(), 0770)) {
$this->gitoliteRepository = \PHPGit_Repository::create($this->getGitLocalRepositoryPath());
} else {
throw new \Exception('Impossible to create Directory informed in Git local repository (possibly).');
}
}
}
}
return $this->gitoliteRepository;
}

/**
* Write a File down to disk
*
* @param string $filename The file to be write to disk
* @param string $data The content to be write
* @param boolean $checkChange Wheter check or not if data is changed
*
* @return string
*/
protected function writeFile($filename, $data, $checkChange=true)
{
if (!file_exists($filename)) {
if (!file_put_contents($filename, $data)) {
throw new \Exception("Impossible to write file {$filename}", 1);
}
} else {
if (!$checkChange) {
if (!file_put_contents($filename, $data)) {
throw new \Exception("Impossible to write file {$filename}", 1);
}
} else {
if ($data != file_get_contents($filename)) {
file_put_contents($filename, $data);
}
return true;
}
}
}

/**
* Push configuration to Gitolite Server
*
* @return void
*/
public function pushConfig()
{
$cmds[] = 'push gitoliteorigin master';
$this->runGitCommand($cmds);
}

/**
* Commits changes in configuration
*
* @return void
*/
public function commitConfig()
{
$status = $this->runGitCommand('status');
if( ! preg_match('/nothing to commit/', $status))
{
$cmds[] = 'add .';
// check for deleted keys
preg_match_all('/deleted:[\s]+(.+)/', $status, $matches);
if(isset($matches[1]) && is_array($matches[1]))
{
foreach($matches[1] as $v)
{
$cmds[] = 'rm '.$v;
}
}
$cmds[] = 'commit -m "Update configuration from ' .
$this->getGitServerName() . ' on ' .date('Y-m-d H:i:s') . '"';
$this->runGitCommand($cmds);
return true;
}
return false;
}

/**
* Write full conf file to disk
*
* @return void
*/
public function writeFullConfFile()
{
return $this->writeFile(
$this->getGitLocalRepositoryPath() . DIRECTORY_SEPARATOR .
self::GITOLITE_CONF_DIR . self::GITOLITE_CONF_FILE,
$this->renderFullConfFile()
);
}

/**
* Write users keys to disk
*
* @return void
*/
public function writeUsers()
{
// delete old keys
exec('rm ' . $this->getGitLocalRepositoryPath() . DIRECTORY_SEPARATOR . self::GITOLITE_KEY_DIR . '*.pub');
foreach ($this->getUsers() as $user) {
$this->writeFile(
$this->getGitLocalRepositoryPath() . DIRECTORY_SEPARATOR .
self::GITOLITE_KEY_DIR .
$user->renderKeyFileName(),
$user->getFirstKey()
);
}
}

/**
* Write everything to the disk, commit and push
*
* @return void
*/
public function writeAndPush()
{
$this->gitConfig();
$this->writeFullConfFile();
$this->writeUsers();
if($this->commitConfig()) $this->pushConfig();
}

/**
* Return full conf file
*
* @return string
*/
public function renderFullConfFile()
{
return $this->renderUserAndTeams() . $this->renderRepos();
}

/**
* Return user and teams for conf file
*
* @return string
*/
public function renderUserAndTeams()
{
$return = '';
foreach ($this->getTeams() as $team) {
$return .= $team->render();
}
return $return . PHP_EOL;
}

/**
* Return repos for conf file
*
* @return string
*/
public function renderRepos()
{
$return = '';
foreach ($this->getRepos() as $repo) {
$return .= $repo->render();
}
return $return;
}

/**
* Configure the repository
*
* @return void
*/
public function gitConfig()
{
$cmds[] = sprintf('config user.name "%s"', $this->getGitUsername());
$cmds[] = sprintf('config user.email "%s"', $this->getGitEmail());
$remotes = $this->runGitCommand('remote -v');
$gitoliteRemote = sprintf('gitoliteorigin %s', $this->getGitRemoteRepositoryURL());

if( ! preg_match('/'.preg_quote($gitoliteRemote, '/').'/', $remotes))
{
if(preg_match('/gitoliteorigin/', $remotes)) $cmds[] = 'remote rm gitoliteorigin';
$cmds[] = 'remote add '.$gitoliteRemote;
}
$cmds[] = 'pull gitoliteorigin master';
$this->runGitCommand($cmds);
}

/**
* Run git commands
*
* @param mixed $cmds A command or an array of commands
*
* @return string
*/
protected function runGitCommand($cmds='')
{
if (!is_string($cmds) && !is_array($cmds)) {
return false;
}

if (!is_array($cmds)) {
$cmds = array($cmds);
}

foreach ($cmds as $cmd) {
try {
$date = date('Y-m-d H:i:s');
$output = $this->getGitoliteRepository()->git($cmd);
$this->log("$date COMMAND RUN: git $cmd");
$this->log("$date OUTPUT : . $output");
} catch (\GitRuntimeException $e) {
$this->log_error("$date GIT ERROR: " . $e->getMessage());
} catch (\Exception $e) {
$this->log_error("$date ERROR: " . $e->getMessage());
}
}
return $output;
}

/**
* Log a message
*
* @param type $message The message to log
*
* @return void
*/
protected function log($message)
{
$this->log['info'][] = $message;
}
/**
* Log a error message
*
* @param type $message The message to log
*
* @return void
*/
protected function log_error($message)
{
$this->log['error'][] = $message;
}

/**
* Get the log
*
* @return array
*/
public function getLog()
{
return $this->log;
}

/**
* Get the log as string
*
* @param string type = info or error
* @return string
*/
public function getLogAsString($type = 'info')
{
if( ! isset($this->log[$type])) return false;
return implode(PHP_EOL, $this->log[$type]);
}

}

+ 0
- 110
includes/Gitolite/Repo.php View File

@@ -1,110 +0,0 @@
<?php

namespace Gitolite;

/**
* Gitolite Repository Class
*
* Project: gitolite-php
* File: src/Gitolite/Repo.php
*
* Copyright (C) 2012 Rafael Goulart
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* @author Rafael Goulart <rafaelgou@gmail.com>
* @license GNU Lesser General Public License
* @link https://github.com/rafaelgou/gitolite-php
* see CHANGELOG
*/
class Repo
{
protected $name = null;
protected $acls = array();

/**
* Set Name
*
* @param string $name The repository name
*
* @return Gitolite\Team
*/
public function setName($name)
{
$this->name = (string) $name;
return $this;
}

/**
* Get Name
*
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* Set Acls
*
* @param array $acls An array of acl objects
*
* @return Gitolite\Team
*/
public function setAcls(array $acls)
{
$this->$acls = $acls;
return $this;
}

/**
* Get Acls
*
* @return array of Acls
*/
public function getAcls()
{
return $this->acls;
}

/**
* Add acl
*
* @param Acl $acl An acl object
*
* @return Gitolite\Team
*/
public function addAcl(Acl $acl)
{
$this->acls[] = $acl;
return $this;
}

/**
* Returns team group line
*
* Format: @<team_name> = <user 1> <user 2> <user 3> <user 'n'>
*
* @return string
*/
public function render()
{
if (count($this->acls) == 0) {
throw new \Exception("No acls for repo {$this->getName()}");
}

$return = 'repo ' . $this->getName() . PHP_EOL;

foreach ($this->getAcls() as $acl) {
$return .= ' ' . $acl->render();
}

return $return . PHP_EOL;
}


}

+ 0
- 167
includes/Gitolite/Team.php View File

@@ -1,167 +0,0 @@
<?php

namespace Gitolite;

/**
* Gitolite Team Class
*
* Project: gitolite-php
* File: src/Gitolite/Team.php
*
* Copyright (C) 2012 Rafael Goulart
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* @author Rafael Goulart <rafaelgou@gmail.com>
* @license GNU Lesser General Public License
* @link https://github.com/rafaelgou/gitolite-php
* see CHANGELOG
*/
class Team
{
protected $name = null;
protected $users = array();
protected $teams = array();

/**
* Set Name
*
* @param string $name The team name
*
* @return Gitolite\Team
*/
public function setName($name)
{
$this->name = (string) $name;
return $this;
}

/**
* Get Name
*
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* Get Formated Name (as @team)
*
* @return string
*/
public function getFormatedName()
{
return '@' . $this->name;
}

/**
* Set Users
*
* @param array $users An array of user objects
*
* @return Gitolite\Team
*/
public function setUsers(array $users)
{
$this->users = array();
foreach ($users as $user) {
$this->addUser($user);
}
return $this;
}

/**
* Get Users
*
* @return array of Users
*/
public function getUsers()
{
return $this->users;
}

/**
* Add user
*
* @param User $user An user object
*
* @return Gitolite\Team
*/
public function addUser(User $user)
{
$this->users[] = $user;
return $this;
}

/**
* Set Teams
*
* @param array $teams An array of team objects
*
* @return Gitolite\Acl
*/
public function setTeams(array $teams)
{
$this->teams = array();
foreach ($teams as $team) {
$this->addTeam($team);
}
return $this;
}

/**
* Get Teams
*
* @return array of Teams
*/
public function getTeams()
{
return $this->teams;
}

/**
* Add Team
*
* @param Team $team A team object
*
* @return Gitolite\Acl
*/
public function addTeam(Team $team)
{
$this->teams[] = $team;
return $this;
}

/**
* Returns team group line
*
* Format: @<team_name> = <user 1> <user 2> <user 3> <user 'n'>
*
* @param string $nl Include a new line (default true)
*
* @return string
*/
public function render($nl=true)
{
$users = array();
foreach ($this->getUsers() as $user) {
$users[] = $user->getUsername();
}

$teams = array();
foreach ($this->getTeams() as $team) {
$teams[] = $team->getFormatedName();
}

return $this->getFormatedName() . ' = '
. implode(' ', $users) . ' '
. implode(' ', $teams)
. ($nl ? PHP_EOL : '');
}

}

+ 0
- 133
includes/Gitolite/User.php View File

@@ -1,133 +0,0 @@
<?php

namespace Gitolite;

/**
* Gitolite User Class
*
* Project: gitolite-php
* File: src/Gitolite/User.php
*
* Copyright (C) 2012 Rafael Goulart
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* @author Rafael Goulart <rafaelgou@gmail.com>
* @license GNU Lesser General Public License
* @link https://github.com/rafaelgou/gitolite-php
* see CHANGELOG
*/
class User
{
protected $username = null;
protected $email = null;
protected $keys = array();

/**
* Set Username
*
* @param string $username The user name
*
* @return Gitolite\User
*/
public function setUsername($username)
{
$this->username = (string) $username;
return $this;
}

/**
* Get Username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}

/**
* Set Keys
*
* @param array $keys An array of keys
*
* @return Gitolite\User
*/
public function setKeys(array $keys)
{
$this->keys = array();
foreach ($keys as $key) {
$this->addKey($key);
}
return $this;
}

/**
* Get Keys
*
* @return string
*/
public function getKeys()
{
return $this->keys;
}

/**
* Get First Key
*
* @return string
*/
public function getFirstKey()
{
return (string) $this->keys[0];
}

/**
* Add key
*
* @param string $key A key
*
* @return Gitolite\User
*/
public function addKey($key)
{
$this->keys[] = (string) $key;
return $this;
}

/**
* Set Email
*
* @param string $email An email
*
* @return Gitolite\User
*/
public function setEmail($email)
{
$this->email = (string) $email;
return $this;
}

/**
* Get Email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}

/**
* Returns key filename in form username.pub
*
* @return string
*/
public function renderKeyFileName()
{
return $this->username . '.pub';
}
}

+ 0
- 80
includes/GitoliteAutoload.php View File

@@ -1,80 +0,0 @@
<?php
/**
* Gitolite Autoload Class
*
* Project: gitolite-php
* File: src/GitoliteAutoload.php
*
* Copyright (C) 2012 Rafael Goulart
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* @author Rafael Goulart <rafaelgou@gmail.com>
* @license GNU Lesser General Public License
* @link https://github.com/rafaelgou/gitolite-php
* see CHANGELOG
*/
class GitoliteAutoload
{

/**
* The init path for autoload
* @var string
*/
static public $initPath;

/**
* Flag to check if is already intialized
* @var boolean
*/
static public $initialized = false;

/**
* Constructor
*
* set private to avoid directly instatiation to implement
* but is not a Singleton Design Pattern
**/
private function __construct()
{
}

/**
* Configure autoloading using Gitolite.
*
* This is designed to play nicely with other autoloaders.
*
* @param string $initPath The init script to load when autoloading the first Gitolite class
*
* @return void
*/
public static function registerAutoload($initPath = null)
{
self::$initPath = $initPath;
spl_autoload_register(array('GitoliteAutoload', 'autoload'));
}

/**
* Internal autoloader for spl_autoload_register().
*
* @param string $class The class to load
*
* @return void
*/
public static function autoload($class)
{
$path = dirname(__FILE__).'/'.str_replace('\\', '/', $class).'.php';
if (!file_exists($path)) {
return;
}
if (self::$initPath && !self::$initialized) {
self::$initialized = true;
require self::$initPath;
}
require_once $path;
}

}

+ 54
- 9
includes/update_profile.php View File

@@ -1,5 +1,6 @@
<?php
require_once('config.php');
require_once('Git.php');
//initialize php variables used in the form
$current_password = "";
@@ -24,7 +25,6 @@ if(isset($_POST))
array(
'website' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW),
'quote' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW),
'public_key' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW),
'about' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => !FILTER_FLAG_STRIP_LOW),
'blog_title' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW),
'blog_desc' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => !FILTER_FLAG_STRIP_LOW)
@@ -37,7 +37,7 @@ if(isset($_POST))
$password = rawurldecode($_POST['password']);
$password_confirm = rawurldecode($_POST['password_confirm']);
$theme = rawurldecode($_POST['theme']);
$public_key = rawurldecode($revised_post_array['public_key']);
$public_key = rawurldecode($_POST['public_key']);
//$minecraft = rawurldecode($revised_post_array['minecraft']);
$website = rawurldecode($revised_post_array['website']);
$quote = rawurldecode($revised_post_array['quote']);
@@ -108,11 +108,16 @@ if(isset($_POST))
$success = false;
}
$pattern = "/^(ssh-rsa)\s([0-9A-Za-z\/\+]+)([=]*)((\s.*)|())$/";
if($success && $public_key && !preg_match($pattern, $public_key))
$keys = explode(",", $public_key);
foreach ($keys as $key)
{
$error = "Invalid Public Key.<br />Please make sure it follows this format.<br /><b>ssh-rsa [0-9A-Za-z/+ ]</b>";
$success = false;
$pattern = "/^(ssh-rsa)\s([0-9A-Za-z\/\+]+)([=]*)((\s.*)|())$/";
if($success && $key && !preg_match($pattern, $key))
{
$error = "Invalid Public Key.<br />Please make sure it follows this format.<br /><b>ssh-rsa [0-9A-Za-z/+ ]</b>";
$success = false;
break;
}
}
if($success)
@@ -123,10 +128,50 @@ if(isset($_POST))
$user->hashedPassword = hashPassword($password, $CONF); //encrypt the password for storage
}
// Add the user's keys to his git account
if ($public_key != $user->public_key)
{
preg_match($pattern, $public_key, $matches);
$public_key = "ssh-rsa " . $matches[2];
{
if (is_dir('../cache/gitolite-admin'))
{
unlink('../cache/gitolite-admin');
}
$Git = new Git();
$Git->windows_mode();
$repo = $Git->clone_remote('../cache/gitolite-admin', 'git@localhost:gitolite-admin');
if (is_dir("../cache/gitolite-admin/keydir/u/".$user->username))
{
$files = glob("../cache/gitolite-admin/keydir/u/".$user->username."/*");
foreach($files as $file){ // iterate files
if(is_file($file))
unlink($file); // delete file
}
}
else
{
mkdir("../cache/gitolite-admin/keydir/u/".$user->username, 0777, true);
}
$index = 0;
$keys = explode(",", $public_key);
foreach ($keys as $key)
{
preg_match($pattern, $key, $matches);
$key = "ssh-rsa " . $matches[2];
$keyFileName = "../cache/gitolite-admin/keydir/u/".$user->username."/".$user->username."@Key".$index.".pub";
$fileHandle = fopen($keyFileName, 'w');
fwrite($fileHandle, $key);
fclose($fileHandle);
$index++;
}
$repo->add('.');
$repo->commit('Modified keys for '.$user->username);
$repo->push('origin', 'master');
if (is_dir('../cache/gitolite-admin'))
{
unlink('../cache/gitolite-admin');
}
}
/*
if ($minecraft != $user->minecraft_user)

+ 1
- 1
templates/default/js/profile.js View File

@@ -56,7 +56,7 @@ $(document).ready(function() {
}
else
{
bootbox.alert("The key '"+result+"' is already added.", function() { });
bootbox.alert("That key is already in the list.", function() { });
}
}
});

Loading…
Cancel
Save