Add webcontrol_base_path

Co-authored-by: Gareth <g01z@yahoo.co.uk>
Co-authored-by: Mr-Dave <MotionMrDave@gmail.com>
This commit is contained in:
Mr-Dave
2022-04-14 20:44:24 -06:00
parent d1d7401488
commit 3d7ce0d49f
4 changed files with 82 additions and 17 deletions

View File

@@ -1245,6 +1245,12 @@
<td align="left"></td>
<td align="left"><a href="#webcontrol_port" >webcontrol_port</a></td>
</tr>
<tr>
<td align="left"><br /></td>
<td align="left"></td>
<td align="left"></td>
<td align="left"><a href="#webcontrol_base_path" >webcontrol_base_path</a></td>
</tr>
<tr>
<td align="left"><br /></td>
<td align="left"></td>
@@ -1611,6 +1617,7 @@
</tr>
<tr>
<td bgcolor="#edf4f9" ><a href="#webcontrol_html" >webcontrol_html</a> </td>
<td bgcolor="#edf4f9" ><a href="#webcontrol_base_path" >webcontrol_base_path</a> </td>
</tr>
</tbody>
</table>
@@ -3632,6 +3639,18 @@
placed in motionplus.conf and not in a camera config file.
<p></p>
<h3><a name="webcontrol_base_path"></a> webcontrol_base_path </h3>
<p></p>
<ul>
<li> Type: String</li>
<li> Valid values: Valid url path</li>
<li> Default: </li>
</ul>
<p></p>
Change the base path for the web UI. This option must be placed in motionplus.conf
and not in a camera config file.
<p></p>
<h3><a name="webcontrol_parms"></a> webcontrol_parms </h3>
<p></p>
<ul>

View File

