<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13681">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><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>now register/unregister the URI handlers as appropriate, if the<br>/static URI is disabled we will return a 404 instead.<br><br>Additionally:<br><br>* Change 'enablestatic' to 'enable_static' but keep the former for<br> backwards compatibility.<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>A doc/CHANGES-staging/http.txt<br>M main/http.c<br>3 files changed, 53 insertions(+), 17 deletions(-)<br><br></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 28437b0..1920a1c 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/doc/CHANGES-staging/http.txt b/doc/CHANGES-staging/http.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..ad778ec</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/http.txt</span><br><span>@@ -0,0 +1,4 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: http</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+You can now disable the /httpstatus page served by Asterisk's built-in</span><br><span style="color: hsl(120, 100%, 40%);">+HTTP server by setting 'enable_status' to 'no' in http.conf.</span><br><span>diff --git a/main/http.c b/main/http.c</span><br><span>index e27f2ce..3088552 100644</span><br><span>--- a/main/http.c</span><br><span>+++ b/main/http.c</span><br><span>@@ -139,7 +139,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>@@ -260,9 +261,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>@@ -413,7 +418,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>@@ -422,7 +427,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>@@ -2071,8 +2076,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>@@ -2150,8 +2156,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>@@ -2202,7 +2210,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>@@ -2248,6 +2255,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>@@ -2329,8 +2352,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>@@ -2343,8 +2371,6 @@</span><br><span> </span><br><span> static int load_module(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> </span><br><span> return __ast_http_load(0) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13681">change 13681</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/+/13681"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 17 </div>
<div style="display:none"> Gerrit-Change-Id: I647510f796473793b1d3ce1beb32659813be69e1 </div>
<div style="display:none"> Gerrit-Change-Number: 13681 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>