add ip table command to allow acs for connection request

Signed-off-by: MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
This commit is contained in:
MOHAMED Kallel 2014-05-14 10:40:15 +01:00 committed by Strhuan Blomquist
parent e9c847b5bd
commit 6e62056466
6 changed files with 38 additions and 7 deletions

6
cwmp.c
View file

@ -442,20 +442,20 @@ int run_session_end_func (struct session *session)
if (session->end_session & END_SESSION_EXTERNAL_ACTION)
{
CWMP_LOG (INFO,"Executing external commands: end session request");
external_simple("end_session");
external_simple("end_session", NULL);
}
if (session->end_session & END_SESSION_FACTORY_RESET)
{
CWMP_LOG (INFO,"Executing factory reset: end session request");
external_simple("factory_reset");
external_simple("factory_reset", NULL);
exit(EXIT_SUCCESS);
}
if (session->end_session & END_SESSION_REBOOT)
{
CWMP_LOG (INFO,"Executing Reboot: end session request");
external_simple("reboot");
external_simple("reboot", NULL);
exit(EXIT_SUCCESS);
}

View file

@ -339,7 +339,7 @@ int external_object_action(char *command, char *name)
return 0;
}
int external_simple(char *command)
int external_simple(char *command, char *arg)
{
DD(INFO,"executing %s request", command);
@ -349,6 +349,7 @@ int external_simple(char *command)
json_obj_out = json_object_new_object();
json_obj_out_add(json_obj_out, "command", command);
if (arg) json_obj_out_add(json_obj_out, "arg", arg);
external_write_pipe_output(json_object_to_json_string(json_obj_out));

14
http.c
View file

@ -158,6 +158,8 @@ http_send_message(struct cwmp *cwmp, char *msg_out, char **msg_in)
#ifdef HTTP_CURL
CURLcode res;
long http_code = 0;
static char *ip_acs = NULL;
char *ip = NULL;
curl_easy_setopt(curl, CURLOPT_URL, http_c.url);
curl_easy_setopt(curl, CURLOPT_USERNAME, cwmp->conf.acs_userid);
curl_easy_setopt(curl, CURLOPT_PASSWORD, cwmp->conf.acs_passwd);
@ -165,6 +167,7 @@ http_send_message(struct cwmp *cwmp, char *msg_out, char **msg_in)
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_c.header_list);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, HTTP_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, HTTP_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, msg_out);
if (msg_out)
@ -191,7 +194,16 @@ http_send_message(struct cwmp *cwmp, char *msg_out, char **msg_in)
if (!strlen(*msg_in))
FREE(*msg_in);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip);
if (ip) {
if (!ip_acs || strcmp(ip_acs, ip) != 0) {
FREE(ip_acs);
ip_acs = strdup(ip);
external_simple("allow_cr_ip", ip_acs);
}
}
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
if(http_code == 204)
{

View file

@ -38,7 +38,7 @@ void external_fetch_delObjectResp (char **status, char **fault);
int external_get_action(char *action, char *name, char *next_level);
int external_set_action(char *action, char *name, char *value, char *change);
int external_object_action(char *command, char *name);
int external_simple(char *command);
int external_simple(char *command, char *arg);
int external_download(char *url, char *size, char *type, char *user, char *pass);
int external_apply(char *action, char *type);
int external_handle_action(int (*external_handler)(char *msg));

View file

@ -150,6 +150,10 @@ case "$1" in
end_session)
action="end_session"
;;
allow_cr_ip)
action="allow_cr_ip"
__arg1="$2"
;;
json_continuous_input)
action="json_continuous_input"
;;
@ -611,6 +615,16 @@ handle_action() {
/bin/sh /tmp/end_session.sh
fi
if [ "$action" = "allow_cr_ip" ]; then
local port=`$UCI_GET cwmp.cpe.port`
local if_wan=`$UCI_GET cwmp.cpe.default_wan_interface`
[ "$if_wan" = "" ] && return
local zone=`$UCI_SHOW firewall | grep "firewall\.@zone\[[0-9]\+\]\.network=.*$if_wan" | head -1 | cut -f2 -d.`
[ "$if_wan" = "" ] && return
local zone_name=`$UCI_GET firewall.$zone.name`
iptables -I $zone_name -p tcp -s $__arg1 --dport $port -j ACCEPT
fi
if [ "$action" = "json_continuous_input" ]; then
echo "EOF"
while read CMD; do
@ -696,6 +710,10 @@ handle_action() {
end_session)
action="end_session"
;;
allow_cr_ip)
action="allow_cr_ip"
json_get_var __arg1 arg
;;
end)
echo "EOF"
;;

2
xml.c
View file

@ -549,7 +549,7 @@ int cwmp_rpc_acs_prepare_message_inform (struct cwmp *cwmp, struct session *sess
}
}
external_simple("inform");
external_simple("inform", NULL);
external_handle_action(cwmp_handle_getParamValues);