Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1

Merged
merged 35 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4216f9d
add dockerfile and dependencies
PandorasActorMS Sep 18, 2023
02787d0
add github action
PandorasActorMS Sep 19, 2023
afffe88
change nginx to caddy
PandorasActorMS Sep 19, 2023
50d66da
get environment variables
PandorasActorMS Sep 19, 2023
eeccc19
fix ci
PandorasActorMS Sep 19, 2023
f405876
fix: remove instruction
PandorasActorMS Sep 19, 2023
6d7d18c
remove instruction
PandorasActorMS Sep 19, 2023
7aa5d32
get link from environment variable
PandorasActorMS Sep 19, 2023
7a12c9f
change path and use email as 'username'
PandorasActorMS Sep 19, 2023
3728024
remove comment out lines
PandorasActorMS Sep 19, 2023
057a5fe
show email when logged in
PandorasActorMS Sep 19, 2023
b81a1b6
get API key over environment variable
PandorasActorMS Sep 20, 2023
af93876
remove instruction
PandorasActorMS Sep 20, 2023
488b2f6
add title
PandorasActorMS Sep 20, 2023
8c6a5fa
add user initials
PandorasActorMS Sep 20, 2023
3029499
add oidc logout
PandorasActorMS Sep 20, 2023
b9f72d2
move logout from oidc to new file
PandorasActorMS Sep 20, 2023
7416e74
fix function call
PandorasActorMS Sep 20, 2023
193ff57
fix logout oidc
PandorasActorMS Sep 20, 2023
024c5df
add HM logo and favicon
PandorasActorMS Sep 20, 2023
51ca005
fix favicon
PandorasActorMS Sep 20, 2023
f230103
fix favicon
PandorasActorMS Sep 20, 2023
94a38ea
fix favicon part 3
PandorasActorMS Sep 20, 2023
bec8e43
fix favicon part 4
PandorasActorMS Sep 20, 2023
bb4f119
fix favicon part 5
PandorasActorMS Sep 20, 2023
c115af4
remove icon
PandorasActorMS Sep 20, 2023
1b413ca
change session variable
PandorasActorMS Sep 20, 2023
7692a7c
change video address
PandorasActorMS Sep 20, 2023
b73d11a
change: config values from .env or environment
PandorasActorMS Sep 21, 2023
7050ade
fix: array key name
PandorasActorMS Sep 21, 2023
71a05b4
rename: oic to oidc
PandorasActorMS Sep 21, 2023
69b3a30
rename: filename
PandorasActorMS Sep 21, 2023
d4d7417
fix: logout
PandorasActorMS Sep 21, 2023
f0aab3b
add: tags
PandorasActorMS Sep 22, 2023
77849e8
changed: tag
PandorasActorMS Sep 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; Authentication method: LDAP or OIC
; Authentication method: LDAP or OIDC
Authentication="LDAP"
; LDAP config
LDAP_HOST="ldaps://..."
Expand All @@ -18,11 +18,11 @@ TESTUSER=false

; OpenID Connect configuration
; ID provider
OIC_IDP="https://xxx"
OIDC_IDP="https://xxx"
; Client ID
OIC_CLIENT_ID="xxx"
OIDC_CLIENT_ID="xxx"
; Client secret
OIC_CLIENT_SECRET="xxx"
OIDC_CLIENT_SECRET="xxx"

; Path to composer auoload file (without /vendor/autoload.php)
; normally set to "."
Expand Down
83 changes: 83 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
on:
push:
pull_request:

name: CI build
jobs:
build:
name: CI build
runs-on: ubuntu-latest
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
permissions:
contents: read
packages: write
steps:

- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0



- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta-php
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-php
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value={{branch}}-{{sha}}-{{date 'X'}},enable=${{ github.event_name != 'pull_request' && !contains(github.ref, 'refs/tags/') }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.php
push: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]'}}
tags: ${{ steps.meta-php.outputs.tags }}
labels: ${{ steps.meta-php.outputs.labels }}

- name: Extract Docker metadata
id: meta-caddy
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-caddy
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value={{branch}}-{{sha}}-{{date 'X'}},enable=${{ github.event_name != 'pull_request' && !contains(github.ref, 'refs/tags/') }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.caddy
push: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]'}}
tags: ${{ steps.meta-caddy.outputs.tags }}
labels: ${{ steps.meta-caddy.outputs.labels }}
2 changes: 2 additions & 0 deletions Dockerfile.caddy
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM caddy:latest
COPY . /var/www/html/public
12 changes: 12 additions & 0 deletions Dockerfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM php:8.2-fpm
#WORKDIR /var/www/html
COPY ./ /var/www/html/

RUN apt-get update \
&& apt-get install -y git libzip-dev zip \
&& docker-php-ext-install zip \
&& cd /var/www/html \
&& chmod +x composer_install.sh && ./composer_install.sh \
&& mv composer.phar /usr/local/bin/composer \
&& composer install \
&& rm composer_install.sh Dockerfile.caddy Dockerfile.php
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ To get started you need to add a configuration file to the project first. Copy t

