Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
shirosaidev committed Nov 5, 2022
1 parent 9e99d3e commit 581de76
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 33 deletions.
9 changes: 9 additions & 0 deletions diskover-web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Diskover-web v2 Community Edition Change Log

# [2.0.6] - 2022-11-06
### fixed
- issue searching for full paths to hidden dot files/folders and files with double extensions (e.g. tar.gz)
- issue searching for full file path
- issue with rootpath not updating and directory searches showing no results
- es search error [ids] unknown field [type]
- occasional php fatal error when search contains parent_path field


# [2.0.5] - 2022-10-21
### fixed
- changing index in url params doesn't set the index or root path
Expand Down
1 change: 0 additions & 1 deletion diskover-web/public/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
session_destroy();
// Delete any path cookies
setcookie('path');
setcookie('prevpath');
setcookie('rootpath');
setcookie('parentpath');
setcookie('toppath');
Expand Down
3 changes: 2 additions & 1 deletion diskover-web/public/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
$request = predict_search($searchquery);

// check for path in search query and update paths in session and cookies
if (!isset($_GET['path']) && strpos($request, 'parent_path:') !== false) {
if (!isset($_GET['path']) && strpos($request, 'parent_path:\/') !== false) {
// parse out actual path from es query string
$pp = explode('parent_path:', $request)[1];
$pp = preg_replace('/ (AND|OR) .*/i', '', $pp);
Expand All @@ -68,6 +68,7 @@
// set path cookie to update tree
createCookie('path', $path);
createCookie('parentpath', getParentDir($path));
$_GET['path'] = $path;
}
}

Expand Down
2 changes: 1 addition & 1 deletion diskover-web/public/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
$searchParams['body'] = [
'query' => [
'ids' => [
'type' => '_doc',
//'type' => '_doc',
'values' => [ $_REQUEST['id'] ]
]
]
Expand Down
30 changes: 9 additions & 21 deletions diskover-web/src/diskover/Diskover.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,20 +499,13 @@ function setPaths()
$path = get_es_path($esIndex, 1);
$_SESSION['rootpath'] = $path;
createCookie('rootpath', $path);
createCookie('prevpath', $path);
createCookie('parentpath', getParentDir($path));
}
}
// remove any trailing slash (unless root)
if ($path !== "/") {
$path = rtrim($path, '/');
}
createCookie('path', $path);
createCookie('parentpath', getParentDir($path));
// check rootpath session is set
if (!isset($_SESSION['rootpath'])) {
$_SESSION['rootpath'] = $path;
}

$toppath = $_SESSION['toppath'];
if (empty($toppath)) {
Expand All @@ -526,15 +519,11 @@ function setPaths()
$_SESSION['toppath'] = $toppath;
}

$prevpath = getCookie('prevpath');

// update prevpath to be current path
createCookie('prevpath', $path);

// update rootpath session and cookie and parentpath if path changed
if ($path == $toppath && $path != $prevpath) {
$_SESSION['rootpath'] = $path;
createCookie('rootpath', $path);
$rootpath = getRootpath($path);
if (!is_null($rootpath)) {
$_SESSION['rootpath'] = $rootpath;
createCookie('rootpath', $rootpath);
createCookie('path', $path);
createCookie('parentpath', getParentDir($path));
}
}
Expand Down Expand Up @@ -632,7 +621,6 @@ function checkIndices()
function clearPaths() {
deleteCookie('path');
deleteCookie('rootpath');
deleteCookie('prevpath');
deleteCookie('parentpath');
unset($_SESSION['rootpath']);
unset($_SESSION['toppath']);
Expand Down Expand Up @@ -1095,17 +1083,17 @@ function predict_search($q)
// check for wildcard at end of path
if (preg_match('/^.*\\*$/', $request)) {
$pathnowild = rtrim($request, '\*');
// update path cookie to update tree
$cookiepath = str_replace('\\', '', $pathnowild);
createCookie('path', $cookiepath);
$request = 'parent_path:' . $pathnowild . '*';
} elseif (preg_match('/^.*\.\w{3,4}$/', $request)) { // file
} elseif (preg_match('/(^.*\.\w{3,4}(\.\w{2}){0,1}$)|(^.*\/\..*$)/', $request)) { // file
$request = 'parent_path:' . rtrim(dirname($request), '\/') . ' AND name:' . rtrim(basename($request), '\/');
$cookiepath = rtrim(dirname($q), '/');
createCookie('path', $cookiepath);
} else { // directory
// update path cookie to update tree
$cookiepath = str_replace('\\', '', $request);
createCookie('path', $cookiepath);
$request = 'parent_path:' . $request;
$request = '(parent_path:' . rtrim(dirname($request), '\/') . ' AND name:' . rtrim(basename($request), '\/') . ') OR parent_path:' . $request;
}
// NOT es field query such as name:filename
} elseif (preg_match('/(\w+):/i', $q) == false && !empty($q)) {
Expand Down
2 changes: 1 addition & 1 deletion diskover-web/src/diskover/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
*/

// diskover-web version
$VERSION = '2.0.5 community edition (ce)';
$VERSION = '2.0.6 community edition (ce)';
5 changes: 5 additions & 0 deletions diskover/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Diskover v2 Community Edition Change Log

# [2.0.6] - 2022-11-06
### changed
- better handling of errors when importing alternate scanner modules


# [2.0.5] - 2022-10-21
### fixed
- log file names having 12H format instead of 24H
Expand Down
25 changes: 17 additions & 8 deletions diskover/diskover.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
get_file_name, load_plugins, list_plugins, get_plugins_info, set_times, \
get_mem_usage, get_win_path, rem_win_path

version = '2.0.5 community edition (ce)'
version = '2.0.6 community edition (ce)'
__version__ = version

# Windows check
Expand Down Expand Up @@ -221,6 +221,16 @@ def config_warn(e):
emptyindex = False


class AltScannerError(Exception):
def __init__(self, message):
self.message = message
super().__init__(self.message)
logmsg = 'ALT SCANNER EXCEPTION {0}'.format(self.message)
logger.exception(logmsg)
if logtofile: logger_warn.exception(logmsg)
sys.exit(1)


def close_app():
"""Handle exiting cleanly when a keyboard interupt/sigint occurs."""
global quit
Expand Down Expand Up @@ -1028,13 +1038,8 @@ def log_setup():
try:
full_module_name = 'scanners.' + options.altscanner
alt_scanner = importlib.import_module(full_module_name)
except ModuleNotFoundError:
logmsg = 'Alternate scanner {0} not found!'.format(options.altscanner)
logger.error(logmsg)
if logtofile: logger_warn.error(logmsg)
sys.exit(1)
except Exception:
raise
except Exception as e:
raise AltScannerError(e)
logger.info('Using alternate scanner {0}'.format(alt_scanner))
# point os.scandir() to scandir() in alt scanner module
os.scandir = alt_scanner.scandir
Expand All @@ -1043,11 +1048,15 @@ def log_setup():
alt_scanner.log_setup(loglevel, logformat, logtofile, handler_file, handler_warnfile, handler_con)
except AttributeError:
pass
except Exception as e:
raise AltScannerError(e)
# call init function to create any connections to api, db, etc
try:
alt_scanner.init(globals())
except AttributeError:
pass
except Exception as e:
raise AltScannerError(e)
else:
alt_scanner = None

Expand Down

0 comments on commit 581de76

Please sign in to comment.