Skip to content

Commit bf7c446

Browse files
authored
Merge pull request #1146 from UniversityRadioYork/mg-stuffs
fun fact: this has been running in prod for a while
2 parents b759efc + 00a8a27 commit bf7c446

File tree

11 files changed

+101
-7
lines changed

11 files changed

+101
-7
lines changed

Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM php:8.2-apache
22

33
RUN apt-get update && apt-get install -y libpq-dev libpng-dev libjpeg-dev libldap-dev unzip \
44
libcurl4-openssl-dev libxslt-dev git libz-dev libzip-dev libmemcached-dev \
5-
postgresql-client jq msmtp-mta
5+
postgresql-client jq msmtp-mta ffmpeg
66

77
RUN docker-php-ext-install pgsql pdo_pgsql gd ldap curl xsl zip
88

@@ -18,6 +18,10 @@ RUN pecl install xdebug-3.3.1 && docker-php-ext-enable xdebug \
1818

1919
RUN echo 'error_reporting=E_ALL' >> /usr/local/etc/php/conf.d/error-reporting.ini
2020

21+
RUN echo "memory_limit=512M" >> /usr/local/etc/php/conf.d/uploads.ini
22+
RUN echo "upload_max_filesize=512M" >> /usr/local/etc/php/conf.d/uploads.ini
23+
RUN echo "post_max_size=512M" >> /usr/local/etc/php/conf.d/uploads.ini
24+
2125
RUN echo sendmail_path = "/usr/bin/msmtp -t --host mail --port 1025 --from [email protected]" > /usr/local/etc/php/conf.d/sendmail.ini
2226

2327
# Self-signed certificate

