forked from PA7T/sdr_wspr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.conf
executable file
·163 lines (139 loc) · 7.35 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
location /start_wspr {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
default_type application/json;
content_by_lua '
local f = io.popen("systemctl enable redpitaya_wspr.service")
f:close()
local f = io.popen("systemctl start redpitaya_wspr.service")
f:close()
ngx.say("OK")
';
}
location /stop_wspr {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
default_type application/json;
content_by_lua '
local f = io.popen("systemctl stop redpitaya_wspr.service")
f:close()
local f = io.popen("systemctl disable redpitaya_wspr.service")
f:close()
ngx.say("OK")
';
}
location /store_wspr_config {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
default_type application/json;
content_by_lua '
function string:split( inSplitPattern, outResults )
if not outResults then
outResults = {}
end
local theStart = 1
local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
while theSplitStart do
table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
theStart = theSplitEnd + 1
theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
end
table.insert( outResults, string.sub( self, theStart ) )
return outResults
end
local args = ngx.req.get_uri_args()
local rc = args.rc or 0
local rl = args.rl or 0
local c = args.c or 0
local ppm = args.ppm or 0
local bands = args.bands or 0
local wlid = args.wlid or 0
local wlpw = args.wlpw or 0
os.execute("rw")
local f = io.open("/opt/redpitaya/www/apps/sdr_wspr/wspr-vars.sh","w+")
f:write("CALL="..rc.."\\nGRID="..rl.."\\nCOMMENT="..c.."\\nWLID="..wlid.."\\nWLPW="..wlpw.."")
f:close()
local f = io.open("/opt/redpitaya/www/apps/sdr_wspr/write-c2-files.cfg","w+")
f:write(string.format("corr = %s;\\n\\n",ppm))
f:write("bands = (\\n")
local bands_table = bands:split("|")
for i=1,#bands_table do
if i<#bands_table then
f:write(string.format(" { freq = %s; chan = 1; },\\n",bands_table[i]))
end
if i==#bands_table then
f:write(string.format(" { freq = %s; chan = 1; }\\n",bands_table[i]))
end
end
f:write(");\\n")
f:close()
os.execute("ro")
ngx.say("OK")
local f = io.popen("cp /opt/redpitaya/www/apps/sdr_wspr/redpitaya_wspr.service /etc/systemd/system")
local content = f:read("*all")
f:close()
ngx.say(content)
';
}
location /read_writec2filescfg {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Content-type' 'text/plain; charset=utf-8';
content_by_lua '
local args = ngx.req.get_uri_args()
local handle = io.open("/opt/redpitaya/www/apps/sdr_wspr/write-c2-files.cfg", "r");
local res = handle:read("*all");
io.close(handle);
ngx.say(res);
';
}
location /read_wspr_vars {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Content-type' 'text/plain; charset=utf-8';
content_by_lua '
local args = ngx.req.get_uri_args()
local handle = io.open("/opt/redpitaya/www/apps/sdr_wspr/wspr-vars.sh", "r");
local res = handle:read("*all");
io.close(handle);
ngx.say(res);
';
}
location /get_wspr_status {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
default_type application/json;
content_by_lua '
local f = io.popen("if [ $(( `pgrep -c wspr-server`)) -eq 0 ]; then echo inactive; else echo active; fi")
--local f = io.popen("systemctl is-active redpitaya_wspr.service")
local content = f:read("*all")
f:close()
ngx.say(content)
';
}
location /get_wspr_decodes {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
default_type application/json;
content_by_lua '
--local f = io.popen("cat /dev/shm/wspr_spots.txt | awk \'BEGIN { FS = "[ \s+]+" } { print $2 " " $7 " " $8 " " $4 }\'")
local f = io.popen("cat /dev/shm/wspr_spots.txt")
local content = f:read("*all")
f:close()
ngx.say(content)
';
}