|
@@ -0,0 +1,888 @@
|
|
|
+/*
|
|
|
+============================================================================
|
|
|
+Name : generate_trunk_conf.sh
|
|
|
+Author : ssc
|
|
|
+Version : v1.0
|
|
|
+Copyright : ZYCOO copyright
|
|
|
+Description : Generate trunk info from mysql to turnk conf file
|
|
|
+============================================================================
|
|
|
+*/
|
|
|
+
|
|
|
+#include <stdio.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <string.h>
|
|
|
+#include <errno.h>
|
|
|
+#include <assert.h>
|
|
|
+#include <time.h>
|
|
|
+#include <ctype.h>
|
|
|
+#include <cjson/cJSON.h>
|
|
|
+#include <mysql/mysql.h>
|
|
|
+
|
|
|
+MYSQL *g_conn; // mysql 连接
|
|
|
+MYSQL_RES *g_res; // mysql 记录集
|
|
|
+MYSQL_ROW g_row; // 字符串数组,mysql 记录行
|
|
|
+
|
|
|
+#define MAX_SIZE 2048
|
|
|
+#define MIDLE_SIZE 512
|
|
|
+#define MINI_SIZE 64
|
|
|
+#define MYSQL_CONNECT_CONF "/etc/asterisk/exten_gen.ini"
|
|
|
+#define EXTEN_IVR_FILE "/etc/asterisk/extensions_ivr_custom.conf"
|
|
|
+#define EXTEN_DIALRULE_FILE "/etc/asterisk/extensions_dialrule_custom.conf"
|
|
|
+#define EXTEN_INBOUND_FILE "/etc/asterisk/extensions_inbound_custom.conf"
|
|
|
+#define EXTEN_GLOBAL_FILE "/etc/asterisk/extensions_global_custom.conf"
|
|
|
+#define EXTEN_CALLTRIGGER_FILE "/etc/asterisk/extensions_call_trigger_custom.conf"
|
|
|
+#define EXTEN_FEATURECODES_FILE "/etc/asterisk/extensions_featurecodes_custom.conf"
|
|
|
+#define SIP_NAT_FILE "/etc/asterisk/sip_nat.conf"
|
|
|
+#define SIP_SETTINGS_FILE "/etc/asterisk/sip_settings.conf"
|
|
|
+#define RTP_SETTINGS_FILE "/etc/asterisk/rtp_settings.conf"
|
|
|
+#define KEYVALLEN 100
|
|
|
+#define VERSION "V1.0.1"
|
|
|
+
|
|
|
+#define QUERY_IVR_SQL "select name,exten,prompt,loops,timeout,language,dialplan,keys_action from t_pbx_ivr"
|
|
|
+#define QUERY_DIALRULE_SQL "select t_pbx_users_voiptrunk.trunk as trunk,rule,del_prefix,add_before,add_after from t_pbx_dialrule join t_pbx_users_voiptrunk on t_pbx_users_voiptrunk.id=t_pbx_dialrule.trunk_id"
|
|
|
+#define QUERY_GLOBAL_SQL "select * from t_global_config"
|
|
|
+
|
|
|
+char g_host_name[MINI_SIZE];
|
|
|
+char g_user_name[MINI_SIZE];
|
|
|
+char g_password[MINI_SIZE];
|
|
|
+char g_db_name[MINI_SIZE];
|
|
|
+const unsigned int g_db_port = 3306;
|
|
|
+char dialrule[MIDLE_SIZE];
|
|
|
+char ivrstr[MAX_SIZE];
|
|
|
+char inboundstr[MIDLE_SIZE];
|
|
|
+char prompt[MINI_SIZE];
|
|
|
+
|
|
|
+//读取配置文件函数----功能:删除左边空格
|
|
|
+char *l_trim(char *szOutput, const char *szInput)
|
|
|
+{
|
|
|
+ assert(szInput != NULL);
|
|
|
+ assert(szOutput != NULL);
|
|
|
+ assert(szOutput != szInput);
|
|
|
+ for (NULL; *szInput != '\0' && isspace(*szInput); ++szInput)
|
|
|
+ {
|
|
|
+ ;
|
|
|
+ }
|
|
|
+ return strcpy(szOutput, szInput);
|
|
|
+}
|
|
|
+
|
|
|
+/* 删除右边的空格 */
|
|
|
+char *r_trim(char *szOutput, const char *szInput)
|
|
|
+{
|
|
|
+ char *p = NULL;
|
|
|
+ assert(szInput != NULL);
|
|
|
+ assert(szOutput != NULL);
|
|
|
+ assert(szOutput != szInput);
|
|
|
+ strcpy(szOutput, szInput);
|
|
|
+ for(p = szOutput + strlen(szOutput) - 1; p >= szOutput && isspace(*p); --p)
|
|
|
+ {
|
|
|
+ ;
|
|
|
+ }
|
|
|
+ *(++p) = '\0';
|
|
|
+ return szOutput;
|
|
|
+}
|
|
|
+
|
|
|
+/* 删除两边的空格 */
|
|
|
+char *a_trim(char *szOutput, const char *szInput)
|
|
|
+{
|
|
|
+ char *p = NULL;
|
|
|
+ assert(szInput != NULL);
|
|
|
+ assert(szOutput != NULL);
|
|
|
+ l_trim(szOutput, szInput);
|
|
|
+ for (p = szOutput + strlen(szOutput) - 1; p >= szOutput && isspace(*p); --p)
|
|
|
+ {
|
|
|
+ ;
|
|
|
+ }
|
|
|
+ *(++p) = '\0';
|
|
|
+ return szOutput;
|
|
|
+}
|
|
|
+
|
|
|
+//main函数接口 参数1:配置文件路径 参数2:配置文件的那一部分,如general 参数3:键名 参数4:键值
|
|
|
+int GetProfileString(char *profile, char *AppName, char *KeyName, char *KeyVal )
|
|
|
+{
|
|
|
+ char appname[32], keyname[32];
|
|
|
+ char *buf, *c;
|
|
|
+ char buf_i[KEYVALLEN], buf_o[KEYVALLEN];
|
|
|
+ FILE *fp;
|
|
|
+ int found = 0; /* 1 AppName 2 KeyName */
|
|
|
+ if( (fp = fopen( profile, "r" )) == NULL )
|
|
|
+ {
|
|
|
+ printf( "openfile [%s] error [%s]\n", profile, strerror(errno) );
|
|
|
+ return(-1);
|
|
|
+ }
|
|
|
+ fseek( fp, 0, SEEK_SET );
|
|
|
+ memset( appname, 0, sizeof(appname) );
|
|
|
+ sprintf( appname, "[%s]", AppName );
|
|
|
+
|
|
|
+ while( !feof(fp) && fgets( buf_i, KEYVALLEN, fp ) != NULL )
|
|
|
+ {
|
|
|
+ l_trim(buf_o, buf_i);
|
|
|
+ if( strlen(buf_o) <= 0 )
|
|
|
+ continue;
|
|
|
+ buf = NULL;
|
|
|
+ buf = buf_o;
|
|
|
+
|
|
|
+ if( found == 0 )
|
|
|
+ {
|
|
|
+ if( buf[0] != '[' )
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else if ( strncmp(buf, appname, strlen(appname)) == 0 )
|
|
|
+ {
|
|
|
+ found = 1;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else if( found == 1 )
|
|
|
+ {
|
|
|
+ if( buf[0] == '#' )
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else if ( buf[0] == '[' )
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if( (c = (char *)strchr(buf, '=')) == NULL )
|
|
|
+ continue;
|
|
|
+ memset( keyname, 0, sizeof(keyname) );
|
|
|
+
|
|
|
+ sscanf( buf, "%[^=|^ |^\t]", keyname );
|
|
|
+ if( strcmp(keyname, KeyName) == 0 )
|
|
|
+ {
|
|
|
+ sscanf( ++c, "%[^\n]", KeyVal );
|
|
|
+ char *KeyVal_o = (char *)malloc(strlen(KeyVal) + 1);
|
|
|
+ if(KeyVal_o != NULL)
|
|
|
+ {
|
|
|
+ memset(KeyVal_o, 0, sizeof(KeyVal_o));
|
|
|
+ a_trim(KeyVal_o, KeyVal);
|
|
|
+ if(KeyVal_o && strlen(KeyVal_o) > 0)
|
|
|
+ strcpy(KeyVal, KeyVal_o);
|
|
|
+ free(KeyVal_o);
|
|
|
+ KeyVal_o = NULL;
|
|
|
+ }
|
|
|
+ found = 2;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fclose( fp );
|
|
|
+ if( found == 2 )
|
|
|
+ return(0);
|
|
|
+ else
|
|
|
+ return(-1);
|
|
|
+}
|
|
|
+
|
|
|
+char * mytime(){
|
|
|
+ time_t my_time;
|
|
|
+ time(&my_time);
|
|
|
+ char *time_string = ctime(&my_time);
|
|
|
+ if (time_string[strlen(time_string) - 1] == '\n')
|
|
|
+ {
|
|
|
+ time_string[strlen(time_string) - 1] = '\0';
|
|
|
+ }
|
|
|
+ return time_string;
|
|
|
+}
|
|
|
+
|
|
|
+void print_mysql_error(const char *msg) { // 打印最后一次错误
|
|
|
+if (msg)
|
|
|
+ printf("%s: %s\n", msg, mysql_error(g_conn));
|
|
|
+else
|
|
|
+ puts(mysql_error(g_conn));
|
|
|
+}
|
|
|
+
|
|
|
+int executesql(const char * sql) {
|
|
|
+/*query the database according the sql*/
|
|
|
+if (mysql_real_query(g_conn, sql, strlen(sql))) // 如果失败
|
|
|
+ return -1; // 表示失败
|
|
|
+
|
|
|
+return 0; // 成功执行
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int init_mysql() { // 初始化连接
|
|
|
+// init the database connection
|
|
|
+g_conn = mysql_init(NULL);
|
|
|
+
|
|
|
+/* connect the database */
|
|
|
+if(!mysql_real_connect(g_conn, g_host_name, g_user_name, g_password, g_db_name, g_db_port, NULL, 0)) // 如果失败
|
|
|
+ return -1;
|
|
|
+
|
|
|
+// 是否连接已经可用
|
|
|
+if (executesql("set names utf8")) // 如果失败
|
|
|
+ return -1;
|
|
|
+
|
|
|
+return 0; // 返回成功
|
|
|
+}
|
|
|
+
|
|
|
+int main(int argc, char **argv) {
|
|
|
+cJSON *pJson,*pSub;
|
|
|
+int iCount=0;
|
|
|
+
|
|
|
+typedef struct keys_action {
|
|
|
+ char key[MINI_SIZE];
|
|
|
+ char type[MINI_SIZE];
|
|
|
+ char exten[MINI_SIZE];
|
|
|
+} KeysObject;
|
|
|
+
|
|
|
+strcpy(g_host_name,getenv("MYSQL"));
|
|
|
+strcpy(g_user_name,getenv("MYSQL_USER"));
|
|
|
+strcpy(g_password,getenv("MYSQL_PASSWORD"));
|
|
|
+strcpy(g_db_name,getenv("MYSQL_DATABASE"));
|
|
|
+
|
|
|
+if (init_mysql()){
|
|
|
+ print_mysql_error(NULL);
|
|
|
+ exit(1);
|
|
|
+}
|
|
|
+
|
|
|
+//读取自动话务员的数据,并写入配置文件
|
|
|
+if (executesql(QUERY_IVR_SQL)){
|
|
|
+ print_mysql_error(NULL);
|
|
|
+ exit(1);
|
|
|
+}
|
|
|
+
|
|
|
+g_res = mysql_store_result(g_conn); // 从服务器传送结果集至本地,mysql_use_result直接使用服务器上的记录集
|
|
|
+FILE *conf_ivr_fp = fopen(EXTEN_IVR_FILE, "w+");
|
|
|
+
|
|
|
+if (conf_ivr_fp == NULL){
|
|
|
+ perror("Open paging conf file Error: ");
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ fprintf(conf_ivr_fp, ";!\n\
|
|
|
+;! Automatically generated configuration file\n\
|
|
|
+;! Filename: extensions_ivr_custom.conf (/etc/asterisk/extensions_ivr_custom.conf)\n\
|
|
|
+;! Generator: Generator IVR\n\
|
|
|
+;! Creation Date: %s\n\
|
|
|
+;!\n\n\
|
|
|
+",\
|
|
|
+mytime()\
|
|
|
+);
|
|
|
+
|
|
|
+//name:g_row[0],exten:g_row[1],prompt:g_row[2],loops:g_row[3],timeout:g_row[4],language:g_row[5],dialplan:g_row[6],keys_action
|
|
|
+//+----+--------------+-------+---------------------------------------+-------+---------+----------+----------+------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+---------------------+
|
|
|
+//| id | name | exten | prompt | loops | timeout | language | dialplan | keys_action | createdAt | updatedAt |
|
|
|
+//+----+--------------+-------+---------------------------------------+-------+---------+----------+----------+------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+---------------------+
|
|
|
+//| 1 | 上班时间 | 6500 | /etc/asterisk/sysconf/prompts/welcome | 1 | 3 | NULL | default | [{"key": "i", "type": "hangup", "exten": ""}, {"key": "t", "type": "hangup", "exten": ""}, {"key": "0", "type": "extension", "exten": "8001"}] | 2019-07-31 17:58:00 | 2019-08-05 01:30:48 |
|
|
|
+//| 2 | 下班时间 | 6501 | /etc/asterisk/sysconf/prompts/closed | 1 | 3 | NULL | default | [{"key": "i", "type": "hangup", "exten": ""}, {"key": "t", "type": "hangup", "exten": ""}] | 2019-07-31 17:58:00 | 2019-08-06 01:30:24 |
|
|
|
+//| 4 | test | 6505 | /etc/asterisk/sysconf/prompts/welcome | 1 | 3 | NULL | default | [{"key": "i", "type": "hangup", "exten": ""}, {"key": "t", "type": "hangup", "exten": ""}, {"key": "1", "type": "extension", "exten": "8500"}] | 2019-08-05 01:33:58 | 2019-08-05 13:02:10 |
|
|
|
+//+----+--------------+-------+---------------------------------------+-------+---------+----------+----------+------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+---------------------+
|
|
|
+//3 rows in set (0.00 sec)
|
|
|
+while ((g_row=mysql_fetch_row(g_res))){ // 打印结果集
|
|
|
+ if (g_row[0] == NULL || g_row[1] == NULL || g_row[2] == NULL){
|
|
|
+ printf("some feild is empty!\n");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ fprintf(conf_ivr_fp,"\
|
|
|
+[voicemenu-custom-%s]\n\
|
|
|
+include => %s\n\
|
|
|
+exten => %s,1,NoOp(%s)\n",\
|
|
|
+g_row[1],\
|
|
|
+g_row[6],\
|
|
|
+g_row[1],\
|
|
|
+g_row[0]\
|
|
|
+ );
|
|
|
+ if(g_row[5] != NULL){
|
|
|
+ fprintf(conf_ivr_fp,"same => n,Set(CHANNEL(language)=%s)\n",g_row[5]);
|
|
|
+ }
|
|
|
+ memset(prompt, 0, sizeof(prompt));
|
|
|
+ strncpy(prompt,g_row[2],strlen(g_row[2])-4);
|
|
|
+ fprintf(conf_ivr_fp,"\
|
|
|
+same => n,Set(COUNT=%s)\n\
|
|
|
+same => n(loop),Background(%s)\n",\
|
|
|
+g_row[3],\
|
|
|
+prompt
|
|
|
+ );
|
|
|
+ if(strcmp(g_row[4], "0") != 0 && g_row[4] != NULL){
|
|
|
+ fprintf(conf_ivr_fp,"same => n,WaitExten(%s)\n",g_row[4]);
|
|
|
+ }
|
|
|
+ fprintf(conf_ivr_fp,"\
|
|
|
+same => n,Set(COUNT=$[${COUNT}-1])\n\
|
|
|
+same => n,GotoIf($[${COUNT} < 0]?:loop)\n\
|
|
|
+same => n,WaitExten(1)\n");
|
|
|
+ KeysObject keysObject[MINI_SIZE];
|
|
|
+ memset(keysObject, 0, sizeof(keysObject));
|
|
|
+ if(g_row[7] != NULL){
|
|
|
+ pJson = cJSON_Parse(g_row[7]);
|
|
|
+ iCount = cJSON_GetArraySize(pJson);
|
|
|
+ for(int i = 0;i < iCount;i++){
|
|
|
+ pSub = cJSON_GetArrayItem(pJson,i);
|
|
|
+ if(pSub != NULL){
|
|
|
+ strcpy(keysObject[i].key,cJSON_GetObjectItem(pSub, "key")->valuestring);
|
|
|
+ strcpy(keysObject[i].type,cJSON_GetObjectItem(pSub, "type")->valuestring);
|
|
|
+ strcpy(keysObject[i].exten,cJSON_GetObjectItem(pSub, "exten")->valuestring);
|
|
|
+ if(strcmp(keysObject[i].type, "hangup") == 0){
|
|
|
+ fprintf(conf_ivr_fp,"exten => %s,1,Hangup()\n",keysObject[i].key);
|
|
|
+ }
|
|
|
+ else if(strcmp(keysObject[i].type, "extension") == 0){
|
|
|
+ fprintf(conf_ivr_fp,"exten => %s,1,Goto(default,%s,1)\n",keysObject[i].key,keysObject[i].exten);
|
|
|
+ }
|
|
|
+ else if(strcmp(keysObject[i].type, "ivr") == 0){
|
|
|
+ fprintf(conf_ivr_fp,"exten => %s,1,Goto(voicemenu-custom-%s,%s,1)\n",keysObject[i].key,keysObject[i].exten,keysObject[i].exten);
|
|
|
+ }
|
|
|
+ else if(strcmp(keysObject[i].type, "group") == 0){
|
|
|
+ fprintf(conf_ivr_fp,"exten => %s,1,Goto(paging-group-%s,%s,1)\n",keysObject[i].key,keysObject[i].exten,keysObject[i].exten);
|
|
|
+ }
|
|
|
+ else if(strcmp(keysObject[i].type, "user") == 0){
|
|
|
+ int id = 100000 + atoi(keysObject[i].exten);
|
|
|
+ fprintf(conf_ivr_fp,"exten => %s,1,Goto(manager-queue-%d,s,1)\n",keysObject[i].key,id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fprintf(conf_ivr_fp,"\n\n");
|
|
|
+}
|
|
|
+/*
|
|
|
+while ((g_row=mysql_fetch_row(g_res))){ // 打印结果集
|
|
|
+ if (g_row[0] == NULL || g_row[1] == NULL || g_row[2] == NULL){
|
|
|
+ printf("some feild is empty!\n");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ sprintf(ivrstr,"\
|
|
|
+[voicemenu-custom-%s]\n\
|
|
|
+include => %s\n\
|
|
|
+exten => %s,1,NoOp(%s)",\
|
|
|
+g_row[1],\
|
|
|
+g_row[6],\
|
|
|
+g_row[1],\
|
|
|
+g_row[0]\
|
|
|
+ );
|
|
|
+ if(g_row[5] != NULL){
|
|
|
+ sprintf(ivrstr,"%s\nsame => n,Set(CHANNEL(language)=%s)",ivrstr,g_row[5]);
|
|
|
+ }
|
|
|
+ memset(prompt, 0, sizeof(prompt));
|
|
|
+ strncpy(prompt,g_row[2],strlen(g_row[2])-4);
|
|
|
+ sprintf(ivrstr,"%s\n\
|
|
|
+same => n,Set(COUNT=%s)\n\
|
|
|
+same => n(loop),Background(%s)",ivrstr,\
|
|
|
+g_row[3],\
|
|
|
+prompt
|
|
|
+ );
|
|
|
+ if(strcmp(g_row[4], "0") != 0 && g_row[4] != NULL){
|
|
|
+ sprintf(ivrstr,"%s\nsame => n,WaitExten(%s)",ivrstr,g_row[4]);
|
|
|
+ }
|
|
|
+ sprintf(ivrstr,"%s\n\
|
|
|
+same => n,Set(COUNT=$[${COUNT}-1])\n\
|
|
|
+same => n,GotoIf($[${COUNT} < 0]?:loop)\n\
|
|
|
+same => n,WaitExten(1)",ivrstr
|
|
|
+ );
|
|
|
+ KeysObject keysObject[MINI_SIZE];
|
|
|
+ memset(keysObject, 0, sizeof(keysObject));
|
|
|
+ if(g_row[7] != NULL){
|
|
|
+ pJson = cJSON_Parse(g_row[7]);
|
|
|
+ iCount = cJSON_GetArraySize(pJson);
|
|
|
+ for(int i = 0;i < iCount;i++){
|
|
|
+ pSub = cJSON_GetArrayItem(pJson,i);
|
|
|
+ if(pSub != NULL){
|
|
|
+ strcpy(keysObject[i].key,cJSON_GetObjectItem(pSub, "key")->valuestring);
|
|
|
+ strcpy(keysObject[i].type,cJSON_GetObjectItem(pSub, "type")->valuestring);
|
|
|
+ strcpy(keysObject[i].exten,cJSON_GetObjectItem(pSub, "exten")->valuestring);
|
|
|
+ if(strcmp(keysObject[i].type, "hangup") == 0){
|
|
|
+ sprintf(ivrstr,"%s\nexten => %s,1,Hangup()",ivrstr,keysObject[i].key);
|
|
|
+ }
|
|
|
+ else if(strcmp(keysObject[i].type, "extension") == 0){
|
|
|
+ sprintf(ivrstr,"%s\nexten => %s,1,Goto(default,%s,1)",ivrstr,keysObject[i].key,keysObject[i].exten);
|
|
|
+ }
|
|
|
+ else if(strcmp(keysObject[i].type, "ivr") == 0){
|
|
|
+ sprintf(ivrstr,"%s\nexten => %s,1,Goto(voicemenu-custom-%s,%s,1)",ivrstr,keysObject[i].key,keysObject[i].exten,keysObject[i].exten);
|
|
|
+ }
|
|
|
+ else if(strcmp(keysObject[i].type, "group") == 0){
|
|
|
+ sprintf(ivrstr,"%s\nexten => %s,1,Goto(paging-group-%s,%s,1)",ivrstr,keysObject[i].key,keysObject[i].exten,keysObject[i].exten);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ strcat(ivrstr,"\n\n");
|
|
|
+ fputs(ivrstr,conf_ivr_fp);
|
|
|
+}
|
|
|
+/*
|
|
|
+[voicemenu-custom-%s]
|
|
|
+include = default
|
|
|
+exten = _IVR-X.,1,NoOp(%s)
|
|
|
+exten = _IVR-X.,n,NoOp(Default language)
|
|
|
+exten = _IVR-X.,n,Set(COUNT=3)
|
|
|
+exten = _IVR-X.,n(loop),Background(%s)
|
|
|
+exten = _IVR-X.,n,Set(COUNT=$[${COUNT}-1])
|
|
|
+exten = _IVR-X.,n,WaitExten(%s)
|
|
|
+exten = _IVR-X.,n,GotoIf($[${COUNT}>1]?6)
|
|
|
+exten = _IVR-X.,n,WaitExten(1)
|
|
|
+exten = t,1,Hangup
|
|
|
+*/
|
|
|
+
|
|
|
+//读取拨号规则的数据,并写入配置文件
|
|
|
+if (executesql(QUERY_DIALRULE_SQL)){
|
|
|
+ print_mysql_error(NULL);
|
|
|
+ exit(1);
|
|
|
+}
|
|
|
+
|
|
|
+g_res = mysql_store_result(g_conn); // 从服务器传送结果集至本地,mysql_use_result直接使用服务器上的记录集
|
|
|
+FILE *conf_dialrule_fp = fopen(EXTEN_DIALRULE_FILE, "w+");
|
|
|
+
|
|
|
+if (conf_dialrule_fp == NULL){
|
|
|
+ perror("Open paging conf file Error: ");
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ fprintf(conf_dialrule_fp, ";!\n\
|
|
|
+;! Automatically generated configuration file\n\
|
|
|
+;! Filename: extensions_dialrule_custom.conf (/etc/asterisk/extensions_dialrule_custom.conf)\n\
|
|
|
+;! Generator: Generator DIALRULE\n\
|
|
|
+;! Creation Date: %s\n\
|
|
|
+;!\n\n\
|
|
|
+",\
|
|
|
+mytime()\
|
|
|
+);
|
|
|
+
|
|
|
+fputs("[CallingRule_OutCall]\n",conf_dialrule_fp);
|
|
|
+//t_pbx_users_voiptrunk.trunk as trunk,rule,del_prefix,add_before,add_after
|
|
|
+ while ((g_row=mysql_fetch_row(g_res))){ // 打印结果集
|
|
|
+ if (g_row[0] == NULL || g_row[1] == NULL){
|
|
|
+ printf("some feild is empty!\n");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ memset(dialrule,0,sizeof(dialrule));
|
|
|
+ sprintf(dialrule, "exten => _%s,1,Macro(trunkdial-failover,${EXTEN},${%s}",g_row[1], g_row[0]);
|
|
|
+ if(g_row[3] != NULL){
|
|
|
+ strcat(dialrule,g_row[3]);
|
|
|
+ }
|
|
|
+ strcat(dialrule,"${EXTEN:");
|
|
|
+ if(g_row[2] != NULL){
|
|
|
+ strcat(dialrule,g_row[2]);
|
|
|
+ }
|
|
|
+ strcat(dialrule,"}");
|
|
|
+ if(g_row[4] != NULL){
|
|
|
+ strcat(dialrule,g_row[4]);
|
|
|
+ }
|
|
|
+ strcat(dialrule,")\n");
|
|
|
+ fputs(dialrule,conf_dialrule_fp);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+//读取全局配置数据,并写入配置文件
|
|
|
+if (executesql(QUERY_GLOBAL_SQL)){
|
|
|
+ print_mysql_error(NULL);
|
|
|
+ exit(1);
|
|
|
+}
|
|
|
+
|
|
|
+g_res = mysql_store_result(g_conn); // 从服务器传送结果集至本地,mysql_use_result直接使用服务器上的记录集
|
|
|
+FILE *conf_inbound_fp = fopen(EXTEN_INBOUND_FILE, "w+");
|
|
|
+if (conf_inbound_fp == NULL){
|
|
|
+ perror("Open inbound conf file Error: ");
|
|
|
+ exit(1);
|
|
|
+}
|
|
|
+
|
|
|
+FILE *conf_global_fp = fopen(EXTEN_GLOBAL_FILE, "w+");
|
|
|
+if (conf_global_fp == NULL){
|
|
|
+ perror("Open global conf file Error: ");
|
|
|
+ exit(1);
|
|
|
+}
|
|
|
+
|
|
|
+FILE *conf_calltrigger_fp = fopen(EXTEN_CALLTRIGGER_FILE, "w+");
|
|
|
+if (conf_calltrigger_fp == NULL){
|
|
|
+ perror("Open calltrigger conf file Error: ");
|
|
|
+ exit(1);
|
|
|
+}
|
|
|
+
|
|
|
+FILE *conf_featurecodes_fp = fopen(EXTEN_FEATURECODES_FILE, "w+");
|
|
|
+if (conf_featurecodes_fp == NULL){
|
|
|
+ perror("Open featurecodes conf file Error: ");
|
|
|
+ exit(1);
|
|
|
+}
|
|
|
+
|
|
|
+FILE *conf_sip_nat_fp = fopen(SIP_NAT_FILE, "w+");
|
|
|
+if (conf_sip_nat_fp == NULL){
|
|
|
+ perror("Open sip nat conf file Error: ");
|
|
|
+ exit(1);
|
|
|
+}
|
|
|
+
|
|
|
+FILE *conf_sipsetting_fp = fopen(SIP_SETTINGS_FILE, "w+");
|
|
|
+if (conf_sipsetting_fp == NULL){
|
|
|
+ perror("Open sip settings conf file Error: ");
|
|
|
+ exit(1);
|
|
|
+}
|
|
|
+
|
|
|
+FILE *conf_rtpsetting_fp = fopen(RTP_SETTINGS_FILE, "w+");
|
|
|
+if (conf_rtpsetting_fp == NULL){
|
|
|
+ perror("Open rtp settings conf file Error: ");
|
|
|
+ exit(1);
|
|
|
+}
|
|
|
+
|
|
|
+ fprintf(conf_inbound_fp, ";!\n\
|
|
|
+;! Automatically generated configuration file\n\
|
|
|
+;! Filename: extensions_inbound_custom.conf (/etc/asterisk/extensions_inbound_custom.conf)\n\
|
|
|
+;! Generator: Generator INBOUND\n\
|
|
|
+;! Creation Date: %s\n\
|
|
|
+;!\n\n\
|
|
|
+",\
|
|
|
+mytime()\
|
|
|
+);
|
|
|
+
|
|
|
+ fprintf(conf_global_fp, ";!\n\
|
|
|
+;! Automatically generated configuration file\n\
|
|
|
+;! Filename: extensions_global_custom.conf (/etc/asterisk/extensions_global_custom.conf)\n\
|
|
|
+;! Generator: Generator GLOBAL\n\
|
|
|
+;! Creation Date: %s\n\
|
|
|
+;!\n\n\
|
|
|
+",\
|
|
|
+mytime()\
|
|
|
+);
|
|
|
+fprintf(conf_global_fp, "\
|
|
|
+AGISERVERHOST = %s\n\
|
|
|
+AGISERVERPORT = %s\n\
|
|
|
+",\
|
|
|
+getenv("BROADCAST_GATEWAY"),\
|
|
|
+getenv("AGI_SERVER_PORT")\
|
|
|
+);
|
|
|
+
|
|
|
+ fprintf(conf_calltrigger_fp, ";!\n\
|
|
|
+;! Automatically generated configuration file\n\
|
|
|
+;! Filename: extensions_call_trigger_custom.conf (/etc/asterisk/extensions_call_trigger_custom.conf)\n\
|
|
|
+;! Generator: Generator TRIGGER\n\
|
|
|
+;! Creation Date: %s\n\
|
|
|
+;!\n\n\
|
|
|
+",\
|
|
|
+mytime()\
|
|
|
+);
|
|
|
+
|
|
|
+ fprintf(conf_featurecodes_fp, ";!\n\
|
|
|
+;! Automatically generated configuration file\n\
|
|
|
+;! Filename: extensions_featurecodes_custom.conf (/etc/asterisk/extensions_featurecodes_custom.conf)\n\
|
|
|
+;! Generator: Generator FEATURECODES\n\
|
|
|
+;! Creation Date: %s\n\
|
|
|
+;!\n\n\
|
|
|
+[featurecodes]\n",\
|
|
|
+mytime()\
|
|
|
+);
|
|
|
+
|
|
|
+ fprintf(conf_sip_nat_fp, ";!\n\
|
|
|
+;! Automatically generated configuration file\n\
|
|
|
+;! Filename: sip_nat.conf (/etc/asterisk/sip_nat.conf)\n\
|
|
|
+;! Generator: Generator SIP NAT\n\
|
|
|
+;! Creation Date: %s\n\
|
|
|
+;!\n\n\
|
|
|
+\n",\
|
|
|
+mytime()\
|
|
|
+);
|
|
|
+
|
|
|
+ fprintf(conf_sipsetting_fp, ";!\n\
|
|
|
+;! Automatically generated configuration file\n\
|
|
|
+;! Filename: sip_settings.conf (/etc/asterisk/sip_settings.conf)\n\
|
|
|
+;! Generator: Generator SIP SETTINGS\n\
|
|
|
+;! Creation Date: %s\n\
|
|
|
+;!\n\n\
|
|
|
+\n",\
|
|
|
+mytime()\
|
|
|
+);
|
|
|
+
|
|
|
+ fprintf(conf_rtpsetting_fp, ";!\n\
|
|
|
+;! Automatically generated configuration file\n\
|
|
|
+;! Filename: rtp_settings.conf (/etc/asterisk/rtp_settings.conf)\n\
|
|
|
+;! Generator: Generator RTP SETTINGS\n\
|
|
|
+;! Creation Date: %s\n\
|
|
|
+;!\n\n\
|
|
|
+\n",\
|
|
|
+mytime()\
|
|
|
+);
|
|
|
+
|
|
|
+//t_pbx_users_voiptrunk.trunk as trunk,rule,del_prefix,add_before,add_after
|
|
|
+ while ((g_row=mysql_fetch_row(g_res))){ // 打印结果集
|
|
|
+ if (g_row[0] == NULL || g_row[1] == NULL || g_row[2] == NULL){
|
|
|
+ printf("some feild is empty!\n");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(strcmp(g_row[1],"pbx.voip.inbound") == 0){
|
|
|
+ memset(inboundstr,0,sizeof(inboundstr));
|
|
|
+ pJson = cJSON_Parse(g_row[2]);
|
|
|
+ if(strcmp(cJSON_GetObjectItem(pJson, "type")->valuestring, "hangup") == 0){
|
|
|
+ sprintf(inboundstr,"\
|
|
|
+[direct-analog]\n\
|
|
|
+exten => direct,1,Hangup()\n\
|
|
|
+[direct-voip]\n\
|
|
|
+exten => direct,1,Hangup()\n"
|
|
|
+ );
|
|
|
+ }
|
|
|
+ else if(strcmp(cJSON_GetObjectItem(pJson, "type")->valuestring, "extension") == 0){
|
|
|
+ sprintf(inboundstr,"\
|
|
|
+[direct-analog]\n\
|
|
|
+exten => direct,1,Goto(default,%s,1)\n\
|
|
|
+[direct-voip]\n\
|
|
|
+exten => direct,1,Goto(default,%s,1)\n",\
|
|
|
+cJSON_GetObjectItem(pJson, "exten")->valuestring,\
|
|
|
+cJSON_GetObjectItem(pJson, "exten")->valuestring\
|
|
|
+ );
|
|
|
+ }
|
|
|
+ else if(strcmp(cJSON_GetObjectItem(pJson, "type")->valuestring, "ivr") == 0){
|
|
|
+ sprintf(inboundstr,"\
|
|
|
+[direct-analog]\n\
|
|
|
+exten => direct,1,Goto(voicemenu-custom-%s,%s,1)\n\
|
|
|
+[direct-voip]\n\
|
|
|
+exten => direct,1,Goto(voicemenu-custom-%s,%s,1)\n",\
|
|
|
+cJSON_GetObjectItem(pJson, "exten")->valuestring,\
|
|
|
+cJSON_GetObjectItem(pJson, "exten")->valuestring,\
|
|
|
+cJSON_GetObjectItem(pJson, "exten")->valuestring,\
|
|
|
+cJSON_GetObjectItem(pJson, "exten")->valuestring\
|
|
|
+ );
|
|
|
+ }
|
|
|
+ else if(strcmp(cJSON_GetObjectItem(pJson, "type")->valuestring, "group") == 0){
|
|
|
+ sprintf(inboundstr,"\
|
|
|
+[direct-analog]\n\
|
|
|
+exten => direct,1,Goto(paging-group-%s,%s,1)\n\
|
|
|
+[direct-voip]\n\
|
|
|
+exten => direct,1,Goto(paging-group-%s,%s,1)\n",\
|
|
|
+cJSON_GetObjectItem(pJson, "exten")->valuestring,\
|
|
|
+cJSON_GetObjectItem(pJson, "exten")->valuestring,\
|
|
|
+cJSON_GetObjectItem(pJson, "exten")->valuestring,\
|
|
|
+cJSON_GetObjectItem(pJson, "exten")->valuestring\
|
|
|
+ );
|
|
|
+ }
|
|
|
+ fputs(inboundstr,conf_inbound_fp);
|
|
|
+ }
|
|
|
+ else if(strcmp(g_row[1],"paging.prompt.config") == 0){
|
|
|
+ pJson = cJSON_Parse(g_row[2]);
|
|
|
+ fprintf(conf_global_fp, "\
|
|
|
+enPaging_prompt_start = %s\n\
|
|
|
+enPaging_prompt_end = %s\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pJson, "start")->valuestring,\
|
|
|
+cJSON_GetObjectItem(pJson, "end")->valuestring\
|
|
|
+);
|
|
|
+ if(cJSON_GetObjectItem(pJson, "startfile") != NULL){
|
|
|
+ memset(prompt, 0, sizeof(prompt));
|
|
|
+ if(strcmp(cJSON_GetObjectItem(pJson, "startfile")->valuestring,"start") == 0)
|
|
|
+ strcpy(prompt,cJSON_GetObjectItem(pJson, "startfile")->valuestring);
|
|
|
+ else
|
|
|
+ strncpy(prompt,cJSON_GetObjectItem(pJson, "startfile")->valuestring,strlen(cJSON_GetObjectItem(pJson, "startfile")->valuestring)-4);
|
|
|
+ fprintf(conf_global_fp, "\
|
|
|
+Paging_start_file = %s\n\
|
|
|
+",\
|
|
|
+prompt\
|
|
|
+);
|
|
|
+ }else{
|
|
|
+ fprintf(conf_global_fp, "\
|
|
|
+Paging_start_file = start\n\
|
|
|
+");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(strcmp(g_row[1],"pbx.ringtime.config") == 0){
|
|
|
+ pJson = cJSON_Parse(g_row[2]);
|
|
|
+ if(cJSON_GetObjectItem(pJson, "ringtime") != NULL){
|
|
|
+ fprintf(conf_global_fp, "\
|
|
|
+RINGTIME = %d\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pJson, "ringtime")->valueint\
|
|
|
+);
|
|
|
+ }else{
|
|
|
+ fprintf(conf_global_fp, "\
|
|
|
+RINGTIME = 30\n\
|
|
|
+");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(strcmp(g_row[1],"pbx.nat.config") == 0){
|
|
|
+ pJson = cJSON_Parse(g_row[2]);
|
|
|
+ if(pJson && cJSON_GetObjectItem(pJson, "enable")->valueint == 1){
|
|
|
+ fprintf(conf_sip_nat_fp, "\
|
|
|
+externaddr = %s\n\
|
|
|
+externhost = %s\n\
|
|
|
+externrefresh = %d\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pJson, "externaddr")->valuestring,\
|
|
|
+cJSON_GetObjectItem(pJson, "externhost")->valuestring,\
|
|
|
+cJSON_GetObjectItem(pJson, "externrefresh")->valueint\
|
|
|
+);
|
|
|
+ if(cJSON_GetObjectItem(pJson, "externtcpport") && cJSON_GetObjectItem(pJson, "externtcpport")->valueint != 0)
|
|
|
+ {
|
|
|
+ fprintf(conf_sip_nat_fp, "\
|
|
|
+externtcpport = %d\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pJson, "externtcpport")->valueint\
|
|
|
+);
|
|
|
+ }
|
|
|
+ if(cJSON_GetObjectItem(pJson, "externtlsport") && cJSON_GetObjectItem(pJson, "externtlsport")->valueint != 0)
|
|
|
+ {
|
|
|
+ fprintf(conf_sip_nat_fp, "\
|
|
|
+externtlsport = %d\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pJson, "externtlsport")->valueint\
|
|
|
+);
|
|
|
+ }
|
|
|
+ cJSON *localnetArray = cJSON_GetObjectItem( pJson, "localnet");
|
|
|
+ if(localnetArray != NULL){
|
|
|
+ int array_size = cJSON_GetArraySize (localnetArray);
|
|
|
+ for(int n = 0; n < array_size; n++){
|
|
|
+ pSub = cJSON_GetArrayItem(localnetArray, n);
|
|
|
+ if(NULL == pSub ){ continue ; }
|
|
|
+ fprintf(conf_sip_nat_fp, "\
|
|
|
+localnet = %s\n\
|
|
|
+",\
|
|
|
+pSub->valuestring\
|
|
|
+);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(strcmp(g_row[1],"paging.record.config") == 0){
|
|
|
+ pJson = cJSON_Parse(g_row[2]);
|
|
|
+ if(cJSON_GetObjectItem(pJson, "paging_record") != NULL){
|
|
|
+ fprintf(conf_global_fp, "\
|
|
|
+PAGING_RECORD = %s\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pJson, "paging_record")->valuestring\
|
|
|
+);
|
|
|
+ }
|
|
|
+ if(cJSON_GetObjectItem(pJson, "intercom_record") != NULL){
|
|
|
+ fprintf(conf_global_fp, "\
|
|
|
+INTERCOM_RECORD = %s\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pJson, "intercom_record")->valuestring\
|
|
|
+);
|
|
|
+ }
|
|
|
+ if(cJSON_GetObjectItem(pJson, "conference_record") != NULL){
|
|
|
+ fprintf(conf_global_fp, "\
|
|
|
+CONFERENCE_RECORD = %s\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pJson, "conference_record")->valuestring\
|
|
|
+);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(strcmp(g_row[1],"pbx.autoanswer.config") == 0){
|
|
|
+ pJson = cJSON_Parse(g_row[2]);
|
|
|
+ if(cJSON_GetObjectItem(pJson, "intercom_autoanswer") != NULL){
|
|
|
+ fprintf(conf_global_fp, "\
|
|
|
+INTERCOM_AUTO = %s\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pJson, "intercom_autoanswer")->valuestring\
|
|
|
+);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fprintf(conf_global_fp, "\
|
|
|
+INTERCOM_AUTO = yes\n\
|
|
|
+");
|
|
|
+ }
|
|
|
+ if(cJSON_GetObjectItem(pJson, "paging_autoanswer") != NULL){
|
|
|
+ fprintf(conf_global_fp, "\
|
|
|
+PAGING_AUTO = %s\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pJson, "paging_autoanswer")->valuestring\
|
|
|
+);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fprintf(conf_global_fp, "\
|
|
|
+PAGING_AUTO = yes\n\
|
|
|
+");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(strcmp(g_row[1],"paging.calltrigger.config") == 0){
|
|
|
+ pJson = cJSON_Parse(g_row[2]);
|
|
|
+ fprintf(conf_calltrigger_fp, "\
|
|
|
+exten => _%s.,1,Macro(calltrigger,${EXTEN})\n\
|
|
|
+exten => _%s.,1,Macro(calltrigger,${EXTEN})\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pJson, "start")->valuestring,\
|
|
|
+cJSON_GetObjectItem(pJson, "stop")->valuestring\
|
|
|
+);
|
|
|
+ }
|
|
|
+ else if(strcmp(g_row[1],"pbx.sipsettings.config") == 0){
|
|
|
+ pJson = cJSON_Parse(g_row[2]);
|
|
|
+ if(cJSON_GetObjectItem(pJson, "udp"))
|
|
|
+ {
|
|
|
+ fprintf(conf_sipsetting_fp, "udpbindaddr = 0.0.0.0:%d\n",cJSON_GetObjectItem(pJson, "udp")->valueint);
|
|
|
+ }
|
|
|
+ pSub = cJSON_GetObjectItem(pJson, "tcp");
|
|
|
+ if(pSub && cJSON_GetObjectItem(pSub, "enable")->valueint == 1){
|
|
|
+ fprintf(conf_sipsetting_fp, "\
|
|
|
+tcpenable = yes\n\
|
|
|
+tcpbindaddr = 0.0.0.0:%d\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pSub, "port")->valueint\
|
|
|
+);
|
|
|
+ }
|
|
|
+ pSub = cJSON_GetObjectItem(pJson, "tls");
|
|
|
+ if(pSub && cJSON_GetObjectItem(pSub, "enable")->valueint == 1){
|
|
|
+ fprintf(conf_sipsetting_fp, "\
|
|
|
+tlsenable = yes\n\
|
|
|
+tlsbindaddr = 0.0.0.0:%d\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pSub, "port")->valueint\
|
|
|
+);
|
|
|
+ }
|
|
|
+ pSub = cJSON_GetObjectItem(pJson, "rtp");
|
|
|
+ if(pSub){
|
|
|
+ fprintf(conf_rtpsetting_fp, "\
|
|
|
+rtpstart = %d\n\
|
|
|
+rtpend = %d\n\
|
|
|
+",\
|
|
|
+cJSON_GetObjectItem(pSub, "start_port")->valueint,\
|
|
|
+cJSON_GetObjectItem(pSub, "end_port")->valueint\
|
|
|
+);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(strcmp(g_row[1],"paging.featurecodes.config") == 0){
|
|
|
+ pJson = cJSON_Parse(g_row[2]);
|
|
|
+ pSub = cJSON_GetObjectItem(pJson, "bargein");
|
|
|
+ if(cJSON_GetObjectItem(pSub, "enable")->valueint == 1){
|
|
|
+ fprintf(conf_featurecodes_fp, "exten = _%s.,1,Macro(spy-barge,${EXTEN:%ld},${CALLERID(num)})\n",cJSON_GetObjectItem(pSub, "code")->valuestring,strlen(cJSON_GetObjectItem(pSub, "code")->valuestring));
|
|
|
+ }
|
|
|
+ pSub = cJSON_GetObjectItem(pJson, "clear");
|
|
|
+ if(cJSON_GetObjectItem(pSub, "enable")->valueint == 1){
|
|
|
+ fprintf(conf_featurecodes_fp, "exten = _%s.,1,Macro(exten-clear,${EXTEN:%ld},${CALLERID(num)})\n",cJSON_GetObjectItem(pSub, "code")->valuestring,strlen(cJSON_GetObjectItem(pSub, "code")->valuestring));
|
|
|
+ }
|
|
|
+ pSub = cJSON_GetObjectItem(pJson, "syp");
|
|
|
+ if(cJSON_GetObjectItem(pSub, "enable")->valueint == 1){
|
|
|
+ fprintf(conf_featurecodes_fp, "exten = _%s.,1,Macro(spy-normal,${EXTEN:%ld},${CALLERID(num)})\n",cJSON_GetObjectItem(pSub, "code")->valuestring,strlen(cJSON_GetObjectItem(pSub, "code")->valuestring));
|
|
|
+ }
|
|
|
+ pSub = cJSON_GetObjectItem(pJson, "whisper");
|
|
|
+ if(cJSON_GetObjectItem(pSub, "enable")->valueint == 1){
|
|
|
+ fprintf(conf_featurecodes_fp, "exten = _%s.,1,Macro(spy-whisper,${EXTEN:%ld},${CALLERID(num)})\n",cJSON_GetObjectItem(pSub, "code")->valuestring,strlen(cJSON_GetObjectItem(pSub, "code")->valuestring));
|
|
|
+ }
|
|
|
+ pSub = cJSON_GetObjectItem(pJson, "wakeup");
|
|
|
+ if(cJSON_GetObjectItem(pSub, "enable")->valueint == 1){
|
|
|
+ fprintf(conf_featurecodes_fp, "exten = %s,1,Macro(wakeup-call,${CALLERID(num)})\n",cJSON_GetObjectItem(pSub, "code")->valuestring);
|
|
|
+ }
|
|
|
+ pSub = cJSON_GetObjectItem(pJson, "dnd");
|
|
|
+ if(cJSON_GetObjectItem(pSub, "enable")->valueint == 1){
|
|
|
+ fprintf(conf_featurecodes_fp, "exten = %s,1,Goto(app-dnd-on,s,1)\n",cJSON_GetObjectItem(pSub, "code")->valuestring);
|
|
|
+ }
|
|
|
+ pSub = cJSON_GetObjectItem(pJson, "cf-alway");
|
|
|
+ if(cJSON_GetObjectItem(pSub, "enable")->valueint == 1){
|
|
|
+ fprintf(conf_featurecodes_fp, "exten = _%s.,1,Goto(app-cf-on,cf-${EXTEN:%ld},1)\n",cJSON_GetObjectItem(pSub, "code")->valuestring,strlen(cJSON_GetObjectItem(pSub, "code")->valuestring));
|
|
|
+ fprintf(conf_featurecodes_fp, "exten = %s,1,Goto(app-cf-off,s,1)\n",cJSON_GetObjectItem(pSub, "code")->valuestring);
|
|
|
+ }
|
|
|
+ pSub = cJSON_GetObjectItem(pJson, "cf-busy");
|
|
|
+ if(cJSON_GetObjectItem(pSub, "enable")->valueint == 1){
|
|
|
+ fprintf(conf_featurecodes_fp, "exten = _%s.,1,Goto(app-cfb-on,cf-${EXTEN:%ld},1)\n",cJSON_GetObjectItem(pSub, "code")->valuestring,strlen(cJSON_GetObjectItem(pSub, "code")->valuestring));
|
|
|
+ fprintf(conf_featurecodes_fp, "exten = %s,1,Goto(app-cfb-off,s,1)\n",cJSON_GetObjectItem(pSub, "code")->valuestring);
|
|
|
+ }
|
|
|
+ pSub = cJSON_GetObjectItem(pJson, "cf-noanswer");
|
|
|
+ if(cJSON_GetObjectItem(pSub, "enable")->valueint == 1){
|
|
|
+ fprintf(conf_featurecodes_fp, "exten = _%s.,1,Goto(app-cfu-on,cf-${EXTEN:%ld},1)\n",cJSON_GetObjectItem(pSub, "code")->valuestring,strlen(cJSON_GetObjectItem(pSub, "code")->valuestring));
|
|
|
+ fprintf(conf_featurecodes_fp, "exten = %s,1,Goto(app-cfu-off,s,1)\n",cJSON_GetObjectItem(pSub, "code")->valuestring);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+fclose(conf_dialrule_fp);
|
|
|
+fclose(conf_ivr_fp);
|
|
|
+fclose(conf_inbound_fp);
|
|
|
+fclose(conf_global_fp);
|
|
|
+fclose(conf_calltrigger_fp);
|
|
|
+fclose(conf_featurecodes_fp);
|
|
|
+fclose(conf_sip_nat_fp);
|
|
|
+fclose(conf_sipsetting_fp);
|
|
|
+mysql_free_result(g_res); // 释放结果集
|
|
|
+mysql_close(g_conn); // 关闭链接
|
|
|
+cJSON_Delete(pJson);
|
|
|
+}
|
|
|
+
|