Skip to content

Commit

Permalink
Merge branch 'main' into swap-ioutil-with-io
Browse files Browse the repository at this point in the history
  • Loading branch information
manschwa authored Feb 27, 2024
2 parents b3b331d + 95bf374 commit 7de6d48
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 16 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,28 @@ https://github.com/virtUOS/opencast-ca-display/assets/1008395/ead22cd2-9d7a-4d26
- The display and laptop do not know about each other
- The laptop is running an Opencast capture agent
- When the laptop starts capturing video, the display shows an active recording

## Opencast User

To improve security, you can limit the access rights for the Opencast user by
creating a user which has only read access to the capture agent status API and
nothing else.

To do this, first create a new security rule in your Opencast's
`etc/security/mh_default_org.xml` allowing read access for a new role
`ROLE_CAPTURE_AGENT_CALENDAR`:

```xml
<!-- Enable capture agent updates and ingest -->
<sec:intercept-url pattern="/capture-admin/agents/**" method="GET" access="ROLE_ADMIN, ROLE_CAPTURE_AGENT, ROLE_CAPTURE_AGENT_CALENDAR" />
<sec:intercept-url pattern="/capture-admin/**" access="ROLE_ADMIN, ROLE_CAPTURE_AGENT" />
```

Next, go to the Opencast REST Docs → `/user-utils` and fill out the form for
`POST /` with data like this:

- username: `ca-display`
- password: `secret-password`
- roles: `["ROLE_CAPTURE_AGENT_CALENDAR"]`

You should now be able to use this new user.
40 changes: 26 additions & 14 deletions assets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,37 @@ fetch('/config')
setInterval(updateTimer, 2000);
})

/**
* Update the view
*/
function updateView(active) {
// Update text
document.getElementById('text').innerText = active.text;

// Update colors
const body = document.getElementsByTagName('body')[0];
body.style.backgroundColor = active.background;
body.style.color = active.color;

// Update logo
document.getElementById('logo').src = active.image.replace(/\s/g, '');
}

/**
* Check for capture agent status
*/
function updateTimer() {
fetch('/status')
.then(response => response.json())
.then(capturing => {
.then(response => {
if (!response.ok) {
const active = config.unknown;
active.text = response.statusText;
updateView(active);
throw Error(response.statusText);
}
return response.json()
}).then(capturing => {
console.debug('capturing', capturing)
const active = capturing ? config.capturing : config.idle;

// Update text
document.getElementById('text').innerText = active.text;

// Update colors
const body = document.getElementsByTagName('body')[0];
body.style.backgroundColor = active.background;
body.style.color = active.color;

// Update logo
document.getElementById('logo').src = active.image.replace(/\s/g, '');
updateView(capturing ? config.capturing : config.idle);
})
}
2 changes: 0 additions & 2 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ body {
top: 0;
right: 0;
width: 10vw;
border-left: 0.2vw solid white;
border-bottom: 0.2vw solid white;
}

#text {
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Config struct {
Display struct {
Capturing DisplayConfig `json:"capturing"`
Idle DisplayConfig `json:"idle"`
Unknown DisplayConfig `json:"unknown"`
}

Listen string
Expand Down Expand Up @@ -120,9 +121,17 @@ func setupRouter() *gin.Engine {
req.SetBasicAuth(config.Opencast.Username, config.Opencast.Password)
resp, err := client.Do(req)
if err != nil {
log.Println(err)
c.JSON(http.StatusBadGateway, nil)
return
}

if resp.StatusCode != 200 {
log.Println(resp)
c.JSON(resp.StatusCode, nil)
return
}

bodyText, err := io.ReadAll(resp.Body)
s := string(bodyText)
var result AgentStateResult
Expand Down
5 changes: 5 additions & 0 deletions opencast-ca-display.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ display:
bdf+Ja02rbN0Tm63v7bb1/63qhYAAAAAAAAAAAAAAAAAAAAAAAAAAIDY8w9T
Gxe/25sMhQAAAABJRU5ErkJggg==
unknown:
text: Unknown
color: white
background: black


# IP address and port to bind to
listen: 127.0.0.1:8080

0 comments on commit 7de6d48

Please sign in to comment.