-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.php
More file actions
62 lines (57 loc) · 1.84 KB
/
Copy pathcontroller.php
File metadata and controls
62 lines (57 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
ini_set('display_errors',1);
/*
* Soli Deo Gloria
* Copyright (c) Tim Holum, distributed
* as-is and without warranty under the MIT License. See
* [root]/license.txt for more. This information must remain intact.
*/
require_once('../../config.php');
//require_once('class.grepfind.php');
class grepfind{
var $path;
var $searchstring;
function __construct($request){
$this->path = $request['path'];
$this->searchstring = $request['searchstring'];
}
function error($error){
$error = array();
$error['status'] = 'error';
$error['data'] = array('error' => $error);
echo json_encode($error);
}
function __call($name , $args){
$this->error( $name . 'is not a valid function');
}
function search(){
$input = $this->searchstring;//base64_decode($searchstring);
//Might need to find a better way to do this, but for now it will have to work
chdir(WORKSPACE);
if($this->path[0] == "/"){
$path = substr($this->path,1);
} else {
$path = $this->path;
}
$input = str_replace('"' , '', $input);
$output = shell_exec('grep -i -I -n -R "' . $input . '" ' . $path . '/* ');
$output_arr = explode("\n" , $output );
$return = array();
// $return[] = $path;
foreach( $output_arr as $line){
$data = explode(":", $line);
$da = array();
if( count($data) > 2 ){
$da['line'] = $data[1];
$da['file'] = '/' . $data[0];
$da['string'] = str_replace($data[0] . ":" . $data[1] . ':' , '', $line);
$return[] = $da;
}
}
echo json_encode($return);
}
}
$grepfind = new grepfind($_REQUEST);
$action = $_REQUEST['action'];
$grepfind->$action();
?>