<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13669">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">http: Add ability to disable /httpstatus URI<br><br>Add a new configuration option 'enable_status' which allows the<br>/httpstatus URI handler to be administratively disabled.<br><br>We also no longer unconditionally register the /static and /httpstatus<br>URI handlers, but instead do it based upon configuration.<br><br>Behavior change: If enable_static was turned off, the URI handler was<br>still installed but returned a 403 when it was accessed. Because we<br>know register/unregister the URI handlers as appropriate, if the<br>/static URI is diabled we will return a 404 instead.<br><br>Additionally:<br><br>* Change 'enablestatic' to 'enable_static' but keep the former for<br>  backwards compatability.<br>* Improve some internal variable names<br><br>ASTERISK-28710 #close<br><br>Change-Id: I647510f796473793b1d3ce1beb32659813be69e1<br>---<br>M configs/samples/http.conf.sample<br>M main/http.c<br>2 files changed, 49 insertions(+), 17 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/69/13669/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configs/samples/http.conf.sample b/configs/samples/http.conf.sample</span><br><span>index 342dff4..62ed642 100644</span><br><span>--- a/configs/samples/http.conf.sample</span><br><span>+++ b/configs/samples/http.conf.sample</span><br><span>@@ -1,5 +1,5 @@</span><br><span> ;</span><br><span style="color: hsl(0, 100%, 40%);">-; Asterisk Builtin mini-HTTP server</span><br><span style="color: hsl(120, 100%, 40%);">+; Asterisk Built-in mini-HTTP server</span><br><span> ;</span><br><span> ;</span><br><span> ; Note about Asterisk documentation:</span><br><span>@@ -65,7 +65,13 @@</span><br><span> ; Whether Asterisk should serve static content from static-http</span><br><span> ; Default is no.</span><br><span> ;</span><br><span style="color: hsl(0, 100%, 40%);">-;enablestatic=yes</span><br><span style="color: hsl(120, 100%, 40%);">+;enable_static=yes</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; Whether Asterisk should serve a status page showing the running</span><br><span style="color: hsl(120, 100%, 40%);">+; configuration of this built-in HTTP server.</span><br><span style="color: hsl(120, 100%, 40%);">+; Default is yes.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+;enable_status=no</span><br><span> ;</span><br><span> ; Redirect one URI to another.  This is how you would set a</span><br><span> ; default page.</span><br><span>diff --git a/main/http.c b/main/http.c</span><br><span>index 136c916..0600bfa 100644</span><br><span>--- a/main/http.c</span><br><span>+++ b/main/http.c</span><br><span>@@ -134,7 +134,8 @@</span><br><span> </span><br><span> /* all valid URIs must be prepended by the string in prefix. */</span><br><span> static char prefix[MAX_PREFIX];</span><br><span style="color: hsl(0, 100%, 40%);">-static int enablestatic;</span><br><span style="color: hsl(120, 100%, 40%);">+static int static_uri_enabled;</span><br><span style="color: hsl(120, 100%, 40%);">+static int status_uri_enabled;</span><br><span> </span><br><span> /*! \brief Limit the kinds of files we're willing to serve up */</span><br><span> static struct {</span><br><span>@@ -255,9 +256,13 @@</span><br><span>               return 0;</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   /* Yuck.  I'm not really sold on this, but if you don't deliver static content it makes your configuration</span><br><span style="color: hsl(0, 100%, 40%);">-         substantially more challenging, but this seems like a rather irritating feature creep on Asterisk. */</span><br><span style="color: hsl(0, 100%, 40%);">-        if (!enablestatic || ast_strlen_zero(uri)) {</span><br><span style="color: hsl(120, 100%, 40%);">+  /* Yuck.  I'm not really sold on this, but if you don't deliver static content it</span><br><span style="color: hsl(120, 100%, 40%);">+      * makes your configuration substantially more challenging, but this seems like a</span><br><span style="color: hsl(120, 100%, 40%);">+      * rather irritating feature creep on Asterisk.</span><br><span style="color: hsl(120, 100%, 40%);">+        *</span><br><span style="color: hsl(120, 100%, 40%);">+     * XXX: It is not clear to me what this comment means or if it is any longer</span><br><span style="color: hsl(120, 100%, 40%);">+   *      relevant. */</span><br><span style="color: hsl(120, 100%, 40%);">+  if (ast_strlen_zero(uri)) {</span><br><span>          goto out403;</span><br><span>         }</span><br><span> </span><br><span>@@ -408,7 +413,7 @@</span><br><span>  return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static struct ast_http_uri statusuri = {</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_http_uri status_uri = {</span><br><span>        .callback = httpstatus_callback,</span><br><span>     .description = "Asterisk HTTP General Status",</span><br><span>     .uri = "httpstatus",</span><br><span>@@ -417,7 +422,7 @@</span><br><span>         .key = __FILE__,</span><br><span> };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static struct ast_http_uri staticuri = {</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_http_uri static_uri = {</span><br><span>        .callback = static_callback,</span><br><span>         .description = "Asterisk HTTP Static Delivery",</span><br><span>    .uri = "static",</span><br><span>@@ -2095,8 +2100,9 @@</span><br><span> {</span><br><span>      struct ast_config *cfg;</span><br><span>      struct ast_variable *v;</span><br><span style="color: hsl(0, 100%, 40%);">- int enabled=0;</span><br><span style="color: hsl(0, 100%, 40%);">-  int newenablestatic=0;</span><br><span style="color: hsl(120, 100%, 40%);">+        int enabled = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+      int new_static_uri_enabled = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+       int new_status_uri_enabled = 1; /* Default to enabled for BC */</span><br><span>      char newprefix[MAX_PREFIX] = "";</span><br><span>   char server_name[MAX_SERVER_NAME_LENGTH];</span><br><span>    struct http_uri_redirect *redirect;</span><br><span>@@ -2174,8 +2180,10 @@</span><br><span>                         }</span><br><span>            } else if (!strcasecmp(v->name, "enabled")) {</span><br><span>                   enabled = ast_true(v->value);</span><br><span style="color: hsl(0, 100%, 40%);">-                } else if (!strcasecmp(v->name, "enablestatic")) {</span><br><span style="color: hsl(0, 100%, 40%);">-                 newenablestatic = ast_true(v->value);</span><br><span style="color: hsl(120, 100%, 40%);">+              } else if (!strcasecmp(v->name, "enablestatic") || !strcasecmp(v->name, "enable_static")) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 new_static_uri_enabled = ast_true(v->value);</span><br><span style="color: hsl(120, 100%, 40%);">+               } else if (!strcasecmp(v->name, "enable_status")) {</span><br><span style="color: hsl(120, 100%, 40%);">+                      new_status_uri_enabled = ast_true(v->value);</span><br><span>              } else if (!strcasecmp(v->name, "bindport")) {</span><br><span>                  if (ast_parse_arg(v->value, PARSE_UINT32 | PARSE_IN_RANGE | PARSE_DEFAULT,</span><br><span>                                &bindport, DEFAULT_PORT, 0, 65535)) {</span><br><span>@@ -2226,7 +2234,6 @@</span><br><span>    }</span><br><span> </span><br><span>        ast_copy_string(http_server_name, server_name, sizeof(http_server_name));</span><br><span style="color: hsl(0, 100%, 40%);">-       enablestatic = newenablestatic;</span><br><span> </span><br><span>  if (num_addrs && enabled) {</span><br><span>          int i;</span><br><span>@@ -2272,6 +2279,22 @@</span><br><span>              }</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (static_uri_enabled && !new_static_uri_enabled) {</span><br><span style="color: hsl(120, 100%, 40%);">+          ast_http_uri_unlink(&static_uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!static_uri_enabled && new_static_uri_enabled) {</span><br><span style="color: hsl(120, 100%, 40%);">+           ast_http_uri_link(&static_uri);</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   static_uri_enabled = new_static_uri_enabled;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        if (status_uri_enabled && !new_status_uri_enabled) {</span><br><span style="color: hsl(120, 100%, 40%);">+          ast_http_uri_unlink(&status_uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!status_uri_enabled && new_status_uri_enabled) {</span><br><span style="color: hsl(120, 100%, 40%);">+           ast_http_uri_link(&status_uri);</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   status_uri_enabled = new_status_uri_enabled;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>       return 0;</span><br><span> }</span><br><span> </span><br><span>@@ -2353,8 +2376,13 @@</span><br><span>  ast_free(http_tls_cfg.pvtfile);</span><br><span>      ast_free(http_tls_cfg.cipher);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-      ast_http_uri_unlink(&statusuri);</span><br><span style="color: hsl(0, 100%, 40%);">-    ast_http_uri_unlink(&staticuri);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (status_uri_enabled) {</span><br><span style="color: hsl(120, 100%, 40%);">+             ast_http_uri_unlink(&status_uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (static_uri_enabled) {</span><br><span style="color: hsl(120, 100%, 40%);">+             ast_http_uri_unlink(&static_uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span>        AST_RWLIST_WRLOCK(&uri_redirects);</span><br><span>       while ((redirect = AST_RWLIST_REMOVE_HEAD(&uri_redirects, entry))) {</span><br><span>@@ -2365,8 +2393,6 @@</span><br><span> </span><br><span> int ast_http_init(void)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-    ast_http_uri_link(&statusuri);</span><br><span style="color: hsl(0, 100%, 40%);">-      ast_http_uri_link(&staticuri);</span><br><span>   ast_cli_register_multiple(cli_http, ARRAY_LEN(cli_http));</span><br><span>    ast_register_cleanup(http_shutdown);</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13669">change 13669</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/13669"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I647510f796473793b1d3ce1beb32659813be69e1 </div>
<div style="display:none"> Gerrit-Change-Number: 13669 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>