Skip to content

Commit b8b7c01

Browse files
committed
Add Powerbox proxy
1 parent 121fabc commit b8b7c01

File tree

11 files changed

+71
-6
lines changed

11 files changed

+71
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11

22
*.spk
33

4+
# Copied during build
5+
includes/powerbox-http-proxy.js

.sandstorm/go-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
go1.25.4

.sandstorm/launcher.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ if [ ! -e /var/.db-created ]; then
5757
touch /var/.db-created
5858
fi
5959

60+
# Start our powerbox proxy server, and wait for it to write the cert:
61+
export DB_TYPE=mysql
62+
export DB_URI="root@unix(/var/run/mysqld/mysqld.sock)/app"
63+
export CA_CERT_PATH=/var/ca-spoof-cert.pem
64+
rm -f $CA_CERT_PATH
65+
/opt/powerbox-http-proxy/powerbox-http-proxy &
66+
wait_for "root cert" "$CA_CERT_PATH"
67+
68+
export http_proxy=http://127.0.0.1:$POWERBOX_PROXY_PORT
69+
export https_proxy=http://127.0.0.1:$POWERBOX_PROXY_PORT
70+
6071
wait_for php-fpm8.2 /var/run/php/php8.2-fpm.sock
6172

6273
# Start nginx.

.sandstorm/sandstorm-files.list

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ etc/php/8.2/mods-available/xmlreader.ini
7979
etc/php/8.2/mods-available/xmlwriter.ini
8080
etc/php/8.2/mods-available/xsl.ini
8181
etc/services
82+
etc/ssl/certs
83+
etc/ssl/certs/ca-certificates.crt
8284
etc/ssl/openssl.cnf
8385
lib
8486
lib64
@@ -107,6 +109,8 @@ opt/app/includes/global.php
107109
opt/app/includes/global_req_login.php
108110
opt/app/includes/header.php
109111
opt/app/includes/include_lconfig.php
112+
opt/app/includes/include_proxycontext.php
113+
opt/app/includes/powerbox-http-proxy.js
110114
opt/app/includes/variables.php
111115
opt/app/index.php
112116
opt/app/install_into_db.sql
@@ -138,6 +142,7 @@ opt/app/styles/xrflight/images/footer.png
138142
opt/app/styles/xrflight/style.css
139143
opt/app/viewrecord.php
140144
opt/app/xrfinfo.php
145+
opt/powerbox-http-proxy/powerbox-http-proxy
141146
proc/cpuinfo
142147
sandstorm-http-bridge
143148
sandstorm-http-bridge-config
@@ -155,7 +160,7 @@ usr/bin/touch
155160
usr/lib/locale/C.utf8/LC_CTYPE
156161
usr/lib/mysql/plugin/authentication_oci_client.so
157162
usr/lib/mysql/plugin/component_reference_cache.so
158-
usr/lib/mysql/private/libprotobuf-lite.so.3.19.4
163+
usr/lib/mysql/private/libprotobuf-lite.so.24.4.0
159164
usr/lib/php/20220829/calendar.so
160165
usr/lib/php/20220829/ctype.so
161166
usr/lib/php/20220829/curl.so
@@ -185,6 +190,8 @@ usr/lib/php/20220829/xml.so
185190
usr/lib/php/20220829/xmlreader.so
186191
usr/lib/php/20220829/xmlwriter.so
187192
usr/lib/php/20220829/xsl.so
193+
usr/lib/ssl/cert.pem
194+
usr/lib/ssl/certs
188195
usr/lib/ssl/openssl.cnf
189196
usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
190197
usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
@@ -350,6 +357,7 @@ usr/share/zoneinfo/Arctic/Longyearbyen
350357
usr/share/zoneinfo/Asia
351358
usr/share/zoneinfo/Asia/Ashkhabad
352359
usr/share/zoneinfo/Asia/Calcutta
360+
usr/share/zoneinfo/Asia/Choibalsan
353361
usr/share/zoneinfo/Asia/Chongqing
354362
usr/share/zoneinfo/Asia/Chungking
355363
usr/share/zoneinfo/Asia/Dacca

.sandstorm/sandstorm-pkgdef.capnp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ const myCommand :Spk.Manifest.Command = (
226226
# Note that this defines the *entire* environment seen by your app.
227227
(key = "PATH", value = "/usr/local/bin:/usr/bin:/bin"),
228228
(key = "SANDSTORM", value = "1"),
229+
(key = "POWERBOX_WEBSOCKET_PORT", value = "3000"),
230+
(key = "POWERBOX_PROXY_PORT", value = "4000"),
229231
# Export SANDSTORM=1 into the environment, so that apps running within Sandstorm
230232
# can detect if $SANDSTORM="1" at runtime, switching UI and/or backend to use
231233
# the app's Sandstorm-specific integration code.

.sandstorm/service-config/nginx.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,12 @@ http {
8181
# PHP only, required if PHP was built with --enable-force-cgi-redirect
8282
fastcgi_param REDIRECT_STATUS 200;
8383
}
84+
location /_sandstorm/websocket {
85+
proxy_pass http://127.0.0.1:3000;
86+
proxy_http_version 1.1;
87+
proxy_set_header Upgrade $http_upgrade;
88+
proxy_set_header Connection "Upgrade";
89+
proxy_set_header Host $host;
90+
}
8491
}
8592
}

