Skip to content

Commit

Permalink
Replace Python HTTP server with custom C++ one
Browse files Browse the repository at this point in the history
  • Loading branch information
Semphriss committed Jun 2, 2024
1 parent 077b901 commit 7904bbe
Show file tree
Hide file tree
Showing 14 changed files with 493 additions and 125 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
arch: [amd64, arm64, armhf]

steps:
- uses: actions/checkout@v3
with:
Expand All @@ -26,7 +30,9 @@ jobs:
run: pip3 install --user --upgrade clickable-ut

- name: Build
run: clickable build --output .
env:
ARCH: ${{ matrix.arch }}
run: clickable build --arch $ARCH --output .

- name: Generate variables
id: filename
Expand All @@ -35,7 +41,7 @@ jobs:
run: |
GIT_VERSION="$(git describe --tags --always)"
echo "version=$GIT_VERSION" >> $GITHUB_OUTPUT
echo "zipname=annotate-$GIT_VERSION" >> $GITHUB_OUTPUT
echo "zipname=annotate-$ARCH-$GIT_VERSION" >> $GITHUB_OUTPUT
- name: Upload package
uses: actions/upload-artifact@v2
Expand Down
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
project(annotate)
cmake_minimum_required(VERSION 3.0)

set(CMAKE_CXX_STANDARD 20)

add_executable(webserver webserver/webserver.cpp)
add_executable(genkey webserver/genkey.cpp)

install(TARGETS webserver genkey DESTINATION bin)
install(DIRECTORY www assets DESTINATION .)
install(FILES annotate.apparmor
annotate.desktop
annotate-contenthub.json
LICENSE
manifest.json
README.md
DESTINATION .)
install(PROGRAMS run.sh DESTINATION .)

5 changes: 3 additions & 2 deletions annotate.apparmor
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"template": "unconfined",
"template": "ubuntu-webapp",
"policy_groups": [
"webview",
"networking",
"content_exchange"
"content_exchange",
"content_exchange_source"
],
"policy_version": 20.04
}
5 changes: 2 additions & 3 deletions clickable.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
clickable_minimum_required: 7.1.2
builder: pure
clickable_minimum_required: 8.0.0
builder: cmake
kill: webapp-container*
framework: ubuntu-sdk-20.04
skip_review: true
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "annotate.semphris",
"description": "View and annotate your PDF files",
"architecture": "all",
"architecture": "@CLICK_ARCH@",
"title": "Annotate",
"hooks": {
"annotate": {
Expand All @@ -10,7 +10,7 @@
"content-hub": "annotate-contenthub.json"
}
},
"version": "0.1.0",
"version": "0.1.1",
"maintainer": "Semphris <semphris@protonmail.com>",
"framework" : "ubuntu-sdk-20.04"
}
8 changes: 3 additions & 5 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/bin/bash

cd www

# The key only provides weak security. The key can be obtained with `ps -aux`. It's mostly meant to avoid mistakes.
export ANNOTATE_KEY="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 64)"
export ANNOTATE_KEY="$(./bin/genkey)"

python3 -m http.server --cgi --bind 127.0.0.1 9283 &
webapp-container --app-id="annotate.semphris" http://localhost:9283/?key=$ANNOTATE_KEY
./bin/webserver &
webapp-container --app-id="annotate.semphris" http://localhost:9283/index.html?key=$ANNOTATE_KEY
20 changes: 20 additions & 0 deletions webserver/genkey.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#include <string>
#include <sys/random.h>

int main() {
char buffer[65];
char *ptr = buffer;

while (ptr != buffer + 64) {
getrandom(ptr, 1, 0);
char c = *ptr;
if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9') {
ptr++;
}
}
*ptr = '\0';

std::cout << buffer << std::flush;
return 0;
}
Loading

0 comments on commit 7904bbe

Please sign in to comment.