From 5aa34e500730793415b2803143f5b68a9e9cc5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20M=C3=A4del?= Date: Sat, 27 Mar 2021 20:36:05 +0100 Subject: [PATCH] Refactoring, move to twig, webroot seperation --- apply_config.php | 130 +++++++ bootstrap.php | 14 + cgi-bin/applyConfig.php | 117 ------ cgi-bin/config.php | 22 -- cgi-bin/ottercast | 362 ------------------ config.php | 71 ++++ example_config.ini | 17 + example_config.sh | 10 - .../assets}/bootstrap.bundle.min.js | 0 .../assets}/bootstrap.bundle.min.js.map | 0 {assets => public/assets}/bootstrap.min.css | 0 .../assets}/bootstrap.min.css.map | 0 .../assets}/emoji_u1f9a6_headphone2.svg | 0 {assets => public/assets}/form-validation.css | 0 {assets => public/assets}/form-validation.js | 0 {assets => public/assets}/jquery-3.5.1.min.js | 0 {assets => public/assets}/logo.svg | 0 public/assets/ottercast.css | 63 +++ public/cgi-bin/ottercast | 80 ++++ index.html => public/index.html | 0 templates/layout.twig | 56 +++ templates/setup.twig | 160 ++++++++ 22 files changed, 591 insertions(+), 511 deletions(-) create mode 100644 apply_config.php create mode 100644 bootstrap.php delete mode 100755 cgi-bin/applyConfig.php delete mode 100644 cgi-bin/config.php delete mode 100755 cgi-bin/ottercast create mode 100644 config.php create mode 100644 example_config.ini delete mode 100644 example_config.sh rename {assets => public/assets}/bootstrap.bundle.min.js (100%) rename {assets => public/assets}/bootstrap.bundle.min.js.map (100%) rename {assets => public/assets}/bootstrap.min.css (100%) rename {assets => public/assets}/bootstrap.min.css.map (100%) rename {assets => public/assets}/emoji_u1f9a6_headphone2.svg (100%) rename {assets => public/assets}/form-validation.css (100%) rename {assets => public/assets}/form-validation.js (100%) rename {assets => public/assets}/jquery-3.5.1.min.js (100%) rename {assets => public/assets}/logo.svg (100%) create mode 100644 public/assets/ottercast.css create mode 100644 public/cgi-bin/ottercast rename index.html => public/index.html (100%) create mode 100644 templates/layout.twig create mode 100644 templates/setup.twig diff --git a/apply_config.php b/apply_config.php new file mode 100644 index 0000000..86f0fde --- /dev/null +++ b/apply_config.php @@ -0,0 +1,130 @@ + '/tmp/twig_cache', +]); + diff --git a/cgi-bin/applyConfig.php b/cgi-bin/applyConfig.php deleted file mode 100755 index 9e18f61..0000000 --- a/cgi-bin/applyConfig.php +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - OtterCastAudio - - - - - - - - - - - - - - -
- -
- - -
-
-
-

-
- - - - - -
-
-

- Status -

-
    -
  • -
    -
    WiFi
    - connected, dBm, not connected -
    -
  • -
  • -
    -
    Ethernet
    - connected, not connected -
    -
  • -
  • -
    -
    System load
    - -
    -
  • -
-
-
-
-
- - " pattern="[A-Za-z0-9\-]{3,50}" required> -
- Please enter a valid hostname. -
-
- - -
- -

WiFi details

- -
-
- - " required> -
- Please enter a valid network name (SSID). -
-
- -
- - -
- Please enter your passphase (PSK). -
-
-
- -
- -

Protocols

- -
- > - -
- -
- > - -
- -
- > - -
- -
- > - -
-
- - "> -
- Please enter a valid hostname or IP address. -
-
- -
- -

Line-In Streaming (Snapcast Server)

-
OtterCast is able to stream the Line-In port directly to another OtterCast or Snapcast Client.
- Make sure "Snapcast Client" protocol is active on the receiver.
Avahi/mDNS can be used with the ".local" suffix.
-
- > - -
- - -
- - -
-
-
-
- -
-

© 2020-2021 by
Jan Henrik Hemsig, Niklas Fauth,
Tobias Schramm, Tobias Mädel

