Compare commits

...

16 Commits

Author SHA1 Message Date
Jeff Moe 751ec8388b mv ss 2022-05-02 22:49:48 -06:00
Jeff Moe 2a9d08da85 screenshot 2022-05-02 22:49:00 -06:00
Jeff Moe 9d3a8ff1d5 deb stable 2022-05-02 22:36:26 -06:00
Jeff Moe 287483db7a token 2022-05-02 22:29:30 -06:00
Jeff Moe 68719b6014 fw 8080 2022-05-02 22:25:40 -06:00
Jeff Moe 6a16f55b19 need esm 2022-05-02 22:23:54 -06:00
Jeff Moe 4a9b23dcd8 .env 2022-05-02 22:16:49 -06:00
Jeff Moe 8439d19ebd npm run 2022-05-02 22:16:40 -06:00
Jeff Moe cab8462dd8 setup stub 2022-05-02 22:11:39 -06:00
root fb9fadf67f readme stub 2022-05-02 20:27:28 -06:00
root 60c6829883 mv upstream README 2022-05-02 20:26:31 -06:00
AdamSBlack 48cc94819a
Merge remote-tracking branch 'origin/production' 2022-05-01 23:50:03 +01:00
AdamSBlack f68f76c237
lint 2022-05-01 23:35:55 +01:00
AdamSBlack 7ff8d5f190
Add settings api, update models 2022-05-01 23:08:16 +01:00
AdamSBlack 21067730dd
add user settings, add checkbox to share data on
/useradmin/overview page
2022-05-01 23:01:13 +01:00
AdamSBlack 0679c44b08
Removed older 2fa/oauth code in favour
of reworking
2022-04-30 16:11:09 +01:00
9 changed files with 201 additions and 112 deletions

106
README-upstream.md 100644
View File

