dect
/
asterisk
Archived
13
0
Fork 0

Update res_phoneprov to default to setting the SERVER variable to the IP

the HTTP request for the config came in on and the SERVER_PORT to the
bindport setting in sip.conf.  I've left in the ability to override these
options, because I can't always guess how someone might decide to do something
weird with what is available to them--although needing to is pretty unlikely.

Documentation was updated to reflect preference for not setting serveraddr,
serveriface, or serverport.  Tested on Linux and OS X.


git-svn-id: http://svn.digium.com/svn/asterisk/trunk@98988 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
twilson 2008-01-17 03:09:32 +00:00
parent 507fd79b11
commit 7918f534be
3 changed files with 69 additions and 35 deletions

View File

@ -1,9 +1,14 @@
[general]
;serveraddr=192.168.1.1 ; Address to send to the phone to use as server address.
serveriface=eth0 ; Same as above, except an ethernet interface.
; Useful for when the interface uses DHCP.
; There is no default for either of the above, and only one should be set.
serverport=5060 ; Port to send to the phone to use as server port. Default is 5060.
; The default behavior of res_phoneprov will be to set the SERVER template variable to
; the IP address that the phone uses to contact the provisioning server and the
; SERVER_PORT variable to the bindport setting in sip.conf. Unless you have a very
; unusual setup, you should not need to set serveraddr, serveriface, or serverport.
;serveraddr=192.168.1.1 ; Override address to send to the phone to use as server address.
;serveriface=eth0 ; Same as above, except an ethernet interface.
; Useful for when the interface uses DHCP and the asterisk http
; server listens on a different IP than chan_sip.
;serverport=5060 ; Override port to send to the phone to use as server port.
default_profile=polycom ; The default profile to use if none specified in users.conf
; You can define profiles for different phones specifying what files to register

View File

@ -21,20 +21,26 @@ Below is a sample of the general section of \path{phoneprov.conf}:
\begin{verbatim}
[general]
;serveriface=eth0
serveraddr=192.168.1.1
serverport=5060
;serveraddr=192.168.1.1
;serverport=5060
default_profile=polycom
\end{verbatim}
\end{astlisting}
There are two choices for setting the SERVER variable. If the IP address of the server is
known, or the hostname resolvable by the phones, the appropriate \textbf{serveraddr}
value should be set. Alternatively, the network interface that the server listens on can
be set by specifying a \textbf{serveriface} and SERVER will be set to the IP address of
that interface. Only one of these options should be set.
By default, res\_phoneprov will set the SERVER variable to the IP address on the server
that the requesting phone uses to contact the asterisk HTTP server. The SERVER\_PORT
variable will default to the \textbf{bindport} setting in sip.conf.
The SERVER\_PORT variable is set by setting the \textbf{serverport}. If serverport is
not specified, it is set to a default value of 5060.
Should the defaults be insufficient, there are two choices for overriding the default
setting of the SERVER variable. If the IP address of the server is known, or the hostname
resolvable by the phones, the appropriate \textbf{serveraddr} value should be set.
Alternatively, the network interface that the server listens on can be set by specifying a
\textbf{serveriface} and SERVER will be set to the IP address of that interface. Only one
of these options should be set.
The default SERVER\_PORT variable can be overridden by setting the \textbf{serverport}.
If \textbf{bindport} is not set in \path{sip.conf} and serverport is not specified, it
is set to a default value of 5060.
Any user set for auto-provisioning in users.conf without a specified profile will be
assumed to belong to the profile set with \textbf{default\_profile}.

View File

@ -153,7 +153,7 @@ static struct {
};
char global_server[80] = ""; /*!< Server to substitute into templates */
char global_serverport[6] = "5060"; /*!< Server port to substitute into templates */
char global_serverport[6] = ""; /*!< Server port to substitute into templates */
char global_default_profile[80] = ""; /*!< Default profile to use if one isn't specified */
/*! \brief List of global variables currently available: VOICEMAIL_EXTEN, EXTENSION_LENGTH */
@ -397,6 +397,23 @@ static struct ast_str *phoneprov_callback(struct server_instance *ser, const cha
goto out500;
}
/* Unless we are overridden by serveriface or serveraddr, we set the SERVER variable to
* the IP address we are listening on that the phone contacted for this config file */
if (ast_strlen_zero(global_server)) {
struct sockaddr name;
socklen_t namelen = sizeof(name);
int res;
if ((res = getsockname(ser->fd, &name, &namelen)))
ast_log(LOG_WARNING, "Could not get server IP, breakage likely.\n");
else {
struct ast_var_t *var;
if ((var = ast_var_assign("SERVER", ast_inet_ntoa(((struct sockaddr_in *)&name)->sin_addr))))
AST_LIST_INSERT_TAIL(route->user->headp, var, entries);
}
}
pbx_substitute_variables_varshead(route->user->headp, file, tmp, bufsize);
if (file)
@ -698,10 +715,11 @@ static struct user *build_user(struct ast_config *cfg, const char *name, const c
if (!ast_strlen_zero(global_server)) {
if ((var = ast_var_assign("SERVER", global_server)))
AST_LIST_INSERT_TAIL(user->headp, var, entries);
if (!ast_strlen_zero(global_serverport)) {
if ((var = ast_var_assign("SERVER_PORT", global_serverport)))
AST_LIST_INSERT_TAIL(user->headp, var, entries);
}
}
if (!ast_strlen_zero(global_serverport)) {
if ((var = ast_var_assign("SERVER_PORT", global_serverport)))
AST_LIST_INSERT_TAIL(user->headp, var, entries);
}
/* Append profile variables here, and substitute variables on profile
@ -736,20 +754,27 @@ static int build_user_routes(struct user *user)
/* \brief Parse config files and create appropriate structures */
static int set_config(void)
{
struct ast_config *phoneprov_cfg, *users_cfg;
struct ast_config *cfg;
char *cat;
struct ast_variable *v;
struct ast_flags config_flags = { 0 };
if (!(phoneprov_cfg = ast_config_load("phoneprov.conf", config_flags))) {
/* Try to grab the port from sip.conf. If we don't get it here, we'll set it
* to whatever is set in phoneprov.conf or default to 5060 */
if ((cfg = ast_config_load("sip.conf", config_flags))) {
ast_copy_string(global_serverport, S_OR(ast_variable_retrieve(cfg, "general", "bindport"), "5060"), sizeof(global_serverport));
ast_config_destroy(cfg);
}
if (!(cfg = ast_config_load("phoneprov.conf", config_flags))) {
ast_log(LOG_ERROR, "Unable to load config phoneprov.conf\n");
return -1;
}
cat = NULL;
while ((cat = ast_category_browse(phoneprov_cfg, cat))) {
while ((cat = ast_category_browse(cfg, cat))) {
if (!strcasecmp(cat, "general")) {
for (v = ast_variable_browse(phoneprov_cfg, cat); v; v = v->next) {
for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
if (!strcasecmp(v->name, "serveraddr"))
ast_copy_string(global_server, v->value, sizeof(global_server));
else if (!strcasecmp(v->name, "serveriface")) {
@ -761,28 +786,26 @@ static int set_config(void)
else if (!strcasecmp(v->name, "default_profile"))
ast_copy_string(global_default_profile, v->value, sizeof(global_default_profile));
}
if (ast_strlen_zero(global_server))
ast_log(LOG_WARNING, "No serveraddr/serveriface set in phoneprov.conf. Breakage likely.\n");
} else
build_profile(cat, ast_variable_browse(phoneprov_cfg, cat));
build_profile(cat, ast_variable_browse(cfg, cat));
}
ast_config_destroy(phoneprov_cfg);
ast_config_destroy(cfg);
if (!(users_cfg = ast_config_load("users.conf", config_flags))) {
if (!(cfg = ast_config_load("users.conf", config_flags))) {
ast_log(LOG_WARNING, "Unable to load users.cfg\n");
return 0;
}
cat = NULL;
while ((cat = ast_category_browse(users_cfg, cat))) {
while ((cat = ast_category_browse(cfg, cat))) {
const char *tmp, *mac;
struct user *user;
struct phone_profile *profile;
struct ast_var_t *var;
if (!strcasecmp(cat, "general")) {
for (v = ast_variable_browse(users_cfg, cat); v; v = v->next) {
for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
if (!strcasecmp(v->name, "vmexten")) {
if ((var = ast_var_assign("VOICEMAIL_EXTEN", v->value)))
AST_LIST_INSERT_TAIL(&global_variables, var, entries);
@ -797,15 +820,15 @@ static int set_config(void)
if (!strcasecmp(cat, "authentication"))
continue;
if (!((tmp = ast_variable_retrieve(users_cfg, cat, "autoprov")) && ast_true(tmp)))
if (!((tmp = ast_variable_retrieve(cfg, cat, "autoprov")) && ast_true(tmp)))
continue;
if (!(mac = ast_variable_retrieve(users_cfg, cat, "macaddress"))) {
if (!(mac = ast_variable_retrieve(cfg, cat, "macaddress"))) {
ast_log(LOG_WARNING, "autoprov set for %s, but no mac address - skipping.\n", cat);
continue;
}
tmp = S_OR(ast_variable_retrieve(users_cfg, cat, "profile"), global_default_profile);
tmp = S_OR(ast_variable_retrieve(cfg, cat, "profile"), global_default_profile);
if (ast_strlen_zero(tmp)) {
ast_log(LOG_WARNING, "No profile for user [%s] with mac '%s' - skipping\n", cat, mac);
continue;
@ -816,7 +839,7 @@ static int set_config(void)
continue;
}
if (!(user = build_user(users_cfg, cat, mac, profile))) {
if (!(user = build_user(cfg, cat, mac, profile))) {
ast_log(LOG_WARNING, "Could not create user %s - skipping.\n", cat);
continue;
}
@ -832,7 +855,7 @@ static int set_config(void)
AST_RWLIST_UNLOCK(&users);
}
ast_config_destroy(users_cfg);
ast_config_destroy(cfg);
return 0;
}