stc-broadcast.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. package broadcast
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "io"
  7. "net"
  8. "net/http"
  9. "os"
  10. "pbx-api-gin/internal/app/ami/action"
  11. "pbx-api-gin/internal/app/ami/model"
  12. "pbx-api-gin/internal/app/stc/active"
  13. msgdata "pbx-api-gin/internal/app/stc/data"
  14. "pbx-api-gin/internal/app/stc/priority"
  15. alstatus "pbx-api-gin/internal/app/stc/sendstatus"
  16. "pbx-api-gin/pkg/lfshook"
  17. "sort"
  18. "strconv"
  19. "strings"
  20. "sync"
  21. "time"
  22. "github.com/sirupsen/logrus"
  23. "gopkg.in/ini.v1"
  24. )
  25. func HandleStcCmd(ctx context.Context, conn net.Conn) {
  26. for {
  27. select {
  28. case <-ctx.Done():
  29. return
  30. default:
  31. var buf bytes.Buffer
  32. tmp := make([]byte, 1024)
  33. if conn != nil {
  34. n, err := conn.Read(tmp)
  35. if err != nil {
  36. if err != io.EOF {
  37. conn.Close()
  38. }
  39. return
  40. }
  41. buf.Write(tmp[:n])
  42. }
  43. for {
  44. packet, err := msgdata.ExtractPacket(&buf)
  45. if err != nil {
  46. break
  47. }
  48. go processPacket(packet)
  49. }
  50. }
  51. }
  52. }
  53. // 处理单个数据包(原 switch 逻辑迁移过来)
  54. func processPacket(packet []byte) {
  55. //check if Master role
  56. if !active.Master {
  57. lfshook.NewLogger().Logger.Infof("=========Not Master Role Ignore data=============")
  58. return
  59. }
  60. if len(packet) < 6 {
  61. fmt.Println("Invalid packet length")
  62. return
  63. }
  64. //for recv data log debug
  65. //if packet[5] != 0x03 && packet[5] != 0x0c && packet[5] != 0x01 {
  66. lfshook.NewLogger().Logger.Infof("Get data from STC ===============:%x", packet)
  67. //}
  68. //check if the cmd type is avtive
  69. if packet[5] == 0x03 { // ACTIVE
  70. Active([1]byte{packet[8]})
  71. return
  72. }
  73. switch packet[5] {
  74. case 0x01: //heartbeat
  75. //PAD-OCC异常情况处理
  76. if priority.OCCAnswer == 1 {
  77. //定时监测ICP queue 转到OCC queue, 避免异常情形下PAD进入ICP queue之后无法被接听
  78. resCaller, err := action.QueueStatus("0300", "") // check ICP queue, get entries
  79. if err != nil {
  80. lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
  81. return
  82. }
  83. if resCaller.Calls != "0" {
  84. sort.Slice(resCaller.Entrys, func(i, j int) bool {
  85. return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
  86. })
  87. for _, caller := range resCaller.Entrys {
  88. priority.ICPAnswer = 0
  89. lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
  90. //order by pos
  91. action.RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
  92. time.Sleep(time.Microsecond * 200) //200 ms delay
  93. }
  94. }
  95. //定时监测OCC queue, 避免异常情况下PAD 在OCC queue里面不能自动转到OCC
  96. res, err := action.QueueStatus("0301", "") // check OCC queue ,if empty PAD end
  97. if err != nil {
  98. lfshook.NewLogger().Infof("==OCC=QueueStatus==%+v", err)
  99. return
  100. }
  101. if res.Calls != "0" { //OCC queue is not empty
  102. // HangupAllLocalChan()
  103. lfshook.NewLogger().Infof("====Start OCC-PAD===next==%+v", res)
  104. if active.ActivedCab == "1" && action.ExtenStatus("1411") == "Idle" { //check active and OCC status
  105. time.Sleep(time.Second)
  106. PADChan := ""
  107. for _, chanEntry := range res.Entrys {
  108. lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
  109. if chanEntry.Position == "1" {
  110. PADChan = chanEntry.Channel
  111. break
  112. }
  113. }
  114. if PADChan != "" {
  115. alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
  116. go action.RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
  117. go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
  118. } else {
  119. lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
  120. }
  121. break
  122. } else if active.ActivedCab == "8" && action.ExtenStatus("1481") == "Idle" {
  123. time.Sleep(time.Second)
  124. PADChan := ""
  125. for _, chanEntry := range res.Entrys {
  126. lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
  127. if chanEntry.Position == "1" {
  128. PADChan = chanEntry.Channel
  129. break
  130. }
  131. }
  132. if PADChan != "" {
  133. alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
  134. go action.RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", "8") //PAD Page(OCC+ICPs)
  135. go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC1
  136. } else {
  137. lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
  138. }
  139. break
  140. }
  141. }
  142. }
  143. case 0x02: // STN
  144. if priority.CheckPriority("STN") {
  145. action.HangupRunningTask("STN") //STN interrupt other
  146. StationAnn(packet)
  147. } else {
  148. alstatus.PaStatus("", "STN", "refuse")
  149. }
  150. case 0x05: // SPC
  151. if priority.CheckPriority("SPC") {
  152. action.HangupRunningTask("SPC") //SPC interrupt other
  153. SpecialAnn(packet)
  154. } else {
  155. alstatus.PaStatus("", "SPC", "refuse")
  156. }
  157. case 0x06: // EMG
  158. if priority.CheckPriority("EMG") {
  159. action.HangupRunningTask("EMG") //EMG interrupt other
  160. EmgMsg(packet)
  161. } else {
  162. alstatus.PaStatus("", "EMG", "refuse")
  163. }
  164. case 0x07: // STOP
  165. AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
  166. case 0x08: // DCS
  167. if priority.CheckPriority("DCS") {
  168. action.HangupRunningTask("DCS") //DCS interrupt other
  169. DcsAnn(packet)
  170. } else {
  171. alstatus.PaStatus("", "DCS", "refuse")
  172. }
  173. case 0x09: // SELF CHECK
  174. if priority.CheckPriority("CHK") {
  175. action.HangupRunningTask("CHK") //CHK interrupt other
  176. SelfCheck(packet)
  177. } else {
  178. alstatus.PaStatus("", "CHK", "refuse")
  179. }
  180. case 0x0a: // Tone-test
  181. if priority.CheckPriority("VOL") {
  182. action.HangupRunningTask("VOL") //VOL interrupt other
  183. ToneTest(packet)
  184. } else {
  185. alstatus.PaStatus("", "VOL", "refuse")
  186. }
  187. case 0x0e: //TMS answer PAD
  188. if priority.CheckPriority("PAD-TMS") {
  189. action.HangupRunningTask("PAD-TMS") //PAD-TMS interrupt other
  190. AlarmHandleTMS(packet)
  191. active.QueueTimer.Stop()
  192. } else {
  193. alstatus.PaStatus("", "PAD-TMS", "refuse")
  194. }
  195. case 0x0b: // reset all PAD
  196. AlarmHoldResetAll(packet[8]) // reset all pad
  197. case 0x0c: // recored config
  198. RecordStorageConf(packet[8:]) // RCD setting
  199. case 0x0d: // ICP answer PAD
  200. if priority.CheckPriority("PAD-ICP") {
  201. action.HangupRunningTask("PAD-ICP") //PAD-ICP interrupt other
  202. active.QueueTimer.Stop()
  203. AlarmHandleICP(packet) //
  204. } else {
  205. alstatus.PaStatus("", "PAD-ICP", "refuse")
  206. }
  207. default:
  208. fmt.Printf("Unknown command: %x\n", packet[5])
  209. }
  210. }
  211. // STN , 自动报站广播
  212. func StationAnn(data []byte) (err error) {
  213. specialVoice := int(data[8])
  214. delay := data[9]
  215. cycleCount := data[10]
  216. datalen := int(data[11])
  217. filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
  218. //set spc voice tag
  219. priority.SpecialVoice = specialVoice
  220. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "STN")
  221. return nil
  222. }
  223. // 激活信号
  224. func Active(data [1]byte) {
  225. //var info model.Sysinfo
  226. //active.Actived = true
  227. Signal := int(data[0])
  228. //lfshook.NewLogger().Logger.Infof("Active data : %x", Signal)
  229. switch Signal {
  230. case 0:
  231. //lfshook.NewLogger().Logger.Infof("=================Inactive==================")
  232. active.ActivedCab = ""
  233. action.InActiveHangup()
  234. case 1:
  235. active.ActivedCab = "1"
  236. //lfshook.NewLogger().Logger.Infof("=================active===MC1===============")
  237. if active.CabNum == "8" { // local cab is MC1
  238. action.InActiveHangup()
  239. }
  240. case 8:
  241. active.ActivedCab = "8"
  242. //lfshook.NewLogger().Logger.Infof("=================active===MC8===============")
  243. if active.CabNum == "1" { //Local cab is MC8
  244. action.InActiveHangup()
  245. }
  246. }
  247. }
  248. // SPC ,特殊服务消息广播
  249. func SpecialAnn(data []byte) {
  250. delay := data[8]
  251. cycleCount := data[9]
  252. datalen := int(data[10])
  253. filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
  254. if int(cycleCount) == 255 {
  255. action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "SPC")
  256. } else {
  257. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "SPC")
  258. }
  259. }
  260. // EMG ,紧急服务消息广播
  261. func EmgMsg(data []byte) {
  262. delay := data[8]
  263. cycleCount := data[9]
  264. datalen := int(data[10])
  265. filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
  266. if int(cycleCount) == 255 {
  267. action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "EMG")
  268. priority.ResumeEmgPara = priority.BroadcastResumeParas{FileName: filename, Count: 99999999, Delay: int(delay), BroadcastType: "EMG"}
  269. } else {
  270. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "EMG")
  271. }
  272. }
  273. // 停止指定类型广播
  274. func AnnStop(data [4]byte) {
  275. //PaType := ""
  276. lfshook.NewLogger().Logger.Infof("=AnnStop Type %x", data[0])
  277. switch data[0] {
  278. case 0x03:
  279. if priority.RunningType == "DCS" {
  280. action.HangupRunningTask("") //STOP DCS
  281. }
  282. case 0x04:
  283. if priority.RunningType == "EMG" {
  284. action.HangupRunningTask("AnnStop") //STOP EMG
  285. }
  286. case 0x07:
  287. if priority.RunningType == "SPC" {
  288. action.HangupRunningTask("AnnStop") //STOP SPC
  289. }
  290. case 0x08:
  291. if priority.RunningType == "STN" {
  292. action.HangupRunningTask("AnnStop") //STOP STN
  293. }
  294. case 0x09:
  295. if priority.RunningType == "CHK" {
  296. action.HangupRunningTask("AnnStop") //STOP CHK
  297. }
  298. case 0x0a:
  299. if priority.RunningType == "VOL" {
  300. action.HangupRunningTask("AnnStop") //STOP VOL
  301. }
  302. default:
  303. action.HangupRunningTask("AnnStop")
  304. }
  305. }
  306. // DCS 语音
  307. func DcsAnn(data []byte) {
  308. delay := data[8]
  309. cycleCount := data[9]
  310. datalen := int(data[10])
  311. filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
  312. if int(cycleCount) == 255 {
  313. action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "DCS")
  314. } else {
  315. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "DCS")
  316. }
  317. }
  318. // tone-test广播
  319. func ToneTest(data []byte) {
  320. check := data[8]
  321. delay := data[9]
  322. cycleCount := data[10]
  323. datalen := int(data[11])
  324. filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
  325. switch check {
  326. case 0x01: //start
  327. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "VOL")
  328. case 0x02: //stop
  329. //alstatus.PaStatus("", "VOL", "end")
  330. action.HangupAllExcept("")
  331. }
  332. }
  333. // 自检广播
  334. func SelfCheck(data []byte) {
  335. check := data[8]
  336. delay := data[9]
  337. //cycleCount := data[10]
  338. cycleCount := 0x32
  339. datalen := int(data[11])
  340. filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
  341. switch check {
  342. case 0x01: //start
  343. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "CHK")
  344. case 0x02: //stop
  345. //Pa status report
  346. priority.CleanPriorityTag()
  347. //alstatus.PaStatus("", "CHK", "end")
  348. action.HangupAllExcept("")
  349. }
  350. }
  351. // 全局变量:记录正在抑制的 exten
  352. var (
  353. suppressedExts = sync.Map{} // map[string]struct{},值存在即表示被抑制
  354. //suppressionMu sync.Mutex // 保护初始化和清理操作(可选)
  355. )
  356. // suppressKey 生成用于抑制的 key(可以根据需求扩展)
  357. func suppressKey(exten string, handler byte) string {
  358. return fmt.Sprintf("%s_h%x", exten, handler)
  359. }
  360. // ICP操作乘客报警(根据激活信息判断转到1车还是8车================)
  361. func AlarmHandleICP(data []byte) {
  362. handler := data[8]
  363. carr := data[12]
  364. pos := data[13]
  365. exten := fmt.Sprintf("24%c%c", carr, pos)
  366. key := suppressKey(exten, handler)
  367. //Drop other handler in 2 sec
  368. //PACUs---call---->ICP1
  369. //PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
  370. if handler == 0x01 {
  371. if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
  372. lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 4 seconds", exten)
  373. return
  374. }
  375. time.AfterFunc(4*time.Second, func() {
  376. suppressedExts.Delete(key)
  377. lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
  378. })
  379. }
  380. switch handler {
  381. case 0x01: //answer(ICP+Alarm+PACU)
  382. //NotifyPaiu(exten, "answer")
  383. priority.ICPAnswer = 1
  384. if priority.PADStart == 0 {
  385. alstatus.PaStatus(exten, "PAD", "start")
  386. priority.PADStart = 1
  387. }
  388. lfshook.NewLogger().Logger.Infof("================ICP Answer PAD================:%s ", exten)
  389. if active.ActivedCab == "1" {
  390. action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
  391. //goto ami event ConfbridgeJoin, ICP answer PAD
  392. } else if active.ActivedCab == "8" {
  393. action.Dial("0402", "0511", "pad-rule-pacus", "ani8", exten, "8") // PACUs dial ICP8
  394. //goto ami event ConfbridgeJoin, ICP answer PAD
  395. }
  396. case 0x02: //hold 重新放回队列里面
  397. NotifyPaiu(exten, "hold")
  398. err := action.RedirectInQueue(exten, "0300", "default", "1")
  399. if err != nil {
  400. lfshook.NewLogger().Info(err)
  401. }
  402. action.HangupAllLocalChan()
  403. case 0x03: //hangup
  404. //NotifyPaiu(exten, "hangup")
  405. action.Hangup(exten) //Pad
  406. action.HangupAllLocalChan()
  407. action.HangupICP()
  408. priority.CleanPriorityTag()
  409. }
  410. }
  411. // TMS操作乘客报警(根据激活信息判断转到1车还是8车================)
  412. func AlarmHandleTMS(data []byte) {
  413. handler := data[8]
  414. //extlen := data[9]
  415. carr := data[12]
  416. pos := data[13]
  417. exten := fmt.Sprintf("24%c%c", carr, pos)
  418. PacuNum := fmt.Sprintf("21%c%c", carr, pos)
  419. key := suppressKey(exten, handler)
  420. //Drop other handler in 2 sec
  421. // 只对 handler == 0x01 做 2 秒去重
  422. if handler == 0x01 {
  423. if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
  424. lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 4 seconds", exten)
  425. return // 已存在,说明在2秒窗口期内,直接丢弃
  426. }
  427. // 设置4秒后删除该 key,允许下次通过
  428. time.AfterFunc(4*time.Second, func() {
  429. suppressedExts.Delete(key)
  430. lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
  431. })
  432. }
  433. switch handler {
  434. case 0x01: //answer(ICP+Alarm+PACU)
  435. //PACU---call---->ICP1
  436. //PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
  437. if priority.PADStart == 0 {
  438. alstatus.PaStatus(exten, "PAD", "start")
  439. priority.PADStart = 1
  440. }
  441. priority.ICPAnswer = 1
  442. lfshook.NewLogger().Logger.Infof("================TMS Answer PAD:%s===PACU:%s==========", exten, PacuNum)
  443. if action.ExtenStatus(PacuNum) == "Idle" {
  444. if active.ActivedCab == "1" {
  445. action.Dial("0403", PacuNum, "default", PacuNum, exten, "1") // PACU dial ICP1
  446. //goto ami event BridgeEnter, ICP8 whisper ICP1
  447. } else if active.ActivedCab == "8" {
  448. action.Dial("0403", PacuNum, "default", PacuNum, exten, "8") // PACU dial ICP8
  449. //goto ami event BridgeEnter, ICP1 whisper ICP8
  450. }
  451. } else {
  452. action.RedirectInQueue(exten, "0405", "default", exten) // PAD dial ICPs
  453. }
  454. case 0x02: //hold 重新放回队列里面
  455. NotifyPaiu(exten, "hold")
  456. err := action.RedirectInQueue(exten, "0300", "default", "1")
  457. if err != nil {
  458. lfshook.NewLogger().Info(err)
  459. }
  460. action.HangupAllLocalChan()
  461. case 0x03: //hangup
  462. //NotifyPaiu(exten, "hangup")
  463. action.Hangup(exten) //Pad
  464. action.HangupAllLocalChan()
  465. action.HangupICP()
  466. priority.CleanPriorityTag()
  467. }
  468. }
  469. // 挂断所有报警器
  470. func NotifyPaiu(Exten, Action string) {
  471. url := ""
  472. switch Action {
  473. case "answer":
  474. url = fmt.Sprintf("http://10.0.24.%s/api/sipphone?action=answer", Exten[2:])
  475. case "hold":
  476. url = fmt.Sprintf("http://10.0.24.%s/api/sipphone?action=hold", Exten[2:])
  477. case "hangup":
  478. url = fmt.Sprintf("http://10.0.24.%s/api/sipphone?action=hangup", Exten[2:])
  479. }
  480. lfshook.NewLogger().Logger.Infof("======Notify PAIU Alarm====:%+v ", url)
  481. resp, err := http.Get(url)
  482. if err != nil {
  483. lfshook.NewLogger().Logger.Infof("======Notify PAIU Alarm====:%+v ", err)
  484. return
  485. }
  486. defer resp.Body.Close()
  487. /*
  488. body, err := io.ReadAll(resp.Body)
  489. if err != nil {
  490. // 读取数据错误
  491. lfshook.NewLogger().Warn("ioutil ReadAll failed :", err.Error())
  492. return
  493. }
  494. fmt.Printf("状态码: %d\n", resp.StatusCode)
  495. fmt.Printf("响应内容: %s\n", body)
  496. */
  497. }
  498. // 挂断所有报警器
  499. func AlarmHoldResetAll(handler byte) {
  500. //all hold
  501. //hangup all actived PAD
  502. action.HangupAllPAD()
  503. //hangup running task
  504. if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-OCC" || priority.RunningType == "PAD-TMS" {
  505. action.HangupRunningTask("AlarmHoldResetAll") //Reset PAD ALL
  506. priority.CleanPriorityTag()
  507. }
  508. }
  509. func RecordStorageConf(data []byte) {
  510. var info model.RcdConf
  511. info.PadRcdEnable = strconv.Itoa(int(data[0]))
  512. info.PadRcdStorageDays = strconv.Itoa(int(data[1]))
  513. info.PaRcdStorageDays = strconv.Itoa(int(data[2]))
  514. info.CpaRcdStorageDays = strconv.Itoa(int(data[3]))
  515. info.PadRcdDelDays = strconv.Itoa(int(data[4]))
  516. info.PaRcdDelDays = strconv.Itoa(int(data[5]))
  517. info.CpaRcdDelDays = strconv.Itoa(int(data[6]))
  518. //info.OpaRcdStorageDays = int(data[7])
  519. //info.OpaRcdDelDays = int(data[8])
  520. //lfshook.NewLogger().Infof("=============Set record Conf : %+v", info)
  521. filePath := "/etc/asterisk/recording.conf"
  522. _, err := os.Stat(filePath)
  523. if err != nil {
  524. logrus.Error(err)
  525. return
  526. }
  527. iniFile, err := ini.Load(filePath)
  528. if err != nil {
  529. logrus.Error(err)
  530. return
  531. }
  532. iniFile.Section("general").Key("PADRCD").SetValue(info.PadRcdEnable)
  533. iniFile.Section("general").Key("PADRCDDAYS").SetValue(info.PadRcdStorageDays)
  534. iniFile.Section("general").Key("PARCDDAYS").SetValue(info.PaRcdStorageDays)
  535. iniFile.Section("general").Key("CPARCDDAYS").SetValue(info.CpaRcdStorageDays)
  536. iniFile.Section("general").Key("PADRCDDELDAYS").SetValue(info.PadRcdDelDays)
  537. iniFile.Section("general").Key("PARCDDELDAYS").SetValue(info.PaRcdDelDays)
  538. iniFile.Section("general").Key("CPARCDDELDAYS").SetValue(info.CpaRcdDelDays)
  539. iniFile.SaveTo(filePath)
  540. }