mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralgw.git
synced 2025-11-02 11:47:47 +00:00
Compare commits
579 Commits
v2.6.0-RC1
...
release/v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a45d351081 | ||
|
|
7f291914bd | ||
|
|
3edbb02187 | ||
|
|
27beb0bd5d | ||
|
|
24ec3259c6 | ||
|
|
b09cec0bc2 | ||
|
|
d14ca95010 | ||
|
|
2df1100795 | ||
|
|
2f961f992a | ||
|
|
ecdc5b3531 | ||
|
|
5f08a581f2 | ||
|
|
87b4a5d626 | ||
|
|
6aa2ef2878 | ||
|
|
9267a36529 | ||
|
|
72db313d8d | ||
|
|
93f0b2500e | ||
|
|
76b7aba5bd | ||
|
|
0585884033 | ||
|
|
c31fa08579 | ||
|
|
d9c3fea93d | ||
|
|
6325476325 | ||
|
|
054e172b64 | ||
|
|
7ae51f0fec | ||
|
|
531c0e24ba | ||
|
|
d97a31e002 | ||
|
|
70e5b1d0db | ||
|
|
63516e85db | ||
|
|
35b1dbdc2e | ||
|
|
c9abe16cfe | ||
|
|
aee7530b2b | ||
|
|
ceda99fa84 | ||
|
|
ce78b144e6 | ||
|
|
3fd3717978 | ||
|
|
9be3f1dfa9 | ||
|
|
2249367696 | ||
|
|
b68af82771 | ||
|
|
884d2e323b | ||
|
|
5a21b6f197 | ||
|
|
62c0178aa9 | ||
|
|
041452cf93 | ||
|
|
89ebaf78bc | ||
|
|
295a6496ef | ||
|
|
48fb10bcec | ||
|
|
525e464592 | ||
|
|
5f20866a31 | ||
|
|
05f60cd08b | ||
|
|
bd7b56757d | ||
|
|
bc3c85fe2d | ||
|
|
22c87decdc | ||
|
|
d13216e0e2 | ||
|
|
992d977312 | ||
|
|
9cb789d0b0 | ||
|
|
b4e9747bfa | ||
|
|
351633f215 | ||
|
|
5ec9d6a2c8 | ||
|
|
3abb24919f | ||
|
|
089446c3b4 | ||
|
|
345195dd1e | ||
|
|
21db12bcc6 | ||
|
|
be01cfb142 | ||
|
|
55645c5da4 | ||
|
|
aa0316462f | ||
|
|
ebb3c8fed0 | ||
|
|
4fb788def4 | ||
|
|
5b1e048be3 | ||
|
|
03ebc88672 | ||
|
|
80bb7ffa07 | ||
|
|
1776a70a0e | ||
|
|
3a0de1fee9 | ||
|
|
8414ed719b | ||
|
|
eebb18fccf | ||
|
|
1e59b8e160 | ||
|
|
6da673e754 | ||
|
|
ee4cb53517 | ||
|
|
61da6aa317 | ||
|
|
bbbadd3a23 | ||
|
|
855eb0dc13 | ||
|
|
0601aaf340 | ||
|
|
100d0302be | ||
|
|
1fe4dbf49f | ||
|
|
720222137c | ||
|
|
d464b8a6f4 | ||
|
|
019a995bdd | ||
|
|
f70a8f1732 | ||
|
|
0c79d2a632 | ||
|
|
1d16bd352a | ||
|
|
88564f2a77 | ||
|
|
1907ab9623 | ||
|
|
60e50b2af4 | ||
|
|
cd24a45c87 | ||
|
|
cab25f6fd7 | ||
|
|
23c5879a4b | ||
|
|
4e90422e7c | ||
|
|
e75983019a | ||
|
|
a6afef5f8e | ||
|
|
15e45f32a1 | ||
|
|
4c7e1807a2 | ||
|
|
301b24415c | ||
|
|
da0698ab9b | ||
|
|
f8454e6b83 | ||
|
|
cfaab404e9 | ||
|
|
e5f98cda04 | ||
|
|
bd8fece423 | ||
|
|
68a707fe57 | ||
|
|
e02a5595a1 | ||
|
|
744c1143fb | ||
|
|
41423a6d5f | ||
|
|
060c8673e7 | ||
|
|
1210ae821b | ||
|
|
1a2e4cc184 | ||
|
|
e32ace120b | ||
|
|
3f2c046a96 | ||
|
|
9459bb022c | ||
|
|
9526a2639a | ||
|
|
2051467c0b | ||
|
|
bacaa9959c | ||
|
|
875ee6bfd1 | ||
|
|
8f966fa80c | ||
|
|
d9ac843134 | ||
|
|
4abedcddf0 | ||
|
|
c14abf8aa0 | ||
|
|
d779fca535 | ||
|
|
7e1d545f26 | ||
|
|
9c2d60ed3a | ||
|
|
b8516cad84 | ||
|
|
eba979d9da | ||
|
|
d163f7522d | ||
|
|
132fdafd32 | ||
|
|
3d6527f30b | ||
|
|
dc114de8fa | ||
|
|
0592537b71 | ||
|
|
eddaaa0cd6 | ||
|
|
46e72369ae | ||
|
|
3fc3af68ee | ||
|
|
58648d7dc5 | ||
|
|
b2bd6aab9e | ||
|
|
3781f5283f | ||
|
|
7b990a7d2f | ||
|
|
eca43e1d57 | ||
|
|
c1347fc3b8 | ||
|
|
888fcbbcd3 | ||
|
|
4e4156c420 | ||
|
|
ee98a7b8a5 | ||
|
|
0b5518d265 | ||
|
|
7bc0656f25 | ||
|
|
177a8b40ee | ||
|
|
85ee78f35e | ||
|
|
9043b3a558 | ||
|
|
4d2d488812 | ||
|
|
adf226f2e8 | ||
|
|
749d425d80 | ||
|
|
a6f9deb315 | ||
|
|
f4236408fc | ||
|
|
377c7bfc0b | ||
|
|
2e3efd97e4 | ||
|
|
58abf04e42 | ||
|
|
5e002899b5 | ||
|
|
d43c8f63ab | ||
|
|
07a64877bb | ||
|
|
a00ba50920 | ||
|
|
c2fa87d6bd | ||
|
|
ab0b36a96f | ||
|
|
89f8047e2f | ||
|
|
1515c9bb6a | ||
|
|
b53e6f44fa | ||
|
|
769c9c90f6 | ||
|
|
dc0eb35376 | ||
|
|
e6b497f0b4 | ||
|
|
bab9d869b1 | ||
|
|
a9127d4fcf | ||
|
|
fea78abe9b | ||
|
|
bd72993fa5 | ||
|
|
7d74694bf9 | ||
|
|
8e84a0f1f3 | ||
|
|
98c8f29555 | ||
|
|
42a4ee0864 | ||
|
|
fcce86acf4 | ||
|
|
31aad8b41b | ||
|
|
a828039445 | ||
|
|
6905aeaeec | ||
|
|
3293b7b71d | ||
|
|
2d6df5ea29 | ||
|
|
e466f76b75 | ||
|
|
170b97514b | ||
|
|
a463bb60dd | ||
|
|
9bbb12b674 | ||
|
|
46cc41e065 | ||
|
|
1776643579 | ||
|
|
c0d9aca88a | ||
|
|
88018335da | ||
|
|
7ce7927c95 | ||
|
|
5b797cf937 | ||
|
|
cd615e8f2b | ||
|
|
cf3f0fe67f | ||
|
|
b80e92f3dc | ||
|
|
11034bd4fd | ||
|
|
01980892b1 | ||
|
|
f4d4405663 | ||
|
|
a8370dc8dd | ||
|
|
861c4d0dee | ||
|
|
8c70e833ea | ||
|
|
f8928bbec2 | ||
|
|
0b7e474e01 | ||
|
|
14f0bb75d1 | ||
|
|
32d37a3b9c | ||
|
|
24391c5ac4 | ||
|
|
7ac47dfaa0 | ||
|
|
fd77d6ef37 | ||
|
|
04c9deffd3 | ||
|
|
f8bc00cb55 | ||
|
|
f2ae0b6bd4 | ||
|
|
1904b34c84 | ||
|
|
23ea21d2b4 | ||
|
|
276572a8a5 | ||
|
|
b9bd5ca6a5 | ||
|
|
201a4dd6e7 | ||
|
|
769eb83744 | ||
|
|
66a30c4f37 | ||
|
|
2a744e2fde | ||
|
|
f212aa2e8c | ||
|
|
fc478bd304 | ||
|
|
6e8a2478c4 | ||
|
|
eceb5a9034 | ||
|
|
782acea8c7 | ||
|
|
524d392e83 | ||
|
|
885f1affeb | ||
|
|
50abf75a0a | ||
|
|
4af6427814 | ||
|
|
2a6ec50ce1 | ||
|
|
4497dc655b | ||
|
|
1e2d04ad07 | ||
|
|
5874d3f1fd | ||
|
|
a4abbe6ef3 | ||
|
|
41e3cbb2b2 | ||
|
|
1f77083973 | ||
|
|
b08f993a20 | ||
|
|
113baa625e | ||
|
|
3765d22815 | ||
|
|
24d492903b | ||
|
|
3b4fd70522 | ||
|
|
19cf9101fe | ||
|
|
004319e7ad | ||
|
|
94893d1185 | ||
|
|
13dce2f3e8 | ||
|
|
ea7bc3c52f | ||
|
|
0235a13841 | ||
|
|
be33c88337 | ||
|
|
0456f638c9 | ||
|
|
83ada79ca3 | ||
|
|
913d1e571d | ||
|
|
8f98e510db | ||
|
|
fb0da90b63 | ||
|
|
1e1dec51ab | ||
|
|
c35602e30e | ||
|
|
4c90a777e0 | ||
|
|
9abfa4bad5 | ||
|
|
7ecd0c9891 | ||
|
|
6e25ccdd87 | ||
|
|
a8f970eaf2 | ||
|
|
9f4d362a6d | ||
|
|
5f3f9e93d2 | ||
|
|
c84f05cd22 | ||
|
|
a532520044 | ||
|
|
6d82ee355e | ||
|
|
02c3b2fe2e | ||
|
|
cce4a7ec93 | ||
|
|
9aef183dc2 | ||
|
|
60a3365a9e | ||
|
|
6c052d7afe | ||
|
|
88eae31b7f | ||
|
|
d59f6e3dfc | ||
|
|
c97566f625 | ||
|
|
1fb41a9460 | ||
|
|
cfec8a1cbc | ||
|
|
7a84640c71 | ||
|
|
0d2276ff5a | ||
|
|
d227f83384 | ||
|
|
acb4d91a3d | ||
|
|
72b2913cc5 | ||
|
|
746ef603e2 | ||
|
|
ab792f7239 | ||
|
|
c4bb577763 | ||
|
|
3caf67102e | ||
|
|
8a3ade14ae | ||
|
|
4199b859ad | ||
|
|
be1b571f7f | ||
|
|
3002e17fd2 | ||
|
|
0d1a794e10 | ||
|
|
2aa7d97c80 | ||
|
|
0d3a0cbf03 | ||
|
|
1d8cb5447b | ||
|
|
3526a7abd9 | ||
|
|
d7ec9a3552 | ||
|
|
9f567e0e69 | ||
|
|
b16a410f1d | ||
|
|
0955f23dfc | ||
|
|
bd10ebc19c | ||
|
|
f74c5b496f | ||
|
|
6e961be74e | ||
|
|
c92d22f3cb | ||
|
|
e1770dc6a2 | ||
|
|
eace417fd3 | ||
|
|
ec3b5ededc | ||
|
|
4c6a0ab9e2 | ||
|
|
78a6b011f8 | ||
|
|
a5450418b3 | ||
|
|
c74aa0d89f | ||
|
|
5f5e887f91 | ||
|
|
54a9290589 | ||
|
|
24be35c974 | ||
|
|
937d2818c0 | ||
|
|
f014960b3a | ||
|
|
cc5b319141 | ||
|
|
d5e7a6661f | ||
|
|
3368782471 | ||
|
|
2f013557a9 | ||
|
|
09595abc8c | ||
|
|
5104ab1dc3 | ||
|
|
8f3b2f795f | ||
|
|
9779ee669b | ||
|
|
f7187749a1 | ||
|
|
ddec407856 | ||
|
|
4650ac592a | ||
|
|
bc5c9e30cf | ||
|
|
1b53398e1e | ||
|
|
7b59a981dd | ||
|
|
ec3cb6586f | ||
|
|
c40be95aa8 | ||
|
|
ba8edb7f74 | ||
|
|
ea14936a1d | ||
|
|
676f131ca9 | ||
|
|
2e1fc663c8 | ||
|
|
cd9ef2ed2a | ||
|
|
4a1a903656 | ||
|
|
f6409fc063 | ||
|
|
6af855f6ca | ||
|
|
bec81bc380 | ||
|
|
0e4e4156a1 | ||
|
|
2aa60a5676 | ||
|
|
8b396e51ff | ||
|
|
01f53d7b78 | ||
|
|
b3c188701f | ||
|
|
7eb4c9e38b | ||
|
|
c93c34c042 | ||
|
|
418f8d31ae | ||
|
|
77c0c191f7 | ||
|
|
f0f4cf54bb | ||
|
|
917abf1d7f | ||
|
|
b4e7e4e26b | ||
|
|
9d0a146859 | ||
|
|
2efed5e626 | ||
|
|
7420b72b23 | ||
|
|
5fc675484c | ||
|
|
38ad11542b | ||
|
|
63f2a4085a | ||
|
|
fea70efb2d | ||
|
|
da42c9845f | ||
|
|
ed46778bd4 | ||
|
|
1f7c0b7fdf | ||
|
|
15ec31fc89 | ||
|
|
d2a0d6da8a | ||
|
|
77cae31031 | ||
|
|
6cab1caf6c | ||
|
|
faf7881c87 | ||
|
|
eea8203869 | ||
|
|
040397aa8e | ||
|
|
bba92aa9b8 | ||
|
|
c332a3946d | ||
|
|
02e677f849 | ||
|
|
a26f7c03c1 | ||
|
|
9181ae01cc | ||
|
|
7825b00d2e | ||
|
|
8b895c2088 | ||
|
|
49d39d37a1 | ||
|
|
406d59d5d7 | ||
|
|
186d12c78a | ||
|
|
421c24c961 | ||
|
|
e00c835680 | ||
|
|
3f972ebb4a | ||
|
|
cf8d29e66f | ||
|
|
d5e11d246a | ||
|
|
6ac29199e0 | ||
|
|
2f9452d6ef | ||
|
|
caed454e1a | ||
|
|
30916cbed1 | ||
|
|
81899788a9 | ||
|
|
e1590cbe90 | ||
|
|
bcbc212436 | ||
|
|
520671684b | ||
|
|
eacf9c0450 | ||
|
|
bef4c3ed5c | ||
|
|
4fe6254bf2 | ||
|
|
63ba3d633d | ||
|
|
1255cf0a56 | ||
|
|
7a6f2a517c | ||
|
|
6c15908ed6 | ||
|
|
d0a7670fff | ||
|
|
17d6253cfe | ||
|
|
ab592305ce | ||
|
|
0da527e1d7 | ||
|
|
d3848a6f8b | ||
|
|
c522c22d31 | ||
|
|
783886662f | ||
|
|
56ab9b1409 | ||
|
|
67e86a0edf | ||
|
|
70c12a5b77 | ||
|
|
03f2e2d457 | ||
|
|
ed12331d20 | ||
|
|
ec0c295c7c | ||
|
|
2438bd7ca7 | ||
|
|
18d18f68c5 | ||
|
|
120f94a95a | ||
|
|
7b9cda8c3d | ||
|
|
0d116119ed | ||
|
|
b9a7f53a92 | ||
|
|
ee3aa66b11 | ||
|
|
459029d5d7 | ||
|
|
bfe0ff4481 | ||
|
|
b70a95d12b | ||
|
|
8280ff46db | ||
|
|
59da808bcd | ||
|
|
dbc785aca6 | ||
|
|
5207579645 | ||
|
|
840c22e0d1 | ||
|
|
996e410fde | ||
|
|
521dcc2eed | ||
|
|
4d73467b8a | ||
|
|
515444d223 | ||
|
|
dccda306d4 | ||
|
|
3fd5c59994 | ||
|
|
87fee4ecd2 | ||
|
|
b37e7d4c5d | ||
|
|
f8c21f0c68 | ||
|
|
f74c098b99 | ||
|
|
1619cec197 | ||
|
|
62211b6e8b | ||
|
|
1bebe0729a | ||
|
|
6a8a6aa851 | ||
|
|
4b6880a306 | ||
|
|
3d252116dd | ||
|
|
2fc5e69145 | ||
|
|
8d2e85d0ee | ||
|
|
d1efdc93a4 | ||
|
|
c27627302f | ||
|
|
ae18fead11 | ||
|
|
75a6300ffb | ||
|
|
f84a4c83d0 | ||
|
|
b882f07eef | ||
|
|
d5c8cb5837 | ||
|
|
a09f2ec7bd | ||
|
|
7af9be5845 | ||
|
|
bc6e7d538b | ||
|
|
59ed9df3c9 | ||
|
|
0f46a6ded0 | ||
|
|
ef09214187 | ||
|
|
aa4631b55d | ||
|
|
08b59e04ee | ||
|
|
3455297cd6 | ||
|
|
8f4e585c88 | ||
|
|
350ccd5371 | ||
|
|
b89c0773c5 | ||
|
|
d03cd6a6df | ||
|
|
142a04ffc3 | ||
|
|
bb519eb84b | ||
|
|
2b8e496bbc | ||
|
|
776a781a87 | ||
|
|
f5d66365b8 | ||
|
|
fd8b021225 | ||
|
|
1d2b54b6cf | ||
|
|
b073246293 | ||
|
|
8205cb7336 | ||
|
|
9339ae893a | ||
|
|
ce483ba51c | ||
|
|
85a7de67fb | ||
|
|
abdabe7da3 | ||
|
|
669af7640c | ||
|
|
83c46c44aa | ||
|
|
7b2ba4fed4 | ||
|
|
ef5aa26991 | ||
|
|
92b25846d2 | ||
|
|
77663f9184 | ||
|
|
61c7ab3267 | ||
|
|
8ae0006343 | ||
|
|
64a1fa1c85 | ||
|
|
2b9c90d5e6 | ||
|
|
565cee2373 | ||
|
|
36c5c9c5b6 | ||
|
|
837c3d5570 | ||
|
|
2a71721548 | ||
|
|
055bdcf937 | ||
|
|
221ee05298 | ||
|
|
afb8252dc2 | ||
|
|
77f86d139f | ||
|
|
b2353b6a0e | ||
|
|
bf4b9b0d63 | ||
|
|
e51236f0ca | ||
|
|
5be8ad75ed | ||
|
|
054e3e1591 | ||
|
|
06366f875c | ||
|
|
64d3f8c3ee | ||
|
|
8878445e03 | ||
|
|
ea30684f0c | ||
|
|
ebf08a63f1 | ||
|
|
e9e7db9ac0 | ||
|
|
7f9d03ed34 | ||
|
|
084483b028 | ||
|
|
285dbacd12 | ||
|
|
8f79d70753 | ||
|
|
6d20481d64 | ||
|
|
7da4bbba61 | ||
|
|
ff955d8b2f | ||
|
|
29d615393f | ||
|
|
2a716e6c66 | ||
|
|
b662dcf88c | ||
|
|
253ffbf111 | ||
|
|
dfd689512b | ||
|
|
cee2705bf8 | ||
|
|
af1e293bde | ||
|
|
58266eb239 | ||
|
|
87dc357c9f | ||
|
|
02798de88a | ||
|
|
d7bd812f97 | ||
|
|
b692a7868e | ||
|
|
f57dfc62c0 | ||
|
|
21794d669e | ||
|
|
2139093a73 | ||
|
|
bc1f0670fb | ||
|
|
a0b0a169fa | ||
|
|
7feb9f3655 | ||
|
|
3878d8abe6 | ||
|
|
770b5969f8 | ||
|
|
00bca216fc | ||
|
|
64eb7748d1 | ||
|
|
d6434666b4 | ||
|
|
747c84de4a | ||
|
|
538bdb25b1 | ||
|
|
07229e7e1f | ||
|
|
a63a1785e2 | ||
|
|
14820bd9c8 | ||
|
|
aeeb333c62 | ||
|
|
caa8f8c5a5 | ||
|
|
02aada469b | ||
|
|
020f9aea16 | ||
|
|
a8d5717fd5 | ||
|
|
51dd030419 | ||
|
|
6a83895efc | ||
|
|
c5e2574ab1 | ||
|
|
5a1828eaea | ||
|
|
c62f5a16f5 | ||
|
|
b6e778ada3 | ||
|
|
1b34ec8a78 | ||
|
|
57eb7312c8 | ||
|
|
368cdb72d4 | ||
|
|
712d326560 | ||
|
|
11df029ec0 | ||
|
|
020542b751 | ||
|
|
4b19163091 | ||
|
|
852ae3fde7 | ||
|
|
1ab9729ec1 | ||
|
|
9b1711fff6 | ||
|
|
929bc79136 | ||
|
|
e8fec5075f | ||
|
|
0bae840106 | ||
|
|
bf519637aa | ||
|
|
b15dc2b517 | ||
|
|
44f2843a7f | ||
|
|
e2eda25764 | ||
|
|
b2411d97d6 | ||
|
|
4a61f57912 | ||
|
|
1cafe0b6fc | ||
|
|
20763dedf6 | ||
|
|
80c0a3c07e | ||
|
|
0138cfdede | ||
|
|
066bad7953 | ||
|
|
2ca1508be1 | ||
|
|
737e49a376 | ||
|
|
251a4c2310 | ||
|
|
4e4ad418b6 | ||
|
|
b07c381bf7 |
9
.github/workflows/cleanup.yml
vendored
9
.github/workflows/cleanup.yml
vendored
@@ -4,7 +4,6 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- 'release/*'
|
||||
types: [ closed ]
|
||||
|
||||
defaults:
|
||||
@@ -18,4 +17,10 @@ jobs:
|
||||
- name: Cleanup Docker image with PR branch tag
|
||||
run: |
|
||||
export PR_BRANCH_TAG=$(echo ${GITHUB_HEAD_REF#refs/heads/} | tr '/' '-')
|
||||
curl -uucentral:${{ secrets.DOCKER_REGISTRY_PASSWORD }} -X DELETE "https://tip.jfrog.io/artifactory/tip-wlan-cloud-ucentral/owgw/$PR_BRANCH_TAG"
|
||||
|
||||
if [[ ! $PR_BRANCH_TAG =~ (main|master|release-*) ]]; then
|
||||
echo "PR branch is $PR_BRANCH_TAG, deleting Docker image"
|
||||
curl -s -uucentral:${{ secrets.DOCKER_REGISTRY_PASSWORD }} -X DELETE "https://tip.jfrog.io/artifactory/tip-wlan-cloud-ucentral/owgw/$PR_BRANCH_TAG"
|
||||
else
|
||||
echo "PR branch is $PR_BRANCH_TAG, not deleting Docker image"
|
||||
fi
|
||||
|
||||
@@ -67,6 +67,8 @@ add_compile_options(-Wall -Wextra)
|
||||
if(ASAN)
|
||||
add_compile_options(-fsanitize=address)
|
||||
add_link_options(-fsanitize=address)
|
||||
add_compile_options(-fsanitize=undefined)
|
||||
add_link_options(-fsanitize=undefined)
|
||||
endif()
|
||||
|
||||
add_executable( owgw
|
||||
@@ -116,7 +118,7 @@ add_executable( owgw
|
||||
src/TelemetryStream.cpp src/TelemetryStream.h
|
||||
src/framework/ConfigurationValidator.cpp src/framework/ConfigurationValidator.h
|
||||
src/ConfigurationCache.h
|
||||
src/CapabilitiesCache.h src/FindCountry.h src/rttys/RTTYS_server.cpp src/rttys/RTTYS_server.h src/rttys/RTTYS_device.cpp src/rttys/RTTYS_device.h src/rttys/RTTYS_ClientConnection.cpp src/rttys/RTTYS_ClientConnection.h src/rttys/RTTYS_WebServer.cpp src/rttys/RTTYS_WebServer.h src/RESTAPI/RESTAPI_device_helper.h src/SDKcalls.cpp src/SDKcalls.h src/StateUtils.cpp src/StateUtils.h src/WS_ReactorPool.h src/WS_Connection.h src/WS_Connection.cpp src/TelemetryClient.h src/TelemetryClient.cpp src/RESTAPI/RESTAPI_iptocountry_handler.cpp src/RESTAPI/RESTAPI_iptocountry_handler.h src/framework/ow_constants.h src/GwWebSocketClient.cpp src/GwWebSocketClient.h src/framework/WebSocketClientNotifications.h src/RADIUS_proxy_server.cpp src/RADIUS_proxy_server.h src/RESTAPI/RESTAPI_radiusProxyConfig_handler.cpp src/RESTAPI/RESTAPI_radiusProxyConfig_handler.h)
|
||||
src/CapabilitiesCache.h src/FindCountry.h src/rttys/RTTYS_server.cpp src/rttys/RTTYS_server.h src/rttys/RTTYS_device.cpp src/rttys/RTTYS_device.h src/rttys/RTTYS_ClientConnection.cpp src/rttys/RTTYS_ClientConnection.h src/rttys/RTTYS_WebServer.cpp src/rttys/RTTYS_WebServer.h src/RESTAPI/RESTAPI_device_helper.h src/SDKcalls.cpp src/SDKcalls.h src/StateUtils.cpp src/StateUtils.h src/WS_ReactorPool.h src/WS_Connection.h src/WS_Connection.cpp src/TelemetryClient.h src/TelemetryClient.cpp src/RESTAPI/RESTAPI_iptocountry_handler.cpp src/RESTAPI/RESTAPI_iptocountry_handler.h src/framework/ow_constants.h src/GwWebSocketClient.cpp src/GwWebSocketClient.h src/framework/WebSocketClientNotifications.h src/RADIUS_proxy_server.cpp src/RADIUS_proxy_server.h src/RESTAPI/RESTAPI_radiusProxyConfig_handler.cpp src/RESTAPI/RESTAPI_radiusProxyConfig_handler.h src/ParseWifiScan.h src/RADIUS_helpers.h src/VenueBroadcaster.h src/sdks/sdk_prov.h)
|
||||
|
||||
if(NOT SMALL_BUILD)
|
||||
|
||||
|
||||
182
MICRO_SERVICE_PROTOCOL.md
Normal file
182
MICRO_SERVICE_PROTOCOL.md
Normal file
@@ -0,0 +1,182 @@
|
||||
# Micro-service backbone responsibilities
|
||||
|
||||
## Bus management
|
||||
Each microservice must get onto kafka and consume/produce messages on the kafka bus. The topic to subscribe to is `service_events`.
|
||||
|
||||
## System messages
|
||||
System messages are what maintains the collection of micro-services working on the system. Each message has the format
|
||||
|
||||
```json
|
||||
{
|
||||
"event": <event-type>,
|
||||
"id": 1234567890,
|
||||
"type": "owrrm",
|
||||
"publicEndPoint": "https://myhostname.com:16020",
|
||||
"privateEndPoint": "https://localhost:17020",
|
||||
"key" : "289479847948794870749",
|
||||
"version" : "1.0"
|
||||
}
|
||||
```
|
||||
|
||||
### `event-type`
|
||||
When a service joins the bus, it should generate an event-type of `join`. When a service shutdown, it should generate a `leave` event-type. Every 30 seconds, a service
|
||||
should generate a `keep-alive` message.
|
||||
|
||||
### `id`
|
||||
You should generate a random number from some unique factor for the system. This ID is used to identify different services. You should reuse that ID
|
||||
when you restart.
|
||||
|
||||
## Micro-service maintaining bus state
|
||||
A micro-service should maintain its own lists of available micro-services by looking at the messages it receives and keep a list.
|
||||
|
||||
## The `type`
|
||||
The `type` in the system message is oen of the following:
|
||||
```c++
|
||||
static const std::string uSERVICE_SECURITY{"owsec"};
|
||||
static const std::string uSERVICE_GATEWAY{"owgw"};
|
||||
static const std::string uSERVICE_FIRMWARE{ "owfms"};
|
||||
static const std::string uSERVICE_TOPOLOGY{ "owtopo"};
|
||||
static const std::string uSERVICE_PROVISIONING{ "owprov"};
|
||||
static const std::string uSERVICE_OWLS{ "owls"};
|
||||
static const std::string uSERVICE_SUBCRIBER{ "owsub"};
|
||||
static const std::string uSERVICE_INSTALLER{ "owinst"};
|
||||
static const std::string uSERVICE_ANALYTICS{ "owanalytics"};
|
||||
static const std::string uSERVICE_OWRRM{ "owrrm"};
|
||||
```
|
||||
|
||||
The `type` is what you should use to find the `privateEndPoint` you are looking to communicate with.
|
||||
|
||||
### Example
|
||||
Assume you want to communicate with the gateway t pconfigure a device.
|
||||
|
||||
```text
|
||||
1. Look into my list of current Micro-services for the type=owgw.
|
||||
2. Use the priovateEndPoint associated with that entry
|
||||
```
|
||||
|
||||
## REST API calls on the private interface
|
||||
For inter-service REST calls, you should never use the `Authorization: Bearer token` method. Instead, the following headers should be included in all API calls
|
||||
```json
|
||||
{
|
||||
"X-API-KEY" : "289479847948794870749",
|
||||
"X-INTERNAL-NAME" : "https://myhostname.com:16020"
|
||||
}
|
||||
```
|
||||
|
||||
### `X-API-KEY`
|
||||
This is the `key` you included in your `system-messages`.
|
||||
|
||||
### `X-INTERNAL-NAME`
|
||||
This is the `publicEndPoint` you included in your `system-messages`.
|
||||
|
||||
This method can _only_ be used to any another `privateEndPoint` in the system. You can use the exact same EndPoints provided in the OpenAPI files for any of the services.
|
||||
|
||||
## OpenAPI Integration
|
||||
To appear in the UI consoles, a micro-service should ne able to handle a get to the `/api/v1/system` endpoint on its `publicEndPoint` interface.
|
||||
|
||||
Here is a brief description of what the micro-service should answer:
|
||||
```yaml
|
||||
/system:
|
||||
get:
|
||||
tags:
|
||||
- System Commands
|
||||
summary: Retrieve different values from the running service.
|
||||
operationId: getSystemCommand
|
||||
parameters:
|
||||
- in: query
|
||||
description: Get a value
|
||||
name: command
|
||||
schema:
|
||||
type: string
|
||||
enum:
|
||||
- info
|
||||
required: true
|
||||
|
||||
responses:
|
||||
200:
|
||||
description: Successful command execution
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/SystemInfoResults'
|
||||
403:
|
||||
$ref: '#/components/responses/Unauthorized'
|
||||
404:
|
||||
$ref: '#/components/responses/NotFound'
|
||||
```
|
||||
The relevant data structures are:
|
||||
```yaml
|
||||
SystemInfoResults:
|
||||
type: object
|
||||
properties:
|
||||
version:
|
||||
type: string
|
||||
uptime:
|
||||
type: integer
|
||||
format: integer64
|
||||
start:
|
||||
type: integer
|
||||
format: integer64
|
||||
os:
|
||||
type: string
|
||||
processors:
|
||||
type: integer
|
||||
hostname:
|
||||
type: string
|
||||
certificates:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
filename:
|
||||
type: string
|
||||
expires:
|
||||
type: integer
|
||||
format: int64
|
||||
|
||||
```
|
||||
and
|
||||
```yaml
|
||||
responses:
|
||||
NotFound:
|
||||
description: The specified resource was not found.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
properties:
|
||||
ErrorCode:
|
||||
type: integer
|
||||
ErrorDetails:
|
||||
type: string
|
||||
ErrorDescription:
|
||||
type: string
|
||||
|
||||
Unauthorized:
|
||||
description: The requested does not have sufficient rights to perform the operation.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
properties:
|
||||
ErrorCode:
|
||||
type: integer
|
||||
enum:
|
||||
- 0 # Success
|
||||
- 1 # PASSWORD_CHANGE_REQUIRED,
|
||||
- 2 # INVALID_CREDENTIALS,
|
||||
- 3 # PASSWORD_ALREADY_USED,
|
||||
- 4 # USERNAME_PENDING_VERIFICATION,
|
||||
- 5 # PASSWORD_INVALID,
|
||||
- 6 # INTERNAL_ERROR,
|
||||
- 7 # ACCESS_DENIED,
|
||||
- 8 # INVALID_TOKEN
|
||||
- 9 # EXPIRED_TOKEN
|
||||
- 10 # RATE_LIMIT_EXCEEDED
|
||||
- 11 # BAD_MFA_TRANSACTION
|
||||
- 12 # MFA_FAILURE
|
||||
- 13 # SECURITY_SERVICE_UNREACHABLE
|
||||
ErrorDetails:
|
||||
type: string
|
||||
ErrorDescription:
|
||||
type: string
|
||||
```
|
||||
173
PROTOCOL.md
173
PROTOCOL.md
@@ -30,7 +30,7 @@ In this RPC, here are some common interpretations:
|
||||
#### Connection event
|
||||
Device Sends connection notification to the controller after establishing a connection. The controller
|
||||
my decide to send the AP a newer configuration. The controller will record the device capabilities provided.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "connect" ,
|
||||
"params" : {
|
||||
@@ -47,7 +47,7 @@ my decide to send the AP a newer configuration. The controller will record the d
|
||||
#### State event
|
||||
The device sends device state information periodically. If the controller detects that it has a newer configuration, it
|
||||
may decide to send this new configuration to the AP.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "state" ,
|
||||
"params" : {
|
||||
@@ -62,7 +62,7 @@ may decide to send this new configuration to the AP.
|
||||
#### Healthcheck event
|
||||
Device sends a `healthcheck` periodically. This message contains information about how vital subsystems are operating and
|
||||
if they need attention.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "healthcheck" ,
|
||||
"params" : {
|
||||
@@ -77,7 +77,7 @@ if they need attention.
|
||||
|
||||
#### Log event
|
||||
Device sends a log message whenever necessary. The controller will log this message to the log system for the device.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "log" ,
|
||||
"params" : {
|
||||
@@ -102,7 +102,7 @@ The `severity` matches the `syslog` levels. Here are the details:
|
||||
|
||||
#### Crash Log event
|
||||
Device may send a crash log event after rebooting after a crash. The event cannot be sent until a connection event has been sent.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "crashlog" ,
|
||||
"params" : {
|
||||
@@ -117,7 +117,7 @@ Device may send a crash log event after rebooting after a crash. The event canno
|
||||
Device sends this message to tell the controller that the device
|
||||
has received a configuration but is still running an older configuration. The controller will not
|
||||
reply to this message.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "cfgpending" ,
|
||||
"params" : {
|
||||
@@ -131,7 +131,7 @@ reply to this message.
|
||||
#### DeviceUpdate event
|
||||
Device sends this message to tell the controller it is changing something is its configuration because
|
||||
of some requirement or some changes.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "deviceupdate" ,
|
||||
"params" : {
|
||||
@@ -145,7 +145,7 @@ of some requirement or some changes.
|
||||
#### Send a keepalive to the controller event
|
||||
Device sends a keepalive whenever necessary. The device will send this message to tell the controller
|
||||
which version it is running. The Controller may decide to send the device a newer configuration.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "ping" ,
|
||||
"params" : {
|
||||
@@ -157,7 +157,7 @@ which version it is running. The Controller may decide to send the device a newe
|
||||
|
||||
#### Recovery Event
|
||||
Device may decide it has to do into recovery mode. This event should be used.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "recovery" ,
|
||||
"params" : {
|
||||
@@ -170,6 +170,34 @@ Device may decide it has to do into recovery mode. This event should be used.
|
||||
}
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
"status" : {
|
||||
"error" : 0 or an error number,
|
||||
"text" : <description of the error or success>
|
||||
}
|
||||
},
|
||||
"id" : <same number>
|
||||
}
|
||||
```
|
||||
|
||||
#### Device requests a venue broadcast message
|
||||
Device send this message when it wants to reach out to all other APs in the same venue. The GW will find the
|
||||
venue where this device belongs and resend the same message to all other devices in the venue.
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "venue_broadcast" ,
|
||||
"params" : {
|
||||
"serial" : <serial number> ,
|
||||
"timestamp" : <the UTC timestamp when the message was sent>,
|
||||
"data" : <an opaque string from the AP. This could be Zipped and so on and most likely base64 encoded>
|
||||
}
|
||||
}
|
||||
```
|
||||
Upon receiving a `venue_broadcast` message, the GW will simply resent the message to all the APs in the venue.
|
||||
|
||||
### Controller commands
|
||||
Most controller commands include a `when` member. This is a UTC clock time asking the AP
|
||||
@@ -180,7 +208,7 @@ always a numeric parameter.
|
||||
#### Controller wants the device to apply a given configuration
|
||||
Controller sends this command when it believes the device should load a new configuration. The device
|
||||
should send message with `pending change` events until this version has been applied and running.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "configure" ,
|
||||
"params" : {
|
||||
@@ -194,7 +222,7 @@ should send message with `pending change` events until this version has been app
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
@@ -233,7 +261,7 @@ The rejected section is an array containing the following:
|
||||
|
||||
#### Controller wants the device to reboot
|
||||
Controller sends this command when it believes the device should reboot.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "reboot" ,
|
||||
"params" : {
|
||||
@@ -245,7 +273,7 @@ Controller sends this command when it believes the device should reboot.
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
@@ -264,7 +292,7 @@ The device should answer:
|
||||
|
||||
#### Controller wants the device to upgrade its firmware
|
||||
Controller sends this command when it believes the device should upgrade its firmware.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "upgrade" ,
|
||||
"params" : {
|
||||
@@ -277,7 +305,7 @@ Controller sends this command when it believes the device should upgrade its fir
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
@@ -293,7 +321,7 @@ The device should answer:
|
||||
|
||||
#### Controller wants the device to perform a factory reset
|
||||
Controller sends this command when it believes the device should upgrade its firmware.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "factory" ,
|
||||
"params" : {
|
||||
@@ -306,7 +334,7 @@ Controller sends this command when it believes the device should upgrade its fir
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
@@ -320,9 +348,50 @@ The device should answer:
|
||||
}
|
||||
```
|
||||
|
||||
#### Controller issuing RRM commands to the AP
|
||||
Controller sends this command to perform several RRM commands.
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "rrm" ,
|
||||
"params" : {
|
||||
"serial" : <serial number> ,
|
||||
"actions": [
|
||||
{
|
||||
"type": "roam",
|
||||
"bss": [ "00:11:22:33:44:55", ... ],
|
||||
"params" : { action specific data }
|
||||
}, {
|
||||
"type": "tx-power",
|
||||
"bss": [ "00:11:22:33:44:55", ... ],
|
||||
“params”: { action specific data }
|
||||
}, {
|
||||
"type": "beacon-request",
|
||||
"bss": [ "00:11:22:33:44:55", ... ],
|
||||
"params": { action specific data }
|
||||
}
|
||||
]
|
||||
},
|
||||
"id" : <some number>
|
||||
}
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
"status" : {
|
||||
"error" : 0 or an error number,
|
||||
"text" : <description of the error or success>,
|
||||
}
|
||||
},
|
||||
"id" : <same number>
|
||||
}
|
||||
```
|
||||
|
||||
#### Controller wants the device to flash its LEDs
|
||||
Controller sends this command when it wants the device to flash its LEDs.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "leds" ,
|
||||
"params" : {
|
||||
@@ -336,14 +405,13 @@ Controller sends this command when it wants the device to flash its LEDs.
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
"status" : {
|
||||
"error" : 0 or an error number,
|
||||
"text" : <description of the error or success>,
|
||||
"when" : <time when this will be performed as UTC seconds>,
|
||||
}
|
||||
},
|
||||
"id" : <same number>
|
||||
@@ -358,7 +426,7 @@ The device should answer:
|
||||
#### Controller sends a device specific command
|
||||
Controller sends this command specific to this device. The command is proprietary and must be agreed upon by the device
|
||||
and the controller.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "perform" ,
|
||||
"params" : {
|
||||
@@ -372,7 +440,7 @@ and the controller.
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
@@ -395,7 +463,7 @@ The device should answer with teh above message. The `error` value should be int
|
||||
|
||||
#### Controller wants the device to perform a trace
|
||||
Controller sends this command when it needs the device to perform a trace (i.e. tcpdump).
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "trace" ,
|
||||
"params" : {
|
||||
@@ -412,7 +480,7 @@ Controller sends this command when it needs the device to perform a trace (i.e.
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
@@ -438,7 +506,7 @@ uploaded or the timeout occurs, the upload will be rejected.
|
||||
|
||||
#### Controller wants the device to perform a WiFi Scan
|
||||
Controller sends this command when it needs the device to perform a WiFi Scan.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "wifiscan" ,
|
||||
"params" : {
|
||||
@@ -446,15 +514,16 @@ Controller sends this command when it needs the device to perform a WiFi Scan.
|
||||
"bands" : [ "2","5","5l","5u",6" ], <optional this is a list of bands to scan: on or more bands >
|
||||
"channels" : [ 1,2,3...] , <optional list of discreet channels to scan >
|
||||
"verbose" : <optional boolean: true or false> (by default false),
|
||||
"bandwidth" : <optional int: 20,40,80 in MHz>
|
||||
"active" : 0 or 1 (to select passive or active scan)
|
||||
"bandwidth" : <optional int: 20,40,80 in MHz>,
|
||||
"active" : 0 or 1 (to select passive or active scan),
|
||||
"ies": <optional: array of unsigned int 8 bits: i.e. [1,4,34,58,91]>
|
||||
},
|
||||
"id" : <some number>
|
||||
}
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
@@ -477,7 +546,7 @@ Controller sends this command when it needs the device to provide a message back
|
||||
supported messages are "state" and "healthcheck". More messages maybe added later. The messages will
|
||||
be returned the usual way. The RPC response to this message just says that the request has been accepted and the
|
||||
message will be returned "soon".
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "request" ,
|
||||
"params" : {
|
||||
@@ -491,7 +560,7 @@ message will be returned "soon".
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
@@ -507,7 +576,7 @@ The device should answer:
|
||||
|
||||
#### Controller requesting eventqueue buffers
|
||||
Controller sends this command when it needs the device to provide the content of ist ring buffers.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "event" ,
|
||||
"params" : {
|
||||
@@ -521,7 +590,7 @@ Controller sends this command when it needs the device to provide the content of
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
@@ -537,7 +606,7 @@ The device should answer:
|
||||
|
||||
#### Controller requesting telemetry stream information
|
||||
Controller sends this command when it needs the device to telemetry streaming.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "telemetry" ,
|
||||
"params" : {
|
||||
@@ -550,7 +619,7 @@ Controller sends this command when it needs the device to telemetry streaming.
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
@@ -564,7 +633,7 @@ The device should answer:
|
||||
```
|
||||
|
||||
When the interval is greater than 0, the gateway will start to receive messages
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "telemetry" ,
|
||||
"params" : {
|
||||
@@ -579,7 +648,7 @@ The device will stop sending data after 30 minutes or if it receives a `telemetr
|
||||
|
||||
#### Controller requesting an `rtty` session
|
||||
Controller sends this command an administrator requests to start an `rtty` session with the AP.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "remote_access" ,
|
||||
"params" : {
|
||||
@@ -597,7 +666,7 @@ Controller sends this command an administrator requests to start an `rtty` sessi
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
@@ -613,7 +682,7 @@ The device should answer:
|
||||
|
||||
#### Controller wants to ping the device
|
||||
Controller sends this command when it tries to establish latency to the device.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "ping" ,
|
||||
"params" : {
|
||||
@@ -624,7 +693,7 @@ Controller sends this command when it tries to establish latency to the device.
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
@@ -637,12 +706,12 @@ The device should answer:
|
||||
|
||||
#### Controller wants the device to perform a script
|
||||
Controller sends this command to run a predefined script. Extreme care must be taken.
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "script" ,
|
||||
"params" : {
|
||||
"serial" : <serial number>,
|
||||
"type" : <one of "uci", "shell", "ucode">,
|
||||
"type" : <one of "shell", "ucode">,
|
||||
"script" : <text blob containing the script>,
|
||||
"timeout" : <max timeout in seconds, default is 30>,
|
||||
"when" : <time when this will be performed as UTC seconds>
|
||||
@@ -652,12 +721,12 @@ Controller sends this command to run a predefined script. Extreme care must be t
|
||||
```
|
||||
|
||||
The device should answer:
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"result" : {
|
||||
"serial" : <serial number> ,
|
||||
"status" : {
|
||||
"error" : <0 or the value of $? from the shell running the command>,
|
||||
"error" : <0 or the value of $? from the shell running the command, 255 signifies a timeout>,
|
||||
one of either
|
||||
"result_64" : <gzipped base64 result of running the command>,
|
||||
"result_sz" : <size of unzipped content>
|
||||
@@ -686,7 +755,7 @@ params will be dropped. Additional compression schemes may be developed later.
|
||||
The original `params` element should be run through `zlib:compress` and then encoded using base64, and passed as a string. Here is an example
|
||||
of the completed message. The following should how the `state` event could be compressed:
|
||||
|
||||
```
|
||||
```json
|
||||
{ "jsonrpc" : "2.0" ,
|
||||
"method" : "state" ,
|
||||
"params" : {
|
||||
@@ -699,13 +768,10 @@ of the completed message. The following should how the `state` event could be co
|
||||
The gateway can receive RADIUS messages from the device and forward them. It can also receive messages
|
||||
on its behalf and send them to the device.
|
||||
|
||||
```
|
||||
```json
|
||||
{
|
||||
"radius" : <type, can be auth, acct, das> ,
|
||||
"radius" : <type, can be auth, acct, coa> ,
|
||||
"data" : <base 64 encoded raw RADIUS payload>
|
||||
"dst" : <ip:port> as a string - optional. If this is supplied, the GW will send the data to that destination,
|
||||
if not provided, the GW will use one of the radius servers it has in its configuration. This is only
|
||||
valid for messages coming from the device.
|
||||
}
|
||||
```
|
||||
|
||||
@@ -716,11 +782,10 @@ identify the destination for its messages.
|
||||
The GW must be configured with the following:
|
||||
|
||||
```asm
|
||||
radius.incoming.proxy.enable = true
|
||||
radius.incoming.proxy.accounting.port = 1813
|
||||
radius.incoming.proxy.auth.port = 1812
|
||||
radius.incoming.proxy.das.port = 1814
|
||||
radius.incoming.serialnumbertlv = 127
|
||||
radius.proxy.enable = true
|
||||
radius.proxy.accounting.port = 1813
|
||||
radius.proxy.authentication.port = 1812
|
||||
radius.proxy.coa.port = 3799
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ sudo cmake --build . --target install
|
||||
cd ~
|
||||
git clone https://github.com/nlohmann/json.git
|
||||
cd json
|
||||
git checkout tags/v3.10.2
|
||||
mkdir cmake-build
|
||||
cd cmake-build
|
||||
cmake ..
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@ if [ "$SELFSIGNED_CERTS" = 'true' ]; then
|
||||
update-ca-certificates
|
||||
fi
|
||||
|
||||
if [[ "$TEMPLATE_CONFIG" = 'true' && ! -f "$OWGW_CONFIG"/owgw.properties ]]; then
|
||||
if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
|
||||
WEBSOCKET_HOST_ROOTCA=${WEBSOCKET_HOST_ROOTCA:-"\$OWGW_ROOT/certs/root.pem"} \
|
||||
WEBSOCKET_HOST_ISSUER=${WEBSOCKET_HOST_ISSUER:-"\$OWGW_ROOT/certs/issuer.pem"} \
|
||||
WEBSOCKET_HOST_CERT=${WEBSOCKET_HOST_CERT:-"\$OWGW_ROOT/certs/websocket-cert.pem"} \
|
||||
@@ -39,6 +39,10 @@ if [[ "$TEMPLATE_CONFIG" = 'true' && ! -f "$OWGW_CONFIG"/owgw.properties ]]; the
|
||||
SYSTEM_URI_PUBLIC=${SYSTEM_URI_PUBLIC:-"https://localhost:16002"} \
|
||||
SYSTEM_URI_UI=${SYSTEM_URI_UI:-"http://localhost"} \
|
||||
SIMULATORID=${SIMULATORID:-""} \
|
||||
IPTOCOUNTRY_PROVIDER=${IPTOCOUNTRY_PROVIDER:-"ipinfo"} \
|
||||
IPTOCOUNTRY_IPINFO_TOKEN=${IPTOCOUNTRY_IPINFO_TOKEN:-""} \
|
||||
IPTOCOUNTRY_IPDATA_APIKEY=${IPTOCOUNTRY_IPDATA_APIKEY:-""} \
|
||||
AUTOPROVISIONING_PROCESS=${AUTOPROVISIONING_PROCESS:-"prov,default"} \
|
||||
RTTY_INTERNAL=${RTTY_INTERNAL:-"true"} \
|
||||
RTTY_ENABLED=${RTTY_ENABLED:-"true"} \
|
||||
RTTY_SERVER=${RTTY_SERVER:-"localhost"} \
|
||||
|
||||
@@ -9,7 +9,7 @@ fullnameOverride: ""
|
||||
images:
|
||||
owgw:
|
||||
repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owgw
|
||||
tag: v2.6.0-RC1
|
||||
tag: v2.6.2
|
||||
pullPolicy: Always
|
||||
# regcred:
|
||||
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io
|
||||
@@ -215,7 +215,7 @@ configProperties:
|
||||
openwifi.devicetypes.0: AP:linksys_ea8300,edgecore_eap101,linksys_e8450-ubi
|
||||
openwifi.devicetypes.1: SWITCH:edgecore_ecs4100-12ph
|
||||
openwifi.devicetypes.2: IOT:esp32
|
||||
oui.download.uri: https://linuxnet.ca/ieee/oui.txt
|
||||
oui.download.uri: https://standards-oui.ieee.org/oui/oui.txt
|
||||
firmware.autoupdate.policy.default: auto
|
||||
iptocountry.provider: ipinfo
|
||||
# Callback
|
||||
|
||||
@@ -31,58 +31,13 @@ components:
|
||||
|
||||
responses:
|
||||
NotFound:
|
||||
description: The specified resource was not found.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
properties:
|
||||
ErrorCode:
|
||||
type: integer
|
||||
ErrorDetails:
|
||||
type: string
|
||||
ErrorDescription:
|
||||
type: string
|
||||
|
||||
$ref: 'https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml#/components/responses/NotFound'
|
||||
Unauthorized:
|
||||
description: The requested does not have sufficient rights to perform the operation.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
properties:
|
||||
ErrorCode:
|
||||
type: integer
|
||||
enum:
|
||||
- 0 # Success
|
||||
- 1 # PASSWORD_CHANGE_REQUIRED,
|
||||
- 2 # INVALID_CREDENTIALS,
|
||||
- 3 # PASSWORD_ALREADY_USED,
|
||||
- 4 # USERNAME_PENDING_VERIFICATION,
|
||||
- 5 # PASSWORD_INVALID,
|
||||
- 6 # INTERNAL_ERROR,
|
||||
- 7 # ACCESS_DENIED,
|
||||
- 8 # INVALID_TOKEN
|
||||
- 9 # EXPIRED_TOKEN
|
||||
- 10 # RATE_LIMIT_EXCEEDED
|
||||
- 11 # BAD_MFA_TRANSACTION
|
||||
- 12 # MFA_FAILURE
|
||||
- 13 # SECURITY_SERVICE_UNREACHABLE
|
||||
ErrorDetails:
|
||||
type: string
|
||||
ErrorDescription:
|
||||
type: string
|
||||
|
||||
$ref: 'https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml#/components/responses/Unauthorized'
|
||||
Success:
|
||||
description: The requested operation was performed.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
properties:
|
||||
Operation:
|
||||
type: string
|
||||
Details:
|
||||
type: string
|
||||
Code:
|
||||
type: integer
|
||||
$ref: 'https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml#/components/responses/Success'
|
||||
BadRequest:
|
||||
$ref: 'https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml#/components/responses/BadRequest'
|
||||
|
||||
schemas:
|
||||
DeviceType:
|
||||
@@ -1001,6 +956,12 @@ components:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/WifiBands'
|
||||
- $ref: '#/components/schemas/WifiChannels'
|
||||
ies:
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
minimum: 0
|
||||
maximum: 255
|
||||
required:
|
||||
- serialNumber
|
||||
|
||||
@@ -1084,6 +1045,10 @@ components:
|
||||
type: integer
|
||||
weight:
|
||||
type: integer
|
||||
secret:
|
||||
type: string
|
||||
certificate:
|
||||
type: string
|
||||
|
||||
RadiusProxyServerConfig:
|
||||
type: object
|
||||
@@ -1123,6 +1088,8 @@ components:
|
||||
$ref: '#/components/schemas/RadiusProxyServerConfig'
|
||||
acctConfig:
|
||||
$ref: '#/components/schemas/RadiusProxyServerConfig'
|
||||
coaConfig:
|
||||
$ref: '#/components/schemas/RadiusProxyServerConfig'
|
||||
|
||||
RadiusProxyPoolList:
|
||||
type: object
|
||||
@@ -2586,6 +2553,16 @@ paths:
|
||||
403:
|
||||
$ref: '#/components/responses/Unauthorized'
|
||||
|
||||
delete:
|
||||
tags:
|
||||
- RADIUSProxy
|
||||
summary: Delete RADIUS Proxy configuration.
|
||||
operationId: deleteRadiusProxyConfig
|
||||
responses:
|
||||
204:
|
||||
$ref: '#/components/responses/Success'
|
||||
403:
|
||||
$ref: '#/components/responses/Unauthorized'
|
||||
|
||||
/deviceDashboard:
|
||||
get:
|
||||
|
||||
@@ -96,6 +96,12 @@ rtty.timeout = 60
|
||||
rtty.viewport = 5913
|
||||
rtty.assets = $OWGW_ROOT/rtty_ui
|
||||
|
||||
### RADIUS proxy config
|
||||
radius.proxy.enable = false
|
||||
radius.proxy.accounting.port = 1813
|
||||
radius.proxy.authentication.port = 1812
|
||||
radius.proxy.coa.port = 3799
|
||||
|
||||
#############################
|
||||
# Generic information for all micro services
|
||||
#############################
|
||||
|
||||
@@ -52,8 +52,8 @@ openwifi.fileuploader.host.0.cert = ${FILEUPLOADER_HOST_CERT}
|
||||
openwifi.fileuploader.host.0.key = ${FILEUPLOADER_HOST_KEY}
|
||||
openwifi.fileuploader.host.0.key.password = ${FILEUPLOADER_HOST_KEY_PASSWORD}
|
||||
openwifi.fileuploader.path = ${FILEUPLOADER_PATH}
|
||||
openwifi.fileuploader.uri = ${FILEUPLOADER_URI}
|
||||
openwifi.fileuploader.maxsize = 10000
|
||||
openwifi.fileuploader.uri = ${FILEUPLOADER_URI}
|
||||
|
||||
#
|
||||
# Generic section that all microservices must have
|
||||
@@ -75,8 +75,13 @@ openwifi.devicetypes.0 = AP:linksys_ea8300,edgecore_eap101,linksys_e8450-ubi
|
||||
openwifi.devicetypes.1 = SWITCH:edgecore_ecs4100-12ph
|
||||
openwifi.devicetypes.2 = IOT:esp32
|
||||
oui.download.uri = https://standards-oui.ieee.org/oui/oui.txt
|
||||
firmware.autoupdate.policy.default = auto
|
||||
simulatorid = ${SIMULATORID}
|
||||
iptocountry.default = US
|
||||
iptocountry.provider = ${IPTOCOUNTRY_PROVIDER}
|
||||
iptocountry.ipinfo.token = ${IPTOCOUNTRY_IPINFO_TOKEN}
|
||||
iptocountry.ipdata.apikey = ${IPTOCOUNTRY_IPDATA_APIKEY}
|
||||
|
||||
autoprovisioning.process = ${AUTOPROVISIONING_PROCESS}
|
||||
|
||||
#
|
||||
# rtty
|
||||
@@ -108,6 +113,7 @@ openwifi.kafka.enable = ${KAFKA_ENABLE}
|
||||
openwifi.kafka.brokerlist = ${KAFKA_BROKERLIST}
|
||||
openwifi.kafka.auto.commit = false
|
||||
openwifi.kafka.queue.buffering.max.ms = 50
|
||||
|
||||
openwifi.kafka.ssl.ca.location = ${KAFKA_SSL_CA_LOCATION}
|
||||
openwifi.kafka.ssl.certificate.location = ${KAFKA_SSL_CERTIFICATE_LOCATION}
|
||||
openwifi.kafka.ssl.key.location = ${KAFKA_SSL_KEY_LOCATION}
|
||||
|
||||
1
pcap/radius.blob.bin
Normal file
1
pcap/radius.blob.bin
Normal file
@@ -0,0 +1 @@
|
||||
192.168.178.1
|
||||
72
radius_config_sample.json
Normal file
72
radius_config_sample.json
Normal file
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"pools" : [
|
||||
{
|
||||
"name" : "master" ,
|
||||
"description" : "master pool",
|
||||
"useByDefault" : true,
|
||||
"authConfig" : {
|
||||
"strategy" : "weighted",
|
||||
"monitor" : false,
|
||||
"monitorMethod" : "none",
|
||||
"methodParameters" : [],
|
||||
"servers" : [ {
|
||||
"name" : "svr1",
|
||||
"ip" : "10.100.0.1",
|
||||
"port" : 1812,
|
||||
"weight" : 10,
|
||||
"secret" : "my_secret!"
|
||||
},
|
||||
{
|
||||
"name" : "svr2",
|
||||
"ip" : "10.100.10.1",
|
||||
"port" : 1812,
|
||||
"weight" : 20,
|
||||
"secret" : "my_secret!"
|
||||
}
|
||||
]
|
||||
},
|
||||
"acctConfig" : {
|
||||
"strategy" : "random",
|
||||
"monitor" : false,
|
||||
"monitorMethod" : "none",
|
||||
"methodParameters" : [],
|
||||
"servers" : [ {
|
||||
"name" : "svr1",
|
||||
"ip" : "10.100.0.1",
|
||||
"port" : 1813,
|
||||
"weight" : 10,
|
||||
"secret" : "my_secret!"
|
||||
},
|
||||
{
|
||||
"name" : "svr2",
|
||||
"ip" : "10.100.10.1",
|
||||
"port" : 1813,
|
||||
"weight" : 20,
|
||||
"secret" : "my_secret!"
|
||||
}
|
||||
]
|
||||
},
|
||||
"coaConfig" : {
|
||||
"strategy" : "round_robin",
|
||||
"monitor" : false,
|
||||
"monitorMethod" : "none",
|
||||
"methodParameters" : [],
|
||||
"servers" : [ {
|
||||
"name" : "svr1",
|
||||
"ip" : "10.100.0.1",
|
||||
"port" : 3799,
|
||||
"weight" : 10,
|
||||
"secret" : "my_secret!"
|
||||
},
|
||||
{
|
||||
"name" : "svr2",
|
||||
"ip" : "10.100.10.1",
|
||||
"port" : 3799,
|
||||
"weight" : 20,
|
||||
"secret" : "my_secret!"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
namespace OpenWifi {
|
||||
|
||||
void CommandManager::run() {
|
||||
Utils::SetThreadName("cmd-mgr");
|
||||
Running_ = true;
|
||||
Poco::AutoPtr<Poco::Notification> NextMsg(ResponseQueue_.waitDequeueNotification());
|
||||
while(NextMsg && Running_) {
|
||||
@@ -31,42 +32,32 @@ namespace OpenWifi {
|
||||
std::ostringstream SS;
|
||||
Payload.stringify(SS);
|
||||
|
||||
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
|
||||
// std::cout << "Got RPC Answer: " << SerialNumber << " Payload:" << SS.str() << std::endl;
|
||||
Logger().debug(fmt::format("({}): RPC Response received.", SerialNumber));
|
||||
if(!Payload.has(uCentralProtocol::ID)){
|
||||
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
|
||||
Logger().error(fmt::format("({}): Invalid RPC response.", SerialNumber));
|
||||
} else {
|
||||
uint64_t ID = Payload.get(uCentralProtocol::ID);
|
||||
if (ID < 2) {
|
||||
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
|
||||
Logger().debug(fmt::format("({}): Ignoring RPC response.", SerialNumber));
|
||||
} else {
|
||||
auto Idx = CommandTagIndex{.Id = ID, .SerialNumber = SerialNumber};
|
||||
std::lock_guard G(Mutex_);
|
||||
auto RPC = OutStandingRequests_.find(Idx);
|
||||
if (RPC == OutStandingRequests_.end()) {
|
||||
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
|
||||
Logger().warning(
|
||||
fmt::format("({}): Outdated RPC {}", SerialNumber, ID));
|
||||
} else {
|
||||
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
|
||||
std::chrono::duration<double, std::milli> rpc_execution_time =
|
||||
std::chrono::high_resolution_clock::now() - RPC->second->submitted;
|
||||
StorageService()->CommandCompleted(RPC->second->uuid, Payload,
|
||||
rpc_execution_time, true);
|
||||
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
|
||||
if (RPC->second->rpc_entry) {
|
||||
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
|
||||
RPC->second->rpc_entry->set_value(Payload);
|
||||
}
|
||||
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
|
||||
OutstandingUUIDs_.erase(RPC->second->uuid);
|
||||
OutStandingRequests_.erase(Idx);
|
||||
Logger().information(
|
||||
fmt::format("({}): Received RPC answer {}", SerialNumber, ID));
|
||||
// std::cout << SerialNumber << ": " << __LINE__ << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,8 +68,6 @@ namespace OpenWifi {
|
||||
|
||||
int CommandManager::Start() {
|
||||
Logger().notice("Starting...");
|
||||
ManagerThread.setStackSize(2000000);
|
||||
ManagerThread.setName("CMD-MGR");
|
||||
ManagerThread.start(*this);
|
||||
JanitorCallback_ = std::make_unique<Poco::TimerCallback<CommandManager>>(*this,&CommandManager::onJanitorTimer);
|
||||
JanitorTimer_.setStartInterval( 10000 );
|
||||
@@ -90,15 +79,11 @@ namespace OpenWifi {
|
||||
CommandRunnerTimer_.setPeriodicInterval(30 * 1000); // 1 hours
|
||||
CommandRunnerTimer_.start(*CommandRunnerCallback_);
|
||||
|
||||
// RPCResponseQueue_->Readable_ += Poco::delegate(this,&CommandManager::onRPCAnswer);
|
||||
// RPCResponseQueue_->Writable_ += Poco::delegate(this,&CommandManager::onRPCAnswer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CommandManager::Stop() {
|
||||
Logger().notice("Stopping...");
|
||||
// RPCResponseQueue_->Readable_ -= Poco::delegate(this,&CommandManager::onRPCAnswer);
|
||||
// RPCResponseQueue_->Writable_ -= Poco::delegate(this,&CommandManager::onRPCAnswer);
|
||||
Running_ = false;
|
||||
JanitorTimer_.stop();
|
||||
CommandRunnerTimer_.stop();
|
||||
@@ -114,24 +99,29 @@ namespace OpenWifi {
|
||||
|
||||
void CommandManager::onJanitorTimer([[maybe_unused]] Poco::Timer & timer) {
|
||||
std::lock_guard G(Mutex_);
|
||||
Logger().information(
|
||||
Utils::SetThreadName("cmd-janitor");
|
||||
Poco::Logger & MyLogger = Poco::Logger::get("CMD-MGR-JANITOR");
|
||||
MyLogger.information(
|
||||
fmt::format("Removing expired commands: start. {} outstanding-requests {} outstanding-uuids commands.",
|
||||
OutStandingRequests_.size(), OutstandingUUIDs_.size() ));
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
for(auto i=OutStandingRequests_.begin();i!=OutStandingRequests_.end();) {
|
||||
std::chrono::duration<double, std::milli> delta = now - i->second->submitted;
|
||||
if(delta > 6000000ms) {
|
||||
Logger().debug(fmt::format("{}: Timed out.", i->second->uuid));
|
||||
MyLogger.debug(fmt::format("{}: Timed out.", i->second->uuid));
|
||||
OutstandingUUIDs_.erase(i->second->uuid);
|
||||
i = OutStandingRequests_.erase(i);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
Logger().information("Removing expired commands: done.");
|
||||
MyLogger.information("Removing expired commands: done.");
|
||||
}
|
||||
|
||||
void CommandManager::onCommandRunnerTimer([[maybe_unused]] Poco::Timer &timer) {
|
||||
Utils::SetThreadName("cmd-schdlr");
|
||||
Poco::Logger & MyLogger = Poco::Logger::get("CMD-MGR-SCHEDULER");
|
||||
|
||||
std::vector<GWObjects::CommandDetails> Commands;
|
||||
if(StorageService()->GetReadyToExecuteCommands(0,200,Commands))
|
||||
{
|
||||
@@ -148,7 +138,7 @@ namespace OpenWifi {
|
||||
|
||||
Poco::JSON::Parser P;
|
||||
bool Sent;
|
||||
Logger().information(fmt::format("{}-{}: Processing.", Cmd.SerialNumber, Cmd.UUID));
|
||||
MyLogger.information(fmt::format("{}: Preparing execution of {} for {}.", Cmd.UUID, Cmd.Command, Cmd.SerialNumber));
|
||||
auto Params = P.parse(Cmd.Details).extract<Poco::JSON::Object::Ptr>();
|
||||
auto Result = PostCommandDisk( Cmd.SerialNumber,
|
||||
Cmd.Command,
|
||||
@@ -157,17 +147,18 @@ namespace OpenWifi {
|
||||
Sent);
|
||||
if(Sent) {
|
||||
StorageService()->SetCommandExecuted(Cmd.UUID);
|
||||
std::lock_guard M(Mutex_);
|
||||
OutstandingUUIDs_.insert(Cmd.UUID);
|
||||
Logger().information(fmt::format("{}-{}: Sent command {}.", Cmd.SerialNumber, Cmd.UUID, Cmd.Command));
|
||||
MyLogger.information(fmt::format("{}: Queued command.", Cmd.UUID));
|
||||
} else {
|
||||
Logger().information(fmt::format("{}-{}: Could not Send command {}.", Cmd.SerialNumber, Cmd.UUID, Cmd.Command));
|
||||
MyLogger.information(fmt::format("{}: Could queue command.", Cmd.UUID));
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger().information(fmt::format("{}-{}: Failed command {}.", Cmd.SerialNumber, Cmd.UUID, Cmd.Command));
|
||||
Logger().log(E);
|
||||
MyLogger.information(fmt::format("{}: Failed. Command marked as completed.", Cmd.UUID));
|
||||
MyLogger.log(E);
|
||||
StorageService()->SetCommandExecuted(Cmd.UUID);
|
||||
} catch (...) {
|
||||
Logger().information(fmt::format("{}-{}: Hard failed command {}.", Cmd.SerialNumber, Cmd.UUID, Cmd.Command));
|
||||
MyLogger.information(fmt::format("{}: Hard failure.", Cmd.UUID));
|
||||
StorageService()->SetCommandExecuted(Cmd.UUID);
|
||||
}
|
||||
}
|
||||
@@ -205,9 +196,6 @@ namespace OpenWifi {
|
||||
CompleteRPC.set(uCentralProtocol::METHOD, Method);
|
||||
CompleteRPC.set(uCentralProtocol::PARAMS, Params);
|
||||
Poco::JSON::Stringifier::stringify(CompleteRPC, ToSend);
|
||||
Logger().information(
|
||||
fmt::format("{}-{}: Sending command {}, ID: {}", SerialNumber, UUID, Method, Idx.Id));
|
||||
|
||||
Object->submitted = std::chrono::high_resolution_clock::now();
|
||||
Object->uuid = UUID;
|
||||
if(disk_only) {
|
||||
@@ -221,10 +209,13 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
Logger().information(fmt::format("{}: Sending command. ID: {}", UUID, Idx.Id));
|
||||
if(DeviceRegistry()->SendFrame(SerialNumber, ToSend.str())) {
|
||||
Logger().information(fmt::format("{}: Sent command. ID: {}", UUID, Idx.Id));
|
||||
Sent=true;
|
||||
return Object->rpc_entry;
|
||||
}
|
||||
Logger().information(fmt::format("{}: Failed to send command. ID: {}", UUID, Idx.Id));
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace
|
||||
@@ -154,16 +154,15 @@ namespace OpenWifi {
|
||||
void onRPCAnswer(bool& b);
|
||||
|
||||
private:
|
||||
std::atomic_bool Running_ = false;
|
||||
volatile bool Running_ = false;
|
||||
Poco::Thread ManagerThread;
|
||||
uint64_t Id_=3; // do not start @1. We ignore ID=1 & 0 is illegal..
|
||||
volatile uint64_t Id_=3; // do not start @1. We ignore ID=1 & 0 is illegal..
|
||||
std::map<CommandTagIndex,std::shared_ptr<RpcObject>> OutStandingRequests_;
|
||||
std::set<std::string> OutstandingUUIDs_;
|
||||
Poco::Timer JanitorTimer_;
|
||||
std::unique_ptr<Poco::TimerCallback<CommandManager>> JanitorCallback_;
|
||||
Poco::Timer CommandRunnerTimer_;
|
||||
std::unique_ptr<Poco::TimerCallback<CommandManager>> CommandRunnerCallback_;
|
||||
// std::unique_ptr<FIFO<RPCResponse>> RPCResponseQueue_=std::make_unique<FIFO<RPCResponse>>(100);
|
||||
Poco::NotificationQueue ResponseQueue_;
|
||||
|
||||
std::shared_ptr<promise_type_t> PostCommand(
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "FindCountry.h"
|
||||
#include "rttys/RTTYS_server.h"
|
||||
#include "RADIUS_proxy_server.h"
|
||||
#include "VenueBroadcaster.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class Daemon *Daemon::instance() {
|
||||
@@ -47,7 +48,8 @@ namespace OpenWifi {
|
||||
TelemetryStream(),
|
||||
RTTYS_server(),
|
||||
WebSocketServer(),
|
||||
RADIUS_proxy_server()
|
||||
RADIUS_proxy_server(),
|
||||
VenueBroadcaster()
|
||||
});
|
||||
return &instance;
|
||||
}
|
||||
|
||||
@@ -173,6 +173,23 @@ namespace OpenWifi {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DeviceRegistry::SendRadiusCoAData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size) {
|
||||
std::lock_guard Guard(Mutex_);
|
||||
auto Device = Devices_.find(Utils::SerialNumberToInt(SerialNumber));
|
||||
if(Device!=Devices_.end() && Device->second->WSConn_!= nullptr) {
|
||||
try {
|
||||
return Device->second->WSConn_->SendRadiusCoAData(buffer,size);
|
||||
} catch (...) {
|
||||
Logger().debug(fmt::format("Could not send data to device '{}'", SerialNumber));
|
||||
Device->second->Conn_.Address = "";
|
||||
Device->second->WSConn_ = nullptr;
|
||||
Device->second->Conn_.Connected = false;
|
||||
Device->second->Conn_.VerifiedCertificate = GWObjects::NO_CERTIFICATE;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DeviceRegistry::SetPendingUUID(uint64_t SerialNumber, uint64_t PendingUUID) {
|
||||
std::lock_guard Guard(Mutex_);
|
||||
auto Device = Devices_.find(SerialNumber);
|
||||
|
||||
@@ -105,6 +105,7 @@ namespace OpenWifi {
|
||||
|
||||
bool SendRadiusAuthenticationData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size);
|
||||
bool SendRadiusAccountingData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size);
|
||||
bool SendRadiusCoAData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size);
|
||||
|
||||
private:
|
||||
inline static std::atomic_uint64_t Id_=1;
|
||||
|
||||
@@ -194,6 +194,7 @@ namespace OpenWifi {
|
||||
|
||||
void handleRequest(Poco::Net::HTTPServerRequest& Request, Poco::Net::HTTPServerResponse& Response) final {
|
||||
|
||||
Utils::SetThreadName("FileUploader");
|
||||
const auto ContentType = Request.getContentType();
|
||||
const auto Tokens = Poco::StringTokenizer(ContentType,";",Poco::StringTokenizer::TOK_TRIM);
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
void OUIServer::onTimer([[maybe_unused]] Poco::Timer & timer) {
|
||||
Utils::SetThreadName("ouisvr-timer");
|
||||
if(Updating_)
|
||||
return;
|
||||
Updating_ = true;
|
||||
|
||||
@@ -33,8 +33,8 @@ namespace OpenWifi {
|
||||
uint64_t LastUpdate_ = 0 ;
|
||||
bool Initialized_ = false;
|
||||
OUIMap OUIs_;
|
||||
std::atomic_bool Updating_=false;
|
||||
std::atomic_bool Running_=false;
|
||||
volatile std::atomic_bool Updating_=false;
|
||||
volatile std::atomic_bool Running_=false;
|
||||
Poco::Timer Timer_;
|
||||
std::unique_ptr<Poco::TimerCallback<OUIServer>> UpdaterCallBack_;
|
||||
std::string LatestOUIFileName_,CurrentOUIFileName_;
|
||||
|
||||
1829
src/ParseWifiScan.h
Normal file
1829
src/ParseWifiScan.h
Normal file
File diff suppressed because it is too large
Load Diff
211
src/RADIUS_helpers.h
Normal file
211
src/RADIUS_helpers.h
Normal file
@@ -0,0 +1,211 @@
|
||||
//
|
||||
// Created by stephane bourque on 2022-06-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
namespace OpenWifi::RADIUS {
|
||||
|
||||
#pragma pack(push,1)
|
||||
struct RadiusAttribute {
|
||||
unsigned char type{0};
|
||||
uint16_t pos{0};
|
||||
unsigned len{0};
|
||||
};
|
||||
struct RawRadiusPacket {
|
||||
unsigned char code{1};
|
||||
unsigned char identifier{0};
|
||||
uint16_t len{0};
|
||||
unsigned char authenticator[16]{0};
|
||||
unsigned char attributes[4096]{0};
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
//
|
||||
// From: https://github.com/Telecominfraproject/wlan-dictionary/blob/main/dictionary.tip
|
||||
//
|
||||
static const uint32_t TIP_vendor_id = 58888;
|
||||
static const unsigned char TIP_serial = 1;
|
||||
static const unsigned char TIP_AAAipaddr = 2;
|
||||
static const unsigned char TIP_AAAipv6addr = 3;
|
||||
|
||||
|
||||
using AttributeList = std::list<RadiusAttribute>;
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, AttributeList const &P) {
|
||||
for(const auto &attr:P) {
|
||||
os << "\tAttr: " << (uint16_t) attr.type << " Size: " << (uint16_t) attr.len << std::endl;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
bool ParseRadius(uint32_t offset, const unsigned char *Buffer, uint16_t Size, AttributeList &Attrs) {
|
||||
Attrs.clear();
|
||||
uint16_t pos=0;
|
||||
auto x=25;
|
||||
while(pos<Size && x) {
|
||||
RadiusAttribute Attr{ .type=Buffer[pos], .pos=(uint16_t )(pos+2+offset), .len=Buffer[pos+1]};
|
||||
// std::cout << "POS: " << pos << " P:" << (uint32_t) Attr.pos << " T:" << (uint32_t) Attr.type << " L:" << (uint32_t) Attr.len << " S:" << (uint32_t) Size << std::endl;
|
||||
if(pos+Attr.len<=Size) {
|
||||
Attrs.emplace_back(Attr);
|
||||
} else {
|
||||
std::cout << "Bad parse1: " << (uint32_t) (pos+Attr.len) << " S:" << Size << std::endl;
|
||||
return false;
|
||||
}
|
||||
if(Buffer[pos+1]==0) {
|
||||
std::cout << "Bad parse2: " << (uint32_t) (pos+Attr.len) << " S:" << Size << std::endl;
|
||||
return false;
|
||||
}
|
||||
pos+=Buffer[pos+1];
|
||||
x--;
|
||||
}
|
||||
// std::cout << "Good parse" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
class RadiusPacket {
|
||||
public:
|
||||
explicit RadiusPacket(const unsigned char *buffer, uint16_t size) {
|
||||
memcpy((void *)&P_,buffer, size);
|
||||
Size_=size;
|
||||
Valid_ = ParseRadius(0,(unsigned char *)&P_.attributes[0],Size_-20,Attrs_);
|
||||
}
|
||||
|
||||
explicit RadiusPacket(const std::string &p) {
|
||||
memcpy((void *)&P_,(const unsigned char*) p.c_str(), p.size());
|
||||
Size_=p.size();
|
||||
Valid_ = ParseRadius(0,(unsigned char *)&P_.attributes[0],Size_-20,Attrs_);
|
||||
}
|
||||
|
||||
RadiusPacket() = default;
|
||||
|
||||
unsigned char * Buffer() { return (unsigned char *)&P_; }
|
||||
[[nodiscard]] uint16_t BufferLen() const { return sizeof(P_);}
|
||||
|
||||
void Evaluate(uint16_t size) {
|
||||
Size_ = size;
|
||||
Valid_ = ParseRadius(0,(unsigned char *)&P_.attributes[0],Size_-20,Attrs_);
|
||||
}
|
||||
|
||||
[[nodiscard]] uint16_t Len() const { return htons(P_.len); }
|
||||
[[nodiscard]] uint16_t Size() const { return Size_; }
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &os, RadiusPacket const &P);
|
||||
|
||||
void Log(std::ostream &os) {
|
||||
uint16_t p = 0;
|
||||
|
||||
while(p<Size_) {
|
||||
os << std::setfill('0') << std::setw(4) << p << ": ";
|
||||
uint16_t v=0;
|
||||
while(v<16 && p+v<Size_) {
|
||||
os << std::setfill('0') << std::setw(2) << std::right << std::hex << (uint16_t )((const unsigned char *)&P_)[p+v] << " ";
|
||||
v++;
|
||||
}
|
||||
os << std::endl;
|
||||
p+=16;
|
||||
}
|
||||
os << std::dec << std::endl;
|
||||
}
|
||||
|
||||
std::string ExtractSerialNumberTIP() {
|
||||
std::string R;
|
||||
|
||||
for(const auto &attribute:Attrs_) {
|
||||
if(attribute.type==26) {
|
||||
AttributeList VendorAttributes;
|
||||
uint32_t VendorId = htonl( *(const uint32_t *)&(P_.attributes[attribute.pos]));
|
||||
// std::cout << VendorId << std::endl;
|
||||
if(VendorId==TIP_vendor_id) {
|
||||
if (ParseRadius(attribute.pos + 4, &P_.attributes[attribute.pos + 4], attribute.len - 4 - 2,
|
||||
VendorAttributes)) {
|
||||
// std::cout << VendorAttributes << std::endl;
|
||||
for (const auto &vendorAttr: VendorAttributes) {
|
||||
if (vendorAttr.type == TIP_serial) {
|
||||
for (uint16_t i = 0; i < vendorAttr.len; i++) {
|
||||
if (P_.attributes[vendorAttr.pos + i] == '-')
|
||||
continue;
|
||||
R += (char) P_.attributes[vendorAttr.pos + i];
|
||||
}
|
||||
return R;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return R;
|
||||
}
|
||||
|
||||
std::string ExtractSerialNumberFromProxyState() {
|
||||
std::string Result;
|
||||
for(const auto &attribute:Attrs_) {
|
||||
if(attribute.type==33) {
|
||||
const char * SN = (const char *)&P_.attributes[attribute.pos];
|
||||
auto i=0;
|
||||
while(*SN!=':' && i<12) {
|
||||
Result+=*SN++;
|
||||
i++;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
std::string ExtractProxyStateDestination() {
|
||||
std::string Result;
|
||||
for(const auto &attribute:Attrs_) {
|
||||
if(attribute.type==33 && attribute.len>2) {
|
||||
std::string Attr33;
|
||||
// format is serial:IP:port:interface
|
||||
Attr33.assign((const char *)(const char *)&P_.attributes[attribute.pos],attribute.len-2);
|
||||
auto Parts = Poco::StringTokenizer(Attr33,":");
|
||||
if(Parts.count()==4)
|
||||
return Parts[1]+":"+Parts[2];
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
std::string ExtractCallingStationID() {
|
||||
std::string Result;
|
||||
for(const auto &attribute:Attrs_) {
|
||||
if(attribute.type==31 && attribute.len>2) {
|
||||
Result.assign((const char *)(const char *)&P_.attributes[attribute.pos],attribute.len-2);
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
std::string ExtractCalledStationID() {
|
||||
std::string Result;
|
||||
for(const auto &attribute:Attrs_) {
|
||||
if(attribute.type==30 && attribute.len>2) {
|
||||
Result.assign((const char *)(const char *)&P_.attributes[attribute.pos],attribute.len-2);
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
private:
|
||||
RawRadiusPacket P_;
|
||||
uint16_t Size_{0};
|
||||
AttributeList Attrs_;
|
||||
bool Valid_=false;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, RadiusPacket const &P) {
|
||||
os << P.Attrs_ ;
|
||||
return os;
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,25 @@
|
||||
|
||||
#include "RADIUS_proxy_server.h"
|
||||
#include "DeviceRegistry.h"
|
||||
#include "RADIUS_helpers.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
const int SMALLEST_RADIUS_PACKET = 20+19+4;
|
||||
const int RADIUS_BUFFER_SIZE = 2048;
|
||||
const int DEFAULT_RADIUS_AUTHENTICATION_PORT = 1812;
|
||||
const int DEFAULT_RADIUS_ACCOUNTING_PORT = 1813;
|
||||
const int DEFAULT_RADIUS_CoA_PORT = 3799;
|
||||
|
||||
int RADIUS_proxy_server::Start() {
|
||||
|
||||
enabled_ = MicroService::instance().ConfigGetBool("radius.proxy.enable",false);
|
||||
if(!enabled_)
|
||||
return 0;
|
||||
|
||||
ConfigFilename_ = MicroService::instance().DataDir()+"/radius_pool_config.json";
|
||||
|
||||
|
||||
|
||||
Poco::Net::SocketAddress AuthSockAddrV4(Poco::Net::AddressFamily::IPv4,
|
||||
MicroService::instance().ConfigGetInt("radius.proxy.authentication.port",DEFAULT_RADIUS_AUTHENTICATION_PORT));
|
||||
AuthenticationSocketV4_ = std::make_unique<Poco::Net::DatagramSocket>(AuthSockAddrV4,true);
|
||||
@@ -30,151 +37,215 @@ namespace OpenWifi {
|
||||
MicroService::instance().ConfigGetInt("radius.proxy.accounting.port",DEFAULT_RADIUS_ACCOUNTING_PORT));
|
||||
AccountingSocketV6_ = std::make_unique<Poco::Net::DatagramSocket>(AcctSockAddrV6,true);
|
||||
|
||||
Poco::Net::SocketAddress CoASockAddrV4(Poco::Net::AddressFamily::IPv4,
|
||||
MicroService::instance().ConfigGetInt("radius.proxy.coa.port",DEFAULT_RADIUS_CoA_PORT));
|
||||
CoASocketV4_ = std::make_unique<Poco::Net::DatagramSocket>(CoASockAddrV4,true);
|
||||
Poco::Net::SocketAddress CoASockAddrV6(Poco::Net::AddressFamily::IPv6,
|
||||
MicroService::instance().ConfigGetInt("radius.proxy.coa.port",DEFAULT_RADIUS_CoA_PORT));
|
||||
CoASocketV6_ = std::make_unique<Poco::Net::DatagramSocket>(CoASockAddrV6,true);
|
||||
|
||||
AuthenticationReactor_.addEventHandler(*AuthenticationSocketV4_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
|
||||
AuthenticationReactor_.addEventHandler(*AuthenticationSocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
|
||||
|
||||
AccountingReactor_.addEventHandler(*AccountingSocketV4_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
|
||||
AuthenticationReactor_.addEventHandler(*AuthenticationSocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
|
||||
AccountingReactor_.addEventHandler(*AccountingSocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
|
||||
|
||||
|
||||
CoAReactor_.addEventHandler(*CoASocketV4_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnCoASocketReadable));
|
||||
CoAReactor_.addEventHandler(*CoASocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnCoASocketReadable));
|
||||
|
||||
ParseConfig();
|
||||
|
||||
AuthenticationReactorThread_.start(AuthenticationReactor_);
|
||||
AccountingReactorThread_.start(AccountingReactor_);
|
||||
CoAReactorThread_.start(CoAReactor_);
|
||||
|
||||
Utils::SetThreadName(AuthenticationReactorThread_,"radproxy-auth");
|
||||
Utils::SetThreadName(AccountingReactorThread_,"radproxy-acct");
|
||||
Utils::SetThreadName(CoAReactorThread_,"radproxy-coa");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RADIUS_proxy_server::Stop() {
|
||||
AuthenticationReactor_.removeEventHandler(*AuthenticationSocketV4_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
|
||||
AccountingReactor_.removeEventHandler(*AccountingSocketV4_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
|
||||
AuthenticationReactor_.removeEventHandler(*AuthenticationSocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
|
||||
AccountingReactor_.removeEventHandler(*AccountingSocketV6_,Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
|
||||
if(enabled_) {
|
||||
AuthenticationReactor_.removeEventHandler(
|
||||
*AuthenticationSocketV4_,
|
||||
Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
|
||||
AuthenticationReactor_.removeEventHandler(
|
||||
*AuthenticationSocketV6_,
|
||||
Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAuthenticationSocketReadable));
|
||||
|
||||
AuthenticationReactor_.stop();
|
||||
AuthenticationReactorThread_.join();
|
||||
AccountingReactor_.removeEventHandler(
|
||||
*AccountingSocketV4_,
|
||||
Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
|
||||
AccountingReactor_.removeEventHandler(
|
||||
*AccountingSocketV6_,
|
||||
Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
|
||||
|
||||
AccountingReactor_.stop();
|
||||
AccountingReactorThread_.join();
|
||||
}
|
||||
CoAReactor_.removeEventHandler(
|
||||
*CoASocketV4_,
|
||||
Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
|
||||
CoAReactor_.removeEventHandler(
|
||||
*CoASocketV6_,
|
||||
Poco::NObserver<RADIUS_proxy_server, Poco::Net::ReadableNotification>(
|
||||
*this, &RADIUS_proxy_server::OnAccountingSocketReadable));
|
||||
|
||||
std::string ExtractSerialNumber(const unsigned char *b, uint32_t s) {
|
||||
std::string result;
|
||||
AuthenticationReactor_.stop();
|
||||
AuthenticationReactorThread_.join();
|
||||
|
||||
try {
|
||||
uint32_t pos=0;
|
||||
while(pos<s) {
|
||||
auto len = b[pos+1];
|
||||
if(b[pos] != 26) {
|
||||
pos += len;
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t vendor_id = b[pos+2] * 256 * 256 * 256 + b[pos+3] * 256 * 256 + b[pos+4] * 256+ b[pos+5];
|
||||
if(vendor_id!=58888) {
|
||||
pos += len;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto tpos0 = pos + 6;
|
||||
auto tend0 = tpos0 + b[tpos0+1];
|
||||
while (tpos0<tend0) {
|
||||
if (b[tpos0] == 71) {
|
||||
auto tpos1 = tpos0+2;
|
||||
auto tlen1 = b[tpos0+1];
|
||||
auto tend1 = tpos1 + tlen1;
|
||||
while (tpos1 < tend1) {
|
||||
if (b[tpos1] == 0x01) {
|
||||
uint32_t tlen = b[tpos1 + 1] - 2;
|
||||
tpos1 += 2;
|
||||
while (tlen) {
|
||||
if (b[tpos1] != '-') {
|
||||
result += (char) b[tpos1];
|
||||
}
|
||||
tlen--;
|
||||
tpos1++;
|
||||
}
|
||||
if (result.size() == 12)
|
||||
return result;
|
||||
return "";
|
||||
} else {
|
||||
tpos1 += b[tpos1+1];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tpos0 += b[tpos0 + 1];
|
||||
}
|
||||
}
|
||||
pos += len;
|
||||
}
|
||||
} catch (...) {
|
||||
AccountingReactor_.stop();
|
||||
AccountingReactorThread_.join();
|
||||
|
||||
CoAReactor_.stop();
|
||||
CoAReactorThread_.join();
|
||||
enabled_=false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void RADIUS_proxy_server::OnAccountingSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf) {
|
||||
Poco::Net::SocketAddress Sender;
|
||||
unsigned char Buffer[RADIUS_BUFFER_SIZE];
|
||||
RADIUS::RadiusPacket P;
|
||||
|
||||
auto ReceiveSize = pNf.get()->socket().impl()->receiveBytes(Buffer,sizeof(Buffer));
|
||||
if(ReceiveSize<SMALLEST_RADIUS_PACKET)
|
||||
auto ReceiveSize = pNf->socket().impl()->receiveBytes(P.Buffer(),P.BufferLen());
|
||||
if(ReceiveSize<SMALLEST_RADIUS_PACKET) {
|
||||
Logger().warning("Accounting: bad packet received.");
|
||||
return;
|
||||
auto SerialNumber = ExtractSerialNumber(&Buffer[20],ReceiveSize);
|
||||
Logger().information(fmt::format("Accounting Packet received for {}",SerialNumber));
|
||||
std::cout << "Received an Accounting packet for :" << SerialNumber << std::endl;
|
||||
DeviceRegistry()->SendRadiusAccountingData(SerialNumber,Buffer,ReceiveSize);
|
||||
}
|
||||
P.Evaluate(ReceiveSize);
|
||||
auto SerialNumber = P.ExtractSerialNumberFromProxyState();
|
||||
if(SerialNumber.empty()) {
|
||||
Logger().warning("Accounting: missing serial number.");
|
||||
return;
|
||||
}
|
||||
auto CallingStationID = P.ExtractCallingStationID();
|
||||
auto CalledStationID = P.ExtractCalledStationID();
|
||||
|
||||
Logger().information(fmt::format("Accounting Packet received for {}, CalledStationID: {}, CallingStationID:{}",SerialNumber, CalledStationID, CallingStationID));
|
||||
DeviceRegistry()->SendRadiusAccountingData(SerialNumber,P.Buffer(),P.Size());
|
||||
}
|
||||
|
||||
void RADIUS_proxy_server::OnAuthenticationSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf) {
|
||||
Poco::Net::SocketAddress Sender;
|
||||
unsigned char Buffer[RADIUS_BUFFER_SIZE];
|
||||
RADIUS::RadiusPacket P;
|
||||
|
||||
auto ReceiveSize = pNf.get()->socket().impl()->receiveBytes(Buffer,sizeof(Buffer));
|
||||
if(ReceiveSize<SMALLEST_RADIUS_PACKET)
|
||||
auto ReceiveSize = pNf->socket().impl()->receiveBytes(P.Buffer(),P.BufferLen());
|
||||
if(ReceiveSize<SMALLEST_RADIUS_PACKET) {
|
||||
Logger().warning("Authentication: bad packet received.");
|
||||
return;
|
||||
auto SerialNumber = ExtractSerialNumber(&Buffer[20],ReceiveSize);
|
||||
Logger().information(fmt::format("Authentication Packet received for {}",SerialNumber));
|
||||
std::cout << "Received an Authentication packet for :" << SerialNumber << std::endl;
|
||||
DeviceRegistry()->SendRadiusAuthenticationData(SerialNumber,Buffer,ReceiveSize);
|
||||
}
|
||||
P.Evaluate(ReceiveSize);
|
||||
auto SerialNumber = P.ExtractSerialNumberFromProxyState();
|
||||
if(SerialNumber.empty()) {
|
||||
Logger().warning("Authentication: missing serial number.");
|
||||
return;
|
||||
}
|
||||
auto CallingStationID = P.ExtractCallingStationID();
|
||||
auto CalledStationID = P.ExtractCalledStationID();
|
||||
|
||||
Logger().information(fmt::format("Authentication Packet received for {}, CalledStationID: {}, CallingStationID:{}",SerialNumber, CalledStationID, CallingStationID));
|
||||
DeviceRegistry()->SendRadiusAuthenticationData(SerialNumber,P.Buffer(),P.Size());
|
||||
}
|
||||
|
||||
void RADIUS_proxy_server::SendAccountingData(const std::string &serialNumber, const std::string &Destination,const char *buffer, std::size_t size) {
|
||||
void RADIUS_proxy_server::OnCoASocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf) {
|
||||
Poco::Net::SocketAddress Sender;
|
||||
RADIUS::RadiusPacket P;
|
||||
|
||||
auto ReceiveSize = pNf.get()->socket().impl()->receiveBytes(P.Buffer(),P.BufferLen());
|
||||
if(ReceiveSize<SMALLEST_RADIUS_PACKET) {
|
||||
Logger().warning("CoA/DM: bad packet received.");
|
||||
return;
|
||||
}
|
||||
P.Evaluate(ReceiveSize);
|
||||
auto SerialNumber = P.ExtractSerialNumberTIP();
|
||||
if(SerialNumber.empty()) {
|
||||
Logger().warning("CoA/DM: missing serial number.");
|
||||
return;
|
||||
}
|
||||
auto CallingStationID = P.ExtractCallingStationID();
|
||||
auto CalledStationID = P.ExtractCalledStationID();
|
||||
|
||||
Logger().information(fmt::format("CoA Packet received for {}, CalledStationID: {}, CallingStationID:{}",SerialNumber, CalledStationID, CallingStationID));
|
||||
DeviceRegistry()->SendRadiusCoAData(SerialNumber,P.Buffer(),P.Size());
|
||||
}
|
||||
|
||||
void RADIUS_proxy_server::SendAccountingData(const std::string &serialNumber, const char *buffer, std::size_t size) {
|
||||
RADIUS::RadiusPacket P((unsigned char *)buffer,size);
|
||||
auto Destination = P.ExtractProxyStateDestination();
|
||||
auto CallingStationID = P.ExtractCallingStationID();
|
||||
auto CalledStationID = P.ExtractCalledStationID();
|
||||
Poco::Net::SocketAddress Dst(Destination);
|
||||
|
||||
std::lock_guard G(Mutex_);
|
||||
if(Dst.af()==Poco::Net::AddressFamily::IPv4)
|
||||
AccountingSocketV4_->sendTo(buffer,(int)size,Route(Dst,AcctPoolsV4_,AcctPoolsIndexV4_));
|
||||
auto FinalDestination = Route(radius_type::auth, Dst);
|
||||
auto AllSent = SendData(Dst.family()==Poco::Net::SocketAddress::IPv4 ? *AccountingSocketV4_ : *AccountingSocketV6_, (const unsigned char *)buffer, size, FinalDestination);
|
||||
if(!AllSent)
|
||||
Logger().error(fmt::format("{}: Could not send Accounting packet packet to {}.", serialNumber, Destination));
|
||||
else
|
||||
AccountingSocketV6_->sendTo(buffer,(int)size,Route(Dst,AcctPoolsV6_,AcctPoolsIndexV6_));
|
||||
Logger().information(fmt::format("{}: Sending Accounting Packet to {}", serialNumber, Destination));
|
||||
std::cout << "Sending Accounting data to " << Destination << std::endl;
|
||||
Logger().information(fmt::format("{}: Sending Accounting Packet to {}, CalledStationID: {}, CallingStationID:{}", serialNumber, FinalDestination.toString(), CalledStationID, CallingStationID));
|
||||
}
|
||||
|
||||
void RADIUS_proxy_server::SendAuthenticationData(const std::string &serialNumber, const std::string &Destination,const char *buffer, std::size_t size) {
|
||||
bool RADIUS_proxy_server::SendData( Poco::Net::DatagramSocket & Sock, const unsigned char *buf , std::size_t size, const Poco::Net::SocketAddress &S) {
|
||||
return Sock.sendTo(buf, size, S)==(int)size;
|
||||
}
|
||||
|
||||
void RADIUS_proxy_server::SendAuthenticationData(const std::string &serialNumber, const char *buffer, std::size_t size) {
|
||||
RADIUS::RadiusPacket P((unsigned char *)buffer,size);
|
||||
auto Destination = P.ExtractProxyStateDestination();
|
||||
auto CallingStationID = P.ExtractCallingStationID();
|
||||
auto CalledStationID = P.ExtractCalledStationID();
|
||||
Poco::Net::SocketAddress Dst(Destination);
|
||||
|
||||
std::lock_guard G(Mutex_);
|
||||
if(Dst.af()==Poco::Net::AddressFamily::IPv4)
|
||||
AuthenticationSocketV4_->sendTo(buffer,(int)size,Route(Dst,AuthPoolsV4_,AuthPoolsIndexV4_));
|
||||
auto FinalDestination = Route(radius_type::auth, Dst);
|
||||
auto AllSent = SendData(Dst.family()==Poco::Net::SocketAddress::IPv4 ? *AuthenticationSocketV4_ : *AuthenticationSocketV6_, (const unsigned char *)buffer, size, FinalDestination);
|
||||
if(!AllSent)
|
||||
Logger().error(fmt::format("{}: Could not send Authentication packet packet to {}.", serialNumber, Destination));
|
||||
else
|
||||
AuthenticationSocketV6_->sendTo(buffer,(int)size,Route(Dst,AuthPoolsV6_,AuthPoolsIndexV6_));
|
||||
Logger().information(fmt::format("{}: Sending Authentication Packet to {}", serialNumber, Destination));
|
||||
std::cout << "Sending Authentication data to " << Destination << std::endl;
|
||||
Logger().information(fmt::format("{}: Sending Authentication Packet to {}, CalledStationID: {}, CallingStationID:{}", serialNumber, FinalDestination.toString(), CalledStationID, CallingStationID));
|
||||
}
|
||||
|
||||
void RADIUS_proxy_server::ParseServerList(const GWObjects::RadiusProxyServerConfig & Config, PoolIndexMap_t &MapV4, PoolIndexMap_t &MapV6, PoolIndexVec_t &VecV4, PoolIndexVec_t &VecV6) {
|
||||
void RADIUS_proxy_server::SendCoAData(const std::string &serialNumber, const char *buffer, std::size_t size) {
|
||||
RADIUS::RadiusPacket P((unsigned char *)buffer,size);
|
||||
auto Destination = P.ExtractProxyStateDestination();
|
||||
// auto CallingStationID = P.ExtractCallingStationID();
|
||||
// auto CalledStationID = P.ExtractCalledStationID();
|
||||
|
||||
std::vector<Destination> DestsV4,DestsV6;
|
||||
if(Destination.empty()) {
|
||||
Destination = "0.0.0.0:0";
|
||||
}
|
||||
|
||||
Poco::Net::SocketAddress Dst(Destination);
|
||||
std::lock_guard G(Mutex_);
|
||||
auto FinalDestination = Route(radius_type::auth, Dst);
|
||||
auto AllSent = SendData(Dst.family()==Poco::Net::SocketAddress::IPv4 ? *CoASocketV4_ : *CoASocketV6_, (const unsigned char *)buffer, size, FinalDestination);
|
||||
if(!AllSent)
|
||||
Logger().error(fmt::format("{}: Could not send CoA packet packet to {}.", serialNumber, Destination));
|
||||
else
|
||||
Logger().information(fmt::format("{}: Sending CoA Packet to {}", serialNumber, FinalDestination.toString()));
|
||||
}
|
||||
|
||||
void RADIUS_proxy_server::ParseServerList(const GWObjects::RadiusProxyServerConfig & Config, std::vector<Destination> &V4, std::vector<Destination> &V6, bool setAsDefault) {
|
||||
uint64_t TotalV4=0, TotalV6=0;
|
||||
|
||||
for(const auto &server:Config.servers) {
|
||||
auto S = Poco::Net::SocketAddress(fmt::format("{}:{}",server.name,server.port));
|
||||
Poco::Net::IPAddress a;
|
||||
if(!Poco::Net::IPAddress::tryParse(server.ip,a)) {
|
||||
Logger().error(fmt::format("RADIUS-PARSE Config: server address {} is nto a valid address in v4 or v6. Entry skipped.",server.ip));
|
||||
continue;
|
||||
}
|
||||
auto S = Poco::Net::SocketAddress(fmt::format("{}:{}",server.ip,server.port));
|
||||
Destination D{
|
||||
.Addr = S,
|
||||
.state = 0,
|
||||
@@ -184,32 +255,34 @@ namespace OpenWifi {
|
||||
.strategy = Config.strategy,
|
||||
.monitor = Config. monitor,
|
||||
.monitorMethod = Config.monitorMethod,
|
||||
.methodParameters = Config.methodParameters
|
||||
.methodParameters = Config.methodParameters,
|
||||
.useAsDefault = setAsDefault
|
||||
};
|
||||
|
||||
if(S.af()==Poco::Net::AddressFamily::IPv4) {
|
||||
if(S.family()==Poco::Net::IPAddress::IPv4) {
|
||||
TotalV4 += server.weight;
|
||||
DestsV4.push_back(D);
|
||||
MapV4[S] = VecV4.size();
|
||||
V4.push_back(D);
|
||||
} else {
|
||||
TotalV6 += server.weight;
|
||||
DestsV6.push_back(D);
|
||||
MapV6[S] = VecV6.size();
|
||||
V6.push_back(D);
|
||||
}
|
||||
}
|
||||
|
||||
for(auto &i:DestsV4) {
|
||||
i.step = 1000 - ((1000*i.weight)/TotalV4);
|
||||
for(auto &i:V4) {
|
||||
if(TotalV4==0) {
|
||||
i.step = 1000;
|
||||
} else {
|
||||
i.step = 1000 - ((1000 * i.weight) / TotalV4);
|
||||
}
|
||||
}
|
||||
|
||||
for(auto &i:DestsV6) {
|
||||
i.step = 1000 - ((1000*i.weight)/TotalV6);
|
||||
for(auto &i:V6) {
|
||||
if(TotalV6==0) {
|
||||
i.step = 1000;
|
||||
} else {
|
||||
i.step = 1000 - ((1000 * i.weight) / TotalV6);
|
||||
}
|
||||
}
|
||||
|
||||
if(!DestsV4.empty())
|
||||
VecV4.push_back(DestsV4);
|
||||
if(!DestsV6.empty())
|
||||
VecV6.push_back((DestsV6));
|
||||
}
|
||||
|
||||
void RADIUS_proxy_server::ParseConfig() {
|
||||
@@ -228,8 +301,11 @@ namespace OpenWifi {
|
||||
ResetConfig();
|
||||
PoolList_ = RPC;
|
||||
for(const auto &pool:RPC.pools) {
|
||||
ParseServerList(pool.authConfig,AuthPoolsIndexV4_, AuthPoolsIndexV6_, AuthPoolsV4_, AuthPoolsV6_);
|
||||
ParseServerList(pool.acctConfig,AcctPoolsIndexV4_, AcctPoolsIndexV6_, AcctPoolsV4_, AcctPoolsV6_);
|
||||
RadiusPool NewPool;
|
||||
ParseServerList(pool.authConfig, NewPool.AuthV4, NewPool.AuthV6, pool.useByDefault);
|
||||
ParseServerList(pool.acctConfig, NewPool.AcctV4, NewPool.AcctV6, pool.useByDefault);
|
||||
ParseServerList(pool.coaConfig, NewPool.CoaV4, NewPool.CoaV6, pool.useByDefault);
|
||||
Pools_.push_back(NewPool);
|
||||
}
|
||||
} else {
|
||||
Logger().warning(fmt::format("Configuration file '{}' is bad.",ConfigFilename_));
|
||||
@@ -244,20 +320,79 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
Poco::Net::SocketAddress RADIUS_proxy_server::Route(const Poco::Net::SocketAddress &A, PoolIndexVec_t & P, PoolIndexMap_t &M) {
|
||||
Poco::Net::SocketAddress RADIUS_proxy_server::DefaultRoute([[maybe_unused]] radius_type rtype, const Poco::Net::SocketAddress &RequestedAddress) {
|
||||
bool IsV4 = RequestedAddress.family()==Poco::Net::SocketAddress::IPv4;
|
||||
switch(rtype) {
|
||||
case radius_type::coa: {
|
||||
return ChooseAddress(IsV4 ? Pools_[defaultPoolIndex_].CoaV4
|
||||
: Pools_[defaultPoolIndex_].CoaV6,
|
||||
RequestedAddress);
|
||||
}
|
||||
case radius_type::auth: {
|
||||
return ChooseAddress(IsV4 ? Pools_[defaultPoolIndex_].AuthV4
|
||||
: Pools_[defaultPoolIndex_].AuthV6,
|
||||
RequestedAddress);
|
||||
}
|
||||
case radius_type::acct:
|
||||
default: {
|
||||
return ChooseAddress(IsV4 ? Pools_[defaultPoolIndex_].AcctV4
|
||||
: Pools_[defaultPoolIndex_].AcctV6,
|
||||
RequestedAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Poco::Net::SocketAddress RADIUS_proxy_server::Route([[maybe_unused]] radius_type rtype, const Poco::Net::SocketAddress &RequestedAddress) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
if(PoolList_.pools.empty())
|
||||
return A;
|
||||
if(Pools_.empty()) {
|
||||
return RequestedAddress;
|
||||
}
|
||||
|
||||
auto It = M.find(A);
|
||||
if(It==M.end())
|
||||
return A;
|
||||
auto Index = It->second;
|
||||
auto Pool = P[Index];
|
||||
bool IsV4 = RequestedAddress.family()==Poco::Net::SocketAddress::IPv4;
|
||||
bool useDefault = false;
|
||||
useDefault = IsV4 ? RequestedAddress.host() == Poco::Net::IPAddress::wildcard(Poco::Net::IPAddress::IPv4) : RequestedAddress.host() == Poco::Net::IPAddress::wildcard(Poco::Net::IPAddress::IPv6) ;
|
||||
|
||||
// is there anything of the same af ?
|
||||
if(Pool[0].strategy=="weighted") {
|
||||
if(useDefault) {
|
||||
return DefaultRoute(rtype, RequestedAddress);
|
||||
}
|
||||
|
||||
auto isAddressInPool = [&](const std::vector<Destination> & D) -> bool {
|
||||
for(const auto &entry:D)
|
||||
if(entry.Addr.host()==RequestedAddress.host())
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
for(auto &i:Pools_) {
|
||||
switch(rtype) {
|
||||
case radius_type::coa: {
|
||||
if (isAddressInPool((IsV4 ? i.CoaV4 : i.CoaV6))) {
|
||||
return ChooseAddress(IsV4 ? i.CoaV4 : i.CoaV6, RequestedAddress);
|
||||
}
|
||||
} break;
|
||||
case radius_type::auth: {
|
||||
if (isAddressInPool((IsV4 ? i.AuthV4 : i.AuthV6))) {
|
||||
return ChooseAddress(IsV4 ? i.AuthV4 : i.AuthV6, RequestedAddress);
|
||||
}
|
||||
} break;
|
||||
case radius_type::acct: {
|
||||
if (isAddressInPool((IsV4 ? i.AcctV4 : i.AcctV6))) {
|
||||
return ChooseAddress(IsV4 ? i.AcctV4 : i.AcctV6, RequestedAddress);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
return DefaultRoute(rtype, RequestedAddress);
|
||||
}
|
||||
|
||||
Poco::Net::SocketAddress RADIUS_proxy_server::ChooseAddress(std::vector<Destination> &Pool, const Poco::Net::SocketAddress & OriginalAddress) {
|
||||
|
||||
if(Pool.size()==1) {
|
||||
return Pool[0].Addr;
|
||||
}
|
||||
|
||||
if (Pool[0].strategy == "weighted") {
|
||||
bool found = false;
|
||||
uint64_t cur_state = std::numeric_limits<uint64_t>::max();
|
||||
std::size_t pos = 0, index = 0;
|
||||
@@ -274,12 +409,13 @@ namespace OpenWifi {
|
||||
pos++;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return A;
|
||||
if (!found) {
|
||||
return OriginalAddress;
|
||||
}
|
||||
|
||||
Pool[index].state += Pool[index].step;
|
||||
return Pool[index].Addr;
|
||||
} else if (Pool[0].strategy=="round_robin") {
|
||||
} else if (Pool[0].strategy == "round_robin") {
|
||||
bool found = false;
|
||||
uint64_t cur_state = std::numeric_limits<uint64_t>::max();
|
||||
std::size_t pos = 0, index = 0;
|
||||
@@ -296,19 +432,20 @@ namespace OpenWifi {
|
||||
pos++;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return A;
|
||||
if (!found) {
|
||||
return OriginalAddress;
|
||||
}
|
||||
|
||||
Pool[index].state += 1;
|
||||
return Pool[index].Addr;
|
||||
} else if (Pool[0].strategy=="random") {
|
||||
if(Pool.size()>1) {
|
||||
return Pool[ std::rand() % Pool.size() ].Addr;
|
||||
} else if (Pool[0].strategy == "random") {
|
||||
if (Pool.size() > 1) {
|
||||
return Pool[std::rand() % Pool.size()].Addr;
|
||||
} else {
|
||||
return A;
|
||||
return OriginalAddress;
|
||||
}
|
||||
}
|
||||
return A;
|
||||
return OriginalAddress;
|
||||
}
|
||||
|
||||
void RADIUS_proxy_server::SetConfig(const GWObjects::RadiusProxyPoolList &C) {
|
||||
@@ -327,14 +464,8 @@ namespace OpenWifi {
|
||||
|
||||
void RADIUS_proxy_server::ResetConfig() {
|
||||
PoolList_.pools.clear();
|
||||
AuthPoolsIndexV4_.clear();
|
||||
AuthPoolsIndexV6_.clear();
|
||||
AcctPoolsIndexV4_.clear();
|
||||
AcctPoolsIndexV6_.clear();
|
||||
AuthPoolsV4_.clear();
|
||||
AuthPoolsV6_.clear();
|
||||
AcctPoolsV4_.clear();
|
||||
AcctPoolsV6_.clear();
|
||||
Pools_.clear();
|
||||
defaultPoolIndex_=0;
|
||||
}
|
||||
|
||||
void RADIUS_proxy_server::DeleteConfig() {
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
#include "RESTObjects/RESTAPI_GWobjects.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
enum class radius_type {
|
||||
auth, acct, coa
|
||||
};
|
||||
|
||||
class RADIUS_proxy_server : public SubSystemServer {
|
||||
public:
|
||||
inline static auto instance() {
|
||||
@@ -19,11 +24,15 @@ namespace OpenWifi {
|
||||
|
||||
int Start() final;
|
||||
void Stop() final;
|
||||
inline bool Enabled() const { return enabled_; }
|
||||
|
||||
void OnAccountingSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
|
||||
void OnAuthenticationSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
|
||||
void SendAccountingData(const std::string &serialNumber, const std::string &Destination,const char *buffer, std::size_t size);
|
||||
void SendAuthenticationData(const std::string &serialNumber, const std::string &Destination,const char *buffer, std::size_t size);
|
||||
void OnCoASocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
|
||||
|
||||
void SendAccountingData(const std::string &serialNumber, const char *buffer, std::size_t size);
|
||||
void SendAuthenticationData(const std::string &serialNumber, const char *buffer, std::size_t size);
|
||||
void SendCoAData(const std::string &serialNumber, const char *buffer, std::size_t size);
|
||||
|
||||
void SetConfig(const GWObjects::RadiusProxyPoolList &C);
|
||||
void DeleteConfig();
|
||||
@@ -39,6 +48,7 @@ namespace OpenWifi {
|
||||
bool monitor=false;
|
||||
std::string monitorMethod;
|
||||
std::vector<std::string> methodParameters;
|
||||
bool useAsDefault=false;
|
||||
};
|
||||
|
||||
private:
|
||||
@@ -46,34 +56,44 @@ namespace OpenWifi {
|
||||
std::unique_ptr<Poco::Net::DatagramSocket> AccountingSocketV6_;
|
||||
std::unique_ptr<Poco::Net::DatagramSocket> AuthenticationSocketV4_;
|
||||
std::unique_ptr<Poco::Net::DatagramSocket> AuthenticationSocketV6_;
|
||||
std::unique_ptr<Poco::Net::DatagramSocket> CoASocketV4_;
|
||||
std::unique_ptr<Poco::Net::DatagramSocket> CoASocketV6_;
|
||||
Poco::Net::SocketReactor AccountingReactor_;
|
||||
Poco::Net::SocketReactor AuthenticationReactor_;
|
||||
Poco::Net::SocketReactor CoAReactor_;
|
||||
Poco::Thread AuthenticationReactorThread_;
|
||||
Poco::Thread AccountingReactorThread_;
|
||||
Poco::Thread CoAReactorThread_;
|
||||
|
||||
GWObjects::RadiusProxyPoolList PoolList_;
|
||||
std::string ConfigFilename_;
|
||||
|
||||
typedef std::map<Poco::Net::SocketAddress,uint> PoolIndexMap_t;
|
||||
PoolIndexMap_t AuthPoolsIndexV4_;
|
||||
PoolIndexMap_t AcctPoolsIndexV4_;
|
||||
PoolIndexMap_t AuthPoolsIndexV6_;
|
||||
PoolIndexMap_t AcctPoolsIndexV6_;
|
||||
struct RadiusPool {
|
||||
std::vector<Destination> AuthV4;
|
||||
std::vector<Destination> AuthV6;
|
||||
std::vector<Destination> AcctV4;
|
||||
std::vector<Destination> AcctV6;
|
||||
std::vector<Destination> CoaV4;
|
||||
std::vector<Destination> CoaV6;
|
||||
};
|
||||
|
||||
typedef std::vector<std::vector<Destination>> PoolIndexVec_t;
|
||||
PoolIndexVec_t AuthPoolsV4_;
|
||||
PoolIndexVec_t AuthPoolsV6_;
|
||||
PoolIndexVec_t AcctPoolsV4_;
|
||||
PoolIndexVec_t AcctPoolsV6_;
|
||||
std::vector<RadiusPool> Pools_;
|
||||
uint defaultPoolIndex_=0;
|
||||
bool enabled_=false;
|
||||
|
||||
RADIUS_proxy_server() noexcept:
|
||||
SubSystemServer("RADIUS-PROXY", "RADIUS-PROXY", "radius.proxy")
|
||||
{
|
||||
}
|
||||
|
||||
static bool SendData( Poco::Net::DatagramSocket & Sock, const unsigned char *buf , std::size_t size, const Poco::Net::SocketAddress &S);
|
||||
|
||||
void ParseConfig();
|
||||
void ResetConfig();
|
||||
Poco::Net::SocketAddress Route(const Poco::Net::SocketAddress &A, PoolIndexVec_t & P, PoolIndexMap_t &M);
|
||||
void ParseServerList(const GWObjects::RadiusProxyServerConfig & Config, PoolIndexMap_t &MapV4, PoolIndexMap_t &MapV6, PoolIndexVec_t &VecV4, PoolIndexVec_t &VecV6);
|
||||
Poco::Net::SocketAddress Route(radius_type rtype, const Poco::Net::SocketAddress &A);
|
||||
void ParseServerList(const GWObjects::RadiusProxyServerConfig & Config, std::vector<Destination> &V4, std::vector<Destination> &V6, bool setAsDefault);
|
||||
static Poco::Net::SocketAddress ChooseAddress(std::vector<Destination> &Pool, const Poco::Net::SocketAddress & OriginalAddress);
|
||||
Poco::Net::SocketAddress DefaultRoute([[maybe_unused]] radius_type rtype, const Poco::Net::SocketAddress &RequestedAddress);
|
||||
};
|
||||
|
||||
inline auto RADIUS_proxy_server() { return RADIUS_proxy_server::instance(); }
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "DeviceRegistry.h"
|
||||
#include "StorageService.h"
|
||||
#include "framework/ow_constants.h"
|
||||
#include "ParseWifiScan.h"
|
||||
|
||||
namespace OpenWifi::RESTAPI_RPC {
|
||||
void SetCommandStatus(GWObjects::CommandDetails &Cmd,
|
||||
@@ -22,9 +23,12 @@ namespace OpenWifi::RESTAPI_RPC {
|
||||
if (StorageService()->AddCommand(Cmd.SerialNumber, Cmd, Status)) {
|
||||
Poco::JSON::Object RetObj;
|
||||
Cmd.to_json(RetObj);
|
||||
return Handler->ReturnObject(RetObj);
|
||||
if(Handler!= nullptr)
|
||||
return Handler->ReturnObject(RetObj);
|
||||
return;
|
||||
}
|
||||
return Handler->ReturnStatus(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
|
||||
if(Handler!= nullptr)
|
||||
return Handler->ReturnStatus(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
void WaitForCommand(GWObjects::CommandDetails &Cmd,
|
||||
@@ -36,10 +40,13 @@ namespace OpenWifi::RESTAPI_RPC {
|
||||
RESTAPIHandler * Handler,
|
||||
Poco::Logger &Logger) {
|
||||
|
||||
Logger.information(fmt::format("{}: New {} command. User={} Serial={}. ", Cmd.UUID, Cmd.Command, Cmd.SubmittedBy, Cmd.SerialNumber));
|
||||
|
||||
// if the command should be executed in the future, or if the device is not connected,
|
||||
// then we should just add the command to
|
||||
// the DB and let it figure out when to deliver the command.
|
||||
if (Cmd.RunAt || !DeviceRegistry()->Connected(Cmd.SerialNumber)) {
|
||||
Logger.information(fmt::format("{}: Command will be run in the future or when device is connected again.", Cmd.UUID));
|
||||
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_PENDING, Logger);
|
||||
return;
|
||||
}
|
||||
@@ -51,93 +58,88 @@ namespace OpenWifi::RESTAPI_RPC {
|
||||
std::shared_ptr<CommandManager::promise_type_t> rpc_endpoint =
|
||||
CommandManager()->PostCommand(Cmd.SerialNumber, Cmd.Command, Params, Cmd.UUID, Sent);
|
||||
|
||||
Logger.information(fmt::format("{}: user={} serial={}. Sent RPC request.", Cmd.Command, Cmd.SubmittedBy, Cmd.SerialNumber));
|
||||
if(!Sent || rpc_endpoint== nullptr) {
|
||||
Logger.information(fmt::format("{}: Pending completion. Device is not connected.", Cmd.UUID));
|
||||
return SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_PENDING, Logger);
|
||||
}
|
||||
|
||||
Logger.information(fmt::format("{}: Command sent.", Cmd.UUID));
|
||||
|
||||
Poco::JSON::Object L;
|
||||
|
||||
if (Sent && rpc_endpoint!= nullptr) {
|
||||
std::future<CommandManager::objtype_t> rpc_future(rpc_endpoint->get_future());
|
||||
auto rpc_result = rpc_future.wait_for(WaitTimeInMs);
|
||||
if (rpc_result == std::future_status::ready) {
|
||||
std::chrono::duration<double, std::milli> rpc_execution_time = std::chrono::high_resolution_clock::now() - rpc_submitted;
|
||||
auto rpc_answer = rpc_future.get();
|
||||
if (rpc_answer.has(uCentralProtocol::RESULT) && rpc_answer.isObject(uCentralProtocol::RESULT)) {
|
||||
auto ResultFields =
|
||||
rpc_answer.get(uCentralProtocol::RESULT).extract<Poco::JSON::Object::Ptr>();
|
||||
if (ResultFields->has(uCentralProtocol::STATUS) && ResultFields->isObject(uCentralProtocol::STATUS)) {
|
||||
auto StatusInnerObj =
|
||||
ResultFields->get(uCentralProtocol::STATUS).extract<Poco::JSON::Object::Ptr>();
|
||||
if (StatusInnerObj->has(uCentralProtocol::ERROR))
|
||||
Cmd.ErrorCode = StatusInnerObj->get(uCentralProtocol::ERROR);
|
||||
if (StatusInnerObj->has(uCentralProtocol::TEXT))
|
||||
Cmd.ErrorText = StatusInnerObj->get(uCentralProtocol::TEXT).toString();
|
||||
std::stringstream ResultText;
|
||||
if(rpc_answer.has(uCentralProtocol::RESULT)) {
|
||||
Poco::JSON::Stringifier::stringify(
|
||||
rpc_answer.get(uCentralProtocol::RESULT), ResultText);
|
||||
} if (rpc_answer.has(uCentralProtocol::RESULT_64)) {
|
||||
uint64_t sz=0;
|
||||
if(rpc_answer.has(uCentralProtocol::RESULT_SZ))
|
||||
sz=rpc_answer.get(uCentralProtocol::RESULT_SZ);
|
||||
std::string UnCompressedData;
|
||||
Utils::ExtractBase64CompressedData(rpc_answer.get(uCentralProtocol::RESULT_64).toString(),
|
||||
UnCompressedData,sz);
|
||||
Poco::JSON::Stringifier::stringify(UnCompressedData, ResultText);
|
||||
}
|
||||
Cmd.Results = ResultText.str();
|
||||
Cmd.Status = "completed";
|
||||
Cmd.Completed = OpenWifi::Now();
|
||||
Cmd.executionTime = rpc_execution_time.count();
|
||||
|
||||
if (Cmd.ErrorCode && Cmd.Command == uCentralProtocol::TRACE) {
|
||||
Cmd.WaitingForFile = 0;
|
||||
Cmd.AttachDate = Cmd.AttachSize = 0;
|
||||
Cmd.AttachType = "";
|
||||
}
|
||||
|
||||
// Add the completed command to the database...
|
||||
StorageService()->AddCommand(Cmd.SerialNumber, Cmd, Storage::COMMAND_COMPLETED);
|
||||
|
||||
if (ObjectToReturn) {
|
||||
Handler->ReturnObject(*ObjectToReturn);
|
||||
} else {
|
||||
Poco::JSON::Object O;
|
||||
Cmd.to_json(O);
|
||||
Handler->ReturnObject(O);
|
||||
}
|
||||
Logger.information( fmt::format("Command({}): completed in {:.3f}ms.", Cmd.UUID, Cmd.executionTime));
|
||||
return;
|
||||
} else {
|
||||
SetCommandStatus(Cmd, Request, Response, Handler,
|
||||
Storage::COMMAND_FAILED, Logger);
|
||||
Logger.information(fmt::format(
|
||||
"Invalid response for command '{}'. Missing status.", Cmd.UUID));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_FAILED,
|
||||
Logger);
|
||||
Logger.information(fmt::format(
|
||||
"Invalid response for command '{}'. Missing status.", Cmd.UUID));
|
||||
return;
|
||||
}
|
||||
} else if (rpc_result == std::future_status::timeout) {
|
||||
Logger.information(fmt::format(
|
||||
"Timeout2 for command '{}'.", Cmd.UUID));
|
||||
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_TIMEDOUT,
|
||||
Logger);
|
||||
return;
|
||||
} else {
|
||||
Logger.information(fmt::format(
|
||||
"Pending completion for command '{}'.", Cmd.UUID));
|
||||
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_PENDING, Logger);
|
||||
std::future<CommandManager::objtype_t> rpc_future(rpc_endpoint->get_future());
|
||||
auto rpc_result = rpc_future.wait_for(WaitTimeInMs);
|
||||
if (rpc_result == std::future_status::ready) {
|
||||
std::chrono::duration<double, std::milli> rpc_execution_time = std::chrono::high_resolution_clock::now() - rpc_submitted;
|
||||
auto rpc_answer = rpc_future.get();
|
||||
if (!rpc_answer.has(uCentralProtocol::RESULT) || !rpc_answer.isObject(uCentralProtocol::RESULT)) {
|
||||
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_FAILED, Logger);
|
||||
Logger.information(fmt::format("{}: Invalid response. Missing result.", Cmd.UUID));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Logger.information(fmt::format(
|
||||
"Pending completion for command '{}'.", Cmd.UUID));
|
||||
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_PENDING, Logger);
|
||||
|
||||
auto ResultFields = rpc_answer.get(uCentralProtocol::RESULT).extract<Poco::JSON::Object::Ptr>();
|
||||
if (!ResultFields->has(uCentralProtocol::STATUS) || !ResultFields->isObject(uCentralProtocol::STATUS)) {
|
||||
Cmd.executionTime = rpc_execution_time.count();
|
||||
if(Cmd.Command=="ping") {
|
||||
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_COMPLETED, Logger);
|
||||
Logger.information(fmt::format("{}: Invalid response from device (ping: fix override). Missing status.", Cmd.UUID));
|
||||
} else {
|
||||
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_FAILED, Logger);
|
||||
Logger.information(fmt::format("{}: Invalid response from device. Missing status.", Cmd.UUID));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
auto StatusInnerObj = ResultFields->get(uCentralProtocol::STATUS).extract<Poco::JSON::Object::Ptr>();
|
||||
if (StatusInnerObj->has(uCentralProtocol::ERROR))
|
||||
Cmd.ErrorCode = StatusInnerObj->get(uCentralProtocol::ERROR);
|
||||
if (StatusInnerObj->has(uCentralProtocol::TEXT))
|
||||
Cmd.ErrorText = StatusInnerObj->get(uCentralProtocol::TEXT).toString();
|
||||
std::stringstream ResultText;
|
||||
if(rpc_answer.has(uCentralProtocol::RESULT)) {
|
||||
if(Cmd.Command==uCentralProtocol::WIFISCAN) {
|
||||
auto ScanObj = rpc_answer.get(uCentralProtocol::RESULT).extract<Poco::JSON::Object::Ptr>();
|
||||
ParseWifiScan(ScanObj, ResultText, Logger);
|
||||
} else {
|
||||
Poco::JSON::Stringifier::stringify(
|
||||
rpc_answer.get(uCentralProtocol::RESULT), ResultText);
|
||||
}
|
||||
} if (rpc_answer.has(uCentralProtocol::RESULT_64)) {
|
||||
uint64_t sz=0;
|
||||
if(rpc_answer.has(uCentralProtocol::RESULT_SZ))
|
||||
sz=rpc_answer.get(uCentralProtocol::RESULT_SZ);
|
||||
std::string UnCompressedData;
|
||||
Utils::ExtractBase64CompressedData(rpc_answer.get(uCentralProtocol::RESULT_64).toString(),
|
||||
UnCompressedData,sz);
|
||||
Poco::JSON::Stringifier::stringify(UnCompressedData, ResultText);
|
||||
}
|
||||
Cmd.Results = ResultText.str();
|
||||
Cmd.Status = "completed";
|
||||
Cmd.Completed = OpenWifi::Now();
|
||||
Cmd.executionTime = rpc_execution_time.count();
|
||||
|
||||
if (Cmd.ErrorCode && Cmd.Command == uCentralProtocol::TRACE) {
|
||||
Cmd.WaitingForFile = 0;
|
||||
Cmd.AttachDate = Cmd.AttachSize = 0;
|
||||
Cmd.AttachType = "";
|
||||
}
|
||||
|
||||
// Add the completed command to the database...
|
||||
StorageService()->AddCommand(Cmd.SerialNumber, Cmd, Storage::COMMAND_COMPLETED);
|
||||
|
||||
if (ObjectToReturn && Handler) {
|
||||
Handler->ReturnObject(*ObjectToReturn);
|
||||
} else {
|
||||
Poco::JSON::Object O;
|
||||
Cmd.to_json(O);
|
||||
if(Handler)
|
||||
Handler->ReturnObject(O);
|
||||
}
|
||||
Logger.information( fmt::format("{}: Completed in {:.3f}ms.", Cmd.UUID, Cmd.executionTime));
|
||||
return;
|
||||
}
|
||||
Logger.information(fmt::format( "{}: Pending completion.", Cmd.UUID));
|
||||
SetCommandStatus(Cmd, Request, Response, Handler, Storage::COMMAND_PENDING, Logger);
|
||||
}
|
||||
}
|
||||
@@ -207,12 +207,13 @@ namespace OpenWifi {
|
||||
Params.stringify(ParamStream);
|
||||
Cmd.Details = ParamStream.str();
|
||||
|
||||
RESTAPI_RPC::WaitForCommand(Cmd, Params, *Request, *Response, 60000ms, nullptr, this, Logger_);
|
||||
RESTAPI_RPC::WaitForCommand(Cmd, Params, *Request, *Response, 60000ms, nullptr, nullptr, Logger_);
|
||||
|
||||
GWObjects::CommandDetails Cmd2;
|
||||
if(StorageService()->GetCommand(Cmd.UUID,Cmd2)) {
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("latency", Cmd2.executionTime);
|
||||
// Answer.set("latency", Cmd2.executionTime);
|
||||
Answer.set("latency", fmt::format("{:.3f}ms.",Cmd.executionTime));
|
||||
Answer.set("serialNumber", SerialNumber_);
|
||||
Answer.set("currentUTCTime", std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch()).count());
|
||||
@@ -251,7 +252,7 @@ namespace OpenWifi {
|
||||
SCR.script.empty() ||
|
||||
SCR.type.empty() ||
|
||||
SCR.scriptId.empty() ||
|
||||
(SCR.type!="uci" && SCR.type!="shell" && SCR.type!="ucode")) {
|
||||
(SCR.type!="shell" && SCR.type!="ucode")) {
|
||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
|
||||
@@ -699,6 +700,11 @@ namespace OpenWifi {
|
||||
bool ActiveScan = GetB(RESTAPI::Protocol::ACTIVESCAN, Obj, false);
|
||||
uint64_t Bandwidth = Get(RESTAPI::Protocol::BANDWIDTH, Obj, (uint64_t) 0);
|
||||
|
||||
Poco::JSON::Array::Ptr ies;
|
||||
if(Obj->has("ies") && Obj->isArray("ies")) {
|
||||
ies = Obj->getArray("ies");
|
||||
}
|
||||
|
||||
auto UUID = MicroService::CreateUUID();
|
||||
GWObjects::CommandDetails Cmd;
|
||||
|
||||
@@ -712,6 +718,8 @@ namespace OpenWifi {
|
||||
Params.set(uCentralProtocol::SERIAL, SerialNumber_);
|
||||
Params.set(uCentralProtocol::OVERRIDEDFS, OverrideDFS);
|
||||
Params.set(uCentralProtocol::ACTIVE, ActiveScan);
|
||||
if(ies)
|
||||
Params.set(uCentralProtocol::IES, ies);
|
||||
if(Bandwidth!=0)
|
||||
Params.set(uCentralProtocol::BANDWIDTH, Bandwidth);
|
||||
|
||||
@@ -810,7 +818,6 @@ namespace OpenWifi {
|
||||
return BadRequest(RESTAPI::Errors::DeviceNotConnected);
|
||||
}
|
||||
|
||||
Logger_.information(fmt::format("RTTY: user={} serial={}. Getting configuration.", UserInfo_.userinfo.email,SerialNumber_));
|
||||
if (MicroService::instance().ConfigGetBool("rtty.enabled", false)) {
|
||||
GWObjects::Device Device;
|
||||
|
||||
@@ -831,11 +838,8 @@ namespace OpenWifi {
|
||||
};
|
||||
|
||||
if(RTTYS_server()->UseInternal()) {
|
||||
Logger_.information(fmt::format("RTTY: user={} serial={}. Creating hash.", UserInfo_.userinfo.email,SerialNumber_));
|
||||
Rtty.Token = MicroService::instance().CreateHash(UserInfo_.webtoken.refresh_token_ + std::to_string(OpenWifi::Now())).substr(0,32);
|
||||
Logger_.information(fmt::format("RTTY: user={} serial={}. Creating endpoint.", UserInfo_.userinfo.email,SerialNumber_));
|
||||
RTTYS_server()->CreateEndPoint(Rtty.ConnectionId,Rtty.Token, UserInfo_.userinfo.email, SerialNumber_);
|
||||
Logger_.information(fmt::format("RTTY: user={} serial={}. Created endpoint.", UserInfo_.userinfo.email,SerialNumber_));
|
||||
RTTYS_server()->CreateEndPoint(Rtty.ConnectionId, Rtty.Token, UserInfo_.userinfo.email, SerialNumber_);
|
||||
}
|
||||
|
||||
Poco::JSON::Object ReturnedObject;
|
||||
@@ -864,11 +868,9 @@ namespace OpenWifi {
|
||||
Params.stringify(ParamStream);
|
||||
Cmd.Details = ParamStream.str();
|
||||
|
||||
Logger_.information(fmt::format("RTTY: user={} serial={}. Sending RPC request.", UserInfo_.userinfo.email,SerialNumber_));
|
||||
|
||||
Logger_.information(fmt::format("RTTY: user={} serial={} id={}.", UserInfo_.userinfo.email,SerialNumber_,Rtty.ConnectionId));
|
||||
return RESTAPI_RPC::WaitForCommand(Cmd, Params, *Request, *Response, 60000ms, &ReturnedObject, this, Logger_);
|
||||
}
|
||||
Logger_.information(fmt::format("RTTY: user={} serial={}. Device does not exist.", UserInfo_.userinfo.email,SerialNumber_));
|
||||
return NotFound();
|
||||
}
|
||||
Logger_.information(fmt::format("RTTY: user={} serial={}. Internal error.", UserInfo_.userinfo.email,SerialNumber_));
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenWifi {
|
||||
if(pool.name.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::PoolNameInvalid);
|
||||
}
|
||||
for(const auto &config:{pool.acctConfig,pool.authConfig}) {
|
||||
for(const auto &config:{pool.acctConfig,pool.authConfig,pool.coaConfig}) {
|
||||
if(config.strategy!="random" && config.strategy!="round_robin" && config.strategy!="weighted") {
|
||||
return BadRequest(RESTAPI::Errors::InvalidRadiusProxyStrategy);
|
||||
}
|
||||
|
||||
@@ -538,8 +538,8 @@ namespace OpenWifi::AnalyticsObjects {
|
||||
|
||||
void WifiClientHistory::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"timestamp",timestamp);
|
||||
field_to_json(Obj,"stationId",stationId);
|
||||
field_to_json(Obj,"bssId",bssId);
|
||||
field_to_json(Obj,"station_id",station_id);
|
||||
field_to_json(Obj,"bssid",bssid);
|
||||
field_to_json(Obj,"ssid",ssid);
|
||||
field_to_json(Obj,"rssi",rssi);
|
||||
field_to_json(Obj,"rx_bitrate",rx_bitrate);
|
||||
@@ -573,13 +573,14 @@ namespace OpenWifi::AnalyticsObjects {
|
||||
field_to_json(Obj,"connected",connected);
|
||||
field_to_json(Obj,"inactive",inactive);
|
||||
field_to_json(Obj,"tx_retries",tx_retries);
|
||||
field_to_json(Obj,"venue_id",venue_id);
|
||||
}
|
||||
|
||||
bool WifiClientHistory::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"timestamp",timestamp);
|
||||
field_from_json(Obj,"stationId",stationId);
|
||||
field_from_json(Obj,"bssId",bssId);
|
||||
field_from_json(Obj,"station_id",station_id);
|
||||
field_from_json(Obj,"bssid",bssid);
|
||||
field_from_json(Obj,"ssid",ssid);
|
||||
field_from_json(Obj,"rssi",rssi);
|
||||
field_from_json(Obj,"rx_bitrate",rx_bitrate);
|
||||
@@ -613,6 +614,7 @@ namespace OpenWifi::AnalyticsObjects {
|
||||
field_from_json(Obj,"connected",connected);
|
||||
field_from_json(Obj,"inactive",inactive);
|
||||
field_from_json(Obj,"tx_retries",tx_retries);
|
||||
field_from_json(Obj,"venue_id",venue_id);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
|
||||
@@ -376,8 +376,8 @@ namespace OpenWifi {
|
||||
|
||||
struct WifiClientHistory {
|
||||
uint64_t timestamp=OpenWifi::Now();
|
||||
std::string stationId;
|
||||
std::string bssId;
|
||||
std::string station_id;
|
||||
std::string bssid;
|
||||
std::string ssid;
|
||||
int64_t rssi=0;
|
||||
uint32_t rx_bitrate=0;
|
||||
@@ -411,6 +411,7 @@ namespace OpenWifi {
|
||||
uint64_t connected=0;
|
||||
uint64_t inactive=0;
|
||||
uint64_t tx_retries=0;
|
||||
std::string venue_id;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
|
||||
@@ -3,176 +3,206 @@
|
||||
//
|
||||
|
||||
#include "RESTAPI_CertObjects.h"
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
using OpenWifi::RESTAPI_utils::field_to_json;
|
||||
using OpenWifi::RESTAPI_utils::field_from_json;
|
||||
|
||||
namespace OpenWifi {
|
||||
namespace CertObjects {
|
||||
void CertificateEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"id", id);
|
||||
field_to_json(Obj,"entity", entity);
|
||||
field_to_json(Obj,"creator", creator);
|
||||
field_to_json(Obj,"type", type);
|
||||
field_to_json(Obj,"status", status);
|
||||
field_to_json(Obj,"certificate", certificate);
|
||||
field_to_json(Obj,"key", key);
|
||||
field_to_json(Obj,"devid", devid);
|
||||
field_to_json(Obj,"cas", cas);
|
||||
field_to_json(Obj,"manufacturer", manufacturer);
|
||||
field_to_json(Obj,"model", model);
|
||||
field_to_json(Obj,"redirector", redirector);
|
||||
field_to_json(Obj,"commonName", commonName);
|
||||
field_to_json(Obj,"certificateId", certificateId);
|
||||
field_to_json(Obj,"batch", batch);
|
||||
field_to_json(Obj,"created", created);
|
||||
field_to_json(Obj,"modified", modified);
|
||||
field_to_json(Obj,"revoked", revoked);
|
||||
field_to_json(Obj,"revokeCount", revokeCount);
|
||||
}
|
||||
namespace OpenWifi::CertObjects {
|
||||
void CertificateEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"id", id);
|
||||
field_to_json(Obj,"entity", entity);
|
||||
field_to_json(Obj,"creator", creator);
|
||||
field_to_json(Obj,"type", type);
|
||||
field_to_json(Obj,"status", status);
|
||||
field_to_json(Obj,"certificate", certificate);
|
||||
field_to_json(Obj,"key", key);
|
||||
field_to_json(Obj,"devid", devid);
|
||||
field_to_json(Obj,"cas", cas);
|
||||
field_to_json(Obj,"manufacturer", manufacturer);
|
||||
field_to_json(Obj,"model", model);
|
||||
field_to_json(Obj,"redirector", redirector);
|
||||
field_to_json(Obj,"commonName", commonName);
|
||||
field_to_json(Obj,"certificateId", certificateId);
|
||||
field_to_json(Obj,"batch", batch);
|
||||
field_to_json(Obj,"created", created);
|
||||
field_to_json(Obj,"modified", modified);
|
||||
field_to_json(Obj,"revoked", revoked);
|
||||
field_to_json(Obj,"revokeCount", revokeCount);
|
||||
field_to_json(Obj,"synched", synched);
|
||||
}
|
||||
|
||||
bool CertificateEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"id", id);
|
||||
field_from_json(Obj,"entity", entity);
|
||||
field_from_json(Obj,"creator", creator);
|
||||
field_from_json(Obj,"type", type);
|
||||
field_from_json(Obj,"status", status);
|
||||
field_from_json(Obj,"certificate", certificate);
|
||||
field_from_json(Obj,"key", key);
|
||||
field_from_json(Obj,"devid", devid);
|
||||
field_from_json(Obj,"cas", cas);
|
||||
field_from_json(Obj,"manufacturer", manufacturer);
|
||||
field_from_json(Obj,"model", model);
|
||||
field_from_json(Obj,"redirector", redirector);
|
||||
field_from_json(Obj,"commonName", commonName);
|
||||
field_from_json(Obj,"certificateId", certificateId);
|
||||
field_from_json(Obj,"batch", batch);
|
||||
field_from_json(Obj,"created", created);
|
||||
field_from_json(Obj,"modified", modified);
|
||||
field_from_json(Obj,"revoked", revoked);
|
||||
field_from_json(Obj,"revokeCount", revokeCount);
|
||||
return true;
|
||||
} catch (...) {
|
||||
}
|
||||
return false;
|
||||
bool CertificateEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"id", id);
|
||||
field_from_json(Obj,"entity", entity);
|
||||
field_from_json(Obj,"creator", creator);
|
||||
field_from_json(Obj,"type", type);
|
||||
field_from_json(Obj,"status", status);
|
||||
field_from_json(Obj,"certificate", certificate);
|
||||
field_from_json(Obj,"key", key);
|
||||
field_from_json(Obj,"devid", devid);
|
||||
field_from_json(Obj,"cas", cas);
|
||||
field_from_json(Obj,"manufacturer", manufacturer);
|
||||
field_from_json(Obj,"model", model);
|
||||
field_from_json(Obj,"redirector", redirector);
|
||||
field_from_json(Obj,"commonName", commonName);
|
||||
field_from_json(Obj,"certificateId", certificateId);
|
||||
field_from_json(Obj,"batch", batch);
|
||||
field_from_json(Obj,"created", created);
|
||||
field_from_json(Obj,"modified", modified);
|
||||
field_from_json(Obj,"revoked", revoked);
|
||||
field_from_json(Obj,"revokeCount", revokeCount);
|
||||
field_from_json(Obj,"synched", synched);
|
||||
return true;
|
||||
} catch (...) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void EntityEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"id", id);
|
||||
field_to_json(Obj,"creator", creator);
|
||||
field_to_json(Obj,"name", name);
|
||||
field_to_json(Obj,"description", description);
|
||||
field_to_json(Obj,"defaultRedirector", defaultRedirector);
|
||||
field_to_json(Obj,"apiKey", apiKey);
|
||||
field_to_json(Obj,"serverEnrollmentProfile", serverEnrollmentProfile);
|
||||
field_to_json(Obj,"clientEnrollmentProfile", clientEnrollmentProfile);
|
||||
field_to_json(Obj,"organization", organization);
|
||||
field_to_json(Obj,"created", created);
|
||||
field_to_json(Obj,"modified", modified);
|
||||
field_to_json(Obj,"suspended", suspended);
|
||||
field_to_json(Obj,"deleted", deleted);
|
||||
field_to_json(Obj,"notes", notes);
|
||||
}
|
||||
void EntityEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"id", id);
|
||||
field_to_json(Obj,"creator", creator);
|
||||
field_to_json(Obj,"name", name);
|
||||
field_to_json(Obj,"description", description);
|
||||
field_to_json(Obj,"defaultRedirector", defaultRedirector);
|
||||
field_to_json(Obj,"apiKey", apiKey);
|
||||
field_to_json(Obj,"serverEnrollmentProfile", serverEnrollmentProfile);
|
||||
field_to_json(Obj,"clientEnrollmentProfile", clientEnrollmentProfile);
|
||||
field_to_json(Obj,"organization", organization);
|
||||
field_to_json(Obj,"created", created);
|
||||
field_to_json(Obj,"modified", modified);
|
||||
field_to_json(Obj,"suspended", suspended);
|
||||
field_to_json(Obj,"deleted", deleted);
|
||||
field_to_json(Obj,"notes", notes);
|
||||
}
|
||||
|
||||
bool EntityEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"id", id);
|
||||
field_from_json(Obj,"creator", creator);
|
||||
field_from_json(Obj,"name", name);
|
||||
field_from_json(Obj,"description", description);
|
||||
field_from_json(Obj,"defaultRedirector", defaultRedirector);
|
||||
field_from_json(Obj,"apiKey", apiKey);
|
||||
field_from_json(Obj,"serverEnrollmentProfile", serverEnrollmentProfile);
|
||||
field_from_json(Obj,"clientEnrollmentProfile", clientEnrollmentProfile);
|
||||
field_from_json(Obj,"organization", organization);
|
||||
field_from_json(Obj,"created", created);
|
||||
field_from_json(Obj,"modified", modified);
|
||||
field_from_json(Obj,"suspended", suspended);
|
||||
field_from_json(Obj,"deleted", deleted);
|
||||
field_from_json(Obj,"notes", notes);
|
||||
return true;
|
||||
} catch (...) {
|
||||
}
|
||||
return false;
|
||||
bool EntityEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"id", id);
|
||||
field_from_json(Obj,"creator", creator);
|
||||
field_from_json(Obj,"name", name);
|
||||
field_from_json(Obj,"description", description);
|
||||
field_from_json(Obj,"defaultRedirector", defaultRedirector);
|
||||
field_from_json(Obj,"apiKey", apiKey);
|
||||
field_from_json(Obj,"serverEnrollmentProfile", serverEnrollmentProfile);
|
||||
field_from_json(Obj,"clientEnrollmentProfile", clientEnrollmentProfile);
|
||||
field_from_json(Obj,"organization", organization);
|
||||
field_from_json(Obj,"created", created);
|
||||
field_from_json(Obj,"modified", modified);
|
||||
field_from_json(Obj,"suspended", suspended);
|
||||
field_from_json(Obj,"deleted", deleted);
|
||||
field_from_json(Obj,"notes", notes);
|
||||
return true;
|
||||
} catch (...) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void BatchEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"id", id);
|
||||
field_to_json(Obj,"entity", entity);
|
||||
field_to_json(Obj,"creator", creator);
|
||||
field_to_json(Obj,"name", name);
|
||||
field_to_json(Obj,"description", description);
|
||||
field_to_json(Obj,"manufacturer", manufacturer);
|
||||
field_to_json(Obj,"model", model);
|
||||
field_to_json(Obj,"redirector", redirector);
|
||||
field_to_json(Obj,"commonNames", commonNames);
|
||||
field_to_json(Obj,"jobHistory", jobHistory);
|
||||
field_to_json(Obj,"notes", notes);
|
||||
field_to_json(Obj,"submitted", submitted);
|
||||
field_to_json(Obj,"started", started);
|
||||
field_to_json(Obj,"completed", completed);
|
||||
field_to_json(Obj,"modified", modified);
|
||||
}
|
||||
void BatchEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"id", id);
|
||||
field_to_json(Obj,"entity", entity);
|
||||
field_to_json(Obj,"creator", creator);
|
||||
field_to_json(Obj,"name", name);
|
||||
field_to_json(Obj,"description", description);
|
||||
field_to_json(Obj,"manufacturer", manufacturer);
|
||||
field_to_json(Obj,"model", model);
|
||||
field_to_json(Obj,"redirector", redirector);
|
||||
field_to_json(Obj,"commonNames", commonNames);
|
||||
field_to_json(Obj,"jobHistory", jobHistory);
|
||||
field_to_json(Obj,"notes", notes);
|
||||
field_to_json(Obj,"submitted", submitted);
|
||||
field_to_json(Obj,"started", started);
|
||||
field_to_json(Obj,"completed", completed);
|
||||
field_to_json(Obj,"modified", modified);
|
||||
}
|
||||
|
||||
bool BatchEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"id", id);
|
||||
field_from_json(Obj,"entity", entity);
|
||||
field_from_json(Obj,"creator", creator);
|
||||
field_from_json(Obj,"name", name);
|
||||
field_from_json(Obj,"description", description);
|
||||
field_from_json(Obj,"manufacturer", manufacturer);
|
||||
field_from_json(Obj,"model", model);
|
||||
field_from_json(Obj,"redirector", redirector);
|
||||
field_from_json(Obj,"commonNames", commonNames);
|
||||
field_from_json(Obj,"jobHistory", jobHistory);
|
||||
field_from_json(Obj,"notes", notes);
|
||||
field_from_json(Obj,"submitted", submitted);
|
||||
field_from_json(Obj,"started", started);
|
||||
field_from_json(Obj,"completed", completed);
|
||||
field_from_json(Obj,"modified", modified);
|
||||
return true;
|
||||
} catch (...) {
|
||||
}
|
||||
return false;
|
||||
bool BatchEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"id", id);
|
||||
field_from_json(Obj,"entity", entity);
|
||||
field_from_json(Obj,"creator", creator);
|
||||
field_from_json(Obj,"name", name);
|
||||
field_from_json(Obj,"description", description);
|
||||
field_from_json(Obj,"manufacturer", manufacturer);
|
||||
field_from_json(Obj,"model", model);
|
||||
field_from_json(Obj,"redirector", redirector);
|
||||
field_from_json(Obj,"commonNames", commonNames);
|
||||
field_from_json(Obj,"jobHistory", jobHistory);
|
||||
field_from_json(Obj,"notes", notes);
|
||||
field_from_json(Obj,"submitted", submitted);
|
||||
field_from_json(Obj,"started", started);
|
||||
field_from_json(Obj,"completed", completed);
|
||||
field_from_json(Obj,"modified", modified);
|
||||
return true;
|
||||
} catch (...) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void JobEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"id", id);
|
||||
field_to_json(Obj,"entity", entity);
|
||||
field_to_json(Obj,"creator", creator);
|
||||
field_to_json(Obj,"batch", batch);
|
||||
field_to_json(Obj,"commonNames", commonNames);
|
||||
field_to_json(Obj,"completedNames", completedNames);
|
||||
field_to_json(Obj,"errorNames", errorNames);
|
||||
field_to_json(Obj,"status", status);
|
||||
field_to_json(Obj,"command", command);
|
||||
field_to_json(Obj,"parameters", parameters);
|
||||
field_to_json(Obj,"submitted", submitted);
|
||||
field_to_json(Obj,"started", started);
|
||||
field_to_json(Obj,"completed", completed);
|
||||
}
|
||||
void JobEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"id", id);
|
||||
field_to_json(Obj,"entity", entity);
|
||||
field_to_json(Obj,"creator", creator);
|
||||
field_to_json(Obj,"batch", batch);
|
||||
field_to_json(Obj,"commonNames", commonNames);
|
||||
field_to_json(Obj,"completedNames", completedNames);
|
||||
field_to_json(Obj,"errorNames", errorNames);
|
||||
field_to_json(Obj,"status", status);
|
||||
field_to_json(Obj,"command", command);
|
||||
field_to_json(Obj,"parameters", parameters);
|
||||
field_to_json(Obj,"submitted", submitted);
|
||||
field_to_json(Obj,"started", started);
|
||||
field_to_json(Obj,"completed", completed);
|
||||
}
|
||||
|
||||
bool JobEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"id", id);
|
||||
field_from_json(Obj,"entity", entity);
|
||||
field_from_json(Obj,"creator", creator);
|
||||
field_from_json(Obj,"batch", batch);
|
||||
field_from_json(Obj,"commonNames", commonNames);
|
||||
field_from_json(Obj,"completedNames", completedNames);
|
||||
field_from_json(Obj,"errorNames", errorNames);
|
||||
field_from_json(Obj,"status", status);
|
||||
field_from_json(Obj,"command", command);
|
||||
field_from_json(Obj,"parameters", parameters);
|
||||
field_from_json(Obj,"submitted", submitted);
|
||||
field_from_json(Obj,"started", started);
|
||||
field_from_json(Obj,"completed", completed);
|
||||
return true;
|
||||
} catch (...) {
|
||||
}
|
||||
return false;
|
||||
bool JobEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"id", id);
|
||||
field_from_json(Obj,"entity", entity);
|
||||
field_from_json(Obj,"creator", creator);
|
||||
field_from_json(Obj,"batch", batch);
|
||||
field_from_json(Obj,"commonNames", commonNames);
|
||||
field_from_json(Obj,"completedNames", completedNames);
|
||||
field_from_json(Obj,"errorNames", errorNames);
|
||||
field_from_json(Obj,"status", status);
|
||||
field_from_json(Obj,"command", command);
|
||||
field_from_json(Obj,"parameters", parameters);
|
||||
field_from_json(Obj,"submitted", submitted);
|
||||
field_from_json(Obj,"started", started);
|
||||
field_from_json(Obj,"completed", completed);
|
||||
return true;
|
||||
} catch (...) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DashBoardYearlyStats::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "year", year);
|
||||
field_to_json(Obj, "activeCerts", activeCerts);
|
||||
field_to_json(Obj, "revokedCerts", revokedCerts);
|
||||
}
|
||||
|
||||
void Dashboard::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"snapshot", snapshot);
|
||||
field_to_json(Obj,"numberOfIssuedCerts", numberOfIssuedCerts);
|
||||
field_to_json(Obj,"numberOfRevokedCerts", numberOfRevokedCerts);
|
||||
field_to_json(Obj,"activeCertsPerOrganization", activeCertsPerOrganization);
|
||||
field_to_json(Obj,"revokedCertsPerOrganization", revokedCertsPerOrganization);
|
||||
field_to_json(Obj,"numberOfRedirectors", numberOfRedirectors);
|
||||
field_to_json(Obj,"deviceTypes", deviceTypes);
|
||||
field_to_json(Obj,"monthlyNumberOfCerts", monthlyNumberOfCerts);
|
||||
field_to_json(Obj,"monthlyNumberOfCertsPerOrgPerYear", monthlyNumberOfCertsPerOrgPerYear);
|
||||
}
|
||||
|
||||
void Dashboard::reset() {
|
||||
snapshot=0;
|
||||
numberOfRevokedCerts = numberOfIssuedCerts = 0;
|
||||
activeCertsPerOrganization.clear();
|
||||
revokedCertsPerOrganization.clear();
|
||||
numberOfRedirectors.clear();
|
||||
deviceTypes.clear();
|
||||
monthlyNumberOfCerts.clear();
|
||||
monthlyNumberOfCertsPerOrgPerYear.clear();
|
||||
}
|
||||
}
|
||||
@@ -5,97 +5,118 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "framework/MicroService.h"
|
||||
#include "framework/OpenWifiTypes.h"
|
||||
#include "RESTObjects/RESTAPI_SecurityObjects.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
namespace OpenWifi::CertObjects {
|
||||
|
||||
namespace CertObjects {
|
||||
struct CertificateEntry {
|
||||
OpenWifi::Types::UUID_t id;
|
||||
OpenWifi::Types::UUID_t entity;
|
||||
OpenWifi::Types::UUID_t creator;
|
||||
std::string type;
|
||||
std::string status;
|
||||
std::string certificate;
|
||||
std::string key;
|
||||
std::string devid;
|
||||
std::string cas;
|
||||
std::string manufacturer;
|
||||
std::string model;
|
||||
std::string redirector;
|
||||
std::string commonName;
|
||||
std::string certificateId;
|
||||
OpenWifi::Types::UUID_t batch;
|
||||
uint64_t created = 0;
|
||||
uint64_t modified = 0;
|
||||
uint64_t revoked = 0;
|
||||
uint64_t revokeCount = 0;
|
||||
uint64_t synched = 0;
|
||||
|
||||
struct CertificateEntry {
|
||||
OpenWifi::Types::UUID_t id;
|
||||
OpenWifi::Types::UUID_t entity;
|
||||
OpenWifi::Types::UUID_t creator;
|
||||
std::string type;
|
||||
std::string status;
|
||||
std::string certificate;
|
||||
std::string key;
|
||||
std::string devid;
|
||||
std::string cas;
|
||||
std::string manufacturer;
|
||||
std::string model;
|
||||
std::string redirector;
|
||||
std::string commonName;
|
||||
std::string certificateId;
|
||||
OpenWifi::Types::UUID_t batch;
|
||||
uint64_t created = 0;
|
||||
uint64_t modified = 0;
|
||||
uint64_t revoked = 0;
|
||||
uint64_t revokeCount = 0;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
struct EntityEntry {
|
||||
OpenWifi::Types::UUID_t id;
|
||||
OpenWifi::Types::UUID_t creator;
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::string defaultRedirector;
|
||||
std::string apiKey;
|
||||
std::string serverEnrollmentProfile;
|
||||
std::string clientEnrollmentProfile;
|
||||
std::string organization;
|
||||
SecurityObjects::NoteInfoVec notes;
|
||||
bool suspended=false;
|
||||
bool deleted=false;
|
||||
uint64_t created = 0 ;
|
||||
uint64_t modified = 0 ;
|
||||
|
||||
struct EntityEntry {
|
||||
OpenWifi::Types::UUID_t id;
|
||||
OpenWifi::Types::UUID_t creator;
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::string defaultRedirector;
|
||||
std::string apiKey;
|
||||
std::string serverEnrollmentProfile;
|
||||
std::string clientEnrollmentProfile;
|
||||
std::string organization;
|
||||
SecurityObjects::NoteInfoVec notes;
|
||||
bool suspended=false;
|
||||
bool deleted=false;
|
||||
uint64_t created = 0 ;
|
||||
uint64_t modified = 0 ;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
struct BatchEntry {
|
||||
OpenWifi::Types::UUID_t id;
|
||||
OpenWifi::Types::UUID_t entity;
|
||||
OpenWifi::Types::UUID_t creator;
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::string manufacturer;
|
||||
std::string model;
|
||||
std::string redirector;
|
||||
std::vector<std::string> commonNames;
|
||||
std::vector<std::string> jobHistory;
|
||||
SecurityObjects::NoteInfoVec notes;
|
||||
uint64_t submitted = 0 ;
|
||||
uint64_t started = 0 ;
|
||||
uint64_t completed = 0 ;
|
||||
uint64_t modified = 0 ;
|
||||
|
||||
struct BatchEntry {
|
||||
OpenWifi::Types::UUID_t id;
|
||||
OpenWifi::Types::UUID_t entity;
|
||||
OpenWifi::Types::UUID_t creator;
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::string manufacturer;
|
||||
std::string model;
|
||||
std::string redirector;
|
||||
std::vector<std::string> commonNames;
|
||||
std::vector<std::string> jobHistory;
|
||||
SecurityObjects::NoteInfoVec notes;
|
||||
uint64_t submitted = 0 ;
|
||||
uint64_t started = 0 ;
|
||||
uint64_t completed = 0 ;
|
||||
uint64_t modified = 0 ;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
struct JobEntry {
|
||||
OpenWifi::Types::UUID_t id;
|
||||
OpenWifi::Types::UUID_t entity;
|
||||
OpenWifi::Types::UUID_t creator;
|
||||
OpenWifi::Types::UUID_t batch;
|
||||
std::string command;
|
||||
OpenWifi::Types::StringVec commonNames;
|
||||
OpenWifi::Types::StringVec completedNames;
|
||||
OpenWifi::Types::StringVec errorNames;
|
||||
Types::StringPairVec parameters;
|
||||
std::string status;
|
||||
uint64_t submitted=0;
|
||||
uint64_t started=0;
|
||||
uint64_t completed=0;
|
||||
|
||||
struct JobEntry {
|
||||
OpenWifi::Types::UUID_t id;
|
||||
OpenWifi::Types::UUID_t entity;
|
||||
OpenWifi::Types::UUID_t creator;
|
||||
OpenWifi::Types::UUID_t batch;
|
||||
std::string command;
|
||||
OpenWifi::Types::StringVec commonNames;
|
||||
OpenWifi::Types::StringVec completedNames;
|
||||
OpenWifi::Types::StringVec errorNames;
|
||||
Types::StringPairVec parameters;
|
||||
std::string status;
|
||||
uint64_t submitted=0;
|
||||
uint64_t started=0;
|
||||
uint64_t completed=0;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
struct DashBoardYearlyStats {
|
||||
uint64_t year=0;
|
||||
OpenWifi::Types::Counted3DMapSII activeCerts;
|
||||
OpenWifi::Types::Counted3DMapSII revokedCerts;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
};
|
||||
|
||||
struct Dashboard {
|
||||
uint64_t snapshot=0;
|
||||
uint64_t numberOfIssuedCerts=0;
|
||||
uint64_t numberOfRevokedCerts=0;
|
||||
OpenWifi::Types::CountedMap activeCertsPerOrganization;
|
||||
OpenWifi::Types::CountedMap revokedCertsPerOrganization;
|
||||
OpenWifi::Types::CountedMap numberOfRedirectors;
|
||||
OpenWifi::Types::CountedMap deviceTypes;
|
||||
OpenWifi::Types::CountedMap monthlyNumberOfCerts;
|
||||
std::vector<DashBoardYearlyStats> monthlyNumberOfCertsPerOrgPerYear;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
void reset();
|
||||
};
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -314,6 +314,8 @@ namespace OpenWifi::GWObjects {
|
||||
field_to_json(Obj,"description",description);
|
||||
field_to_json(Obj,"authConfig",authConfig);
|
||||
field_to_json(Obj,"acctConfig",acctConfig);
|
||||
field_to_json(Obj,"coaConfig",coaConfig);
|
||||
field_to_json(Obj,"useByDefault",useByDefault);
|
||||
}
|
||||
|
||||
bool RadiusProxyPool::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
@@ -322,6 +324,8 @@ namespace OpenWifi::GWObjects {
|
||||
field_from_json(Obj,"description",description);
|
||||
field_from_json(Obj,"authConfig",authConfig);
|
||||
field_from_json(Obj,"acctConfig",acctConfig);
|
||||
field_from_json(Obj,"coaConfig",coaConfig);
|
||||
field_from_json(Obj,"useByDefault",useByDefault);
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
}
|
||||
@@ -329,7 +333,7 @@ namespace OpenWifi::GWObjects {
|
||||
}
|
||||
|
||||
void RadiusProxyServerConfig::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"policy",strategy);
|
||||
field_to_json(Obj,"strategy",strategy);
|
||||
field_to_json(Obj,"monitor",monitor);
|
||||
field_to_json(Obj,"monitorMethod",monitorMethod);
|
||||
field_to_json(Obj,"methodParameters",methodParameters);
|
||||
@@ -338,7 +342,7 @@ namespace OpenWifi::GWObjects {
|
||||
|
||||
bool RadiusProxyServerConfig::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"policy",strategy);
|
||||
field_from_json(Obj,"strategy",strategy);
|
||||
field_from_json(Obj,"monitor",monitor);
|
||||
field_from_json(Obj,"monitorMethod",monitorMethod);
|
||||
field_from_json(Obj,"methodParameters",methodParameters);
|
||||
@@ -354,6 +358,14 @@ namespace OpenWifi::GWObjects {
|
||||
field_to_json(Obj,"ip",ip);
|
||||
field_to_json(Obj,"port",port);
|
||||
field_to_json(Obj,"weight",weight);
|
||||
field_to_json(Obj,"secret",secret);
|
||||
field_to_json(Obj,"certificate",certificate);
|
||||
field_to_json(Obj,"radsec",radsec);
|
||||
field_to_json(Obj,"radsec_secret",radsec_secret);
|
||||
field_to_json(Obj,"radsec_port",radsec_port);
|
||||
field_to_json(Obj,"radsec_cacerts",radsec_cacerts);
|
||||
field_to_json(Obj,"radsec_cert",radsec_cert);
|
||||
field_to_json(Obj,"radsec_key",radsec_key);
|
||||
}
|
||||
|
||||
bool RadiusProxyServerEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
@@ -362,6 +374,14 @@ namespace OpenWifi::GWObjects {
|
||||
field_from_json(Obj,"ip",ip);
|
||||
field_from_json(Obj,"port",port);
|
||||
field_from_json(Obj,"weight",weight);
|
||||
field_from_json(Obj,"secret",secret);
|
||||
field_from_json(Obj,"certificate",certificate);
|
||||
field_from_json(Obj,"radsec",radsec);
|
||||
field_from_json(Obj,"radsec_port",radsec_port);
|
||||
field_from_json(Obj,"radsec_secret",radsec_secret);
|
||||
field_from_json(Obj,"radsec_cacerts",radsec_cacerts);
|
||||
field_from_json(Obj,"radsec_cert",radsec_cert);
|
||||
field_from_json(Obj,"radsec_key",radsec_key);
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
}
|
||||
|
||||
@@ -216,6 +216,14 @@ namespace OpenWifi::GWObjects {
|
||||
std::string ip;
|
||||
uint16_t port=0;
|
||||
uint64_t weight=0;
|
||||
std::string secret;
|
||||
std::string certificate;
|
||||
bool radsec=false;
|
||||
uint16_t radsec_port=2084;
|
||||
std::string radsec_secret;
|
||||
std::string radsec_key;
|
||||
std::string radsec_cert;
|
||||
std::string radsec_cacerts;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
@@ -237,6 +245,8 @@ namespace OpenWifi::GWObjects {
|
||||
std::string description;
|
||||
RadiusProxyServerConfig authConfig;
|
||||
RadiusProxyServerConfig acctConfig;
|
||||
RadiusProxyServerConfig coaConfig;
|
||||
bool useByDefault=false;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include "framework/OpenWifiTypes.h"
|
||||
#include "Poco/JSON/Object.h"
|
||||
#include "Poco/Data/LOB.h"
|
||||
@@ -27,8 +28,13 @@ namespace OpenWifi {
|
||||
bool Delete_ = true;
|
||||
bool PortalLogin_ = true;
|
||||
|
||||
AclTemplate() noexcept = default;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj); };
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
static_assert( std::is_nothrow_move_constructible_v<AclTemplate> );
|
||||
|
||||
struct WebToken {
|
||||
std::string access_token_;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
namespace OpenWifi {
|
||||
|
||||
void Archiver::onTimer([[maybe_unused]] Poco::Timer &timer){
|
||||
Utils::SetThreadName("strg-archiver");
|
||||
auto now = OpenWifi::Now();
|
||||
for(const auto &i:DBs_) {
|
||||
if (!Poco::icompare(i.DBName, "healthchecks")) {
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
void TelemetryClient::CompleteStartup() {
|
||||
std::lock_guard Guard(Mutex_);
|
||||
try {
|
||||
std::lock_guard Guard(Mutex_);
|
||||
Socket_ = *WS_;
|
||||
CId_ = Utils::FormatIPv6(Socket_.peerAddress().toString());
|
||||
|
||||
@@ -103,21 +103,19 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
void TelemetryClient::OnSocketShutdown([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf) {
|
||||
std::lock_guard Guard(Mutex_);
|
||||
Logger().information(fmt::format("SOCKET-SHUTDOWN({}): Orderly shutdown.", CId_));
|
||||
SendTelemetryShutdown();
|
||||
}
|
||||
|
||||
void TelemetryClient::OnSocketError([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ErrorNotification>& pNf) {
|
||||
std::lock_guard Guard(Mutex_);
|
||||
Logger().information(fmt::format("SOCKET-ERROR({}): Closing.",CId_));
|
||||
SendTelemetryShutdown();
|
||||
}
|
||||
|
||||
void TelemetryClient::OnSocketReadable([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf) {
|
||||
std::lock_guard Guard(Mutex_);
|
||||
try
|
||||
{
|
||||
std::lock_guard Guard(Mutex_);
|
||||
ProcessIncomingFrame();
|
||||
}
|
||||
catch (const Poco::Exception & E)
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace OpenWifi {
|
||||
Messages_->Readable_ += Poco::delegate(this,&TelemetryStream::onMessage);
|
||||
// ReactorPool_.Start("TelemetryWebSocketPool_");
|
||||
Thr_.start(Reactor_);
|
||||
Utils::SetThreadName(Thr_,"telemetry-svr");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,16 +47,14 @@ namespace OpenWifi {
|
||||
void UpdateEndPoint(uint64_t SerialNumber, const std::string &PayLoad);
|
||||
bool RegisterClient(const std::string &UUID, TelemetryClient *Client);
|
||||
void DeRegisterClient(const std::string &UUID);
|
||||
// Poco::Net::SocketReactor & NextReactor() { return ReactorPool_.NextReactor(); }
|
||||
Poco::Net::SocketReactor & NextReactor() { return Reactor_; }
|
||||
|
||||
void onMessage(bool& b);
|
||||
|
||||
private:
|
||||
std::atomic_bool Running_=false;
|
||||
volatile std::atomic_bool Running_=false;
|
||||
std::map<std::string, TelemetryClient *> Clients_; // uuid -> client
|
||||
std::map<uint64_t, std::set<std::string>> SerialNumbers_; // serialNumber -> uuid
|
||||
// ReactorPool ReactorPool_;
|
||||
Poco::Net::SocketReactor Reactor_;
|
||||
std::unique_ptr<FIFO<QueueUpdate>> Messages_=std::make_unique<FIFO<QueueUpdate>>(100);
|
||||
Poco::Thread Thr_;
|
||||
|
||||
142
src/VenueBroadcaster.h
Normal file
142
src/VenueBroadcaster.h
Normal file
@@ -0,0 +1,142 @@
|
||||
//
|
||||
// Created by stephane bourque on 2022-07-16.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "framework/MicroService.h"
|
||||
#include "sdks/sdk_prov.h"
|
||||
#include "DeviceRegistry.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class VenueBroadcastNotification : public Poco::Notification {
|
||||
public:
|
||||
VenueBroadcastNotification(const std::string &SourceSerialNumber, const std::string &Data, uint64_t TimeStamp) :
|
||||
SourceSerialNumber_(SourceSerialNumber),
|
||||
Data_(Data),
|
||||
TimeStamp_(TimeStamp) {
|
||||
|
||||
}
|
||||
std::string SourceSerialNumber_;
|
||||
std::string Data_;
|
||||
uint64_t TimeStamp_=OpenWifi::Now();
|
||||
};
|
||||
|
||||
class VenueBroadcaster : public SubSystemServer, Poco::Runnable {
|
||||
public:
|
||||
static auto instance() {
|
||||
static auto instance_ = new VenueBroadcaster;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
inline int Start() override {
|
||||
Enabled_ = MicroService::instance().ConfigGetBool("venue_broadcast.enabled",true);
|
||||
if(Enabled_) {
|
||||
BroadcastManager_.start(*this);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void Stop() override {
|
||||
if(Enabled_ && Running_) {
|
||||
BroadcastQueue_.wakeUpAll();
|
||||
BroadcastManager_.wakeUp();
|
||||
BroadcastManager_.join();
|
||||
}
|
||||
}
|
||||
|
||||
inline void reinitialize([[maybe_unused]] Poco::Util::Application &self) override {
|
||||
Logger().information("Reinitializing.");
|
||||
}
|
||||
|
||||
|
||||
struct VenueInfo {
|
||||
uint64_t timestamp=OpenWifi::Now();
|
||||
Types::StringVec serialNumbers;
|
||||
};
|
||||
|
||||
inline bool FindSerialNumberList(const std::string &Source, OpenWifi::Types::StringVec & SerialNumbers) {
|
||||
// Can we find our serial number in any of the lists so far...
|
||||
for(const auto &venue:Venues_) {
|
||||
auto entry = std::find(venue.second.serialNumbers.begin(),venue.second.serialNumbers.end(),Source);
|
||||
if(entry!=venue.second.serialNumbers.end() && (OpenWifi::Now()-venue.second.timestamp)<600) {
|
||||
SerialNumbers = venue.second.serialNumbers;
|
||||
auto entry2 = std::find(SerialNumbers.begin(),SerialNumbers.end(),Source);
|
||||
SerialNumbers.erase(entry2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// get the venue from Prov and the serial numbers.
|
||||
Types::UUID_t Venue;
|
||||
Types::StringVec TmpSerialNumbers;
|
||||
if(OpenWifi::SDK::Prov::GetSerialNumbersForVenueOfSerialNumber(Source,Venue,TmpSerialNumbers,Logger())) {
|
||||
std::sort(TmpSerialNumbers.begin(),TmpSerialNumbers.end());
|
||||
VenueInfo V{.timestamp=OpenWifi::Now(), .serialNumbers=TmpSerialNumbers};
|
||||
Venues_[Venue] = V;
|
||||
auto p = std::find(TmpSerialNumbers.begin(),TmpSerialNumbers.end(),Source);
|
||||
if(p!=TmpSerialNumbers.end()) {
|
||||
TmpSerialNumbers.erase(p);
|
||||
SerialNumbers = TmpSerialNumbers;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void SendToDevice(const std::string &SerialNumber,const std::string &Payload) {
|
||||
DeviceRegistry()->SendFrame(SerialNumber,Payload);
|
||||
}
|
||||
|
||||
inline void run() final {
|
||||
Running_ = true;
|
||||
Utils::SetThreadName("venue-bcast");
|
||||
Poco::AutoPtr<Poco::Notification> NextNotification(BroadcastQueue_.waitDequeueNotification());
|
||||
while (NextNotification && Running_) {
|
||||
auto Notification = dynamic_cast<VenueBroadcastNotification *>(NextNotification.get());
|
||||
if (Notification != nullptr) {
|
||||
Types::StringVec SerialNumbers;
|
||||
if(FindSerialNumberList(Notification->SourceSerialNumber_,SerialNumbers)) {
|
||||
Poco::JSON::Object Payload;
|
||||
Payload.set("jsonrpc","2.0");
|
||||
Payload.set("method","venue_broadcast");
|
||||
Poco::JSON::Object ParamBlock;
|
||||
ParamBlock.set("serial",Notification->SourceSerialNumber_);
|
||||
ParamBlock.set("timestamp",Notification->TimeStamp_);
|
||||
ParamBlock.set("data",Notification->Data_);
|
||||
Payload.set("params", ParamBlock);
|
||||
std::ostringstream o;
|
||||
Payload.stringify(o);
|
||||
for(const auto &Device:SerialNumbers) {
|
||||
SendToDevice(Device,o.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
NextNotification = BroadcastQueue_.waitDequeueNotification();
|
||||
}
|
||||
Running_=false;
|
||||
}
|
||||
|
||||
inline void Broadcast(const std::string &SourceSerial, const std::string &Data, uint64_t TimeStamp) {
|
||||
BroadcastQueue_.enqueueNotification(new VenueBroadcastNotification(SourceSerial,Data,TimeStamp));
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::atomic_bool Running_=false;
|
||||
bool Enabled_=false;
|
||||
Poco::NotificationQueue BroadcastQueue_;
|
||||
Poco::Thread BroadcastManager_;
|
||||
|
||||
std::map<OpenWifi::Types::UUID_t,VenueInfo> Venues_;
|
||||
|
||||
VenueBroadcaster() noexcept:
|
||||
SubSystemServer("VenueBroadcaster", "VENUE-BCAST", "venue.broacast")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
inline auto VenueBroadcaster() { return VenueBroadcaster::instance(); }
|
||||
}
|
||||
@@ -5,11 +5,13 @@
|
||||
#include "WS_Connection.h"
|
||||
|
||||
#include "Poco/Net/SecureStreamSocketImpl.h"
|
||||
#include "Poco/Net/SecureServerSocketImpl.h"
|
||||
#include "Poco/Net/HTTPServerResponseImpl.h"
|
||||
#include "Poco/Net/HTTPServerSession.h"
|
||||
#include "Poco/Net/HTTPServerRequestImpl.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Net/SSLException.h"
|
||||
#include "Poco/Net/Context.h"
|
||||
#include "Poco/Base64Decoder.h"
|
||||
#include "Poco/Base64Encoder.h"
|
||||
|
||||
@@ -24,6 +26,7 @@
|
||||
#include "TelemetryStream.h"
|
||||
#include "CentralConfig.h"
|
||||
#include "FindCountry.h"
|
||||
#include "VenueBroadcaster.h"
|
||||
#include "framework/WebSocketClientNotifications.h"
|
||||
|
||||
#include "RADIUS_proxy_server.h"
|
||||
@@ -46,9 +49,9 @@ namespace OpenWifi {
|
||||
PeerAddress_ = SS->peerAddress().host();
|
||||
CId_ = Utils::FormatIPv6(SS->peerAddress().toString());
|
||||
if (!SS->secure()) {
|
||||
Logger().error(fmt::format("{}: Connection is NOT secure.", CId_));
|
||||
poco_error(Logger(),fmt::format("{}: Connection is NOT secure.", CId_));
|
||||
} else {
|
||||
Logger().debug(fmt::format("{}: Connection is secure.", CId_));
|
||||
poco_trace(Logger(),fmt::format("{}: Connection is secure.", CId_));
|
||||
}
|
||||
|
||||
if (SS->havePeerCertificate()) {
|
||||
@@ -60,15 +63,15 @@ namespace OpenWifi {
|
||||
if (WebSocketServer()->ValidateCertificate(CId_, PeerCert)) {
|
||||
CN_ = Poco::trim(Poco::toLower(PeerCert.commonName()));
|
||||
CertValidation_ = GWObjects::MISMATCH_SERIAL;
|
||||
Logger().debug(fmt::format("{}: Valid certificate: CN={}", CId_, CN_));
|
||||
poco_trace(Logger(),fmt::format("{}: Valid certificate: CN={}", CId_, CN_));
|
||||
} else {
|
||||
Logger().debug(fmt::format("{}: Certificate is not valid", CId_));
|
||||
poco_error(Logger(),fmt::format("{}: Certificate is not valid", CId_));
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
LogException(E);
|
||||
}
|
||||
} else {
|
||||
Logger().error(fmt::format("{}: No certificates available..", CId_));
|
||||
poco_error(Logger(),fmt::format("{}: No certificates available..", CId_));
|
||||
}
|
||||
|
||||
if (WebSocketServer::IsSim(CN_) && !WebSocketServer()->IsSimEnabled()) {
|
||||
@@ -113,7 +116,7 @@ namespace OpenWifi {
|
||||
Reactor_.addEventHandler(*WS_, Poco::NObserver<WSConnection, Poco::Net::ErrorNotification>(
|
||||
*this, &WSConnection::OnSocketError));
|
||||
Registered_ = true;
|
||||
Logger().information(fmt::format("CONNECTION({}): completed.", CId_));
|
||||
poco_debug(Logger(),fmt::format("CONNECTION({}): completed.", CId_));
|
||||
return;
|
||||
} catch (const Poco::Net::CertificateValidationException &E) {
|
||||
Logger().error(fmt::format("CONNECTION({}): Poco::Exception Certificate Validation failed during connection. Device will have to retry.",
|
||||
@@ -177,6 +180,7 @@ namespace OpenWifi {
|
||||
|
||||
WSConnection::~WSConnection() {
|
||||
|
||||
poco_debug(Logger(),fmt::format("{}: Removing connection for {}.", CId_, SerialNumber_));
|
||||
if (ConnectionId_)
|
||||
DeviceRegistry()->UnRegister(SerialNumberInt_, ConnectionId_);
|
||||
|
||||
@@ -357,7 +361,8 @@ namespace OpenWifi {
|
||||
auto Firmware = ParamsObj->get(uCentralProtocol::FIRMWARE).toString();
|
||||
auto Capabilities = ParamsObj->get(uCentralProtocol::CAPABILITIES).toString();
|
||||
|
||||
SerialNumber_ = Serial;
|
||||
//// change this
|
||||
CN_ = SerialNumber_ = Serial;
|
||||
SerialNumberInt_ = Utils::SerialNumberToInt(SerialNumber_);
|
||||
Conn_ = DeviceRegistry()->Register(SerialNumberInt_, this, ConnectionId_);
|
||||
Conn_->Conn_.UUID = UUID;
|
||||
@@ -370,7 +375,7 @@ namespace OpenWifi {
|
||||
if ((!CN_.empty() && Utils::SerialNumberMatch(CN_, SerialNumber_)) ||
|
||||
WebSocketServer()->IsSimSerialNumber(CN_)) {
|
||||
CertValidation_ = GWObjects::VERIFIED;
|
||||
poco_information(Logger(), fmt::format("CONNECT({}): Fully validated and authenticated device..", CId_));
|
||||
poco_information(Logger(), fmt::format("CONNECT({}): Fully validated and authenticated device.", CId_));
|
||||
} else {
|
||||
if (CN_.empty())
|
||||
poco_information(Logger(), fmt::format("CONNECT({}): Not authenticated or validated.", CId_));
|
||||
@@ -752,6 +757,14 @@ namespace OpenWifi {
|
||||
}
|
||||
} break;
|
||||
|
||||
case uCentralProtocol::Events::ET_VENUEBROADCAST: {
|
||||
if(ParamsObj->has("data") && ParamsObj->has("serial") && ParamsObj->has("timestamp")) {
|
||||
VenueBroadcaster()->Broadcast(
|
||||
ParamsObj->get("serial").toString(),
|
||||
ParamsObj->get("data").toString(),
|
||||
ParamsObj->get("timestamp"));
|
||||
}
|
||||
} break;
|
||||
// this will never be called but some compilers will complain if we do not have a case for
|
||||
// every single values of an enum
|
||||
case uCentralProtocol::Events::ET_UNKNOWN: {
|
||||
@@ -1057,6 +1070,8 @@ namespace OpenWifi {
|
||||
CId_, std::string{E.what()}, IncomingMessageStr));
|
||||
return delete this;
|
||||
} catch (...) {
|
||||
poco_error(Logger(),fmt::format("Device {} must be disconnected. Unknown exception.", CId_));
|
||||
std::cout << "Device " << CId_ << " must be disconnected due to exception..." << std::endl;
|
||||
return delete this;
|
||||
}
|
||||
|
||||
@@ -1077,12 +1092,7 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
std::string Base64Encode(const unsigned char *buffer, std::size_t size) {
|
||||
std::istringstream s(std::string{(const char *)buffer,size});
|
||||
std::ostringstream o;
|
||||
Poco::Base64Encoder E(o);
|
||||
Poco::StreamCopier::copyStream(s,E);
|
||||
E.close();
|
||||
return o.str();
|
||||
return Utils::base64encode(buffer,size);
|
||||
}
|
||||
|
||||
std::string Base64Decode(const std::string &F) {
|
||||
@@ -1113,19 +1123,31 @@ namespace OpenWifi {
|
||||
return Send(Payload.str());
|
||||
}
|
||||
|
||||
bool WSConnection::SendRadiusCoAData(const unsigned char * buffer, std::size_t size) {
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set(uCentralProtocol::RADIUS,uCentralProtocol::RADIUSCOA);
|
||||
Answer.set(uCentralProtocol::RADIUSDATA, Base64Encode(buffer,size));
|
||||
|
||||
std::ostringstream Payload;
|
||||
Answer.stringify(Payload);
|
||||
return Send(Payload.str());
|
||||
}
|
||||
|
||||
void WSConnection::ProcessIncomingRadiusData(const Poco::JSON::Object::Ptr &Doc) {
|
||||
if( Doc->has(uCentralProtocol::RADIUSDATA)) {
|
||||
auto Type = Doc->get(uCentralProtocol::RADIUS).toString();
|
||||
if(Type==uCentralProtocol::RADIUSACCT) {
|
||||
auto Data = Doc->get(uCentralProtocol::RADIUSDATA).toString();
|
||||
auto DecodedData = Base64Decode(Data);
|
||||
auto Destination = Doc->has(uCentralProtocol::RADIUSDST) ? Doc->get(uCentralProtocol::RADIUSDST).toString() : "";
|
||||
RADIUS_proxy_server()->SendAccountingData(SerialNumber_,Destination,DecodedData.c_str(),DecodedData.size());
|
||||
RADIUS_proxy_server()->SendAccountingData(SerialNumber_,DecodedData.c_str(),DecodedData.size());
|
||||
} else if(Type==uCentralProtocol::RADIUSAUTH) {
|
||||
auto Data = Doc->get(uCentralProtocol::RADIUSDATA).toString();
|
||||
auto DecodedData = Base64Decode(Data);
|
||||
auto Destination = Doc->has(uCentralProtocol::RADIUSDST) ? Doc->get(uCentralProtocol::RADIUSDST).toString() : "";
|
||||
RADIUS_proxy_server()->SendAuthenticationData(SerialNumber_,Destination,DecodedData.c_str(),DecodedData.size());
|
||||
RADIUS_proxy_server()->SendAuthenticationData(SerialNumber_,DecodedData.c_str(),DecodedData.size());
|
||||
} else if(Type==uCentralProtocol::RADIUSCOA) {
|
||||
auto Data = Doc->get(uCentralProtocol::RADIUSDATA).toString();
|
||||
auto DecodedData = Base64Decode(Data);
|
||||
RADIUS_proxy_server()->SendCoAData(SerialNumber_,DecodedData.c_str(),DecodedData.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,79 +17,81 @@
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class WSConnection {
|
||||
static constexpr int BufSize = 128000;
|
||||
public:
|
||||
WSConnection(Poco::Net::StreamSocket& Socket, Poco::Net::SocketReactor& Reactor);
|
||||
~WSConnection();
|
||||
class WSConnection {
|
||||
static constexpr int BufSize = 128000;
|
||||
public:
|
||||
WSConnection(Poco::Net::StreamSocket& Socket, Poco::Net::SocketReactor& Reactor);
|
||||
~WSConnection();
|
||||
|
||||
void ProcessJSONRPCEvent(Poco::JSON::Object::Ptr & Doc);
|
||||
void ProcessJSONRPCResult(Poco::JSON::Object::Ptr Doc);
|
||||
void ProcessIncomingFrame();
|
||||
void ProcessIncomingRadiusData(const Poco::JSON::Object::Ptr &Doc);
|
||||
void ProcessJSONRPCEvent(Poco::JSON::Object::Ptr & Doc);
|
||||
void ProcessJSONRPCResult(Poco::JSON::Object::Ptr Doc);
|
||||
void ProcessIncomingFrame();
|
||||
void ProcessIncomingRadiusData(const Poco::JSON::Object::Ptr &Doc);
|
||||
|
||||
bool Send(const std::string &Payload);
|
||||
bool SendRadiusAuthenticationData(const unsigned char * buffer, std::size_t size);
|
||||
bool SendRadiusAccountingData(const unsigned char * buffer, std::size_t size);
|
||||
bool Send(const std::string &Payload);
|
||||
|
||||
void OnSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
|
||||
void OnSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf);
|
||||
void OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification>& pNf);
|
||||
bool LookForUpgrade(const uint64_t UUID, uint64_t & UpgradedUUID);
|
||||
static bool ExtractBase64CompressedData(const std::string & CompressedData, std::string & UnCompressedData, uint64_t compress_sz);
|
||||
void LogException(const Poco::Exception &E);
|
||||
inline Poco::Logger & Logger() { return Logger_; }
|
||||
bool SetWebSocketTelemetryReporting(uint64_t interval, uint64_t TelemetryWebSocketTimer);
|
||||
bool SetKafkaTelemetryReporting(uint64_t interval, uint64_t TelemetryKafkaTimer);
|
||||
bool StopWebSocketTelemetry();
|
||||
bool StopKafkaTelemetry();
|
||||
inline bool GetTelemetryParameters(bool & Reporting, uint64_t & Interval,
|
||||
uint64_t & WebSocketTimer, uint64_t & KafkaTimer,
|
||||
uint64_t &WebSocketCount, uint64_t & KafkaCount,
|
||||
uint64_t &WebSocketPackets,
|
||||
uint64_t &KafkaPackets ) const {
|
||||
Reporting = TelemetryReporting_;
|
||||
WebSocketTimer = TelemetryWebSocketTimer_;
|
||||
KafkaTimer = TelemetryKafkaTimer_;
|
||||
WebSocketCount = TelemetryWebSocketRefCount_;
|
||||
KafkaCount = TelemetryKafkaRefCount_;
|
||||
Interval = TelemetryInterval_;
|
||||
WebSocketPackets = TelemetryWebSocketPackets_;
|
||||
KafkaPackets = TelemetryKafkaPackets_;
|
||||
return true;
|
||||
}
|
||||
bool SendRadiusAuthenticationData(const unsigned char * buffer, std::size_t size);
|
||||
bool SendRadiusAccountingData(const unsigned char * buffer, std::size_t size);
|
||||
bool SendRadiusCoAData(const unsigned char * buffer, std::size_t size);
|
||||
|
||||
private:
|
||||
std::recursive_mutex Mutex_;
|
||||
Poco::Logger &Logger_;
|
||||
Poco::Net::StreamSocket Socket_;
|
||||
Poco::Net::SocketReactor & Reactor_;
|
||||
std::unique_ptr<Poco::Net::WebSocket> WS_;
|
||||
std::string SerialNumber_;
|
||||
uint64_t SerialNumberInt_=0;
|
||||
std::string Compatible_;
|
||||
std::shared_ptr<DeviceRegistry::ConnectionEntry> Conn_;
|
||||
bool Registered_ = false ;
|
||||
std::string CId_;
|
||||
std::string CN_;
|
||||
GWObjects::CertificateValidation CertValidation_ = GWObjects::CertificateValidation::NO_CERTIFICATE;
|
||||
uint64_t Errors_=0;
|
||||
bool Connected_=false;
|
||||
uint64_t ConnectionId_=0;
|
||||
Poco::Net::IPAddress PeerAddress_;
|
||||
mutable std::atomic_bool TelemetryReporting_ = false;
|
||||
mutable uint64_t TelemetryWebSocketRefCount_ = 0;
|
||||
mutable uint64_t TelemetryKafkaRefCount_ = 0;
|
||||
mutable uint64_t TelemetryWebSocketTimer_ = 0;
|
||||
mutable uint64_t TelemetryKafkaTimer_ = 0 ;
|
||||
mutable uint64_t TelemetryInterval_ = 0;
|
||||
mutable uint64_t TelemetryWebSocketPackets_=0;
|
||||
mutable uint64_t TelemetryKafkaPackets_=0;
|
||||
void OnSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
|
||||
void OnSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf);
|
||||
void OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification>& pNf);
|
||||
bool LookForUpgrade(const uint64_t UUID, uint64_t & UpgradedUUID);
|
||||
static bool ExtractBase64CompressedData(const std::string & CompressedData, std::string & UnCompressedData, uint64_t compress_sz);
|
||||
void LogException(const Poco::Exception &E);
|
||||
inline Poco::Logger & Logger() { return Logger_; }
|
||||
bool SetWebSocketTelemetryReporting(uint64_t interval, uint64_t TelemetryWebSocketTimer);
|
||||
bool SetKafkaTelemetryReporting(uint64_t interval, uint64_t TelemetryKafkaTimer);
|
||||
bool StopWebSocketTelemetry();
|
||||
bool StopKafkaTelemetry();
|
||||
inline bool GetTelemetryParameters(bool & Reporting, uint64_t & Interval,
|
||||
uint64_t & WebSocketTimer, uint64_t & KafkaTimer,
|
||||
uint64_t &WebSocketCount, uint64_t & KafkaCount,
|
||||
uint64_t &WebSocketPackets,
|
||||
uint64_t &KafkaPackets ) const {
|
||||
Reporting = TelemetryReporting_;
|
||||
WebSocketTimer = TelemetryWebSocketTimer_;
|
||||
KafkaTimer = TelemetryKafkaTimer_;
|
||||
WebSocketCount = TelemetryWebSocketRefCount_;
|
||||
KafkaCount = TelemetryKafkaRefCount_;
|
||||
Interval = TelemetryInterval_;
|
||||
WebSocketPackets = TelemetryWebSocketPackets_;
|
||||
KafkaPackets = TelemetryKafkaPackets_;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CompleteStartup();
|
||||
bool StartTelemetry();
|
||||
bool StopTelemetry();
|
||||
void UpdateCounts();
|
||||
};
|
||||
private:
|
||||
std::recursive_mutex Mutex_;
|
||||
Poco::Logger &Logger_;
|
||||
Poco::Net::StreamSocket Socket_;
|
||||
Poco::Net::SocketReactor & Reactor_;
|
||||
std::unique_ptr<Poco::Net::WebSocket> WS_;
|
||||
std::string SerialNumber_;
|
||||
uint64_t SerialNumberInt_=0;
|
||||
std::string Compatible_;
|
||||
std::shared_ptr<DeviceRegistry::ConnectionEntry> Conn_;
|
||||
volatile bool Registered_ = false ;
|
||||
std::string CId_;
|
||||
std::string CN_;
|
||||
GWObjects::CertificateValidation CertValidation_ = GWObjects::CertificateValidation::NO_CERTIFICATE;
|
||||
uint64_t Errors_=0;
|
||||
volatile bool Connected_=false;
|
||||
uint64_t ConnectionId_=0;
|
||||
Poco::Net::IPAddress PeerAddress_;
|
||||
volatile std::atomic_bool TelemetryReporting_ = false;
|
||||
volatile uint64_t TelemetryWebSocketRefCount_ = 0;
|
||||
volatile uint64_t TelemetryKafkaRefCount_ = 0;
|
||||
uint64_t TelemetryWebSocketTimer_ = 0;
|
||||
uint64_t TelemetryKafkaTimer_ = 0 ;
|
||||
uint64_t TelemetryInterval_ = 0;
|
||||
volatile uint64_t TelemetryWebSocketPackets_=0;
|
||||
volatile uint64_t TelemetryKafkaPackets_=0;
|
||||
|
||||
void CompleteStartup();
|
||||
bool StartTelemetry();
|
||||
bool StopTelemetry();
|
||||
void UpdateCounts();
|
||||
};
|
||||
|
||||
}
|
||||
@@ -29,7 +29,8 @@ namespace OpenWifi {
|
||||
auto NewThread = std::make_unique<Poco::Thread>();
|
||||
NewThread->setStackSize(2000000);
|
||||
NewThread->start(*NewReactor);
|
||||
NewThread->setName(ThreadNamePrefix + "#" + std::to_string(i));
|
||||
std::string ThreadName{ThreadNamePrefix + "#" + std::to_string(i)};
|
||||
Utils::SetThreadName(*NewThread,ThreadName.c_str());
|
||||
Reactors_.emplace_back(std::move(NewReactor));
|
||||
Threads_.emplace_back(std::move(NewThread));
|
||||
}
|
||||
|
||||
@@ -8,75 +8,77 @@
|
||||
|
||||
#include "Poco/Net/HTTPHeaderStream.h"
|
||||
#include "Poco/JSON/Array.h"
|
||||
#include "Poco/Net/Context.h"
|
||||
|
||||
#include "ConfigurationCache.h"
|
||||
#include "TelemetryStream.h"
|
||||
#include "WS_Server.h"
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
bool WebSocketServer::ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate) {
|
||||
if(IsCertOk()) {
|
||||
Logger().debug(fmt::format("CERTIFICATE({}): issuer='{}' cn='{}'", ConnectionId, Certificate.issuerName(),Certificate.commonName()));
|
||||
if(!Certificate.issuedBy(*IssuerCert_)) {
|
||||
Logger().debug(fmt::format("CERTIFICATE({}): issuer mismatch. Local='{}' Incoming='{}'", ConnectionId, IssuerCert_->issuerName(), Certificate.issuerName()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
bool WebSocketServer::ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate) {
|
||||
if(IsCertOk()) {
|
||||
Logger().debug(fmt::format("CERTIFICATE({}): issuer='{}' cn='{}'", ConnectionId, Certificate.issuerName(),Certificate.commonName()));
|
||||
if(!Certificate.issuedBy(*IssuerCert_)) {
|
||||
Logger().debug(fmt::format("CERTIFICATE({}): issuer mismatch. Local='{}' Incoming='{}'", ConnectionId, IssuerCert_->issuerName(), Certificate.issuerName()));
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int WebSocketServer::Start() {
|
||||
// ReactorPool_.Start("DeviceReactorPool_");
|
||||
for(const auto & Svr : ConfigServersList_ ) {
|
||||
Logger().notice( fmt::format("Starting: {}:{} Keyfile:{} CertFile: {}",
|
||||
Svr.Address(),
|
||||
Svr.Port(),
|
||||
Svr.KeyFile(),Svr.CertFile()));
|
||||
|
||||
Svr.LogCert(Logger());
|
||||
if(!Svr.RootCA().empty())
|
||||
Svr.LogCas(Logger());
|
||||
|
||||
auto Sock{Svr.CreateSecureSocket(Logger())};
|
||||
|
||||
if(!IsCertOk()) {
|
||||
IssuerCert_ = std::make_unique<Poco::Crypto::X509Certificate>(Svr.IssuerCertFile());
|
||||
Logger().information( fmt::format("Certificate Issuer Name:{}",IssuerCert_->issuerName()));
|
||||
}
|
||||
auto NewSocketAcceptor = std::make_unique<ws_server_reactor_type_t>(Sock, Reactor_); // , 2 /*Poco::Environment::processorCount()*2) */ );
|
||||
Acceptors_.push_back(std::move(NewSocketAcceptor));
|
||||
}
|
||||
|
||||
int WebSocketServer::Start() {
|
||||
// ReactorPool_.Start("DeviceReactorPool_");
|
||||
for(const auto & Svr : ConfigServersList_ ) {
|
||||
Logger().notice( fmt::format("Starting: {}:{} Keyfile:{} CertFile: {}",
|
||||
Svr.Address(),
|
||||
Svr.Port(),
|
||||
Svr.KeyFile(),Svr.CertFile()));
|
||||
|
||||
Svr.LogCert(Logger());
|
||||
if(!Svr.RootCA().empty())
|
||||
Svr.LogCas(Logger());
|
||||
|
||||
auto Sock{Svr.CreateSecureSocket(Logger())};
|
||||
|
||||
if(!IsCertOk()) {
|
||||
IssuerCert_ = std::make_unique<Poco::Crypto::X509Certificate>(Svr.IssuerCertFile());
|
||||
Logger().information( fmt::format("Certificate Issuer Name:{}",IssuerCert_->issuerName()));
|
||||
}
|
||||
auto NewSocketAcceptor = std::make_unique<ws_server_reactor_type_t>(Sock, Reactor_); // , 2 /*Poco::Environment::processorCount()*2) */ );
|
||||
Acceptors_.push_back(std::move(NewSocketAcceptor));
|
||||
}
|
||||
|
||||
auto ProvString = MicroService::instance().ConfigGetString("autoprovisioning.process","default");
|
||||
if(ProvString!="default") {
|
||||
auto Tokens = Poco::StringTokenizer(ProvString, ",");
|
||||
for (const auto &i : Tokens) {
|
||||
if (i == "prov")
|
||||
LookAtProvisioning_ = true;
|
||||
else
|
||||
UseDefaultConfig_ = true;
|
||||
}
|
||||
} else {
|
||||
UseDefaultConfig_ = true;
|
||||
auto ProvString = MicroService::instance().ConfigGetString("autoprovisioning.process","default");
|
||||
if(ProvString!="default") {
|
||||
auto Tokens = Poco::StringTokenizer(ProvString, ",");
|
||||
for (const auto &i : Tokens) {
|
||||
if (i == "prov")
|
||||
LookAtProvisioning_ = true;
|
||||
else
|
||||
UseDefaultConfig_ = true;
|
||||
}
|
||||
} else {
|
||||
UseDefaultConfig_ = true;
|
||||
}
|
||||
|
||||
SimulatorId_ = MicroService::instance().ConfigGetString("simulatorid","");
|
||||
SimulatorEnabled_ = !SimulatorId_.empty();
|
||||
SimulatorId_ = MicroService::instance().ConfigGetString("simulatorid","");
|
||||
SimulatorEnabled_ = !SimulatorId_.empty();
|
||||
|
||||
ReactorThread_.setName("WS-DEVICE-REACTOR");
|
||||
ReactorThread_.setStackSize(3000000);
|
||||
ReactorThread_.start(Reactor_);
|
||||
ReactorThread_.setStackSize(3000000);
|
||||
ReactorThread_.start(Reactor_);
|
||||
Utils::SetThreadName(ReactorThread_,"device-reactor");
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WebSocketServer::Stop() {
|
||||
Logger().notice("Stopping reactors...");
|
||||
// ReactorPool_.Stop();
|
||||
Reactor_.stop();
|
||||
ReactorThread_.join();
|
||||
}
|
||||
void WebSocketServer::Stop() {
|
||||
Logger().notice("Stopping reactors...");
|
||||
// ReactorPool_.Stop();
|
||||
Reactor_.stop();
|
||||
ReactorThread_.join();
|
||||
}
|
||||
|
||||
} //namespace
|
||||
} //namespace
|
||||
@@ -25,53 +25,52 @@
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class WebSocketServer : public SubSystemServer {
|
||||
public:
|
||||
static auto instance() {
|
||||
static auto instance_ = new WebSocketServer;
|
||||
return instance_;
|
||||
}
|
||||
class WebSocketServer : public SubSystemServer {
|
||||
public:
|
||||
static auto instance() {
|
||||
static auto instance_ = new WebSocketServer;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
bool IsCertOk() { return IssuerCert_!= nullptr; }
|
||||
bool ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate);
|
||||
// Poco::Net::SocketReactor & GetNextReactor() { return ReactorPool_.NextReactor(); }
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
bool IsCertOk() { return IssuerCert_!= nullptr; }
|
||||
bool ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate);
|
||||
// Poco::Net::SocketReactor & GetNextReactor() { return ReactorPool_.NextReactor(); }
|
||||
|
||||
inline bool IsSimSerialNumber(const std::string & SerialNumber) const {
|
||||
return IsSim(SerialNumber) && SerialNumber == SimulatorId_;
|
||||
}
|
||||
inline bool IsSimSerialNumber(const std::string & SerialNumber) const {
|
||||
return IsSim(SerialNumber) && SerialNumber == SimulatorId_;
|
||||
}
|
||||
|
||||
inline static bool IsSim(const std::string & SerialNumber) {
|
||||
return SerialNumber.substr(0,6) == "53494d";
|
||||
}
|
||||
inline static bool IsSim(const std::string & SerialNumber) {
|
||||
return SerialNumber.substr(0,6) == "53494d";
|
||||
}
|
||||
|
||||
inline bool IsSimEnabled() const {
|
||||
return SimulatorEnabled_;
|
||||
}
|
||||
inline bool IsSimEnabled() const {
|
||||
return SimulatorEnabled_;
|
||||
}
|
||||
|
||||
inline bool UseProvisioning() const { return LookAtProvisioning_; }
|
||||
inline bool UseDefaults() const { return UseDefaultConfig_; }
|
||||
inline bool UseProvisioning() const { return LookAtProvisioning_; }
|
||||
inline bool UseDefaults() const { return UseDefaultConfig_; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<Poco::Crypto::X509Certificate> IssuerCert_;
|
||||
// typedef std::unique_ptr<Poco::Net::ParallelSocketAcceptor<WSConnection, Poco::Net::SocketReactor>> ws_server_reactor_type_t;
|
||||
typedef Poco::Net::SocketAcceptor<WSConnection> ws_server_reactor_type_t;
|
||||
std::vector<std::unique_ptr<ws_server_reactor_type_t>> Acceptors_;
|
||||
Poco::Net::SocketReactor Reactor_;
|
||||
Poco::Thread ReactorThread_;
|
||||
// ReactorPool ReactorPool_;
|
||||
std::string SimulatorId_;
|
||||
bool LookAtProvisioning_ = false;
|
||||
bool UseDefaultConfig_ = true;
|
||||
bool SimulatorEnabled_=false;
|
||||
private:
|
||||
std::unique_ptr<Poco::Crypto::X509Certificate> IssuerCert_;
|
||||
// typedef std::unique_ptr<Poco::Net::ParallelSocketAcceptor<WSConnection, Poco::Net::SocketReactor>> ws_server_reactor_type_t;
|
||||
typedef Poco::Net::SocketAcceptor<WSConnection> ws_server_reactor_type_t;
|
||||
std::vector<std::unique_ptr<ws_server_reactor_type_t>> Acceptors_;
|
||||
Poco::Net::SocketReactor Reactor_;
|
||||
Poco::Thread ReactorThread_;
|
||||
std::string SimulatorId_;
|
||||
bool LookAtProvisioning_ = false;
|
||||
bool UseDefaultConfig_ = true;
|
||||
bool SimulatorEnabled_=false;
|
||||
|
||||
WebSocketServer() noexcept:
|
||||
SubSystemServer("WebSocketServer", "WS-SVR", "ucentral.websocket") {
|
||||
WebSocketServer() noexcept:
|
||||
SubSystemServer("WebSocketServer", "WS-SVR", "ucentral.websocket") {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
inline auto WebSocketServer() { return WebSocketServer::instance(); }
|
||||
inline auto WebSocketServer() { return WebSocketServer::instance(); }
|
||||
|
||||
} //namespace
|
||||
} //namespace
|
||||
@@ -2610,186 +2610,206 @@ static json DefaultUCentralSchema = R"(
|
||||
}
|
||||
)"_json;
|
||||
|
||||
class custom_error_handler : public nlohmann::json_schema::basic_error_handler
|
||||
{
|
||||
void error(const nlohmann::json_pointer<nlohmann::basic_json<>> &pointer, const json &instance,
|
||||
const std::string &message) override
|
||||
{
|
||||
nlohmann::json_schema::basic_error_handler::error(pointer, instance, message);
|
||||
std::cout << "ERROR: '" << pointer << "' - '" << instance << "': " << message << "\n";
|
||||
}
|
||||
};
|
||||
class custom_error_handler : public nlohmann::json_schema::basic_error_handler
|
||||
{
|
||||
void error(const nlohmann::json_pointer<nlohmann::basic_json<>> &pointer, const json &instance,
|
||||
const std::string &message) override
|
||||
{
|
||||
nlohmann::json_schema::basic_error_handler::error(pointer, instance, message);
|
||||
std::cout << "ERROR: '" << pointer << "' - '" << instance << "': " << message << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
void ConfigurationValidator::Init() {
|
||||
if(Initialized_)
|
||||
return;
|
||||
std::string GitSchema;
|
||||
void ConfigurationValidator::Init() {
|
||||
if(Initialized_)
|
||||
return;
|
||||
|
||||
if(MicroService::instance().ConfigGetBool("ucentral.datamodel.internal",true)) {
|
||||
RootSchema_ = DefaultUCentralSchema;
|
||||
Logger().information("Using uCentral validation from built-in default.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
auto GitURI = MicroService::instance().ConfigGetString("ucentral.datamodel.uri",GitUCentralJSONSchemaFile);
|
||||
if(Utils::wgets(GitURI, GitSchema)) {
|
||||
RootSchema_ = json::parse(GitSchema);
|
||||
Logger().information("Using uCentral validation schema from GIT.");
|
||||
} else {
|
||||
std::string FileName{ MicroService::instance().DataDir() + "/ucentral.schema.json" };
|
||||
std::ifstream input(FileName);
|
||||
std::stringstream schema_file;
|
||||
schema_file << input.rdbuf();
|
||||
input.close();
|
||||
RootSchema_ = json::parse(schema_file.str());
|
||||
Logger().information("Using uCentral validation schema from local file.");
|
||||
std::string GitSchema;
|
||||
if(MicroService::instance().ConfigGetBool("ucentral.datamodel.internal",true)) {
|
||||
RootSchema_ = DefaultUCentralSchema;
|
||||
Logger().information("Using uCentral validation from built-in default.");
|
||||
Initialized_ = Working_ = true;
|
||||
return;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
RootSchema_ = DefaultUCentralSchema;
|
||||
Logger().information("Using uCentral validation from built-in default.");
|
||||
}
|
||||
Initialized_ = Working_ = true;
|
||||
}
|
||||
|
||||
int ConfigurationValidator::Start() {
|
||||
Init();
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
auto GitURI = MicroService::instance().ConfigGetString("ucentral.datamodel.uri",GitUCentralJSONSchemaFile);
|
||||
if(Utils::wgets(GitURI, GitSchema)) {
|
||||
RootSchema_ = json::parse(GitSchema);
|
||||
Logger().information("Using uCentral validation schema from GIT.");
|
||||
} else {
|
||||
std::string FileName{ MicroService::instance().DataDir() + "/ucentral.schema.json" };
|
||||
std::ifstream input(FileName);
|
||||
std::stringstream schema_file;
|
||||
schema_file << input.rdbuf();
|
||||
input.close();
|
||||
RootSchema_ = json::parse(schema_file.str());
|
||||
Logger().information("Using uCentral validation schema from local file.");
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
RootSchema_ = DefaultUCentralSchema;
|
||||
Logger().information("Using uCentral validation from built-in default.");
|
||||
}
|
||||
Initialized_ = Working_ = true;
|
||||
}
|
||||
|
||||
void ConfigurationValidator::Stop() {
|
||||
|
||||
}
|
||||
|
||||
static inline bool IsIPv4(const std::string &value) {
|
||||
Poco::Net::IPAddress A;
|
||||
return ((Poco::Net::IPAddress::tryParse(value,A) && A.family()==Poco::Net::IPAddress::IPv4));
|
||||
}
|
||||
|
||||
static inline bool IsIPv6(const std::string &value) {
|
||||
Poco::Net::IPAddress A;
|
||||
return ((Poco::Net::IPAddress::tryParse(value,A) && A.family()==Poco::Net::IPAddress::IPv6));
|
||||
}
|
||||
|
||||
static inline bool IsIP(const std::string &value) {
|
||||
return IsIPv4(value) || IsIPv6(value);
|
||||
}
|
||||
|
||||
static inline bool IsCIDRv6(const std::string &value) {
|
||||
auto Tokens = Poco::StringTokenizer(value,"/");
|
||||
if(Tokens.count()==2 && IsIPv6(Tokens[0])) {
|
||||
auto Mask = std::atoi(Tokens[1].c_str());
|
||||
if(Mask>=48 && Mask<=128)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool IsCIDRv4(const std::string &value) {
|
||||
auto Tokens = Poco::StringTokenizer(value,"/");
|
||||
if(Tokens.count()==2 && IsIPv4(Tokens[0])) {
|
||||
auto Mask = std::atoi(Tokens[1].c_str());
|
||||
if(Mask>=0 && Mask<=32)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool IsCIDR(const std::string &value) {
|
||||
return IsCIDRv4(value) || IsCIDRv6(value);
|
||||
}
|
||||
|
||||
void ConfigurationValidator::my_format_checker(const std::string &format, const std::string &value)
|
||||
{
|
||||
static const std::regex host_regex{"^(?=.{1,254}$)((?=[a-z0-9-]{1,63}\\.)(xn--+)?[a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,63}$"};
|
||||
static const std::regex mac_regex{"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"};
|
||||
static const std::regex uc_timeout_regex{"^[0-9]+[dmshw]$"};
|
||||
static const std::regex b64_regex("^[a-zA-Z0-9\\+/]*={0,3}$");
|
||||
|
||||
if(format == "uc-cidr4") {
|
||||
if(IsCIDRv4(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid CIDR IPv4: should be something like 192.168.0.0/16.");
|
||||
} else if(format == "uc-cidr6") {
|
||||
if(IsCIDRv6(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid CIDR IPv6: should be something like 2e60:3500::/64.");
|
||||
} else if(format=="uc-cidr") {
|
||||
if(IsCIDR(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid CIDR IPv6/IPv4: should be something like 2e60:3500::/64.");
|
||||
} else if(format == "uc-mac") {
|
||||
if(std::regex_match(value,mac_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid MAC: should be something like 11:22:33:44:55:66");
|
||||
} else if(format == "uc-timeout") {
|
||||
if(std::regex_match(value,uc_timeout_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a proper timeout value: 6d, 300m, 24h, 84000s, infinite");
|
||||
} else if(format == "uc-host") {
|
||||
if(IsIP(value))
|
||||
return;
|
||||
if(std::regex_match(value,host_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a proper FQDN.");
|
||||
} else if(format == "fqdn") {
|
||||
if(std::regex_match(value,host_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a proper FQDN.");
|
||||
} else if(format == "uc-base64") {
|
||||
std::string s{value};
|
||||
Poco::trimInPlace(s);
|
||||
if( (s.size() %4 ==0) && std::regex_match(s,b64_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a base64 encoded value.");
|
||||
} else if(format == "uri") {
|
||||
try {
|
||||
Poco::URI uri(value);
|
||||
return;
|
||||
} catch (...) {
|
||||
}
|
||||
throw std::invalid_argument(value + " is not a valid URI: should be something like https://hello.world.com.");
|
||||
} else if(format == "ip") {
|
||||
if (IsIP(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid IP address.");
|
||||
} else {
|
||||
nlohmann::json_schema::default_string_format_check(format,value);
|
||||
}
|
||||
}
|
||||
|
||||
bool ConfigurationValidator::Validate(const std::string &C, std::string &Error) {
|
||||
if(Working_) {
|
||||
try {
|
||||
auto Doc = json::parse(C);
|
||||
custom_error_handler CE;
|
||||
json_validator Validator(nullptr, my_format_checker);
|
||||
Validator.set_root_schema(RootSchema_);
|
||||
Validator.validate(Doc,CE);
|
||||
return true;
|
||||
} catch (const std::invalid_argument &E) {
|
||||
std::cout << "1 Validation failed, here is why: " << E.what() << "\n";
|
||||
Error = E.what();
|
||||
return false;
|
||||
} catch (const std::logic_error &E) {
|
||||
std::cout << "2 Validation failed, here is why: " << E.what() << "\n";
|
||||
Error = E.what();
|
||||
return false;
|
||||
} catch(const std::exception &E) {
|
||||
Error = E.what();
|
||||
std::cout << "3 Validation failed, here is why: " << E.what() << "\n";
|
||||
return false;
|
||||
} catch(...) {
|
||||
std::cout << "4 Some kind of bullshit exception..." << std::endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConfigurationValidator::reinitialize([[maybe_unused]] Poco::Util::Application &self) {
|
||||
Logger().information("Reinitializing.");
|
||||
Working_ = Initialized_ = false;
|
||||
Init();
|
||||
}
|
||||
int ConfigurationValidator::Start() {
|
||||
Init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ConfigurationValidator::Stop() {
|
||||
|
||||
}
|
||||
|
||||
static inline bool IsIPv4(const std::string &value) {
|
||||
Poco::Net::IPAddress A;
|
||||
return ((Poco::Net::IPAddress::tryParse(value,A) && A.family()==Poco::Net::IPAddress::IPv4));
|
||||
}
|
||||
|
||||
static inline bool IsIPv6(const std::string &value) {
|
||||
Poco::Net::IPAddress A;
|
||||
return ((Poco::Net::IPAddress::tryParse(value,A) && A.family()==Poco::Net::IPAddress::IPv6));
|
||||
}
|
||||
|
||||
static inline bool IsIP(const std::string &value) {
|
||||
return IsIPv4(value) || IsIPv6(value);
|
||||
}
|
||||
|
||||
static inline bool IsCIDRv6(const std::string &value) {
|
||||
auto Tokens = Poco::StringTokenizer(value,"/");
|
||||
if(Tokens.count()==2 && IsIPv6(Tokens[0])) {
|
||||
auto Mask = std::atoi(Tokens[1].c_str());
|
||||
if(Mask>=48 && Mask<=128)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool IsCIDRv4(const std::string &value) {
|
||||
auto Tokens = Poco::StringTokenizer(value,"/");
|
||||
if(Tokens.count()==2 && IsIPv4(Tokens[0])) {
|
||||
auto Mask = std::atoi(Tokens[1].c_str());
|
||||
if(Mask>=0 && Mask<=32)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool IsCIDR(const std::string &value) {
|
||||
return IsCIDRv4(value) || IsCIDRv6(value);
|
||||
}
|
||||
|
||||
static inline bool IsPortRangeIsValid(const std::string &r) {
|
||||
const auto ports = Poco::StringTokenizer("-",r,Poco::StringTokenizer::TOK_TRIM);
|
||||
|
||||
for(const auto &port:ports) {
|
||||
uint32_t port_num = std::stoul(port);
|
||||
if(port_num==0 || port_num>65535)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConfigurationValidator::my_format_checker(const std::string &format, const std::string &value)
|
||||
{
|
||||
static const std::regex host_regex{"^(?=.{1,254}$)((?=[a-z0-9-]{1,63}\\.)(xn--+)?[a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,63}$"};
|
||||
static const std::regex mac_regex{"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"};
|
||||
static const std::regex uc_timeout_regex{"^[0-9]+[dmshw]$"};
|
||||
static const std::regex b64_regex("^[a-zA-Z0-9\\+/]*={0,3}$");
|
||||
|
||||
if(format == "uc-cidr4") {
|
||||
if(IsCIDRv4(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid CIDR IPv4: should be something like 192.168.0.0/16.");
|
||||
} else if(format == "uc-cidr6") {
|
||||
if(IsCIDRv6(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid CIDR IPv6: should be something like 2e60:3500::/64.");
|
||||
} else if(format=="uc-cidr") {
|
||||
if(IsCIDR(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid CIDR IPv6/IPv4: should be something like 2e60:3500::/64.");
|
||||
} else if(format == "uc-mac") {
|
||||
if(std::regex_match(value,mac_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid MAC: should be something like 11:22:33:44:55:66");
|
||||
} else if(format == "uc-timeout") {
|
||||
if(std::regex_match(value,uc_timeout_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a proper timeout value: 6d, 300m, 24h, 84000s, infinite");
|
||||
} else if(format == "uc-host") {
|
||||
if(IsIP(value))
|
||||
return;
|
||||
if(std::regex_match(value,host_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a proper FQDN.");
|
||||
} else if(format == "fqdn") {
|
||||
if(std::regex_match(value,host_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a proper FQDN.");
|
||||
} else if(format == "uc-base64") {
|
||||
std::string s{value};
|
||||
Poco::trimInPlace(s);
|
||||
if( (s.size() %4 ==0) && std::regex_match(s,b64_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a base64 encoded value.");
|
||||
} else if(format == "uri") {
|
||||
try {
|
||||
Poco::URI uri(value);
|
||||
return;
|
||||
} catch (...) {
|
||||
}
|
||||
throw std::invalid_argument(value + " is not a valid URI: should be something like https://hello.world.com.");
|
||||
} else if(format == "uc-portrange") {
|
||||
try {
|
||||
if(IsPortRangeIsValid(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid port range: should an integer between 1-65535 or a port range like post-port.");
|
||||
} catch (...) {
|
||||
}
|
||||
throw std::invalid_argument(value + " is not a valid port range: should an integer between 1-65535 or a port range like post-port.");
|
||||
} else if(format == "ip") {
|
||||
if (IsIP(value))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid IP address.");
|
||||
} else {
|
||||
nlohmann::json_schema::default_string_format_check(format,value);
|
||||
}
|
||||
}
|
||||
|
||||
bool ConfigurationValidator::Validate(const std::string &C, std::string &Error) {
|
||||
if(Working_) {
|
||||
try {
|
||||
auto Doc = json::parse(C);
|
||||
custom_error_handler CE;
|
||||
json_validator Validator(nullptr, my_format_checker);
|
||||
Validator.set_root_schema(RootSchema_);
|
||||
Validator.validate(Doc,CE);
|
||||
return true;
|
||||
} catch (const std::invalid_argument &E) {
|
||||
std::cout << "1 Validation failed, here is why: " << E.what() << "\n";
|
||||
Error = E.what();
|
||||
return false;
|
||||
} catch (const std::logic_error &E) {
|
||||
std::cout << "2 Validation failed, here is why: " << E.what() << "\n";
|
||||
Error = E.what();
|
||||
return false;
|
||||
} catch(const std::exception &E) {
|
||||
Error = E.what();
|
||||
std::cout << "3 Validation failed, here is why: " << E.what() << "\n";
|
||||
return false;
|
||||
} catch(...) {
|
||||
std::cout << "4 Some kind of bullshit exception..." << std::endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConfigurationValidator::reinitialize([[maybe_unused]] Poco::Util::Application &self) {
|
||||
Logger().information("Reinitializing.");
|
||||
Working_ = Initialized_ = false;
|
||||
Init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@ namespace OpenWifi {
|
||||
inline uint64_t Now() { return std::time(nullptr); };
|
||||
}
|
||||
|
||||
namespace OpenWifi::Utils {
|
||||
std::vector<unsigned char> base64decode(const std::string& input);
|
||||
std::string base64encode(const unsigned char *input, uint32_t size);
|
||||
}
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
#include "Poco/Util/Application.h"
|
||||
@@ -238,6 +243,11 @@ namespace OpenWifi::RESTAPI_utils {
|
||||
Obj.set(Field,Value);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Poco::Data::BLOB &Value) {
|
||||
auto Result = Utils::base64encode((const unsigned char *)Value.rawContent(),Value.size());
|
||||
Obj.set(Field,Result);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::StringPairVec & S) {
|
||||
Poco::JSON::Array Array;
|
||||
for(const auto &i:S) {
|
||||
@@ -334,12 +344,12 @@ namespace OpenWifi::RESTAPI_utils {
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, double & Value) {
|
||||
if(Obj->has(Field) && !Obj->isNull(Field))
|
||||
Value = (double) Obj->get(Field);
|
||||
Value = (double)Obj->get(Field);
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, float & Value) {
|
||||
if(Obj->has(Field) && !Obj->isNull(Field))
|
||||
Value = (float) Obj->get(Field);
|
||||
Value = (float)Obj->get(Field);
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, bool &Value) {
|
||||
@@ -374,7 +384,14 @@ namespace OpenWifi::RESTAPI_utils {
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, uint64_t &Value) {
|
||||
if(Obj->has(Field) && !Obj->isNull(Field))
|
||||
Value = (uint64_t ) Obj->get(Field);
|
||||
Value = (uint64_t)Obj->get(Field);
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, Poco::Data::BLOB &Value) {
|
||||
if(Obj->has(Field) && !Obj->isNull(Field)) {
|
||||
auto Result = Utils::base64decode(Obj->get(Field).toString());
|
||||
Value.assignRaw((const unsigned char *)&Result[0],Result.size());
|
||||
}
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, Types::StringPairVec &Vec) {
|
||||
@@ -643,6 +660,27 @@ namespace OpenWifi::RESTAPI_utils {
|
||||
|
||||
namespace OpenWifi::Utils {
|
||||
|
||||
inline void SetThreadName(const char *name) {
|
||||
#ifdef __linux__
|
||||
Poco::Thread::current()->setName(name);
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
Poco::Thread::current()->setName(name);
|
||||
pthread_setname_np(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void SetThreadName(Poco::Thread &thr, const char *name) {
|
||||
#ifdef __linux__
|
||||
thr.setName(name);
|
||||
pthread_setname_np(thr.tid(), name);
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
thr.setName(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
enum MediaTypeEncodings {
|
||||
PLAIN,
|
||||
BINARY,
|
||||
@@ -1167,6 +1205,7 @@ namespace OpenWifi {
|
||||
static const std::string uSERVICE_SUBCRIBER{ "owsub"};
|
||||
static const std::string uSERVICE_INSTALLER{ "owinst"};
|
||||
static const std::string uSERVICE_ANALYTICS{ "owanalytics"};
|
||||
static const std::string uSERVICE_OWRRM{ "owrrm"};
|
||||
|
||||
class ConfigurationEntry {
|
||||
public:
|
||||
@@ -1315,7 +1354,7 @@ namespace OpenWifi {
|
||||
inline void Start();
|
||||
inline void Stop();
|
||||
private:
|
||||
std::atomic_bool Running_ = false;
|
||||
mutable std::atomic_bool Running_ = false;
|
||||
Poco::Thread Thread_;
|
||||
};
|
||||
|
||||
@@ -1846,7 +1885,8 @@ namespace OpenWifi {
|
||||
Request = &RequestIn;
|
||||
Response = &ResponseIn;
|
||||
|
||||
Poco::Thread::current()->setName("WebServerThread_" + std::to_string(TransactionId_));
|
||||
std::string th_name = "restsvr_" + std::to_string(TransactionId_);
|
||||
Utils::SetThreadName(th_name.c_str());
|
||||
|
||||
if(Request->getContentLength()>0) {
|
||||
if(Request->getContentType().find("application/json")!=std::string::npos) {
|
||||
@@ -1895,36 +1935,32 @@ namespace OpenWifi {
|
||||
[[nodiscard]] inline bool NeedAdditionalInfo() const { return QB_.AdditionalInfo; }
|
||||
[[nodiscard]] inline const std::vector<std::string> & SelectedRecords() const { return QB_.Select; }
|
||||
|
||||
/* [[nodiscard]] inline const Poco::JSON::Object::Ptr ParseStream() {
|
||||
return IncomingParser_.parse(Request->stream()).extract<Poco::JSON::Object::Ptr>();
|
||||
}
|
||||
*/
|
||||
inline static bool ParseBindings(const std::string & Request, const std::list<std::string> & EndPoints, BindingMap &bindings) {
|
||||
bindings.clear();
|
||||
auto PathItems = Poco::StringTokenizer(Request, "/");
|
||||
|
||||
inline static bool ParseBindings(const std::string & Request, const std::list<std::string> & EndPoints, BindingMap &bindings) {
|
||||
bindings.clear();
|
||||
std::vector<std::string> PathItems = Utils::Split(Request, '/');
|
||||
for(const auto &EndPoint:EndPoints) {
|
||||
auto ParamItems = Poco::StringTokenizer(EndPoint, "/");
|
||||
if (PathItems.count() != ParamItems.count())
|
||||
continue;
|
||||
|
||||
for(const auto &EndPoint:EndPoints) {
|
||||
std::vector<std::string> ParamItems = Utils::Split(EndPoint, '/');
|
||||
if (PathItems.size() != ParamItems.size())
|
||||
continue;
|
||||
|
||||
bool Matched = true;
|
||||
for (size_t i = 0; i != PathItems.size() && Matched; i++) {
|
||||
if (PathItems[i] != ParamItems[i]) {
|
||||
if (ParamItems[i][0] == '{') {
|
||||
auto ParamName = ParamItems[i].substr(1, ParamItems[i].size() - 2);
|
||||
bindings[Poco::toLower(ParamName)] = PathItems[i];
|
||||
} else {
|
||||
Matched = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(Matched)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool Matched = true;
|
||||
for (size_t i = 0; i < PathItems.count(); i++) {
|
||||
if (PathItems[i] != ParamItems[i]) {
|
||||
if (ParamItems[i][0] == '{') {
|
||||
auto ParamName = ParamItems[i].substr(1, ParamItems[i].size() - 2);
|
||||
bindings[Poco::toLower(ParamName)] = PathItems[i];
|
||||
} else {
|
||||
Matched = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(Matched)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void PrintBindings() {
|
||||
for (const auto &[key, value] : Bindings_)
|
||||
@@ -2045,6 +2081,17 @@ namespace OpenWifi {
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool AssignIfPresent(const Poco::JSON::Object::Ptr &O, const std::string &Field, Poco::Data::BLOB &Value) {
|
||||
if(O->has(Field)) {
|
||||
std::string Content = O->get(Field).toString();
|
||||
auto DecodedBlob = Utils::base64decode(Content);
|
||||
Value.assignRaw((const unsigned char *)&DecodedBlob[0],DecodedBlob.size());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template <typename T> bool AssignIfPresent(const Poco::JSON::Object::Ptr &O, const std::string &Field, const T &value, T & assignee) {
|
||||
if(O->has(Field)) {
|
||||
assignee = value;
|
||||
@@ -2582,7 +2629,7 @@ namespace OpenWifi {
|
||||
private:
|
||||
std::recursive_mutex Mutex_;
|
||||
Poco::Thread Worker_;
|
||||
std::atomic_bool Running_=false;
|
||||
mutable std::atomic_bool Running_=false;
|
||||
Poco::NotificationQueue Queue_;
|
||||
};
|
||||
|
||||
@@ -2608,7 +2655,7 @@ namespace OpenWifi {
|
||||
private:
|
||||
std::recursive_mutex Mutex_;
|
||||
Poco::Thread Worker_;
|
||||
std::atomic_bool Running_=false;
|
||||
mutable std::atomic_bool Running_=false;
|
||||
};
|
||||
|
||||
class KafkaDispatcher : public Poco::Runnable {
|
||||
@@ -2665,6 +2712,7 @@ namespace OpenWifi {
|
||||
|
||||
inline void run() override {
|
||||
Poco::AutoPtr<Poco::Notification> Note(Queue_.waitDequeueNotification());
|
||||
Utils::SetThreadName("kafka-dispatch");
|
||||
while(Note && Running_) {
|
||||
auto Msg = dynamic_cast<KafkaMessage*>(Note.get());
|
||||
if(Msg!= nullptr) {
|
||||
@@ -2690,7 +2738,7 @@ namespace OpenWifi {
|
||||
std::recursive_mutex Mutex_;
|
||||
Types::NotifyTable Notifiers_;
|
||||
Poco::Thread Worker_;
|
||||
std::atomic_bool Running_=false;
|
||||
mutable std::atomic_bool Running_=false;
|
||||
uint64_t FunctionId_=1;
|
||||
Poco::NotificationQueue Queue_;
|
||||
};
|
||||
@@ -2885,6 +2933,7 @@ namespace OpenWifi {
|
||||
|
||||
void handleRequest(Poco::Net::HTTPServerRequest& Request, Poco::Net::HTTPServerResponse& Response) override
|
||||
{
|
||||
Utils::SetThreadName("alb-request");
|
||||
try {
|
||||
if((id_ % 100) == 0) {
|
||||
Logger_.debug(fmt::format("ALB-REQUEST({}): ALB Request {}.",
|
||||
@@ -2953,7 +3002,7 @@ namespace OpenWifi {
|
||||
std::unique_ptr<Poco::Net::HTTPServer> Server_;
|
||||
std::unique_ptr<Poco::Net::ServerSocket> Socket_;
|
||||
int Port_ = 0;
|
||||
std::atomic_bool Running_=false;
|
||||
mutable std::atomic_bool Running_=false;
|
||||
};
|
||||
|
||||
inline auto ALBHealthCheckServer() { return ALBHealthCheckServer::instance(); }
|
||||
@@ -2985,7 +3034,7 @@ namespace OpenWifi {
|
||||
|
||||
inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) {
|
||||
RESTAPIHandler::BindingMap Bindings;
|
||||
Poco::Thread::current()->setName(fmt::format("RESTAPI_ExtServer_{}",Id));
|
||||
Utils::SetThreadName(fmt::format("rest_ext_{}",Id).c_str());
|
||||
return RESTAPI_ExtRouter(Path, Bindings, Logger(), Server_, Id);
|
||||
}
|
||||
|
||||
@@ -3009,7 +3058,7 @@ namespace OpenWifi {
|
||||
inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override {
|
||||
try {
|
||||
Poco::URI uri(Request.getURI());
|
||||
Poco::Thread::current()->setName(fmt::format("ExtWebServer_{}",TransactionId_));
|
||||
Utils::SetThreadName(fmt::format("rest_ext_{}",TransactionId_).c_str());
|
||||
return RESTAPI_ExtServer()->CallServer(uri.getPath(), TransactionId_++);
|
||||
} catch (...) {
|
||||
|
||||
@@ -3118,7 +3167,7 @@ namespace OpenWifi {
|
||||
|
||||
inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) {
|
||||
RESTAPIHandler::BindingMap Bindings;
|
||||
Poco::Thread::current()->setName(fmt::format("RESTAPI_IntServer_{}",Id));
|
||||
Utils::SetThreadName(fmt::format("rest_int_{}",Id).c_str());
|
||||
return RESTAPI_IntRouter(Path, Bindings, Logger(), Server_, Id);
|
||||
}
|
||||
private:
|
||||
@@ -3215,7 +3264,12 @@ namespace OpenWifi {
|
||||
return Poco::Logger::get(Name);
|
||||
}
|
||||
|
||||
static inline void Exit(int Reason);
|
||||
virtual void GetExtraConfiguration(Poco::JSON::Object & Cfg) {
|
||||
Cfg.set("additionalConfiguration",false);
|
||||
}
|
||||
|
||||
|
||||
static inline void Exit(int Reason);
|
||||
inline void BusMessageReceived(const std::string &Key, const std::string & Payload);
|
||||
inline MicroServiceMetaVec GetServices(const std::string & Type);
|
||||
inline MicroServiceMetaVec GetServices();
|
||||
@@ -3527,7 +3581,9 @@ namespace OpenWifi {
|
||||
void DaemonPostInitialization(Poco::Util::Application &self);
|
||||
|
||||
inline void MicroService::initialize(Poco::Util::Application &self) {
|
||||
// add the default services
|
||||
// Utils::SetThreadName("microservice");
|
||||
|
||||
// add the default services
|
||||
LoadConfigurationFile();
|
||||
InitializeLoggingSystem();
|
||||
|
||||
@@ -3922,6 +3978,7 @@ namespace OpenWifi {
|
||||
|
||||
inline int MicroService::main([[maybe_unused]] const ArgVec &args) {
|
||||
|
||||
// Utils::SetThreadName("main");
|
||||
MyErrorHandler ErrorHandler(*this);
|
||||
Poco::ErrorHandler::set(&ErrorHandler);
|
||||
|
||||
@@ -4037,6 +4094,7 @@ namespace OpenWifi {
|
||||
|
||||
inline void BusEventManager::run() {
|
||||
Running_ = true;
|
||||
Utils::SetThreadName("BusEventManager");
|
||||
auto Msg = MicroService::instance().MakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN);
|
||||
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS,MicroService::instance().PrivateEndPoint(),Msg, false);
|
||||
while(Running_) {
|
||||
@@ -4122,6 +4180,8 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
inline void KafkaProducer::run() {
|
||||
|
||||
Utils::SetThreadName("KafkaProducer");
|
||||
cppkafka::Configuration Config({
|
||||
{ "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") },
|
||||
{ "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") }
|
||||
@@ -4160,6 +4220,8 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
inline void KafkaConsumer::run() {
|
||||
Utils::SetThreadName("KafkaConsumer");
|
||||
|
||||
cppkafka::Configuration Config({
|
||||
{ "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") },
|
||||
{ "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") },
|
||||
@@ -4298,6 +4360,11 @@ namespace OpenWifi {
|
||||
Answer.set("certificates", Certificates);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
if(GetBoolParameter("extraConfiguration")) {
|
||||
Poco::JSON::Object Answer;
|
||||
MicroService::instance().GetExtraConfiguration(Answer);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
BadRequest(RESTAPI::Errors::InvalidCommand);
|
||||
}
|
||||
|
||||
@@ -4400,7 +4467,7 @@ namespace OpenWifi {
|
||||
Path,
|
||||
Poco::Net::HTTPMessage::HTTP_1_1);
|
||||
|
||||
Poco::Logger::get("REST-CALLER-GET").debug(fmt::format(" {}", URI.toString()));
|
||||
poco_debug(Poco::Logger::get("REST-CALLER-GET"),fmt::format(" {}", URI.toString()));
|
||||
|
||||
if(BearerToken.empty()) {
|
||||
Request.add("X-API-KEY", Svc.AccessKey);
|
||||
@@ -4458,7 +4525,7 @@ namespace OpenWifi {
|
||||
for (const auto &qp : QueryData_)
|
||||
URI.addQueryParameter(qp.first, qp.second);
|
||||
|
||||
Poco::Logger::get("REST-CALLER-PUT").debug(fmt::format("{}", URI.toString()));
|
||||
poco_debug(Poco::Logger::get("REST-CALLER-PUT"),fmt::format("{}", URI.toString()));
|
||||
|
||||
std::string Path(URI.getPathAndQuery());
|
||||
|
||||
@@ -4537,7 +4604,7 @@ namespace OpenWifi {
|
||||
for (const auto &qp : QueryData_)
|
||||
URI.addQueryParameter(qp.first, qp.second);
|
||||
|
||||
Poco::Logger::get("REST-CALLER-POST").debug(fmt::format(" {}", URI.toString()));
|
||||
poco_debug(Poco::Logger::get("REST-CALLER-POST"),fmt::format(" {}", URI.toString()));
|
||||
|
||||
std::string Path(URI.getPathAndQuery());
|
||||
|
||||
@@ -4613,7 +4680,7 @@ namespace OpenWifi {
|
||||
for (const auto &qp : QueryData_)
|
||||
URI.addQueryParameter(qp.first, qp.second);
|
||||
|
||||
Poco::Logger::get("REST-CALLER-DELETE").debug(fmt::format(" {}", URI.toString()));
|
||||
poco_debug(Poco::Logger::get("REST-CALLER-DELETE"),fmt::format(" {}", URI.toString()));
|
||||
|
||||
std::string Path(URI.getPathAndQuery());
|
||||
|
||||
@@ -4818,7 +4885,7 @@ namespace OpenWifi {
|
||||
[[nodiscard]] bool SendToUser(const std::string &userName, const std::string &Payload);
|
||||
void SendToAll(const std::string &Payload);
|
||||
private:
|
||||
std::atomic_bool Running_ = false;
|
||||
mutable std::atomic_bool Running_ = false;
|
||||
Poco::Thread Thr_;
|
||||
// std::unique_ptr<MyParallelSocketReactor> ReactorPool_;
|
||||
Poco::Net::SocketReactor Reactor_;
|
||||
@@ -4915,6 +4982,7 @@ namespace OpenWifi {
|
||||
|
||||
inline void WebSocketClientServer::run() {
|
||||
Running_ = true ;
|
||||
Utils::SetThreadName("ws:clnt-svr");
|
||||
while(Running_) {
|
||||
Poco::Thread::trySleep(2000);
|
||||
|
||||
@@ -4962,8 +5030,12 @@ namespace OpenWifi {
|
||||
|
||||
for(const auto &client:Clients_) {
|
||||
if(client.second.second == UserName) {
|
||||
if(client.second.first->Send(Payload))
|
||||
Sent++;
|
||||
try {
|
||||
if (client.second.first->Send(Payload))
|
||||
Sent++;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Sent>0;
|
||||
@@ -4985,70 +5057,70 @@ namespace OpenWifi {
|
||||
int flags;
|
||||
int n;
|
||||
bool Done=false;
|
||||
Poco::Buffer<char> IncomingFrame(0);
|
||||
n = WS_->receiveFrame(IncomingFrame, flags);
|
||||
auto Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
|
||||
try {
|
||||
Poco::Buffer<char> IncomingFrame(0);
|
||||
n = WS_->receiveFrame(IncomingFrame, flags);
|
||||
auto Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
|
||||
|
||||
if(n==0) {
|
||||
return delete this;
|
||||
}
|
||||
if (n == 0) {
|
||||
return delete this;
|
||||
}
|
||||
|
||||
switch(Op) {
|
||||
case Poco::Net::WebSocket::FRAME_OP_PING: {
|
||||
WS_->sendFrame("", 0,
|
||||
(int)Poco::Net::WebSocket::FRAME_OP_PONG |
|
||||
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
|
||||
}
|
||||
break;
|
||||
case Poco::Net::WebSocket::FRAME_OP_PONG: {
|
||||
}
|
||||
break;
|
||||
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
|
||||
Logger().warning(Poco::format("CLOSE(%s): Client is closing its connection.",Id_));
|
||||
Done=true;
|
||||
}
|
||||
break;
|
||||
case Poco::Net::WebSocket::FRAME_OP_TEXT: {
|
||||
IncomingFrame.append(0);
|
||||
if(!Authenticated_) {
|
||||
std::string Frame{IncomingFrame.begin()};
|
||||
auto Tokens = Utils::Split(Frame,':');
|
||||
bool Expired = false, Contacted = false;
|
||||
if(Tokens.size()==2 && AuthClient()->IsAuthorized(Tokens[1], UserInfo_, Expired, Contacted)) {
|
||||
Authenticated_=true;
|
||||
std::string S{"Welcome! Bienvenue! Bienvenidos!"};
|
||||
WS_->sendFrame(S.c_str(),S.size());
|
||||
WebSocketClientServer()->SetUser(Id_,UserInfo_.userinfo.email);
|
||||
} else {
|
||||
std::string S{"Invalid token. Closing connection."};
|
||||
WS_->sendFrame(S.c_str(),S.size());
|
||||
Done=true;
|
||||
}
|
||||
switch (Op) {
|
||||
case Poco::Net::WebSocket::FRAME_OP_PING: {
|
||||
WS_->sendFrame("", 0,
|
||||
(int)Poco::Net::WebSocket::FRAME_OP_PONG |
|
||||
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
|
||||
} break;
|
||||
case Poco::Net::WebSocket::FRAME_OP_PONG: {
|
||||
} break;
|
||||
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
|
||||
Logger().warning(Poco::format("CLOSE(%s): Client is closing its connection.", Id_));
|
||||
Done = true;
|
||||
} break;
|
||||
case Poco::Net::WebSocket::FRAME_OP_TEXT: {
|
||||
IncomingFrame.append(0);
|
||||
if (!Authenticated_) {
|
||||
std::string Frame{IncomingFrame.begin()};
|
||||
auto Tokens = Utils::Split(Frame, ':');
|
||||
bool Expired = false, Contacted = false;
|
||||
if (Tokens.size() == 2 &&
|
||||
AuthClient()->IsAuthorized(Tokens[1], UserInfo_, Expired, Contacted)) {
|
||||
Authenticated_ = true;
|
||||
std::string S{"Welcome! Bienvenue! Bienvenidos!"};
|
||||
WS_->sendFrame(S.c_str(), S.size());
|
||||
WebSocketClientServer()->SetUser(Id_, UserInfo_.userinfo.email);
|
||||
} else {
|
||||
std::string S{"Invalid token. Closing connection."};
|
||||
WS_->sendFrame(S.c_str(), S.size());
|
||||
Done = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
Poco::JSON::Parser P;
|
||||
auto Obj = P.parse(IncomingFrame.begin())
|
||||
.extract<Poco::JSON::Object::Ptr>();
|
||||
std::string Answer;
|
||||
if(Processor_!= nullptr)
|
||||
Processor_->Processor(Obj, Answer, Done);
|
||||
if (!Answer.empty())
|
||||
WS_->sendFrame(Answer.c_str(), (int) Answer.size());
|
||||
else {
|
||||
WS_->sendFrame("{}", 2);
|
||||
}
|
||||
} catch (const Poco::JSON::JSONException & E) {
|
||||
Logger().log(E);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Poco::JSON::Parser P;
|
||||
auto Obj =
|
||||
P.parse(IncomingFrame.begin()).extract<Poco::JSON::Object::Ptr>();
|
||||
std::string Answer;
|
||||
if (Processor_ != nullptr)
|
||||
Processor_->Processor(Obj, Answer, Done);
|
||||
if (!Answer.empty())
|
||||
WS_->sendFrame(Answer.c_str(), (int)Answer.size());
|
||||
else {
|
||||
WS_->sendFrame("{}", 2);
|
||||
}
|
||||
} catch (const Poco::JSON::JSONException &E) {
|
||||
Logger().log(E);
|
||||
Done=true;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
Done=true;
|
||||
}
|
||||
|
||||
if(Done) {
|
||||
delete this;
|
||||
|
||||
@@ -133,6 +133,37 @@ namespace ORM {
|
||||
return R;
|
||||
}
|
||||
|
||||
inline std::string WHERE_AND_(std::string Result) {
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename T, typename... Args> std::string WHERE_AND_(std::string Result, const char *fieldName, const T &Value, Args... args) {
|
||||
if constexpr(std::is_same_v<T,std::string>)
|
||||
{
|
||||
if(!Value.empty()) {
|
||||
if(!Result.empty())
|
||||
Result += " and ";
|
||||
Result += fieldName;
|
||||
Result += '=';
|
||||
Result += "'";
|
||||
Result += Escape(Value);
|
||||
Result += "'";
|
||||
}
|
||||
} else {
|
||||
if(!Result.empty())
|
||||
Result += " and ";
|
||||
Result += fieldName ;
|
||||
Result += '=';
|
||||
Result += std::to_string(Value);
|
||||
}
|
||||
return WHERE_AND_(Result,args...);
|
||||
}
|
||||
|
||||
template <typename... Args> std::string WHERE_AND(Args... args) {
|
||||
std::string Result;
|
||||
return WHERE_AND_(Result, args...);
|
||||
}
|
||||
|
||||
enum SqlComparison { EQ = 0, NEQ, LT, LTE, GT, GTE };
|
||||
enum SqlBinaryOp { AND = 0 , OR };
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include "Poco/String.h"
|
||||
|
||||
#if defined(__GNUC__)
|
||||
@@ -427,7 +428,9 @@ namespace OpenWifi::uCentralProtocol {
|
||||
static const char *RADIUSDATA = "data";
|
||||
static const char *RADIUSACCT = "acct";
|
||||
static const char *RADIUSAUTH = "auth";
|
||||
static const char *RADIUSCOA = "coa";
|
||||
static const char *RADIUSDST = "dst";
|
||||
static const char *IES = "ies";
|
||||
}
|
||||
|
||||
namespace OpenWifi::uCentralProtocol::Events {
|
||||
@@ -442,6 +445,7 @@ namespace OpenWifi::uCentralProtocol::Events {
|
||||
static const char *RECOVERY = "recovery";
|
||||
static const char *TELEMETRY = "telemetry";
|
||||
static const char *DEVICEUPDATE = "deviceupdate";
|
||||
static const char *VENUE_BROADCAST = "venue_broadcast";
|
||||
|
||||
enum EVENT_MSG {
|
||||
ET_UNKNOWN,
|
||||
@@ -454,28 +458,34 @@ namespace OpenWifi::uCentralProtocol::Events {
|
||||
ET_CFGPENDING,
|
||||
ET_RECOVERY,
|
||||
ET_DEVICEUPDATE,
|
||||
ET_TELEMETRY
|
||||
ET_TELEMETRY,
|
||||
ET_VENUEBROADCAST
|
||||
};
|
||||
|
||||
inline static EVENT_MSG EventFromString(const std::string & Method) {
|
||||
static std::vector<std::pair<const char *,EVENT_MSG>> Values{
|
||||
{ CFGPENDING , ET_CFGPENDING },
|
||||
{ CONNECT, ET_CONNECT },
|
||||
{ CRASHLOG, ET_CRASHLOG },
|
||||
{ DEVICEUPDATE, ET_DEVICEUPDATE },
|
||||
{ HEALTHCHECK, ET_HEALTHCHECK },
|
||||
{ LOG, ET_LOG },
|
||||
{ PING, ET_PING },
|
||||
{ RECOVERY, ET_RECOVERY },
|
||||
{ STATE, ET_STATE },
|
||||
{ TELEMETRY, ET_TELEMETRY }
|
||||
};
|
||||
|
||||
std::string L = Poco::toLower(Method);
|
||||
auto hint = std::find_if(cbegin(Values),cend(Values),[&](const std::pair<const char *,EVENT_MSG> &v) ->bool { return strcmp(v.first,L.c_str())==0; });
|
||||
if(hint == cend(Values))
|
||||
return ET_UNKNOWN;
|
||||
return hint->second;
|
||||
inline EVENT_MSG EventFromString(const std::string & Method) {
|
||||
if(strcmp(STATE,Method.c_str())==0)
|
||||
return ET_STATE;
|
||||
else if(strcmp(HEALTHCHECK,Method.c_str())==0)
|
||||
return ET_HEALTHCHECK;
|
||||
else if(strcmp(CONNECT,Method.c_str())==0)
|
||||
return ET_CONNECT;
|
||||
else if(strcmp(CFGPENDING,Method.c_str())==0)
|
||||
return ET_CFGPENDING;
|
||||
else if(strcmp(CRASHLOG,Method.c_str())==0)
|
||||
return ET_CRASHLOG;
|
||||
else if(strcmp(DEVICEUPDATE,Method.c_str())==0)
|
||||
return ET_DEVICEUPDATE;
|
||||
else if(strcmp(LOG,Method.c_str())==0)
|
||||
return ET_LOG;
|
||||
else if(strcmp(PING,Method.c_str())==0)
|
||||
return ET_PING;
|
||||
else if(strcmp(RECOVERY,Method.c_str())==0)
|
||||
return ET_RECOVERY;
|
||||
else if(strcmp(TELEMETRY,Method.c_str())==0)
|
||||
return ET_TELEMETRY;
|
||||
else if(strcmp(VENUE_BROADCAST,Method.c_str())==0)
|
||||
return ET_VENUEBROADCAST;
|
||||
return ET_UNKNOWN;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,94 +8,75 @@
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
RTTYS_ClientConnection::RTTYS_ClientConnection(
|
||||
Poco::Net::HTTPServerRequest & Request,
|
||||
Poco::Net::HTTPServerResponse & Response,
|
||||
std::string &Id,
|
||||
Poco::Net::SocketReactor &Reactor, Poco::Logger &L)
|
||||
: Id_(std::move(Id)),
|
||||
SR_(Reactor),
|
||||
Logger_(L) {
|
||||
|
||||
WS_ = new Poco::Net::WebSocket(Request, Response);
|
||||
RTTYS_server()->Register(Id_, this);
|
||||
Logger().information(fmt::format("{}: Client starting connection, session: {}.",
|
||||
Id_, RTTYS_server()->DeviceSessionID(Id_)));
|
||||
SR_.addEventHandler(
|
||||
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ReadableNotification>(
|
||||
*this, &RTTYS_ClientConnection::onSocketReadable));
|
||||
SR_.addEventHandler(
|
||||
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ShutdownNotification>(
|
||||
*this, &RTTYS_ClientConnection::onSocketShutdown));
|
||||
SR_.addEventHandler(
|
||||
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ErrorNotification>(
|
||||
*this, &RTTYS_ClientConnection::onSocketError));
|
||||
|
||||
auto DoLogin = [this]() -> void {
|
||||
int tries = 0;
|
||||
while (tries < 20) {
|
||||
if (RTTYS_server()->Login(this->Id_)) {
|
||||
Logger().information(
|
||||
fmt::format("{}: Client connected to device, session: {}.", Id_,
|
||||
RTTYS_server()->DeviceSessionID(Id_)));
|
||||
this->Connected_ = true;
|
||||
return;
|
||||
}
|
||||
std::this_thread::sleep_for(2000ms);
|
||||
tries++;
|
||||
Logger().information(fmt::format(
|
||||
"{}: Waiting for device to connect to start session. (try={})", Id_,
|
||||
tries));
|
||||
}
|
||||
Logger().information(
|
||||
fmt::format("{}: Client could not connect to device, session: {}.", Id_,
|
||||
RTTYS_server()->DeviceSessionID(Id_)));
|
||||
delete this;
|
||||
};
|
||||
|
||||
std::thread CompleteConnection(DoLogin);
|
||||
CompleteConnection.detach();
|
||||
}
|
||||
RTTYS_ClientConnection::RTTYS_ClientConnection(Poco::Net::HTTPServerRequest &request,
|
||||
Poco::Net::HTTPServerResponse &response,
|
||||
Poco::Net::SocketReactor &reactor,
|
||||
const std::string &Id)
|
||||
:
|
||||
Reactor_(reactor),
|
||||
Id_(Id),
|
||||
Logger_(Poco::Logger::get(fmt::format("RTTY-client({})",Id_)))
|
||||
{
|
||||
Logger_.information("Starting connection");
|
||||
Valid_ = true;
|
||||
WS_ = std::make_unique<Poco::Net::WebSocket>(request,response);
|
||||
Reactor_.addEventHandler(
|
||||
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ReadableNotification>(
|
||||
*this, &RTTYS_ClientConnection::onSocketReadable));
|
||||
Reactor_.addEventHandler(
|
||||
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ShutdownNotification>(
|
||||
*this, &RTTYS_ClientConnection::onSocketShutdown));
|
||||
}
|
||||
|
||||
RTTYS_ClientConnection::~RTTYS_ClientConnection() {
|
||||
Logger().information(fmt::format("{}: Client disconnecting.", Id_));
|
||||
RTTYS_server()->DeRegister(Id_, this);
|
||||
if(Connected_) {
|
||||
SR_.removeEventHandler(
|
||||
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ReadableNotification>(
|
||||
*this, &RTTYS_ClientConnection::onSocketReadable));
|
||||
SR_.removeEventHandler(
|
||||
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ShutdownNotification>(
|
||||
*this, &RTTYS_ClientConnection::onSocketShutdown));
|
||||
SR_.removeEventHandler(
|
||||
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ErrorNotification>(
|
||||
*this, &RTTYS_ClientConnection::onSocketError));
|
||||
if(Valid_) {
|
||||
MyGuard G(Mutex_);
|
||||
EndConnection(false);
|
||||
}
|
||||
delete WS_;
|
||||
Logger().information(fmt::format("{}: Client disconnected.", Id_));
|
||||
}
|
||||
|
||||
void RTTYS_ClientConnection::Close() {
|
||||
CloseConnection_ = true;
|
||||
void RTTYS_ClientConnection::EndConnection(bool SendNotification) {
|
||||
if(Valid_) {
|
||||
Valid_=false;
|
||||
try {
|
||||
Reactor_.removeEventHandler(
|
||||
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ReadableNotification>(
|
||||
*this, &RTTYS_ClientConnection::onSocketReadable));
|
||||
Reactor_.removeEventHandler(
|
||||
*WS_, Poco::NObserver<RTTYS_ClientConnection, Poco::Net::ShutdownNotification>(
|
||||
*this, &RTTYS_ClientConnection::onSocketShutdown));
|
||||
// WS_->shutdown();
|
||||
if (SendNotification)
|
||||
RTTYS_server()->NotifyClientDisconnect(Id_, this);
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
Logger_.information("Disconnected.");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void RTTYS_ClientConnection::onSocketReadable([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf) {
|
||||
|
||||
int flags;
|
||||
auto n = WS_->receiveFrame(Buffer_, sizeof(Buffer_), flags);
|
||||
auto Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
|
||||
switch(Op) {
|
||||
MyGuard G(Mutex_);
|
||||
bool MustDisconnect = false;
|
||||
try {
|
||||
int flags;
|
||||
auto n = WS_->receiveFrame(Buffer_, sizeof(Buffer_), flags);
|
||||
auto Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
|
||||
switch (Op) {
|
||||
case Poco::Net::WebSocket::FRAME_OP_PING: {
|
||||
WS_->sendFrame("", 0,(int)Poco::Net::WebSocket::FRAME_OP_PONG | (int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
|
||||
}
|
||||
break;
|
||||
WS_->sendFrame("", 0,
|
||||
(int)Poco::Net::WebSocket::FRAME_OP_PONG |
|
||||
(int)Poco::Net::WebSocket::FRAME_FLAG_FIN);
|
||||
} break;
|
||||
case Poco::Net::WebSocket::FRAME_OP_PONG: {
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case Poco::Net::WebSocket::FRAME_OP_TEXT: {
|
||||
if (n == 0)
|
||||
return delete this;
|
||||
std::string s((char*)Buffer_, n);
|
||||
if (n == 0) {
|
||||
Logger_.information("Socket readable shutdown.");
|
||||
MustDisconnect = true;
|
||||
} else {
|
||||
std::string s((char *)Buffer_, n);
|
||||
try {
|
||||
auto Doc = nlohmann::json::parse(s);
|
||||
if (Doc.contains("type")) {
|
||||
@@ -103,55 +84,82 @@ namespace OpenWifi {
|
||||
if (Type == "winsize") {
|
||||
auto cols = Doc["cols"];
|
||||
auto rows = Doc["rows"];
|
||||
if(!RTTYS_server()->WindowSize(Id_,cols, rows)) {
|
||||
return delete this;
|
||||
if (!RTTYS_server()->WindowSize(Id_, cols, rows)) {
|
||||
Logger_.information("Winsize shutdown.");
|
||||
MustDisconnect = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
// just ignore parse errors
|
||||
Logger_.information("Frame text exception shutdown.");
|
||||
MustDisconnect = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case Poco::Net::WebSocket::FRAME_OP_BINARY: {
|
||||
if (n == 0)
|
||||
return delete this;
|
||||
if(!RTTYS_server()->SendKeyStrokes(Id_,Buffer_,n)) {
|
||||
return delete this;
|
||||
if (n == 0) {
|
||||
Logger_.information("Frame binary size shutdown.");
|
||||
MustDisconnect = true;
|
||||
} else {
|
||||
poco_trace(Logger_, fmt::format("Sending {} key strokes to device.", n));
|
||||
if (!RTTYS_server()->SendKeyStrokes(Id_, Buffer_, n)) {
|
||||
Logger_.information("Sendkeystrokes shutdown.");
|
||||
MustDisconnect = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
|
||||
return delete this;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
Logger_.information("Frame frame close shutdown.");
|
||||
MustDisconnect = true;
|
||||
} break;
|
||||
|
||||
default: {
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
Logger_.information("Frame readable shutdown.");
|
||||
MustDisconnect = true;
|
||||
}
|
||||
|
||||
if(MustDisconnect)
|
||||
EndConnection();
|
||||
}
|
||||
|
||||
void RTTYS_ClientConnection::SendData( const u_char *Buf, size_t len ) {
|
||||
WS_->sendFrame(Buf, len, Poco::Net::WebSocket::FRAME_FLAG_FIN | Poco::Net::WebSocket::FRAME_OP_BINARY);
|
||||
if(!Valid_)
|
||||
return;
|
||||
// MyGuard G(Mutex_);
|
||||
try {
|
||||
WS_->sendFrame(Buf, len,
|
||||
Poco::Net::WebSocket::FRAME_FLAG_FIN |
|
||||
Poco::Net::WebSocket::FRAME_OP_BINARY);
|
||||
return;
|
||||
} catch (...) {
|
||||
Logger_.information("SendData shutdown.");
|
||||
}
|
||||
MyGuard G(Mutex_);
|
||||
EndConnection();
|
||||
}
|
||||
|
||||
void RTTYS_ClientConnection::SendData( const std::string &s , bool login) {
|
||||
if(login) {
|
||||
RTTYS_server()->LoginDone(Id_);
|
||||
void RTTYS_ClientConnection::SendData( const std::string &s) {
|
||||
if(!Valid_)
|
||||
return;
|
||||
// MyGuard G(Mutex_);
|
||||
try {
|
||||
WS_->sendFrame(s.c_str(), s.length());
|
||||
return;
|
||||
} catch (...) {
|
||||
Logger_.information("SendData shutdown.");
|
||||
}
|
||||
WS_->sendFrame( s.c_str(), s.length());
|
||||
MyGuard G(Mutex_);
|
||||
EndConnection();
|
||||
}
|
||||
|
||||
void RTTYS_ClientConnection::onSocketShutdown([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf) {
|
||||
// RTTYS_server()->Close(Id_);
|
||||
delete this;
|
||||
}
|
||||
|
||||
void RTTYS_ClientConnection::onSocketError([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf) {
|
||||
// RTTYS_server()->Close(Id_);
|
||||
delete this;
|
||||
MyGuard G(Mutex_);
|
||||
Logger_.information("Socket shutdown.");
|
||||
EndConnection();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,31 +12,41 @@
|
||||
#include "Poco/FIFOBuffer.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
enum class connection_state {
|
||||
initialized, waiting_for_login, connected, aborting, shutting_down, done
|
||||
};
|
||||
|
||||
class RTTYS_ClientConnection {
|
||||
public:
|
||||
// RTTYS_ClientConnection(std::unique_ptr<Poco::Net::WebSocket> WS, std::string &Id,
|
||||
RTTYS_ClientConnection(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response, std::string &Id,
|
||||
Poco::Net::SocketReactor &Reactor, Poco::Logger &L);
|
||||
RTTYS_ClientConnection(Poco::Net::HTTPServerRequest &request,
|
||||
Poco::Net::HTTPServerResponse &response,
|
||||
Poco::Net::SocketReactor & reactor,
|
||||
const std::string &Id);
|
||||
~RTTYS_ClientConnection();
|
||||
void onSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf);
|
||||
void onSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf);
|
||||
void onSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf);
|
||||
|
||||
void SendData( const u_char *Buf, size_t len );
|
||||
void SendData( const std::string & S, bool login=false);
|
||||
void SendData( const std::string & S );
|
||||
|
||||
void Close();
|
||||
[[nodiscard]] inline std::string ID() { return Id_; }
|
||||
[[nodiscard]] inline bool Valid() { return Valid_; }
|
||||
using MyMutexType = std::recursive_mutex;
|
||||
using MyGuard = std::lock_guard<MyMutexType>;
|
||||
|
||||
private:
|
||||
Poco::Net::WebSocket *WS_= nullptr;
|
||||
std::string Id_;
|
||||
std::string Sid_;
|
||||
Poco::Net::SocketReactor &SR_;
|
||||
std::atomic_bool Connected_=false;
|
||||
Poco::Logger & Logger_;
|
||||
u_char Buffer_[16000]{0};
|
||||
volatile bool CloseConnection_=false;
|
||||
Poco::Net::SocketReactor &Reactor_;
|
||||
std::string Id_;
|
||||
std::unique_ptr<Poco::Net::WebSocket> WS_;
|
||||
Poco::Logger &Logger_;
|
||||
std::string Sid_;
|
||||
std::atomic_bool Valid_=false;
|
||||
u_char Buffer_[64000]{0};
|
||||
MyMutexType Mutex_;
|
||||
// volatile connection_state state_ = connection_state::initialized;
|
||||
|
||||
void EndConnection(bool SendNotification=true);
|
||||
|
||||
inline Poco::Logger & Logger() { return Logger_; }
|
||||
};
|
||||
}
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
RTTY_Client_WebSocketRequestHandler::RTTY_Client_WebSocketRequestHandler(Poco::Net::SocketReactor &R, Poco::Logger & L)
|
||||
:R_(R), Logger_(L) {
|
||||
RTTYS_Client_WebSocketRequestHandler::RTTYS_Client_WebSocketRequestHandler(Poco::Logger & L)
|
||||
:Logger_(L) {
|
||||
}
|
||||
|
||||
void RTTY_Client_WebSocketRequestHandler::handleRequest(Poco::Net::HTTPServerRequest &request,
|
||||
void RTTYS_Client_WebSocketRequestHandler::handleRequest(Poco::Net::HTTPServerRequest &request,
|
||||
Poco::Net::HTTPServerResponse &response) {
|
||||
Poco::URI uri(request.getURI());
|
||||
const auto & P = uri.getPath();
|
||||
@@ -30,9 +30,7 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
try {
|
||||
Poco::Thread::current()->setName(fmt::format("WebRTTYRequest_WSHandler_{}", T[2]));
|
||||
new RTTYS_ClientConnection(request, response, T[2], R_, Logger_);
|
||||
Logger_.information("Websocket has finished");
|
||||
RTTYS_server()->CreateNewClient(request,response,T[2]);
|
||||
} catch (...) {
|
||||
Logger_.warning("Exception during WS creation");
|
||||
}
|
||||
@@ -105,9 +103,10 @@ namespace OpenWifi {
|
||||
void PageRequestHandler::handleRequest(Poco::Net::HTTPServerRequest &request,
|
||||
Poco::Net::HTTPServerResponse &response) {
|
||||
|
||||
uint64_t id = rtty_ws_id++;
|
||||
Utils::SetThreadName("rt:webserver");
|
||||
[[maybe_unused]] uint64_t id = rtty_ws_id++;
|
||||
|
||||
Logger_.information(fmt::format("{}: Starting request.",id));
|
||||
poco_debug(Logger(),fmt::format("{}: Starting request.",id));
|
||||
Poco::URI uri(request.getURI());
|
||||
auto Path = uri.getPath();
|
||||
|
||||
@@ -129,7 +128,7 @@ namespace OpenWifi {
|
||||
if (ParsedPath.count() > 1) {
|
||||
if (ParsedPath[1] == "connect") {
|
||||
response.redirect(Poco::replace(Path,"/connect/","/rtty/"));
|
||||
RTTYS_server()->Logger().information(fmt::format("redirect: {}",Path));
|
||||
poco_debug(Logger(),fmt::format("{}: Redirect: {}",id,Path));
|
||||
return;
|
||||
} else if (ParsedPath[1] == "authorized") {
|
||||
SetCommonHeaders(request,response, false);
|
||||
@@ -138,7 +137,7 @@ namespace OpenWifi {
|
||||
response.setContentType("application/json");
|
||||
std::ostream &answer = response.send();
|
||||
answer << to_string(doc);
|
||||
Logger_.information(fmt::format("{}: Finishing authorization request.",id));
|
||||
poco_debug(Logger(),fmt::format("{}: Finishing authorization request.",id));
|
||||
return;
|
||||
} else if (ParsedPath[1] == "fontsize") {
|
||||
SetCommonHeaders(request,response, false);
|
||||
@@ -147,7 +146,7 @@ namespace OpenWifi {
|
||||
response.setContentType("application/json");
|
||||
std::ostream &answer = response.send();
|
||||
answer << to_string(doc);
|
||||
Logger_.information(fmt::format("{}: Finishing font size request.",id));
|
||||
poco_debug(Logger(),fmt::format("{}: Finishing font size request.",id));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -155,12 +154,12 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
if(Path.find("../")!=std::string::npos) {
|
||||
Logger_.information(fmt::format("{}: Finishing request.",id));
|
||||
poco_debug(Logger(),fmt::format("{}: Finishing request.",id));
|
||||
return;
|
||||
}
|
||||
|
||||
if(Path.find("~/")!=std::string::npos) {
|
||||
Logger_.information(fmt::format("{}: Finishing request.",id));
|
||||
poco_debug(Logger(),fmt::format("{}: Finishing request.",id));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -170,7 +169,7 @@ namespace OpenWifi {
|
||||
// std::cout << id << ": Path " << Path << " does not exist" << std::endl;
|
||||
Path = RTTYS_server()->UIAssets() + "/index.html";
|
||||
response.sendFile(Path,"text/html");
|
||||
Logger_.information(fmt::format("{}: Finishing request.",id));
|
||||
poco_debug(Logger(),fmt::format("{}: Finishing request.",id));
|
||||
return;
|
||||
}
|
||||
Poco::Path P(Path);
|
||||
@@ -187,7 +186,7 @@ namespace OpenWifi {
|
||||
} else if (Ext == "css") {
|
||||
Type = "text/css; charset=utf-8";
|
||||
if(IsFileGZipped(Path)) {
|
||||
Logger_.information(fmt::format("{}: Downloading UI Assets.",id));
|
||||
poco_debug(Logger(),fmt::format("{}: Downloading UI Assets.",id));
|
||||
response.set("Content-Encoding", "gzip");
|
||||
}
|
||||
} else if (Ext == "ico")
|
||||
@@ -201,19 +200,19 @@ namespace OpenWifi {
|
||||
|
||||
response.setContentLength(F.getSize());
|
||||
response.sendFile(Path, Type);
|
||||
Logger_.information(fmt::format("{}: Finishing request.",id));
|
||||
poco_debug(Logger(),fmt::format("{}: Finishing request.",id));
|
||||
}
|
||||
|
||||
RTTY_Client_RequestHandlerFactory::RTTY_Client_RequestHandlerFactory(Poco::Net::SocketReactor &R, Poco::Logger & L)
|
||||
: Reactor_(R), Logger_(L) {}
|
||||
RTTYS_Client_RequestHandlerFactory::RTTYS_Client_RequestHandlerFactory(Poco::Logger & L)
|
||||
: Logger_(L) {}
|
||||
|
||||
Poco::Net::HTTPRequestHandler *
|
||||
RTTY_Client_RequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest &request) {
|
||||
RTTYS_Client_RequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest &request) {
|
||||
try {
|
||||
if (request.find("Upgrade") != request.end() &&
|
||||
Poco::icompare(request["Upgrade"], "websocket") == 0) {
|
||||
Poco::Thread::current()->setName("WebRTTYRequest_WSHandler");
|
||||
return new RTTY_Client_WebSocketRequestHandler(Reactor_, Logger_);
|
||||
return new RTTYS_Client_WebSocketRequestHandler(Logger_);
|
||||
} else {
|
||||
Poco::Thread::current()->setName("WebRTTYRequest_PageHandler");
|
||||
return new PageRequestHandler(Logger_);
|
||||
|
||||
@@ -10,15 +10,14 @@
|
||||
#include "Poco/Net/WebSocket.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class RTTY_Client_WebSocketRequestHandler : public Poco::Net::HTTPRequestHandler {
|
||||
class RTTYS_Client_WebSocketRequestHandler : public Poco::Net::HTTPRequestHandler {
|
||||
public:
|
||||
explicit RTTY_Client_WebSocketRequestHandler(Poco::Net::SocketReactor &R, Poco::Logger &L );
|
||||
explicit RTTYS_Client_WebSocketRequestHandler(Poco::Logger &L);
|
||||
|
||||
void handleRequest(Poco::Net::HTTPServerRequest &request,
|
||||
Poco::Net::HTTPServerResponse &response) override;
|
||||
|
||||
private:
|
||||
Poco::Net::SocketReactor &R_;
|
||||
Poco::Logger &Logger_;
|
||||
};
|
||||
|
||||
@@ -33,17 +32,17 @@ namespace OpenWifi {
|
||||
|
||||
private:
|
||||
Poco::Logger & Logger_;
|
||||
inline Poco::Logger &Logger() { return Logger_; }
|
||||
};
|
||||
|
||||
class RTTY_Client_RequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory {
|
||||
class RTTYS_Client_RequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory {
|
||||
public:
|
||||
explicit RTTY_Client_RequestHandlerFactory(Poco::Net::SocketReactor &R, Poco::Logger &L);
|
||||
explicit RTTYS_Client_RequestHandlerFactory(Poco::Logger &L);
|
||||
|
||||
Poco::Net::HTTPRequestHandler *
|
||||
createRequestHandler(const Poco::Net::HTTPServerRequest &request) override;
|
||||
|
||||
private:
|
||||
Poco::Net::SocketReactor &Reactor_;
|
||||
Poco::Logger &Logger_;
|
||||
};
|
||||
}
|
||||
@@ -4,194 +4,243 @@
|
||||
|
||||
#include "RTTYS_device.h"
|
||||
#include "rttys/RTTYS_server.h"
|
||||
#include "rttys/RTTYS_ClientConnection.h"
|
||||
#include "Poco/Net/SecureStreamSocketImpl.h"
|
||||
#include "Poco/Net/StreamSocket.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
RTTY_Device_ConnectionHandler::RTTY_Device_ConnectionHandler(const Poco::Net::StreamSocket & socket) :
|
||||
Poco::Net::TCPServerConnection(socket),
|
||||
Logger_(RTTYS_server()->Logger()) {
|
||||
device_address_ = socket.address().toString();
|
||||
Logger().information(fmt::format("{}: Started.", device_address_));
|
||||
conn_id_ = global_device_connection_id++;
|
||||
RTTYS_Device_ConnectionHandler::RTTYS_Device_ConnectionHandler(Poco::Net::StreamSocket& socket, Poco::Net::SocketReactor & reactor):
|
||||
socket_(socket),
|
||||
reactor_(reactor),
|
||||
Logger_(Poco::Logger::get(fmt::format("RTTY-device({})",socket_.peerAddress().toString())))
|
||||
{
|
||||
// std::thread T([=]() { CompleteConnection(); });
|
||||
// T.detach();
|
||||
CompleteConnection();
|
||||
}
|
||||
|
||||
RTTY_Device_ConnectionHandler::~RTTY_Device_ConnectionHandler() {
|
||||
Logger().information(fmt::format("{}: Completing.", device_address_));
|
||||
running_ = false;
|
||||
RTTYS_server()->DeRegisterDevice(id_, this);
|
||||
// socket().close();
|
||||
Logger().information(fmt::format("{}: Completed.", device_address_));
|
||||
}
|
||||
void RTTYS_Device_ConnectionHandler::CompleteConnection() {
|
||||
try {
|
||||
valid_=true;
|
||||
device_address_ = socket_.peerAddress();
|
||||
|
||||
void RTTY_Device_ConnectionHandler::AddCommand(u_char C) {
|
||||
std::lock_guard G(M_);
|
||||
// std::cout << conn_id_ << ": Adding command " << (int)C << std::endl;
|
||||
commands_.push_back(C);
|
||||
}
|
||||
|
||||
bool RTTY_Device_ConnectionHandler::ProcessCommands() {
|
||||
std::lock_guard G(M_);
|
||||
if(!commands_.empty()) {
|
||||
// std::cout << conn_id_ << ": Commands: " << commands_.size() << std::endl;
|
||||
for(const auto &i:commands_) {
|
||||
// std::cout << "Command: " << (int)i << std::endl;
|
||||
if(i==msgTypeLogin) {
|
||||
// std::cout << "Doing login..." << std::endl;
|
||||
Login();
|
||||
}
|
||||
else if(i==msgTypeLogout) {
|
||||
// std::cout << "Doing logout..." << std::endl;
|
||||
Logout();
|
||||
}
|
||||
auto SS = dynamic_cast<Poco::Net::SecureStreamSocketImpl *>(socket_.impl());
|
||||
while (true) {
|
||||
auto V = SS->completeHandshake();
|
||||
if (V == 1)
|
||||
break;
|
||||
}
|
||||
commands_.clear();
|
||||
|
||||
if ((SS->secure())) {
|
||||
poco_information(Logger(), "Secure connection.");
|
||||
}
|
||||
|
||||
reactor_.addEventHandler(
|
||||
socket_,
|
||||
Poco::NObserver<RTTYS_Device_ConnectionHandler, Poco::Net::ReadableNotification>(
|
||||
*this, &RTTYS_Device_ConnectionHandler::onSocketReadable));
|
||||
reactor_.addEventHandler(
|
||||
socket_,
|
||||
Poco::NObserver<RTTYS_Device_ConnectionHandler, Poco::Net::ShutdownNotification>(
|
||||
*this, &RTTYS_Device_ConnectionHandler::onSocketShutdown));
|
||||
} catch (...) {
|
||||
poco_warning(Logger(), "Device caused exception while completing connection.");
|
||||
Guard G(M_);
|
||||
EndConnection();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
RTTYS_Device_ConnectionHandler::~RTTYS_Device_ConnectionHandler() {
|
||||
if(valid_) {
|
||||
Guard G(M_);
|
||||
poco_warning(Logger(), "Device connection being deleted.");
|
||||
EndConnection(false);
|
||||
}
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::run() {
|
||||
running_ = true ;
|
||||
void RTTYS_Device_ConnectionHandler::EndConnection(bool SendNotification) {
|
||||
try {
|
||||
if(valid_) {
|
||||
valid_ = false;
|
||||
reactor_.removeEventHandler(
|
||||
socket_,
|
||||
Poco::NObserver<RTTYS_Device_ConnectionHandler, Poco::Net::ReadableNotification>(
|
||||
*this, &RTTYS_Device_ConnectionHandler::onSocketReadable));
|
||||
reactor_.removeEventHandler(
|
||||
socket_,
|
||||
Poco::NObserver<RTTYS_Device_ConnectionHandler, Poco::Net::ShutdownNotification>(
|
||||
*this, &RTTYS_Device_ConnectionHandler::onSocketShutdown));
|
||||
if(SendNotification)
|
||||
RTTYS_server()->NotifyDeviceDisconnect(Id_,this);
|
||||
poco_information(Logger(), "Connection done.");
|
||||
socket_.close();
|
||||
}
|
||||
} catch (...) {
|
||||
|
||||
Poco::Timespan pollTimeOut(0,100);
|
||||
Poco::Timespan pollError(0,1);
|
||||
Poco::Timespan recvTimeOut(120,0);
|
||||
}
|
||||
}
|
||||
|
||||
socket().setKeepAlive(true);
|
||||
socket().setNoDelay(true);
|
||||
socket().setReceiveBufferSize(64000);
|
||||
socket().setLinger(false,0);
|
||||
socket().setSendBufferSize(64000);
|
||||
socket().setReceiveTimeout(recvTimeOut);
|
||||
[[maybe_unused]] static void dump(unsigned char *p,uint l) {
|
||||
for(uint i=0;i<l;i++) {
|
||||
std::cout << std::hex << (uint) p[i] << " ";
|
||||
if(i % 16 == 0)
|
||||
std::cout << std::endl;
|
||||
}
|
||||
std::cout << std::dec << std::endl ;
|
||||
}
|
||||
|
||||
int reason=0;
|
||||
while(running_) {
|
||||
void RTTYS_Device_ConnectionHandler::onSocketReadable([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf) {
|
||||
bool good = true;
|
||||
|
||||
if(!ProcessCommands()) {
|
||||
reason=1;
|
||||
running_=false;
|
||||
break;
|
||||
Guard G(M_);
|
||||
|
||||
try {
|
||||
auto received_bytes = socket_.receiveBytes(inBuf_);
|
||||
if (received_bytes == 0) {
|
||||
poco_information(Logger(), fmt::format("{}: Device Closing connection - 0 bytes received.",Id_));
|
||||
return EndConnection();
|
||||
}
|
||||
|
||||
// std::lock_guard G(M_);
|
||||
if (socket().poll(pollError, Poco::Net::Socket::SELECT_ERROR) == true) {
|
||||
reason=2;
|
||||
running_=false;
|
||||
continue;
|
||||
}
|
||||
while (inBuf_.isReadable() && good) {
|
||||
uint32_t msg_len = 0;
|
||||
if (waiting_for_bytes_ != 0) {
|
||||
|
||||
if (socket().poll(pollTimeOut, Poco::Net::Socket::SELECT_READ) == false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int received = socket().receiveBytes(inBuf_);
|
||||
if(received<0) {
|
||||
running_ = false;
|
||||
reason=3;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(received==0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
while (!inBuf_.isEmpty() && running_) {
|
||||
// std::cout << conn_id_ << ": processing buffer" << std::endl;
|
||||
std::size_t msg_len;
|
||||
if (waiting_for_bytes_ == 0) {
|
||||
u_char header[3]{0};
|
||||
inBuf_.read((char *)&header[0], 3);
|
||||
last_command_ = header[0];
|
||||
msg_len = header[1] * 256 + header[2];
|
||||
} else {
|
||||
msg_len = received;
|
||||
if (inBuf_.used() >= 3) {
|
||||
auto *head = (unsigned char *)inBuf_.begin();
|
||||
last_command_ = head[0];
|
||||
msg_len = head[1] * 256 + head[2];
|
||||
inBuf_.drain(3);
|
||||
} else {
|
||||
good = false;
|
||||
if (!good)
|
||||
std::cout << "do_msgTypeTermData:5 " << inBuf_.used() << std::endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
switch (last_command_) {
|
||||
case msgTypeRegister: {
|
||||
do_msgTypeRegister(msg_len);
|
||||
good = do_msgTypeRegister(msg_len);
|
||||
} break;
|
||||
case msgTypeLogin: {
|
||||
do_msgTypeLogin(msg_len);
|
||||
good = do_msgTypeLogin(msg_len);
|
||||
} break;
|
||||
case msgTypeLogout: {
|
||||
do_msgTypeLogout(msg_len);
|
||||
good = do_msgTypeLogout(msg_len);
|
||||
} break;
|
||||
case msgTypeTermData: {
|
||||
do_msgTypeTermData(msg_len);
|
||||
good = do_msgTypeTermData(msg_len);
|
||||
} break;
|
||||
case msgTypeWinsize: {
|
||||
do_msgTypeWinsize(msg_len);
|
||||
good = do_msgTypeWinsize(msg_len);
|
||||
} break;
|
||||
case msgTypeCmd: {
|
||||
do_msgTypeCmd(msg_len);
|
||||
good = do_msgTypeCmd(msg_len);
|
||||
} break;
|
||||
case msgTypeHeartbeat: {
|
||||
do_msgTypeHeartbeat(msg_len);
|
||||
good = do_msgTypeHeartbeat(msg_len);
|
||||
} break;
|
||||
case msgTypeFile: {
|
||||
do_msgTypeFile(msg_len);
|
||||
good = do_msgTypeFile(msg_len);
|
||||
} break;
|
||||
case msgTypeHttp: {
|
||||
do_msgTypeHttp(msg_len);
|
||||
good = do_msgTypeHttp(msg_len);
|
||||
} break;
|
||||
case msgTypeAck: {
|
||||
do_msgTypeAck(msg_len);
|
||||
good = do_msgTypeAck(msg_len);
|
||||
} break;
|
||||
case msgTypeMax: {
|
||||
do_msgTypeMax(msg_len);
|
||||
good = do_msgTypeMax(msg_len);
|
||||
} break;
|
||||
default:
|
||||
Logger().warning(fmt::format("{}: ID:{} Unknown command {}", conn_id_, id_, (int)last_command_));
|
||||
running_ = false;
|
||||
continue;
|
||||
default: {
|
||||
poco_warning(Logger(),
|
||||
fmt::format("{}: Unknown command {} from device. GW closing connection.", Id_,
|
||||
(int)last_command_));
|
||||
good = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
good = false;
|
||||
Logger().log(E,__FILE__,__LINE__);
|
||||
poco_warning(Logger(),fmt::format("{}: Exception. GW closing connection.", Id_));
|
||||
} catch (const std::exception &E) {
|
||||
poco_warning(Logger(),fmt::format("{}: Exception. GW closing connection.", Id_));
|
||||
good = false;
|
||||
}
|
||||
|
||||
if(!good) {
|
||||
return EndConnection();
|
||||
}
|
||||
}
|
||||
|
||||
void RTTYS_Device_ConnectionHandler::onSocketShutdown([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf) {
|
||||
Guard G(M_);
|
||||
poco_information(Logger(),fmt::format("{}: Connection being closed - socket shutdown.",Id_));
|
||||
EndConnection();
|
||||
}
|
||||
|
||||
bool RTTYS_Device_ConnectionHandler::SendToClient(const u_char *Buf, int Len) {
|
||||
return RTTYS_server()->SendToClient(Id_, Buf, Len);
|
||||
}
|
||||
|
||||
bool RTTYS_Device_ConnectionHandler::SendToClient(const std::string &S) {
|
||||
return RTTYS_server()->SendToClient(Id_, S);
|
||||
}
|
||||
|
||||
bool RTTYS_Device_ConnectionHandler::KeyStrokes(const u_char *buf, size_t len) {
|
||||
if(!valid_)
|
||||
return false;
|
||||
|
||||
if(len<=(sizeof(small_buf_)-3)) {
|
||||
small_buf_[0] = msgTypeTermData;
|
||||
small_buf_[1] = (len & 0xff00) >> 8;
|
||||
small_buf_[2] = (len & 0x00ff);
|
||||
memcpy(&small_buf_[3],buf,len);
|
||||
try {
|
||||
socket_.sendBytes(small_buf_,len+3);
|
||||
return true;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
auto Msg = std::make_unique<unsigned char []>(len + 3);
|
||||
Msg.get()[0] = msgTypeTermData;
|
||||
Msg.get()[1] = (len & 0xff00) >> 8;
|
||||
Msg.get()[2] = (len & 0x00ff);
|
||||
memcpy((void *)(Msg.get() + 3), buf, len);
|
||||
try {
|
||||
socket_.sendBytes(Msg.get(), len + 3);
|
||||
return true;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Logger().information(fmt::format("{}: ID:{} Exiting. Reason:{}", conn_id_, id_, reason));
|
||||
// RTTYS_server()->DeRegister(id_, this);
|
||||
// Logger().information(fmt::format("{}: ID:{} Exiting. Deregistered.", conn_id_, id_, reason));
|
||||
loop_done_=true;
|
||||
}
|
||||
/*
|
||||
unsigned char Msg[64];
|
||||
Msg[0] = msgTypeTermData;
|
||||
Msg[1] = (len & 0xff00) >> 8;
|
||||
Msg[2] = (len & 0x00ff);
|
||||
|
||||
void RTTY_Device_ConnectionHandler::Stop() {
|
||||
running_ = false;
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::SendToClient(const u_char *Buf, int Len) {
|
||||
RTTYS_server()->SendToClient(id_, Buf, Len);
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::SendToClient(const std::string &S) {
|
||||
RTTYS_server()->SendToClient(id_, S);
|
||||
}
|
||||
|
||||
bool RTTY_Device_ConnectionHandler::KeyStrokes(const u_char *buf, size_t len) {
|
||||
std::lock_guard G(M_);
|
||||
u_char outBuf[16]{0};
|
||||
|
||||
if(len>(sizeof(outBuf)-5))
|
||||
return false;
|
||||
|
||||
auto total_len = 3 + 1 + len-1;
|
||||
outBuf[0] = msgTypeTermData;
|
||||
outBuf[1] = 0 ;
|
||||
outBuf[2] = len +1-1;
|
||||
outBuf[3] = sid_;
|
||||
memcpy( &outBuf[4], &buf[1], len-1);
|
||||
Poco::Net::SocketBufVec MsgParts{ Poco::Net::SocketBuf{ .iov_base=Msg, .iov_len=3},
|
||||
Poco::Net::SocketBuf{ .iov_base=(unsigned char *)buf, .iov_len=len}};
|
||||
try {
|
||||
socket().sendBytes(outBuf, total_len);
|
||||
socket_.sendBytes(MsgParts);
|
||||
return true;
|
||||
} catch (...) {
|
||||
return false;
|
||||
|
||||
}
|
||||
return false;
|
||||
*/
|
||||
}
|
||||
|
||||
bool RTTY_Device_ConnectionHandler::WindowSize(int cols, int rows) {
|
||||
std::lock_guard G(M_);
|
||||
bool RTTYS_Device_ConnectionHandler::WindowSize(int cols, int rows) {
|
||||
if(!valid_)
|
||||
return false;
|
||||
|
||||
// Guard G(M_);
|
||||
|
||||
u_char outBuf[8]{0};
|
||||
outBuf[0] = msgTypeWinsize;
|
||||
outBuf[1] = 0 ;
|
||||
@@ -202,7 +251,7 @@ namespace OpenWifi {
|
||||
outBuf[6] = rows >> 8;
|
||||
outBuf[7] = rows & 0x00ff;
|
||||
try {
|
||||
socket().sendBytes(outBuf, 8);
|
||||
socket_.sendBytes(outBuf, 8);
|
||||
return true;
|
||||
} catch (...) {
|
||||
|
||||
@@ -210,35 +259,40 @@ namespace OpenWifi {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RTTY_Device_ConnectionHandler::Login() {
|
||||
std::lock_guard G(M_);
|
||||
bool RTTYS_Device_ConnectionHandler::Login() {
|
||||
if(!valid_)
|
||||
return false;
|
||||
|
||||
// Guard G(M_);
|
||||
u_char outBuf[3]{0};
|
||||
outBuf[0] = msgTypeLogin;
|
||||
outBuf[1] = 0;
|
||||
outBuf[2] = 0;
|
||||
try {
|
||||
socket().sendBytes(outBuf, 3);
|
||||
socket_.sendBytes(outBuf, 3);
|
||||
} catch (const Poco::IOException &E) {
|
||||
// std::cout << "1 " << E.what() << " " << E.name() << " "<< E.className() << " "<< E.message() << std::endl;
|
||||
return false;
|
||||
} catch (const Poco::Exception &E) {
|
||||
// std::cout << "2 " << E.what() << " " << E.name() << std::endl;
|
||||
return false;
|
||||
}
|
||||
Logger().debug(fmt::format("{}: Device {} login", conn_id_, id_));
|
||||
poco_information(Logger(),fmt::format("{}: Device login", Id_));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RTTY_Device_ConnectionHandler::Logout() {
|
||||
std::lock_guard G(M_);
|
||||
bool RTTYS_Device_ConnectionHandler::Logout() {
|
||||
if(!valid_)
|
||||
return false;
|
||||
|
||||
Guard G(M_);
|
||||
|
||||
u_char outBuf[4]{0};
|
||||
outBuf[0] = msgTypeLogout;
|
||||
outBuf[1] = 0;
|
||||
outBuf[2] = 1;
|
||||
outBuf[3] = sid_;
|
||||
Logger().debug(fmt::format("{}: ID:{} Logout", conn_id_, id_));
|
||||
poco_information(Logger(),fmt::format("{}: Logout", Id_));
|
||||
try {
|
||||
socket().sendBytes(outBuf, 4);
|
||||
socket_.sendBytes(outBuf, 4);
|
||||
return true;
|
||||
} catch (...) {
|
||||
|
||||
@@ -246,7 +300,7 @@ namespace OpenWifi {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string RTTY_Device_ConnectionHandler::ReadString() {
|
||||
std::string RTTYS_Device_ConnectionHandler::ReadString() {
|
||||
std::string Res;
|
||||
|
||||
while(inBuf_.used()) {
|
||||
@@ -261,16 +315,16 @@ namespace OpenWifi {
|
||||
return Res;
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::do_msgTypeRegister([[maybe_unused]] std::size_t msg_len) {
|
||||
socket().receiveBytes(inBuf_);
|
||||
id_ = ReadString();
|
||||
desc_ = ReadString();
|
||||
token_ = ReadString();
|
||||
serial_ = RTTYS_server()->SerialNumber(id_);
|
||||
bool RTTYS_Device_ConnectionHandler::do_msgTypeRegister([[maybe_unused]] std::size_t msg_len) {
|
||||
bool good = true;
|
||||
try {
|
||||
Id_ = ReadString();
|
||||
desc_ = ReadString();
|
||||
token_ = ReadString();
|
||||
|
||||
Poco::Thread::current()->setName(fmt::format("RTTY-device-thread-{}:{}:{}", conn_id_, id_, serial_));
|
||||
Logger().debug(fmt::format("{}: ID:{} Serial:{} Description:{} Device registration", conn_id_, id_, serial_, desc_));
|
||||
if (RTTYS_server()->Register(id_, token_, this)) {
|
||||
poco_information(Logger(),
|
||||
fmt::format("{}: Description:{} Device registration", Id_, desc_));
|
||||
RTTYS_server()->NotifyDeviceRegistration(Id_,token_,this);
|
||||
u_char OutBuf[8];
|
||||
OutBuf[0] = msgTypeRegister;
|
||||
OutBuf[1] = 0;
|
||||
@@ -279,18 +333,20 @@ namespace OpenWifi {
|
||||
OutBuf[4] = 'O';
|
||||
OutBuf[5] = 'K';
|
||||
OutBuf[6] = 0;
|
||||
if(socket().sendBytes(OutBuf, 7) !=7) {
|
||||
Logger().debug(fmt::format("{}: ID:{} Serial:{} Description:{} Could not complete registration", conn_id_, id_, serial_, desc_));
|
||||
running_ = false;
|
||||
if (socket_.sendBytes(OutBuf, 7) != 7) {
|
||||
poco_information(Logger(),
|
||||
fmt::format("{}: Description:{} Could not send data to complete registration",
|
||||
Id_, desc_));
|
||||
good = false;
|
||||
}
|
||||
} else {
|
||||
Logger().debug(fmt::format("{}: ID:{} Serial:{} Description:{} Could not complete registration", conn_id_, id_, serial_, desc_));
|
||||
running_ = false;
|
||||
} catch (...) {
|
||||
good = false;
|
||||
}
|
||||
return good;
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::do_msgTypeLogin([[maybe_unused]] std::size_t msg_len) {
|
||||
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for login", conn_id_, id_, serial_));
|
||||
bool RTTYS_Device_ConnectionHandler::do_msgTypeLogin([[maybe_unused]] std::size_t msg_len) {
|
||||
poco_information(Logger(),fmt::format("{}: Asking for login", Id_));
|
||||
nlohmann::json doc;
|
||||
char Error;
|
||||
inBuf_.read(&Error, 1);
|
||||
@@ -298,62 +354,79 @@ namespace OpenWifi {
|
||||
doc["type"] = "login";
|
||||
doc["err"] = Error;
|
||||
const auto login_msg = to_string(doc);
|
||||
SendToClient(login_msg);
|
||||
return SendToClient(login_msg);
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::do_msgTypeLogout([[maybe_unused]] std::size_t msg_len) {
|
||||
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for logout", conn_id_, id_, serial_));
|
||||
bool RTTYS_Device_ConnectionHandler::do_msgTypeLogout([[maybe_unused]] std::size_t msg_len) {
|
||||
poco_information(Logger(),fmt::format("{}: Asking for logout", Id_));
|
||||
return true;
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::do_msgTypeTermData(std::size_t msg_len) {
|
||||
if(waiting_for_bytes_!=0) {
|
||||
auto to_read = std::min(inBuf_.used(),waiting_for_bytes_);
|
||||
inBuf_.read(&scratch_[0], to_read);
|
||||
SendToClient((u_char *)&scratch_[0], (int) to_read);
|
||||
if(to_read<waiting_for_bytes_)
|
||||
waiting_for_bytes_ -= to_read;
|
||||
else
|
||||
bool RTTYS_Device_ConnectionHandler::do_msgTypeTermData(std::size_t msg_len) {
|
||||
bool good;
|
||||
if(waiting_for_bytes_>0) {
|
||||
if(inBuf_.used()<waiting_for_bytes_) {
|
||||
waiting_for_bytes_ = waiting_for_bytes_ - inBuf_.used();
|
||||
good = SendToClient((unsigned char *)inBuf_.begin(), (int) inBuf_.used());
|
||||
if(!good) std::cout << "do_msgTypeTermData:1" << std::endl;
|
||||
inBuf_.drain();
|
||||
} else {
|
||||
good = SendToClient((unsigned char *)inBuf_.begin(), waiting_for_bytes_);
|
||||
if(!good) std::cout << "do_msgTypeTermData:2" << std::endl;
|
||||
inBuf_.drain(waiting_for_bytes_);
|
||||
waiting_for_bytes_ = 0 ;
|
||||
}
|
||||
} else {
|
||||
if(inBuf_.used()<msg_len) {
|
||||
auto read_count = inBuf_.read(&scratch_[0], inBuf_.used());
|
||||
SendToClient((u_char *)&scratch_[0], read_count);
|
||||
waiting_for_bytes_ = msg_len - read_count;
|
||||
good = SendToClient((unsigned char *)inBuf_.begin(), inBuf_.used());
|
||||
if(!good) std::cout << "do_msgTypeTermData:3" << std::endl;
|
||||
waiting_for_bytes_ = msg_len - inBuf_.used();
|
||||
inBuf_.drain();
|
||||
} else {
|
||||
inBuf_.read(&scratch_[0], msg_len);
|
||||
SendToClient((u_char *)&scratch_[0], (int)msg_len);
|
||||
waiting_for_bytes_=0;
|
||||
waiting_for_bytes_ = 0 ;
|
||||
good = SendToClient((unsigned char *)inBuf_.begin(), msg_len);
|
||||
if(!good) std::cout << "do_msgTypeTermData:4" << std::endl;
|
||||
inBuf_.drain(msg_len);
|
||||
}
|
||||
}
|
||||
return good;
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::do_msgTypeWinsize([[maybe_unused]] std::size_t msg_len) {
|
||||
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for msgTypeWinsize", conn_id_, id_, serial_));
|
||||
bool RTTYS_Device_ConnectionHandler::do_msgTypeWinsize([[maybe_unused]] std::size_t msg_len) {
|
||||
poco_information(Logger(),fmt::format("{}: Asking for msgTypeWinsize", Id_));
|
||||
return true;
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::do_msgTypeCmd([[maybe_unused]] std::size_t msg_len) {
|
||||
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for msgTypeCmd", conn_id_, id_, serial_));
|
||||
bool RTTYS_Device_ConnectionHandler::do_msgTypeCmd([[maybe_unused]] std::size_t msg_len) {
|
||||
poco_information(Logger(),fmt::format("{}: Asking for msgTypeCmd", Id_));
|
||||
return true;
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::do_msgTypeHeartbeat([[maybe_unused]] std::size_t msg_len) {
|
||||
bool RTTYS_Device_ConnectionHandler::do_msgTypeHeartbeat([[maybe_unused]] std::size_t msg_len) {
|
||||
// if(!RTTYS_server()->ValidClient(Id_))
|
||||
// return false;
|
||||
u_char MsgBuf[3]{0};
|
||||
MsgBuf[0] = msgTypeHeartbeat;
|
||||
socket().sendBytes(MsgBuf, 3);
|
||||
return socket_.sendBytes(MsgBuf, 3)==3;
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::do_msgTypeFile([[maybe_unused]] std::size_t msg_len) {
|
||||
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for msgTypeFile", conn_id_, id_, serial_));
|
||||
bool RTTYS_Device_ConnectionHandler::do_msgTypeFile([[maybe_unused]] std::size_t msg_len) {
|
||||
poco_information(Logger(),fmt::format("{}: Asking for msgTypeFile", Id_));
|
||||
return true;
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::do_msgTypeHttp([[maybe_unused]] std::size_t msg_len) {
|
||||
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for msgTypeHttp", conn_id_, id_, serial_));
|
||||
bool RTTYS_Device_ConnectionHandler::do_msgTypeHttp([[maybe_unused]] std::size_t msg_len) {
|
||||
poco_information(Logger(),fmt::format("{}: Asking for msgTypeHttp", Id_));
|
||||
return true;
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::do_msgTypeAck([[maybe_unused]] std::size_t msg_len) {
|
||||
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for msgTypeAck", conn_id_, id_, serial_));
|
||||
bool RTTYS_Device_ConnectionHandler::do_msgTypeAck([[maybe_unused]] std::size_t msg_len) {
|
||||
poco_information(Logger(),fmt::format("{}: Asking for msgTypeAck", Id_));
|
||||
return true;
|
||||
}
|
||||
|
||||
void RTTY_Device_ConnectionHandler::do_msgTypeMax([[maybe_unused]] std::size_t msg_len) {
|
||||
Logger().debug(fmt::format("{}: ID:{} Serial:{} Asking for msgTypeMax", conn_id_, id_, serial_));
|
||||
bool RTTYS_Device_ConnectionHandler::do_msgTypeMax([[maybe_unused]] std::size_t msg_len) {
|
||||
poco_information(Logger(),fmt::format("{}: Asking for msgTypeMax", Id_));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -7,78 +7,79 @@
|
||||
#include <array>
|
||||
#include "framework/MicroService.h"
|
||||
#include "Poco/FIFOBuffer.h"
|
||||
#include "Poco/Net/TCPServerConnectionFactory.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
inline static const std::size_t RTTY_DEVICE_BUFSIZE=64000;
|
||||
constexpr std::size_t RTTY_DEVICE_BUFSIZE=64000;
|
||||
|
||||
inline static std::atomic_uint64_t global_device_connection_id = 1;
|
||||
class RTTYS_Device_ConnectionHandler{
|
||||
public:
|
||||
enum RTTY_MSG_TYPE {
|
||||
msgTypeRegister = 0,
|
||||
msgTypeLogin,
|
||||
msgTypeLogout,
|
||||
msgTypeTermData,
|
||||
msgTypeWinsize,
|
||||
msgTypeCmd,
|
||||
msgTypeHeartbeat,
|
||||
msgTypeFile,
|
||||
msgTypeHttp,
|
||||
msgTypeAck,
|
||||
msgTypeMax };
|
||||
|
||||
class RTTY_Device_ConnectionHandler : public Poco::Net::TCPServerConnection {
|
||||
public:
|
||||
enum RTTY_MSG_TYPE {
|
||||
msgTypeRegister = 0,
|
||||
msgTypeLogin,
|
||||
msgTypeLogout,
|
||||
msgTypeTermData,
|
||||
msgTypeWinsize,
|
||||
msgTypeCmd,
|
||||
msgTypeHeartbeat,
|
||||
msgTypeFile,
|
||||
msgTypeHttp,
|
||||
msgTypeAck,
|
||||
msgTypeMax };
|
||||
explicit RTTYS_Device_ConnectionHandler(Poco::Net::StreamSocket& socket, Poco::Net::SocketReactor& reactor);
|
||||
~RTTYS_Device_ConnectionHandler();
|
||||
|
||||
explicit RTTY_Device_ConnectionHandler(const Poco::Net::StreamSocket & socket) ;
|
||||
~RTTY_Device_ConnectionHandler();
|
||||
bool Login();
|
||||
bool Logout();
|
||||
|
||||
void run() final;
|
||||
bool Login();
|
||||
bool Logout();
|
||||
void Stop();
|
||||
[[nodiscard]] bool SendToClient(const u_char *buf, int len);
|
||||
[[nodiscard]] bool SendToClient(const std::string &S);
|
||||
[[nodiscard]] bool WindowSize(int cols, int rows);
|
||||
[[nodiscard]] bool KeyStrokes(const u_char *buf, size_t len);
|
||||
std::string ReadString();
|
||||
// inline auto SessionID() const { return conn_id_; }
|
||||
|
||||
void SendToClient(const u_char *buf, int len);
|
||||
void SendToClient(const std::string &S);
|
||||
bool WindowSize(int cols, int rows);
|
||||
bool KeyStrokes(const u_char *buf, size_t len);
|
||||
std::string ReadString();
|
||||
inline auto SessionID() const { return conn_id_; }
|
||||
void AddCommand(u_char C);
|
||||
void onSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
|
||||
void onSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf);
|
||||
|
||||
private:
|
||||
std::atomic_bool running_=false;
|
||||
volatile std::atomic_bool loop_done_=false;
|
||||
std::string device_address_;
|
||||
std::recursive_mutex M_;
|
||||
Poco::Logger &Logger_;
|
||||
std::string id_;
|
||||
std::string token_;
|
||||
std::string desc_;
|
||||
std::string serial_;
|
||||
char sid_=0;
|
||||
Poco::FIFOBuffer inBuf_{64000};
|
||||
std::array<char,32000> scratch_{0};
|
||||
std::size_t waiting_for_bytes_{0};
|
||||
u_char last_command_=0;
|
||||
uint64_t conn_id_=0;
|
||||
std::vector<u_char> commands_;
|
||||
using My_mutex_type = std::recursive_mutex;
|
||||
using Guard = std::lock_guard<My_mutex_type>;
|
||||
|
||||
inline Poco::Logger & Logger() { return Logger_; }
|
||||
inline Poco::Logger &Logger() { return Logger_; }
|
||||
inline bool Valid() { return valid_; }
|
||||
|
||||
void do_msgTypeRegister(std::size_t msg_len);
|
||||
void do_msgTypeLogin(std::size_t msg_len);
|
||||
void do_msgTypeLogout(std::size_t msg_len);
|
||||
void do_msgTypeTermData(std::size_t msg_len);
|
||||
void do_msgTypeWinsize(std::size_t msg_len);
|
||||
void do_msgTypeCmd(std::size_t msg_len);
|
||||
void do_msgTypeHeartbeat(std::size_t msg_len);
|
||||
void do_msgTypeFile(std::size_t msg_len);
|
||||
void do_msgTypeHttp(std::size_t msg_len);
|
||||
void do_msgTypeAck(std::size_t msg_len);
|
||||
void do_msgTypeMax(std::size_t msg_len);
|
||||
private:
|
||||
Poco::Net::StreamSocket socket_;
|
||||
Poco::Net::SocketReactor &reactor_;
|
||||
Poco::FIFOBuffer inBuf_{RTTY_DEVICE_BUFSIZE};
|
||||
Poco::Logger &Logger_;
|
||||
|
||||
bool ProcessCommands();
|
||||
};
|
||||
std::atomic_bool valid_=false;
|
||||
Poco::Net::SocketAddress device_address_;
|
||||
My_mutex_type M_;
|
||||
std::string Id_;
|
||||
std::string token_;
|
||||
std::string desc_;
|
||||
char sid_=0;
|
||||
std::size_t waiting_for_bytes_{0};
|
||||
u_char last_command_=0;
|
||||
unsigned char small_buf_[64];
|
||||
|
||||
void EndConnection(bool SendNotification=true) ;
|
||||
void CompleteConnection();
|
||||
|
||||
[[nodiscard]] bool do_msgTypeRegister(std::size_t msg_len);
|
||||
[[nodiscard]] bool do_msgTypeLogin(std::size_t msg_len);
|
||||
[[nodiscard]] bool do_msgTypeLogout(std::size_t msg_len);
|
||||
[[nodiscard]] bool do_msgTypeTermData(std::size_t msg_len);
|
||||
[[nodiscard]] bool do_msgTypeWinsize(std::size_t msg_len);
|
||||
[[nodiscard]] bool do_msgTypeCmd(std::size_t msg_len);
|
||||
[[nodiscard]] bool do_msgTypeHeartbeat(std::size_t msg_len);
|
||||
[[nodiscard]] bool do_msgTypeFile(std::size_t msg_len);
|
||||
[[nodiscard]] bool do_msgTypeHttp(std::size_t msg_len);
|
||||
[[nodiscard]] bool do_msgTypeAck(std::size_t msg_len);
|
||||
[[nodiscard]] bool do_msgTypeMax(std::size_t msg_len);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ namespace OpenWifi {
|
||||
auto TcpServerParams = new Poco::Net::TCPServerParams();
|
||||
TcpServerParams->setMaxThreads(50);
|
||||
TcpServerParams->setMaxQueued(100);
|
||||
TcpServerParams->setThreadIdleTime(Poco::Timespan(10,0));
|
||||
|
||||
if(MicroService::instance().NoAPISecurity()) {
|
||||
Poco::Net::ServerSocket DeviceSocket(DSport, 64);
|
||||
DeviceSocket.setNoDelay(true);
|
||||
DeviceAcceptor_ = std::make_unique<Poco::Net::TCPServer>(new Poco::Net::TCPServerConnectionFactoryImpl<RTTY_Device_ConnectionHandler>(), DeviceSocket, TcpServerParams);
|
||||
DeviceAcceptor_ = std::make_unique<Poco::Net::SocketAcceptor<RTTYS_Device_ConnectionHandler>>(DeviceSocket,DeviceReactor_);
|
||||
} else {
|
||||
auto DeviceSecureContext = new Poco::Net::Context(Poco::Net::Context::SERVER_USE,
|
||||
KeyFileName, CertFileName, "",
|
||||
@@ -44,10 +44,10 @@ namespace OpenWifi {
|
||||
SSL_CTX_dane_enable(SSLCtxDevice);
|
||||
|
||||
Poco::Net::SecureServerSocket DeviceSocket(DSport, 64, DeviceSecureContext);
|
||||
DeviceSocket.setNoDelay(true);
|
||||
DeviceAcceptor_ = std::make_unique<Poco::Net::TCPServer>(new Poco::Net::TCPServerConnectionFactoryImpl<RTTY_Device_ConnectionHandler>(), DeviceSocket, TcpServerParams);
|
||||
DeviceAcceptor_ = std::make_unique<Poco::Net::SocketAcceptor<RTTYS_Device_ConnectionHandler>>(DeviceSocket,DeviceReactor_);
|
||||
}
|
||||
DeviceAcceptor_->start();
|
||||
DeviceReactorThread_.start(DeviceReactor_);
|
||||
Utils::SetThreadName(DeviceReactorThread_,"rt:devreactor");
|
||||
|
||||
auto WebServerHttpParams = new Poco::Net::HTTPServerParams;
|
||||
WebServerHttpParams->setMaxThreads(50);
|
||||
@@ -57,7 +57,7 @@ namespace OpenWifi {
|
||||
if(MicroService::instance().NoAPISecurity()) {
|
||||
Poco::Net::ServerSocket ClientSocket(CSport, 64);
|
||||
ClientSocket.setNoDelay(true);
|
||||
WebServer_ = std::make_unique<Poco::Net::HTTPServer>(new RTTY_Client_RequestHandlerFactory(ClientReactor_, Logger()), ClientSocket, WebServerHttpParams);
|
||||
WebServer_ = std::make_unique<Poco::Net::HTTPServer>(new RTTYS_Client_RequestHandlerFactory(Logger()), ClientSocket, WebServerHttpParams);
|
||||
} else {
|
||||
auto WebClientSecureContext = new Poco::Net::Context(Poco::Net::Context::SERVER_USE, KeyFileName, CertFileName,
|
||||
"", Poco::Net::Context::VERIFY_RELAXED);
|
||||
@@ -73,300 +73,232 @@ namespace OpenWifi {
|
||||
|
||||
Poco::Net::SecureServerSocket ClientSocket(CSport, 64, WebClientSecureContext);
|
||||
ClientSocket.setNoDelay(true);
|
||||
WebServer_ = std::make_unique<Poco::Net::HTTPServer>(new RTTY_Client_RequestHandlerFactory(ClientReactor_, Logger()), ClientSocket, WebServerHttpParams);
|
||||
WebServer_ = std::make_unique<Poco::Net::HTTPServer>(new RTTYS_Client_RequestHandlerFactory(Logger()), ClientSocket, WebServerHttpParams);
|
||||
};
|
||||
WebServer_->start();
|
||||
|
||||
ClientReactorThread_.setName("RTTYWebServerClientThread");
|
||||
ClientReactorThread_.start(ClientReactor_);
|
||||
Utils::SetThreadName(ClientReactorThread_,"rt:clntreactor");
|
||||
}
|
||||
|
||||
GCCallBack_ = std::make_unique<Poco::TimerCallback<RTTYS_server>>(*this, &RTTYS_server::onTimer);
|
||||
Timer_.setStartInterval(10 * 1000); // first run in 30 seconds
|
||||
Timer_.setPeriodicInterval(1 * 60 * 1000);
|
||||
Timer_.setStartInterval(30 * 1000); // first run in 30 seconds
|
||||
Timer_.setPeriodicInterval(20 * 1000);
|
||||
Timer_.start(*GCCallBack_);
|
||||
|
||||
NotificationManager_.start(*this);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RTTYS_server::Stop() {
|
||||
if(Internal_) {
|
||||
NotificationManagerRunning_=false;
|
||||
ResponseQueue_.wakeUpAll();
|
||||
NotificationManager_.wakeUp();
|
||||
NotificationManager_.join();
|
||||
Timer_.stop();
|
||||
WebServer_->stopAll();
|
||||
DeviceAcceptor_->stop();
|
||||
WebServer_->stop();
|
||||
DeviceAcceptor_->unregisterAcceptor();
|
||||
DeviceReactor_.stop();
|
||||
DeviceReactorThread_.join();
|
||||
ClientReactor_.stop();
|
||||
ClientReactorThread_.join();
|
||||
}
|
||||
}
|
||||
|
||||
void RTTYS_server::onTimer([[maybe_unused]] Poco::Timer & timer) {
|
||||
Logger().debug("Removing stale RTTY connection information.");
|
||||
std::lock_guard G(Mutex_);
|
||||
auto now = OpenWifi::Now();
|
||||
dump("GC ", std::cout);
|
||||
for(auto element=EndPoints_.begin();element!=EndPoints_.end();) {
|
||||
if( element->second.ShutdownComplete ||
|
||||
(element->second.ShuttingDown && (now-element->second.TimeStamp>60))) {
|
||||
poco_debug(Logger(),"Removing stale connections.");
|
||||
Utils::SetThreadName("rt:janitor");
|
||||
static int count = 0;
|
||||
// MutexLockerDbg L(__func__ ,M_);
|
||||
|
||||
std::unique_lock G(M_);
|
||||
for(auto element=EndPoints_.begin();element!=EndPoints_.end();) {
|
||||
if(element->second->TooOld()) {
|
||||
auto c = fmt::format("Removing {}. Serial: {} Device connection time: {}s. Client connection time: {}s",
|
||||
element->first,
|
||||
element->second->SerialNumber(),
|
||||
element->second->TimeDeviceConnected(),
|
||||
element->second->TimeClientConnected());
|
||||
Logger().information(c);
|
||||
TotalConnectedClientTime_ += element->second->TimeClientConnected();
|
||||
TotalConnectedDeviceTime_ += element->second->TimeDeviceConnected();
|
||||
element = EndPoints_.erase(element);
|
||||
} else {
|
||||
++element;
|
||||
}
|
||||
}
|
||||
dump("GC ", std::cout);
|
||||
FailedDevices.clear();
|
||||
FailedClients.clear();
|
||||
count++;
|
||||
if(count==10) {
|
||||
count=0;
|
||||
Logger().information(fmt::format("Total connections:{} Total Device Connection Time: {}s Total Client Connection Time: {}s Device failures: {} Client failures: {}",
|
||||
TotalEndPoints_,
|
||||
TotalConnectedDeviceTime_,
|
||||
TotalConnectedClientTime_,
|
||||
FaildedNumDevices_,
|
||||
FailedNumClients_));
|
||||
}
|
||||
}
|
||||
|
||||
void RTTYS_server::Register(const std::string &Id, RTTYS_ClientConnection *Client) {
|
||||
std::lock_guard G(Mutex_);
|
||||
dump("C REG--> ", std::cout);
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It!=EndPoints_.end()) {
|
||||
It->second.Client = Client;
|
||||
It->second.ClientConnected = OpenWifi::Now();
|
||||
dump("C REG--> ", std::cout);
|
||||
}
|
||||
dump("C Already REG--> ", std::cout);
|
||||
void RTTYS_server::CreateNewClient(Poco::Net::HTTPServerRequest &request,
|
||||
Poco::Net::HTTPServerResponse &response, const std::string &id) {
|
||||
|
||||
auto NewClient = new RTTYS_ClientConnection(request, response, ClientReactor_, id);
|
||||
NotifyClientRegistration(id,NewClient);
|
||||
}
|
||||
|
||||
bool RTTYS_server::Register(const std::string &Id, const std::string &Token, RTTY_Device_ConnectionHandler *Device) {
|
||||
std::lock_guard G(Mutex_);
|
||||
dump("D REG--> ", std::cout);
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It!=EndPoints_.end()) {
|
||||
It->second.Device = Device;
|
||||
It->second.Token = Token;
|
||||
It->second.DeviceConnected = OpenWifi::Now();
|
||||
Logger().information(fmt::format("Creating session: {}, device:'{}'",Id,It->second.SerialNumber));
|
||||
dump("D REG--> ", std::cout);
|
||||
return true;
|
||||
void RTTYS_server::run() {
|
||||
Utils::SetThreadName("rtty-mgr");
|
||||
NotificationManagerRunning_ = true;
|
||||
Poco::AutoPtr<Poco::Notification> NextNotification(ResponseQueue_.waitDequeueNotification());
|
||||
while (NextNotification && NotificationManagerRunning_) {
|
||||
auto Notification = dynamic_cast<RTTYS_Notification *>(NextNotification.get());
|
||||
if (Notification != nullptr) {
|
||||
std::unique_lock G(M_);
|
||||
auto It = EndPoints_.find(Notification->id_);
|
||||
if (It != EndPoints_.end()) {
|
||||
switch (Notification->type_) {
|
||||
case RTTYS_Notification_type::device_disconnection: {
|
||||
It->second->DisconnectDevice();
|
||||
} break;
|
||||
case RTTYS_Notification_type::client_disconnection: {
|
||||
It->second->DisconnectClient();
|
||||
} break;
|
||||
case RTTYS_Notification_type::device_registration: {
|
||||
auto ptr = std::unique_ptr<RTTYS_Device_ConnectionHandler>{Notification->device_};
|
||||
It->second->SetDevice(std::move(ptr));
|
||||
if(!It->second->Joined() && It->second->ValidClient()) {
|
||||
It->second->Join();
|
||||
It->second->Login();
|
||||
}
|
||||
} break;
|
||||
case RTTYS_Notification_type::client_registration: {
|
||||
auto ptr = std::unique_ptr<RTTYS_ClientConnection>{Notification->client_};
|
||||
It->second->SetClient(std::move(ptr));
|
||||
if(!It->second->Joined() && It->second->ValidDevice()) {
|
||||
It->second->Join();
|
||||
It->second->Login();
|
||||
}
|
||||
} break;
|
||||
case RTTYS_Notification_type::unknown: {
|
||||
} break;
|
||||
};
|
||||
} else {
|
||||
if(Notification->type_==RTTYS_Notification_type::device_registration) {
|
||||
FaildedNumDevices_++;
|
||||
auto ptr = std::unique_ptr<RTTYS_Device_ConnectionHandler>{Notification->device_};
|
||||
FailedDevices.push_back(std::move(ptr));
|
||||
} else if(Notification->type_==RTTYS_Notification_type::client_registration) {
|
||||
FailedNumClients_++;
|
||||
auto ptr = std::unique_ptr<RTTYS_ClientConnection>{Notification->client_};
|
||||
FailedClients.push_back(std::move(ptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
NextNotification = ResponseQueue_.waitDequeueNotification();
|
||||
}
|
||||
dump("D Already REG--> ", std::cout);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RTTYS_server::SendToClient(const std::string &Id, const u_char *Buf, std::size_t Len) {
|
||||
std::lock_guard G(Mutex_);
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It!=EndPoints_.end() && It->second.Client!= nullptr) {
|
||||
It->second.Client->SendData(Buf,Len);
|
||||
return true;
|
||||
std::shared_lock Guard(M_);
|
||||
try {
|
||||
auto It = EndPoints_.find(Id);
|
||||
if (It != EndPoints_.end()) {
|
||||
return It->second->SendToClient(Buf,Len);
|
||||
}
|
||||
} catch(const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
} catch (...) {
|
||||
std::cout << "Exception in SendToClient 1" << std::endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RTTYS_server::SendToClient(const std::string &Id, const std::string &s) {
|
||||
std::lock_guard G(Mutex_);
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It!=EndPoints_.end() && It->second.Client!= nullptr) {
|
||||
It->second.Client->SendData(s);
|
||||
return true;
|
||||
std::shared_lock Guard(M_);
|
||||
try {
|
||||
auto It = EndPoints_.find(Id);
|
||||
if (It != EndPoints_.end()) {
|
||||
return It->second->SendToClient(s);
|
||||
}
|
||||
} catch(const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
} catch (...) {
|
||||
std::cout << "Exception in SendToClient 2" << std::endl;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
void RTTYS_server::DeRegister(const std::string &Id, RTTYS_ClientConnection *Client) {
|
||||
std::lock_guard G(Mutex_);
|
||||
dump("C DEREG--> ", std::cout);
|
||||
bool RTTYS_server::ValidClient(const std::string &Id) {
|
||||
std::shared_lock Guard(M_);
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It!=EndPoints_.end() && It->second.Client==Client) {
|
||||
if(It->second.Device!= nullptr) {
|
||||
if(!It->second.ShuttingDown) {
|
||||
It->second.ShuttingDown = true;
|
||||
It->second.Device->Stop();
|
||||
} else {
|
||||
It->second.ShutdownComplete = true;
|
||||
}
|
||||
} else {
|
||||
if(!It->second.ShuttingDown) {
|
||||
It->second.ShuttingDown = true;
|
||||
} else {
|
||||
It->second.ShutdownComplete = true;
|
||||
}
|
||||
}
|
||||
It->second.ClientConnected=0;
|
||||
It->second.Client= nullptr;
|
||||
}
|
||||
dump("C DEREG--> ", std::cout);
|
||||
return It!=EndPoints_.end() && It->second->ValidClient();
|
||||
}
|
||||
|
||||
void RTTYS_server::DeRegisterDevice(const std::string &Id, RTTY_Device_ConnectionHandler *Device) {
|
||||
std::lock_guard G(Mutex_);
|
||||
dump("D DEREG--> ", std::cout);
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It!=EndPoints_.end() && It->second.Device==Device) {
|
||||
It->second.Device = nullptr;
|
||||
It->second.DeviceConnected = 0 ;
|
||||
if(It->second.Client!=nullptr) {
|
||||
if(!It->second.ShuttingDown) {
|
||||
It->second.ShuttingDown = true;
|
||||
It->second.Client->Close();
|
||||
} else {
|
||||
It->second.ShutdownComplete = true;
|
||||
}
|
||||
} else {
|
||||
if(!It->second.ShuttingDown) {
|
||||
It->second.ShuttingDown = true;
|
||||
} else {
|
||||
It->second.ShutdownComplete = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool RTTYS_server::SendKeyStrokes(const std::string &Id, const u_char *buffer, std::size_t len) {
|
||||
std::shared_lock Guard(M_);
|
||||
|
||||
dump("D DEREG--> ", std::cout);
|
||||
if(Device!= nullptr) {
|
||||
for (auto i = EndPoints_.begin(); i != EndPoints_.end(); i++) {
|
||||
if (i->second.Device == Device) {
|
||||
EndPoints_.erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
dump("D DEREG--> ", std::cout);
|
||||
}
|
||||
}
|
||||
|
||||
bool RTTYS_server::SendKeyStrokes(const std::string &Id, const u_char *buffer, std::size_t s) {
|
||||
std::lock_guard G(Mutex_);
|
||||
auto It=EndPoints_.find(Id);
|
||||
if(It==EndPoints_.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(It->second.Device!= nullptr)
|
||||
return It->second.Device->KeyStrokes(buffer,s);
|
||||
try {
|
||||
return It->second->KeyStrokes(buffer, len);
|
||||
} catch(const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
} catch (...) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RTTYS_server::WindowSize(const std::string &Id, int cols, int rows) {
|
||||
std::lock_guard G(Mutex_);
|
||||
std::shared_lock Guard(M_);
|
||||
auto It=EndPoints_.find(Id);
|
||||
if(It==EndPoints_.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(It->second.Device!= nullptr)
|
||||
return It->second.Device->WindowSize(cols,rows);
|
||||
try {
|
||||
return It->second->WindowSize(cols,rows);
|
||||
} catch(const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
} catch (...) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool RTTYS_server::CreateEndPoint(const std::string &Id, const std::string & Token, const std::string & UserName, const std::string & SerialNumber ) {
|
||||
std::lock_guard G(Mutex_);
|
||||
std::unique_lock Guard(M_);
|
||||
|
||||
EndPoint E;
|
||||
E.ShuttingDown = false;
|
||||
E.Token = Token;
|
||||
E.TimeStamp = OpenWifi::Now();
|
||||
E.SerialNumber = SerialNumber;
|
||||
E.UserName = UserName;
|
||||
EndPoints_[Id] = E;
|
||||
auto NewEP = std::make_unique<RTTYS_EndPoint>(Token, SerialNumber, UserName );
|
||||
EndPoints_[Id] = std::move(NewEP);
|
||||
++TotalEndPoints_;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string RTTYS_server::SerialNumber(const std::string & Id) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It==EndPoints_.end())
|
||||
return "";
|
||||
return It->second.SerialNumber;
|
||||
}
|
||||
|
||||
bool RTTYS_server::ValidId(const std::string &Token) {
|
||||
std::lock_guard G(Mutex_);
|
||||
std::shared_lock Guard(M_);
|
||||
return EndPoints_.find(Token) != EndPoints_.end();
|
||||
}
|
||||
|
||||
void RTTYS_server::LoginDone(const std::string & Id) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It==EndPoints_.end())
|
||||
return;
|
||||
Logger().information(fmt::format("User: {}, Serial: {} logged in.",It->second.UserName, It->second.SerialNumber ));
|
||||
}
|
||||
|
||||
bool RTTYS_server::ValidEndPoint(const std::string &Id, const std::string &Token) {
|
||||
std::lock_guard G(Mutex_);
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It==EndPoints_.end()) {
|
||||
return false;
|
||||
}
|
||||
uint64_t Now = OpenWifi::Now();
|
||||
return ((It->second.Token == Token) && ((Now-It->second.TimeStamp)<30));
|
||||
}
|
||||
|
||||
bool RTTYS_server::CanConnect( const std::string &Id, RTTYS_ClientConnection *Conn) {
|
||||
std::lock_guard G(Mutex_);
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It!=EndPoints_.end() && It->second.Client==Conn) {
|
||||
It->second.ClientConnected = OpenWifi::Now();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RTTYS_server::IsDeviceRegistered( const std::string &Id, const std::string &Token, [[maybe_unused]] RTTY_Device_ConnectionHandler *Conn) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It == EndPoints_.end() || It->second.Token != Token )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t RTTYS_server::DeviceSessionID(const std::string & Id) {
|
||||
auto it = EndPoints_.find(Id);
|
||||
if(it==EndPoints_.end()) {
|
||||
return 0;
|
||||
} else {
|
||||
if(it->second.Device== nullptr) {
|
||||
return 0;
|
||||
} else {
|
||||
return it->second.Device->SessionID();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool RTTYS_server::Login(const std::string & Id) {
|
||||
std::lock_guard G(Mutex_);
|
||||
std::shared_lock Guard(M_);
|
||||
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It == EndPoints_.end()) {
|
||||
auto ep = EndPoints_.find(Id);
|
||||
if(ep == EndPoints_.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(It->second.Device!= nullptr) {
|
||||
// std::cout << "login " << Id << " session " << It->second.Device->SessionID() << std::endl;
|
||||
// It->second.Device->AddCommand(RTTY_Device_ConnectionHandler::msgTypeLogin);
|
||||
// std::cout << "login done" << Id << std::endl;
|
||||
return It->second.Device->Login();
|
||||
try {
|
||||
return ep->second->Login();
|
||||
} catch(const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
} catch (...) {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RTTYS_server::Logout(const std::string & Id) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It == EndPoints_.end()) {
|
||||
return false;
|
||||
}
|
||||
if(It->second.Device!= nullptr)
|
||||
It->second.Device->Logout();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RTTYS_server::Close(const std::string & Id) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
auto It = EndPoints_.find(Id);
|
||||
if(It == EndPoints_.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(It->second.Device!= nullptr)
|
||||
It->second.Device->Stop();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,204 @@
|
||||
#include "Poco/Net/SocketReactor.h"
|
||||
#include "Poco/Net/SocketAcceptor.h"
|
||||
#include "Poco/Timer.h"
|
||||
#include "rttys/RTTYS_device.h"
|
||||
#include "rttys/RTTYS_ClientConnection.h"
|
||||
#include <shared_mutex>
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class RTTY_Device_ConnectionHandler;
|
||||
class RTTYS_Device_ConnectionHandler;
|
||||
class RTTYS_ClientConnection;
|
||||
|
||||
class RTTYS_server : public SubSystemServer
|
||||
template <typename T> class MutexLockerDbg {
|
||||
public:
|
||||
MutexLockerDbg(const std::string &name, T &L) :
|
||||
name_(name),
|
||||
L_(L)
|
||||
{
|
||||
std::cout << name_ << ":L:0:" << Poco::Thread::current()->name() << ":" << Poco::Thread::currentTid() << std::endl;
|
||||
L_.lock();
|
||||
std::cout << name_ << ":L:1:" << Poco::Thread::current()->name() << ":" << Poco::Thread::currentTid() << std::endl;
|
||||
}
|
||||
|
||||
~MutexLockerDbg() {
|
||||
std::cout << name_ << ":U:0:" << Poco::Thread::current()->name() << ":" << Poco::Thread::currentTid() << std::endl;
|
||||
L_.unlock();
|
||||
std::cout << name_ << ":U:1:" << Poco::Thread::current()->name() << ":" << Poco::Thread::currentTid() << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
T & L_;
|
||||
};
|
||||
|
||||
enum class RTTYS_Notification_type {
|
||||
unknown,
|
||||
device_disconnection,
|
||||
client_disconnection,
|
||||
client_registration,
|
||||
device_registration
|
||||
};
|
||||
|
||||
class RTTYS_Notification: public Poco::Notification {
|
||||
public:
|
||||
RTTYS_Notification(const RTTYS_Notification_type &type, const std::string &id,
|
||||
RTTYS_Device_ConnectionHandler * device) :
|
||||
type_(type),
|
||||
id_(id),
|
||||
device_(device) {
|
||||
}
|
||||
|
||||
RTTYS_Notification(const RTTYS_Notification_type &type, const std::string &id,
|
||||
RTTYS_ClientConnection * client) :
|
||||
type_(type),
|
||||
id_(id),
|
||||
client_(client) {
|
||||
}
|
||||
|
||||
RTTYS_Notification(const RTTYS_Notification_type &type,
|
||||
const std::string &id,
|
||||
const std::string &token,
|
||||
RTTYS_Device_ConnectionHandler * device) :
|
||||
type_(type),
|
||||
id_(id),
|
||||
token_(token),
|
||||
device_(device) {
|
||||
}
|
||||
|
||||
RTTYS_Notification_type type_=RTTYS_Notification_type::unknown;
|
||||
std::string id_;
|
||||
std::string token_;
|
||||
RTTYS_Device_ConnectionHandler *device_= nullptr;
|
||||
RTTYS_ClientConnection *client_ = nullptr;
|
||||
};
|
||||
|
||||
class RTTYS_EndPoint {
|
||||
public:
|
||||
RTTYS_EndPoint(const std::string &Token, const std::string &SerialNumber, const std::string &UserName ):
|
||||
Token_(Token),
|
||||
SerialNumber_(SerialNumber),
|
||||
UserName_(UserName)
|
||||
{
|
||||
Created_ = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
inline void SetClient(std::unique_ptr<RTTYS_ClientConnection> Client) {
|
||||
ClientConnected_ = std::chrono::high_resolution_clock::now();
|
||||
Client_ = std::move(Client);
|
||||
}
|
||||
|
||||
inline void SetDevice(std::unique_ptr<RTTYS_Device_ConnectionHandler> Device) {
|
||||
DeviceConnected_ = std::chrono::high_resolution_clock::now();
|
||||
Device_ = std::move(Device);
|
||||
}
|
||||
|
||||
inline bool Login() {
|
||||
if(Device_!= nullptr) {
|
||||
return Device_->Login();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RTTYS_EndPoint & operator=(RTTYS_EndPoint Other) {
|
||||
Other.Client_ = std::move(Client_);
|
||||
Other.Device_ = std::move(Device_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void DisconnectClient() {
|
||||
ClientDisconnected_ = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
inline void DisconnectDevice() {
|
||||
DeviceDisconnected_ = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool TooOld() {
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
|
||||
if(ClientDisconnected_!=std::chrono::time_point<std::chrono::high_resolution_clock>{0s} && (now-ClientDisconnected_)>15s) {
|
||||
if(DeviceDisconnected_==std::chrono::time_point<std::chrono::high_resolution_clock>{0s}) {
|
||||
DeviceDisconnected_ = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if(DeviceDisconnected_!=std::chrono::time_point<std::chrono::high_resolution_clock>{0s} && (now-DeviceDisconnected_)>15s) {
|
||||
if(ClientDisconnected_==std::chrono::time_point<std::chrono::high_resolution_clock>{0s}) {
|
||||
ClientDisconnected_ = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!Joined_ && (now-Created_)>30s) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// std::cout << ClientDisconnected_ << " " << ClientConnected_ << " " << DeviceDisconnected_ << " " << DeviceConnected_ << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SendToClient(const u_char *Buf, std::size_t Len) {
|
||||
if(Client_!= nullptr && Client_->Valid()) {
|
||||
Client_->SendData(Buf,Len);
|
||||
return true;
|
||||
}
|
||||
std::cout << "SendToClientFailure: " << (Client_!= nullptr) << " " << Client_->Valid() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool KeyStrokes(const u_char *buffer, std::size_t len) {
|
||||
if( Device_!= nullptr && Device_->Valid() )
|
||||
return Device_->KeyStrokes(buffer,len);
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool WindowSize( int cols, int rows) {
|
||||
if(Device_!= nullptr && Device_->Valid())
|
||||
return Device_->WindowSize(cols,rows);
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool ValidClient() const {
|
||||
return Client_!= nullptr && Client_->Valid();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool ValidDevice() const {
|
||||
return Device_!= nullptr && Device_->Valid();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool Joined() volatile const { return Joined_; }
|
||||
void Join() {
|
||||
Joined_=true;
|
||||
}
|
||||
|
||||
inline bool SendToClient(const std::string &S) {
|
||||
if(Client_!= nullptr && Client_->Valid()) {
|
||||
Client_->SendData(S);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const std::string & UserName() const { return UserName_; }
|
||||
[[nodiscard]] inline const std::string & SerialNumber() const { return SerialNumber_; }
|
||||
|
||||
[[nodiscard]] inline auto TimeDeviceConnected() const { return std::chrono::duration<double>{DeviceDisconnected_ - DeviceConnected_}.count(); }
|
||||
[[nodiscard]] inline auto TimeClientConnected() const { return std::chrono::duration<double>{ClientDisconnected_ - ClientConnected_}.count(); }
|
||||
|
||||
private:
|
||||
std::string Token_;
|
||||
std::string SerialNumber_;
|
||||
std::string UserName_;
|
||||
std::unique_ptr<RTTYS_ClientConnection> Client_;
|
||||
std::unique_ptr<RTTYS_Device_ConnectionHandler> Device_;
|
||||
std::string Id_;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock>
|
||||
Created_{0s},DeviceDisconnected_{0s},
|
||||
ClientDisconnected_{0s},DeviceConnected_{0s} ,ClientConnected_{0s};
|
||||
volatile bool Joined_=false;
|
||||
};
|
||||
|
||||
class RTTYS_server : public SubSystemServer, Poco::Runnable
|
||||
{
|
||||
public:
|
||||
static auto instance() {
|
||||
@@ -27,38 +218,35 @@ namespace OpenWifi {
|
||||
|
||||
inline auto UIAssets() { return RTTY_UIAssets_; }
|
||||
|
||||
void Register(const std::string &Id, RTTYS_ClientConnection *Client);
|
||||
void DeRegister(const std::string &Id, RTTYS_ClientConnection *Client);
|
||||
bool Register(const std::string &Id, const std::string &Token, RTTY_Device_ConnectionHandler *Device);
|
||||
void DeRegisterDevice(const std::string &Id, RTTY_Device_ConnectionHandler *Device);
|
||||
bool CreateEndPoint(const std::string &Id, const std::string & Token, const std::string & UserName, const std::string & SerialNumber );
|
||||
std::string SerialNumber(const std::string & Id);
|
||||
void LoginDone(const std::string & Id);
|
||||
bool ValidEndPoint(const std::string &Id, const std::string &Token);
|
||||
bool CanConnect( const std::string &Id, RTTYS_ClientConnection *Conn);
|
||||
bool IsDeviceRegistered( const std::string &Id, const std::string &Token, [[maybe_unused]] RTTY_Device_ConnectionHandler *Conn);
|
||||
bool Login(const std::string & Id_);
|
||||
bool Logout(const std::string & Id_);
|
||||
bool Close(const std::string & Id_);
|
||||
uint64_t DeviceSessionID(const std::string & Id);
|
||||
bool SendKeyStrokes(const std::string &Id, const u_char *buffer, std::size_t s);
|
||||
bool WindowSize(const std::string &Id, int cols, int rows);
|
||||
bool SendToClient(const std::string &id, const u_char *Buf, std::size_t Len);
|
||||
bool SendToClient(const std::string &id, const std::string &s);
|
||||
bool ValidClient(const std::string &id);
|
||||
bool ValidId(const std::string &Id);
|
||||
|
||||
struct EndPoint {
|
||||
std::string Token;
|
||||
RTTYS_ClientConnection * Client = nullptr;
|
||||
RTTY_Device_ConnectionHandler * Device = nullptr;
|
||||
uint64_t TimeStamp = OpenWifi::Now();
|
||||
uint64_t DeviceConnected = 0;
|
||||
uint64_t ClientConnected = 0;
|
||||
std::string UserName;
|
||||
std::string SerialNumber;
|
||||
bool ShuttingDown = false;
|
||||
bool ShutdownComplete = false;
|
||||
};
|
||||
void run() final;
|
||||
|
||||
inline void NotifyDeviceDisconnect(const std::string &id, RTTYS_Device_ConnectionHandler *device) {
|
||||
ResponseQueue_.enqueueNotification(new RTTYS_Notification(RTTYS_Notification_type::device_disconnection,id,device));
|
||||
}
|
||||
|
||||
inline void NotifyClientDisconnect(const std::string &id, RTTYS_ClientConnection *client) {
|
||||
ResponseQueue_.enqueueNotification(new RTTYS_Notification(RTTYS_Notification_type::client_disconnection,id,client));
|
||||
}
|
||||
|
||||
inline void NotifyDeviceRegistration(const std::string &id, const std::string &token, RTTYS_Device_ConnectionHandler *device) {
|
||||
ResponseQueue_.enqueueNotification(new RTTYS_Notification(RTTYS_Notification_type::device_registration,id,token,device));
|
||||
}
|
||||
|
||||
inline void NotifyClientRegistration(const std::string &id, RTTYS_ClientConnection *client) {
|
||||
ResponseQueue_.enqueueNotification(new RTTYS_Notification(RTTYS_Notification_type::client_registration,id,client));
|
||||
}
|
||||
|
||||
void CreateNewClient(Poco::Net::HTTPServerRequest &request,
|
||||
Poco::Net::HTTPServerResponse &response, const std::string &id);
|
||||
|
||||
void onTimer(Poco::Timer & timer);
|
||||
|
||||
@@ -66,28 +254,35 @@ namespace OpenWifi {
|
||||
return Internal_;
|
||||
}
|
||||
|
||||
inline void dump([[maybe_unused]] const char *ID, [[maybe_unused]] std::ostream &s) {
|
||||
/* for(const auto &[id,point]:EndPoints_) {
|
||||
s << ID << " ID: " << id << " C:" << (point.Client == nullptr) << " D:" << (point.Device== nullptr)
|
||||
<< " Shutting down: " << point.ShuttingDown
|
||||
<< " Shutdown: " << point.ShutdownComplete << std::endl;
|
||||
}
|
||||
*/
|
||||
}
|
||||
inline Poco::Net::SocketReactor & ClientReactor() { return ClientReactor_; }
|
||||
|
||||
private:
|
||||
// std::recursive_mutex M_;
|
||||
Poco::Net::SocketReactor ClientReactor_;
|
||||
Poco::Thread ClientReactorThread_;
|
||||
std::string RTTY_UIAssets_;
|
||||
std::atomic_bool Internal_ = false;
|
||||
Poco::Net::SocketReactor ClientReactor_;
|
||||
Poco::Net::SocketReactor DeviceReactor_;
|
||||
Poco::Thread ClientReactorThread_;
|
||||
std::string RTTY_UIAssets_;
|
||||
bool Internal_ = false;
|
||||
|
||||
std::map<std::string, EndPoint> EndPoints_; // id, endpoint
|
||||
std::map<std::string,std::unique_ptr<RTTYS_EndPoint>> EndPoints_; // id, endpoint
|
||||
std::unique_ptr<Poco::Net::HTTPServer> WebServer_;
|
||||
std::unique_ptr<Poco::Net::TCPServer> DeviceAcceptor_;
|
||||
std::unique_ptr<Poco::Net::SocketAcceptor<RTTYS_Device_ConnectionHandler>> DeviceAcceptor_;
|
||||
Poco::Thread DeviceReactorThread_;
|
||||
Poco::NotificationQueue ResponseQueue_;
|
||||
mutable bool NotificationManagerRunning_=false;
|
||||
Poco::Thread NotificationManager_;
|
||||
|
||||
Poco::Timer Timer_;
|
||||
std::unique_ptr<Poco::TimerCallback<RTTYS_server>> GCCallBack_;
|
||||
std::list<std::unique_ptr<RTTYS_Device_ConnectionHandler>> FailedDevices;
|
||||
std::list<std::unique_ptr<RTTYS_ClientConnection>> FailedClients;
|
||||
mutable std::shared_mutex M_;
|
||||
|
||||
uint64_t TotalEndPoints_=0;
|
||||
uint64_t FaildedNumDevices_=0;
|
||||
uint64_t FailedNumClients_=0;
|
||||
double TotalConnectedDeviceTime_=0.0;
|
||||
double TotalConnectedClientTime_=0.0;
|
||||
|
||||
|
||||
explicit RTTYS_server() noexcept:
|
||||
SubSystemServer("RTTY_Server", "RTTY-SVR", "rtty.server")
|
||||
|
||||
52
src/sdks/sdk_prov.h
Normal file
52
src/sdks/sdk_prov.h
Normal file
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// Created by stephane bourque on 2022-07-16.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "framework/MicroService.h"
|
||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||
|
||||
namespace OpenWifi::SDK::Prov {
|
||||
|
||||
inline bool GetSerialNumbersForVenueOfSerialNumber( const std::string & SerialNumber, Types::UUID_t &Venue, Types::StringVec & AdjacentSerialNumbers , Poco::Logger &Logger ) {
|
||||
OpenAPIRequestGet GetInventoryForSerialNumber( uSERVICE_PROVISIONING, "/api/v1/inventory/" + SerialNumber , {} , 30000);
|
||||
|
||||
auto CallResponse1 = Poco::makeShared<Poco::JSON::Object>();
|
||||
if(!GetInventoryForSerialNumber.Do(CallResponse1,"")) {
|
||||
Logger.error(fmt::format("{}: Cannot find serial number in inventory.", SerialNumber));
|
||||
return false;
|
||||
}
|
||||
|
||||
ProvObjects::InventoryTag Device;
|
||||
if(!Device.from_json(CallResponse1)) {
|
||||
Logger.error(fmt::format("{}: Invalid Inventory response.", SerialNumber));
|
||||
return false;
|
||||
}
|
||||
|
||||
Venue = Device.venue;
|
||||
|
||||
OpenAPIRequestGet GetInventoryForVenue( uSERVICE_PROVISIONING, "/api/v1/inventory" ,
|
||||
{
|
||||
{"serialOnly","true"},
|
||||
{"venue", Venue}
|
||||
}, 30000);
|
||||
|
||||
auto CallResponse2 = Poco::makeShared<Poco::JSON::Object>();
|
||||
if(!GetInventoryForVenue.Do(CallResponse2,"")) {
|
||||
Logger.error(fmt::format("{}: Cannot get inventory for venue.", SerialNumber));
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
OpenWifi::RESTAPI_utils::field_from_json(CallResponse2, "serialNumbers",
|
||||
AdjacentSerialNumbers);
|
||||
} catch(...) {
|
||||
Logger.error(fmt::format("{}: Cannot parse inventory list", SerialNumber));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -66,7 +66,7 @@ namespace OpenWifi {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Select(Sess);
|
||||
|
||||
std::string St{"SELECT FROM DefaultConfigs WHERE Name=?"};
|
||||
std::string St{"SELECT name FROM DefaultConfigs WHERE Name=?"};
|
||||
Select << ConvertParams(St) ,
|
||||
Poco::Data::Keywords::into(TmpName) ,
|
||||
Name;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenWifi {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Insert(Sess);
|
||||
|
||||
Logger().information("Device:" + Stats.SerialNumber + " Stats size:" + std::to_string(Stats.Data.size()));
|
||||
poco_debug(Logger(),"Device:" + Stats.SerialNumber + " Stats size:" + std::to_string(Stats.Data.size()));
|
||||
std::string St{"INSERT INTO Statistics ( " +
|
||||
DB_StatsSelectFields +
|
||||
" ) VALUES ( " +
|
||||
|
||||
54
templates/livinlab-radius.json
Normal file
54
templates/livinlab-radius.json
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"pools": [
|
||||
{
|
||||
"acctConfig": {
|
||||
"methodParameters": [],
|
||||
"monitor": false,
|
||||
"monitorMethod": "none",
|
||||
"servers": [
|
||||
{
|
||||
"ip": "69.157.193.71",
|
||||
"name": "svr1",
|
||||
"port": 1813,
|
||||
"weight": 10,
|
||||
"secret": "testing123"
|
||||
}
|
||||
],
|
||||
"strategy": "random"
|
||||
},
|
||||
"authConfig": {
|
||||
"methodParameters": [],
|
||||
"monitor": false,
|
||||
"monitorMethod": "none",
|
||||
"servers": [
|
||||
{
|
||||
"ip": "69.157.193.71",
|
||||
"name": "svr1",
|
||||
"port": 1812,
|
||||
"weight": 10,
|
||||
"secret": "testing123"
|
||||
}
|
||||
],
|
||||
"strategy": "weighted"
|
||||
},
|
||||
"coaConfig": {
|
||||
"methodParameters": [],
|
||||
"monitor": false,
|
||||
"monitorMethod": "none",
|
||||
"servers": [
|
||||
{
|
||||
"ip": "69.157.193.71",
|
||||
"name": "svr1",
|
||||
"port": 3799,
|
||||
"weight": 10,
|
||||
"secret": "testing123"
|
||||
}
|
||||
],
|
||||
"strategy": "round_robin"
|
||||
},
|
||||
"description": "master pool",
|
||||
"name": "master",
|
||||
"useByDefault" : true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -536,15 +536,18 @@ rtty() {
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
jq < ${result_file}
|
||||
|
||||
cid=$(cat ${result_file} | jq -r '.connectionId')
|
||||
vport=$(cat ${result_file} | jq -r '.viewport')
|
||||
server=$(cat ${result_file} | jq -r '.server')
|
||||
url=https://${server}:${vport}/connect/${cid}
|
||||
|
||||
findbrowser
|
||||
if [[ "${browser}" != "" ]]
|
||||
if [[ "$2" != "noconnect" ]]
|
||||
then
|
||||
${browser} ${url}
|
||||
cid=$(cat ${result_file} | jq -r '.connectionId')
|
||||
vport=$(cat ${result_file} | jq -r '.viewport')
|
||||
server=$(cat ${result_file} | jq -r '.server')
|
||||
url=https://${server}:${vport}/connect/${cid}
|
||||
|
||||
findbrowser
|
||||
if [[ "${browser}" != "" ]]
|
||||
then
|
||||
${browser} ${url}
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -659,6 +662,16 @@ runscript() {
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
deviceping() {
|
||||
payload="$(printf '{ "serialNumber": "%s" }' "$1" )"
|
||||
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/ping" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-d "$payload" > ${result_file}
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
caplist() {
|
||||
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/capabilities" \
|
||||
-H "Content-Type: application/json" \
|
||||
@@ -675,6 +688,23 @@ iptocountry() {
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
setradiusconfig() {
|
||||
curl ${FLAGS} -X PUT "https://${OWGW}/api/v1/radiusProxyConfig" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Accept: application/json" \
|
||||
-d "@${1}" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
getradiusconfig() {
|
||||
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/radiusProxyConfig" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
check_response() {
|
||||
|
||||
if [ -s "$1" ]; then
|
||||
@@ -839,15 +869,15 @@ help() {
|
||||
echo "setloglevel <sys> <level> Set the logging system level for individual subsystems."
|
||||
echo " sys:ufileuploader/websocket/storage/restapi/commandmanager/auth/deviceregistry/all"
|
||||
echo " level:none/fatal/critical/error/warning/notice/information/debug/trace"
|
||||
echo "getloglevels Get the log levels of all the subsystems"
|
||||
echo "getloglevels Get the log levels of all the subsystems"
|
||||
echo "getloglevelnames Get the list of log level names possible"
|
||||
echo "getsubsystemnames Get the subsystems that can be used when setting log levels."
|
||||
echo "getfile <serial> <uuid> <name> Get the file associated with trace command <uuid> for device <serial>"
|
||||
echo " The file will be saved with the name <name>"
|
||||
echo " The file will be saved with the name <name>"
|
||||
echo
|
||||
echo "rtty <serial> Get the details for an rtty session."
|
||||
echo "rtty <serial> <noconnect> Get the details for an rtty session."
|
||||
echo
|
||||
echo "laststats <serial> Get the last statistics for a device"
|
||||
echo "laststats <serial> Get the last statistics for a device"
|
||||
echo "neweststats <serial> Get the newest statistics for a device"
|
||||
echo
|
||||
echo "ouilookup <serial> Lookup an OUI"
|
||||
@@ -869,73 +899,76 @@ help() {
|
||||
|
||||
shopt -s nocasematch
|
||||
case "$1" in
|
||||
"getdevice") login; getdevice "$2"; logout ;;
|
||||
"help") login; help ; logout ;;
|
||||
"getcommand") login; getcommand "$2" ; logout ;;
|
||||
"deletecommand") login; deletecommand "$2" ; logout ;;
|
||||
"getcapabilities") login; getcapabilities "$2" ; logout ;;
|
||||
"deletecapabilities") login; deletecapabilities "$2" ; logout ;;
|
||||
"listdevices") login; listdevices ; logout ;;
|
||||
"deletedevice") login; deletedevice "$2" ; logout ;;
|
||||
"deleteoui") login; deleteoui "$2" ; logout ;;
|
||||
"createdevice") login; createdevice "$2" "$3" "$4" ; logout ;;
|
||||
"reboot") login; reboot "$2" ; logout ;;
|
||||
"getdevicestatus") login; getdevicestatus "$2" ; logout ;;
|
||||
"upgrade") login; upgrade "$2" "$3" ; logout ;;
|
||||
"factory") login; factory "$2" "$3" ; logout ;;
|
||||
"leds") login; leds "$2" "$3" "$4" ; logout ;;
|
||||
"listcommands") login; listcommands "$2" ; logout ;;
|
||||
"deletecommands") login; deletecommands "$2" ; logout ;;
|
||||
"configure") login; configure "$2" "$3" ; logout ;;
|
||||
"request") login; request "$2" "$3" ; logout ;;
|
||||
"wifiscan") login; wifiscan "$2" "$3" ; logout ;;
|
||||
"activescan") login; activescan "$2" "$3" ; logout ;;
|
||||
"trace") login; trace "$2" "$3" "$4" ; logout ;;
|
||||
"getstats") login; getstats "$2" ; logout ;;
|
||||
"getlogs") login; getlogs "$2" ; logout ;;
|
||||
"deletelogs") login; deletelogs "$2" ; logout ;;
|
||||
"gethealthchecks") login; gethealthchecks "$2" ; logout ;;
|
||||
"createdefaultconfig") login; createdefaultconfig "$2" "$3" "$4" ; logout ;;
|
||||
"getdefaultconfig") login; getdefaultconfig "$2" ; logout ;;
|
||||
"deletedefaultconfig") login; deletedefaultconfig "$2" ; logout ;;
|
||||
"listdefaultconfigs") login; listdefaultconfigs "$2" ; logout ;;
|
||||
"addblacklistdevice") login; addblacklistdevice "$2" "$3" ; logout ;;
|
||||
"deleteblacklistdevice") login; deleteblacklistdevice "$2" ; logout ;;
|
||||
"getblacklist") login; getblacklist ; logout ;;
|
||||
"modblacklistdevice") login; modblacklistdevice "$2" "$3" ; logout;;
|
||||
"eventqueue") login; eventqueue "$2" ; logout ;;
|
||||
"selectdevices") login; selectdevices "$2" ; logout ;;
|
||||
"deviceserialnumbers") login; deviceserialnumbers ; logout ;;
|
||||
"devicecount") login; devicecount ; logout ;;
|
||||
"deviceswithstatus") login; deviceswithstatus "$2" ; logout ;;
|
||||
"getdevicecomplete") login; getdevicecomplete "$2" ; logout ;;
|
||||
"getfile") login; getfile "$2" "$3" ; logout ;;
|
||||
"rtty") login; rtty "$2" ; logout ;;
|
||||
"laststats") login; laststats "$2"; logout;;
|
||||
"newestcommands") login; newestcommands "$2"; logout;;
|
||||
"neweststats") login; neweststats "$2"; logout;;
|
||||
"newestlogs") login; newestlogs "$2"; logout;;
|
||||
"newesthealthchecks") login; newesthealthchecks "$2"; logout;;
|
||||
"lasthealthcheck") login; lasthealthcheck "$2"; logout;;
|
||||
"login") login ;;
|
||||
"findbrowser") findbrowser; echo "Browser: ${browser}" ;;
|
||||
"setloglevel") login; setloglevel "$2" "$3" ; logout ;;
|
||||
"getloglevels") login; getloglevels; logout ;;
|
||||
"getloglevelnames") login; getloglevelnames; logout ;;
|
||||
"getsubsystemnames") login; getsubsystemnames; logout ;;
|
||||
"reloadsubsystem") login; reloadsubsystem; logout ;;
|
||||
"systeminfo") login; systeminfo ; logout;;
|
||||
"ouilookup") login; ouilookup "$2"; logout;;
|
||||
"telemetry") login; telemetry "$2"; logout;;
|
||||
"telemetry_to_kafka") login; telemetry_to_kafka "$2" "$3"; logout;;
|
||||
"dashboard") login; dashboard ; logout;;
|
||||
"addnote") login; addnote "$2" "$3"; logout;;
|
||||
"ldevs") login; ldevs "$2" "$3"; logout ;;
|
||||
"validateconfig") login; validateconfig "$2" ; logout ;;
|
||||
"wstest") login; wstest; logout;;
|
||||
"caplist") login; caplist; logout;;
|
||||
"iptocountry") login; iptocountry $2; logout;;
|
||||
"test_service") login; test_service $2; logout;;
|
||||
"runscript") login; runscript $2 $3 $4; logout;;
|
||||
"getdevice") login; getdevice "$2"; logout ;;
|
||||
"help") login; help ; logout ;;
|
||||
"getcommand") login; getcommand "$2" ; logout ;;
|
||||
"deletecommand") login; deletecommand "$2" ; logout ;;
|
||||
"getcapabilities") login; getcapabilities "$2" ; logout ;;
|
||||
"deletecapabilities") login; deletecapabilities "$2" ; logout ;;
|
||||
"listdevices") login; listdevices ; logout ;;
|
||||
"deletedevice") login; deletedevice "$2" ; logout ;;
|
||||
"deleteoui") login; deleteoui "$2" ; logout ;;
|
||||
"createdevice") login; createdevice "$2" "$3" "$4" ; logout ;;
|
||||
"reboot") login; reboot "$2" ; logout ;;
|
||||
"getdevicestatus") login; getdevicestatus "$2" ; logout ;;
|
||||
"upgrade") login; upgrade "$2" "$3" ; logout ;;
|
||||
"factory") login; factory "$2" "$3" ; logout ;;
|
||||
"leds") login; leds "$2" "$3" "$4" ; logout ;;
|
||||
"listcommands") login; listcommands "$2" ; logout ;;
|
||||
"deletecommands") login; deletecommands "$2" ; logout ;;
|
||||
"configure") login; configure "$2" "$3" ; logout ;;
|
||||
"request") login; request "$2" "$3" ; logout ;;
|
||||
"wifiscan") login; wifiscan "$2" "$3" ; logout ;;
|
||||
"activescan") login; activescan "$2" "$3" ; logout ;;
|
||||
"trace") login; trace "$2" "$3" "$4" ; logout ;;
|
||||
"getstats") login; getstats "$2" ; logout ;;
|
||||
"getlogs") login; getlogs "$2" ; logout ;;
|
||||
"deletelogs") login; deletelogs "$2" ; logout ;;
|
||||
"gethealthchecks") login; gethealthchecks "$2" ; logout ;;
|
||||
"createdefaultconfig") login; createdefaultconfig "$2" "$3" "$4" ; logout ;;
|
||||
"getdefaultconfig") login; getdefaultconfig "$2" ; logout ;;
|
||||
"deletedefaultconfig") login; deletedefaultconfig "$2" ; logout ;;
|
||||
"listdefaultconfigs") login; listdefaultconfigs "$2" ; logout ;;
|
||||
"addblacklistdevice") login; addblacklistdevice "$2" "$3" ; logout ;;
|
||||
"deleteblacklistdevice") login; deleteblacklistdevice "$2" ; logout ;;
|
||||
"getblacklist") login; getblacklist ; logout ;;
|
||||
"modblacklistdevice") login; modblacklistdevice "$2" "$3" ; logout;;
|
||||
"eventqueue") login; eventqueue "$2" ; logout ;;
|
||||
"selectdevices") login; selectdevices "$2" ; logout ;;
|
||||
"deviceserialnumbers") login; deviceserialnumbers ; logout ;;
|
||||
"devicecount") login; devicecount ; logout ;;
|
||||
"deviceswithstatus") login; deviceswithstatus "$2" ; logout ;;
|
||||
"getdevicecomplete") login; getdevicecomplete "$2" ; logout ;;
|
||||
"getfile") login; getfile "$2" "$3" ; logout ;;
|
||||
"rtty") login; rtty "$2" "$3" ; logout ;;
|
||||
"laststats") login; laststats "$2"; logout;;
|
||||
"newestcommands") login; newestcommands "$2"; logout;;
|
||||
"neweststats") login; neweststats "$2"; logout;;
|
||||
"newestlogs") login; newestlogs "$2"; logout;;
|
||||
"newesthealthchecks") login; newesthealthchecks "$2"; logout;;
|
||||
"lasthealthcheck") login; lasthealthcheck "$2"; logout;;
|
||||
"login") login ;;
|
||||
"findbrowser") findbrowser; echo "Browser: ${browser}" ;;
|
||||
"setloglevel") login; setloglevel "$2" "$3" ; logout ;;
|
||||
"getloglevels") login; getloglevels; logout ;;
|
||||
"getloglevelnames") login; getloglevelnames; logout ;;
|
||||
"getsubsystemnames") login; getsubsystemnames; logout ;;
|
||||
"reloadsubsystem") login; reloadsubsystem; logout ;;
|
||||
"systeminfo") login; systeminfo ; logout;;
|
||||
"ouilookup") login; ouilookup "$2"; logout;;
|
||||
"telemetry") login; telemetry "$2"; logout;;
|
||||
"telemetry_to_kafka") login; telemetry_to_kafka "$2" "$3"; logout;;
|
||||
"dashboard") login; dashboard ; logout;;
|
||||
"addnote") login; addnote "$2" "$3"; logout;;
|
||||
"ldevs") login; ldevs "$2" "$3"; logout ;;
|
||||
"validateconfig") login; validateconfig "$2" ; logout ;;
|
||||
"wstest") login; wstest; logout;;
|
||||
"caplist") login; caplist; logout;;
|
||||
"iptocountry") login; iptocountry $2; logout;;
|
||||
"test_service") login; test_service $2; logout;;
|
||||
"runscript") login; runscript $2 $3 $4; logout;;
|
||||
"getradiusconfig") login; getradiusconfig ; logout;;
|
||||
"setradiusconfig") login; setradiusconfig $2; logout;;
|
||||
"deviceping") login; deviceping $2; logout;;
|
||||
*) help ;;
|
||||
esac
|
||||
|
||||
54
test_scripts/curl/living-lab-radius-config.json
Normal file
54
test_scripts/curl/living-lab-radius-config.json
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"pools": [
|
||||
{
|
||||
"acctConfig": {
|
||||
"methodParameters": [],
|
||||
"monitor": false,
|
||||
"monitorMethod": "none",
|
||||
"servers": [
|
||||
{
|
||||
"ip": "69.157.193.71",
|
||||
"name": "svr1",
|
||||
"port": 1813,
|
||||
"weight": 10,
|
||||
"secret": "testing123"
|
||||
}
|
||||
],
|
||||
"strategy": "random"
|
||||
},
|
||||
"authConfig": {
|
||||
"methodParameters": [],
|
||||
"monitor": false,
|
||||
"monitorMethod": "none",
|
||||
"servers": [
|
||||
{
|
||||
"ip": "69.157.193.71",
|
||||
"name": "svr1",
|
||||
"port": 1812,
|
||||
"weight": 10,
|
||||
"secret": "testing123"
|
||||
}
|
||||
],
|
||||
"strategy": "weighted"
|
||||
},
|
||||
"coaConfig": {
|
||||
"methodParameters": [],
|
||||
"monitor": false,
|
||||
"monitorMethod": "none",
|
||||
"servers": [
|
||||
{
|
||||
"ip": "69.157.193.71",
|
||||
"name": "svr1",
|
||||
"port": 3799,
|
||||
"weight": 10,
|
||||
"secret": "testing123"
|
||||
}
|
||||
],
|
||||
"strategy": "round_robin"
|
||||
},
|
||||
"description": "master pool",
|
||||
"name": "master",
|
||||
"useByDefault" : true
|
||||
}
|
||||
]
|
||||
}
|
||||
50
test_scripts/curl/living_lab_radius_config.json
Normal file
50
test_scripts/curl/living_lab_radius_config.json
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"pools" : [
|
||||
{
|
||||
"name" : "master" ,
|
||||
"description" : "master pool",
|
||||
"authConfig" : {
|
||||
"strategy" : "weighted",
|
||||
"monitor" : false,
|
||||
"monitorMethod" : "none",
|
||||
"methodParameters" : [],
|
||||
"servers" : [ {
|
||||
"name" : "svr1",
|
||||
"ip" : "69.157.193.71",
|
||||
"port" : 1812,
|
||||
"weight" : 10,
|
||||
"secret" : "my_secret!"
|
||||
}
|
||||
]
|
||||
},
|
||||
"acctConfig" : {
|
||||
"strategy" : "random",
|
||||
"monitor" : false,
|
||||
"monitorMethod" : "none",
|
||||
"methodParameters" : [],
|
||||
"servers" : [ {
|
||||
"name" : "svr1",
|
||||
"ip" : "69.157.193.71",
|
||||
"port" : 1813,
|
||||
"weight" : 10,
|
||||
"secret" : "my_secret!"
|
||||
}
|
||||
]
|
||||
},
|
||||
"coaConfig" : {
|
||||
"strategy" : "round_robin",
|
||||
"monitor" : false,
|
||||
"monitorMethod" : "none",
|
||||
"methodParameters" : [],
|
||||
"servers" : [ {
|
||||
"name" : "svr1",
|
||||
"ip" : "69.157.193.71",
|
||||
"port" : 3799,
|
||||
"weight" : 10,
|
||||
"secret" : "my_secret!"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
64
test_scripts/curl/radius_config_sample.json
Normal file
64
test_scripts/curl/radius_config_sample.json
Normal file
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"pools" : [
|
||||
{
|
||||
"name" : "master" ,
|
||||
"description" : "master pool",
|
||||
"authConfig" : {
|
||||
"strategy" : "weighted",
|
||||
"monitor" : false,
|
||||
"monitorMethod" : "none",
|
||||
"methodParameters" : [],
|
||||
"servers" : [ {
|
||||
"name" : "svr1",
|
||||
"ip" : "10.100.0.1",
|
||||
"port" : 1812,
|
||||
"weight" : 10
|
||||
},
|
||||
{
|
||||
"name" : "svr2",
|
||||
"ip" : "10.100.10.1",
|
||||
"port" : 1812,
|
||||
"weight" : 20
|
||||
}
|
||||
]
|
||||
},
|
||||
"acctConfig" : {
|
||||
"strategy" : "random",
|
||||
"monitor" : false,
|
||||
"monitorMethod" : "none",
|
||||
"methodParameters" : [],
|
||||
"servers" : [ {
|
||||
"name" : "svr1",
|
||||
"ip" : "10.100.0.1",
|
||||
"port" : 1813,
|
||||
"weight" : 10
|
||||
},
|
||||
{
|
||||
"name" : "svr2",
|
||||
"ip" : "10.100.10.1",
|
||||
"port" : 1813,
|
||||
"weight" : 20 }
|
||||
]
|
||||
},
|
||||
"coaConfig" : {
|
||||
"strategy" : "round_robin",
|
||||
"monitor" : false,
|
||||
"monitorMethod" : "none",
|
||||
"methodParameters" : [],
|
||||
"servers" : [ {
|
||||
"name" : "svr1",
|
||||
"ip" : "10.100.0.1",
|
||||
"port" : 3799,
|
||||
"weight" : 10
|
||||
},
|
||||
{
|
||||
"name" : "svr2",
|
||||
"ip" : "10.100.10.1",
|
||||
"port" : 3799,
|
||||
"weight" : 20
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
14
test_scripts/curl/start_rttys.sh
Executable file
14
test_scripts/curl/start_rttys.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo "This test script "
|
||||
|
||||
echo "Getting all serial numbers.."
|
||||
./cli listdevices
|
||||
cp result.json devices.json
|
||||
jq -r '.devices[].serialNumber' devices.json > serialNumbers
|
||||
while IFS= read -r serialNumber
|
||||
do
|
||||
echo "Serial Number: $serialNumber"
|
||||
./cli rtty "$serialNumber" noconnect
|
||||
done < serialNumbers
|
||||
|
||||
@@ -73,7 +73,7 @@ ucentral.autoprovisioning = true
|
||||
ucentral.devicetypes.0 = AP:linksys_ea8300,edgecore_eap101,linksys_e8450-ubi
|
||||
ucentral.devicetypes.1 = SWITCH:edgecore_ecs4100-12ph
|
||||
ucentral.devicetypes.2 = IOT:esp32
|
||||
oui.download.uri = https://linuxnet.ca/ieee/oui.txt
|
||||
oui.download.uri = https://standards-oui.ieee.org/oui/oui.txt
|
||||
firmware.autoupdate.policy.default = auto
|
||||
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user