Thanks for the encouragement Annie. A pengine controlled train set is also a tempting distraction lol.
Okay so I am a bit confused by the authentication.
At the moment the basic site is running from a raspberry pi, all this does is produce a page with an iframe which links to the
http://swish.swi-prolog.org/p/embed%20youtube%20test.swinb . The pi also runs an apache reverse proxy so that the site is available on the web. My router forwards port 80 traffic to the pi. The router also forwards port 6357 to the lego brick.
The webcam is handled by a separate pc, which sends the stream to youtube using OBS
So I think I want the authentication to be on the lego brick, so that any application on the web can connect. So I don't think
lib/authenticate.pl is the right tool because I am not securing the swish server as that is not under my control and I want to be able to have other prolog applications connect to the robot.
I am looking at your code here Annie
https://github.com/Anniepoo/swiplwebtut/blob/master/basic_authenticate_example.plMy current code is at the end of this email.
Would I change for example color/1 to:
color(Lines):-
http_current_request(Request),
( http_authenticate(basic(passwd), Request, _Fields)
-> true
; throw(http_reply(authorise(basic, harbinger_realm))) %not sure what harbinger_realm is..
),
setup_call_cleanup(
process_create(
path(python3),
['python_ev3/color_test2.py'],[stdout(pipe(Out))]),
read_lines(Out,Lines),
close(Out)).
I would have made a password file on the lego brick using:
add_uname_pw(Uname, PW) :-
http_read_passwd_file(passwd, Users),
crypt(PW, Hash),
http_write_passwd_file(passwd, [passwd(Uname, Hash, []) | Users]).
% start the passwd file with user adminuser password adminpw
start_pw_file :-
crypt(adminpw, Hash),
atom_codes(AHash, Hash),
http_write_passwd_file(passwd, [passwd(adminuser, AHash, [])]).
But how would a user send a username and password to the pengine? I am missing something simple? I think I need color/1 to be color_username_password/3? but I don't think that would be securely sent?
To make the pldoc available I guess I need to run doc_server(A_port_Number, [allow(X)]). on the brick, but what would X be and how would this need to be setup with the router? I am also not sure if the lego brick would cope with running two servers at the same time - its quite low powered.
Thanks for your help :)
The server code is server.pl:- use_module(library(pengines)).
:- use_module(library(http/http_unix_daemon)).
:- use_module(pengine_sandbox:test).
:- use_module(library(sandbox)).
:- multifile sandbox:safe_primitive/1.
sandbox:safe_primitive(test:open_claw(_)).
sandbox:safe_primitive(test:close_claw(_)).
sandbox:safe_primitive(test:arm_up(_)).
sandbox:safe_primitive(test:arm_down(_)).
sandbox:safe_primitive(test:centre(_)).
sandbox:safe_primitive(test:face_left(_)).
sandbox:safe_primitive(test:face_right(_)).
sandbox:safe_primitive(test:color(_)).
:- initialization http_daemon.
and test.pl:- module(test,[centre/1,
face_left/1,
face_right/1,
arm_up/1,
arm_down/1,
open_claw/1,
close_claw/1,
color/1
]).
color(Lines):-setup_call_cleanup(
process_create(
path(python3),
['python_ev3/color_test2.py'],[stdout(pipe(Out))]),
read_lines(Out,Lines),
close(Out)).
centre(Lines):-setup_call_cleanup(
process_create(
path(python3),
['python_ev3/centre.py'],[stdout(pipe(Out))]),
read_lines(Out,Lines),
close(Out)).
face_left(Lines):-setup_call_cleanup(
process_create(
path(python3),
['python_ev3/face_left.py'],[stdout(pipe(Out))]),
read_lines(Out,Lines),
close(Out)).
face_right(Lines):-setup_call_cleanup(
process_create(
path(python3),
['python_ev3/face_right.py'],[stdout(pipe(Out))]),
read_lines(Out,Lines),
close(Out)).
arm_up(Lines):-setup_call_cleanup(
process_create(
path(python3),
['python_ev3/arm_up.py'],[stdout(pipe(Out))]),
read_lines(Out,Lines),
close(Out)).
arm_down(Lines):-setup_call_cleanup(
process_create(
path(python3),
['python_ev3/arm_down.py'],[stdout(pipe(Out))]),
read_lines(Out,Lines),
close(Out)).
open_claw(Lines):-setup_call_cleanup(
process_create(
path(python3),
['python_ev3/open_claw.py'],[stdout(pipe(Out))]),
read_lines(Out,Lines),
close(Out)).
close_claw(Lines):-setup_call_cleanup(
process_create(
path(python3),
['python_ev3/close_claw.py'],[stdout(pipe(Out))]),