Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/jquery-terminal/examples/json-rpc-service-demo.php
1293 views
1
<?php
2
3
require('json-rpc.php');
4
5
if (function_exists('xdebug_disable')) {
6
xdebug_disable();
7
}
8
9
class Demo {
10
static $login_documentation = "login to the server (return token)";
11
public function login($user, $passwd) {
12
if (strcmp($user, 'demo') == 0 && strcmp($passwd, 'demo') == 0) {
13
// If you need to handle more than one user you can create
14
// new token and save it in database
15
// UPDATE users SET token = '$token' WHERE name = '$user'
16
return md5($user . ":" . $passwd);
17
} else {
18
throw new Exception("Wrong Password");
19
}
20
}
21
// ---------------------------------------------------------------------------
22
static $ls_documentation = "list directory if token is valid";
23
public function ls($token, $path = null) {
24
if (strcmp(md5("demo:demo"), $token) == 0) {
25
if (preg_match("/\.\./", $path)) {
26
throw new Exception("No directory traversal Dude");
27
}
28
$base = preg_replace("/(.*\/).*/", "$1", $_SERVER["SCRIPT_FILENAME"]);
29
$path = realpath($base . ($path[0] != '/' ? "/" : "") . $path);
30
$dir = opendir($path);
31
while($name = readdir($dir)) {
32
$fname = $path . "/" . $name;
33
if (!preg_match("/^\\.{1,2}$/", $name) && !is_dir($fname)) {
34
$list[] = $name;
35
}
36
}
37
closedir($dir);
38
return $list;
39
} else {
40
throw new Exception("Access Denied");
41
}
42
}
43
// ---------------------------------------------------------------------------
44
static $whoami_documentation = "return user information";
45
public function whoami($token) {
46
return array("your User Agent" => $_SERVER["HTTP_USER_AGENT"],
47
"your IP" => $_SERVER['REMOTE_ADDR'],
48
"you acces this from" => $_SERVER["HTTP_REFERER"]);
49
}
50
}
51
52
handle_json_rpc(new Demo());
53
54
?>
55
56