Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
dt_ctrl
Commits
c43b8625
Commit
c43b8625
authored
Nov 12, 2013
by
Jeroen Vreeken
Browse files
Add command and shell handling to websocket module
Move all command and shell javascripts to websocket.
parent
b932dc78
Changes
15
Hide whitespace changes
Inline
Side-by-side
common/utils/tcp_connect.c
View file @
c43b8625
...
...
@@ -29,6 +29,7 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/sockios.h>
#include "tcp_connect.h"
...
...
@@ -108,3 +109,38 @@ int tcp_connect(char *host, int port)
// printf("Failed to connect\n");
return
sock
;
}
int
tcp_flushwrite
(
int
sock
)
{
int
retries
=
20
;
while
(
retries
--
)
{
int
outstanding
;
ioctl
(
sock
,
SIOCOUTQ
,
&
outstanding
);
if
(
!
outstanding
)
break
;
usleep
(
100000
);
}
return
0
;
}
int
tcp_flushread
(
int
sock
)
{
char
buffer
[
1024
];
int
retries
=
20
;
ioctl
(
sock
,
FIONBIO
,
&
(
int
){
1
});
while
(
retries
--
)
{
ssize_t
r
=
read
(
sock
,
buffer
,
1024
);
if
(
r
<
0
&&
errno
!=
EAGAIN
)
break
;
usleep
(
100000
);
}
return
0
;
}
common/utils/tcp_connect.h
View file @
c43b8625
...
...
@@ -3,4 +3,7 @@
int
tcp_connect
(
char
*
host
,
int
port
);
int
tcp_flushwrite
(
int
sock
);
int
tcp_flushread
(
int
sock
);
#endif
/* _INCLUDE_TCP_CONNECT_H_ */
console/console/Makefile
View file @
c43b8625
...
...
@@ -18,14 +18,14 @@ all: lib/libaa.la lib/libpredict.la \
setpoint.o console_joystick command_shell
\
spg_list spg_log_parser
\
console_moontracker
\
trace_proxy
trace.cgi_install
trace_log
\
trace_proxy trace_log
\
console_j2000tracker console_j2000tracer console_j2000_indi
\
log_proxy spg_auth console_idle console_zenith
\
console_suntracker console_azel console_manual
\
console_weather console_dt_model
\
await_controller
\
console_sattracker
\
status.cgi_install
command.cgi_install shell.cgi_install
\
status.cgi_install
\
mod_websocket_dt/mod_websocket_dt.so
\
...
...
@@ -76,13 +76,6 @@ console_zenith: console_zenith.o setpoint.o
trace_proxy
:
trace_proxy.o
trace.cgi
:
trace.cgi.o
trace.cgi_install
:
trace.cgi
@
echo
" CP trace.cgi"
@
cp
trace.cgi ../htdocs
trace_log
:
trace_log.o
log_proxy
:
log_proxy.o
...
...
@@ -92,18 +85,6 @@ spg_auth: spg_auth.o setpoint.o
console_sattracker_LDFLAGS
=
-lpthread
$(LIBNOVA)
-lm
-lpredict
console_sattracker
:
console_sattracker.o setpoint.o lib/libpredict.la
command.cgi
:
command.cgi.o
command.cgi_install
:
command.cgi
@
echo
" CP command.cgi"
@
cp
command.cgi ../htdocs
shell.cgi
:
shell.cgi.o
shell.cgi_install
:
shell.cgi
@
echo
" CP shell.cgi"
@
cp
shell.cgi ../htdocs
status.cgi
:
status.cgi.o
status.cgi_install
:
status.cgi
...
...
@@ -130,7 +111,6 @@ clean:
rm
-rf
*
.o
*
.d lib/
*
*
.lo
*
.a
*
.la .libs
rm
-f
\
await_controller
\
command.cgi
\
command_shell
\
console_joystick
\
console_dt_model
\
...
...
@@ -146,15 +126,13 @@ clean:
console_weather
\
console_zenith
\
log_proxy
\
shell.cgi
\
spg_auth
\
spg_list
\
spg_log_parser
\
status.cgi
\
trace_proxy
\
trace_proxy
\
trace_log
\
trace.cgi
trace_log
$(MAKE)
-C
aalib clean
$(MAKE)
-C
doc clean
$(MAKE)
-C
predictlib clean
...
...
console/console/command.cgi.c
deleted
100644 → 0
View file @
b932dc78
/*
HTTP frontend for commands
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2013
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "tcp_connect.h"
#include "dt_port_numbers.h"
#include "dt_host.h"
int
main
(
int
argc
,
char
**
argv
)
{
int
fd
;
char
buffer
[
1000
];
char
*
host
;
int
port
=
-
1
;
host
=
dt_host_console
();
fgets
(
buffer
,
sizeof
(
buffer
),
stdin
);
while
(
buffer
[
strlen
(
buffer
)
-
1
]
==
'\n'
)
buffer
[
strlen
(
buffer
)
-
1
]
=
0
;
if
(
!
strcmp
(
buffer
,
"sat"
))
port
=
CONSOLE_SAT_CMD_PORT
;
else
if
(
!
strcmp
(
buffer
,
"sun"
))
port
=
CONSOLE_SUN_CMD_PORT
;
else
if
(
!
strcmp
(
buffer
,
"moon"
))
port
=
CONSOLE_MOON_CMD_PORT
;
else
if
(
!
strcmp
(
buffer
,
"auth"
))
port
=
CONSOLE_ACTIVE_PORT
;
else
if
(
!
strcmp
(
buffer
,
"j2000"
))
port
=
CONSOLE_J2000_CMD_PORT
;
else
if
(
!
strcmp
(
buffer
,
"offset"
))
port
=
CONSOLE_OFFSET_PORT
;
else
if
(
!
strcmp
(
buffer
,
"azel"
))
port
=
CONSOLE_AZEL_PORT
;
else
if
(
!
strcmp
(
buffer
,
"manual"
))
port
=
CONSOLE_MANUAL_CMD_PORT
;
else
if
(
!
strcmp
(
buffer
,
"dt_model"
))
port
=
CONSOLE_DT_MODEL_CMD_PORT
;
alarm
(
10
);
fd
=
tcp_connect
(
host
,
port
);
if
(
fd
>=
0
)
{
ioctl
(
fd
,
FIONBIO
,
&
(
int
){
0
});
while
(
fgets
(
buffer
,
sizeof
(
buffer
),
stdin
))
write
(
fd
,
buffer
,
strlen
(
buffer
));
write
(
fd
,
"
\n
"
,
1
);
fsync
(
fd
);
printf
(
"Content-type: text/plain
\n
"
);
printf
(
"Cache-Control: no-cache
\n
"
);
printf
(
"Pragma: no-cache
\n
"
);
printf
(
"
\n
"
);
printf
(
"done
\n
"
);
}
else
{
printf
(
"Content-type: text/plain
\n
"
);
printf
(
"Cache-Control: no-cache
\n
"
);
printf
(
"Pragma: no-cache
\n
"
);
printf
(
"
\n
"
);
sleep
(
1
);
printf
(
"failed
\n
"
);
printf
(
"No response from %s:%d
\n
"
,
host
,
port
);
}
return
0
;
}
console/console/mod_websocket_dt/mod_websocket_dt.c
View file @
c43b8625
...
...
@@ -216,6 +216,35 @@ static void do_command(char *ident, char *command)
write
(
fd
,
"
\n
"
,
1
);
fsync
(
fd
);
tcp_flushwrite
(
fd
);
close
(
fd
);
}
}
static
void
do_shell
(
char
*
command
)
{
char
*
host
;
int
port
=
-
1
;
int
fd
;
host
=
dt_host_controller
();
port
=
CTRL_SHELL_PORT
;
fd
=
tcp_connect
(
host
,
port
);
if
(
fd
>=
0
)
{
ioctl
(
fd
,
FIONBIO
,
&
(
int
){
0
});
write
(
fd
,
command
,
strlen
(
command
));
fsync
(
fd
);
write
(
fd
,
"
\n
"
,
1
);
write
(
fd
,
"quit
\n
"
,
5
);
fsync
(
fd
);
tcp_flushwrite
(
fd
);
tcp_flushread
(
fd
);
close
(
fd
);
}
...
...
@@ -254,6 +283,16 @@ static size_t on_message(void *plugin_private,
sscanf
(
text
,
"%*s %as"
,
&
ident
);
command
=
text
+
strlen
(
cmd
)
+
strlen
(
ident
)
+
2
;
do_command
(
ident
,
command
);
free
(
ident
);
}
else
if
(
!
strcmp
(
cmd
,
"shell"
))
{
char
*
command
;
command
=
text
+
strlen
(
cmd
)
+
1
;
do_shell
(
command
);
}
else
{
server
->
send
(
priv
->
server
,
MESSAGE_TYPE_TEXT
,
buffer
,
buffer_size
);
}
free
(
cmd
);
...
...
console/console/shell.cgi.c
deleted
100644 → 0
View file @
b932dc78
/*
HTTP frontend for commands
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2013
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "tcp_connect.h"
#include "dt_port_numbers.h"
#include "dt_host.h"
int
main
(
int
argc
,
char
**
argv
)
{
int
fd
;
char
buffer
[
1000
];
char
*
host
;
int
port
=
-
1
;
host
=
dt_host_controller
();
port
=
CTRL_SHELL_PORT
;
alarm
(
10
);
fd
=
tcp_connect
(
host
,
port
);
if
(
fd
>=
0
)
{
ioctl
(
fd
,
FIONBIO
,
&
(
int
){
0
});
while
(
fgets
(
buffer
,
sizeof
(
buffer
),
stdin
))
{
write
(
fd
,
buffer
,
strlen
(
buffer
));
fsync
(
fd
);
}
write
(
fd
,
"
\n
"
,
1
);
write
(
fd
,
"quit
\n
"
,
5
);
fsync
(
fd
);
sleep
(
1
);
printf
(
"Content-type: text/plain
\n
"
);
printf
(
"Cache-Control: no-cache
\n
"
);
printf
(
"Pragma: no-cache
\n
"
);
printf
(
"
\n
"
);
printf
(
"done
\n
"
);
}
else
{
printf
(
"Content-type: text/plain
\n
"
);
printf
(
"Cache-Control: no-cache
\n
"
);
printf
(
"Pragma: no-cache
\n
"
);
printf
(
"
\n
"
);
sleep
(
1
);
printf
(
"failed
\n
"
);
printf
(
"No response from %s:%d
\n
"
,
host
,
port
);
}
return
0
;
}
console/console/trace.cgi.c
deleted
100644 → 0
View file @
b932dc78
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2008, 2009, 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2008, 2009, 2013
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <time.h>
#include "tcp_connect.h"
#include "dt_port_numbers.h"
#include "dt_host.h"
char
*
host
;
int
port
=
CONSOLE_TRACE_VAL_PORT
;
int
main
(
int
argc
,
char
**
argv
)
{
int
i
;
int
fd
;
int
r
;
char
buf
[
10
];
char
linebuf
[
1000
];
int
linepos
=
0
;
char
*
query
;
host
=
dt_host_console
();
fd
=
tcp_connect
(
host
,
port
);
query
=
getenv
(
"QUERY_STRING"
);
for
(
i
=
0
;
i
<
strlen
(
query
);
i
++
)
if
(
query
[
i
]
==
'&'
)
break
;
i
++
;
for
(;
i
<
strlen
(
query
)
+
1
;
i
++
)
if
(
query
[
i
]
==
'&'
)
write
(
fd
,
&
(
char
){
0
},
1
);
else
write
(
fd
,
&
query
[
i
],
1
);
write
(
fd
,
&
(
char
){
0
},
1
);
ioctl
(
fd
,
FIONBIO
,
&
(
int
){
0
});
while
((
r
=
read
(
fd
,
buf
,
1
)
>
0
))
{
linebuf
[
linepos
]
=
buf
[
0
];
linepos
++
;
}
linebuf
[
linepos
]
=
0
;
printf
(
"Content-type: text/plain
\n
"
);
printf
(
"Content-Length: %d
\n
"
,
linepos
);
printf
(
"Cache-Control: no-cache
\n
"
);
printf
(
"Pragma: no-cache
\n
"
);
printf
(
"
\n
"
);
printf
(
"%s"
,
linebuf
);
return
0
;
}
console/htdocs/auth.js
View file @
c43b8625
...
...
@@ -19,41 +19,14 @@
*/
function
auth_cb_default
(
object
,
line
)
{
/* default callback */
}
function
auth
(
url
,
ident
)
{
var
auth_this
=
this
;
/* Callbacks */
this
.
callback
=
auth_cb_default
;
this
.
xrequest
=
0
;
this
.
xrequest_prev
=
0
;
this
.
handle_xml
=
function
(
event
)
{
auth_this
.
callback
(
auth_this
,
event
.
target
.
responseText
);
}
this
.
url
=
url
;
this
.
ident
=
ident
;
this
.
open
=
function
(
command
)
this
.
open
=
function
open
(
command
)
{
if
(
auth_this
.
xrequest_prev
)
{
auth_this
.
xrequest
.
abort
();
delete
auth_this
.
xrequest
;
}
auth_this
.
xrequest
=
new
XMLHttpRequest
();
auth_this
.
xrequest
.
multipart
=
true
;
auth_this
.
xrequest
.
open
(
"
POST
"
,
this
.
url
+
"
?
"
+
command
,
true
);
auth_this
.
xrequest
.
onload
=
this
.
handle_xml
;
auth_this
.
xrequest
.
send
(
this
.
ident
+
"
\n
"
+
command
);
auth_this
.
xrequest_prev
=
1
;
dt_websocket_send
(
"
command
"
+
ident
+
"
"
+
command
);
}
}
console/htdocs/azel_command.js
View file @
c43b8625
...
...
@@ -19,46 +19,14 @@
*/
function
azel_command_cb_default
(
line
)
{
/* default callback */
}
function
azel_command
(
url
,
ident
)
{
var
azel_command_this
=
this
;
/* Callbacks */
this
.
callback
=
azel_command_cb_default
;
this
.
xrequest
=
0
;
this
.
xrequest_prev
=
0
;
this
.
handle_xml
=
function
azel_command_handle_xml
(
event
)
{
azel_command_this
.
callback
(
azel_command_this
,
event
.
target
.
responseText
);
azel_command_this
.
data_wd
=
1
;
}
this
.
url
=
url
;
this
.
ident
=
ident
;
this
.
open
=
function
azel_command_open
(
az
,
el
)
this
.
open
=
function
(
az
,
el
)
{
if
(
azel_command_this
.
xrequest_prev
)
{
azel_command_this
.
xrequest
.
abort
();
delete
azel_command_this
.
xrequest
;
}
azel_command_this
.
xrequest
=
new
XMLHttpRequest
();
azel_command_this
.
xrequest
.
multipart
=
true
;
azel_command_this
.
xrequest
.
open
(
"
POST
"
,
this
.
url
,
true
);
azel_command_this
.
xrequest
.
onload
=
this
.
handle_xml
;
azel_command_this
.
xrequest
.
send
(
this
.
ident
+
"
\n
"
+
dt_websocket_send
(
"
command
"
+
ident
+
"
"
+
az
+
"
"
+
el
);
azel_command_this
.
xrequest_prev
=
1
;
}
}
console/htdocs/dt_websocket.js
View file @
c43b8625
...
...
@@ -61,8 +61,10 @@ function dt_websocket(url)
dt_socket_onmessage
[
i
].
func
(
dt_socket_onmessage
[
i
].
obj
,
args
);
return
;
}
}
alert
(
"
no handler for:
"
+
msg
.
data
);
}
}
...
...
console/htdocs/index.html
View file @
c43b8625
...
...
@@ -771,25 +771,25 @@ var trace_url = "trace.cgi";
var
url_red
=
"
light_red.gif
"
;
var
url_green
=
"
light_green.gif
"
;
var
shell_url
=
"
shell.cgi
"
;
var
auth_url
=
"
command.cgi
"
;
var
auth_url
=
"
command.cgi
_auth
"
;
var
auth_status_url
=
"
status.cgi
"
;
var
offset_url
=
"
command.cgi
"
;
var
offset_url
=
"
command.cgi
_offset
"
;
var
azel_command_url
=
"
command.cgi
"
;
var
azel_command_url
=
"
command.cgi
_azel
"
;
var
j2000_status_url
=
"
status.cgi
"
;
var
j2000_command_url
=
"
command.cgi
"
;
var
j2000_command_url
=
"
command.cgi
_j2000
"
;
var
sat_status_url
=
"
status.cgi
"
;
var
sat_command_url
=
"
command.cgi
"
;
var
sat_command_url
=
"
command.cgi
_sat
"
;
var
sun_status_url
=
"
status.cgi
"
;
var
sun_command_url
=
"
command.cgi
"
;
var
sun_command_url
=
"
command.cgi
_sun
"
;
var
moon_status_url
=
"
status.cgi
"
;
var
moon_command_url
=
"
command.cgi
"
;
var
moon_command_url
=
"
command.cgi
_moon
"
;
var
manual_command_url
=
"
command.cgi
"
;
var
manual_command_url
=
"
command.cgi
_manual
"
;
...
...
@@ -2193,7 +2193,7 @@ log_draw();
*/
var
DT_model_status_url
=
"
status.cgi
"
;
var
DT_model_command_url
=
"
command.cgi
"
;
var
DT_model_command_url
=
"
command.cgi
_dt_model
"
;
var
DT_model_table
=
document
.
getElementById
(
'
DT_model_table
'
);
var
DT_model_show
=
document
.
getElementById
(
'
DT_model_show
'
);
...
...
console/htdocs/j2000_command.js
View file @
c43b8625
...
...
@@ -19,46 +19,15 @@
*/
function
j2000_command_cb_default
(
line
)
{
/* default callback */
}
function
j2000_command
(
url
,
ident
)
{
var
j2000_command_this
=
this
;
/* Callbacks */
this
.
callback
=
j2000_command_cb_default
;
this
.
xrequest
=
0
;
this
.
xrequest_prev
=
0
;
this
.
handle_xml
=
function
(
event
)
{
j2000_command_this
.
callback
(
j2000_command_this
,
event
.
target
.
responseText
);
j2000_command_this
.
data_wd
=
1
;
}
this
.
url
=
url
;
this
.
ident
=
ident
;
this
.
open
=
function
(
ra
,
dec
,
switches
)
{
if
(
j2000_command_this
.
xrequest_prev
)
{
j2000_command_this
.
xrequest
.
abort
();