]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add auth to xmlrpc
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 1 Jun 2006 17:16:15 +0000 (17:16 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 1 Jun 2006 17:16:15 +0000 (17:16 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1530 d0543943-73ff-0310-b7d9-9358b9ac24b2

conf/freeswitch.xml
src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c

index 426e149f53bfa778a73997ad2765c8d8be8408c7..3fe48e6311d2944e1fa8335bd6a6db55f0d82ef4 100644 (file)
       <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) -->
index ca67b60dc9f904bd073976cd4512c7065ada9599..787f55962ee0be7cde6c3741ba45e20ac3183144 100644 (file)
@@ -50,10 +50,16 @@ static struct {
        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;
@@ -138,7 +144,9 @@ static switch_status_t do_config(void)
 {
        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;
@@ -149,7 +157,13 @@ static switch_status_t do_config(void)
                        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);
@@ -162,7 +176,11 @@ static switch_status_t do_config(void)
        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;
@@ -214,12 +232,24 @@ static switch_status_t http_stream_write(switch_stream_handle_t *handle, char *f
        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;
        }
@@ -242,8 +272,6 @@ abyss_bool HandleHook(TSession *r)
        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;