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() { public static function is_admin() {
global $sql; global $sql;
$query = "SELECT COUNT( * ) FROM users WHERE id=? AND ( access=? OR access='admin' );"; $admin = false;
$bind_variables = array( $_SESSION["user_id"], Permissions::SYSTEM_LEVELS["admin"] );
$return = $sql->query( $query, $bind_variables, -1, 'fetchColumn' ); if( isset( $_SESSION["user_id"] ) ) {
$admin = ( $return > 0 );
$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; return $admin;
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,5 @@
<?php <?php
require_once( __DIR__ . "/class.sql.conversions.php" );
require_once( __DIR__ . "/../permissions/class.permissions.php" ); require_once( __DIR__ . "/../permissions/class.permissions.php" );
class sql { class sql {
@ -13,13 +12,10 @@ class sql {
); );
public $connection = null; public $connection = null;
public $conversions = null;
public $identifier_character = null; public $identifier_character = null;
protected static $instance = null; protected static $instance = null;
public function __construct() { public function __construct() {
$this->conversions = new sql_conversions();
} }
public function close() { public function close() {
@ -46,12 +42,6 @@ class sql {
return( $this->connection ); 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() { public function create_default_tables() {
$create_tables = $this->create_tables(); $create_tables = $this->create_tables();
@ -302,16 +292,19 @@ class sql {
$convert = true; $convert = true;
} }
$current_user = null;
foreach( $users as $row => $user ) { foreach( $users as $row => $user ) {
if( $project["owner"] == $user["username"] ) { if( $project["owner"] == $user["username"] ) {
$update_query .= "UPDATE projects SET owner={$user["id"]} WHERE id={$project["id"]};"; $update_query .= "UPDATE projects SET owner={$user["id"]} WHERE id={$project["id"]};";
$current_user = $user;
break; 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"]};"; $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('../settings/class.settings.php');
require_once('./class.update.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"; $user_settings_file = BASE_PATH . "/data/settings.php";
$projects_file = BASE_PATH . "/data/projects.php"; $projects_file = BASE_PATH . "/data/projects.php";
$users_file = BASE_PATH . "/data/users.php"; $users_file = BASE_PATH . "/data/users.php";
//checkSession(); //checkSession();
if ( ! checkAccess() ) { if ( ! checkAccess() && ! check_access_legacy() ) {
echo "Error, you do not have access to update Codiad."; echo "Error, you do not have access to update Codiad.";
exit(); exit();

View File

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