Added legacy support to necessary functions used in update processes, Continued work on search feature, Updated jsend to use let instead of var, Continued removal of no longer used methods

This commit is contained in:
xevidos 2019-10-24 08:56:24 -04:00
parent aad8c48a82
commit c85c920340
8 changed files with 79 additions and 49 deletions

View File

@ -167,10 +167,15 @@ class Common {
public static function is_admin() {
global $sql;
$query = "SELECT COUNT( * ) FROM users WHERE id=? AND ( access=? OR access='admin' );";
$bind_variables = array( $_SESSION["user_id"], Permissions::SYSTEM_LEVELS["admin"] );
$return = $sql->query( $query, $bind_variables, -1, 'fetchColumn' );
$admin = ( $return > 0 );
$admin = false;
if( isset( $_SESSION["user_id"] ) ) {
$query = "SELECT COUNT( * ) FROM users WHERE id=? AND ( access=? OR access='admin' );";
$bind_variables = array( $_SESSION["user_id"], Permissions::SYSTEM_LEVELS["admin"] );
$return = $sql->query( $query, $bind_variables, -1, 'fetchColumn' );
$admin = ( $return > 0 );
}
return $admin;
}

View File

@ -635,6 +635,12 @@ class Filemanager extends Common {
"status" => "none",
"message" => null,
);
if( ! common::isAbsPath( $path ) ) {
$path = WORKSPACE . "/$path";
}
if ( ! function_exists( 'shell_exec' ) ) {
$response["status"] = "error";
@ -654,7 +660,7 @@ class Filemanager extends Common {
$da['line'] = $data[1];
$da['file'] = str_replace( $path, '', $data[0] );
$da['result'] = str_replace( $path, '', $data[0] );
$da['result'] = $_SESSION["project"] . str_replace( $path, '', $data[0] );
$da['string'] = str_replace( $data[0] . ":" . $data[1] . ':', '', $line );
$return[] = $da;
}
@ -666,7 +672,8 @@ class Filemanager extends Common {
} else {
$response["status"] = "success";
$response["index"] = $return;
$response["data"] = array();
$response["data"]["index"] = $return;
}
}
return $response;

View File

@ -46,9 +46,9 @@ if( ! isset( $_SESSION['project'] ) ) {
require_once('../project/controller.php');
}
if( isset( $_GET["path"] ) ) {
if( isset( $_GET["path"] ) || isset( $_POST["path"] ) ) {
$path = $_GET["path"];
$path = isset( $_GET["path"] ) ? $_GET["path"] : $_POST["path"];
} else {
$response["status"] = "error";
@ -60,7 +60,7 @@ if( isset( $_GET["path"] ) ) {
// Security Check
//////////////////////////////////////////////////////////////////
$access = Permissions::get_access( $_GET['path'] );
$access = Permissions::get_access( $path );
if ( ! Permissions::check_access( "read", $access ) ) {
@ -91,7 +91,7 @@ switch( $action ) {
case 'archive':
if( ! isset( $_GET["path"] ) ) {
if( ! isset( $path ) ) {
exit( formatJSEND( "error", "No path specified." ) );
}
@ -102,7 +102,7 @@ switch( $action ) {
}
$Archive = new Archive();
$path = $Filemanager->formatPath( $_GET["path"] );
$path = $Filemanager->formatPath( $path );
$result = $Archive->compress( $path );
if( $result ) {
@ -238,15 +238,19 @@ switch( $action ) {
case 'search':
if( isset( $_GET["query"] ) ) {
if( isset( $path ) && isset( $_POST["query"] ) ) {
$query = $_GET["query"];
if( isset( $_GET["options"] ) ) {
$query = $_POST["query"];
$options = $_GET["options"];
if( isset( $_POST["options"] ) ) {
$options = json_decode( $_POST["options"], true );
} else {
$options = array();
}
$response = $Filemanager->search( $path, $query );
$response = $Filemanager->search( $path, $query, $options );
} else {
$response["status"] = "error";

View File

@ -1139,9 +1139,11 @@
action: 'search',
path: path
});
codiad.modal.load_process.done( async function() {
var lastSearched = JSON.parse( await codiad.settings.get_option( "lastSearched" ) );
if( lastSearched ) {
$( '#modal-content form input[name="search_string"]' ).val( lastSearched.searchText );
$( '#modal-content form input[name="search_file_type"]' ).val( lastSearched.fileExtension );
$( '#modal-content form select[name="search_type"]' ).val( lastSearched.searchType );
@ -1152,15 +1154,11 @@
});
codiad.modal.hideOverlay();
let _this = this;
$( '#modal-content form' )
.live( 'submit', function( e ) {
$( '#filemanager-search-processing' )
.show();
$( '#modal-content form' ).live( 'submit', function( e ) {
$( '#filemanager-search-processing' ).show();
e.preventDefault();
searchString = $( '#modal-content form input[name="search_string"]' )
.val();
fileExtensions = $( '#modal-content form input[name="search_file_type"]' )
.val();
searchString = $( '#modal-content form input[name="search_string"]' ).val();
fileExtensions = $( '#modal-content form input[name="search_file_type"]' ).val();
searchFileType = $.trim( fileExtensions );
if( searchFileType != '' ) {
//season the string to use in find command
@ -1168,12 +1166,21 @@
}
searchType = $( '#modal-content form select[name="search_type"]' )
.val();
$.post( _this.controller + '?action=search&path=' + encodeURIComponent( path ) + '&type=' + searchType, {
search_string: searchString,
search_file_type: searchFileType
let options = {
filetype: fileExtensions,
};
$.post( _this.controller + '?action=search', {
path: path,
query: searchString,
options: JSON.stringify( options )
}, function( data ) {
searchResponse = codiad.jsend.parse( data );
var results = '';
let searchResponse = codiad.jsend.parse( data );
let results = '';
console.log( data );
console.log( searchResponse );
if( searchResponse != 'error' ) {
$.each( searchResponse.index, function( key, val ) {
// Cleanup file format

View File

@ -23,7 +23,6 @@ class Project extends Common {
public $no_return = false;
public $assigned = false;
public $command_exec = '';
public $public_project = false;
public $user = '';
//////////////////////////////////////////////////////////////////
@ -47,12 +46,12 @@ class Project extends Common {
public function add_project( $project_name, $project_path, $owner = null ) {
global $sql;
if( $this->public_project ) {
if( $owner == null ) {
$owner = 'nobody';
$owner = -1;
} else {
$owner = $_SESSION["user"];
$owner = $_SESSION["user_id"];
}
$query = "INSERT INTO projects( name, path, owner ) VALUES ( ?, ?, ? );";
@ -69,7 +68,7 @@ class Project extends Common {
global $sql;
$query = "SELECT * FROM projects WHERE path=? AND owner=? LIMIT 1";
$bind_variables = array( $this->path, $_SESSION["user"] );
$bind_variables = array( $this->path, $_SESSION["user_id"] );
$project = $sql->query( $query, $bind_variables, array(), "fetch" );
if( empty( $project ) ) {

View File

@ -1,6 +1,5 @@
<?php
require_once( __DIR__ . "/class.sql.conversions.php" );
require_once( __DIR__ . "/../permissions/class.permissions.php" );
class sql {
@ -13,13 +12,10 @@ class sql {
);
public $connection = null;
public $conversions = null;
public $identifier_character = null;
protected static $instance = null;
public function __construct() {
$this->conversions = new sql_conversions();
}
public function close() {
@ -46,12 +42,6 @@ class sql {
return( $this->connection );
}
public function create_table( $table_name, $fields=array(), $attributes=array() ) {
$query = $this->conversions->table( $table_name, $fields, $attributes );
//$this->query( $query, array(), array(), null, "rowCount" );
}
public function create_default_tables() {
$create_tables = $this->create_tables();
@ -302,16 +292,19 @@ class sql {
$convert = true;
}
$current_user = null;
foreach( $users as $row => $user ) {
if( $project["owner"] == $user["username"] ) {
$update_query .= "UPDATE projects SET owner={$user["id"]} WHERE id={$project["id"]};";
$current_user = $user;
break;
}
}
if( $project["owner"] != $user["username"] ) {
if( $current_user != null && $project["owner"] != $current_user["username"] ) {
$update_query .= "UPDATE projects SET owner=-1 WHERE id={$project["id"]};";
}

View File

@ -8,13 +8,27 @@ require_once('../../common.php');
require_once('../settings/class.settings.php');
require_once('./class.update.php');
function check_access_legacy() {
$pass = false;
if( isset( $_SESSION["token"] ) && isset( $_SESSION["user"] ) ) {
global $sql;
$query = "SELECT COUNT( * ) FROM users WHERE username=? AND access=?;";
$bind_variables = array( $_SESSION["user"], "admin" );
$return = $sql->query( $query, $bind_variables, -1, 'fetchColumn' );
$admin = ( $return > 0 );
return $admin;
}
return $pass;
}
$user_settings_file = BASE_PATH . "/data/settings.php";
$projects_file = BASE_PATH . "/data/projects.php";
$users_file = BASE_PATH . "/data/users.php";
//checkSession();
if ( ! checkAccess() ) {
if ( ! checkAccess() && ! check_access_legacy() ) {
echo "Error, you do not have access to update Codiad.";
exit();

View File

@ -1,6 +1,6 @@
( function( global, $ ) {
var codiad = global.codiad;
let codiad = global.codiad;
//////////////////////////////////////////////////////////////////////
// Parse JSEND Formatted Returns
@ -11,7 +11,8 @@
parse: function( d ) {
// (Data)
var obj = $.parseJSON( d );
let obj = $.parseJSON( d );
if ( obj === undefined || obj === null ) {
return 'error';