| Value | Type | Example | Description |
| ---------------- | ------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| Authentication | string | 'LDAP' or 'OIC' | Authentication method: LDAP or OpenID Connect |
| Authentication | string | 'LDAP' or 'OIDC' | Authentication method: LDAP or OpenID Connect |
| LDAP_HOST | string | "ldaps://...de" | The URL of your LDAP server. |
| LDAP_BIND_PW | string | secretpassword | Password of the user that is trying to bind to the LDAP Server. |
| LDAP_BASE_DN | string | "cn=...,ou=...,dc=..." | Distinguised name that is used to initially bind to your LDAP server. |
| LDAP_SEARCH_DN | string | "ou=...,dc=..." | Distinguished name that is used for authenticating users. |
| OIC_IDP | string | "https://...." | URL of the Identity provider supporting OpenID Connect. |
| OIC_CLIENT_ID | string | "..." | Client Id for this application in Identity provider. |
| OIC_CLIENT_SECRET | string | "..." | Secret key for OpenID Connect. |
| OIDC_IDP | string | "https://...." | URL of the Identity provider supporting OpenID Connect. |
| OIDC_CLIENT_ID | string | "..." | Client Id for this application in Identity provider. |
| OIDC_CLIENT_SECRET | string | "..." | Secret key for OpenID Connect. |
| COMPOSER_PATH | string | "..." | Path to PHP Composer libariries (only needed for OpenID Connect). |
| OPENAI_API_KEY | string | sk-... | Open AI Api key |
| IMPRINT_LOCATION | string | https://your-university/imprint | A link to your imprint. Alternatively you can replace the file index.php under /impressum with your own html/ php of your imprint. |
Expand Down
6 changes: 4 additions & 2 deletions api.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
session_start();

$env = parse_ini_file('.env');
$apiKey = $env["OPENAI_API_KEY"];
if (file_exists(".env")){
$env = parse_ini_file('.env');
}
$apiKey = isset($env) ? $env['OPENAI_API_KEY'] : getenv('OPENAI_API_KEY');;

if (!isset($_SESSION['username'])) {
http_response_code(401);
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"jumbojett/openid-connect-php": "^0.9.10"
}
}
17 changes: 17 additions & 0 deletions composer_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"

if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
>&2 echo 'ERROR: Invalid installer checksum'
rm composer-setup.php
exit 1
fi

php composer-setup.php --quiet
RESULT=$?
rm composer-setup.php
exit $RESULT
6 changes: 4 additions & 2 deletions datenschutz/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
$env = parse_ini_file('../.env');
$privacyLocation = $env["PRIVACY_LOCATION"];
if (file_exists(".env")){
$env = parse_ini_file('.env');
}
$privacyLocation = isset($env) ? $env["PRIVACY_LOCATION"] : getenv("PRIVACY_LOCATION");

header("Location: $privacyLocation");
exit;
19 changes: 18 additions & 1 deletion img/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions impressum/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
$env = parse_ini_file('../.env');
$imprintLocation = $env["IMPRINT_LOCATION"];
if (file_exists(".env")){
$env = parse_ini_file('.env');
}
$imprintLocation = isset($env) ? $env["IMPRINT_LOCATION"] : getenv("IMPRINT_LOCATION");

header("Location: $imprintLocation");
exit;
Expand Down
31 changes: 26 additions & 5 deletions interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,25 @@
}

?>

<head>
<title>HAWKI</title>
<?php
if (file_exists(".env")){
$env = parse_ini_file('.env');
}
$favicon = isset($env) ? ($env["FAVICON_URI"]??false) : getenv("FAVICON_URI");
if ($favicon) {
echo
'<link rel="shortcut icon" type="image/x-icon" href="'. $favicon .'" media="screen" />
<link rel="icon" type="image/x-icon" href="'. $favicon .'" media="screen" />
';
}
?>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="app.css">
<link rel="stylesheet" href="app.css">


<div class="wrapper">
<div class="sidebar">
Expand Down Expand Up @@ -97,7 +112,13 @@
<div class="info">
<a href="#" onclick="load(this, 'about.htm')">Über HAWKI</a>
<a href="#" id="feedback" onclick="load(this, 'userpost.php')">Feedback</a>
<a href="logout.php">Abmelden</a>
<a href=<?php
if (file_exists(".env")){
$env = parse_ini_file('.env');
}
if ((isset($env) ? $env["Authentication"] : getenv("Authentication")) == "OIDC"){
echo "oidc_logout.php";
} else echo "logout.php" ?>>Abmelden (<?php echo $_SESSION['username']?>)</a>
<br>
<a href="/datenschutz" target="_blank" >Datenschutz</a>
<a href="/impressum" target="_blank">Impressum</a>
Expand Down Expand Up @@ -415,7 +436,7 @@ function addMessage(message){
if(message.role == "assistant"){
messageElement.querySelector(".message-icon").textContent = "AI";
}else{
messageElement.querySelector(".message-icon").textContent = '<?= $_SESSION['username'] ?>';
messageElement.querySelector(".message-icon").textContent = '<?= isset($_SESSION['initials']) ? $_SESSION['initials']: $_SESSION['username'] ?>';
messageElement.querySelector(".message").classList.add("me");
}

Expand Down Expand Up @@ -462,7 +483,7 @@ function modalClick(element){
const inputField = document.querySelector(".userpost-field");

let message = {};
message.role = '<?= $_SESSION['username'] ?>';
message.role = '<?= isset($_SESSION['initials']) ? $_SESSION['initials']: $_SESSION['username'] ?>';
message.content = inputField.value.trim();

fetch('userpost.php', {
Expand Down
Loading