Files
ICEcoder/plugins/ice-repo/file-control.php
Matt Pass e2aefab2ae SESSION userLevel now loggedIn
Moving away from the idea of multiple user levels, users will either
have full access or no access
Swapped all userLevel session vars to a loggedIn var, which is a bool
Makes things simpler and paves the way towards the new login screen
(before you see any files, code etc)
2012-09-18 08:53:13 +01:00

144 lines
4.8 KiB
PHP

<?php
session_start();
if (!$_SESSION['loggedIn']) {
die("Sorry, you need to be logged in to use ICErepo");
}
// returns converted entities where there are HTML entity equivalents
function strClean($var) {
return htmlentities($var, ENT_QUOTES, "UTF-8");
}
// returns a number, whole or decimal or null
function numClean($var) {
return is_numeric($var) ? floatval($var) : false;
}
$repoPath = strClean($_POST['repoPath']);
$gitRepo = strClean($_POST['gitRepo']);
$path = strClean($_POST['path']);
$rowID = strClean($_POST['rowID']);
$repo = strClean($_POST['repo']);
$dir = strClean($_POST['dir']);
$action = str_replace("PULL:","",str_replace("SAVEPULLS:","",strClean($_POST['action'])));
$rowIDArray = explode(",",$rowID);
$repoArray = explode(",",$repo);
$dirArray = explode(",",$dir);
$actionArray = explode(",",$action);
?>
<!DOCTYPE html>
<html>
<head>
<title>ICErepo v<?php echo $version;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="lib/underscore-min.js"></script>
<script src="lib/base64.js"></script>
<script src="lib/github.js"></script>
<script src="lib/difflib.js"></script>
<script src="ice-repo.js"></script>
<link rel="stylesheet" type="text/css" href="ice-repo.css">
</head>
<body>
<script>
fullRepoPath='<?php echo $repo;?>';
gitRepo='<?php echo $gitRepo;?>';
var github = new Github(<?php
if ($_POST['token']!="") {
echo '{token: "'.strClean($_POST['token']).'", auth: "oauth"}';
} else{
echo '{username: "'.strClean($_POST['username']).'", password: "'.strClean($_POST['password']).'", auth: "basic"}';
}?>);
repoUser = gitRepo.split('/')[0];
repoName = gitRepo.split('/')[1];
filePath = fullRepoPath.replace(repoUser+"/"+repoName+"/","");
var repo = github.getRepo(repoUser,repoName);
</script>
<?php if ($_POST['action']=="view") {?>
<form name="fcForm">
<textarea name="fileContents"><?php echo htmlentities(file_get_contents($dir)); ?></textarea>
</form>
<script>
rowID = <?php echo $rowID; ?>;
baseTextName = "Server: <?php echo str_replace($_SERVER['DOCUMENT_ROOT']."/","",$dir);?> ";
newTextName = "Github: <?php echo $repo;?>";
window.onLoad = sendData(baseTextName,newTextName);
</script>
<?php } else if (substr($_POST['action'],0,5)=="PULL:") { ?>
<form name="fcForm" action="file-control.php" method="POST">
<?php
echo '<input type="hidden" name="rowID" value="'.$rowID.'">';
echo '<input type="hidden" name="repo" value="'.$repo.'">';
echo '<input type="hidden" name="dir" value="'.$dir.'">';
echo '<input type="hidden" name="action" value="SAVEPULLS:'.$action.'">';
echo '<input type="hidden" name="path" value="'.$path.'">';
for ($i=0;$i<count($rowIDArray);$i++) {
if ($repoArray[$i]!="") {
echo '<textarea name="repoContents'.$rowIDArray[$i].'"></textarea>';
}
}
?>
</form>
<script>
rowIDArray = [<?php echo implode(",", $rowIDArray);?>];
repoArray = [<?php echo "'".implode("','", $repoArray)."'";?>];
dirArray = [<?php echo "'".implode("','", $dirArray)."'";?>];
actionArray = [<?php echo "'".implode("','", $actionArray)."'";?>];
window.onLoad = getData();
</script>
<?php } else if (substr($_POST['action'],0,10)=="SAVEPULLS:") {?>
<script>
<?php
for ($i=0;$i<count($rowIDArray);$i++) {
if ($actionArray[$i]!="new") {
$dirs = explode("/",$repoArray[$i]);
$relDir = "";
for ($j=0;$j<count($dirs)-1;$j++) {
$relDir .= "/".$dirs[$j];
if (!is_dir($path.$relDir)) {
mkdir($path.$relDir, 0755);
}
}
$fh = fopen($path."/".$repoArray[$i], 'w') or die("alert('Sorry, there was a problem pulling ".$repoArray[$i].". Either the file is unavailable on Github or server permissions aren\'t allowing it to be created/updated.');get('blackMask','top').style.display='none';");
fwrite($fh, $_POST['repoContents'.$rowIDArray[$i]]);
fclose($fh);
echo "hideRow(".$rowIDArray[$i].");top.newCount--;";
} else {
is_dir($dir) ? $success = rmdir($dir) : $success = unlink($dir);
if (!$success) {
echo "alert('Sorry, couldn\'t delete ".$dir."\\n\\n";
echo "Maybe you need to give file permissions for it to be deleted?');";
} else {
echo "hideRow(".$rowIDArray[$i].");top.deletedCount--;";
}
}
}
echo "get('blackMask','top').style.display = 'none';";
?>
</script>
<?php } else { ?>
<form name="fcForm">
<?php
for ($i=0;$i<count($rowIDArray);$i++) {
if ($dirArray[$i]!="") {
echo '<textarea name="fileContents'.$rowIDArray[$i].'">';
echo htmlentities(file_get_contents($dirArray[$i]));
echo '</textarea>';
}
}
?>
</form>
<script>
rowIDArray = [<?php echo implode(",", $rowIDArray);?>];
repoArray = [<?php echo "'".implode("','", $repoArray)."'";?>];
dirArray = [<?php echo "'".implode("','", $dirArray)."'";?>];
actionArray = [<?php echo "'".implode("','", $actionArray)."'";?>];
window.onLoad = startProcess();
</script>
<?php } ?>
</body>
</html>