Merge branch 'development' into 'permissions'

# Conflicts:
#   components/filemanager/class.filemanager.php
#   components/filemanager/controller.php
This commit is contained in:
xevidos 2019-07-17 15:55:45 +00:00
commit 954d6a43d0
6 changed files with 878 additions and 848 deletions

View file

@ -38,6 +38,8 @@ Current Tasks:
Task List: Task List:
* Add ability to login with LDAP * Add ability to login with LDAP
* Add archive management
* Add bookmark files
* Add custom market * Add custom market
* \- Add in new admin interface ( Check admin-portal branch for progress ) * \- Add in new admin interface ( Check admin-portal branch for progress )
- Group Management - Group Management
@ -46,13 +48,17 @@ Task List:
- Project Management - Project Management
- System Settings - System Settings
- User Management - User Management
* Add different code linters
* Add Drag and Drop natively to filemanager * Add Drag and Drop natively to filemanager
* Add folder / filestructure upload ability * Add folder / filestructure upload ability
* Add if file could not be saved 5 times close the open file * Add if file could not be saved 5 times close the open file
* Add multi level users. ( Projects for only certain groups, Permission levels ) * Add multi level users. ( Projects for only certain groups, Permission levels )
* Add mobile compatibility * Add mobile compatibility
* Add move files
* Add permissions module ( more in depth permissions such as read/write, delete, etc ) * Add permissions module ( more in depth permissions such as read/write, delete, etc )
* Add print code
* Add support for more database systems ( MSSQL, Oracle, SQLite, Filesystem storage, etc ) * Add support for more database systems ( MSSQL, Oracle, SQLite, Filesystem storage, etc )
* Add terminal support ( optional per permission level )
* Add in auto save timer that saves after the user stops typing instead of after every change * Add in auto save timer that saves after the user stops typing instead of after every change
* Clean up update script * Clean up update script
* Fix broken themes * Fix broken themes

View file