Dockerfile.prod

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
FROM php:8.2-apache
2+
3+
RUN apt-get update && apt-get install -y libpq-dev libpng-dev libjpeg-dev libldap-dev unzip \
4+
libcurl4-openssl-dev libxslt-dev git libz-dev libzip-dev libmemcached-dev \
5+
postgresql-client jq msmtp-mta ffmpeg
6+
7+
RUN docker-php-ext-install pgsql pdo_pgsql gd ldap curl xsl zip
8+
9+
RUN pecl install memcached && \
10+
echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini
11+
12+
RUN pecl install xdebug-3.3.1 && docker-php-ext-enable xdebug \
13+
&& echo 'zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so"' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
14+
&& echo 'xdebug.client_port=9003' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
15+
&& echo 'xdebug.mode=develop,debug' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
16+
&& echo 'xdebug.start_with_request=yes' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
17+
&& echo 'xdebug.client_host=localhost' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
18+
19+
RUN echo 'error_reporting=E_ALL' >> /usr/local/etc/php/conf.d/error-reporting.ini
20+
21+
RUN echo "memory_limit=512M" >> /usr/local/etc/php/conf.d/uploads.ini
22+
RUN echo "upload_max_filesize=512M" >> /usr/local/etc/php/conf.d/uploads.ini
23+
RUN echo "post_max_size=512M" >> /usr/local/etc/php/conf.d/uploads.ini
24+
25+
RUN echo sendmail_path = "/usr/bin/msmtp -t --host ury.york.ac.uk --port 587 --from [email protected]" > /usr/local/etc/php/conf.d/sendmail.ini
26+
27+
# Self-signed certificate
28+
RUN openssl req -nodes -new -subj "/C=GB/ST=North Yorkshire/L=York/O=University Radio York/OU=Localhost/CN=localhost" > myradio.csr && \
29+
openssl rsa -in privkey.pem -out myradio.key && \
30+
openssl x509 -in myradio.csr -out myradio.crt -req -signkey myradio.key -days 999 && \
31+
cp myradio.crt /etc/apache2/myradio.crt && \
32+
cp myradio.key /etc/apache2/myradio.key
33+
34+
RUN a2enmod rewrite ssl
35+
36+
COPY sample_configs/apache.conf /etc/apache2/sites-available/myradio.conf
37+
RUN a2dissite 000-default && a2ensite myradio && \
38+
service apache2 restart && apachectl -S
39+
40+
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
41+
42+
RUN mkdir -p /var/www/myradio && chown -R www-data:www-data /var/www/myradio && \
43+
mkdir -p /var/log/myradio && chown -R www-data:www-data /var/log/myradio
44+
45+
WORKDIR /var/www/myradio
46+
COPY composer.* /var/www/myradio/
47+
RUN COMPOSER_VENDOR_DIR=/var/www/myradio/src/vendor composer install
48+
49+
COPY schema schema
50+
COPY src src
51+
52+
COPY sample_configs/docker-config.php src/MyRadio_Config.local.php
53+
RUN chown www-data:www-data /var/www/myradio/src/MyRadio_Config.local.php && chmod 664 /var/www/myradio/src/MyRadio_Config.local.php
54+
55+
CMD ["apache2-foreground"]

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
"ext-xmlwriter": "*",
1010
"webonyx/graphql-php": "^0.13.8",
1111
"ext-json": "*",
12+
"spatie/icalendar-generator": "^2.1",
13+
"simshaun/recurr": "^4.0",
1214
"geoip2/geoip2": "^2.10.0",
1315
"spatie/icalendar-generator": "^2.1",
14-
"ext-pgsql": "*"
16+
"ext-pgsql": "*",
17+
"rbdwllr/reallysimplejwt": "4.0.3"
1518
},
1619
"require-dev": {
1720
"squizlabs/php_codesniffer": "~3.5",

src/Classes/Config.php

+1
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ final class Config
543543
*/
544544
public static $recaptcha_public_key = 'YOUR_API_KEY';
545545
public static $recaptcha_private_key = 'YOUR_PRIVATE_KEY';
546+
public static $jwt_signing_secret = 'SECRET_HERE';
546547

547548
public static $autoviz_clips_path = '';
548549
public static $autoviz_public_clips_base = '/media/autoviz-clips';

src/Classes/ServiceAPI/MyRadio_Demo.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ public static function listDemos()
326326
$demos = [];
327327
foreach ($result as $demo) {
328328
$demo['demo_time'] = date('D d M H:i', strtotime($demo['demo_time']));
329-
$demo['memberid'] = MyRadio_User::getInstance($demo['memberid'])->getName();
329+
$demo['member'] = MyRadio_User::getInstance($demo['memberid'])->getName();
330+
$demo['memberid'] = (int)$demo['memberid'];
330331
$demo['presenterstatusid'] = MyRadio_TrainingStatus::getInstance($demo['presenterstatusid'])->getTitle();
331332
$demos[] = $demo;
332333
}

src/Classes/ServiceAPI/MyRadio_User.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public function getEmail()
556556
//Return the local mailbox, or, failing that, eduroam
557557
$local = $this->getLocalName();
558558
if (!empty($local)) {
559-
return $local;
559+
return $local.'@'.Config::$email_domain;
560560
} else {
561561
//ffs, some people don't have an eduroam either.
562562
$eduroam = $this->getEduroam();

src/Controllers/MyRadio/jwt.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use ReallySimpleJWT\Token;
4+
5+
use \MyRadio\Config;
6+
use \MyRadio\MyRadioException;
7+
use \MyRadio\ServiceAPI\MyRadio_User;
8+
9+
if (isset($_GET['redirectto'])) {
10+
// would be nice to replace this with an RSA based
11+
// one, so a consumer can't be a producer
12+
13+
$payload = [
14+
'iat' => time(),
15+
'uid' => $_SESSION['memberid'],
16+
'name' => MyRadio_User::getCurrentUser()->getName(),
17+
'exp' => time() + 3600 * 3,
18+
'iss' => Config::$base_url
19+
];
20+
21+
header("Location: " . $_GET["redirectto"] . "?jwt=" . Token::customPayload($payload, Config::$jwt_signing_secret));
22+
23+
} else {
24+
throw new MyRadioException('redirectto must be provided', 400);
25+
}

src/Controllers/root.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function ($e) {
119119
// Changing the serialize handler to the general serialize/unserialize methods lets us
120120
// read sessions without actually having to activate them and read them into $_SESSION
121121
ini_set('session.serialize_handler', 'php_serialize');
122-
122+
123123
session_set_save_handler($session_handler, true);
124124
session_start();
125125
}

src/Menus/menu.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
{
6363
"title": "Book an off-air studio",
64-
"url": "https://docs.google.com/spreadsheets/d/1tJ9E0laOPX-_nkWiPT9amDaliCWFRZENWDW51gLhTOM/edit?usp=sharing",
64+
"url": "https://booking.ury.org.uk",
6565
"description": "Need an off-air studio? Book here now!"
6666
},
6767
{

src/MyRadio_Config.local.php.dist

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ Config::$api_uri = '/api/';
6969
Config::$api_url = '//ury.org.uk/api';
7070

7171
/**
72-
* Recaptcha Settings
72+
* Auth Settings
7373
*/
7474
Config::$recaptcha_public_key = 'YOUR KEY HERE';
7575
Config::$recaptcha_private_key = 'YOUR KEY HERE';
76+
Config::$jwt_signing_secret = 'SECRET_HERE';
7677

7778
/**
7879
* Feature enable

src/Public/js/myradio.training.demolist.js

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ $(".twig-datatable").dataTable({
1717
{
1818
"sTitle": "Time"
1919
},
20+
//memberid
21+
{
22+
"bVisible": false
23+
},
2024
//member
2125
{
2226
"sTitle": "Trainer"

0 commit comments

Comments
 (0)