.sandstorm/setup.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ set -euo pipefail
88
export DEBIAN_FRONTEND=noninteractive
99

1010
echo -e "deb http://repo.mysql.com/apt/debian/ bookworm mysql-8.0\ndeb-src http://repo.mysql.com/apt/debian/ bookworm mysql-8.0" > /etc/apt/sources.list.d/mysql.list
11-
wget -O /tmp/RPM-GPG-KEY-mysql https://repo.mysql.com/RPM-GPG-KEY-mysql-2023
12-
apt-key add /tmp/RPM-GPG-KEY-mysql
11+
apt-key adv --keyserver hkps://keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C
1312

1413
apt-get update
1514
apt-get install -y nginx php-fpm php-mysql php-cli php-curl git php-dev mysql-server
@@ -55,4 +54,24 @@ innodb_log_file_size = 1048576
5554
tmpdir = /var/tmp
5655
# Set the main data file to grow by 1MB at a time, rather than 8MB at a time.
5756
innodb_autoextend_increment = 1
58-
EOF
57+
EOF
58+
59+
# The version of golang in the debian repositories tends to be incredibly
60+
# out of date; let's get ourselves a newer version from upstream:
61+
if [ -e /opt/app/.sandstorm/go-version ]; then
62+
# Get the same version we've used before
63+
curl -L "https://go.dev/dl/$(cat '/opt/app/.sandstorm/go-version').linux-amd64.tar.gz" -o go.tar.gz
64+
else
65+
# Get the newest version for a new project
66+
curl -L "https://go.dev/dl/$(curl 'https://go.dev/VERSION?m=text' | head -n 1).linux-amd64.tar.gz" -o go.tar.gz
67+
fi
68+
tar -C /usr/local -xzf go.tar.gz
69+
rm go.tar.gz
70+
echo 'export PATH=/usr/local/go/bin:$PATH' > /etc/profile.d/go.sh
71+
72+
# Get the same version next time
73+
/usr/local/go/bin/go version | cut -d ' ' -f 3 > /opt/app/.sandstorm/go-version
74+
75+
cd /opt && git clone https://github.com/sandstorm-org/powerbox-http-proxy
76+
cd /opt/powerbox-http-proxy && /usr/local/go/bin/go build
77+
cp /opt/powerbox-http-proxy/powerbox-http-proxy.js /opt/app/includes/powerbox-http-proxy.js

includes/header.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
else {$xrf_style = $xrf_mystylepref;}
55
if (isset($xrf_page_subtitle)) { $xrf_title_nugget = " - "; } else { $xrf_page_subtitle = ""; $xrf_title_nugget = ""; }
66
echo "<html><head><title>$xrf_site_name Library$xrf_title_nugget$xrf_page_subtitle</title>
7+
<script src=\"includes\powerbox-http-proxy.js\"></script>
78
<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/$xrf_style/style.css\" />
89
<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/print/style.css\" media=\"print\" />
910
</head><body>";

includes/include_proxycontext.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$xrf_proxyopts = array(
4+
'http' => array(
5+
'proxy' => 'tcp://127.0.0.1:4000',
6+
'ignore_errors' => true,
7+
),
8+
);
9+
$xrf_proxycontext = stream_context_create($xrf_proxyopts);
10+
11+
// $proxyrequest = file_get_contents("https://sandstorm.io", false, $xrf_proxycontext);
12+
13+
?>

modules/library/acpm_addbook.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require("ismodule.php");
33
require("modules/$modfolder/functions_lib.php");
44
require("modules/$modfolder/include_lconfig.php");
5+
require("includes/include_proxycontext.php");
56
$do = $_GET['do'] ?? '';
67
if ($do == "add")
78
{
@@ -105,7 +106,7 @@
105106
$sourcetags = xrf_mysql_result($sourcedataresult,0,"tags");
106107
} elseif ($copyfrom != "" && $xrfl_locgov_enable == 1) {
107108
// import from library of congress
108-
$marcxml = simplexml_load_file("https://lccn.loc.gov/$copyfrom/marcxml");
109+
$marcxml = simplexml_load_file(file_get_contents("https://lccn.loc.gov/$copyfrom/marcxml",false,$xrf_proxycontext));
109110
foreach($marcxml as $datafield) {
110111
if ($datafield['tag'] == "245") {
111112
// title

0 commit comments

Comments
 (0)