conf_handle.sh 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271
  1. #!/usr/bin/python
  2. import configparser
  3. import ruamel.yaml
  4. import sys
  5. import json
  6. import re
  7. import os
  8. import time
  9. SYSTEM_CONF_PATH=["/etc/speaker.conf", "/oem/etc/volctrl.conf", "/oem/etc/schedule.conf", "/oem/.record/firmware_url"]
  10. TMPFILE="/tmp/conf"
  11. origin_keys = {
  12. "system": [
  13. "firmware",
  14. "hard_version",
  15. "model",
  16. "ui_model"
  17. ],
  18. "account_info_p2p": [
  19. "transport",
  20. "allowanoymous"
  21. ],
  22. "secret": [
  23. "ui_username"
  24. ],
  25. "upgrade": [
  26. "reset_default",
  27. "date"
  28. ],
  29. "volume": [
  30. "hard_volume_control"
  31. ]
  32. }
  33. comment_data = {
  34. 'system': {
  35. 'system': {
  36. 'cn': '系统设置.',
  37. 'en': 'System Settings.'
  38. },
  39. 'language': {
  40. 'cn': '系统语音语言. 值:cn | en',
  41. 'en': 'System voice language. Value: cn | en',
  42. 'check': {
  43. 'type': 'string',
  44. 'empty': False,
  45. 'method': 'enums',
  46. 'data_enums': ['cn', 'en']
  47. }
  48. },
  49. 'broadcast_service': {
  50. 'cn': 'IP Audio Center服务开启. 值:yes | no',
  51. 'en': 'Enable IP Audio Center Service. Value: yes | no',
  52. 'check': {
  53. 'type': 'bool',
  54. 'empty': False,
  55. 'relate': True,
  56. 'data_relate': {
  57. 'yes': {
  58. 'account_info_1': [
  59. 'server',
  60. 'port',
  61. 'username',
  62. 'authuser',
  63. 'reg_expires',
  64. 'transport',
  65. 'enable'
  66. ]
  67. }
  68. }
  69. }
  70. },
  71. 'ip_assign': {
  72. 'cn': '系统IP获取方式. 值:static | dhcp',
  73. 'en': 'System IP get mode. Value: static | dhcp',
  74. 'check': {
  75. 'type': 'string',
  76. 'empty': False,
  77. 'relate': True,
  78. 'data_relate': {
  79. 'static': {
  80. 'system': [
  81. 'ipaddr',
  82. 'netmask',
  83. 'gateway',
  84. 'dns1'
  85. ]
  86. }
  87. },
  88. 'method': 'enums',
  89. 'data_enums': ['static', 'dhcp']
  90. }
  91. },
  92. 'ipaddr': {
  93. 'cn': '系统IP地址. 例: 192.168.1.100',
  94. 'en': 'System IP address. el: 192.168.1.100',
  95. 'check': {
  96. 'type': 'string',
  97. 'method': 'regex_ip'
  98. }
  99. },
  100. 'netmask': {
  101. 'cn': '子网掩码. 例:255.255.255.0',
  102. 'en': 'Subnet mask. el: 255.255.255.0',
  103. 'check': {
  104. 'type': 'string',
  105. 'method': 'regex_ip'
  106. }
  107. },
  108. 'gateway': {
  109. 'cn': '系统网络网关地址 例:192.168.1.1',
  110. 'en': 'System gateway ip address. el: 192.168.1.1',
  111. 'check': {
  112. 'type': 'string',
  113. 'method': 'regex_ip'
  114. }
  115. },
  116. 'dns1': {
  117. 'cn': '系统主dns地址. 例: 114.114.114.114',
  118. 'en': 'System Primary DNS address. el: 114.114.114.114',
  119. 'check': {
  120. 'type': 'string',
  121. 'method': 'regex_ip'
  122. }
  123. },
  124. 'dns2': {
  125. 'cn': '系统备dns地址. 例: 8.8.8.8',
  126. 'en': 'System Alternative DNS address. el: 8.8.8.8',
  127. 'check': {
  128. 'type': 'string',
  129. 'method': 'regex_ip'
  130. }
  131. },
  132. 'enable_ntp': {
  133. 'cn': '启动NTP服务(系统自动获取网络时间) 值:yes | no',
  134. 'en': 'Enanle NTP service(Auto get system time from network). Vlaue: yes | no',
  135. 'check': {
  136. 'type': 'bool',
  137. 'empty': False,
  138. 'relate': True,
  139. 'data_relate': {
  140. 'yes': {
  141. 'system': [
  142. 'ntpserver',
  143. 'timezone',
  144. 'tzname'
  145. ]
  146. }
  147. }
  148. }
  149. },
  150. 'ntpserver': {
  151. 'cn': 'NTP服务器地址. 例: pool.ntp.org',
  152. 'en': 'NTP server address. el: pool.ntp.org',
  153. 'check': {
  154. 'type': 'string',
  155. 'method': 'regex_domain'
  156. }
  157. },
  158. 'timezone': {
  159. 'cn': '系统时区 例: CST-8',
  160. 'en': 'System time zone. el: CST-8',
  161. 'check': {
  162. 'type': 'string',
  163. 'method': 'default'
  164. }
  165. },
  166. 'tzname': {
  167. 'cn': '系统时区名 例: Asia/Chongqing',
  168. 'en': 'System time zone name. el: Asia/chongqing',
  169. 'check': {
  170. 'type': 'string',
  171. 'method': 'default'
  172. }
  173. },
  174. 'location': {
  175. 'cn': '系统备注信息 例: Confrence intercom',
  176. 'en': 'System mark information. el: Confrence intercom',
  177. 'check': {
  178. 'type': 'string',
  179. 'method': 'default'
  180. }
  181. },
  182. 'access_type': {
  183. 'cn': 'WEB UI访问协议 值:0 | 1 | 2. 例: 1 (http)',
  184. 'en': 'WEB UI access protocol. Value: 0 | 1 | 2. el: 1 (http)',
  185. 'check': {
  186. 'type': 'string',
  187. 'empty': False,
  188. 'method': 'enums',
  189. 'data_enums': ['0', '1', '2']
  190. }
  191. },
  192. 'route': {
  193. 'cn': '系统默认路由 值:local | pppoe. 例: local',
  194. 'en': 'System default route. Value: local | pppoe. el: pppoe',
  195. 'check': {
  196. 'type': 'string',
  197. 'empty': False,
  198. 'method': 'enums',
  199. 'data_enums': ['local', 'pppoe']
  200. }
  201. }
  202. },
  203. 'account_info_1': {
  204. 'account_info_1': {
  205. 'cn': '主SIP账号配置.',
  206. 'en': 'Primary SIP Account Settings.'
  207. },
  208. 'server': {
  209. 'cn': 'SIP服务器地址.',
  210. 'en': 'SIP server address.',
  211. 'check': {
  212. 'type': 'string',
  213. 'method': 'regex_domain'
  214. }
  215. },
  216. 'port': {
  217. 'cn': 'SIP服务器端口. 范围: 1 - 65535. 例: 5060',
  218. 'en': 'System server port. range: 1 - 65535. el: 5060',
  219. 'check': {
  220. 'type': 'int',
  221. 'method': 'range',
  222. 'range': {
  223. 'start': 1,
  224. 'end': 65535
  225. }
  226. }
  227. },
  228. 'username': {
  229. 'cn': 'SIP用户名.',
  230. 'en': 'SIP username.',
  231. 'check': {
  232. 'type': 'string',
  233. 'method': 'regex_username'
  234. }
  235. },
  236. 'authuser': {
  237. 'cn': 'SIP认证用户.',
  238. 'en': 'SIP Auth user.',
  239. 'check': {
  240. 'type': 'string',
  241. 'method': 'regex_username'
  242. }
  243. },
  244. 'passwd': {
  245. 'cn': 'SIP账号密码.',
  246. 'en': 'SIP account password.',
  247. 'check': {
  248. 'type': 'string',
  249. 'method': 'default'
  250. }
  251. },
  252. 'enable': {
  253. 'cn': '启用此SIP账号. 值: yes | no',
  254. 'en': 'Enable SIP account. Value: yes | no',
  255. 'check': {
  256. 'type': 'bool',
  257. 'empty': False,
  258. 'relate': True,
  259. 'data_relate': {
  260. 'yes': {
  261. 'account_info_1': [
  262. 'server',
  263. 'port',
  264. 'username',
  265. 'authuser',
  266. 'reg_expires',
  267. 'transport'
  268. ]
  269. }
  270. }
  271. }
  272. },
  273. 'reg_expires': {
  274. 'cn': '注册过期时间(秒). 范围: 1 - 3600. 例: 180',
  275. 'en': 'Register expires(Seconds). range: 1 - 3600. el: 180',
  276. 'check': {
  277. 'type': 'int',
  278. 'method': 'range',
  279. 'range': {
  280. 'start': 1,
  281. 'end': 3600
  282. }
  283. }
  284. },
  285. 'transport': {
  286. 'cn': '网络传输协议. 值: udp | tcp | tls',
  287. 'en': 'Network transmission protocol. Value: udp | tcp | tls',
  288. 'check': {
  289. 'type': 'string',
  290. 'method': 'enums',
  291. 'data_enums': ['udp', 'tcp', 'tls']
  292. }
  293. },
  294. 'autoanswer': {
  295. 'cn': '自动接听. 值:yes | no | 10 (延迟10秒应答)',
  296. 'en': 'Auto Answer. Value: yes | no | 10 (delay 10 Seconds answer)',
  297. 'check': {
  298. 'type': 'string',
  299. 'empty': False,
  300. 'relate': True,
  301. 'data_relate': {
  302. 'yes': {},
  303. 'no': {
  304. 'account_info_1': [
  305. 'ringfile'
  306. ]
  307. },
  308. 'default': {
  309. 'account_info_1': [
  310. 'ringfile'
  311. ]
  312. }
  313. },
  314. 'method': 'default'
  315. }
  316. },
  317. 'ringfile': {
  318. 'cn': '来电铃声. 例: sweet.wav',
  319. 'en': 'Ring. el: sweet.wav',
  320. 'check': {
  321. 'type': 'string',
  322. 'method': 'enums',
  323. 'data_enums': [
  324. 'alarm_tone0.wav',
  325. 'alarm_tone1.wav',
  326. 'alarm_tone2.wav',
  327. 'bell_burglar_ring.wav',
  328. 'bells_music_tone.wav',
  329. 'bigben.wav',
  330. 'digital_telephone.wav',
  331. 'emergency_alarm_tone.wav',
  332. 'emergency_beep_tone.wav',
  333. 'oldphone.wav',
  334. 'ring.wav',
  335. 'special_music_tone.wav',
  336. 'sweet.wav',
  337. 'toy.wav',
  338. '1.wav',
  339. '2.wav',
  340. '3.wav',
  341. '4.wav',
  342. '5.wav'
  343. ]
  344. }
  345. },
  346. 'nat_mode': {
  347. 'cn': 'NAT模式. 值: disabled | stun | turn | ice',
  348. 'en': 'NAT Mode. Value: disabled | stun | turn | ice',
  349. 'check': {
  350. 'type': 'string',
  351. 'method': 'enums',
  352. 'data_enums': [
  353. 'disabled',
  354. 'stun',
  355. 'turn',
  356. 'ice'
  357. ]
  358. }
  359. },
  360. 'stun_server': {
  361. 'cn': '服务器地址.',
  362. 'en': 'Server address.',
  363. 'check': {
  364. 'type': 'string',
  365. 'method': 'regex_domain'
  366. }
  367. },
  368. 'stun_port': {
  369. 'cn': '服务器端口. 范围: 1 - 65535. 例: 3478',
  370. 'en': 'Server port. range: 1 - 65535. el: 3478',
  371. 'check': {
  372. 'type': 'int',
  373. 'method': 'range',
  374. 'range': {
  375. 'start': 1,
  376. 'end': 65535
  377. }
  378. }
  379. },
  380. 'nat_username': {
  381. 'cn': 'NAT用户名.',
  382. 'en': 'NAT username.',
  383. 'check': {
  384. 'type': 'string',
  385. 'method': 'default'
  386. }
  387. },
  388. 'nat_password': {
  389. 'cn': 'NAT账号密码.',
  390. 'en': 'NAT account password.',
  391. 'check': {
  392. 'type': 'string',
  393. 'method': 'default'
  394. }
  395. }
  396. },
  397. 'account_info_2': {
  398. 'account_info_2': {
  399. 'cn': '备SIP账号1配置.',
  400. 'en': 'Secondary SIP Account-1 Settings.'
  401. },
  402. 'server': {
  403. 'cn': 'SIP服务器地址.',
  404. 'en': 'SIP server address.',
  405. 'check': {
  406. 'type': 'string',
  407. 'method': 'regex_domain'
  408. }
  409. },
  410. 'port': {
  411. 'cn': 'SIP服务器端口. 范围: 1 - 65535. 例: 5060',
  412. 'en': 'System server port. range: 1 - 65535. el: 5060',
  413. 'check': {
  414. 'type': 'int',
  415. 'method': 'range',
  416. 'range': {
  417. 'start': 1,
  418. 'end': 65535
  419. }
  420. }
  421. },
  422. 'username': {
  423. 'cn': 'SIP用户名.',
  424. 'en': 'SIP username.',
  425. 'check': {
  426. 'type': 'string',
  427. 'method': 'regex_username'
  428. }
  429. },
  430. 'authuser': {
  431. 'cn': 'SIP认证用户.',
  432. 'en': 'SIP Auth user.',
  433. 'check': {
  434. 'type': 'string',
  435. 'method': 'regex_username'
  436. }
  437. },
  438. 'passwd': {
  439. 'cn': 'SIP账号密码.',
  440. 'en': 'SIP account password.',
  441. 'check': {
  442. 'type': 'string',
  443. 'method': 'default'
  444. }
  445. },
  446. 'enable': {
  447. 'cn': '启用此SIP账号. 值: yes | no',
  448. 'en': 'Enable SIP account. Value: yes | no',
  449. 'check': {
  450. 'type': 'bool',
  451. 'empty': False,
  452. 'relate': True,
  453. 'data_relate': {
  454. 'yes': {
  455. 'account_info_2': [
  456. 'server',
  457. 'port',
  458. 'username',
  459. 'authuser',
  460. 'reg_expires',
  461. 'transport'
  462. ]
  463. }
  464. }
  465. }
  466. },
  467. 'reg_expires': {
  468. 'cn': '注册过期时间(秒). 范围: 1 - 3600. 例: 180',
  469. 'en': 'Register expires(Seconds). range: 1 - 3600. el: 180',
  470. 'check': {
  471. 'type': 'int',
  472. 'method': 'range',
  473. 'range': {
  474. 'start': 1,
  475. 'end': 3600
  476. }
  477. }
  478. },
  479. 'transport': {
  480. 'cn': '网络传输协议. 值: udp | tcp | tls',
  481. 'en': 'Network transmission protocol. Value: udp | tcp | tls',
  482. 'check': {
  483. 'type': 'string',
  484. 'method': 'enums',
  485. 'data_enums': ['udp', 'tcp', 'tls']
  486. }
  487. },
  488. 'autoanswer': {
  489. 'cn': '自动接听. 值:yes | no | 10 (延迟10秒应答)',
  490. 'en': 'Auto Answer. Value: yes | no | 10 (delay 10 Seconds answer)',
  491. 'check': {
  492. 'type': 'string',
  493. 'empty': False,
  494. 'relate': True,
  495. 'data_relate': {
  496. 'yes': {},
  497. 'no': {
  498. 'account_info_2': [
  499. 'ringfile'
  500. ]
  501. },
  502. 'default': {
  503. 'account_info_2': [
  504. 'ringfile'
  505. ]
  506. }
  507. },
  508. 'method': 'default'
  509. }
  510. },
  511. 'ringfile': {
  512. 'cn': '来电铃声. 例: sweet.wav',
  513. 'en': 'Ring. el: sweet.wav',
  514. 'check': {
  515. 'type': 'string',
  516. 'method': 'enums',
  517. 'data_enums': [
  518. 'alarm_tone0.wav',
  519. 'alarm_tone1.wav',
  520. 'alarm_tone2.wav',
  521. 'bell_burglar_ring.wav',
  522. 'bells_music_tone.wav',
  523. 'bigben.wav',
  524. 'digital_telephone.wav',
  525. 'emergency_alarm_tone.wav',
  526. 'emergency_beep_tone.wav',
  527. 'oldphone.wav',
  528. 'ring.wav',
  529. 'special_music_tone.wav',
  530. 'sweet.wav',
  531. 'toy.wav',
  532. '1.wav',
  533. '2.wav',
  534. '3.wav',
  535. '4.wav',
  536. '5.wav'
  537. ]
  538. }
  539. },
  540. 'nat_mode': {
  541. 'cn': 'NAT模式. 值: disabled | stun | turn | ice',
  542. 'en': 'NAT Mode. Value: disabled | stun | turn | ice',
  543. 'check': {
  544. 'type': 'string',
  545. 'method': 'enums',
  546. 'data_enums': [
  547. 'disabled',
  548. 'stun',
  549. 'turn',
  550. 'ice'
  551. ]
  552. }
  553. },
  554. 'stun_server': {
  555. 'cn': '服务器地址.',
  556. 'en': 'Server address.',
  557. 'check': {
  558. 'type': 'string',
  559. 'method': 'regex_domain'
  560. }
  561. },
  562. 'stun_port': {
  563. 'cn': '服务器端口. 范围: 1 - 65535. 例: 3478',
  564. 'en': 'Server port. range: 1 - 65535. el: 3478',
  565. 'check': {
  566. 'type': 'int',
  567. 'method': 'range',
  568. 'range': {
  569. 'start': 1,
  570. 'end': 65535
  571. }
  572. }
  573. },
  574. 'nat_username': {
  575. 'cn': 'NAT用户名.',
  576. 'en': 'NAT username.',
  577. 'check': {
  578. 'type': 'string',
  579. 'method': 'default'
  580. }
  581. },
  582. 'nat_password': {
  583. 'cn': 'NAT账号密码.',
  584. 'en': 'NAT account password.',
  585. 'check': {
  586. 'type': 'string',
  587. 'method': 'default'
  588. }
  589. }
  590. },
  591. 'account_info_3': {
  592. 'account_info_3': {
  593. 'cn': '备SIP账号2配置.',
  594. 'en': 'Secondary SIP Account-2 Settings.'
  595. },
  596. 'server': {
  597. 'cn': 'SIP服务器地址.',
  598. 'en': 'SIP server address.',
  599. 'check': {
  600. 'type': 'string',
  601. 'method': 'regex_domain'
  602. }
  603. },
  604. 'port': {
  605. 'cn': 'SIP服务器端口. 范围: 1 - 65535. 例: 5060',
  606. 'en': 'System server port. range: 1 - 65535. el: 5060',
  607. 'check': {
  608. 'type': 'int',
  609. 'method': 'range',
  610. 'range': {
  611. 'start': 1,
  612. 'end': 65535
  613. }
  614. }
  615. },
  616. 'username': {
  617. 'cn': 'SIP用户名.',
  618. 'en': 'SIP username.',
  619. 'check': {
  620. 'type': 'string',
  621. 'method': 'regex_username'
  622. }
  623. },
  624. 'authuser': {
  625. 'cn': 'SIP认证用户.',
  626. 'en': 'SIP Auth user.',
  627. 'check': {
  628. 'type': 'string',
  629. 'method': 'regex_username'
  630. }
  631. },
  632. 'passwd': {
  633. 'cn': 'SIP账号密码.',
  634. 'en': 'SIP account password.',
  635. 'check': {
  636. 'type': 'string',
  637. 'method': 'default'
  638. }
  639. },
  640. 'enable': {
  641. 'cn': '启用此SIP账号. 值: yes | no',
  642. 'en': 'Enable SIP account. Value: yes | no',
  643. 'check': {
  644. 'type': 'bool',
  645. 'empty': False,
  646. 'relate': True,
  647. 'data_relate': {
  648. 'yes': {
  649. 'account_info_3': [
  650. 'server',
  651. 'port',
  652. 'username',
  653. 'authuser',
  654. 'reg_expires',
  655. 'transport'
  656. ]
  657. }
  658. }
  659. }
  660. },
  661. 'reg_expires': {
  662. 'cn': '注册过期时间(秒). 范围: 1 - 3600. 例: 180',
  663. 'en': 'Register expires(Seconds). range: 1 - 3600. el: 180',
  664. 'check': {
  665. 'type': 'int',
  666. 'method': 'range',
  667. 'range': {
  668. 'start': 1,
  669. 'end': 3600
  670. }
  671. }
  672. },
  673. 'transport': {
  674. 'cn': '网络传输协议. 值: udp | tcp | tls',
  675. 'en': 'Network transmission protocol. Value: udp | tcp | tls',
  676. 'check': {
  677. 'type': 'string',
  678. 'method': 'enums',
  679. 'data_enums': ['udp', 'tcp', 'tls']
  680. }
  681. },
  682. 'autoanswer': {
  683. 'cn': '自动接听. 值:yes | no | 10 (延迟10秒应答)',
  684. 'en': 'Auto Answer. Value: yes | no | 10 (delay 10 Seconds answer)',
  685. 'check': {
  686. 'type': 'string',
  687. 'empty': False,
  688. 'relate': True,
  689. 'data_relate': {
  690. 'yes': {},
  691. 'no': {
  692. 'account_info_3': [
  693. 'ringfile'
  694. ]
  695. },
  696. 'default': {
  697. 'account_info_3': [
  698. 'ringfile'
  699. ]
  700. }
  701. },
  702. 'method': 'default'
  703. }
  704. },
  705. 'ringfile': {
  706. 'cn': '来电铃声. 例: sweet.wav',
  707. 'en': 'Ring. el: sweet.wav',
  708. 'check': {
  709. 'type': 'string',
  710. 'method': 'enums',
  711. 'data_enums': [
  712. 'alarm_tone0.wav',
  713. 'alarm_tone1.wav',
  714. 'alarm_tone2.wav',
  715. 'bell_burglar_ring.wav',
  716. 'bells_music_tone.wav',
  717. 'bigben.wav',
  718. 'digital_telephone.wav',
  719. 'emergency_alarm_tone.wav',
  720. 'emergency_beep_tone.wav',
  721. 'oldphone.wav',
  722. 'ring.wav',
  723. 'special_music_tone.wav',
  724. 'sweet.wav',
  725. 'toy.wav',
  726. '1.wav',
  727. '2.wav',
  728. '3.wav',
  729. '4.wav',
  730. '5.wav'
  731. ]
  732. }
  733. },
  734. 'nat_mode': {
  735. 'cn': 'NAT模式. 值: disabled | stun | turn | ice',
  736. 'en': 'NAT Mode. Value: disabled | stun | turn | ice',
  737. 'check': {
  738. 'type': 'string',
  739. 'method': 'enums',
  740. 'data_enums': [
  741. 'disabled',
  742. 'stun',
  743. 'turn',
  744. 'ice'
  745. ]
  746. }
  747. },
  748. 'stun_server': {
  749. 'cn': '服务器地址.',
  750. 'en': 'Server address.',
  751. 'check': {
  752. 'type': 'string',
  753. 'method': 'regex_domain'
  754. }
  755. },
  756. 'stun_port': {
  757. 'cn': '服务器端口. 范围: 1 - 65535. 例: 3478',
  758. 'en': 'Server port. range: 1 - 65535. el: 3478',
  759. 'check': {
  760. 'type': 'int',
  761. 'method': 'range',
  762. 'range': {
  763. 'start': 1,
  764. 'end': 65535
  765. }
  766. }
  767. },
  768. 'nat_username': {
  769. 'cn': 'NAT用户名.',
  770. 'en': 'NAT username.',
  771. 'check': {
  772. 'type': 'string',
  773. 'method': 'default'
  774. }
  775. },
  776. 'nat_password': {
  777. 'cn': 'NAT账号密码.',
  778. 'en': 'NAT account password.',
  779. 'check': {
  780. 'type': 'string',
  781. 'method': 'default'
  782. }
  783. }
  784. },
  785. 'account_info_p2p': {
  786. 'account_info_p2p': {
  787. 'cn': 'P2P账号配置.',
  788. 'en': 'P2P account settings.'
  789. },
  790. 'username': {
  791. 'cn': 'p2p账号. 例: 1001',
  792. 'en': 'p2p account. el: 1001',
  793. 'check': {
  794. 'type': 'string',
  795. 'method': 'regex_username'
  796. }
  797. },
  798. 'enable': {
  799. 'cn': '启动p2p账号. 值:yes | no',
  800. 'en': 'Enable p2p account. Value: yes | no',
  801. 'check': {
  802. 'type': 'bool',
  803. 'empty': False,
  804. 'relate': True,
  805. 'data_relate': {
  806. 'yes': {
  807. 'account_info_p2p': [
  808. 'username',
  809. ]
  810. }
  811. }
  812. }
  813. },
  814. 'autoanswer': {
  815. 'cn': '自动接听. 值:yes | no | 10 (延迟10秒应答)',
  816. 'en': 'Auto Answer. Value: yes | no | 10 (delay 10 Seconds answer)',
  817. 'check': {
  818. 'type': 'string',
  819. 'empty': False,
  820. 'relate': True,
  821. 'data_relate': {
  822. 'yes': {},
  823. 'no': {
  824. 'account_info_p2p': [
  825. 'ringfile'
  826. ]
  827. },
  828. 'default': {
  829. 'account_info_p2p': [
  830. 'ringfile'
  831. ]
  832. }
  833. },
  834. 'method': 'default'
  835. }
  836. },
  837. 'ringfile': {
  838. 'cn': '来电铃声. 例: sweet.wav',
  839. 'en': 'Ring. el: sweet.wav',
  840. 'check': {
  841. 'type': 'string',
  842. 'method': 'enums',
  843. 'data_enums': [
  844. 'alarm_tone0.wav',
  845. 'alarm_tone1.wav',
  846. 'alarm_tone2.wav',
  847. 'bell_burglar_ring.wav',
  848. 'bells_music_tone.wav',
  849. 'bigben.wav',
  850. 'digital_telephone.wav',
  851. 'emergency_alarm_tone.wav',
  852. 'emergency_beep_tone.wav',
  853. 'oldphone.wav',
  854. 'ring.wav',
  855. 'special_music_tone.wav',
  856. 'sweet.wav',
  857. 'toy.wav',
  858. '1.wav',
  859. '2.wav',
  860. '3.wav',
  861. '4.wav',
  862. '5.wav'
  863. ]
  864. }
  865. }
  866. },
  867. 'sip_advance': {
  868. 'sip_advance': {
  869. 'cn': 'SIP高级设置.',
  870. 'en': 'Advance SIP Settings.'
  871. },
  872. 'localport': {
  873. 'cn': 'SIP本地端口. 范围: 1 - 65535. 例: 5060',
  874. 'en': 'System local port. range: 1 - 65535. el: 5060',
  875. 'check': {
  876. 'type': 'int',
  877. 'empty': False,
  878. 'method': 'range',
  879. 'range': {
  880. 'start': 1,
  881. 'end': 65535
  882. }
  883. }
  884. },
  885. 'rtpstartport': {
  886. 'cn': 'RTP开始端口. 范围: 1 - 65535. 例: 5060',
  887. 'en': 'RTP start port. range: 1 - 65535. el: 5060',
  888. 'check': {
  889. 'type': 'int',
  890. 'empty': False,
  891. 'method': 'range',
  892. 'range': {
  893. 'start': 1,
  894. 'end': 65535
  895. }
  896. }
  897. },
  898. 'rtpendport': {
  899. 'cn': 'RTP结束端口. 范围: 1 - 65535. 例: 5060',
  900. 'en': 'RTP end port. range: 1 - 65535. el: 5060',
  901. 'check': {
  902. 'type': 'int',
  903. 'empty': False,
  904. 'method': 'range',
  905. 'range': {
  906. 'start': 1,
  907. 'end': 65535
  908. }
  909. }
  910. },
  911. 'rtptimeout': {
  912. 'cn': 'RTP超时时间(秒). 范围: 1 - 3600. 例: 60',
  913. 'en': 'RTP timeout(Seconds) range: 1 - 3600. el: 60',
  914. 'check': {
  915. 'type': 'int',
  916. 'empty': False,
  917. 'method': 'range',
  918. 'range': {
  919. 'start': 1,
  920. 'end': 3600
  921. }
  922. }
  923. }
  924. },
  925. 'codec': {
  926. 'codec': {
  927. 'cn': '音频编码设置.',
  928. 'en': 'Audio Codecs Settings.'
  929. },
  930. 'g722': {
  931. 'cn': '开启G722编码. 值: yes | no',
  932. 'en': 'Enable G722 codec. Value: yes | no',
  933. 'check': {
  934. 'type': 'bool',
  935. 'empty': False,
  936. }
  937. },
  938. 'alaw': {
  939. 'cn': '开启G711(alaw)编码. 值: yes | no',
  940. 'en': 'Enable G711(alaw) codec. Value: yes | no',
  941. 'check': {
  942. 'type': 'bool',
  943. 'empty': False,
  944. }
  945. },
  946. 'ulaw': {
  947. 'cn': '开启G711(ulaw)编码. 值: yes | no',
  948. 'en': 'Enable G711(ulaw) codec. Value: yes | no',
  949. 'check': {
  950. 'type': 'bool',
  951. 'empty': False,
  952. }
  953. },
  954. 'opus': {
  955. 'cn': '开启OPUS编码. 值: yes | no',
  956. 'en': 'Enable OPUS codec. Value: yes | no',
  957. 'check': {
  958. 'type': 'bool',
  959. 'empty': False,
  960. }
  961. }
  962. },
  963. 'intercom': {
  964. 'intercom': {
  965. 'cn': '对讲及拨号设置.',
  966. 'en': 'Press to talk Settings.'
  967. },
  968. 'onekey_num': {
  969. 'cn': '一键对讲号码. 例: 101',
  970. 'en': 'One-key intercom number. el: 101',
  971. 'check': {
  972. 'type': 'string',
  973. 'method': 'regex_username'
  974. }
  975. },
  976. 'onekey_1_num': {
  977. 'cn': '一键对讲号码 1. 例: 101',
  978. 'en': 'One-key intercom number 1. el: 101',
  979. 'check': {
  980. 'type': 'string',
  981. 'method': 'regex_username'
  982. }
  983. },
  984. 'onekey_2_num': {
  985. 'cn': '一键对讲号码 2. 例: 102',
  986. 'en': 'One-key intercom number 2. el: 102',
  987. 'check': {
  988. 'type': 'string',
  989. 'method': 'regex_username'
  990. }
  991. },
  992. 'onekey_line': {
  993. 'cn': '一键呼出线路. 值: auto | account_info_1 | account_info_2 | account_info_3 | p2p',
  994. 'en': 'One-key outgoing line. Value: auto | account_info_1 | account_info_2 | account_info_3 | p2p',
  995. 'check': {
  996. 'type': 'string',
  997. 'method': 'enums',
  998. 'data_enums': [
  999. 'auto',
  1000. 'account_info_1',
  1001. 'account_info_2',
  1002. 'account_info_3',
  1003. 'p2p'
  1004. ]
  1005. }
  1006. },
  1007. 'onekey_1_line': {
  1008. 'cn': '号码1呼出线路. 值: auto | account_info_1 | account_info_2 | account_info_3 | p2p',
  1009. 'en': 'One-key outgoing line. Value: auto | account_info_1 | account_info_2 | account_info_3 | p2p',
  1010. 'check': {
  1011. 'type': 'string',
  1012. 'method': 'enums',
  1013. 'data_enums': [
  1014. 'auto',
  1015. 'account_info_1',
  1016. 'account_info_2',
  1017. 'account_info_3',
  1018. 'p2p'
  1019. ]
  1020. }
  1021. },
  1022. 'onekey_2_line': {
  1023. 'cn': '号码2呼出线路. 值: auto | account_info_1 | account_info_2 | account_info_3 | p2p',
  1024. 'en': 'One-key outgoing line. Value: auto | account_info_1 | account_info_2 | account_info_3 | p2p',
  1025. 'check': {
  1026. 'type': 'string',
  1027. 'method': 'enums',
  1028. 'data_enums': [
  1029. 'auto',
  1030. 'account_info_1',
  1031. 'account_info_2',
  1032. 'account_info_3',
  1033. 'p2p'
  1034. ]
  1035. }
  1036. },
  1037. 'repress_cancel': {
  1038. 'cn': '再次按键取消呼叫. 值:yes | no',
  1039. 'en': 'Press again to cancel the call. Value: yes | no',
  1040. 'check': {
  1041. 'type': 'bool',
  1042. 'empty': False,
  1043. }
  1044. }
  1045. },
  1046. 'input_detect': {
  1047. 'input_detect': {
  1048. 'cn': '输入口设置.',
  1049. 'en': 'Sensor Settings.'
  1050. },
  1051. 'enable': {
  1052. 'cn': '启动输入检测. 值:yes | no',
  1053. 'en': 'Enable input check. Value: yes | no',
  1054. 'check': {
  1055. 'type': 'bool',
  1056. 'empty': False,
  1057. 'relate': True,
  1058. 'data_relate': {
  1059. 'yes': {
  1060. 'input_detect': [
  1061. 'level'
  1062. ]
  1063. }
  1064. }
  1065. }
  1066. },
  1067. 'level': {
  1068. 'cn': '触发模式(上升沿触发或下降沿触发). 值:low | high',
  1069. 'en': 'Trigger mode (rising edge trigger or falling edge trigger). Value: cn | en',
  1070. 'check': {
  1071. 'type': 'string',
  1072. 'method': 'enums',
  1073. 'data_enums': ['low', 'high']
  1074. }
  1075. },
  1076. 'trigger_dial_enable': {
  1077. 'cn': '启动触发拨号 值:yes | no',
  1078. 'en': 'Enable trigger dial. Value: yes | no',
  1079. 'check': {
  1080. 'type': 'bool',
  1081. 'empty': False,
  1082. 'relate': True,
  1083. 'data_relate': {
  1084. 'yes': {
  1085. 'input_detect': [
  1086. 'trigger_num'
  1087. ]
  1088. }
  1089. }
  1090. }
  1091. },
  1092. 'trigger_num': {
  1093. 'cn': '触发拨号的目的号码 例: 101',
  1094. 'en': 'The destination number that triggers the dialing. el: 101',
  1095. 'check': {
  1096. 'type': 'string',
  1097. 'method': 'regex_username'
  1098. }
  1099. },
  1100. 'trigger_line': {
  1101. 'cn': '呼出线路. 值: auto | account_info_1 | account_info_2 | account_info_3 | p2p',
  1102. 'en': 'Outgoing line. Value: auto | account_info_1 | account_info_2 | account_info_3 | p2p',
  1103. 'check': {
  1104. 'type': 'string',
  1105. 'method': 'enums',
  1106. 'data_enums': [
  1107. 'auto',
  1108. 'account_info_1',
  1109. 'account_info_2',
  1110. 'account_info_3',
  1111. 'p2p'
  1112. ]
  1113. }
  1114. }
  1115. },
  1116. 'output': {
  1117. 'output': {
  1118. 'cn': '输出口设置.',
  1119. 'en': 'Relay Control Settings.'
  1120. },
  1121. 'mode': {
  1122. 'cn': '触发模式. 值: delay | hangup | answered',
  1123. 'en': 'Trigger mode. Value: delay | hangup | answered',
  1124. 'check': {
  1125. 'type': 'string',
  1126. 'empty': False,
  1127. 'method': 'enums',
  1128. 'data_enums': ['delay', 'hangup', 'answered']
  1129. }
  1130. },
  1131. 'duration': {
  1132. 'cn': '持续时间(秒). 范围: 1 - 600 例: 10',
  1133. 'en': 'Duration(Seconds). range: 1 - 600 el: 10',
  1134. 'check': {
  1135. 'type': 'int',
  1136. 'empty': False,
  1137. 'method': 'range',
  1138. 'range': {
  1139. 'start': 1,
  1140. 'end': 600
  1141. }
  1142. }
  1143. },
  1144. 'type': {
  1145. 'cn': '触发类型. 值: On | FastFlashing | SlowFlashing',
  1146. 'en': 'Trigger type. Value: On | FastFlashing | SlowFlashing',
  1147. 'check': {
  1148. 'type': 'string',
  1149. 'empty': False,
  1150. 'method': 'enums',
  1151. 'data_enums': ['On', 'FastFlashing', 'SlowFlashing']
  1152. }
  1153. }
  1154. },
  1155. 'trigger': {
  1156. 'trigger': {
  1157. 'cn': '触发设置.',
  1158. 'en': 'Trigger Settings.'
  1159. },
  1160. 'input': {
  1161. 'cn': '启动输入触发. 值: yes | no',
  1162. 'en': 'Enable input trigger. Value: yes | no',
  1163. 'check': {
  1164. 'type': 'string',
  1165. 'empty': False,
  1166. }
  1167. },
  1168. 'dtmf': {
  1169. 'cn': '启动DTMF触发. 值: yes | no',
  1170. 'en': 'Enable DTMF trigger. Value: yes | no',
  1171. 'check': {
  1172. 'type': 'bool',
  1173. 'empty': False,
  1174. 'relate': True,
  1175. 'data_relate': {
  1176. 'yes': {
  1177. 'trigger': [
  1178. 'dtmf_code'
  1179. ]
  1180. }
  1181. }
  1182. }
  1183. },
  1184. 'dtmf_code': {
  1185. 'cn': 'DTMF触发特征码. 例: 1*',
  1186. 'en': 'DTMF trigger feature code. Value: 1*',
  1187. 'check': {
  1188. 'type': 'string',
  1189. 'method': 'regex_dtmf'
  1190. }
  1191. },
  1192. 'call_state': {
  1193. 'cn': '启动通话状态触发. 值: yes | no',
  1194. 'en': 'Enable Call State trigger. Value: yes | no',
  1195. 'check': {
  1196. 'type': 'bool',
  1197. 'empty': False,
  1198. 'relate': True,
  1199. 'data_relate': {
  1200. 'yes': {
  1201. 'trigger': [
  1202. 'state_info'
  1203. ]
  1204. }
  1205. }
  1206. }
  1207. },
  1208. 'state_info': {
  1209. 'cn': '设定触发的通话状态. 值: outgoing | incoming | hangup | both | answered',
  1210. 'en': 'Set the triggered call status. Value: outgoing | incoming | hangup | both | answered',
  1211. 'check': {
  1212. 'type': 'string',
  1213. 'method': 'enums',
  1214. 'data_enums': [
  1215. 'outgoing',
  1216. 'incoming',
  1217. 'hangup',
  1218. 'both',
  1219. 'answered'
  1220. ]
  1221. }
  1222. }
  1223. },
  1224. 'multicast_player': {
  1225. 'multicast_player': {
  1226. 'cn': '组播设置.',
  1227. 'en': 'Multicast Settings.'
  1228. },
  1229. 'enable': {
  1230. 'cn': '启动主播监听. 值: yes | no',
  1231. 'en': 'Enable multicast. Value: yes | no',
  1232. 'check': {
  1233. 'type': 'bool',
  1234. 'empty': False,
  1235. }
  1236. },
  1237. 'address1': {
  1238. 'cn': '组播地址1. 例: rtp://@239.168.12.1:2000',
  1239. 'en': 'Multicast address 1. el: rtp://@239.168.12.1:2000',
  1240. 'check': {
  1241. 'type': 'string',
  1242. 'method': 'regex_multicast'
  1243. }
  1244. },
  1245. 'name1': {
  1246. 'cn': '组播地址1名称. 例: Background-Music-1',
  1247. 'en': 'Multicast address 1 name. el: Background-Music-1',
  1248. 'check': {
  1249. 'type': 'string',
  1250. 'method': 'default'
  1251. }
  1252. },
  1253. 'gpio1': {
  1254. 'cn': 'GPIO触发. 值: Disabled | On | FastFlashing | SlowFlashing',
  1255. 'en': 'GPIO Trigger. Value: Disabled | On | FastFlashing | SlowFlashing',
  1256. 'check': {
  1257. 'type': 'string',
  1258. 'method': 'enums',
  1259. 'data_enums': [
  1260. 'Disabled',
  1261. 'On',
  1262. 'FastFlashing',
  1263. 'SlowFlashing'
  1264. ]
  1265. }
  1266. },
  1267. 'address2': {
  1268. 'cn': '组播地址2. 例: rtp://@239.168.12.2:2000',
  1269. 'en': 'Multicast address 2. el: rtp://@239.168.12.2:2000',
  1270. 'check': {
  1271. 'type': 'string',
  1272. 'method': 'regex_multicast'
  1273. }
  1274. },
  1275. 'name2': {
  1276. 'cn': '组播地址2名称. 例: Background-Music-2',
  1277. 'en': 'Multicast address 2 name. el: Background-Music-2',
  1278. 'check': {
  1279. 'type': 'string',
  1280. 'method': 'default'
  1281. }
  1282. },
  1283. 'gpio2': {
  1284. 'cn': 'GPIO触发. 值: Disabled | On | FastFlashing | SlowFlashing',
  1285. 'en': 'GPIO Trigger. Value: Disabled | On | FastFlashing | SlowFlashing',
  1286. 'check': {
  1287. 'type': 'string',
  1288. 'method': 'enums',
  1289. 'data_enums': [
  1290. 'Disabled',
  1291. 'On',
  1292. 'FastFlashing',
  1293. 'SlowFlashing'
  1294. ]
  1295. }
  1296. },
  1297. 'address3': {
  1298. 'cn': '组播地址3. 例: rtp://@239.168.12.3:2000',
  1299. 'en': 'Multicast address 3. el: rtp://@239.168.12.3:2000',
  1300. 'check': {
  1301. 'type': 'string',
  1302. 'method': 'regex_multicast'
  1303. }
  1304. },
  1305. 'name3': {
  1306. 'cn': '组播地址3名称. 例: Background-Music-3',
  1307. 'en': 'Multicast address 3 name. el: Background-Music-3',
  1308. 'check': {
  1309. 'type': 'string',
  1310. 'method': 'default'
  1311. }
  1312. },
  1313. 'gpio3': {
  1314. 'cn': 'GPIO触发. 值: Disabled | On | FastFlashing | SlowFlashing',
  1315. 'en': 'GPIO Trigger. Value: Disabled | On | FastFlashing | SlowFlashing',
  1316. 'check': {
  1317. 'type': 'string',
  1318. 'method': 'enums',
  1319. 'data_enums': [
  1320. 'Disabled',
  1321. 'On',
  1322. 'FastFlashing',
  1323. 'SlowFlashing'
  1324. ]
  1325. }
  1326. },
  1327. 'address4': {
  1328. 'cn': '组播地址4. 例: rtp://@239.168.12.4:2000',
  1329. 'en': 'Multicast address 4. el: rtp://@239.168.12.4:2000',
  1330. 'check': {
  1331. 'type': 'string',
  1332. 'method': 'regex_multicast'
  1333. }
  1334. },
  1335. 'name4': {
  1336. 'cn': '组播地址4名称. 例: Background-Music-4',
  1337. 'en': 'Multicast address 4 name. el: Background-Music-4',
  1338. 'check': {
  1339. 'type': 'string',
  1340. 'method': 'default'
  1341. }
  1342. },
  1343. 'gpio4': {
  1344. 'cn': 'GPIO触发. 值: Disabled | On | FastFlashing | SlowFlashing',
  1345. 'en': 'GPIO Trigger. Value: Disabled | On | FastFlashing | SlowFlashing',
  1346. 'check': {
  1347. 'type': 'string',
  1348. 'method': 'enums',
  1349. 'data_enums': [
  1350. 'Disabled',
  1351. 'On',
  1352. 'FastFlashing',
  1353. 'SlowFlashing'
  1354. ]
  1355. }
  1356. },
  1357. 'address5': {
  1358. 'cn': '组播地址5. 例: rtp://@239.168.12.5:2000',
  1359. 'en': 'Multicast address 5. el: rtp://@239.168.12.5:2000',
  1360. 'check': {
  1361. 'type': 'string',
  1362. 'method': 'regex_multicast'
  1363. }
  1364. },
  1365. 'name5': {
  1366. 'cn': '组播地址5名称. 例: Background-Music-5',
  1367. 'en': 'Multicast address 5 name. el: Background-Music-5',
  1368. 'check': {
  1369. 'type': 'string',
  1370. 'method': 'default'
  1371. }
  1372. },
  1373. 'gpio5': {
  1374. 'cn': 'GPIO触发. 值: Disabled | On | FastFlashing | SlowFlashing',
  1375. 'en': 'GPIO Trigger. Value: Disabled | On | FastFlashing | SlowFlashing',
  1376. 'check': {
  1377. 'type': 'string',
  1378. 'method': 'enums',
  1379. 'data_enums': [
  1380. 'Disabled',
  1381. 'On',
  1382. 'FastFlashing',
  1383. 'SlowFlashing'
  1384. ]
  1385. }
  1386. },
  1387. 'address6': {
  1388. 'cn': '组播地址6. 例: rtp://@239.168.12.6:2000',
  1389. 'en': 'Multicast address 6. el: rtp://@239.168.12.6:2000',
  1390. 'check': {
  1391. 'type': 'string',
  1392. 'method': 'regex_multicast'
  1393. }
  1394. },
  1395. 'name6': {
  1396. 'cn': '组播地址6名称. 例: Background-Music-6',
  1397. 'en': 'Multicast address 6 name. el: Background-Music-6',
  1398. 'check': {
  1399. 'type': 'string',
  1400. 'method': 'default'
  1401. }
  1402. },
  1403. 'gpio6': {
  1404. 'cn': 'GPIO触发. 值: Disabled | On | FastFlashing | SlowFlashing',
  1405. 'en': 'GPIO Trigger. Value: Disabled | On | FastFlashing | SlowFlashing',
  1406. 'check': {
  1407. 'type': 'string',
  1408. 'method': 'enums',
  1409. 'data_enums': [
  1410. 'Disabled',
  1411. 'On',
  1412. 'FastFlashing',
  1413. 'SlowFlashing'
  1414. ]
  1415. }
  1416. },
  1417. 'address7': {
  1418. 'cn': '组播地址7. 例: rtp://@239.168.12.7:2000',
  1419. 'en': 'Multicast address 7. el: rtp://@239.168.12.7:2000',
  1420. 'check': {
  1421. 'type': 'string',
  1422. 'method': 'regex_multicast'
  1423. }
  1424. },
  1425. 'name7': {
  1426. 'cn': '组播地址7名称. 例: Background-Music-7',
  1427. 'en': 'Multicast address 7 name. el: Background-Music-7',
  1428. 'check': {
  1429. 'type': 'string',
  1430. 'method': 'default'
  1431. }
  1432. },
  1433. 'gpio7': {
  1434. 'cn': 'GPIO触发. 值: Disabled | On | FastFlashing | SlowFlashing',
  1435. 'en': 'GPIO Trigger. Value: Disabled | On | FastFlashing | SlowFlashing',
  1436. 'check': {
  1437. 'type': 'string',
  1438. 'method': 'enums',
  1439. 'data_enums': [
  1440. 'Disabled',
  1441. 'On',
  1442. 'FastFlashing',
  1443. 'SlowFlashing'
  1444. ]
  1445. }
  1446. },
  1447. 'address8': {
  1448. 'cn': '组播地址8. 例: rtp://@239.168.12.8:2000',
  1449. 'en': 'Multicast address 8. el: rtp://@239.168.12.8:2000',
  1450. 'check': {
  1451. 'type': 'string',
  1452. 'method': 'regex_multicast'
  1453. }
  1454. },
  1455. 'name8': {
  1456. 'cn': '组播地址8名称. 例: Background-Music-8',
  1457. 'en': 'Multicast address 8 name. el: Background-Music-8',
  1458. 'check': {
  1459. 'type': 'string',
  1460. 'method': 'default'
  1461. }
  1462. },
  1463. 'gpio8': {
  1464. 'cn': 'GPIO触发. 值: Disabled | On | FastFlashing | SlowFlashing',
  1465. 'en': 'GPIO Trigger. Value: Disabled | On | FastFlashing | SlowFlashing',
  1466. 'check': {
  1467. 'type': 'string',
  1468. 'method': 'enums',
  1469. 'data_enums': [
  1470. 'Disabled',
  1471. 'On',
  1472. 'FastFlashing',
  1473. 'SlowFlashing'
  1474. ]
  1475. }
  1476. },
  1477. 'address9': {
  1478. 'cn': '组播地址9. 例: rtp://@239.168.12.9:2000',
  1479. 'en': 'Multicast address 9. el: rtp://@239.168.12.9:2000',
  1480. 'check': {
  1481. 'type': 'string',
  1482. 'method': 'regex_multicast'
  1483. }
  1484. },
  1485. 'name9': {
  1486. 'cn': '组播地址9名称. 例: Background-Music-9',
  1487. 'en': 'Multicast address 9 name. el: Background-Music-9',
  1488. 'check': {
  1489. 'type': 'string',
  1490. 'method': 'default'
  1491. }
  1492. },
  1493. 'gpio9': {
  1494. 'cn': 'GPIO触发. 值: Disabled | On | FastFlashing | SlowFlashing',
  1495. 'en': 'GPIO Trigger. Value: Disabled | On | FastFlashing | SlowFlashing',
  1496. 'check': {
  1497. 'type': 'string',
  1498. 'method': 'enums',
  1499. 'data_enums': [
  1500. 'Disabled',
  1501. 'On',
  1502. 'FastFlashing',
  1503. 'SlowFlashing'
  1504. ]
  1505. }
  1506. }
  1507. },
  1508. 'secret': {
  1509. 'secret': {
  1510. 'cn': 'WEB密码设置.',
  1511. 'en': 'WEB password settings.'
  1512. },
  1513. 'ui_password': {
  1514. 'cn': 'WEB UI密码. 例: jkcjsdksd',
  1515. 'en': 'WEB UI password. el: jkcjsdksd',
  1516. 'check': {
  1517. 'type': 'string',
  1518. 'empty': False,
  1519. 'method': 'default'
  1520. }
  1521. }
  1522. },
  1523. 'ipc': {
  1524. 'ipc': {
  1525. 'cn': '视频设置.',
  1526. 'en': 'Video settings.'
  1527. },
  1528. 'url': {
  1529. 'cn': '画面效果. 例: 0(清晰)',
  1530. 'en': 'Effect Controls. el: 0(Standard)',
  1531. 'check': {
  1532. 'type': 'string',
  1533. 'method': 'default'
  1534. }
  1535. },
  1536. 'payload': {
  1537. 'cn': 'H.264载荷类型. 例: 99',
  1538. 'en': 'H.264 Payload Type. el: 99',
  1539. 'check': {
  1540. 'type': 'int',
  1541. 'empty': False,
  1542. 'method': 'range',
  1543. 'range': {
  1544. 'start': 96,
  1545. 'end': 127
  1546. }
  1547. }
  1548. },
  1549. 'rtsp_access': {
  1550. 'cn': 'RTSP访问. 值: yes | no',
  1551. 'en': 'RTSP Access. Value: yes | no',
  1552. 'check': {
  1553. 'type': 'bool',
  1554. 'empty': False,
  1555. }
  1556. }
  1557. },
  1558. 'audio_collection': {
  1559. 'audio_collection': {
  1560. 'cn': '音源采集设置.',
  1561. 'en': 'Audio Collection settings.'
  1562. },
  1563. 'enable': {
  1564. 'cn': '开启音源采集. 值: yes | no.',
  1565. 'en': 'Enable Collection. Value: yes | no.',
  1566. 'check': {
  1567. 'type': 'bool',
  1568. 'empty': False,
  1569. 'relate': True,
  1570. 'data_relate': {
  1571. 'yes': {
  1572. 'audio_collection': [
  1573. 'server',
  1574. 'username',
  1575. 'password',
  1576. 'name'
  1577. ]
  1578. }
  1579. }
  1580. }
  1581. },
  1582. 'server': {
  1583. 'cn': '服务器地址.',
  1584. 'en': 'Server address.',
  1585. 'check': {
  1586. 'type': 'string',
  1587. 'method': 'regex_domain'
  1588. }
  1589. },
  1590. 'username': {
  1591. 'cn': '用户名.',
  1592. 'en': 'Username.',
  1593. 'check': {
  1594. 'type': 'string',
  1595. 'method': 'regex_username'
  1596. }
  1597. },
  1598. 'password': {
  1599. 'cn': '密码.',
  1600. 'en': 'Password.',
  1601. 'check': {
  1602. 'type': 'string',
  1603. 'method': 'default'
  1604. }
  1605. },
  1606. 'name': {
  1607. 'cn': '音源名称.',
  1608. 'en': 'Source Name.',
  1609. 'check': {
  1610. 'type': 'string',
  1611. 'method': 'default'
  1612. }
  1613. }
  1614. },
  1615. 'volume': {
  1616. 'volume': {
  1617. 'cn': '系统音量设置.',
  1618. 'en': 'System volume settings.'
  1619. },
  1620. 'agc': {
  1621. 'cn': 'MIC自动增益. 值: yes | no',
  1622. 'en': 'MIC automatic gain. Value: yes | no',
  1623. 'check': {
  1624. 'type': 'bool',
  1625. 'empty': False,
  1626. 'relate': True,
  1627. 'data_relate': {
  1628. 'yes': {
  1629. 'volume': [
  1630. 'agc_min_volume',
  1631. 'agc_max_volume'
  1632. ]
  1633. }
  1634. }
  1635. }
  1636. },
  1637. 'volume_in': {
  1638. 'cn': '麦克风音量. 范围: 0 - 9. el: 5',
  1639. 'en': 'Microphone volume. range: 0 - 9. el: 5',
  1640. 'check': {
  1641. 'type': 'int',
  1642. 'empty': False,
  1643. 'method': 'range',
  1644. 'range': {
  1645. 'start': 0,
  1646. 'end': 9
  1647. }
  1648. }
  1649. },
  1650. 'volume_out': {
  1651. 'cn': '扬声器音量. 范围: 0 - 9. el: 5',
  1652. 'en': 'Speaker volume. range: 0 - 9. el: 5',
  1653. 'check': {
  1654. 'type': 'int',
  1655. 'empty': False,
  1656. 'method': 'range',
  1657. 'range': {
  1658. 'start': 0,
  1659. 'end': 9
  1660. }
  1661. }
  1662. },
  1663. 'agc_min_volume': {
  1664. 'cn': '自动增益最小音量. 范围: 0 - 9. el: 2',
  1665. 'en': 'AGC Min Volume. range: 0 - 9. el: 2',
  1666. 'check': {
  1667. 'type': 'int',
  1668. 'empty': False,
  1669. 'method': 'range',
  1670. 'range': {
  1671. 'start': 0,
  1672. 'end': 9
  1673. }
  1674. }
  1675. },
  1676. 'agc_max_volume': {
  1677. 'cn': '自动增益最大音量. 范围: 0 - 9. el: 2',
  1678. 'en': 'AGC Max Volume. range: 0 - 9. el: 2',
  1679. 'check': {
  1680. 'type': 'int',
  1681. 'empty': False,
  1682. 'method': 'range',
  1683. 'range': {
  1684. 'start': 0,
  1685. 'end': 9
  1686. }
  1687. }
  1688. },
  1689. 'key_beep': {
  1690. 'cn': '按键音启动. 值: yes | no',
  1691. 'en': 'Key beep enable. Value: yes | no',
  1692. 'check': {
  1693. 'type': 'bool',
  1694. 'empty': False,
  1695. }
  1696. }
  1697. },
  1698. 'auto_privisioning': {
  1699. 'auto_privisioning': {
  1700. 'cn': '自动配置设置.',
  1701. 'en': 'Auto Privisioning settings.'
  1702. },
  1703. 'address': {
  1704. 'cn': '服务器地址. 例: 10.10.1.15 或 http://192.168.1.100/files/',
  1705. 'en': 'Server address. el: 10.10.1.15() or http://192.168.1.100/files/',
  1706. 'check': {
  1707. 'type': 'string',
  1708. 'method': 'default'
  1709. }
  1710. },
  1711. 'mode': {
  1712. 'cn': '访问模式. 值: tftp | http',
  1713. 'en': 'Access mode. Value: tftp | http',
  1714. 'check': {
  1715. 'type': 'string',
  1716. 'method': 'enums',
  1717. 'data_enums': [
  1718. 'tftp',
  1719. 'http'
  1720. ]
  1721. }
  1722. },
  1723. 'format': {
  1724. 'cn': '配置文件格式. 值: json | yaml',
  1725. 'en': 'Configuration file format. Value: json | yaml',
  1726. 'check': {
  1727. 'type': 'string',
  1728. 'method': 'enums',
  1729. 'data_enums': [
  1730. 'json',
  1731. 'yaml'
  1732. ]
  1733. }
  1734. }
  1735. },
  1736. 'call_action_url': {
  1737. 'call_action_url': {
  1738. 'cn': '呼叫事件回调URL设置.',
  1739. 'en': 'Call event callback URL settings.'
  1740. },
  1741. 'incoming_enable': {
  1742. 'cn': '呼入回调URL启动. 值: yes | no',
  1743. 'en': 'Incoming callback URL enable. Value: yes | no',
  1744. 'check': {
  1745. 'type': 'bool',
  1746. 'empty': False,
  1747. }
  1748. },
  1749. 'incoming_url': {
  1750. 'cn': '呼入回调URL. el: http://192.168.1.100/incoming',
  1751. 'en': 'Incoming callback URL. el: http://192.168.1.100/incoming',
  1752. 'check': {
  1753. 'type': 'string',
  1754. 'method': 'default',
  1755. }
  1756. },
  1757. 'outgoing_enable': {
  1758. 'cn': '呼出回调URL启动. 值: yes | no',
  1759. 'en': 'Outgoing callback URL enable. Value: yes | no',
  1760. 'check': {
  1761. 'type': 'bool',
  1762. 'empty': False,
  1763. }
  1764. },
  1765. 'outgoing_url': {
  1766. 'cn': '呼出回调URL. el: http://192.168.1.100/outgoing',
  1767. 'en': 'Outgoing callback URL. el: http://192.168.1.100/outgoing',
  1768. 'check': {
  1769. 'type': 'string',
  1770. 'method': 'default',
  1771. }
  1772. },
  1773. 'answered_enable': {
  1774. 'cn': '应答回调URL启动. 值: yes | no',
  1775. 'en': 'Answered callback URL enable. Value: yes | no',
  1776. 'check': {
  1777. 'type': 'bool',
  1778. 'empty': False,
  1779. }
  1780. },
  1781. 'answered_url': {
  1782. 'cn': '应答回调URL. el: http://192.168.1.100/answered',
  1783. 'en': 'Answered callback URL. el: http://192.168.1.100/answered',
  1784. 'check': {
  1785. 'type': 'string',
  1786. 'method': 'default',
  1787. }
  1788. },
  1789. 'hangup_enable': {
  1790. 'cn': '挂断回调URL启动. 值: yes | no',
  1791. 'en': 'Hangup callback URL enable. Value: yes | no',
  1792. 'check': {
  1793. 'type': 'bool',
  1794. 'empty': False,
  1795. }
  1796. },
  1797. 'hangup_url': {
  1798. 'cn': '挂断回调URL. el: http://192.168.1.100/hangup',
  1799. 'en': 'Hangup callback URL. el: http://192.168.1.100/hangup',
  1800. 'check': {
  1801. 'type': 'string',
  1802. 'method': 'default',
  1803. }
  1804. }
  1805. },
  1806. 'relay_action_url': {
  1807. 'relay_action_url': {
  1808. 'cn': '继电器事件回调URL设置.',
  1809. 'en': 'Relay event callback URL settings.'
  1810. },
  1811. 'on_enable': {
  1812. 'cn': '继电器开回调URL启动. 值: yes | no',
  1813. 'en': 'Relay on callback URL enable. Value: yes | no',
  1814. 'check': {
  1815. 'type': 'bool',
  1816. 'empty': False,
  1817. }
  1818. },
  1819. 'on_url': {
  1820. 'cn': '继电器开回调URL. el: http://192.168.1.100/on',
  1821. 'en': 'Relay on callback URL. el: http://192.168.1.100/on',
  1822. 'check': {
  1823. 'type': 'string',
  1824. 'method': 'default',
  1825. }
  1826. },
  1827. 'off_enable': {
  1828. 'cn': '继电器关回调URL启动. 值: yes | no',
  1829. 'en': 'Relay off callback URL enable. Value: yes | no',
  1830. 'check': {
  1831. 'type': 'bool',
  1832. 'empty': False,
  1833. }
  1834. },
  1835. 'off_url': {
  1836. 'cn': '继电器关回调URL. el: http://192.168.1.100/off',
  1837. 'en': 'Relay off callback URL. el: http://192.168.1.100/off',
  1838. 'check': {
  1839. 'type': 'string',
  1840. 'method': 'default',
  1841. }
  1842. }
  1843. },
  1844. 'api': {
  1845. 'api': {
  1846. 'cn': 'API设置.',
  1847. 'en': 'API settings.'
  1848. },
  1849. 'call_enable': {
  1850. 'cn': '呼叫API启动. 值: yes | no',
  1851. 'en': 'Call API enable. Value: yes | no',
  1852. 'check': {
  1853. 'type': 'bool',
  1854. 'empty': False,
  1855. }
  1856. },
  1857. 'relay_enable': {
  1858. 'cn': '继电器API启动. 值: yes | no',
  1859. 'en': 'Relay API enable. Value: yes | no',
  1860. 'check': {
  1861. 'type': 'bool',
  1862. 'empty': False,
  1863. }
  1864. },
  1865. 'player_enable': {
  1866. 'cn': '播放器API启动. 值: yes | no',
  1867. 'en': 'Player API enable. Value: yes | no',
  1868. 'check': {
  1869. 'type': 'bool',
  1870. 'empty': False,
  1871. }
  1872. }
  1873. },
  1874. 'default': {
  1875. 'cn': '',
  1876. 'en': ''
  1877. }
  1878. }
  1879. if not hasattr(ruamel.yaml.comments.CommentedMap, "yaml_set_comment_before_key"):
  1880. def my_yaml_set_comment_before_key(self, key, comment, column=None,
  1881. clear=False):
  1882. """
  1883. append comment to list of comment lines before key, '# ' is inserted
  1884. before the comment
  1885. column: determines indentation, if not specified take indentation from
  1886. previous comment, otherwise defaults to 0
  1887. clear: if True removes any existing comments instead of appending
  1888. """
  1889. key_comment = self.ca.items.setdefault(key, [None, [], None, None])
  1890. if clear:
  1891. key_comment[1] = []
  1892. comment_list = key_comment[1]
  1893. if comment:
  1894. comment_start = '# '
  1895. if comment[-1] == '\n':
  1896. comment = comment[:-1] # strip final newline if there
  1897. else:
  1898. comment_start = '#'
  1899. if column is None:
  1900. if comment_list:
  1901. # if there already are other comments get the column from them
  1902. column = comment_list[-1].start_mark.column
  1903. else:
  1904. column = 0
  1905. # start_mark = ruamel.yaml.error.CommentMark(None, None, None, column, None, None)
  1906. start_mark = ruamel.yaml.error.CommentMark(column)
  1907. comment_list.append(ruamel.yaml.tokens.CommentToken(
  1908. comment_start + comment + '\n', start_mark, None))
  1909. return self
  1910. ruamel.yaml.comments.CommentedMap.yaml_set_comment_before_key = \
  1911. my_yaml_set_comment_before_key
  1912. def deleteKeys(data = {}, keys = origin_keys):
  1913. ret_data = data
  1914. for key, value in keys.items():
  1915. if key in ret_data:
  1916. for k in value:
  1917. if k in ret_data[key]:
  1918. del ret_data[key][k]
  1919. if not ret_data[key]:
  1920. del ret_data[key]
  1921. return ret_data
  1922. def addComment(data, commentkeys = comment_data):
  1923. tmp_data = data
  1924. for key, value in tmp_data.items():
  1925. try:
  1926. if "cn" in commentkeys[key][key].keys() and "en" in commentkeys[key][key].keys():
  1927. tmp_data.yaml_set_comment_before_key(key, commentkeys[key][key]["cn"], column=0)
  1928. tmp_data.yaml_set_comment_before_key(key, commentkeys[key][key]["en"], column=0)
  1929. except:
  1930. tmp_data.yaml_set_comment_before_key(key, commentkeys['default']["cn"], column=0)
  1931. # tmp_data.yaml_set_comment_before_key(key, commentkeys['default']["en"], column=0)
  1932. cm = tmp_data[key]
  1933. for k, v in value.items():
  1934. try:
  1935. if "cn" in commentkeys[key][k].keys() and "en" in commentkeys[key][k].keys():
  1936. cm.yaml_set_comment_before_key(k, commentkeys[key][k]["cn"], column=2)
  1937. cm.yaml_set_comment_before_key(k, commentkeys[key][k]["en"], column=2)
  1938. except:
  1939. cm.yaml_set_comment_before_key(k, commentkeys['default']["cn"], column=2)
  1940. # cm.yaml_set_comment_before_key(k, commentkeys['default']["en"], column=2)
  1941. return tmp_data
  1942. def exportIni2Yaml(src = SYSTEM_CONF_PATH, dest = TMPFILE):
  1943. ini = configparser.RawConfigParser()
  1944. ini.read(src, encoding='utf-8')
  1945. if ini.has_section("firmware"):
  1946. ini.remove_section("firmware")
  1947. ini_data = ini._sections
  1948. final_data = deleteKeys(ini_data)
  1949. data = ruamel.yaml.round_trip_load(ruamel.yaml.round_trip_dump(final_data))
  1950. final_data = addComment(data)
  1951. with open(dest, 'wb') as f:
  1952. ruamel.yaml.round_trip_dump(final_data, f, encoding='utf-8')
  1953. os.system("/etc/scripts/action.sh set_yaml")
  1954. def exportIni2Json(src = SYSTEM_CONF_PATH, dest = TMPFILE):
  1955. ini = configparser.RawConfigParser()
  1956. ini.read(src, encoding='utf-8')
  1957. if ini.has_section("firmware"):
  1958. ini.remove_section("firmware")
  1959. ini_data = ini._sections
  1960. final_data = deleteKeys(ini_data)
  1961. with open(dest, 'w', encoding='utf-8') as f:
  1962. json.dump(final_data, f, indent=4)
  1963. def checkData(data, section, key, value, check):
  1964. res = {}
  1965. if check['type'] == 'string':
  1966. if 'empty' not in check:
  1967. if not value:
  1968. return None
  1969. else:
  1970. if check['empty'] and not value:
  1971. return None
  1972. if check['method'] == 'enums':
  1973. for enum in check['data_enums']:
  1974. if enum == value:
  1975. return None
  1976. res.setdefault("check", "%s.%s" % (section, key))
  1977. return res
  1978. elif check['method'] == 'regex_ip':
  1979. if re.match(r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", value):
  1980. return None
  1981. else:
  1982. res.setdefault("check", "%s.%s" % (section, key))
  1983. # res.setdefault("status", "irregular")
  1984. return res
  1985. elif check['method'] == 'regex_domain':
  1986. if re.match(r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)+([A-Za-z]|[A-Za-z][A-Za-z0-9-]*[A-Za-z0-9])$", value):
  1987. return None
  1988. else:
  1989. res.setdefault("check", "%s.%s" % (section, key))
  1990. # res.setdefault("status", "irregular")
  1991. return res
  1992. elif check['method'] == 'regex_username':
  1993. if re.match(r"^[a-zA-Z0-9.#@*][a-zA-Z0-9.#@*]{0,16}$", value):
  1994. return None
  1995. else:
  1996. res.setdefault("check", "%s.%s" % (section, key))
  1997. # res.setdefault("status", "irregular")
  1998. return res
  1999. elif check['method'] == 'regex_dtmf':
  2000. if re.match(r"^[0-9][0-9*]{0,16}$", value):
  2001. return None
  2002. else:
  2003. res.setdefault("check", "%s.%s" % (section, key))
  2004. # res.setdefault("status", "irregular")
  2005. return res
  2006. elif check['method'] == 'regex_multicast':
  2007. if re.match(r"rtp://@2(?:2[4-9]|3\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d?|0)){3}\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$", value):
  2008. return None
  2009. else:
  2010. res.setdefault("check", "%s.%s" % (section, key))
  2011. # res.setdefault("status", "irregular")
  2012. return res
  2013. elif check['method'] == 'secret':
  2014. if re.match(r"^[a-zA-Z]\w{4,16}$", value):
  2015. return None
  2016. else:
  2017. res.setdefault("check", "%s.%s" % (section, key))
  2018. # res.setdefault("status", "irregular")
  2019. return res
  2020. else:
  2021. pass
  2022. if 'relate' in check and check['relate']:
  2023. for m, n in check['data_relate'].items():
  2024. if m == value:
  2025. if n:
  2026. for x, y in n.items():
  2027. for i in y:
  2028. if not data[x][i] or data[x][i] == '':
  2029. res.setdefault("check", "%s.%s" % (x, i))
  2030. # res.setdefault("status", "relate_irregular")
  2031. return res
  2032. return None
  2033. try:
  2034. number = float(value)
  2035. if number <= 1 or number >= 3600:
  2036. res.setdefault("check", "%s.%s" % (section, key))
  2037. # res.setdefault("status", "relate_irregular")
  2038. return res
  2039. for x, y in check['data_relate']['default'].items():
  2040. for i in y:
  2041. if data[x][i] == '' or not data[x][i]:
  2042. res.setdefault("check", "%s.%s" % (x, i))
  2043. # res.setdefault("status", "relate_irregular")
  2044. return res
  2045. return None
  2046. except:
  2047. res.setdefault("check", "%s.%s" % (section, key))
  2048. # res.setdefault("status", "relate_irregular")
  2049. return res
  2050. return None
  2051. return None
  2052. elif check['type'] == 'int':
  2053. if not value:
  2054. return None
  2055. try:
  2056. if check['range']['start'] <= int(value) and check['range']['end'] >= int(value):
  2057. return None
  2058. else:
  2059. res.setdefault("check", "%s.%s" % (section, key))
  2060. # res.setdefault("status", "irregular")
  2061. return res
  2062. except:
  2063. res.setdefault("check", "%s.%s" % (section, key))
  2064. # res.setdefault("status", "irregular")
  2065. return res
  2066. elif check['type'] == 'bool':
  2067. if 'empty' not in check:
  2068. if not value:
  2069. return None
  2070. else:
  2071. if check['empty'] and not value:
  2072. return None
  2073. if value == 'yes' or value == 'no':
  2074. if 'relate' in check and check['relate']:
  2075. for m, n in check['data_relate'].items():
  2076. if m == value:
  2077. if n:
  2078. for x, y in n.items():
  2079. for i in y:
  2080. if not data[x][i] or data[x][i] == '':
  2081. res.setdefault("check", "%s.%s" % (x, i))
  2082. # res.setdefault("status", "relate_irregular")
  2083. return res
  2084. return None
  2085. return None
  2086. else:
  2087. res.setdefault("check", "%s.%s" % (section, key))
  2088. # res.setdefault("status", "relate_irregular")
  2089. return res
  2090. else:
  2091. return None
  2092. def output_str(res):
  2093. target = {}
  2094. if "check" in res:
  2095. target.setdefault("check", res["check"])
  2096. else:
  2097. target.setdefault("check", "unknown")
  2098. return json.dumps(target)
  2099. def handleFirmwareUrl(url):
  2100. if not url:
  2101. return
  2102. config_firmware = configparser.RawConfigParser()
  2103. config_firmware.read(SYSTEM_CONF_PATH[3])
  2104. old_url = config_firmware.get("firmware", "url")
  2105. if url == old_url:
  2106. return
  2107. else:
  2108. config_firmware.set("firmware", "url", url)
  2109. with open(SYSTEM_CONF_PATH[3], 'w') as f:
  2110. config_firmware.write(f, space_around_delimiters=False)
  2111. config_system = configparser.RawConfigParser()
  2112. config_system.read(SYSTEM_CONF_PATH[0])
  2113. config_system.set("upgrade", "date", time.strftime("%Y-%m-%d"))
  2114. with open(SYSTEM_CONF_PATH[0], 'w') as f:
  2115. config_system.write(f, space_around_delimiters=False)
  2116. os.system("/etc/scripts/onvif_upgrade.sh upgrade %s no" % url)
  2117. def importConfig(src = TMPFILE, dest = SYSTEM_CONF_PATH):
  2118. try:
  2119. with open(src, 'r', encoding='utf-8') as f:
  2120. data = json.loads(f.read())
  2121. except FileNotFoundError:
  2122. res = {}
  2123. res.setdefault("check", "file_not_found")
  2124. print(output_str(res))
  2125. sys.exit(0)
  2126. except:
  2127. try:
  2128. with open(src, 'rb') as f:
  2129. yaml=ruamel.yaml.YAML(typ='safe')
  2130. data = yaml.load(f)
  2131. except:
  2132. res = {}
  2133. res.setdefault("check", "file_format_error")
  2134. print(output_str(res))
  2135. os.remove(src)
  2136. sys.exit(0)
  2137. if type(data) != dict:
  2138. res = {}
  2139. res.setdefault("check", "file_format_error")
  2140. print(output_str(res))
  2141. os.remove(src)
  2142. sys.exit(0)
  2143. output_data = deleteKeys(data)
  2144. for key, value in output_data.items():
  2145. for k, v in value.items():
  2146. # try:
  2147. # res = checkData(output_data, key, k, v, comment_data[key][k]['check'])
  2148. # if res:
  2149. # print(output_str(res))
  2150. # os.remove(TMPFILE)
  2151. # sys.exit(0)
  2152. # except SystemExit:
  2153. # sys.exit(0)
  2154. # except KeyError:
  2155. # continue
  2156. if not v:
  2157. output_data[key][k] = ''
  2158. if "volume" in output_data:
  2159. volume_data = {}
  2160. volume_data.setdefault("volume", output_data["volume"])
  2161. del output_data["volume"]
  2162. if "priority" in output_data:
  2163. volume_data.setdefault("priority", output_data["priority"])
  2164. del output_data["priority"]
  2165. config_volume = configparser.RawConfigParser()
  2166. config_volume.read(dest[1], encoding='utf-8')
  2167. config_volume.read_dict(volume_data)
  2168. with open(dest[1], 'w', encoding='utf-8') as f:
  2169. config_volume.write(f, space_around_delimiters=False)
  2170. if "schedule_1" in output_data:
  2171. schedule_data = {}
  2172. for i in range(1, 31):
  2173. test_section="schedule_"+str(i)
  2174. if test_section in output_data:
  2175. schedule_data.setdefault(test_section, output_data[test_section])
  2176. del output_data[test_section]
  2177. if "holidays" in output_data:
  2178. schedule_data.setdefault("holidays", output_data["holidays"])
  2179. del output_data["holidays"]
  2180. if "screen_preset" in output_data:
  2181. schedule_data.setdefault("screen_preset", output_data["screen_preset"])
  2182. del output_data["screen_preset"]
  2183. if "call_screen" in output_data:
  2184. schedule_data.setdefault("call_screen", output_data["call_screen"])
  2185. del output_data["call_screen"]
  2186. config_schedule = configparser.RawConfigParser()
  2187. config_schedule.read(dest[2], encoding='utf-8')
  2188. config_schedule.read_dict(schedule_data)
  2189. with open(dest[2], 'w', encoding='utf-8') as f:
  2190. config_schedule.write(f, space_around_delimiters=False)
  2191. config_system = configparser.RawConfigParser()
  2192. config_system.read(dest[0], encoding='utf-8')
  2193. config_system.read_dict(output_data)
  2194. with open(dest[0], 'w', encoding='utf-8') as f:
  2195. config_system.write(f, space_around_delimiters=False)
  2196. if "firmware" in data and "url" in data["firmware"] and data["firmware"]["url"]:
  2197. handleFirmwareUrl(data["firmware"]["url"])
  2198. if __name__ == "__main__":
  2199. if len(sys.argv) == 2:
  2200. action=sys.argv[1]
  2201. else:
  2202. res = {}
  2203. res.setdefault("check", "Usage: %s export_yaml | export_json | import" % (sys.argv[0]))
  2204. print(output_str(res))
  2205. sys.exit(0)
  2206. if action == 'export_yaml':
  2207. exportIni2Yaml()
  2208. elif action == 'export_json':
  2209. exportIni2Json()
  2210. elif action == 'import':
  2211. importConfig()
  2212. os.remove(TMPFILE)
  2213. else:
  2214. res = {}
  2215. res.setdefault("check", "not_support_action")
  2216. print(output_str(res))
  2217. sys.exit(0)