-
- -
-
- - - - - - - - \ No newline at end of file diff --git a/config.php b/config.php new file mode 100644 index 0000000..5930883 --- /dev/null +++ b/config.php @@ -0,0 +1,71 @@ + $elements) + { + $result .= "[" . $section . "]\n"; + foreach ($elements as $key => $value) + { + if (is_string($value)) + { + $result .= $key . " = \"" . $value . "\"\n"; + } + elseif (is_bool($value)) + { + $result .= $key . " = " . ($value ? 'true' : 'false') . "\n"; + } + else + { + $result .= $key . " = " . $value . "\n"; + } + } + $result .= "\n"; + } + return $result; +} \ No newline at end of file diff --git a/example_config.ini b/example_config.ini new file mode 100644 index 0000000..9561cdd --- /dev/null +++ b/example_config.ini @@ -0,0 +1,17 @@ +; OtterCast Configuration file +; Make sure to quote special characters, e.g. key = "value" + +[general] +hostname = "OtterCastAudio" + +[network] +wifi_ssid = "" +wifi_passphrase = "" + +[software] +airplay_active = true +pulseaudio_active = true +librespot_active = true +snapcast_client_active = false +snapcast_client_hostname = "" +linein_stream_active = false \ No newline at end of file diff --git a/example_config.sh b/example_config.sh deleted file mode 100644 index e2b83e9..0000000 --- a/example_config.sh +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_DISPLAY_NAME='OtterCastAudio' -CONFIG_WIFI_SSID='' -CONFIG_WIFI_PSK='' -CONFIG_AIRPLAY_ACTIVE='1' -CONFIG_PULSEAUDIO_ACTIVE='1' -CONFIG_PULSEAUDIO_LATENCY='8' -CONFIG_LIBRESPOT_ACTIVE='1' -CONFIG_SNAPCAST_CLIENT_ACTIVE='0' -CONFIG_SNAPCAST_CLIENT_HOST='' -CONFIG_LINEIN_STREAM_ACTIVE='0' diff --git a/assets/bootstrap.bundle.min.js b/public/assets/bootstrap.bundle.min.js similarity index 100% rename from assets/bootstrap.bundle.min.js rename to public/assets/bootstrap.bundle.min.js diff --git a/assets/bootstrap.bundle.min.js.map b/public/assets/bootstrap.bundle.min.js.map similarity index 100% rename from assets/bootstrap.bundle.min.js.map rename to public/assets/bootstrap.bundle.min.js.map diff --git a/assets/bootstrap.min.css b/public/assets/bootstrap.min.css similarity index 100% rename from assets/bootstrap.min.css rename to public/assets/bootstrap.min.css diff --git a/assets/bootstrap.min.css.map b/public/assets/bootstrap.min.css.map similarity index 100% rename from assets/bootstrap.min.css.map rename to public/assets/bootstrap.min.css.map diff --git a/assets/emoji_u1f9a6_headphone2.svg b/public/assets/emoji_u1f9a6_headphone2.svg similarity index 100% rename from assets/emoji_u1f9a6_headphone2.svg rename to public/assets/emoji_u1f9a6_headphone2.svg diff --git a/assets/form-validation.css b/public/assets/form-validation.css similarity index 100% rename from assets/form-validation.css rename to public/assets/form-validation.css diff --git a/assets/form-validation.js b/public/assets/form-validation.js similarity index 100% rename from assets/form-validation.js rename to public/assets/form-validation.js diff --git a/assets/jquery-3.5.1.min.js b/public/assets/jquery-3.5.1.min.js similarity index 100% rename from assets/jquery-3.5.1.min.js rename to public/assets/jquery-3.5.1.min.js diff --git a/assets/logo.svg b/public/assets/logo.svg similarity index 100% rename from assets/logo.svg rename to public/assets/logo.svg diff --git a/public/assets/ottercast.css b/public/assets/ottercast.css new file mode 100644 index 0000000..8aff0d6 --- /dev/null +++ b/public/assets/ottercast.css @@ -0,0 +1,63 @@ +.bd-placeholder-img { + font-size: 1.125rem; + text-anchor: middle; + -webkit-user-select: none; + -moz-user-select: none; + user-select: none; +} + +@media (min-width: 768px) { + .bd-placeholder-img-lg { + font-size: 3.5rem; + } +} + +.logo { + user-drag: none; + user-select: none; + -moz-user-select: none; + -webkit-user-drag: none; + -webkit-user-select: none; + -ms-user-select: none; + margin-right: 20px; +} + +.logo-text { + -webkit-touch-callout: none; /* iOS Safari */ + -webkit-user-select: none; /* Safari */ + -khtml-user-select: none; /* Konqueror HTML */ + -moz-user-select: none; /* Old versions of Firefox */ + -ms-user-select: none; /* Internet Explorer/Edge */ + user-select: none; /* Non-prefixed version, currently + supported by Chrome, Edge, Opera and Firefox */ +} + +label.form-check-label { + user-drag: none; + user-select: none; + -moz-user-select: none; + -webkit-user-drag: none; + -webkit-user-select: none; + -ms-user-select: none; +} + +.bd-callout { + padding: 1.25rem; + /* margin-top: 1.25rem; */ + margin-bottom: 1.25rem; + border: 1px solid #e9ecef; + border-left-width: .25rem; + border-radius: .25rem; + background-color: #ffffff; +} +.bd-callout-info { + border-left-color: #5bc0de !important; +} + +.bd-callout-warning { + border-left-color: #f0ad4e +} + +.bd-callout-danger { + border-left-color: #d9534f +} \ No newline at end of file diff --git a/public/cgi-bin/ottercast b/public/cgi-bin/ottercast new file mode 100644 index 0000000..cf57bba --- /dev/null +++ b/public/cgi-bin/ottercast @@ -0,0 +1,80 @@ +#!/usr/bin/env php-cgi +render('setup.twig', [ + 'restarted_services' => ($restarted_services ?? false), + 'config' => $config, + 'post' => $_POST, + 'status' => [ + "wifi_connected" => $wifi_connected, + "wifi_rssi" => $wifi_rssi, + "wifi_ipv4" => $wifi_ipv4, + + "ethernet_connected" => $ethernet_connected, + "ethernet_ipv4" => $ethernet_ipv4, + + "loadavg" => $loadavg + ] +]); \ No newline at end of file diff --git a/index.html b/public/index.html similarity index 100% rename from index.html rename to public/index.html diff --git a/templates/layout.twig b/templates/layout.twig new file mode 100644 index 0000000..da883cc --- /dev/null +++ b/templates/layout.twig @@ -0,0 +1,56 @@ + + + + + + + + + OtterCastAudio + + + + + + + + + + + + + +
+ +
+ +
+
+ {% block content %}{% endblock %} +
+ +
+

© 2020-2021 by
Jan Henrik Hemsig, Niklas Fauth,
Tobias Schramm, Tobias Mädel

+
+ +
+
+ + + + + {% block script %}{% endblock %} + + \ No newline at end of file diff --git a/templates/setup.twig b/templates/setup.twig new file mode 100644 index 0000000..599d78c --- /dev/null +++ b/templates/setup.twig @@ -0,0 +1,160 @@ +{% extends "layout.twig" %} + +{% block content %} +
+

+
+ + {% if post.ssid %} + + {% endif %} + + {% if restarted_services %} + + {% endif %} + +
+
+

+ Status +

+
    +
  • +
    +
    WiFi
    + {% if status.wifi_connected %} + connected, {{ status.wifi_rssi }}dBm, {{ status.wifi_ipv4 }} + {% else %} + not connected + {% endif %} +
    +
  • +
  • +
    +
    Ethernet
    + {% if status.ethernet_connected %} + connected, {{ status.ethernet_ipv4 }} + {% else %} + not connected + {% endif %} +
    +
  • +
  • +
    +
    System load
    + {{ status.loadavg }} +
    +
  • +
+
+
+
+
+ + +
+ Please enter a valid hostname. +
+
+ + +
+ +

WiFi details

+ +
+
+ + +
+ Please enter a valid network name (SSID). +
+
+ +
+ + +
+ Please enter your passphase (PSK). +
+
+
+ +
+ +

Protocols

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ + +
+ Please enter a valid hostname or IP address. +
+
+ +
+ +

Line-In Streaming (Snapcast Server)

+
OtterCast is able to stream the Line-In port directly to another OtterCast or Snapcast Client.
+ Make sure "Snapcast Client" protocol is active on the receiver.
Avahi/mDNS can be used with the ".local" suffix.
+
+ + +
+ +
+ + +
+
+
+{% endblock %} + +{% block script %} + +{% endblock %}