35 Commits

Author SHA1 Message Date
renovate[bot]
32870cc447 Update actions/stale action to v7 (#161)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-12-22 22:24:13 +00:00
renovate[bot]
0efe142ea0 Update docker Docker tag to v20.10.22 (#160)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-12-17 20:33:54 +00:00
5eba9d705c Create sonar-project.properties 2022-10-21 23:59:03 +01:00
1319d59c8c Add Coverage 2022-10-21 23:57:39 +01:00
05e12dde69 Sonar: phpsecurity:S5131 2022-10-21 23:53:08 +01:00
a0035707b8 Sonar: phpsecurity:S5131 2022-10-21 23:51:31 +01:00
renovate[bot]
cdaf096965 Update docker Docker tag to v20.10.20 (#159)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-10-19 07:24:40 +01:00
renovate[bot]
46263f3195 Update docker Docker tag to v20.10.19 (#158)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-10-16 18:25:00 +01:00
renovate[bot]
3c4efa15c2 Update docker Docker tag to v20.10.18 (#156)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-10-01 11:24:37 +01:00
renovate[bot]
a24d001d98 Update actions/stale action to v6 (#157)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-10-01 11:22:53 +01:00
renovate[bot]
107988a5b3 Update actions/stale action to v5 (#149)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Luke Tainton <ltainton@cisco.com>
2022-04-13 14:47:09 +01:00
dependabot[bot]
ae82b926f6 ⬆️ Bump guzzlehttp/psr7 from 1.6.1 to 1.8.5 in /app (#150)
Bumps [guzzlehttp/psr7](https://github.com/guzzle/psr7) from 1.6.1 to 1.8.5.
- [Release notes](https://github.com/guzzle/psr7/releases)
- [Changelog](https://github.com/guzzle/psr7/blob/1.8.5/CHANGELOG.md)
- [Commits](https://github.com/guzzle/psr7/compare/1.6.1...1.8.5)

---
updated-dependencies:
- dependency-name: guzzlehttp/psr7
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-04-13 14:46:49 +01:00
renovate[bot]
b12134b1c0 Update dependency docker to v20 (#152)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-04-13 14:46:39 +01:00
renovate[bot]
c56e16206b Update actions/checkout action to v3 (#148)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-04-13 14:45:12 +01:00
Luke Tainton
06a4e56ee7 Move back to GitHub 2022-04-13 14:42:05 +01:00
c00037d3f6 Migrate to GitLab 2022-03-11 16:43:49 +00:00
renovate[bot]
c6a578b5bb Update actions/stale action to v4 (#146)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-10-18 20:41:29 +01:00
dependabot[bot]
f7ce7cd401 ⬆️ Bump phpseclib/phpseclib from 2.0.28 to 2.0.31 in /app (#142)
Bumps [phpseclib/phpseclib](https://github.com/phpseclib/phpseclib) from 2.0.28 to 2.0.31.
- [Release notes](https://github.com/phpseclib/phpseclib/releases)
- [Changelog](https://github.com/phpseclib/phpseclib/blob/master/CHANGELOG.md)
- [Commits](https://github.com/phpseclib/phpseclib/compare/2.0.28...2.0.31)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-04-20 22:26:31 +01:00
18cdccb63e Update Docker registry 2021-03-06 16:46:10 +00:00
bb3143c7c8 Update Docker registry 2021-03-06 16:44:29 +00:00
80679499e1 Update docker-compose config location (#141) 2020-10-23 10:37:55 +01:00
renovate[bot]
23bf431c74 Update actions/stale action to v3 (#139)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2020-10-23 10:27:16 +01:00
renovate[bot]
4bced68a09 Update dependency sentry/sdk to v3 (#138)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2020-09-28 19:26:51 +01:00
Alexander Davis
4d3ace9d67 Update deploy.yml (#137) 2020-09-08 22:16:27 +01:00
restyled-io[bot]
e9f1b8477a Restyle Updates (#135)
* Restyled by jq

* Restyled by php-cs-fixer

* Restyled by whitespace

Co-authored-by: Restyled.io <commits@restyled.io>
2020-09-05 16:43:48 +01:00
9809b028d4 🐛 Move opening and closing 'main' tags (#132)
* 🐛 Move opening and closing 'main' tags

Signed-off-by: Luke Tainton <luke@tainton.uk>

* Restyled by php-cs-fixer (#133)

Co-authored-by: Restyled.io <commits@restyled.io>

Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <commits@restyled.io>
2020-08-31 19:16:33 +01:00
da5d7ffa53 🚧 Migrate from Sentry to GlitchTip (#129)
Signed-off-by: Luke Tainton <luke@tainton.uk>
2020-08-18 20:14:08 +01:00
02c397bca2 Add Sentry (#127)
Signed-off-by: Luke Tainton <luke@tainton.uk>
2020-08-18 18:32:29 +01:00
a4ae987f94 Move break rule in footer (#124)
* Update footer.php

* Change line break to pipe

* Remove full stop

Co-authored-by: Alexander Davis <alex@adcm.uk>
2020-08-18 17:58:07 +01:00
Alexander Davis
26c4f801d3 Broken login (#122)
* Fixing Login Die

* Fix Broken Login 2

* Update footer

* Try Somethin New Today
2020-08-17 17:04:34 +01:00
Alexander Davis
49581da52c Broken login (#121)
* Fixing Login Die

* Fix Broken Login 2
2020-08-17 16:48:13 +01:00
57faf21a67 Fixing Login Die 2020-08-17 16:37:41 +01:00
5ff90e0d78 🐛 User not added to DB - force die() on error (#118)
* 🐛 User not added to DB - force die() on error

Signed-off-by: Luke Tainton <luke@tainton.uk>

* Restyled by php-cs-fixer (#119)

Co-authored-by: Restyled.io <commits@restyled.io>

Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <commits@restyled.io>
2020-08-17 16:17:06 +01:00
7a4a1074c5 🔧 Push release version to Docker image (#114)
* 🔧 Push release version to Docker image

Signed-off-by: Luke Tainton <luke@tainton.uk>

* Restyle 🔧 Push release version to Docker image (#115)

* Restyled by php-cs-fixer

* Restyled by whitespace

Co-authored-by: Restyled.io <commits@restyled.io>

Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <commits@restyled.io>
2020-08-17 12:03:32 +01:00
c8576aa757 🐛 Make it plural! (#113) 2020-08-17 11:45:28 +01:00
17 changed files with 2176 additions and 313 deletions

64
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,64 @@
name: Deploy
on:
push:
branches: main
jobs:
tests:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup PHP with Xdebug
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: xdebug
- name: Install dependencies with composer
run: composer update --no-ansi --no-interaction --no-progress
- name: Run tests with phpunit/phpunit
run: vendor/bin/phpunit --coverage-clover=coverage.xml
- name: Fix code coverage paths
run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
release-on-push:
runs-on: ubuntu-latest
outputs:
ver: ${{ steps.release.outputs.version }}
tag: ${{ steps.release.outputs.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Get Release
id: release
uses: rymndhng/release-on-push-action@master
with:
bump_version_scheme: patch
- name: Check Release Output
id: rop-check
run: |
echo "Got tag name ${{ steps.release.outputs.tag_name }}"
echo "Got release version ${{ steps.release.outputs.version }}"
build:
name: GitHub Container Registry
runs-on: ubuntu-latest
needs: [tests, release-on-push]
steps:
- uses: actions/checkout@v3
- name: Login to GitHub Container Registry
run: echo ${{ secrets.PAT }} | docker login ghcr.io -u luketainton --password-stdin
- name: Build image for GitHub Container Registry
run: docker build . --file Dockerfile --tag ghcr.io/luketainton/fhed:${{ needs.release-on-push.outputs.ver }} --tag ghcr.io/luketainton/fhed:latest
- name: Push image to GitHub Container Registry
run: |
docker push ghcr.io/luketainton/fhed:latest
docker push ghcr.io/luketainton/fhed:${{ needs.release-on-push.outputs.ver }}

View File

@@ -1,67 +0,0 @@
name: Deploy
on:
push:
branches: main
jobs:
release-on-push:
runs-on: ubuntu-latest
outputs:
ver: ${{ steps.release.outputs.version }}
tag: ${{ steps.release.outputs.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- id: release
uses: rymndhng/release-on-push-action@master
with:
bump_version_scheme: minor
- name: Check Output Parameters
run: |
echo "Got tag name ${{ steps.release.outputs.tag_name }}"
echo "Got release version ${{ steps.release.outputs.version }}"
docker-dh:
name: Push to Docker Hub
needs: [release-on-push]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Build image for Docker Hub
run: docker build . --file Dockerfile --build-arg VERSION=${{ needs.release-on-push.output.ver }} --tag luketainton/fhed:${{ needs.release-on-push.output.tag }} --tag luketainton/fhed:latest
- name: Push image to Docker Hub
run: |
docker push luketainton/fhed:${{ needs.release-on-push.output.tag }} &&
docker push luketainton/fhed:latest
docker-ghr:
name: Push to GitHub Package Registry
needs: [release-on-push]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub Registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login https://docker.pkg.github.com -u luketainton --password-stdin
- name: Build image for GitHub Package Registry
run: docker build . --file Dockerfile --build-arg VERSION=${{ needs.release-on-push.output.ver }} --tag docker.pkg.github.com/luketainton/fhed/fhed:latest --tag docker.pkg.github.com/luketainton/fhed/fhed:${{ needs.release-on-push.output.tag }}
- name: Push image to GitHub Package Registry
run: |
docker push docker.pkg.github.com/luketainton/fhed/fhed:${{ needs.release-on-push.output.tag }} &&
docker push docker.pkg.github.com/luketainton/fhed/fhed:latest
deploy:
name: Update Docker image on server
runs-on: ubuntu-latest
needs: [docker-dh]
steps:
- name: Update image on server
uses: garygrossgarten/github-action-ssh@release
with:
command: cd /docker/active/fhed && docker-compose pull && docker-compose up -d
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USERNAME }}
privateKey: ${{ secrets.SSH_SSHKEY }}

View File

@@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@v1 - uses: actions/stale@v7
with: with:
repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue has been marked as stale due to inactivity. If this issue is still ongoing, please leave a comment.' stale-issue-message: 'This issue has been marked as stale due to inactivity. If this issue is still ongoing, please leave a comment.'

View File

@@ -0,0 +1,18 @@
stages:
- build
build:
stage: build
only:
- tags
image: docker:20.10.22
services:
- docker:20.10.22-dind
variables:
IMAGE_TAG: "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $CI_REGISTRY_IMAGE:latest -t $IMAGE_TAG .
- docker build -t $IMAGE_TAG -t $CI_REGISTRY_IMAGE:latest .
- docker push $IMAGE_TAG
- docker push $CI_REGISTRY_IMAGE:latest

View File

@@ -4,6 +4,9 @@ RUN composer --working-dir=/srv install
FROM php:apache FROM php:apache
LABEL maintainer="Luke Tainton <luke@tainton.uk>" LABEL maintainer="Luke Tainton <luke@tainton.uk>"
LABEL org.opencontainers.image.source="https://github.com/luketainton/fhed"
ARG VERSION
RUN docker-php-ext-install pdo_mysql && a2enmod rewrite remoteip RUN docker-php-ext-install pdo_mysql && a2enmod rewrite remoteip
COPY vhost.conf /etc/apache2/sites-enabled/000-default.conf COPY vhost.conf /etc/apache2/sites-enabled/000-default.conf
COPY --from=build /srv /srv COPY --from=build /srv /srv
RUN echo $VERSION > /srv/includes/VERSION

View File

@@ -13,3 +13,5 @@ OIDC_HOST = ""
OIDC_CLIENT_ID = "" OIDC_CLIENT_ID = ""
OIDC_CLIENT_SECRET = "" OIDC_CLIENT_SECRET = ""
OIDC_DISABLE_SSL = "" OIDC_DISABLE_SSL = ""
SENTRY_ENVIRONMENT = ""

View File

@@ -1,7 +1,8 @@
{ {
"require": { "require": {
"ramsey/uuid": "^4.0", "ramsey/uuid": "^4.0",
"vlucas/phpdotenv": "^5.0", "vlucas/phpdotenv": "^5.0",
"jumbojett/openid-connect-php": "^0.9.0" "jumbojett/openid-connect-php": "^0.9.0",
} "sentry/sdk": "^3.0"
}
} }

1833
app/composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,53 +1,105 @@
<?php <?php
function get_all_users($db) {
try { function get_version()
$stmt = "SELECT * FROM users"; {
$sql = $db->prepare($stmt); $version = "v" . file_get_contents(__DIR__ . '/VERSION');
$sql->execute(); return $version;
$sql->setFetchMode(PDO::FETCH_ASSOC);
$result = $sql->fetchAll();
} catch (PDOException $e) {
echo("Error: " . $e->getMessage());
}
return $result;
} }
function get_user_name($db, $user_uuid) { function oidc_set_vars($sub, $uid, $fname, $lname, $email)
try { {
$stmt = "SELECT given_name, family_name FROM users WHERE uuid=:uuid"; $_SESSION['uuid'] = $sub;
$sql = $db->prepare($stmt); $_SESSION['username'] = $uid;
$sql->bindParam(':uuid', $user_uuid); $_SESSION['given_name'] = $fname;
$sql->execute(); $_SESSION['family_name'] = $lname;
$sql->setFetchMode(PDO::FETCH_ASSOC); $_SESSION['full_name'] = $fname . " " . $lname;
$result = $sql->fetchAll(); $_SESSION['email'] = $email;
$usr = $result[0]['given_name'] . " " . $result[0]['family_name'];
} catch (PDOException $e) {
echo("Error: " . $e->getMessage());
}
return $usr;
} }
function get_my_open_requests($db) { function is_signed_in()
$ticket_stmt = "SELECT * FROM tickets WHERE created_by=:uuid AND status != 'Closed'"; {
$ticket_sql = $db->prepare($ticket_stmt); if (isset($_SESSION['is_signed_in'])) {
$ticket_sql->bindParam(':uuid', $_SESSION['uuid']); return true;
$ticket_sql->execute(); } else {
$ticket_sql->setFetchMode(PDO::FETCH_ASSOC); return false;
$ticket_result = $ticket_sql->fetchAll(); }
return $ticket_result;
} }
function get_my_closed_requests($db) { function user_exists($db, $uuid)
$ticket_stmt = "SELECT * FROM tickets WHERE created_by=:uuid AND status = 'Closed'"; {
$ticket_sql = $db->prepare($ticket_stmt); try {
$ticket_sql->bindParam(':uuid', $_SESSION['uuid']); $sql = $db->prepare("SELECT uuid FROM users WHERE uuid=:uuid");
$ticket_sql->execute(); $sql->bindParam(':uuid', $uuid);
$ticket_sql->setFetchMode(PDO::FETCH_ASSOC); $sql->execute();
$ticket_result = $ticket_sql->fetchAll(); $sql->setFetchMode(PDO::FETCH_ASSOC);
return $ticket_result; $result = $sql->fetchAll();
} catch (PDOException $e) {
throw new Exception("Error in user_exists(): " . $e->getMessage());
die();
}
if (empty($result)) {
return false;
} else {
return true;
}
} }
function get_subscribed_requests($db) { function get_all_users($db)
{
try {
$stmt = "SELECT * FROM users";
$sql = $db->prepare($stmt);
$sql->execute();
$sql->setFetchMode(PDO::FETCH_ASSOC);
$result = $sql->fetchAll();
} catch (PDOException $e) {
throw new Exception("Error in get_all_users(): " . $e->getMessage());
die();
}
return $result;
}
function get_user_name($db, $user_uuid)
{
try {
$stmt = "SELECT given_name, family_name FROM users WHERE uuid=:uuid";
$sql = $db->prepare($stmt);
$sql->bindParam(':uuid', $user_uuid);
$sql->execute();
$sql->setFetchMode(PDO::FETCH_ASSOC);
$result = $sql->fetchAll();
$usr = $result[0]['given_name'] . " " . $result[0]['family_name'];
} catch (PDOException $e) {
throw new Exception("Error in get_user_name(): " . $e->getMessage());
die();
}
return $usr;
}
function get_my_open_requests($db)
{
$ticket_stmt = "SELECT * FROM tickets WHERE created_by=:uuid AND status != 'Closed'";
$ticket_sql = $db->prepare($ticket_stmt);
$ticket_sql->bindParam(':uuid', $_SESSION['uuid']);
$ticket_sql->execute();
$ticket_sql->setFetchMode(PDO::FETCH_ASSOC);
$ticket_result = $ticket_sql->fetchAll();
return $ticket_result;
}
function get_my_closed_requests($db)
{
$ticket_stmt = "SELECT * FROM tickets WHERE created_by=:uuid AND status = 'Closed'";
$ticket_sql = $db->prepare($ticket_stmt);
$ticket_sql->bindParam(':uuid', $_SESSION['uuid']);
$ticket_sql->execute();
$ticket_sql->setFetchMode(PDO::FETCH_ASSOC);
$ticket_result = $ticket_sql->fetchAll();
return $ticket_result;
}
function get_subscribed_requests($db)
{
$requests = array(); $requests = array();
$sub_tickets_stmt = "SELECT ticket_uuid FROM ticket_subscribers WHERE user_uuid=:uuid"; $sub_tickets_stmt = "SELECT ticket_uuid FROM ticket_subscribers WHERE user_uuid=:uuid";
$sub_tickets_sql = $db->prepare($sub_tickets_stmt); $sub_tickets_sql = $db->prepare($sub_tickets_stmt);
@@ -56,96 +108,108 @@
$sub_tickets_sql->setFetchMode(PDO::FETCH_ASSOC); $sub_tickets_sql->setFetchMode(PDO::FETCH_ASSOC);
$sub_tickets_result = $sub_tickets_sql->fetchAll(); $sub_tickets_result = $sub_tickets_sql->fetchAll();
foreach ($sub_tickets_result as $tkt) { foreach ($sub_tickets_result as $tkt) {
$stmt = "SELECT * FROM tickets WHERE uuid=:uuid"; $stmt = "SELECT * FROM tickets WHERE uuid=:uuid";
$sql = $db->prepare($stmt); $sql = $db->prepare($stmt);
$sql->bindParam(':uuid', $tkt['ticket_uuid']); $sql->bindParam(':uuid', $tkt['ticket_uuid']);
$sql->execute(); $sql->execute();
$sql->setFetchMode(PDO::FETCH_ASSOC); $sql->setFetchMode(PDO::FETCH_ASSOC);
$result = $sql->fetchAll(); $result = $sql->fetchAll();
array_push($requests, $result[0]); array_push($requests, $result[0]);
} }
return $requests; return $requests;
} }
function get_open_subscribed_requests($db) { function get_open_subscribed_requests($db)
$requests = array(); {
$all_subs = get_subscribed_requests($db); $requests = array();
foreach ($all_subs as $sub) { $all_subs = get_subscribed_requests($db);
if ($sub['status'] != 'Closed') { foreach ($all_subs as $sub) {
array_push($requests, $sub); if ($sub['status'] != 'Closed') {
array_push($requests, $sub);
}
} }
} return $requests;
return $requests;
} }
function get_closed_subscribed_requests($db) { function get_closed_subscribed_requests($db)
$requests = array(); {
$all_subs = get_subscribed_requests($db); $requests = array();
foreach ($all_subs as $sub) { $all_subs = get_subscribed_requests($db);
if ($sub['status'] == 'Closed') { foreach ($all_subs as $sub) {
array_push($requests, $sub); if ($sub['status'] == 'Closed') {
array_push($requests, $sub);
}
} }
} return $requests;
return $requests;
} }
function get_request($db, $uuid) { function get_request($db, $uuid)
$ticket_stmt = "SELECT * FROM tickets WHERE uuid=:uuid"; {
$ticket_sql = $db->prepare($ticket_stmt); $ticket_stmt = "SELECT * FROM tickets WHERE uuid=:uuid";
$ticket_sql->bindParam(':uuid', $uuid); $ticket_sql = $db->prepare($ticket_stmt);
$ticket_sql->execute(); $ticket_sql->bindParam(':uuid', $uuid);
$ticket_sql->setFetchMode(PDO::FETCH_ASSOC); $ticket_sql->execute();
$ticket_result = $ticket_sql->fetchAll(); $ticket_sql->setFetchMode(PDO::FETCH_ASSOC);
$request = $ticket_result[0]; $ticket_result = $ticket_sql->fetchAll();
return $request; $request = $ticket_result[0];
return $request;
} }
function get_updates($db, $request) { function get_updates($db, $request)
$updates_stmt = "SELECT * FROM ticket_updates WHERE ticket=:uuid"; {
$updates_sql = $db->prepare($updates_stmt); $updates_stmt = "SELECT * FROM ticket_updates WHERE ticket=:uuid";
$updates_sql->bindParam(':uuid', $request['uuid']); $updates_sql = $db->prepare($updates_stmt);
$updates_sql->execute(); $updates_sql->bindParam(':uuid', $request['uuid']);
$updates_sql->setFetchMode(PDO::FETCH_ASSOC); $updates_sql->execute();
$updates_result = $updates_sql->fetchAll(); $updates_sql->setFetchMode(PDO::FETCH_ASSOC);
return $updates_result; $updates_result = $updates_sql->fetchAll();
return $updates_result;
} }
function get_files($db, $request) { function get_files($db, $request)
$stmt = "SELECT * FROM ticket_uploads WHERE ticket=:uuid"; {
$sql = $db->prepare($stmt); $stmt = "SELECT * FROM ticket_uploads WHERE ticket=:uuid";
$sql->bindParam(':uuid', $request['uuid']); $sql = $db->prepare($stmt);
$sql->execute(); $sql->bindParam(':uuid', $request['uuid']);
$sql->setFetchMode(PDO::FETCH_ASSOC); $sql->execute();
$result = $sql->fetchAll(); $sql->setFetchMode(PDO::FETCH_ASSOC);
return $result; $result = $sql->fetchAll();
return $result;
} }
function get_single_file($db, $fileid) { function get_single_file($db, $fileid)
$stmt = "SELECT * FROM ticket_uploads WHERE id=:fileid"; {
$sql = $db->prepare($stmt); $stmt = "SELECT * FROM ticket_uploads WHERE id=:fileid";
$sql->bindParam(':fileid', $fileid); $sql = $db->prepare($stmt);
$sql->execute(); $sql->bindParam(':fileid', $fileid);
$sql->setFetchMode(PDO::FETCH_ASSOC); $sql->execute();
$result = $sql->fetchAll(); $sql->setFetchMode(PDO::FETCH_ASSOC);
$file = $result[0]; $result = $sql->fetchAll();
return $file; $file = $result[0];
return $file;
} }
function get_subscribers($db, $request) { function get_subscribers($db, $request)
$subs = array(); {
$users_stmt = "SELECT user_uuid FROM ticket_subscribers WHERE ticket_uuid=:uuid"; $subs = array();
$users_sql = $db->prepare($users_stmt); $users_stmt = "SELECT user_uuid FROM ticket_subscribers WHERE ticket_uuid=:uuid";
$users_sql->bindParam(':uuid', $request['uuid']); $users_sql = $db->prepare($users_stmt);
$users_sql->execute(); $users_sql->bindParam(':uuid', $request['uuid']);
$users_sql->setFetchMode(PDO::FETCH_ASSOC); $users_sql->execute();
$users_result = $users_sql->fetchAll(); $users_sql->setFetchMode(PDO::FETCH_ASSOC);
foreach ($users_result as $u) { $users_result = $users_sql->fetchAll();
array_push($subs, $u['user_uuid']); foreach ($users_result as $u) {
} array_push($subs, $u['user_uuid']);
return $subs; }
return $subs;
} }
function isAuthorised($user, $authorised_users, $request) { function isAuthorised($user, $authorised_users, $request)
if ( in_array($user, $authorised_users) || $_SESSION['uuid'] == $request['created_by']) { return true; } else { return false; } {
if (in_array($user, $authorised_users) || $_SESSION['uuid'] == $request['created_by']) {
return true;
} else {
return false;
}
} }

View File

@@ -1,9 +1,10 @@
</main>
<footer class="footer mt-auto py-3"> <footer class="footer mt-auto py-3">
<div class="text-center text-muted"> <div class="text-center text-muted">
<?php <?php
echo($_ENV['APP_NAME'] . " v" . $_ENV['APP_VERSION']); echo($_ENV['APP_NAME'] . " " . get_version());
if ($_ENV['APP_NAME'] != "FHeD") { if ($_ENV['APP_NAME'] != "FHeD") {
echo(", powered by FHeD"); echo("| Powered by FHeD");
}; };
?><br> ?><br>
<?php if (is_signed_in()) { <?php if (is_signed_in()) {

View File

@@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#563d7c"> <meta name="theme-color" content="#563d7c">
<link rel="icon" type="image/png" href="/favicon.png"> <link rel="icon" type="image/png" href="/favicon.png">
<title><?php echo( $PAGE_TITLE ); ?></title> <title><?php echo($PAGE_TITLE); ?></title>
<!-- Bootstrap core CSS --> <!-- Bootstrap core CSS -->
<link rel="stylesheet" href="/css/bootstrap.min.css"> <link rel="stylesheet" href="/css/bootstrap.min.css">
@@ -19,6 +19,8 @@
</head> </head>
<body class="d-flex flex-column h-100"> <body class="d-flex flex-column h-100">
<!-- Begin page content -->
<main role="main" class="flex-shrink-0">
<header> <header>
<!-- Fixed navbar --> <!-- Fixed navbar -->
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark"> <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
@@ -32,10 +34,14 @@
<a class="nav-link" href="/">Home</a> <a class="nav-link" href="/">Home</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link <?php if (!is_signed_in()) {echo(' disabled');} ?>" href="/new">New request</a> <a class="nav-link <?php if (!is_signed_in()) {
echo(' disabled');
} ?>" href="/new">New request</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link <?php if (!is_signed_in()) {echo(' disabled');} ?>" href="/existing">Existing requests</a> <a class="nav-link <?php if (!is_signed_in()) {
echo(' disabled');
} ?>" href="/existing">Existing requests</a>
</li> </li>
</ul> </ul>
<div class="mt-2 mt-md-0"> <div class="mt-2 mt-md-0">

View File

@@ -7,17 +7,27 @@ require_once __DIR__ . "/../vendor/autoload.php";
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . "/.."); $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . "/..");
$dotenv->load(); $dotenv->load();
// Custom functions
require_once __DIR__ . "/app_functions.php";
// Sentry
Sentry\init([
'dsn' => 'https://7c4607ed5e804d08926cc0bbc0d3fbe9@app.glitchtip.com/59',
'release' => get_version(),
]);
// Database auto-generation // Database auto-generation
if (file_exists("/../includes/install.php")) { if (file_exists("/../includes/install.php")) {
return; return;
add_action('run_db_populate'); add_action('run_db_populate');
} }
function run_db_populate() { function run_db_populate()
{
// all my glorious one-time-magic. // all my glorious one-time-magic.
include( "/../includes/install.php" ); include("/../includes/install.php");
// after all execution rename your file; // after all execution rename your file;
rename( "/../includes/install.php", "/../includes/install-backup.php"); rename("/../includes/install.php", "/../includes/install-backup.php");
} }
// Session // Session
@@ -29,30 +39,9 @@ $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// OpenID Connect // OpenID Connect
use Jumbojett\OpenIDConnectClient; use Jumbojett\OpenIDConnectClient;
$oidc = new OpenIDConnectClient($_ENV['OIDC_HOST'], $_ENV['OIDC_CLIENT_ID'], $_ENV['OIDC_CLIENT_SECRET']); $oidc = new OpenIDConnectClient($_ENV['OIDC_HOST'], $_ENV['OIDC_CLIENT_ID'], $_ENV['OIDC_CLIENT_SECRET']);
if ($_ENV['OIDC_DISABLE_SSL'] == "true") { if ($_ENV['OIDC_DISABLE_SSL'] == "true") {
$oidc->setVerifyHost(false); $oidc->setVerifyHost(false);
$oidc->setVerifyPeer(false); $oidc->setVerifyPeer(false);
}
// Custom functions
require_once __DIR__ . "/app_functions.php";
function oidc_set_vars($sub, $uid, $fname, $lname, $email) {
$_SESSION['uuid'] = $sub;
$_SESSION['username'] = $uid;
$_SESSION['given_name'] = $fname;
$_SESSION['family_name'] = $lname;
$_SESSION['full_name'] = $fname . " " . $lname;
$_SESSION['email'] = $email;
}
function is_signed_in() {
if (isset($_SESSION['is_signed_in'])) {
return true;
} else {
return false;
}
} }

View File

@@ -4,9 +4,9 @@
// Perform the OIDC authentication // Perform the OIDC authentication
try { try {
$oidc->authenticate(); $oidc->authenticate();
$_SESSION['access_token'] = $oidc->requestClientCredentialsToken()->access_token; $_SESSION['access_token'] = $oidc->requestClientCredentialsToken()->access_token;
$oidc_user = array( $oidc_user = array(
'sub' => $oidc->requestUserInfo('sub'), 'sub' => $oidc->requestUserInfo('sub'),
'username' => $oidc->requestUserInfo('preferred_username'), 'username' => $oidc->requestUserInfo('preferred_username'),
'given_name' => $oidc->requestUserInfo('given_name'), 'given_name' => $oidc->requestUserInfo('given_name'),
@@ -14,46 +14,41 @@
'email' => $oidc->requestUserInfo('email'), 'email' => $oidc->requestUserInfo('email'),
); );
} catch (Jumbojett\OpenIDConnectClientException $e) { } catch (Jumbojett\OpenIDConnectClientException $e) {
$alert = array("danger", "Error during OpenID Connect authentication: " . $e->getMessage()); $alert = array("danger", "Error during OpenID Connect authentication: " . $e->getMessage());
} }
// Check if the user already exists if (user_exists($db, $oidc_user['sub']) == false) {
try { // User doesn't already exist
$user_exist_sql = $db->prepare("SELECT uuid FROM users WHERE uuid=:uuid"); try {
$user_exist_sql->bindParam(':uuid', $oidc_user['sub']); $stmt = "INSERT INTO users (uuid, uid, given_name, family_name, email) VALUES (:sub, :username, :given, :family, :email)";
$user_exist_sql->execute(); $sql = $db->prepare($stmt);
} catch (PDOException $e) { $sql->bindParam(':sub', $oidc_user['sub']);
$alert = array("danger", "Error during check for user record: " . $e->getMessage()); $sql->bindParam(':username', $oidc_user['username']);
} $sql->bindParam(':given', $oidc_user['given_name']);
$sql->bindParam(':family', $oidc_user['family_name']);
if (empty($user_exist_sql)) { $sql->bindParam(':email', $oidc_user['email']);
// User doesn't already exist $sql->execute();
try { } catch (PDOException $e) {
$stmt = "INSERT INTO users (uuid, uid, given_name, family_name, email) VALUES (:sub, :username, :given, :family, :email)"; echo("Error during creation of new user record: " . $e->getMessage());
$sql = $db->prepare($stmt); die();
$sql->bindParam(':sub', $oidc_user['sub']); $alert = array("danger", "Error during creation of new user record: " . $e->getMessage());
$sql->bindParam(':username', $oidc_user['username']); }
$sql->bindParam(':given', $oidc_user['given_name']);
$sql->bindParam(':family', $oidc_user['family_name']);
$sql->bindParam(':email', $oidc_user['email']);
$sql->execute();
} catch (Jumbojett\PDOException $e) {
$alert = array("danger", "Error during creation of new user record: " . $e->getMessage());
}
} else { } else {
// User already exists // User already exists
try { try {
$stmt = "UPDATE users SET uid=:username, given_name=:given, family_name=:family, email=:email WHERE uuid=:sub"; $stmt = "UPDATE users SET uid=:username, given_name=:given, family_name=:family, email=:email WHERE uuid=:sub";
$sql = $db->prepare($stmt); $sql = $db->prepare($stmt);
$sql->bindParam(':sub', $oidc_user['sub']); $sql->bindParam(':sub', $oidc_user['sub']);
$sql->bindParam(':username', $oidc_user['username']); $sql->bindParam(':username', $oidc_user['username']);
$sql->bindParam(':given', $oidc_user['given_name']); $sql->bindParam(':given', $oidc_user['given_name']);
$sql->bindParam(':family', $oidc_user['family_name']); $sql->bindParam(':family', $oidc_user['family_name']);
$sql->bindParam(':email', $oidc_user['email']); $sql->bindParam(':email', $oidc_user['email']);
$sql->execute(); $sql->execute();
} catch (Jumbojett\PDOException $e) { } catch (PDOException $e) {
$alert = array("danger", "Error during existing user record update: " . $e->getMessage()); echo("Error during existing user record update: " . $e->getMessage());
} die();
$alert = array("danger", "Error during existing user record update: " . $e->getMessage());
}
} }
oidc_set_vars($oidc_user['sub'], $oidc_user['username'], $oidc_user['given_name'], $oidc_user['family_name'], $oidc_user['email']); oidc_set_vars($oidc_user['sub'], $oidc_user['username'], $oidc_user['given_name'], $oidc_user['family_name'], $oidc_user['email']);
@@ -62,4 +57,3 @@
$_SESSION['is_signed_in'] = "true"; $_SESSION['is_signed_in'] = "true";
header('Location: /'); header('Location: /');
?>

View File

@@ -3,21 +3,17 @@
require_once __DIR__ . "/../includes/header.php"; require_once __DIR__ . "/../includes/header.php";
if (is_signed_in()) { if (is_signed_in()) {
$requests = get_my_open_requests($db); $requests = get_my_open_requests($db);
$subscriptions = get_open_subscribed_requests($db); $subscriptions = get_open_subscribed_requests($db);
} }
?> ?>
<!-- Begin page content -->
<main role="main" class="flex-shrink-0">
<section> <section>
<?php <?php
if(isset($alert)) { if (isset($alert)) {
echo(" echo("
<div class='container'> <div class='container'>
<div class='alert alert-" . $alert[0] . " alert-dismissible fade show' role='alert'> <div class='alert alert-" . $alert[0] . " alert-dismissible fade show' role='alert'>
" . $alert[1] . " " . $alert[1] . "
@@ -27,7 +23,7 @@
</div> </div>
</div> </div>
"); ");
unset($alert); unset($alert);
} }
?> ?>
</section> </section>
@@ -37,7 +33,11 @@
<h1>Welcome to <?php echo($_ENV['APP_NAME']); ?></h1> <h1>Welcome to <?php echo($_ENV['APP_NAME']); ?></h1>
<p class="lead text-muted"> <p class="lead text-muted">
<?php <?php
if ($_ENV['APP_NAME'] == "FHeD") {echo("The Free HelpDesk");} else {echo($_ENV['APP_NAME']);}; if ($_ENV['APP_NAME'] == "FHeD") {
echo("The Free HelpDesk");
} else {
echo($_ENV['APP_NAME']);
};
?> ?>
is the one-stop shop for all of your IT-related needs. Let us know how we can help you by opening a request. is the one-stop shop for all of your IT-related needs. Let us know how we can help you by opening a request.
</p> </p>
@@ -63,10 +63,10 @@
<ul class="list-group list-group-flush"> <ul class="list-group list-group-flush">
<?php <?php
if (count($requests) == 0) { if (count($requests) == 0) {
echo("<center><b>No open tickets</b></center>"); echo("<center><b>No open tickets</b></center>");
} else { } else {
foreach($requests as $tkt) { foreach ($requests as $tkt) {
?> ?>
<li class="list-group-item"> <li class="list-group-item">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
@@ -80,7 +80,9 @@
</div> </div>
</div> </div>
</li> </li>
<?php } } ?> <?php
}
} ?>
</ul> </ul>
</div> </div>
</div> </div>
@@ -93,9 +95,9 @@
<ul class="list-group list-group-flush"> <ul class="list-group list-group-flush">
<?php <?php
if (count($subscriptions) == 0) { if (count($subscriptions) == 0) {
echo("<center><b>No subscribed tickets</b></center>"); echo("<center><b>No subscribed tickets</b></center>");
} else { } else {
foreach($subscriptions as $sub) { ?> foreach ($subscriptions as $sub) { ?>
<li class="list-group-item"> <li class="list-group-item">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
@@ -109,7 +111,8 @@
</div> </div>
</div> </div>
</li> </li>
<?php } } ?> <?php }
} ?>
</ul> </ul>
</div> </div>
</section> </section>
@@ -118,8 +121,6 @@
</div> </div>
<?php } ?> <?php } ?>
</main>
<?php <?php
require_once __DIR__ . "/../includes/footer.php"; require_once __DIR__ . "/../includes/footer.php";
?> ?>

View File

@@ -6,6 +6,8 @@
$updates = get_updates($db, $request); $updates = get_updates($db, $request);
$authorised_users = get_subscribers($db, $request); $authorised_users = get_subscribers($db, $request);
$is_authorised = isAuthorised($_SESSION['uuid'], $authorised_users, $request); $is_authorised = isAuthorised($_SESSION['uuid'], $authorised_users, $request);
$rid = htmlspecialchars($_GET['rid'])
?> ?>
@@ -131,7 +133,7 @@
<div class="form-group" style="margin: 2%;"> <div class="form-group" style="margin: 2%;">
<textarea type="text" class="form-control" id="msg" name="msg" rows="3"></textarea> <textarea type="text" class="form-control" id="msg" name="msg" rows="3"></textarea>
<button type="submit" class="btn btn-primary" style="margin-top: 2%;">Submit</button> <button type="submit" class="btn btn-primary" style="margin-top: 2%;">Submit</button>
<a href="/view?rid=<?php echo($_GET['rid']); ?>" class="btn btn-danger" style="margin-top: 2%;">Cancel</a> <a href="/view?rid=<?php echo($rid); ?>" class="btn btn-danger" style="margin-top: 2%;">Cancel</a>
</div> </div>
</form> </form>
</div> </div>

View File

@@ -6,6 +6,8 @@
$updates = get_updates($db, $request); $updates = get_updates($db, $request);
$authorised_users = get_subscribers($db, $request); $authorised_users = get_subscribers($db, $request);
$is_authorised = isAuthorised($_SESSION['uuid'], $authorised_users, $request); $is_authorised = isAuthorised($_SESSION['uuid'], $authorised_users, $request);
$rid = htmlspecialchars($_GET['rid']);
?> ?>
@@ -131,7 +133,7 @@
<div class="form-group" style="margin: 2%;"> <div class="form-group" style="margin: 2%;">
<input type="file" class="form-control-file" id="file" name="file"> <input type="file" class="form-control-file" id="file" name="file">
<button type="submit" class="btn btn-primary" style="margin-top: 2%;">Submit</button> <button type="submit" class="btn btn-primary" style="margin-top: 2%;">Submit</button>
<a href="/view?rid=<?php echo($_GET['rid']); ?>" class="btn btn-danger" style="margin-top: 2%;">Cancel</a> <a href="/view?rid=<?php echo($rid); ?>" class="btn btn-danger" style="margin-top: 2%;">Cancel</a>
</div> </div>
</form> </form>
</div> </div>

12
sonar-project.properties Normal file
View File

@@ -0,0 +1,12 @@
sonar.projectKey=luketainton_FHeD
sonar.organization=luketainton
# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=FHeD
#sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
#sonar.sources=.
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8