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)
This commit is contained in:
Matt Pass
2012-09-18 08:53:13 +01:00
parent 4027ecee5a
commit e2aefab2ae
12 changed files with 34 additions and 34 deletions

View File

@@ -35,7 +35,7 @@ span.CodeMirror-matchhighlight {background: #555}
<body onLoad="top.ICEcoder.updateFileFolderCount()" style="color: #fff; margin: 0" onKeyDown="return top.ICEcoder.interceptKeys('content', event);" onKeyUp="top.ICEcoder.resetKeys(event);">
<div style="margin: 32px 43px; font-family: arial; font-size: 10px; color: #ddd">
<?php if($_SESSION['userLevel'] == 10) {
<?php if($_SESSION['loggedIn']) {
echo '<div style="float: left; margin-right: 50px">'.PHP_EOL;
echo '<h2 style="color: rgba(0,198,255,0.7)">server</h2>'.PHP_EOL;
echo '<span style="color:#888">Server name, OS & IP:</span><br>'.PHP_EOL;

View File

@@ -121,7 +121,7 @@ for ($i=0;$i<count($finalArray);$i++) {
$fileAtts = '<span style="color: #888; font-size: 8px" id="'.str_replace($docRoot,"",str_replace("/","|",$fileFolderName)).'_perms">'.$chmodInfo.'</span>';
}
$type == "folder" ? $class = 'pft-directory' : $class = 'pft-file '.strtolower($ext);
if ($_SESSION['userLevel'] == 10 || ($_SESSION['userLevel'] < 10 && !$restrictedFile)) {
if ($_SESSION['loggedIn'] || (!$_SESSION['loggedIn'] && !$restrictedFile)) {
echo "<li class=\"".$class."\"><a nohref title=\"$fileFolderName\" onMouseOver=\"top.ICEcoder.overFileFolder('$type','".str_replace($docRoot,"",str_replace("/","|",$fileFolderName))."')\" onMouseOut=\"top.ICEcoder.overFileFolder('$type','')\" style=\"position: relative; left:-22px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span id=\"".str_replace($docRoot,"",str_replace("/","|",$fileFolderName))."\">".basename($fileFolderName)."</span> ".$fileAtts."</a>\n";
} else {
echo "<li class=\"".$class."\" style=\"cursor: default\"><span style=\"position: relative; left:-22px; color: #888\" onClick=\"top.ICEcoder.message('Sorry, you need higher admin level rights to view.')\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [HIDDEN]</span>";

View File

@@ -43,7 +43,7 @@ window.onbeforeunload = function() {
}
previousFiles = [<?php
if ($ICEcoder["previousFiles"]!="" && $_SESSION['userLevel'] == 10) {
if ($ICEcoder["previousFiles"]!="" && $_SESSION['loggedIn']) {
$openFilesArray = explode(",",$ICEcoder["previousFiles"]);
echo "'".implode("','",$openFilesArray)."'";
}
@@ -56,7 +56,7 @@ showFileMenu = function() {
</head>
<body onLoad="ICEcoder.init(<?php
if ($_SESSION['userLevel'] == 10) {echo "'login'";};
if ($_SESSION['loggedIn']) {echo "'login'";};
echo ")".$updateMsg.$onLoadExtras;
?>" onResize="ICEcoder.setLayout()" onKeyDown="return ICEcoder.interceptKeys('coder',event);" onKeyUp="parent.ICEcoder.resetKeys(event);">

View File

@@ -31,7 +31,7 @@ if ($_GET['action']=="load") {
$bannedFile=true;
}
}
if (file_exists($file) && ($_SESSION['userLevel'] > 0 || ($_SESSION['userLevel'] == 0 && !$bannedFile))) {
if (file_exists($file) && ($_SESSION['loggedIn'] || (!$_SESSION['loggedIn'] && !$bannedFile))) {
echo '<script>fileType="text";';
echo 'top.ICEcoder.shortURL = top.ICEcoder.rightClickedFile = top.ICEcoder.thisFileFolderLink = "'.$fileLoc."/".$fileName.'";';
echo '</script>';
@@ -53,7 +53,7 @@ if ($_GET['action']=="load") {
// If we're due to add a new folder...
if ($_GET['action']=="newFolder") {
if (is_writable($docRoot.$fileLoc) && $_SESSION['userLevel'] > 0) {
if (is_writable($docRoot.$fileLoc) && $_SESSION['loggedIn']) {
mkdir($file, 0705);
// Reload file manager
echo '<script>top.ICEcoder.selectedFiles=[];top.ICEcoder.updateFileManagerList(\'add\',\''.$fileLoc.'\',\''.$fileName.'\');action="newFolder";</script>';
@@ -71,7 +71,7 @@ if ($_GET['action']=="newFolder") {
// If we're due to rename a file/folder...
if ($_GET['action']=="rename") {
if ($_SESSION['userLevel'] > 0 && is_writable($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])))) {
if ($_SESSION['loggedIn'] && is_writable($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])))) {
rename($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])),$docRoot.$fileLoc."/".$fileName);
// Reload file manager
echo '<script>top.ICEcoder.selectedFiles=[];top.ICEcoder.updateFileManagerList(\'rename\',\''.$fileLoc.'\',\''.$fileName.'\',\'\',\''.str_replace($iceRoot,"",strClean($_GET['oldFileName'])).'\');';
@@ -89,7 +89,7 @@ if ($_GET['action']=="rename") {
// If we're due to replace text in a file...
if ($_GET['action']=="replaceText") {
if ($_SESSION['userLevel'] > 0 && is_writable(str_replace("|","/",strClean($_GET['fileRef'])))) {
if ($_SESSION['loggedIn'] && is_writable(str_replace("|","/",strClean($_GET['fileRef'])))) {
$file = str_replace("|","/",strClean($_GET['fileRef']));
$loadedFile = file_get_contents($file);
$newContent = str_replace(strClean($_GET['find']),strClean($_GET['replace']),$loadedFile);
@@ -110,7 +110,7 @@ if ($_GET['action']=="replaceText") {
// If we're due to change permissions on a file/folder...
if ($_GET['action']=="perms") {
if ($_SESSION['userLevel'] > 0 && is_writable($file)) {
if ($_SESSION['loggedIn'] && is_writable($file)) {
chmod($file,octdec(numClean($_GET['perms'])));
// Reload file manager
echo '<script>top.ICEcoder.selectedFiles=[];top.ICEcoder.updateFileManagerList(\'chmod\',\''.$fileLoc.'\',\''.$fileName.'\',\''.numClean($_GET['perms']).'\');';
@@ -128,7 +128,7 @@ if ($_GET['action']=="perms") {
// If we're due to delete a file...
if ($_GET['action']=="delete") {
if ($_SESSION['userLevel'] > 0) {
if ($_SESSION['loggedIn']) {
$filesArray = split(";",$file); // May contain more than one file here
for ($i=0;$i<=count($filesArray)-1;$i++) {
if (is_writable($iceRoot.$filesArray[$i])) {
@@ -174,7 +174,7 @@ if ($_GET['action']=="save") {
echo '<script>action="save";</script>';
// on the form posting via a reload, save the file
if (isset($_POST['contents'])) {
if ($_SESSION['userLevel'] > 0) {
if ($_SESSION['loggedIn']) {
if ((file_exists($file) && is_writable($file)) || isset($_POST['newFileName']) && $_POST['newFileName']!="") {
if (filemtime($file)==$_GET['fileMDT']||!(isset($_GET['fileMDT']))) {
$fh = fopen($file, 'w') or die("Sorry, cannot save");

View File

@@ -39,7 +39,7 @@ echo number_format($outputSize, 2, '.', '').$outputUnit." (".number_format($byte
<br><br>
<span class="column" style="width: 180px">Type: <?php echo is_dir($fileName) ? "Folder" : "File"; ?></span>
<span class="column" style="margin: 0 10px">Readable / Writeable: <?php
if ($_SESSION['userLevel'] == 10) {
if ($_SESSION['loggedIn']) {
echo is_readable($fileName) ? "Yes" : "No"; ?> / <?php echo is_writeable($fileName) ? "Yes" : "No";
} else {
echo '[HIDDEN]';
@@ -49,7 +49,7 @@ if ($_SESSION['userLevel'] == 10) {
<span style="font-size:10px">
<br><br>
Absolute path:<br><?php
echo $_SESSION['userLevel'] == 10 ? $fileName : '[HIDDEN]';
echo $_SESSION['loggedIn'] ? $fileName : '[HIDDEN]';
?>
<br><br>
</span>
@@ -145,7 +145,7 @@ var validatePerms = function() {
canUpdate = false;
}
<?php
if ($_SESSION['userLevel'] == 10) {
if ($_SESSION['loggedIn']) {
?>
if (canUpdate) {top.ICEcoder.chmod('<?php echo str_replace($docRoot,"",$fileName);?>',permText)};
<?php

View File

@@ -103,7 +103,7 @@ if (startTab!=top.ICEcoder.selectedTab) {
} else if(stristr(file_get_contents($fullPath), $q)) {
$rFile = false;
$bFile = false;
if ($_SESSION['userLevel']==0) {
if (!$_SESSION['loggedIn']) {
for ($i=0;$i<count($ICEcoder["restrictedFiles"]);$i++) {
if (strpos($f,$ICEcoder['restrictedFiles'][$i])>0) {$rFile = true;};
}

View File

@@ -52,7 +52,7 @@ for ($i=0;$i<count($themeArray);$i++) {
<br><br>
file manager root:<br>
<?php echo $_SESSION['userLevel']==10 ? $ICEcoder['root'] : '[HIDDEN]';?>
<?php echo $_SESSION['loggedIn'] ? $ICEcoder['root'] : '[HIDDEN]';?>
<br><br><br><br>
<div style="font-size: 10px; line-height: 12px">ICE coder by Matt Pass (<a href="http://www.twitter.com/mattpass" style="font-size: 10px" target="_blank">@mattpass</a>)<br><br>
@@ -202,7 +202,7 @@ var showHideTabs = function() {
}
var validatePasswords = function() {
<?php if($_SESSION['userLevel']==10) { ?>
<?php if($_SESSION['loggedIn']) { ?>
if (document.settings.accountPassword.value != 0 && document.settings.accountPassword.value.length<8) {
top.ICEcoder.message('Please use at least 8 chars in the password');
} else {

View File

@@ -35,7 +35,7 @@ $ICEcoder = array(
)+$ICEcoder;
// Update this config file?
if (isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['userLevel'] == 10) {
if (isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['loggedIn']) {
$settingsContents = file_get_contents($settingsFile);
// Replace our settings vars
$repPosStart = strpos($settingsContents,'"root"');
@@ -89,15 +89,15 @@ if (isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['userLevel'] == 10) {
// Define the docRoot & iceRoot
$docRoot = rtrim(str_replace("\\","/",$_SERVER['DOCUMENT_ROOT']));
$iceRoot = rtrim(str_replace("\\","/",$ICEcoder["root"]));
if ($_SESSION['userLevel'] == 10) {
if ($_SESSION['loggedIn']) {
echo "<script>top.docRoot='".$docRoot."';top.iceRoot='".$iceRoot."'</script>";
}
$serverType = stristr($_SERVER[SERVER_SOFTWARE], "win") ? "Windows" : "Linux";
// Establish our user level
if (!isset($_SESSION['userLevel'])) {$_SESSION['userLevel'] = 0;};
if(isset($_POST['loginPassword']) && generateHash(strClean($_POST['loginPassword']),$ICEcoder["accountPassword"])==$ICEcoder["accountPassword"]) {$_SESSION['userLevel'] = 10;};
$_SESSION['userLevel'] = $_SESSION['userLevel'];
if (!isset($_SESSION['loggedIn'])) {$_SESSION['loggedIn'] = false;};
if(isset($_POST['loginPassword']) && generateHash(strClean($_POST['loginPassword']),$ICEcoder["accountPassword"])==$ICEcoder["accountPassword"]) {$_SESSION['loggedIn'] = true;};
$_SESSION['loggedIn'] = $_SESSION['loggedIn'];
// Setup our file security vars
$settingsArray = array("findFilesExclude","restrictedFiles","bannedFiles","allowedIPs");
@@ -119,7 +119,7 @@ if (!$allowedIP) {
// Save the currently opened files for next time
if (isset($_GET["saveFiles"]) && $_GET['saveFiles']) {
if ($_SESSION['userLevel'] == 10) {
if ($_SESSION['loggedIn']) {
$settingsContents = file_get_contents($settingsFile);
// Replace our previousFiles var with the the current
@@ -161,9 +161,9 @@ if (isset($_GET["saveFiles"]) && $_GET['saveFiles']) {
}
// If we're updating or calling from the index.php page, do/redo plugins
if ((isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['userLevel'] == 10) || strpos($_SERVER['PHP_SELF'],"index.php")>0) {
if ((isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['loggedIn']) || strpos($_SERVER['PHP_SELF'],"index.php")>0) {
// If we're updating, we need to recreate the plugins array
if (isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['userLevel'] == 10) {
if (isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['loggedIn']) {
$ICEcoder["plugins"] = array();
$pluginsArray = explode("====================",str_replace("\"","",str_replace("\r","",str_replace("\n","",$_POST['plugins']))));
for ($i=0;$i<count($pluginsArray);$i++) {
@@ -179,7 +179,7 @@ if ((isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['userLevel'] == 10)
};
// If we're updating, replace the plugin display with our newly established one
if (isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['userLevel'] == 10) {
if (isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['loggedIn']) {
echo "<script>top.document.getElementById('pluginsContainer').innerHTML = '".$pluginsDisplay."';</script>";
}
@@ -192,7 +192,7 @@ if ((isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['userLevel'] == 10)
};
// If we're updating our settings, clear existing setIntervals & the array refs, then start new ones
if (isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['userLevel'] == 10) {
if (isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['loggedIn']) {
?>
<script>
for (i=0;i<=top.ICEcoder.pluginIntervalRefs.length-1;i++) {
@@ -205,7 +205,7 @@ if ((isset($_POST["theme"]) && $_POST["theme"] && $_SESSION['userLevel'] == 10)
}
// Finally, show server data if we're logged in
if ($_SESSION['userLevel'] == 10) {
if ($_SESSION['loggedIn']) {
$onLoadExtras .= ";top.ICEcoder.content.style.visibility='visible'";
}
}
@@ -257,7 +257,7 @@ if ($ICEcoder["accountPassword"] == "" && isset($_GET['settings'])) {
fwrite($fh, $settingsContents);
fclose($fh);
// Set the session user level
$_SESSION['userLevel'] = 10;
$_SESSION['loggedIn'] = true;
// Finally, load again as now this file has changed and auto login
header('Location: index.php');
} else {

View File

@@ -1,6 +1,6 @@
<?php
session_start();
if ($_SESSION['userLevel'] == 0) {
if (!$_SESSION['loggedIn']) {
die("Sorry, you need to be logged in to use ICErepo");
}

View File

@@ -1,6 +1,6 @@
<?php
session_start();
if ($_SESSION['userLevel'] == 0) {
if (!$_SESSION['loggedIn']) {
die("Sorry, you need to be logged in to use ICErepo");
}
// returns converted entities where there are HTML entity equivalents

View File

@@ -1,7 +1,7 @@
<?php
session_start();
// $_SESSION['userLevel'] = 10;
if ($_SESSION['userLevel'] == 0) {
// $_SESSION['loggedIn'] = true;
if (!$_SESSION['loggedIn']) {
die("Sorry, you need to be logged in to use ICErepo");
}

View File

@@ -76,7 +76,7 @@ Class zipIt {
}
}
}
if($_SESSION['userLevel']==10) {
if($_SESSION['loggedIn']) {
$doZip = new zipIt();
echo '<script>top.ICEcoder.serverMessage("<b>Zipping Files</b>");</script>';
$addToZip = $doZip->zipFilesUp($saveLocation,$fileName,$keepLastDays,$docRoot);