80 lines
2.3 KiB
Bash
80 lines
2.3 KiB
Bash
sudo cp -r encoder/* /var/www/encoder/
|
|
sudo cp -r html/* /var/www/html/
|
|
sudo cp attempts.json /var/www/attempts.json
|
|
DEVICE_ID="$(sudo cat /sys/class/dmi/id/product_uuid | tr -d '\n')"
|
|
sudo sed -i 's/certificatecertificatecertificatecertificate/'$DEVICE_ID'/g' /var/www/html/certification.html
|
|
|
|
cat > /etc/apache2/sites-available/000-default.conf << 'EOL'
|
|
<VirtualHost *:8080>
|
|
ServerName localhost
|
|
ServerAdmin webmaster@localhost
|
|
DocumentRoot /var/www/encoder
|
|
|
|
ErrorLog ${APACHE_LOG_DIR}/encoder-error.log
|
|
CustomLog ${APACHE_LOG_DIR}/encoder-access.log combined
|
|
|
|
SSLEngine on
|
|
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
|
|
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
|
|
|
|
<Directory /var/www/encoder>
|
|
Options Indexes FollowSymLinks
|
|
AllowOverride All
|
|
Require all granted
|
|
</Directory>
|
|
</VirtualHost>
|
|
EOL
|
|
|
|
cat>/etc/apache2/ports.conf<< 'EOL'
|
|
<IfModule mod_ssl.c>
|
|
Listen 8080
|
|
</IfModule>
|
|
EOL
|
|
|
|
|
|
SOURCE_FILE="users.json"
|
|
TARGET_FILE="/var/www/users.json"
|
|
|
|
if [ ! -f "$TARGET_FILE" ]; then
|
|
cp "$SOURCE_FILE" "$TARGET_FILE"
|
|
fi
|
|
|
|
SOURCE_FILE="users.json"
|
|
TARGET_FILE="/var/www/users.json"
|
|
|
|
if [ ! -f "$TARGET_FILE" ]; then
|
|
cp "$SOURCE_FILE" "$TARGET_FILE"
|
|
fi
|
|
|
|
cat > /etc/nginx/sites-available/default << 'EOL'
|
|
server {
|
|
listen 80 default_server;
|
|
listen [::]:80 default_server;
|
|
server_name _;
|
|
|
|
root /var/www/html;
|
|
index index.html;
|
|
|
|
# These are fine at the server level, but safer inside location
|
|
add_header Access-Control-Allow-Origin "*" always;
|
|
add_header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS" always;
|
|
add_header Access-Control-Allow-Headers "Authorization, Content-Type, Accept, Origin, X-Requested-With" always;
|
|
|
|
location / {
|
|
# Handle the OPTIONS (Preflight) request correctly
|
|
if ($request_method = OPTIONS) {
|
|
add_header Access-Control-Allow-Origin "*" always;
|
|
add_header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS" always;
|
|
add_header Access-Control-Allow-Headers "Authorization, Content-Type, Accept, Origin, X-Requested-With" always;
|
|
add_header Content-Length 0;
|
|
add_header Content-Type text/plain;
|
|
return 204;
|
|
}
|
|
|
|
try_files $uri $uri/ =404;
|
|
}
|
|
}
|
|
EOL
|
|
|
|
sudo chown -R www-data:www-data /var/www/*
|
|
sudo reboot |