Skip to content

Commit

Permalink
Refactoring, move to twig, webroot seperation
Browse files Browse the repository at this point in the history
  • Loading branch information
Manawyrm committed Mar 27, 2021
1 parent b8b9353 commit 5aa34e5
Show file tree
Hide file tree
Showing 22 changed files with 591 additions and 511 deletions.
130 changes: 130 additions & 0 deletions apply_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
require(__DIR__ . "/config.php");

`mount -o remount,rw /`;

$snapclient_config_path = "/etc/default/snapclient";
$wpaconf_path = "/etc/wpa_supplicant/wpa_supplicant-wlan0.conf";
$ssh_system_authorized_keys = "/root/.ssh/authorized_keys";

// 23 == 0dB capture gain
`amixer cset name='Capture Volume' 23`;

if (file_exists($ssh_key_file))
{
if (file_get_contents($ssh_system_authorized_keys) != file_get_contents($ssh_key_file))
{
@mkdir(dirname($ssh_system_authorized_keys));
file_put_contents($ssh_system_authorized_keys, file_get_contents($ssh_key_file));
chmod($ssh_system_authorized_keys, 0700);
}
}

if ($config['software']["airplay_active"])
{
`systemctl start shairport-sync`;
}
else
{
`systemctl stop shairport-sync`;
}

if ($config['software']["pulseaudio_active"])
{
`systemctl start pulseaudio`;
}
else
{
`systemctl stop pulseaudio`;
}

if ($config['software']["librespot_active"])
{
`systemctl start librespot`;
}
else
{
`systemctl stop librespot`;
}

if ($config['software']["linein_stream_active"])
{
`systemctl start snapserver`;
}
else
{
`systemctl stop snapserver`;
}

if ($config['software']["snapcast_client_active"])
{
$snapclient_config = 'START_SNAPCLIENT=true' . "\n" .
'SNAPCLIENT_OPTS="-h ' . escapeshellarg($config['software']["snapcast_client_hostname"]) . '"' . "\n";
if (file_get_contents($snapclient_config_path) != $snapclient_config)
{
file_put_contents($snapclient_config_path, $snapclient_config);
`systemctl restart snapclient`;
}
else
{
`systemctl start snapclient`;
}
}
else
{
`systemctl stop snapclient`;
}

$wpaconf = 'ctrl_interface=/var/run/wpa_supplicant
#ap_scan=1
network={
ssid="'. addslashes($config['network']["wifi_ssid"]) .'"
scan_ssid=1
key_mgmt=WPA-PSK
psk="'. addslashes($config['network']["wifi_passphrase"]) .'"
}
';

if (file_get_contents($wpaconf_path) != $wpaconf)
{
file_put_contents($wpaconf_path, $wpaconf);
`ifdown --force wlan0`;
`systemctl restart network`;
`ifup wlan0`;
}
else
{
`ifup wlan0`;
}

if (trim(file_get_contents("/etc/hostname")) != trim($config['general']["hostname"]))
{
$cmd = 'hostnamectl set-hostname ' . escapeshellarg($config['general']["hostname"]);
`$cmd`;

`systemctl restart avahi-daemon`;

if ($config['software']["pulseaudio_active"])
{
`systemctl restart pulseaudio`;
}
if ($config['software']["airplay_active"])
{
`systemctl restart shairport-sync`;
}
if ($config['software']["librespot_active"])
{
`systemctl restart librespot`;
}
if ($config['software']["snapcast_client_active"])
{
`systemctl restart snapclient`;
}
if ($config['software']["linein_stream_active"])
{
`systemctl restart snapserver`;
}
}

`mount -o remount,ro /`;
14 changes: 14 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

define("SERVER_PATH", __DIR__);

require_once(SERVER_PATH . '/vendor/autoload.php');
require_once(SERVER_PATH . '/config.php');

$loader = new \Twig\Loader\FilesystemLoader(SERVER_PATH.'/templates');
$twig = new \Twig\Environment($loader, [
'cache' => '/tmp/twig_cache',
]);

117 changes: 0 additions & 117 deletions cgi-bin/applyConfig.php

This file was deleted.

22 changes: 0 additions & 22 deletions cgi-bin/config.php

This file was deleted.

Loading

0 comments on commit 5aa34e5

Please sign in to comment.