/* ============================================================================ Name : generate_trunk_conf.sh Author : ssc Version : v1.0 Copyright : ZYCOO copyright Description : Generate trunk info from mysql to turnk conf file ============================================================================ */ #include #include #include #include #include #include #include #include #include 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_SETTINGS_FILE "/etc/asterisk/pjsip_transports.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 * 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; char sip_udp_nat[2048], sip_tcp_nat[2048], sip_tls_nat[2048], localnet[1792]; 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\ exten => %s,1,NoOp(%s)\n",\ g_row[1],\ 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,Gosub(stdexten,s,1(%s,PJSIP/%s))\n",keysObject[i].key,keysObject[i].exten,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"); } /* [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,Gosub(trunkdial-failover,s,1(${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_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_sipsetting_fp, ";!\n\ ;! Automatically generated configuration file\n\ ;! Filename: pjsip_transports.conf (/etc/asterisk/pjsip_transports.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,Gosub(stdexten,s,1(%s,PJSIP/%s))\n\ [direct-voip]\n\ exten => direct,1,Gosub(stdexten,s,1(%s,PJSIP/%s))\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, "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){ memset(sip_udp_nat, 0, sizeof(sip_udp_nat)); memset(sip_tcp_nat, 0, sizeof(sip_tcp_nat)); memset(sip_tls_nat, 0, sizeof(sip_tls_nat)); memset(localnet, 0, sizeof(localnet)); 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 ; } sprintf(localnet, "\ local_net = %s\n\ ",\ pSub->valuestring\ ); } } sprintf(sip_udp_nat, "\ external_media_address = %s\n\ external_signaling_address = %s\n\ %s\n\ ",\ cJSON_GetObjectItem(pJson, "externaddr")->valuestring,\ cJSON_GetObjectItem(pJson, "externhost")->valuestring,\ localnet\ ); if(cJSON_GetObjectItem(pJson, "externtcpport") && cJSON_GetObjectItem(pJson, "externtcpport")->valueint != 0) { sprintf(sip_tcp_nat, "\ external_media_address = %s\n\ external_signaling_address = %s\n\ external_signaling_port = %d\n\ %s\n\ ",\ cJSON_GetObjectItem(pJson, "externaddr")->valuestring,\ cJSON_GetObjectItem(pJson, "externhost")->valuestring,\ cJSON_GetObjectItem(pJson, "externtcpport")->valueint,\ localnet\ ); } if(cJSON_GetObjectItem(pJson, "externtlsport") && cJSON_GetObjectItem(pJson, "externtlsport")->valueint != 0) { sprintf(sip_tls_nat, "\ external_media_address = %s\n\ external_signaling_address = %s\n\ external_signaling_port = %d\n\ %s\n\ ",\ cJSON_GetObjectItem(pJson, "externaddr")->valuestring,\ cJSON_GetObjectItem(pJson, "externhost")->valuestring,\ cJSON_GetObjectItem(pJson, "externtlsport")->valueint,\ localnet\ ); } } } 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,Gosub(calltrigger,s,1(${EXTEN}))\n\ exten => _%s.,1,Gosub(calltrigger,s,1(${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, "\ [transport-udp]\n\ type=transport\n\ protocol=udp\n\ bind=0.0.0.0:%d\n\ tos=CS3\n\ cos=3\n\ allow_reload=no\n\ ",cJSON_GetObjectItem(pJson, "udp")->valueint\ ); if(sip_udp_nat) { fprintf(conf_sipsetting_fp, "%s", sip_udp_nat); } } pSub = cJSON_GetObjectItem(pJson, "tcp"); if(pSub && cJSON_GetObjectItem(pSub, "enable")->valueint == 1){ fprintf(conf_sipsetting_fp, "\ [transport-tcp]\n\ type=transport\n\ protocol=tcp\n\ bind=0.0.0.0:%d\n\ tos=CS3\n\ cos=3\n\ allow_reload=no\n\ ",cJSON_GetObjectItem(pSub, "port")->valueint\ ); if(sip_tcp_nat) { fprintf(conf_sipsetting_fp, "%s", sip_tcp_nat); } } pSub = cJSON_GetObjectItem(pJson, "tls"); if(pSub && cJSON_GetObjectItem(pSub, "enable")->valueint == 1){ fprintf(conf_sipsetting_fp, "\ [transport-tls]\n\ type=transport\n\ protocol=tls\n\ bind=0.0.0.0:%d\n\ cert_file=/etc/asterisk/keys/asterisk.pem\n\ ca_list_file=/etc/asterisk/keys/ca.crt\n\ priv_key_file=/etc/asterisk/keys/asterisk.pem\n\ method=tlsv1_3\n\ tos=CS3\n\ cos=3\n\ allow_reload=no\n\ ",cJSON_GetObjectItem(pSub, "port")->valueint\ ); if(sip_tls_nat) { fprintf(conf_sipsetting_fp, "%s", sip_tls_nat); } } fprintf(conf_sipsetting_fp, "\ [transport-wss]\n\ type=transport\n\ protocol=wss\n\ bind=0.0.0.0\n\ allow_reload=no\n\ "); 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,Gosub(spy-barge,s,1(${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,Gosub(exten-clear,s,1(${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,Gosub(spy-normal,s,1(${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,Gosub(spy-whisper,s,1(${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,Gosub(wakeup-call,s,1(${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_sipsetting_fp); mysql_free_result(g_res); // 释放结果集 mysql_close(g_conn); // 关闭链接 cJSON_Delete(pJson); }