@ -0,0 +1,106 @@
# retropilot-server
![Uptime Robot status](https://img.shields.io/uptimerobot/status/m791143178-df355c13f922c35db89054b0)
![Uptime Robot ratio (7 days)](https://img.shields.io/uptimerobot/ratio/7/m791143178-df355c13f922c35db89054b0)
![CI workflow](https://github.com/RetroPilot/retropilot-server/actions/workflows/ci.yml/badge.svg)
Replacement for comma.ai backend and useradmin dashboard. Bundled with a modified version of comma's cabana to allow viewing & analyzing drives.
If you don't want to host your own instance, check out https://api.retropilot.org/useradmin for a hosted version of the backend, useradmin and cabana.
### [Server] Summary
The server consists of 2 node scripts.
- `src/server` is using expressjs and runs the backend (file upload / communication with openpilot) and the useradmin dashboard to manage / view / download drives & logs.
- `src/worker` is a background worker that is processing drives (analyzing video files & logs) to prepare drives for playback in cabana and to gather statistics. It automatically terminates itself after 60 minutes to make sure the video/log libraries do not cause memory leaks.
**Attention:** Minimum required node version is **node 10**.
### [Server] Installation
TODO: write instructions for PostgreSQL database
```
npm install
cp config.sample.js config.js
cp database.empty.sqlite database.sqlite
> EDIT config.js
```
### [Server] Running
```
node -r esm src/server
```
```
node -r esm src/worker
```
### [Server] CABANA Support
A compiled version of a custom cabana fork (https://github.com/RetroPilot/cabana) is directly bundled in the `cabana/` subdirectory and will be served by the express app. After starting `index.js`, cabana is ready to use.
-----
### [Device] Preparation / Enable Custom Server
On the device or in your fork's code, replace all API endpoints with your own server endpoint.
This could be executed directly on the device in the shell to use `https://api.retropilot.org` as backend:
```
find /data/openpilot -type f -exec sed -i 's/https:\/\/api.commadotai.com/https:\/\/api.retropilot.org/g' {} +
```
TODO: add git patch instructions
### [Device] Swapping Servers (Back)
To switch a device between different servers, you have to remove the old `DongleId` and reboot:
```
rm /data/params/d/DongleID
reboot
```
There is no need to backup the `DongleId`, as the new server will identify your device based on its imei, serial and public key.
### [Device] Raw Drives Not Uploading (fcamera & rlog)
1. Raw data is only uploaded if the device is sufficiently charged, not connected to an active panda (offroad) and there are no immediate files (boot, crash, qcamera, qlog) remaining.<br>
2. Your branch might have raw uploads disabled, check *Device Settings > Upload Raw Logs*.
If that doesn't help or the option is not available, try:
```
echo "1" > /data/params/d/IsUploadRawEnabled
echo "1" > /data/params/d/UploadRaw
reboot
```
-----
### Current Limitations
OpenPilot before 0.8.3 will not display any statistics or pairing status in the dashboard.
The reason is that pre 0.8.3, the `offroad.apk` with react and comma-api would require recompilation to accept the new endpoints.
The athena websockets interface is not implemented yet, so the comma app and athena specific remote control commands (including "upload on demand") are not functional as of now.
### Screenshots
![image](https://user-images.githubusercontent.com/48515354/118385101-6bd64780-b60c-11eb-899d-bcb0b32e2939.png)
![image](https://user-images.githubusercontent.com/48515354/118385092-4ba68880-b60c-11eb-987e-2ca801b56caa.png)
![image](https://user-images.githubusercontent.com/48515354/118385075-2a459c80-b60c-11eb-976c-bc331a609391.png)
![image](https://user-images.githubusercontent.com/48515354/118385084-37fb2200-b60c-11eb-8d3e-6db458827808.png)
## Deployment
For deployment instructions and configuration, take a look at the `environment` directory.

140
README.md
View File

@ -1,106 +1,78 @@
# retropilot-server
This is a lesser fork of upstream retropilot-server.
![Uptime Robot status](https://img.shields.io/uptimerobot/status/m791143178-df355c13f922c35db89054b0)
![Uptime Robot ratio (7 days)](https://img.shields.io/uptimerobot/ratio/7/m791143178-df355c13f922c35db89054b0)
![CI workflow](https://github.com/RetroPilot/retropilot-server/actions/workflows/ci.yml/badge.svg)
# Screenshot
![Image](pics/web-screenshot.png)
Replacement for comma.ai backend and useradmin dashboard. Bundled with a modified version of comma's cabana to allow viewing & analyzing drives.
If you don't want to host your own instance, check out https://api.retropilot.org/useradmin for a hosted version of the backend, useradmin and cabana.
# Install
Docs for Debian stable (bullseye/11).
### [Server] Summary
The server consists of 2 node scripts.
- `src/server` is using expressjs and runs the backend (file upload / communication with openpilot) and the useradmin dashboard to manage / view / download drives & logs.
- `src/worker` is a background worker that is processing drives (analyzing video files & logs) to prepare drives for playback in cabana and to gather statistics. It automatically terminates itself after 60 minutes to make sure the video/log libraries do not cause memory leaks.
**Attention:** Minimum required node version is **node 10**.
### [Server] Installation
TODO: write instructions for PostgreSQL database
```
# Do as retropilot user
adduser retropilot
sudo su - retropilot
# Database / Postgres
sudo apt install postgresql
sudo -u postgres psql -c "CREATE DATABASE retropilot;"
sudo -u postgres psql -c "CREATE USER retropilot WITH password 'passwurd';"
sudo -u postgres psql -c "GRANT ALL privileges ON DATABASE retropilot TO retropilot;"
# Lookie:
sudo -u postgres psql
# As retropilot user
cat sql/create_tables.sql | psql -U retropilot -d retropilot
# take a look
psql -U retropilot -d retropilot
# pg commands, ala
\dT
# Install deps
sudo apt update
sudo apt install npm
# Clone fork
git clone git@spacecruft.org:retropilot/retropilot-server.git
cd retropilot-server
# Build thang
npm install
cp config.sample.js config.js
cp database.empty.sqlite database.sqlite
> EDIT config.js
```
# missing?
#cp config.sample.js config.js
# Perhaps:
cp -p .env.sample .env
vim .env
### [Server] Running
# Looks like this is needed ?
npm install esm
```
# In one term run:
node -r esm src/server
```
```
# In another term run:
node -r esm src/worker
```
### [Server] CABANA Support
A compiled version of a custom cabana fork (https://github.com/RetroPilot/cabana) is directly bundled in the `cabana/` subdirectory and will be served by the express app. After starting `index.js`, cabana is ready to use.
-----
### [Device] Preparation / Enable Custom Server
On the device or in your fork's code, replace all API endpoints with your own server endpoint.
This could be executed directly on the device in the shell to use `https://api.retropilot.org` as backend:
# Firewall, open port 8080
```
find /data/openpilot -type f -exec sed -i 's/https:\/\/api.commadotai.com/https:\/\/api.retropilot.org/g' {} +
```
TODO: add git patch instructions
# Use
Go to `http://192.168.1.1:8080` in your browser, using the
correct IP.
### [Device] Swapping Servers (Back)
To switch a device between different servers, you have to remove the old `DongleId` and reboot:
Create an account. Check `server.log` for the token, which appears
to be `verysecrettoken` by default. Then log in with that.
```
rm /data/params/d/DongleID
reboot
```
# Upstream
This is forked from RetroPilot:
There is no need to backup the `DongleId`, as the new server will identify your device based on its imei, serial and public key.
* https://github.com/retropilot/retropilot-server
### [Device] Raw Drives Not Uploading (fcamera & rlog)
See also `README-upstream.md`.
1. Raw data is only uploaded if the device is sufficiently charged, not connected to an active panda (offroad) and there are no immediate files (boot, crash, qcamera, qlog) remaining.<br>
2. Your branch might have raw uploads disabled, check *Device Settings > Upload Raw Logs*.
If that doesn't help or the option is not available, try:
```
echo "1" > /data/params/d/IsUploadRawEnabled
echo "1" > /data/params/d/UploadRaw
reboot
```
-----
### Current Limitations
OpenPilot before 0.8.3 will not display any statistics or pairing status in the dashboard.
The reason is that pre 0.8.3, the `offroad.apk` with react and comma-api would require recompilation to accept the new endpoints.
The athena websockets interface is not implemented yet, so the comma app and athena specific remote control commands (including "upload on demand") are not functional as of now.
### Screenshots
![image](https://user-images.githubusercontent.com/48515354/118385101-6bd64780-b60c-11eb-899d-bcb0b32e2939.png)
![image](https://user-images.githubusercontent.com/48515354/118385092-4ba68880-b60c-11eb-987e-2ca801b56caa.png)
![image](https://user-images.githubusercontent.com/48515354/118385075-2a459c80-b60c-11eb-976c-bc331a609391.png)
![image](https://user-images.githubusercontent.com/48515354/118385084-37fb2200-b60c-11eb-8d3e-6db458827808.png)
## Deployment
For deployment instructions and configuration, take a look at the `environment` directory.

26
package-lock.json generated
View File

@ -5,7 +5,6 @@
"requires": true,
"packages": {
"": {
"name": "retropilot-server",
"version": "1.0.0",
"dependencies": {
"@babel/cli": "^7.17.6",
@ -25,6 +24,7 @@
"crypto": "^1.0.1",
"directory-tree": "^2.2.9",
"dotenv": "^16.0.0",
"esm": "^3.2.25",
"express": "^4.17.3",
"express-fileupload": "^1.3.1",
"express-rate-limit": "^6.3.0",
@ -78,6 +78,8 @@
"integrity": "sha512-l4w608nsDNlxZhiJ5tE3DbNmr61fIKMZ6fTBo171VEFuFMIYuJ3mHRhTLEkKKyvx2Mizkkv/0a8OJOnZqkKYNA==",
"dependencies": {
"@jridgewell/trace-mapping": "^0.3.4",
"@nicolo-ribaudo/chokidar-2": "2.1.8-no-fsevents.3",
"chokidar": "^3.4.0",
"commander": "^4.0.1",
"convert-source-map": "^1.1.0",
"fs-readdir-recursive": "^1.1.0",
@ -3428,6 +3430,7 @@
"dependencies": {
"anymatch": "~3.1.2",
"braces": "~3.0.2",
"fsevents": "~2.3.2",
"glob-parent": "~5.1.2",
"is-binary-path": "~2.1.0",
"is-glob": "~4.0.1",
@ -4611,6 +4614,14 @@
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true
},
"node_modules/esm": {
"version": "3.2.25",
"resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz",
"integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==",
"engines": {
"node": ">=6"
}
},
"node_modules/espree": {
"version": "9.3.1",
"resolved": "https://registry.npmjs.org/espree/-/espree-9.3.1.tgz",
@ -6287,6 +6298,7 @@
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
"dependencies": {
"graceful-fs": "^4.1.6",
"universalify": "^2.0.0"
},
"optionalDependencies": {
@ -9183,8 +9195,10 @@
"resolved": "https://registry.npmjs.org/spm-agent-nodejs/-/spm-agent-nodejs-4.1.4.tgz",
"integrity": "sha512-pd/bV7H+rAISaqfm2JMn7n1DltIxJDzYy6yyqdw8QcIWfTqtPh+vpUdIlXXMFRzBNa4T5UwicUhVRmOx8MtFnA==",
"dependencies": {
"@sematext/gc-stats": "^1.5.2",
"adm-zip": "^0.4.14",
"measured-core": "^1.51.1",
"minimist": "^1.2.5",
"request": "^2.88.0",
"spm-agent": "^2.1.4"
},
@ -9221,6 +9235,7 @@
"hasInstallScript": true,
"dependencies": {
"node-addon-api": "^3.0.0",
"node-gyp": "3.x",
"node-pre-gyp": "^0.11.0"
},
"optionalDependencies": {
@ -9242,7 +9257,9 @@
"hasInstallScript": true,
"dependencies": {
"asn1": "^0.2.4",
"bcrypt-pbkdf": "^1.0.2"
"bcrypt-pbkdf": "^1.0.2",
"cpu-features": "~0.0.4",
"nan": "^2.15.0"
},
"engines": {
"node": ">=10.16.0"
@ -14058,6 +14075,11 @@
"integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==",
"dev": true
},
"esm": {
"version": "3.2.25",
"resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz",
"integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA=="
},
"espree": {
"version": "9.3.1",
"resolved": "https://registry.npmjs.org/espree/-/espree-9.3.1.tgz",

View File

@ -31,6 +31,7 @@
"crypto": "^1.0.1",
"directory-tree": "^2.2.9",
"dotenv": "^16.0.0",
"esm": "^3.2.25",
"express": "^4.17.3",
"express-fileupload": "^1.3.1",
"express-rate-limit": "^6.3.0",

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

View File

@ -1,4 +1,3 @@
import authentication from './authentication';
import { Accounts } from '../../models';

View File

@ -7,8 +7,7 @@ export async function SetResearchStatus(userId, status) {
}
export async function GetResearchStatus(userId) {
return Accounts.findOne({where: {id: userId}, attributes: ['research_enabled']})
return Accounts.findOne({ where: { id: userId }, attributes: ['research_enabled'] });
}
export default null;

View File

@ -1,5 +1,4 @@
import express from 'express';
import log4js from 'log4js';
import admin from './admin';
import auth from './auth';

View File

@ -1,34 +1,25 @@
import bodyParser from 'body-parser';
import crypto from 'crypto';
import dirTree from 'directory-tree';
import express from 'express';
import log4js from 'log4js';
import { requireAuthenticated } from '../../../middlewares/authentication';
import { SetResearchStatus, GetResearchStatus } from '../../../controllers/user/settings';
const logger = log4js.getLogger();
// /api/devices
const router = express.Router();
router.patch('/research/:enabled', requireAuthenticated, async (req, res) => {
const { enabled } = req.params;
if (!enabled) { res.json({ bad: true }); }
const doEnable = enabled === 'true';
const accountId = req.account.id;
const update = await SetResearchStatus(req.account.id, doEnable);
return res.json({ success: true, data: req.account });
});
const { enabled } = req.params;
if (!enabled) { res.json({ bad: true }); }
const doEnable = enabled === 'true';
router.get('/research/', requireAuthenticated, async (req, res) => {
const accountId = req.account.id;
const update = await GetResearchStatus(req.account.id);
return res.json({ success: true, data: update });
});
await SetResearchStatus(req.account.id, doEnable);
return res.json({ success: true, data: req.account });
});
router.get('/research/', requireAuthenticated, async (req, res) => {
const update = await GetResearchStatus(req.account.id);
return res.json({ success: true, data: update });
});
export default router;