Webinterface§
Web interface flask app for spc-eyepi, intended to be accessed by an end user.
Supports password authentication using bcrypt password hashing.
-
webinterface.
add_user
(username: str, password_to_set: str, adminpass: str = None) → bool[source]§ Creates a new user in the small db, or changes the password if it exists.
If the admin password is provided and matches the ‘admin’ users password hash in the db, allows adding of new users and modification of other users accounts.
Hashes passwords using
flask_bcrypt
before storing them in the db.TODO: this should be moved to
api
Parameters: Returns: whether the operation was sucessful
Return type:
-
webinterface.
after_this_request
(func)[source]§ Call after request helper.
Parameters: func (types.FunctionType) – function to call Returns: provided function Return type: types.FunctionType
-
webinterface.
authenticate
()[source]§ really this should just return a 404 for it to be really secure. But I use the message sometimes.
Returns: 401 Access Denied Response Return type: Response
-
webinterface.
available_networks
()[source]§ Gets the available networks doing a scan with … wlp6s0?
todo: get fluffybunny to fix this.
Returns: Streamed response of networks as they are enumerated by the scan, newline separated. Return type: Response
-
webinterface.
bad_auth
(error)[source]§ 401 error handler
Parameters: error – Returns: 401 page Return type: Response
-
webinterface.
break_the_interface
()[source]§ Intentionally load a nonexistent template to start the werkezeug interactive debugger
-
webinterface.
cap_lock_wait
(port: str, serialnumber: str) → bool[source]§ captures and writes an image to static/temp with the file name of the serial number.
todo: Does this even work? this is old and prbably broken FIX MEEEEE!
Parameters: Returns: whether a frame has been written to disk
Return type:
-
webinterface.
capture_preview
(serialnumber: str) → bool[source]§ capture a preview image once.
todo: see
cap_lock_wait()
Parameters: serialnumber – Returns: whether the capture was a success Return type: bool
-
webinterface.
change_hostname
()[source]§ Changes the hostname on the machine, including the /etc/hosts file. Also goes through all the configuration files looking for the old hostname.
Returns: string response indicating success or 400 response if form is incomplete or if writing files failed. Return type: str or Response
-
webinterface.
check_auth
(username: str, password: str) → bool[source]§ validataion of auth. Username and password are checked against the bcrypt password hash in the database.
Parameters: Returns: whether the supplied password matches the hash of the one stored in the database
Return type:
-
webinterface.
commit_ip
(ipaddress: str = None, subnet: str = None, gateway: str = None, dev='eth0')[source]§
-
webinterface.
delcfg
()[source]§ deletes a configuration file from the config directory.
Returns: string response indicating success or failure Return type: str
-
webinterface.
filemanagement
()[source]§ file management view
Information about the system storage status per block device, allows transfer of files to usb etc.
-
webinterface.
gen
(camera) → bytes[source]§ Video streaming generator function.
Intentionally limited to 10fps to account for bad quality connection and slow hardware.
this should be used as the argument for a
Response
along with the mimetype multipart/x-mixed-replace; boundary=frame to ensure that the browser correctly replaces the previous frame, and knows to continue to stream.Returns: image frame as encoded bytes, almost a complete response. Return type: bytes
-
webinterface.
get_hostname
() → str[source]§ Hostname of the system as a string.
Returns: the current hostname Return type: str
-
webinterface.
get_image
(path)[source]§ View to serve an image (like from a camera), from the static/temp directory.
the static/temp dir is normally symlinked to /dev/shm or /tmp, the location where the main capture script drops the last image.
Parameters: path (str) – path/name of the image, without the extension (.jpg is added) Returns: image response Return type: Response
-
webinterface.
get_resource
(selector, path)[source]§ serves css and js files from the static directory
Parameters: - selector – type of resource (“js” or “css”)
- path – name/path of the file.
Returns: file Response
Return type: Response
-
webinterface.
get_time
() → str[source]§ Almost iso8601 formatted time string.
Returns: time string formatted with ‘YYYY-MM-DD HH:mm:ss’ Return type: str
-
webinterface.
get_version
() → str[source]§ Current git version of spc-eyepi.
Returns: version Return type: str
-
webinterface.
getfilteredlog
()[source]§ API enpoint for getting a filtered log view.
TODO: move this to
api
-
webinterface.
images
()[source]§ Image preview view.
Allows the capture of a new image and replace in the client
-
webinterface.
ivport_feed
(cam_num)[source]§ Streaming from a specific picamera with the IVPort multiplexer
Actually calls
pi_feed()
, because the IVPOrt multiplexer works on the picamera.Returns: streamed image Response or emptystring (as per pi_feed) Return type: Response or str
-
webinterface.
ivport_switch
(cam_num) → str[source]§ Switch the current ivport picamera thread
Parameters: cam_num (int) – index to switch to. Returns: string of the camera number that was switched to Return type: str
-
webinterface.
logfile
()[source]§ log view function
TODO: do we have like 3 log page view functions? collect them into one.
-
webinterface.
make_dynamic
(dev: str)[source]§ disable static ip addressing using systemctl.
Dont use this, it is probably broken.
Parameters: dev (str) – device to change (eth0, wlp3s0 etc).
-
webinterface.
newuser
()[source]§ POST endpoint for adding a user.
Accepts ‘username’, ‘pass’, ‘adminpass’ form arguments.
Password has a minimum of 5 chars.
todo: this should be moved to
api
, and should be jsonified like a real api.Returns: string response indicating success or 400 response if request type is not POST. Return type: str
-
webinterface.
not_found
(error)[source]§ 404 error handler
Parameters: error – Returns: 404 page Return type: Response
-
webinterface.
per_request_callbacks
(response)[source]§ I have no idea what this does but it looks important
Parameters: response – ???
Returns: ???
-
webinterface.
pi_feed
()[source]§ Video streaming route for the raspberry pi camera.
Put this in the src attribute of an img tag.
Returns: streamed image Response or emptystring Return type: Response or str
-
webinterface.
pip_install
()[source]§ installs a package using pip.
Doesnt reload/restart anything, so after this is called, python needs to be restarted.
Returns: string response indicating success. Return type: str
-
webinterface.
preview
()[source]§ This gets a preview image from a camera, based on the url parameter “serialnumber”
so the endpoint wouild be /preview_cam?serialnumber=dfjkaghsdfysadftiqw
todo: see
cap_lock_wait()
Returns: the image file or the string “fail” Return type: Response or str
-
webinterface.
requires_auth
(f)[source]§ Decorator for wrapping a view and requiring auth.
Parameters: f (types.FunctionType) – view function Return decorated: wrapped Return type: types.FunctionType
-
webinterface.
reset_machine_id
()[source]§ Resets the machine-id to a random one generated by ‘systemd-machine-id-setup’.
Returns: str, json response {ERR: “error message”} if an error occurs, otherwise {} Return type: str
-
webinterface.
restart
()[source]§ Restarts the raspberry pi through reboot now system call.
Probably unsafe but whatever.
Returns: Response about rebooting Return type: Response
-
webinterface.
run_command
() → str[source]§ runs arbitrary commands from post data.
form_key: value command: space separayed list of arguments
Returns: str, json response of each command and the corresponding stdout (and stderr). Return type: str
-
webinterface.
sanitizeconfig
(towriteconfig, filename: str)[source]§ This method is meant to be a sanitiser for the configuration file, before it gets written.
Parameters: - towriteconfig (configparser.ConfigParser) – config object to write to disk.
- filename (str) – filename to write to.
-
webinterface.
savetousb
()[source]§ moves files in the ‘upload_dir’ specified in the config file, to a disk.
this will only work to move files to /dev/sda1.
Returns: whether the transfer was a success Return type: str
-
webinterface.
server_error
(error)[source]§ 500 error handler
Parameters: error – Returns: 500 page Return type: Response
-
webinterface.
set_ip
(ipaddress: str = None, subnet: str = None, gateway: str = None, dev: str = 'eth0')[source]§ sets a static ip address manually to the device specified.
Parameters: - ipaddress – ip address to commit
- subnet – subnet to user
- gateway – gateway to template
- dev – device to use TODO: actually make this do something
-
webinterface.
set_ips
()[source]§ POST endpoing for setting a static ip (or enabling dhcp).
the form accepts “ip-form-dynamic” as an on off flag to enable/disable dhcp.
Otherwise it requires ip-form-ipaddress, ip-form-subnet and ip-form-gateway to set the IP to them.
Returns: strin response indicating success Return type: str
-
webinterface.
stream
(lt, lc)[source]§ log line streaming endpoint
streams lines that contain lt until a count of lc is reached.
todo: Continue searching through archived logs.
TODO: move this to
api
Parameters: Returns:
-
webinterface.
sync_hwclock
()[source]§ synchronises the hardware clock with the system clock, and redirects to ‘config’ endpoint.
todo: move to
api
-
webinterface.
trunc_at
(s: str, d: str, n: int) → str[source]§ Parameters: Returns: s truncated at the n’th occurrence of the delimiter, d.
Return type:
-
webinterface.
update
()[source]§ Pulls the current version of SPC-eyepi from github, and replaces the one running with it.
Returns: string response indicating success. Return type: str
-
webinterface.
update_camera_config
(serialnumber: str)[source]§ Update camera config endpoint.
Exists to update the cameras configuration.
Parses many values.
Parameters: serialnumber – serialnumber of the camera to update Returns: response indicating result of operation Return type: Response
-
webinterface.
update_section
(section, key, value)[source]§ recurses into a nested dictionary or nested list and changes a value uses the “key” parameter thusly:
“somekey-1-2” would update the 3 in {“somekey”: [10, [1, 2, 3]]}Parameters: - section – nested dictionary or list
- key – string of recurse keys
- value – value to set the searched value for.
-
webinterface.
update_tag
(tag: str)[source]§ the same as update, except this can take a git tag to update to.
Parameters: tag (str) – git tag to update to. Returns: string response indicating success. Return type: str
-
webinterface.
wificonfig
()[source]§ wifi configuration view. Accepts a POST request with ‘ssid’ and ‘key’ which are used to create a netctl profile.
TODO: alter this to work with netctl-auto rather than vanilla netctl.
Returns: string response indicating success or 400 response if request type is not POST. Return type: str