<settings>
<!-- The port where you want to run the http service (default 8080) -->
<param name="http-port" value="8080"/>
+ <!-- if all 3 of the following params exist all http traffic will require auth -->
+ <param name="auth-realm" value="freeswitch"/>
+ <param name="auth-user" value="freeswitch"/>
+ <param name="auth-pass" value="works"/>
<!-- The url to a gateway cgi that can generate xml similar to
what's in this file only on-the-fly (leave it commented if you dont
need it) -->
uint8_t running;
char *url;
char *bindings;
+ char *realm;
+ char *user;
+ char *pass;
} globals;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_url, globals.url);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_realm, globals.realm);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_user, globals.user);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass);
struct config_data {
char *name;
{
char *cf = "xml_rpc.conf";
switch_xml_t cfg, xml, settings, param;
-
+ char *realm, *user, *pass;
+
+ realm = user = pass = NULL;
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
- if (!strcasecmp(var, "gateway-url")) {
+ if (!strcasecmp(var, "auth-realm")) {
+ realm = val;
+ } else if (!strcasecmp(var, "auth-user")) {
+ user = val;
+ } else if (!strcasecmp(var, "auth-pass")) {
+ pass = val;
+ } else if (!strcasecmp(var, "gateway-url")) {
char *bindings = (char *) switch_xml_attr_soft(param, "bindings");
set_global_bindings(bindings);
set_global_url(val);
if (!globals.port) {
globals.port = 8080;
}
-
+ if (user && pass && realm) {
+ set_global_realm(realm);
+ set_global_user(user);
+ set_global_pass(pass);
+ }
switch_xml_free(xml);
return globals.url ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
+
abyss_bool HandleHook(TSession *r)
{
char *m = "text/html";
switch_stream_handle_t stream = {0};
char *command;
+ stream.data = r;
+ stream.write_function = http_stream_write;
+
+ if (globals.realm) {
+ if (!RequestAuth(r,globals.realm, globals.user, globals.pass)) {
+ return TRUE;
+ }
+ }
+
+
+
if(strncmp(r->uri, "/api/", 5)) {
return FALSE;
}
ResponseStatus(r,200);
ResponseContentType(r, m);
ResponseWrite(r);
- stream.data = r;
- stream.write_function = http_stream_write;
switch_api_execute(command, r->query, &stream);
HTTPWriteEnd(r);
return TRUE;