Initial support for r2pipe.html ##r2pipe
$ r2 -i doc/r2pipe.html /bin/ls
This commit is contained in:
parent
65da67035c
commit
444e7b0685
|
@ -0,0 +1,35 @@
|
|||
<html>
|
||||
|
||||
<body>
|
||||
Hello World
|
||||
<button type="button" id="buttonInfo">Info</button>
|
||||
<button type="button" id="buttonFlags">Flags</button>
|
||||
<div id="urls">Starting up...</div>
|
||||
</body>
|
||||
|
||||
|
||||
<script type="application/javascript" src="/m/r2.js">
|
||||
</script>
|
||||
<script>
|
||||
|
||||
r2.id=(x) => document.getElementById(x);
|
||||
r2.onload=(x) => document.addEventListener('DOMContentLoaded', x);
|
||||
|
||||
function main() {
|
||||
const urls = r2.id('urls');
|
||||
r2.id('buttonInfo').addEventListener('click', () => {
|
||||
r2.cmd('i', function(res) {
|
||||
urls.innerHTML = '<pre>' + res + '</pre>';
|
||||
});
|
||||
});
|
||||
r2.id('buttonFlags').addEventListener('click', () => {
|
||||
r2.cmd('f', function(res) {
|
||||
urls.innerHTML = '<pre>' + res + '</pre>';
|
||||
});
|
||||
});
|
||||
urls.innerHTML = 'Press any button';
|
||||
}
|
||||
r2.onload(main);
|
||||
</script>
|
||||
|
||||
</html>
|
|
@ -3351,6 +3351,7 @@ R_API int r_core_config_init(RCore *core) {
|
|||
r_config_desc (cfg, "http.browser", "Command to open HTTP URLs");
|
||||
#endif
|
||||
SETI ("http.maxsize", 0, "Maximum file size for upload");
|
||||
SETPREF ("http.index", "index.html", "Main html file to check in directory");
|
||||
SETPREF ("http.bind", "localhost", "Server address");
|
||||
SETPREF ("http.homeroot", R_JOIN_2_PATHS ("~", R2_HOME_WWWROOT), "http home root directory");
|
||||
#if __ANDROID__
|
||||
|
|
|
@ -871,6 +871,17 @@ R_API bool r_core_run_script(RCore *core, const char *file) {
|
|||
ret = r_core_cmd_lines (core, out);
|
||||
free (out);
|
||||
}
|
||||
} else if (r_str_endswith (file, ".html")) {
|
||||
const bool httpSandbox = r_config_get_i (core->config, "http.sandbox");
|
||||
const bool httpIndex = r_config_get_i (core->config, "http.index");
|
||||
r_config_set_i (core->config, "http.sandbox", 0);
|
||||
char *absfile = r_file_abspath (file);
|
||||
r_config_set (core->config, "http.index", absfile);
|
||||
free (absfile);
|
||||
r_core_cmdf (core, "=H");
|
||||
r_config_set_i (core->config, "http.sandbox", httpSandbox);
|
||||
r_config_set (core->config, "http.index", httpIndex);
|
||||
ret = true;
|
||||
} else if (r_str_endswith (file, ".c")) {
|
||||
r_core_cmd_strf (core, "#!c %s", file);
|
||||
ret = true;
|
||||
|
|
|
@ -12,6 +12,7 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char *
|
|||
char *dir;
|
||||
int iport;
|
||||
const char *host = r_config_get (core->config, "http.bind");
|
||||
const char *index = r_config_get (core->config, "http.index");
|
||||
const char *root = r_config_get (core->config, "http.root");
|
||||
const char *homeroot = r_config_get (core->config, "http.homeroot");
|
||||
const char *port = r_config_get (core->config, "http.port");
|
||||
|
@ -376,12 +377,18 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char *
|
|||
} else {
|
||||
const char *root = r_config_get (core->config, "http.root");
|
||||
const char *homeroot = r_config_get (core->config, "http.homeroot");
|
||||
const char *index = r_config_get (core->config, "http.index");
|
||||
char *path;
|
||||
if (!strcmp (rs->path, "/")) {
|
||||
free (rs->path);
|
||||
rs->path = strdup ("/index.html");
|
||||
}
|
||||
if (homeroot && *homeroot) {
|
||||
if (*index == '/') {
|
||||
rs->path = strdup (index);
|
||||
path = strdup (index);
|
||||
} else {
|
||||
rs->path = r_str_newf ("/%s", index);
|
||||
path = r_file_root (root, rs->path);
|
||||
}
|
||||
} else if (homeroot && *homeroot) {
|
||||
char *homepath = r_file_abspath (homeroot);
|
||||
path = r_file_root (homepath, rs->path);
|
||||
free (homepath);
|
||||
|
@ -390,12 +397,15 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char *
|
|||
path = r_file_root (root, rs->path);
|
||||
}
|
||||
} else {
|
||||
path = r_file_root (root, rs->path);
|
||||
if (*index == '/') {
|
||||
path = strdup (index);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
// FD IS OK HERE
|
||||
if (rs->path [strlen (rs->path) - 1] == '/') {
|
||||
path = r_str_append (path, "index.html");
|
||||
//rs->path = r_str_append (rs->path, "index.html");
|
||||
const char *index = r_config_get (core->config, "http.index");
|
||||
path = (*index == '/')? strdup (index): r_str_append (path, index);
|
||||
} else {
|
||||
//snprintf (path, sizeof (path), "%s/%s", root, rs->path);
|
||||
if (r_file_is_directory (path)) {
|
||||
|
|
Loading…
Reference in New Issue