Created
October 5, 2010 17:46
-
-
Save siddhant3s/611987 to your computer and use it in GitHub Desktop.
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
<?php | |
define('ACCEPT_IP','127.0.0.1'); | |
define('MONITORED_DIR','');//The directory where the .git directory is located. Leave blank if this script is in the same directory as the .git file | |
define('MAIL_TO','siddhant3s@gmail.com'); //mail the report to this email address. Leave blank to disable | |
define('LOG_FILE','_ghupdater.log'); //Log file. Highly recommended | |
//////////////////////////Disable the effect of magic_quotes_gpc//////////////// | |
if (get_magic_quotes_gpc()) { | |
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); | |
while (list($key, $val) = each($process)) { | |
foreach ($val as $k => $v) { | |
unset($process[$key][$k]); | |
if (is_array($v)) { | |
$process[$key][stripslashes($k)] = $v; | |
$process[] = &$process[$key][stripslashes($k)]; | |
} else { | |
$process[$key][stripslashes($k)] = stripslashes($v); | |
} | |
} | |
} | |
unset($process); | |
} | |
//////////////////////////////////////////////////////////////////////////////// | |
$rep_path=isset($_REQUEST['path'])?$_REQUEST['path']:'../linkpit' or die('No Path specified for Repo');//rep path. | |
$templog=''; | |
function logmsg($msg) | |
{ global $templog; | |
echo ($msg.'<br>'); | |
$templog.="$msg<br>\n"; | |
return; | |
} | |
//echo $_POST['payload'];$comit_obj->{'id'} | |
if(!isset($_POST['payload'])){ | |
echo "Data not recieved in POST['payload']. Repo Path is set to $rep_path"; | |
exit(); | |
} | |
echo 'REP_PATH:'.$rep_path; | |
$obj=json_decode($_POST['payload']); | |
if(!$obj) die("Unable to parse the payload"); | |
//var_dump($obj); | |
$commitlist=$obj->{'commits'}; | |
/*print_r($commitlist[1]->{'added'}); echo '<br/>'; | |
print_r($commitlist[1]->{'modified'});echo '<br/>'; | |
print_r($commitlist[1]->{'removed'});echo '<br/>'; | |
print_r($commitlist[1]->{'id'});echo '<br/>';*/ | |
//this is where all the files of a GitHub reposotories can be viewed. the format is {REPO_URL}/raw/commit-id/filename | |
//$gh_raw_url.'commit-id/'.filename gives the file | |
$gh_raw_url=$obj->{'repository'}->{'url'}.'/raw/'; | |
//print $gh_url; | |
foreach($commitlist as $commit_obj) | |
{ | |
$id=$commit_obj->{'id'}; | |
$message=$commit_obj->{'message'}; | |
$commit_raw_url=$gh_raw_url.$id.'/'; | |
logmsg("Processing commit: $id || Message:$message"); | |
$files_to_download=array_merge($commit_obj->{'added'},$commit_obj->{'modified'}); | |
$files_to_remove=$commit_obj->{'removed'}; | |
if($files_to_download) | |
{ | |
logmsg('The following files needs to be downloaded'); | |
foreach($files_to_download as $f) {logmsg($f);} | |
foreach($files_to_download as $f) | |
{ | |
logmsg("Now Downloading file $f"); | |
$local_file=$rep_path.'/'.$f; | |
$dir=dirname($local_file); | |
if (!is_dir($dir)) | |
mkdir($dir,0777,true) or logmsg("Cannot make directory".$dir) or exit(); | |
//TODO Uncomment the following line | |
copy($commit_raw_url.$f,$local_file) or logmsg("Unable to run copy command") or exit(); | |
logmsg("Download complete for file $f"); | |
} | |
} | |
if($files_to_remove) | |
{ | |
logmsg('The following files needs to be removed'); | |
foreach($files_to_remove as $f) {logmsg($f);} | |
foreach($files_to_remove as $f) | |
{ | |
logmsg("Now Removing $f"); | |
$local_file=$rep_path.'/'.$f; | |
unlink($local_file) or logmsg("Cannot remove file $localfile"); | |
logmsg("File removed $f"); | |
} | |
} | |
} | |
echo('<br/><br/><br/>'); | |
if(MAIL_TO) | |
{ | |
mail(MAIL_TO,'gitupdater.php recieved a push',$templog); | |
} | |
echo($templog); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment