Esempio n. 1
0
static void loadconfigurationfile(void)
{
	char *cat;
	struct cw_config *cfg;
	struct cw_variable *v;
	
	cfg = cw_config_load(CONF_FILE);
	if (!cfg) {
		/* Standard configuration */
		enablecdr = 0;
		return;
	}
	
	cat = cw_category_browse(cfg, NULL);
	while (cat) {
		if (!strcasecmp(cat, "general")) {
			v = cw_variable_browse(cfg, cat);
			while (v) {
				if (!strcasecmp(v->name, "enabled")) {
					enablecdr = cw_true(v->value);
				}
				
				v = v->next;
			}
		}
	
		/* Next category */
		cat = cw_category_browse(cfg, cat);
	}
	
	cw_config_destroy(cfg);
}
Esempio n. 2
0
static int config_load(void)
{
	struct cw_config *cfg;
	char *cat;
	struct osp_provider *osp, *prev = NULL, *next;
	cw_mutex_lock(&osplock);
	osp = providers;
	while(osp) {
		osp->dead = 1;
		osp = osp->next;
	}
	cw_mutex_unlock(&osplock);
	cfg = cw_config_load("osp.conf");
	if (cfg) {
		if (!initialized) {
			cat = cw_variable_retrieve(cfg, "general", "accelerate");
			if (cat && cw_true(cat))
				if (OSPPInit(1)) {
					cw_log(LOG_WARNING, "Failed to enable hardware accelleration, falling back to software mode\n");
					OSPPInit(0);
				} else
					hardware = 1;
			else
				OSPPInit(0);
			initialized = 1;
		}
		cat = cw_variable_retrieve(cfg, "general", "tokenformat");
		if (cat) {
			if ((sscanf(cat, "%d", &tokenformat) != 1) || (tokenformat < TOKEN_ALGO_SIGNED) || (tokenformat > TOKEN_ALGO_BOTH)) {
				tokenformat = TOKEN_ALGO_SIGNED;
				cw_log(LOG_WARNING, "tokenformat should be an integer from 0 to 2, not '%s'\n", cat);
			}
		}
		cat = cw_category_browse(cfg, NULL);
		while(cat) {
			if (strcasecmp(cat, "general"))
				osp_build(cfg, cat);
			cat = cw_category_browse(cfg, cat);
		}
		cw_config_destroy(cfg);
	} else
		cw_log(LOG_NOTICE, "No OSP configuration found.  OSP support disabled\n");
	cw_mutex_lock(&osplock);
	osp = providers;
	while(osp) {
		next = osp->next;
		if (osp->dead) {
			if (prev)
				prev->next = next;
			else
				providers = next;
			/* XXX Cleanup OSP structure first XXX */
			free(osp);
		} else 
			prev = osp;
		osp = next;
	}
	cw_mutex_unlock(&osplock);
	return 0;
}
Esempio n. 3
0
static struct cw_config *realtime_directory(char *context)
{
	struct cw_config *cfg;
	struct cw_config *rtdata;
	struct cw_category *cat;
	struct cw_variable *var;
	char *mailbox;
	char *fullname;
	char *hidefromdir;
	char tmp[100];

	/* Load flat file config. */
	cfg = cw_config_load(VOICEMAIL_CONFIG);

	if (!cfg) {
		/* Loading config failed. */
		cw_log(LOG_WARNING, "Loading config failed.\n");
		return NULL;
	}

	/* Get realtime entries, categorized by their mailbox number
	   and present in the requested context */
	rtdata = cw_load_realtime_multientry("voicemail", "mailbox LIKE", "%", "context", context, NULL);

	/* if there are no results, just return the entries from the config file */
	if (!rtdata)
		return cfg;

	/* Does the context exist within the config file? If not, make one */
	cat = cw_category_get(cfg, context);
	if (!cat) {
		cat = cw_category_new(context);
		if (!cat) {
			cw_log(LOG_WARNING, "Out of memory\n");
			cw_config_destroy(cfg);
			return NULL;
		}
		cw_category_append(cfg, cat);
	}

	mailbox = cw_category_browse(rtdata, NULL);
	while (mailbox) {
		fullname = cw_variable_retrieve(rtdata, mailbox, "fullname");
		hidefromdir = cw_variable_retrieve(rtdata, mailbox, "hidefromdir");
		snprintf(tmp, sizeof(tmp), "no-password,%s,hidefromdir=%s",
			 fullname ? fullname : "",
			 hidefromdir ? hidefromdir : "no");
		var = cw_variable_new(mailbox, tmp);
		if (var)
			cw_variable_append(cat, var);
		else
			cw_log(LOG_WARNING, "Out of memory adding mailbox '%s'\n", mailbox);
		mailbox = cw_category_browse(rtdata, mailbox);
	}
	cw_config_destroy(rtdata);

	return cfg;
}
Esempio n. 4
0
static int load_config(void)
{
	struct cw_variable *var;
	struct cw_config *cfg;
	char *cat;

	res_snmp_enabled = 0;
	res_snmp_agentx_subagent = 1;
	cfg = cw_config_load("res_snmp.conf");
	if (!cfg) {
		cw_log(LOG_WARNING, "Could not load res_snmp.conf\n");
		return 0;
	}
	cat = cw_category_browse(cfg, NULL);
	while (cat) {
		var = cw_variable_browse(cfg, cat);

		if (strcasecmp(cat, "general") == 0) {
			while (var) {
				if (strcasecmp(var->name, "subagent") == 0) {
					if (cw_true(var->value))
						res_snmp_agentx_subagent = 1;
					else if (cw_false(var->value))
						res_snmp_agentx_subagent = 0;
					else {
						cw_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value);
						cw_config_destroy(cfg);
						return 1;
					}
				} else if (strcasecmp(var->name, "enabled") == 0) {
					res_snmp_enabled = cw_true(var->value);
				} else {
					cw_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat);
					cw_config_destroy(cfg);
					return 1;
				}
				var = var->next;
			}
		} else {
			cw_log(LOG_ERROR, "Unrecognized category '%s'\n", cat);
			cw_config_destroy(cfg);
			return 1;
		}

		cat = cw_category_browse(cfg, cat);
	}
	cw_config_destroy(cfg);
	return 1;
}
Esempio n. 5
0
static void cw_db_load_config(void)
{
#ifdef HAVE_MEMCACHE
    struct cw_config *cfg;
    char *s;
    int disabled = 0;

    db_server_host = NULL;
    db_server_port = NULL;
    db_cache_lifetime = 0;

    if ((cfg = cw_config_load("db-memcached.conf")))
    {

        if ((s = cw_variable_retrieve(cfg, "memcache", "enabled")))
        {
            if (cw_false(s)) {
                cw_log(LOG_DEBUG,"Memcache server is disabled by configuration.\n");
                disabled = 1;
                return;
            }
        }

        if ((s = cw_variable_retrieve(cfg, "memcache", "server_host")))
        {
            cw_log(LOG_DEBUG,"Memcache server host is %s\n",s);
            db_server_host = strdup(s);
        }

        if ((s = cw_variable_retrieve(cfg, "memcache", "server_port")))
        {
            cw_log(LOG_DEBUG,"Memcache server port is %s\n",s);
            db_server_port = strdup(s);
        }

        if ((s = cw_variable_retrieve(cfg, "memcache", "cache_lifetime")))
        {
            cw_log(LOG_DEBUG,"Memcache server cache lifetime is %s\n",s);
            db_cache_lifetime = atoi(s);
        }

        cw_config_destroy(cfg);
    }
#endif
}
Esempio n. 6
0
static void parse_config(void)
{
    struct cw_config *cfg;
    struct cw_variable *var;
  
    if ((cfg = cw_config_load("codecs.conf")))
    {
        if ((var = cw_variable_browse(cfg, "plc")))
        {
            while (var)
            {
                if (!strcasecmp(var->name, "genericplc"))
                {
                    useplc = cw_true(var->value) ? 1 : 0;
                    if (option_verbose > 2)
                        cw_verbose(VERBOSE_PREFIX_3 "codec_g722: %susing generic PLC\n", useplc  ?  ""  :  "not ");
                }
                var = var->next;
            }
        }
        cw_config_destroy(cfg);
    }
}
Esempio n. 7
0
static int load_config(int reload) 
{
	struct cw_config *cfg;
	struct cw_variable *var;
	int res = -1;

	strcpy(format, "");
	strcpy(master, "");
	if((cfg = cw_config_load("cdr_custom.conf"))) {
		var = cw_variable_browse(cfg, "mappings");
		while(var) {
			cw_mutex_lock(&lock);
			if (!cw_strlen_zero(var->name) && !cw_strlen_zero(var->value)) {
				if (strlen(var->value) > (sizeof(format) - 2))
					cw_log(LOG_WARNING, "Format string too long, will be truncated, at line %d\n", var->lineno);
				strncpy(format, var->value, sizeof(format) - 2);
				strcat(format,"\n");
				snprintf(master, sizeof(master),"%s/%s/%s", cw_config_CW_LOG_DIR, name, var->name);
				cw_mutex_unlock(&lock);
			} else
				cw_log(LOG_NOTICE, "Mapping must have both filename and format at line %d\n", var->lineno);
			if (var->next)
				cw_log(LOG_NOTICE, "Sorry, only one mapping is supported at this time, mapping '%s' will be ignored at line %d.\n", var->next->name, var->next->lineno); 
			var = var->next;
		}
		cw_config_destroy(cfg);
		res = 0;
	} else {
		if (reload)
			cw_log(LOG_WARNING, "Failed to reload configuration file.\n");
		else
			cw_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
	}
	
	return res;
}
Esempio n. 8
0
static int ldap_exec(struct cw_channel *chan, int argc, char **argv)
{
	char result[2048];
	struct localuser *u;
	char *varname, *config, *keys = NULL, *key = NULL, *tail = NULL;
	char *result_conv;
	struct cw_config *cfg;

	int port = LDAP_PORT, version = LDAP_VERSION2, timeout = 10;
	char *temp, *host, *user, *pass, *base, *scope, *filter, *_filter, *attribute,
		 *convert_from = NULL, *convert_to = NULL;

	if (argc != 1) {
		cw_log(LOG_ERROR, "Syntax: %s\n", g_syntax);
		pbx_builtin_setvar_helper(chan, "LDAPSTATUS", "FAILURE");
		return 0;
	}

	LOCAL_USER_ADD(u);

	if (strchr(argv[0], '=')) {
		varname = strsep (&argv[0], "=");
		if (strchr(argv[0], '/')) {
			config = strsep(&argv[0], "/");
			keys = strsep(&argv[0], "\0");
			if (option_verbose > 2)
				cw_verbose(VERBOSE_PREFIX_3 "LDAPget: varname=%s, config-section=%s, keys=%s\n", varname, config, keys);
		} else {
			config = strsep(&argv[0], "\0");
			if (option_verbose > 2)
				cw_verbose(VERBOSE_PREFIX_3 "LDAPget: varname=%s, config-section=%s\n", varname, config);
		}
		if (!varname || !config) {
			cw_log(LOG_WARNING, "Ignoring; Syntax error in argument\n");
			pbx_builtin_setvar_helper(chan, "LDAPSTATUS", "FAILURE");
			return 0;
		}
	} else {
		cw_log(LOG_WARNING, "Ignoring, no parameters\n");
		pbx_builtin_setvar_helper(chan, "LDAPSTATUS", "FAILURE");
		return 0;
	}

	cfg = cw_config_load(LDAP_CONFIG);

	if (!cfg) {
		cw_log(LOG_WARNING, "No such configuration file %s\n", LDAP_CONFIG);
		return -1;
	}
	if (!(host = cw_variable_retrieve(cfg, config, "host"))) {
		host = "localhost";
	}
	if ((temp = cw_variable_retrieve(cfg, config, "port"))) {
		port = atoi(temp);
	}
	if ((temp = cw_variable_retrieve(cfg, config, "timeout"))) {
		timeout = atoi(temp);
	}
	if ((temp = cw_variable_retrieve(cfg, config, "version"))) {
		version = atoi(temp);
	}
	user = cw_variable_retrieve(cfg, config, "user");
	pass = cw_variable_retrieve(cfg, config, "pass");
	base = cw_variable_retrieve(cfg, config, "base");
	if (!base) base = "";
	base = replace_cw_vars(chan, base);
	if (!(scope = cw_variable_retrieve(cfg, config, "scope"))) {
		scope = "sub";
	}
	if (!(_filter = cw_variable_retrieve(cfg, config, "filter"))) {
		_filter = "(&(objectClass=person)(telephoneNumber=${CALLERIDNUM}))";
	}
	if (!(attribute = cw_variable_retrieve(cfg, config, "attribute"))) {
		attribute = "cn";
	}
	if ((temp = cw_variable_retrieve(cfg, config, "convert"))) {
		if (strchr(temp, ',')) {
			convert_from = strtrim(strsep(&temp, ","));
			convert_to = strtrim(strsep(&temp, "\0"));
		} else {
			cw_log(LOG_WARNING, "syntax error: convert = <source-charset>,<destination charset>\n");
		}
	}

	if (option_verbose > 3)
		cw_verbose (VERBOSE_PREFIX_4 "LDAPget: ldap://%s/%s?%s?%s?%s\n", host, base, attribute, scope, _filter);

	filter = replace_cw_vars(chan, _filter);
	if (option_verbose > 3)
		cw_verbose (VERBOSE_PREFIX_4 "LDAPget: %s\n", filter);

	if (keys && strstr(filter, "%s") != NULL) {
		filter = (char *)realloc(filter, (strlen(filter)+strlen(keys)+1)*sizeof(char));
		while((key = strsep(&keys, "|")) != NULL) {
			if ((tail = strstr(filter, "%s")) != NULL) {
				memmove(tail+strlen(key), tail+2, strlen(tail+2)+1);
				memcpy(tail, key, strlen(key));
			}
		}
	}

	if (option_verbose > 2)
		cw_verbose (VERBOSE_PREFIX_3 "LDAPget: ldap://%s/%s?%s?%s?%s\n", host, base, attribute, scope, filter);

	if (ldap_lookup(host, port, version, timeout, user, pass, base, scope, filter, attribute, result)) {

		if (convert_from) {
			if (option_verbose > 2)
				cw_verbose(VERBOSE_PREFIX_3 "LDAPget: convert: %s -> %s\n", convert_from, convert_to);
			result_conv = malloc(strlen(result) * 2);
			strconvert(convert_from, convert_to, result, result_conv);
			strcpy(result, result_conv);
			free(result_conv);
		}
		
		if (strcmp("CALLERIDNAME", varname)==0) {
			cw_set_callerid(chan, NULL, result, NULL);
			if (option_verbose > 2)
				cw_verbose (VERBOSE_PREFIX_3 "LDAPget: set CIDNAME to \"%s\"\n", result);
		} else {
			if (option_verbose > 2)
				cw_verbose (VERBOSE_PREFIX_3 "LDAPget: set %s='%s'\n", varname, result);
			pbx_builtin_setvar_helper(chan, varname, result);
		}
		
	} else {
		pbx_builtin_setvar_helper(chan, "LDAPSTATUS", "FAILURE");
		return 0;
	}
	cw_config_destroy(cfg);
	free(filter);
	free(base);
	pbx_builtin_setvar_helper(chan, "LDAPSTATUS", "SUCCESS");

	LOCAL_USER_REMOVE(u);
	return 0;
}
Esempio n. 9
0
static int privacy_exec (struct cw_channel *chan, int argc, char **argv)
{
	char phone[30];
	struct localuser *u;
	struct cw_config *cfg;
	char *s;
	int res=0;
	int retries;
	int maxretries = 3;
	int minlength = 10;
	int x;

	LOCAL_USER_ADD (u);

	if (!cw_strlen_zero(chan->cid.cid_num)) {
		if (option_verbose > 2)
			cw_verbose (VERBOSE_PREFIX_3 "CallerID Present: Skipping\n");
		pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
	} else {
		/*Answer the channel if it is not already*/
		if (chan->_state != CW_STATE_UP) {
			res = cw_answer(chan);
			if (res) {
				pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAIL");
				LOCAL_USER_REMOVE(u);
				return 0;
			}
		}
		/*Read in the config file*/
		cfg = cw_config_load(PRIV_CONFIG);
		
		
		/*Play unidentified call*/
		res = cw_safe_sleep(chan, 1000);
		if (!res)
			res = cw_streamfile(chan, "privacy-unident", chan->language);
		if (!res)
			res = cw_waitstream(chan, "");

        if (cfg && (s = cw_variable_retrieve(cfg, "general", "maxretries"))) {
                if (sscanf(s, "%d", &x) == 1) {
                        maxretries = x;
                } else {
                        cw_log(LOG_WARNING, "Invalid max retries argument\n");
                }
        }
        if (cfg && (s = cw_variable_retrieve(cfg, "general", "minlength"))) {
                if (sscanf(s, "%d", &x) == 1) {
                        minlength = x;
                } else {
                        cw_log(LOG_WARNING, "Invalid min length argument\n");
                }
        }
			
		/*Ask for 10 digit number, give 3 attempts*/
		for (retries = 0; retries < maxretries; retries++) {
			if (!res ) 
				res = cw_app_getdata(chan, "privacy-prompt", phone, sizeof(phone), 0);

			if (res < 0)
				break;

			/*Make sure we get at least our minimum of digits*/
			if (strlen(phone) >= minlength ) 
				break;
			else {
				res = cw_streamfile(chan, "privacy-incorrect", chan->language);
				if (!res)
					res = cw_waitstream(chan, "");
			}
		}
		
		/*Got a number, play sounds and send them on their way*/
		if ((retries < maxretries) && res == 1 ) {
			res = cw_streamfile(chan, "privacy-thankyou", chan->language);
			if (!res)
				res = cw_waitstream(chan, "");
			cw_set_callerid (chan, phone, "Privacy Manager", NULL);
			if (option_verbose > 2)
				cw_verbose (VERBOSE_PREFIX_3 "Changed Caller*ID to %s\n",phone);
			pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
		} else {
			/* Flag Failure  */
			pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAIL");
		}
		if (cfg) 
			cw_config_destroy(cfg);
	}

  LOCAL_USER_REMOVE (u);
  return 0;
}