@ -1014,14 +1014,17 @@
uploadPositions: function() { uploadPositions: function() {
$.ajax( { if( Object.keys( codiad.active.positions ).length > 0 ) {
type: 'POST',
url: codiad.active.controller + '?action=save_positions', $.ajax( {
data: { type: 'POST',
positions: ( JSON.stringify( codiad.active.positions ) ) url: codiad.active.controller + '?action=save_positions',
}, data: {
success: function( data ) {}, positions: ( JSON.stringify( codiad.active.positions ) )
}); },
success: function( data ) {},
});
}
}, },
savePosition: function() { savePosition: function() {

File diff suppressed because it is too large Load diff

View file

@ -1,99 +1,230 @@
<?php <?php
/* /*
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed * Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
* as-is and without warranty under the MIT License. See * as-is and without warranty under the MIT License. See
* [root]/license.txt for more. This information must remain intact. * [root]/license.txt for more. This information must remain intact.
*/ */
require_once('../../common.php'); require_once( '../../common.php' );
require_once('class.filemanager.php'); require_once( 'class.filemanager.php' );
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Verify Session or Key // Verify Session or Key
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
checkSession(); checkSession();
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Get Action // Get Action
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
$response = array(
"status" => "none",
);
if (!empty($_GET['action'])) { if (!empty($_GET['action'])) {
$action = $_GET['action'];
} else {
exit('{"status":"error","data":{"error":"No Action Specified"}}');
}
//////////////////////////////////////////////////////////////////
// Ensure Project Has Been Loaded
//////////////////////////////////////////////////////////////////
if (!isset($_SESSION['project'])) {
$_GET['action']='get_current';
$_GET['no_return']='true';
require_once('../project/controller.php');
}
//////////////////////////////////////////////////////////////////
// Security Check
//////////////////////////////////////////////////////////////////
$access = Permissions::get_access( $_GET['path'] );
if ( ! Permissions::check_access( "read", $access ) ) {
die( '{"status":"error","message":"Invalid access to ' . $_GET['path'] . '."}' ); $action = $_GET['action'];
} else {
$response["status"] = "error";
$response["data"] = array(
"error" => "No action specified"
);
exit( json_encode( $response ) );
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Define Root // Ensure Project Has Been Loaded
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
$_GET['root'] = WORKSPACE; if ( ! isset( $_SESSION['project'] ) ) {
////////////////////////////////////////////////////////////////// $_GET['action'] = 'get_current';
// Handle Action $_GET['no_return'] = 'true';
////////////////////////////////////////////////////////////////// require_once('../project/controller.php');
$Filemanager = new Filemanager($_GET, $_POST, $_FILES);
$Filemanager->project = @$_SESSION['project']['path'];
$Filemanager->access = $access;
switch ($action) {
case 'index':
$Filemanager->index();
break;
case 'search':
$Filemanager->search();
break;
case 'find':
$Filemanager->find();
break;
case 'open':
$Filemanager->open();
break;
case 'open_in_browser':
$Filemanager->openinbrowser();
break;
case 'create':
$Filemanager->create();
break;
case 'delete':
$Filemanager->delete();
break;
case 'deleteInner':
$Filemanager->delete( true );
break;
case 'modify':
$Filemanager->modify();
break;
case 'duplicate':
$Filemanager->duplicate();
break;
case 'upload':
$Filemanager->upload();
break;
default:
exit('{"status":"fail","data":{"error":"Unknown Action"}}');
} }
if( isset( $_GET["path"] ) ) {
$path = $_GET["path"];
} else {
$response["status"] = "error";
$response["message"] = "Missing path.";
exit( json_encode( $response ) );
}
//////////////////////////////////////////////////////////////////
// Security Check
//////////////////////////////////////////////////////////////////
if ( ! checkPath( $path ) ) {
$response["status"] = "error";
$response["message"] = "Invalid Path";
exit( json_encode( $response ) );
}
if( isset( $_GET["destination"] ) ) {
$destination = $_GET["destination"];
if ( ! checkPath( $destination ) ) {
$response["status"] = "error";
$response["message"] = "Invalid destination";
exit( json_encode( $response ) );
}
}
//////////////////////////////////////////////////////////////////
// Handle Action
//////////////////////////////////////////////////////////////////
$Filemanager = new Filemanager();
switch( $action ) {
case 'create':
if( isset( $_GET["type"] ) ) {
$type = $_GET["type"];
$response = $Filemanager->create( $path, $type );
} else {
$response["status"] = "error";
$response["message"] = "No filetype set";
}
break;
case 'delete':
$response = $Filemanager->delete( $path, true );
break;
case 'deleteInner':
$response = $Filemanager->delete( $path, true, true );
break;
case 'duplicate':
$response = $Filemanager->duplicate( $path, $destination );
break;
case 'find':
if( ! isset( $_GET["query"] ) ) {
$response["status"] = "error";
$response["message"] = "Missing search query.";
} else {
$query = $_GET["query"];
if( isset( $_GET["options"] ) ) {
$options = $_GET["options"];
}
$response = $Filemanager->find( $path, $query, @$options );
}
break;
case 'index':
$response = $Filemanager->index( $path );
break;
case 'modify':
if( isset( $_POST["content"] ) || isset( $_POST["patch"] ) ) {
$content = isset( $_POST["content"] ) ? $_POST["content"] : "";
$patch = isset( $_POST["patch"] ) ? $_POST["patch"] : false;
$mtime = isset( $_POST["mtime"] ) ? $_POST["mtime"] : 0;
if( get_magic_quotes_gpc() ){
$content = stripslashes( $content );
$patch = stripslashes( $patch );
$mtime = stripslashes( $mtime );
}
$response = $Filemanager->modify( $path, $content, $mtime );
} else {
$response["status"] = "error";
$response["message"] = "Missing modification content";
}
break;
case 'move':
if( isset( $destination ) ) {
$response = $Filemanager->move( $path, $destination );
} else {
$response["status"] = "error";
$response["message"] = "Missing destination";
}
break;
case 'open':
$response = $Filemanager->open( $path );
break;
case 'open_in_browser':
$response = $Filemanager->openinbrowser( $path );
break;
case 'rename':
if( isset( $destination ) ) {
$response = $Filemanager->move( $path, $destination );
} else {
$response["status"] = "error";
$response["message"] = "Missing destination";
}
break;
case 'search':
if( isset( $_GET["query"] ) ) {
$query = $_GET["query"];
if( isset( $_GET["options"] ) ) {
$options = $_GET["options"];
}
$response = $Filemanager->search( $path, $query );
} else {
$response["status"] = "error";
$response["message"] = "Missing search query.";
}
break;
case 'upload':
$response = $Filemanager->upload( $path );
break;
default:
$response["status"] = "error";
$response["data"] = array(
"error" => "Unknown action"
);
break;
}
exit( json_encode( $response ) );

View file

@ -14,147 +14,157 @@ require_once('class.filemanager.php');
checkSession(); checkSession();
?> ?><form><?php
<form>
<?php
switch($_GET['action']){ switch( $_GET['action'] ) {
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Create // Create
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
case 'create': case 'create':
?> ?>
<input type="hidden" name="path" value="<?php echo($_GET['path']); ?>"> <input type="hidden" name="path" value="<?php echo($_GET['path']); ?>">
<input type="hidden" name="type" value="<?php echo($_GET['type']); ?>"> <input type="hidden" name="type" value="<?php echo($_GET['type']); ?>">
<label><span class="icon-pencil"></span><?php echo i18n((ucfirst($_GET['type']))); ?></label> <label><span class="icon-pencil"></span><?php echo i18n((ucfirst($_GET['type']))); ?></label>
<input type="text" name="object_name" autofocus="autofocus" autocomplete="off"> <input type="text" name="object_name" autofocus="autofocus" autocomplete="off">
<button class="btn-left"><?php i18n("Create"); ?></button> <button class="btn-left"><?php i18n("Create"); ?></button>
<button class="btn-right" onclick="codiad.modal.unload(); return false;"><?php i18n("Cancel"); ?></button> <button class="btn-right" onclick="codiad.modal.unload(); return false;"><?php i18n("Cancel"); ?></button>
<?php <?php
break; break;
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Rename // Rename
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
case 'rename': case 'rename':
?> ?>
<input type="hidden" name="path" value="<?php echo($_GET['path']); ?>"> <input type="hidden" name="path" value="<?php echo($_GET['path']); ?>">
<input type="hidden" name="type" value="<?php echo($_GET['type']); ?>"> <input type="hidden" name="type" value="<?php echo($_GET['type']); ?>">
<label><span class="icon-pencil"></span> <?php i18n("Rename"); ?> <?php echo i18n((ucfirst($_GET['type']))); ?></label> <label><span class="icon-pencil"></span> <?php i18n("Rename"); ?> <?php echo i18n((ucfirst($_GET['type']))); ?></label>
<input type="text" name="object_name" autofocus="autofocus" autocomplete="off" value="<?php echo($_GET['short_name']); ?>"> <input type="text" name="object_name" autofocus="autofocus" autocomplete="off" value="<?php echo($_GET['short_name']); ?>">
<button class="btn-left"><?php i18n("Rename"); ?></button> <button class="btn-left"><?php i18n("Rename"); ?></button>
<button class="btn-right" onclick="codiad.modal.unload(); return false;"><?php i18n("Cancel"); ?></button> <button class="btn-right" onclick="codiad.modal.unload(); return false;"><?php i18n("Cancel"); ?></button>
<?php <?php
break; break;
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Delete // Delete
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
case 'delete': case 'delete':
?> ?>
<input type="hidden" name="path" value="<?php echo($_GET['path']); ?>"> <input type="hidden" name="path" value="<?php echo($_GET['path']); ?>">
<label><?php i18n("Are you sure you wish to delete the following:"); ?></label> <label><?php i18n("Are you sure you wish to delete the following:"); ?></label>
<pre><?php if(!FileManager::isAbsPath($_GET['path'])) { echo '/'; }; echo($_GET['path']); ?></pre> <pre><?php if(!FileManager::isAbsPath($_GET['path'])) { echo '/'; }; echo($_GET['path']); ?></pre>
<button class="btn-left"><?php i18n("Delete"); ?></button> <button class="btn-left"><?php i18n("Delete"); ?></button>
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Cancel"); ?></button> <button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Cancel"); ?></button>
<?php <?php
break; break;
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Delete // Delete
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
case 'deleteInner': case 'deleteInner':
?> ?>
<input type="hidden" name="path" value="<?php echo($_GET['path']); ?>"> <input type="hidden" name="path" value="<?php echo($_GET['path']); ?>">
<label><?php i18n("Are you sure you wish to delete the contents of the following path:"); ?></label> <label><?php i18n("Are you sure you wish to delete the contents of the following path:"); ?></label>
<pre><?php if(!FileManager::isAbsPath($_GET['path'])) { echo '/'; }; echo($_GET['path']); ?></pre> <pre><?php if(!FileManager::isAbsPath($_GET['path'])) { echo '/'; }; echo($_GET['path']); ?></pre>
<button class="btn-left"><?php i18n("Delete"); ?></button> <button class="btn-left"><?php i18n("Delete"); ?></button>
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Cancel"); ?></button> <button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Cancel"); ?></button>
<?php <?php
break; break;
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Preview // Preview
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
case 'preview': case 'preview':
?> ?>
<label><?php i18n("Inline Preview"); ?></label> <label><?php i18n("Inline Preview"); ?></label>
<div><br><br><img src="<?php echo(str_replace(BASE_PATH . "/", "", WORKSPACE) . "/" . $_GET['path']); ?>"><br><br></div> <div>
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Close"); ?></button> <?php
<?php
break; $source = str_replace( BASE_PATH . "/", "", WORKSPACE ) . "/" . $_GET['path'];
$type = mime_content_type( $source );
//////////////////////////////////////////////////////////////////
// Preview if( strpos( "audio", $type ) !== false ) {
//////////////////////////////////////////////////////////////////
case 'music_preview': ?><audio controls><source src="<?php echo $source;?>"></audio><?php
?> } elseif( strpos( "image", $type ) !== false ) {
<label><?php i18n("Inline Preview"); ?></label>
<div><br><br> ?><img src="<?php echo $source;?>"><?php
<audio controls> } else {
<source src="<?php echo(str_replace(BASE_PATH . "/", "", WORKSPACE) . "/" . $_GET['path']); ?>">
</audio> ?><p>Error, unknown file type.</p><?php
<br><br></div> }
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Close"); ?></button> ?>
<?php </div>
break; <button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Close");?></button>
<?php
////////////////////////////////////////////////////////////////// break;
// Overwrite
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
case 'overwrite': // Overwrite
?> //////////////////////////////////////////////////////////////////
<input type="hidden" name="path" value="<?php echo($_GET['path']); ?>"> case 'overwrite':
<label><?php i18n("Would you like to overwrite or duplicate the following:"); ?></label> ?>
<pre><?php if(!FileManager::isAbsPath($_GET['path'])) { echo '/'; }; echo($_GET['path']); ?></pre> <input type="hidden" name="path" value="<?php echo($_GET['path']); ?>">
<select name="or_action"> <label><?php i18n("Would you like to overwrite or duplicate the following:"); ?></label>
<option value="0"><?php i18n("Overwrite Original"); ?></option> <pre>
<option value="1"><?php i18n("Create Duplicate"); ?></option> <?php
</select> if( ! FileManager::isAbsPath( $_GET['path'] ) ) {
<button class="btn-left"><?php i18n("Continue"); ?></button>
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Cancel"); ?></button> echo '/';
<?php };
break; echo( $_GET['path'] );
?>
////////////////////////////////////////////////////////////////// </pre>
// Search <select name="or_action">
////////////////////////////////////////////////////////////////// <option value="0"><?php i18n("Overwrite Original"); ?></option>
case 'search': <option value="1"><?php i18n("Create Duplicate"); ?></option>
?> </select>
<input type="hidden" name="path" value="<?php echo($_GET['path']); ?>"> <button class="btn-left"><?php i18n("Continue"); ?></button>
<table class="file-search-table"> <button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Cancel"); ?></button>
<tr> <?php
<td width="65%"> break;
<label><?php i18n("Search Files:"); ?></label>
<input type="text" name="search_string" autofocus="autofocus"> //////////////////////////////////////////////////////////////////
</td> // Search
<td width="5%">&nbsp;&nbsp;</td> //////////////////////////////////////////////////////////////////
<td> case 'search':
<label><?php i18n("In:"); ?></label> ?>
<select name="search_type"> <input type="hidden" name="path" value="<?php echo($_GET['path']); ?>">
<option value="0"><?php i18n("Current Project"); ?></option> <table class="file-search-table">
<?php if(checkAccess()) { ?> <tr>
<option value="1"><?php i18n("Workspace Projects"); ?></option> <td width="65%">
<?php } ?> <label><?php i18n("Search Files:"); ?></label>
</select> <input type="text" name="search_string" autofocus="autofocus">
</td> </td>
</tr> <td width="5%">&nbsp;&nbsp;</td>
<tr> <td>
<td colspan="3"> <label><?php i18n("In:"); ?></label>
<label><?php i18n("File Type:"); ?></label> <select name="search_type">
<input type="text" name="search_file_type" placeholder="<?php i18n("space seperated file types eg: js c php"); ?>"> <option value="0"><?php i18n("Current Project"); ?></option>
</td> <?php
</tr> if( checkAccess() ) {
</table>
<pre id="filemanager-search-results"></pre> ?><option value="1"><?php i18n("Workspace Projects"); ?></option><?php
<div id="filemanager-search-processing"></div> }
<button class="btn-left"><?php i18n("Search"); ?></button> ?>
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Cancel"); ?></button> </select>
<?php </td>
break; </tr>
<tr>
<td colspan="3">
<label><?php i18n("File Type:"); ?></label>
<input type="text" name="search_file_type" placeholder="<?php i18n("space seperated file types eg: js c php"); ?>">
</td>
</tr>
</table>
<pre id="filemanager-search-results"></pre>
<div id="filemanager-search-processing"></div>
<button class="btn-left"><?php i18n("Search"); ?></button>
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Cancel"); ?></button>
<?php
break;
} }
?> ?></form>
</form>

View file

@ -60,8 +60,6 @@
this.nodeListener(); this.nodeListener();
this.auto_reload = ( await codiad.settings.get_option( "codiad.filemanager.autoReloadPreview" ) == "true" ); this.auto_reload = ( await codiad.settings.get_option( "codiad.filemanager.autoReloadPreview" ) == "true" );
console.log( this.auto_reload );
amplify.subscribe( 'settings.save', async function() { amplify.subscribe( 'settings.save', async function() {
let option = ( await codiad.settings.get_option( "codiad.filemanager.autoReloadPreview" ) == "true" ); let option = ( await codiad.settings.get_option( "codiad.filemanager.autoReloadPreview" ) == "true" );
@ -731,7 +729,6 @@
} else if( path == this.clipboard ) { } else if( path == this.clipboard ) {
codiad.message.error( i18n( 'Cannot Paste Directory Into Itself' ) ); codiad.message.error( i18n( 'Cannot Paste Directory Into Itself' ) );
} else { } else {
let project = codiad.project.getCurrent();
var shortName = _this.getShortName( _this.clipboard ); var shortName = _this.getShortName( _this.clipboard );
if( $( '#file-manager a[data-path="' + path + '/' + shortName + '"]' ) if( $( '#file-manager a[data-path="' + path + '/' + shortName + '"]' )
.length ) { // Confirm overwrite? .length ) { // Confirm overwrite?
@ -745,15 +742,13 @@
var duplicate = false; var duplicate = false;
if( $( '#modal-content form select[name="or_action"]' ).val() == 1 ) { if( $( '#modal-content form select[name="or_action"]' ).val() == 1 ) {
duplicate = true; duplicate = true;
console.log( 'Dup!' ); //console.log( 'Dup!' );
} }
_this.processPasteNode( path, duplicate ); _this.processPasteNode( path, duplicate );
}); });
} else { // No conflicts; proceed... } else { // No conflicts; proceed...
_this.processPasteNode( path, false ); _this.processPasteNode( path, false );
} }
codiad.filemanager.rescan( project );
} }
}, },
@ -776,6 +771,7 @@
shortName: shortName, shortName: shortName,
duplicate: duplicate duplicate: duplicate
}); });
codiad.filemanager.rescan( path );
} }
}); });
}, },
@ -808,9 +804,9 @@
} }
var newPath = temp.join( '/' ) + '/' + newName; var newPath = temp.join( '/' ) + '/' + newName;
$.get( _this.controller, { $.get( _this.controller, {
action: 'modify', action: 'rename',
path: path, path: path,
new_name: newName destination: newPath
}, function( data ) { }, function( data ) {
var renameResponse = codiad.jsend.parse( data ); var renameResponse = codiad.jsend.parse( data );
let renamedMessage = ""; let renamedMessage = "";