@@ -151,6 +151,7 @@ struct ctx_parm config_parms[] = {
{"video_pipe_motion", PARM_TYP_STRING, PARM_CAT_12, WEBUI_LEVEL_LIMITED },
{"webcontrol_port", PARM_TYP_INT, PARM_CAT_13, WEBUI_LEVEL_ADVANCED },
{"webcontrol_base_path", PARM_TYP_STRING, PARM_CAT_13, WEBUI_LEVEL_ADVANCED },
{"webcontrol_ipv6", PARM_TYP_BOOL, PARM_CAT_13, WEBUI_LEVEL_ADVANCED },
{"webcontrol_localhost", PARM_TYP_BOOL, PARM_CAT_13, WEBUI_LEVEL_ADVANCED },
{"webcontrol_parms", PARM_TYP_LIST, PARM_CAT_13, WEBUI_LEVEL_NEVER},
@@ -2112,6 +2113,33 @@ static void conf_edit_webcontrol_port(struct ctx_cam *cam, std::string &parm, en
MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO,"%s:%s","webcontrol_port",_("webcontrol_port"));
}
static void conf_edit_webcontrol_base_path(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact)
{
if (pact == PARM_ACT_DFLT) {
cam->conf->webcontrol_base_path = "";
} else if (pact == PARM_ACT_SET) {
if (parm == "/") {
MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO
, _("Invalid webcontrol_base_path: Use blank instead of single / "));
cam->conf->webcontrol_base_path = "";
} else if (parm.length() >= 1) {
if (parm.substr(0, 1) != "/") {
MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO
, _("Invalid webcontrol_base_path: Must start with a / "));
cam->conf->webcontrol_base_path = "/" + parm;
} else {
cam->conf->webcontrol_base_path = parm;
}
} else {
cam->conf->webcontrol_base_path = parm;
}
} else if (pact == PARM_ACT_GET) {
parm = cam->conf->webcontrol_base_path;
}
return;
MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO,"%s:%s","webcontrol_base_path",_("webcontrol_base_path"));
}
static void conf_edit_webcontrol_ipv6(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact)
{
if (pact == PARM_ACT_DFLT) {
@@ -2991,6 +3019,7 @@ static void conf_edit_cat13(struct ctx_cam *cam, std::string parm_nm
, std::string &parm_val, enum PARM_ACT pact)
{
if (parm_nm == "webcontrol_port") { conf_edit_webcontrol_port(cam, parm_val, pact);
} else if (parm_nm == "webcontrol_base_path") { conf_edit_webcontrol_base_path(cam, parm_val, pact);
} else if (parm_nm == "webcontrol_ipv6") { conf_edit_webcontrol_ipv6(cam, parm_val, pact);
} else if (parm_nm == "webcontrol_localhost") { conf_edit_webcontrol_localhost(cam, parm_val, pact);
} else if (parm_nm == "webcontrol_parms") { conf_edit_webcontrol_parms(cam, parm_val, pact);

View File

@@ -141,6 +141,7 @@
/* Webcontrol configuration parameters */
int webcontrol_port;
std::string webcontrol_base_path;
bool webcontrol_ipv6;
bool webcontrol_localhost;
int webcontrol_parms;

View File

@@ -204,7 +204,7 @@ static void webu_parms_edit(struct ctx_webui *webui)
static int webu_parseurl(struct ctx_webui *webui)
{
char *tmpurl;
size_t pos_slash1, pos_slash2;
size_t pos_slash1, pos_slash2, baselen;
/* Example: /camid/cmd1/cmd2/cmd3 */
webui->uri_camid = "";
@@ -212,14 +212,6 @@ static int webu_parseurl(struct ctx_webui *webui)
webui->uri_cmd2 = "";
webui->uri_cmd3 = "";
if (webui->url.length() == 0) {
return -1;
}
if (webui->url == "/favicon.ico") {
return -1;
}
MOTION_LOG(DBG, TYPE_STREAM, NO_ERRNO, _("Sent url: %s"),webui->url.c_str());
tmpurl = (char*)mymalloc(webui->url.length()+1);
@@ -232,20 +224,39 @@ static int webu_parseurl(struct ctx_webui *webui)
MOTION_LOG(DBG, TYPE_STREAM, NO_ERRNO, _("Decoded url: %s"),webui->url.c_str());
if (webui->url.length() == 1) {
baselen = webui->motapp->cam_list[0]->conf->webcontrol_base_path.length();
if (webui->url.length() < baselen) {
return -1;
}
if (webui->url.substr(baselen) == "/favicon.ico") {
return -1;
}
if (webui->url.substr(0, baselen) !=
webui->motapp->cam_list[0]->conf->webcontrol_base_path) {
return -1;
}
if (webui->url == "/") {
return 0;
}
/* Remove any trailing slash */
/* Remove any trailing slash to keep parms clean */
if (webui->url.substr(webui->url.length()-1,1) == "/") {
webui->url = webui->url.substr(0, webui->url.length()-1);
}
pos_slash1 = webui->url.find("/", 1);
if (webui->url.length() == baselen) {
return 0;
}
pos_slash1 = webui->url.find("/", baselen+1);
if (pos_slash1 != std::string::npos) {
webui->uri_camid = webui->url.substr(1, pos_slash1 - 1);
webui->uri_camid = webui->url.substr(baselen+1, pos_slash1-baselen- 1);
} else {
webui->uri_camid = webui->url.substr(1);
webui->uri_camid = webui->url.substr(baselen+1);
return 0;
}
@@ -276,7 +287,7 @@ static int webu_parseurl(struct ctx_webui *webui)
if (pos_slash2 != std::string::npos) {
webui->uri_cmd2 = webui->url.substr(pos_slash1, pos_slash2 - pos_slash1);
} else {
webui->uri_cmd1 = webui->url.substr(pos_slash1);
webui->uri_cmd2 = webui->url.substr(pos_slash1);
return 0;
}
@@ -336,9 +347,12 @@ static void webu_hostname(struct ctx_webui *webui)
hdr = MHD_lookup_connection_value(webui->connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_HOST);
if (hdr == NULL) {
webui->hostfull = "//localhost:" + std::to_string(webui->motapp->cam_list[0]->conf->webcontrol_port);
webui->hostfull = "//localhost:" +
std::to_string(webui->motapp->cam_list[0]->conf->webcontrol_port) +
webui->motapp->cam_list[0]->conf->webcontrol_base_path;
} else {
webui->hostfull = "//" + std::string(hdr);
webui->hostfull = "//" + std::string(hdr) +
webui->motapp->cam_list[0]->conf->webcontrol_base_path;
}
MOTION_LOG(DBG,TYPE_ALL, NO_ERRNO, _("Full Host: %s"), webui->hostfull.c_str());
@@ -994,6 +1008,8 @@ static void *webu_mhd_init(void *cls, const char *uri, struct MHD_Connection *co
if (retcd != 0) {
webui->uri_camid = "";
webui->uri_cmd1 = "";
webui->uri_cmd2 = "";
webui->uri_cmd3 = "";
webui->url = "";
}