Merge pull request #57 from seanmorris/master

Separating Drupal, Cleaning up build
This commit is contained in:
Oraoto authored and GitHub committed 2021-11-24 23:53:29 +08:00
commit d3f8d93e8a
68 files changed
+357359 -708282

No files matched your search

+7 -4
View File
@@ -13,11 +13,14 @@ jobs:
make:
parallelism: 1
machine:
image: ubuntu-1604:202007-01
image: ubuntu-2004:202107-02
steps:
- checkout
- run: sudo apt update && sudo apt install pv
- run: sudo apt update
- run: sudo apt install -y pv ca-certificates apt-transport-https
- run: sudo apt-get install --reinstall ca-certificates
- run: sudo update-ca-certificates
- run: docker system prune -af
- run: make pull-image
- run: make -j8
- run: make image
- run: make -j1
+1
View File
@@ -9,3 +9,4 @@
configured
.env
/*-src/
/docs/*.map
+2 -2
View File
@@ -13,10 +13,10 @@ before_install:
- docker run -dit --name emscripten -v $(pwd):/src trzeci/emscripten-ubuntu:latest bash
script:
- sudo apt update && sudo apt install pv
- sudo apt update && sudo apt install -y pv libxml2-dev
- docker system prune -af
- make pull-image
- make -j8
- make -j4
notifications:
email: false
+6
View File
@@ -2,6 +2,12 @@
Changes
## 0.0.4 - Revisiting
* Separated Drupal from standard php-web to save bandwidth
* Running the build automatically on push in CircleCI
* Getting the automatic build working for Drupal
## 0.0.3 - New Horizons
* php.exec() may be used to evaluate a single php expression & return its result.
+51 -20
View File
@@ -1,12 +1,12 @@
-include .env
UID?=1000 # Change this in your .env file if you're not UID 1000
SHELL=bash -euo pipefail
ENVIRONMENT ?=web
INITIAL_MEMORY ?=1gb
INITIAL_MEMORY ?=1024MB
PRELOAD_ASSETS ?=preload/
ASSERTIONS ?=0
OPTIMIZE ?=-O1
OPTIMIZE ?=-O3
RELEASE_SUFFIX ?=
PHP_BRANCH ?=php-7.4.20
@@ -17,7 +17,7 @@ TIDYHTML_TAG ?=5.6.0
PKG_CONFIG_PATH ?=/src/lib/lib/pkgconfig
DOCKER_ENV=UID=${UID} docker-compose -p phpwasm run --rm \
DOCKER_ENV=USERID=${UID} docker-compose -p phpwasm run --rm \
-e PKG_CONFIG_PATH=${PKG_CONFIG_PATH} \
-e PRELOAD_ASSETS='${PRELOAD_ASSETS}' \
-e INITIAL_MEMORY=${INITIAL_MEMORY} \
@@ -30,16 +30,16 @@ DOCKER_RUN_IN_ICU4C =${DOCKER_ENV} -w /src/third_party/libicu-src/icu4c/source/
DOCKER_RUN_IN_LIBXML =${DOCKER_ENV} -w /src/third_party/libxml2/ emscripten-builder
TIMER=(which pv > /dev/null && pv --name '${@}' || cat)
.PHONY: web all clean show-ports image js hooks push-image pull-image
.PHONY: web all clean image js hooks push-image pull-image
all: php-web.wasm php-webview.wasm php-node.wasm php-shell.wasm php-worker.wasm js
all: php-web.wasm php-web-drupal.wasm php-webview.wasm php-node.wasm php-shell.wasm php-worker.wasm js
web: lib/pib_eval.o php-web.wasm
@ echo "Done!"
########### Collect & patch the source code. ###########
third_party/sqlite3.33-src/sqlite3.c:
@ echo -e "\e[33mDownloading and patching SQLite"
@ wget https://sqlite.org/2020/sqlite-amalgamation-3330000.zip
@ ${DOCKER_RUN} unzip sqlite-amalgamation-3330000.zip
@ ${DOCKER_RUN} rm -r sqlite-amalgamation-3330000.zip
@@ -47,6 +47,7 @@ third_party/sqlite3.33-src/sqlite3.c:
@ ${DOCKER_RUN} git apply --no-index patch/sqlite3-wasm.patch
third_party/php7.4-src/patched: third_party/sqlite3.33-src/sqlite3.c
@ echo -e "\e[33mDownloading and patching PHP"
@ ${DOCKER_RUN} git clone https://github.com/php/php-src.git third_party/php7.4-src \
--branch ${PHP_BRANCH} \
--single-branch \
@@ -57,25 +58,31 @@ third_party/php7.4-src/patched: third_party/sqlite3.33-src/sqlite3.c
@ ${DOCKER_RUN} touch third_party/php7.4-src/patched
source/sqlite3.c: third_party/sqlite3.33-src/sqlite3.c third_party/php7.4-src/patched
@ echo -e "\e[33mImporting SQLite"
@ ${DOCKER_RUN} cp -v third_party/sqlite3.33-src/sqlite3.c source/sqlite3.c
@ ${DOCKER_RUN} cp -v third_party/sqlite3.33-src/sqlite3.h source/sqlite3.h
@ ${DOCKER_RUN} cp -v third_party/sqlite3.33-src/sqlite3.h third_party/php7.4-src/main/sqlite3.h
@ ${DOCKER_RUN} cp -v third_party/sqlite3.33-src/sqlite3.c third_party/php7.4-src/main/sqlite3.c
third_party/php7.4-src/ext/vrzno/vrzno.c: third_party/php7.4-src/patched
@ echo -e "\e[33mDownloading and importing VRZNO"
@ ${DOCKER_RUN} git clone https://github.com/seanmorris/vrzno.git third_party/php7.4-src/ext/vrzno \
--branch ${VRZNO_BRANCH} \
--single-branch \
--depth 1
third_party/drupal-7.59/README.txt:
@ echo -e "\e[33mDownloading and patching Drupal"
@ wget https://ftp.drupal.org/files/projects/drupal-7.59.zip
@ ${DOCKER_RUN} unzip drupal-7.59.zip
@ ${DOCKER_RUN} rm -v drupal-7.59.zip
@ ${DOCKER_RUN} mv drupal-7.59 third_party/drupal-7.59
@ ${DOCKER_RUN} git apply --no-index patch/drupal-7.59.patch
@ ${DOCKER_RUN} cp -r extras/drupal-7-settings.php third_party/drupal-7.59/sites/default/settings.php
@ ${DOCKER_RUN} cp -r extras/drowser-files third_party/drupal-7.59/sites/default/files
@ ${DOCKER_RUN} cp -r extras/drowser-files/.ht.sqlite third_party/drupal-7.59/sites/default/files/.ht.sqlite
@ ${DOCKER_RUN} cp -r extras/drowser-files/* third_party/drupal-7.59/sites/default/files
@ ${DOCKER_RUN} cp -r extras/drowser-logo.png third_party/drupal-7.59/sites/default/logo.png
@ ${DOCKER_RUN} mkdir -p third_party/php7.4-src/preload/
@ ${DOCKER_RUN} cp -r third_party/drupal-7.59 third_party/drupal-7.59 third_party/php7.4-src/preload/
# third_party/libicu-src:
@@ -84,8 +91,9 @@ third_party/drupal-7.59/README.txt:
# --single-branch \
# --depth 1;
third_party/libxml2:
@ ${DOCKER_RUN} git clone https://gitlab.gnome.org/GNOME/libxml2.git third_party/libxml2 \
third_party/libxml2/.gitignore:
@ echo -e "\e[33mDownloading LibXML2"
@ ${DOCKER_RUN} env GIT_SSL_NO_VERIFY=true git clone https://gitlab.gnome.org/GNOME/libxml2.git third_party/libxml2 \
--branch ${LIBXML2_TAG} \
--single-branch \
--depth 1;
@@ -98,13 +106,14 @@ third_party/libxml2:
########### Build the objects. ###########
third_party/php7.4-src/configure: third_party/php7.4-src/ext/vrzno/vrzno.c source/sqlite3.c
third_party/php7.4-src/configure: third_party/php7.4-src/ext/vrzno/vrzno.c source/sqlite3.c lib/lib/libxml2.la
@ echo -e "\e[33mBuilding PHP object files"
${DOCKER_RUN_IN_PHP} ./buildconf --force
${DOCKER_RUN_IN_PHP} bash -c "emconfigure ./configure \
PKG_CONFIG_PATH=${PKG_CONFIG_PATH} \
--enable-embed=static \
--with-layout=GNU \
--with-libxml=static \
--with-libxml \
--disable-cgi \
--disable-cli \
--disable-all \
@@ -127,13 +136,18 @@ third_party/php7.4-src/configure: third_party/php7.4-src/ext/vrzno/vrzno.c sourc
--disable-mbregex \
--enable-tokenizer \
--enable-vrzno \
--enable-xml \
--enable-simplexml \
--with-gd \
"
lib/libphp7.a: third_party/php7.4-src/configure third_party/php7.4-src/patched third_party/php7.4-src/**.c source/sqlite3.c
@ echo -e "\e[33mBuilding PHP symbol files"
@ ${DOCKER_RUN_IN_PHP} emmake make -j8
${DOCKER_RUN} cp -v third_party/php7.4-src/.libs/libphp7.la third_party/php7.4-src/.libs/libphp7.a lib/
@ ${DOCKER_RUN} cp -v third_party/php7.4-src/.libs/libphp7.la third_party/php7.4-src/.libs/libphp7.a lib/
lib/pib_eval.o: lib/libphp7.a source/pib_eval.c
@ echo -e "\e[33mRun pkgconfig"
${DOCKER_RUN_IN_PHP} emcc ${OPTIMIZE} \
-I . \
-I Zend \
@@ -141,11 +155,12 @@ lib/pib_eval.o: lib/libphp7.a source/pib_eval.c
-I TSRM/ \
-I /src/third_party/libxml2 \
/src/source/pib_eval.c \
-o /src/lib/pib_eval.o
-o /src/lib/pib_eval.o \
lib/something:
lib/lib/libxml2.la: third_party/libxml2/.gitignore
@ echo -e "\e[33mBuilding LibXML2"
${DOCKER_RUN_IN_LIBXML} ./autogen.sh
${DOCKER_RUN_IN_LIBXML} emconfigure ./configure --prefix=/src/lib/ | ${TIMER}
${DOCKER_RUN_IN_LIBXML} emconfigure ./configure --with-http=no --with-ftp=no --with-python=no --with-threads=no --enable-shared=no --prefix=/src/lib/ | ${TIMER}
${DOCKER_RUN_IN_LIBXML} emmake make | ${TIMER}
${DOCKER_RUN_IN_LIBXML} emmake make install | ${TIMER}
@@ -153,9 +168,7 @@ lib/something:
FINAL_BUILD=${DOCKER_RUN_IN_PHP} emcc ${OPTIMIZE} \
-o ../../build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.js \
--preload-file ../drupal-7.59@/preload/drupal-7.59 \
--llvm-lto 2 \
--preload-file ${PRELOAD_ASSETS} \
-s EXPORTED_FUNCTIONS='["_pib_init", "_pib_destroy", "_pib_run", "_pib_exec" "_pib_refresh", "_main", "_php_embed_init", "_php_embed_shutdown", "_php_embed_shutdown", "_zend_eval_string", "_exec_callback", "_del_callback"]' \
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "UTF8ToString", "lengthBytesUTF8"]' \
-s ENVIRONMENT=${ENVIRONMENT} \
@@ -167,17 +180,28 @@ FINAL_BUILD=${DOCKER_RUN_IN_PHP} emcc ${OPTIMIZE} \
-s EXPORT_NAME="'PHP'" \
-s MODULARIZE=1 \
-s INVOKE_RUN=0 \
-s USE_ZLIB=1 \
/src/lib/pib_eval.o /src/lib/libphp7.a /src/lib/lib/libxml2.a
php-web-drupal.wasm: ENVIRONMENT=web-drupal
php-web-drupal.wasm: lib/libphp7.a lib/pib_eval.o source/**.c source/**.h third_party/drupal-7.59/README.txt
@ echo -e "\e[33mBuilding PHP for web (drupal)"
@ ${FINAL_BUILD} --preload-file ${PRELOAD_ASSETS} -s ENVIRONMENT=web
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./docs-source/app/assets
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./docs-source/public
php-web.wasm: ENVIRONMENT=web
php-web.wasm: lib/libphp7.a lib/pib_eval.o source/**.c source/**.h third_party/drupal-7.59/README.txt
${FINAL_BUILD}
php-web.wasm: lib/libphp7.a lib/pib_eval.o source/**.c source/**.h
@ echo -e "\e[33mBuilding PHP for web"
@ ${FINAL_BUILD}
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./docs-source/app/assets
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./docs-source/public
php-worker.wasm: ENVIRONMENT=worker
php-worker.wasm: lib/libphp7.a lib/pib_eval.o source/**.c source/**.h
@ echo -e "\e[33mBuilding PHP for workers"
@ ${FINAL_BUILD}
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./docs-source/app/assets
@@ -185,6 +209,7 @@ php-worker.wasm: lib/libphp7.a lib/pib_eval.o source/**.c source/**.h
php-node.wasm: ENVIRONMENT=node
php-node.wasm: lib/libphp7.a lib/pib_eval.o source/**.c source/**.h
@ echo -e "\e[33mBuilding PHP for node"
@ ${FINAL_BUILD}
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./docs-source/app/assets
@@ -192,6 +217,7 @@ php-node.wasm: lib/libphp7.a lib/pib_eval.o source/**.c source/**.h
php-shell.wasm: ENVIRONMENT=shell
php-shell.wasm: lib/libphp7.a lib/pib_eval.o source/**.c source/**.h
@ echo -e "\e[33mBuilding PHP for shell"
@ ${FINAL_BUILD}
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./docs-source/app/assets
@@ -199,6 +225,7 @@ php-shell.wasm: lib/libphp7.a lib/pib_eval.o source/**.c source/**.h
php-webview.wasm: ENVIRONMENT=webview
php-webview.wasm: lib/libphp7.a lib/pib_eval.o source/pib_eval.c
@ echo -e "\e[33mBuilding PHP for webview"
@ ${FINAL_BUILD}
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./
@ ${DOCKER_RUN} cp -v build/php-${ENVIRONMENT}${RELEASE_SUFFIX}.* ./docs-source/app/assets
@@ -214,10 +241,14 @@ clean:
@ ${DOCKER_RUN} rm -rfv third_party/libicu-src
@ ${DOCKER_RUN} rm -rfv third_party/sqlite3.33-src
show-ports:
@ ${DOCKER_RUN} emcc --show-ports
hooks:
@ git config core.hooksPath githooks
js:
@ echo -e "\e[33mBuilding JS"
@ npm install | ${TIMER}
@ npx babel source --out-dir . | ${TIMER}
+2 -2
View File
@@ -24,8 +24,8 @@
+ [JSON](https://seanmorris.github.io/php-wasm/?code=%253C%253Fphp%250A%250A%2524x%2520%253D%2520%255B%250A%2520%2520%2520%2522id%2522%2520%253D%253E%25201%2520%2520%250A%255D%253B%250A%250Avar_dump%28json_decode%28json_encode%28%2524x%29%29%29%253B%250A)
+ [Closures](https://seanmorris.github.io/php-wasm/?code=%253C%253Fphp%250A%250A%2524x%2520%253D%252010%253B%250A%250Afunction%2520run%28callable%2520%2524f%29%2520%257B%250A%2520%2520%2520%2520%2524f%28%29%253B%250A%257D%250A%250Arun%28function%2520%28%29%2520use%2520%28%2526%2524x%29%2520%257B%250A%2520%2520%2520%2520%2524x%2520%253D%25209%253B%250A%257D%29%253B%250A%250Avar_dump%28%2524x%29%253B%250A)
+ [File access](https://seanmorris.github.io/php-wasm/?code=%253C%253Fphp%250A%250A%2524it%2520%253D%2520new%2520RecursiveIteratorIterator%28new%2520RecursiveDirectoryIterator%28%2522.%2522%29%29%253B%250A%250Aforeach%2520%28%2524it%2520as%2520%2524name%2520%253D%253E%2520%2524entry%29%2520%257B%250A%2520%2520%2520%2520echo%2520%2524name%2520.%2520%2522%253Cbr%252F%253E%2522%253B%250A%257D%250A)
+ [Zend/bench.php](https://seanmorris.github.io/php-wasm/?autorun=0&persist=0&single-expression=0&code=%253C%253Fphp%250A%250Ainclude%28%2522%252Fpreload%252FZend%252Fbench.php%2522%29%253B%250A&render-as=text)
+ [Drupal 7](https://seanmorris.github.io/php-wasm/?code=%253C%253Fphp%250Aini_set%28%27session.save_path%27%252C%2520%27%252Fhome%252Fweb_user%27%29%253B%250Asession_id%28%27fake-cookie%27%29%253B%250Asession_start%28%29%253B%250A%250A%2524stdErr%2520%253D%2520fopen%28%27php%253A%252F%252Fstderr%27%252C%2520%27w%27%29%253B%250A%2524errors%2520%253D%2520%255B%255D%253B%250A%250Aregister_shutdown_function%28function%28%29%2520use%28%2524stdErr%252C%2520%2526%2524errors%29%257B%250A%2520%2520%2520%2520fwrite%28%2524stdErr%252C%2520json_encode%28%255B%27session_id%27%2520%253D%253E%2520session_id%28%29%255D%29%2520.%2520%2522%255Cn%2522%29%253B%250A%2520%2520%2520%2520fwrite%28%2524stdErr%252C%2520json_encode%28%255B%27headers%27%253D%253Eheaders_list%28%29%255D%29%2520.%2520%2522%255Cn%2522%29%253B%250A%2520%2520%2520%2520fwrite%28%2524stdErr%252C%2520json_encode%28%255B%27errors%27%2520%253D%253E%2520error_get_last%28%29%255D%29%2520.%2520%2522%255Cn%2522%29%253B%250A%257D%29%253B%250A%250Aset_error_handler%28function%28...%2524args%29%2520use%28%2524stdErr%252C%2520%2526%2524errors%29%257B%250A%2509fwrite%28%2524stdErr%252C%2520print_r%28%2524args%252C1%29%29%253B%250A%257D%29%253B%250A%250A%2524origin%2520%2520%253D%2520%27http%253A%252F%252Flocalhost%253A3333%27%253B%250A%2524docroot%2520%253D%2520%27%252Fpreload%252Fdrupal-7.59%27%253B%250A%2524path%2520%2520%2520%2520%253D%2520%27%252F%27%253B%250A%2524script%2520%2520%253D%2520%27index.php%27%253B%250A%250A%2524_SERVER%255B%27REQUEST_URI%27%255D%2520%2520%2520%2520%2520%253D%2520%2524docroot%253B%250A%2524_SERVER%255B%27REMOTE_ADDR%27%255D%2520%2520%2520%2520%2520%253D%2520%27127.0.0.1%27%253B%250A%2524_SERVER%255B%27SERVER_NAME%27%255D%2520%2520%2520%2520%2520%253D%2520%2524origin%253B%250A%2524_SERVER%255B%27SERVER_PORT%27%255D%2520%2520%2520%2520%2520%253D%25203333%253B%250A%2524_SERVER%255B%27REQUEST_METHOD%27%255D%2520%2520%253D%2520%27GET%27%253B%250A%2524_SERVER%255B%27SCRIPT_FILENAME%27%255D%2520%253D%2520%2524docroot%2520.%2520%27%252F%27%2520.%2520%2524script%253B%250A%2524_SERVER%255B%27SCRIPT_NAME%27%255D%2520%2520%2520%2520%2520%253D%2520%2524docroot%2520.%2520%27%252F%27%2520.%2520%2524script%253B%250A%2524_SERVER%255B%27PHP_SELF%27%255D%2520%2520%2520%2520%2520%2520%2520%2520%253D%2520%2524docroot%2520.%2520%27%252F%27%2520.%2520%2524script%253B%250A%250Achdir%28%2524docroot%29%253B%250A%250Adefine%28%27DRUPAL_ROOT%27%252C%2520getcwd%28%29%29%253B%250A%250Arequire_once%2520DRUPAL_ROOT%2520.%2520%27%252Fincludes%252Fbootstrap.inc%27%253B%250Adrupal_bootstrap%28DRUPAL_BOOTSTRAP_FULL%29%253B%250A%250A%2524uid%2520%2520%2520%2520%2520%253D%25201%253B%250A%2524user%2520%2520%2520%2520%253D%2520user_load%28%2524uid%29%253B%250A%2524account%2520%253D%2520array%28%27uid%27%2520%253D%253E%2520%2524user-%253Euid%29%253B%250Auser_login_submit%28array%28%29%252C%2520%2524account%29%253B%250A%250Amenu_execute_active_handler%28%29%253B&persist=0&single-expression=0&render-as=html&autorun=1)
+ [Zend/bench.php](https://seanmorris.github.io/php-wasm?autorun=0&persist=0&single-expression=0&code=%253C%253Fphp%250A%250Ainclude%28%2522%252Fpreload%252FZend%252Fbench.php%2522%29%253B%250A&render-as=text)
+ [Drupal 7](https://seanmorris.github.io/php-wasm/?autorun=0&persist=0&single-expression=0&code=%253C%253Fphp%250Aini_set%28%27session.save_path%27%252C%2520%27%252Fhome%252Fweb_user%27%29%253B%250A%250A%2524stdErr%2520%253D%2520fopen%28%27php%253A%252F%252Fstderr%27%252C%2520%27w%27%29%253B%250A%2524errors%2520%253D%2520%255B%255D%253B%250A%250Aregister_shutdown_function%28function%28%29%2520use%28%2524stdErr%252C%2520%2526%2524errors%29%257B%250A%2520%2520%2520%2520fwrite%28%2524stdErr%252C%2520json_encode%28%255B%27session_id%27%2520%253D%253E%2520session_id%28%29%255D%29%2520.%2520%2522%255Cn%2522%29%253B%250A%2520%2520%2520%2520fwrite%28%2524stdErr%252C%2520json_encode%28%255B%27headers%27%253D%253Eheaders_list%28%29%255D%29%2520.%2520%2522%255Cn%2522%29%253B%250A%2520%2520%2520%2520fwrite%28%2524stdErr%252C%2520json_encode%28%255B%27errors%27%2520%253D%253E%2520error_get_last%28%29%255D%29%2520.%2520%2522%255Cn%2522%29%253B%250A%257D%29%253B%250A%250Aset_error_handler%28function%28...%2524args%29%2520use%28%2524stdErr%252C%2520%2526%2524errors%29%257B%250A%2509fwrite%28%2524stdErr%252C%2520print_r%28%2524args%252C1%29%29%253B%250A%257D%29%253B%250A%250A%2524docroot%2520%253D%2520%27%252Fpreload%252Fdrupal-7.59%27%253B%250A%2524path%2520%2520%2520%2520%253D%2520%27%252F%27%253B%250A%2524script%2520%2520%253D%2520%27index.php%27%253B%250A%250A%2524_SERVER%255B%27REQUEST_URI%27%255D%2520%2520%2520%2520%2520%253D%2520%2524docroot%2520.%2520%2524path%253B%250A%2524_SERVER%255B%27REMOTE_ADDR%27%255D%2520%2520%2520%2520%2520%253D%2520%27127.0.0.1%27%253B%250A%2524_SERVER%255B%27SERVER_NAME%27%255D%2520%2520%2520%2520%2520%253D%2520%27localhost%27%253B%250A%2524_SERVER%255B%27SERVER_PORT%27%255D%2520%2520%2520%2520%2520%253D%25203333%253B%250A%2524_SERVER%255B%27REQUEST_METHOD%27%255D%2520%2520%253D%2520%27GET%27%253B%250A%2524_SERVER%255B%27SCRIPT_FILENAME%27%255D%2520%253D%2520%2524docroot%2520.%2520%27%252F%27%2520.%2520%2524script%253B%250A%2524_SERVER%255B%27SCRIPT_NAME%27%255D%2520%2520%2520%2520%2520%253D%2520%2524docroot%2520.%2520%27%252F%27%2520.%2520%2524script%253B%250A%2524_SERVER%255B%27PHP_SELF%27%255D%2520%2520%2520%2520%2520%2520%2520%2520%253D%2520%2524docroot%2520.%2520%27%252F%27%2520.%2520%2524script%253B%250A%250Achdir%28%2524docroot%29%253B%250A%250Aob_start%28%29%253B%250A%250Adefine%28%27DRUPAL_ROOT%27%252C%2520getcwd%28%29%29%253B%250A%250Arequire_once%2520DRUPAL_ROOT%2520.%2520%27%252Fincludes%252Fbootstrap.inc%27%253B%250Adrupal_bootstrap%28DRUPAL_BOOTSTRAP_FULL%29%253B%250A%250A%2524uid%2520%2520%2520%2520%2520%253D%25201%253B%250A%2524user%2520%2520%2520%2520%253D%2520user_load%28%2524uid%29%253B%250A%2524account%2520%253D%2520array%28%27uid%27%2520%253D%253E%2520%2524user-%253Euid%29%253B%250Auser_login_submit%28array%28%29%252C%2520%2524account%29%253B%250A%250A%2524itemPath%2520%253D%2520%2524path%253B%250A%2524itemPath%2520%253D%2520preg_replace%28%27%252F%255E%255C%255C%252Fpreload%252F%27%252C%2520%27%27%252C%2520%2524itemPath%29%253B%250A%2524itemPath%2520%253D%2520preg_replace%28%27%252F%255E%255C%255C%252Fdrupal-7.59%252F%27%252C%2520%27%27%252C%2520%2524itemPath%29%253B%250A%2524itemPath%2520%253D%2520preg_replace%28%27%252F%255E%255C%252F%252F%27%252C%2520%27%27%252C%2520%2524itemPath%29%253B%250A%250Aif%28%2524itemPath%29%250A%257B%250A%2520%2520%2520%2520%250A%2520%2520%2520%2520%2524router_item%2520%253D%2520menu_get_item%28%2524itemPath%29%253B%250A%2520%2520%2520%2520%2524router_item%255B%27access_callback%27%255D%2520%253D%2520true%253B%250A%2520%2520%2520%2520%2524router_item%255B%27access%27%255D%2520%253D%2520true%253B%250A%2520%2520%2520%2520%250A%2520%2520%2520%2520if%2520%28%2524router_item%255B%27include_file%27%255D%29%2520%257B%250A%2520%2520%2520%2520%2520%2520require_once%2520DRUPAL_ROOT%2520.%2520%27%252F%27%2520.%2520%2524router_item%255B%27include_file%27%255D%253B%250A%2520%2520%2520%2520%257D%250A%2520%2520%2520%2520%250A%2520%2520%2520%2520%2524page_callback_result%2520%253D%2520call_user_func_array%28%2524router_item%255B%27page_callback%27%255D%252C%2520unserialize%28%2524router_item%255B%27page_arguments%27%255D%29%29%253B%250A%2520%2520%2520%2520%250A%2520%2520%2520%2520drupal_deliver_page%28%2524page_callback_result%29%253B%250A%257D%250Aelse%250A%257B%250A%2520%2520%2520%2520menu_execute_active_handler%28%29%253B%250A%257D&render-as=html)
## Getting Started
+1 -1
View File
@@ -3,7 +3,7 @@ version: '3'
services:
emscripten-builder:
user: ${UID}:${UID}
user: ${USERID}
image: seanmorris/php-emscripten-builder
build:
context: ./
+4
View File
@@ -3,10 +3,12 @@
import { process } from 'process/browser';
self.addEventListener('install', event => {
console.log('Install');
self.skipWaiting();
});
self.addEventListener('activate', event => {
console.log('Activate');
event.waitUntil(clients.claim());
});
@@ -15,6 +17,8 @@ self.addEventListener('fetch', event => event.respondWith(new Promise(accept =>
const pathname = url.pathname.replace(/^\//, '');
const path = pathname.split('/');
console.log(path);
if(!path[ path.length-1 ].match(/\.\w+$/)
&& (path[1] === 'drupal-7.59' || path[2] === 'drupal-7.59')
){
+19 -1
View File
@@ -113,6 +113,24 @@ sso++++++///++//oyyyyhhhyyyyssoo+++syhhhdmNNNNmmmmmmmmdhhyhmNNNmddhhddmmmmmmmmNm
<img src = "sean-icon.png" />
</a>
<h1>php-wasm</h1>
<hr />
<select data-select-demo>
<option value>Select a Demo</option>
<option value = "hello-world.php">Hello, World!</option>
<option value = "phpinfo.php">phpinfo();</option>
<option value = "persistent-memory.php">Persistent Memory</option>
<option value = "dom-access.php">DOM Access</option>
<option value = "goto.php">GoTo</option>
<option value = "stdio.php">StdOut, StdIn, & Return</option>
<option value = "sqlite.php">SQLite</option>
<option value = "sqlite-pdo.php">SQLite (PDO)</option>
<option value = "json.php">JSON</option>
<option value = "closures.php">Closures</option>
<option value = "files.php">Files</option>
<option value = "zend-benchmark.php">Zend Benchmark</option>
<option value = "drupal.php">Drupal 7</option>
</select>
<button data-load-demo>load</button>
</div>
</div>
<div class = "separator">
@@ -180,7 +198,7 @@ sso++++++///++//oyyyyhhhyyyyssoo+++syhhhdmNNNNmmmmmmmmdhhyhmNNNmddhhddmmmmmmmmNm
</div>
<div class = "stdout output liquid">
<div class = "column">
<iframe class = "scroller" srcdoc=""></iframe>
<iframe sandbox = "allow-same-origin allow-scripts allow-forms" class = "scroller" srcdoc=""></iframe>
<div class = "scroller"></div>
</div>
</div>
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
Binary file not shown.
+8 -8
View File
@@ -380651,14 +380651,14 @@ function drupal_environment_initialize() {
ini_set('magic_quotes_runtime', '0');
// Use session cookies, not transparent sessions that puts the session id in
// the query string.
ini_set('session.use_cookies', '1');
ini_set('session.use_only_cookies', '1');
ini_set('session.use_trans_sid', '0');
// Don't send HTTP headers using PHP's session handler.
// An empty string is used here to disable the cache limiter.
ini_set('session.cache_limiter', '');
// Use httponly session cookies.
ini_set('session.cookie_httponly', '1');
// ini_set('session.use_cookies', '1');
// ini_set('session.use_only_cookies', '1');
// ini_set('session.use_trans_sid', '0');
// // Don't send HTTP headers using PHP's session handler.
// // An empty string is used here to disable the cache limiter.
// ini_set('session.cache_limiter', '');
// // Use httponly session cookies.
// ini_set('session.cookie_httponly', '1');
// Set sane locale settings, to ensure consistent string, dates, times and
// numbers handling.
Binary file not shown.
@@ -0,0 +1,13 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
$x = 10;
function run(callable $f) {
$f();
}
run(function () use (&$x) {
$x = 9;
});
var_dump($x);
@@ -0,0 +1,20 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
$oldTitle = NULL;
$newTitle = 'Changed@' . date('h:i:s');
// Grab the current title
$oldTitle = vrzno_eval('document.title');
// Change the document title
$newTitle = vrzno_eval('document.title = "' . $newTitle . '"' );
printf(
'Title changed from "%s" to "%s".'
, $oldTitle
, $newTitle
);
// Show an alert
vrzno_run('alert', ['Hello, World!']);
+67
View File
@@ -0,0 +1,67 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "html"}
ini_set('session.save_path', '/home/web_user');
$stdErr = fopen('php://stderr', 'w');
$errors = [];
register_shutdown_function(function() use($stdErr, &$errors){
fwrite($stdErr, json_encode(['session_id' => session_id()]) . "\n");
fwrite($stdErr, json_encode(['headers'=>headers_list()]) . "\n");
fwrite($stdErr, json_encode(['errors' => error_get_last()]) . "\n");
});
set_error_handler(function(...$args) use($stdErr, &$errors){
fwrite($stdErr, print_r($args,1));
});
$docroot = '/preload/drupal-7.59';
$path = '/';
$script = 'index.php';
$_SERVER['REQUEST_URI'] = $docroot . $path;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_NAME'] = 'localhost';
$_SERVER['SERVER_PORT'] = 3333;
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SCRIPT_FILENAME'] = $docroot . '/' . $script;
$_SERVER['SCRIPT_NAME'] = $docroot . '/' . $script;
$_SERVER['PHP_SELF'] = $docroot . '/' . $script;
chdir($docroot);
ob_start();
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$uid = 1;
$user = user_load($uid);
$account = array('uid' => $user->uid);
user_login_submit(array(), $account);
$itemPath = $path;
$itemPath = preg_replace('/^\\/preload/', '', $itemPath);
$itemPath = preg_replace('/^\\/drupal-7.59/', '', $itemPath);
$itemPath = preg_replace('/^\//', '', $itemPath);
if($itemPath)
{
$router_item = menu_get_item($itemPath);
$router_item['access_callback'] = true;
$router_item['access'] = true;
if ($router_item['include_file']) {
require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
}
$page_callback_result = call_user_func_array($router_item['page_callback'], unserialize($router_item['page_arguments']));
drupal_deliver_page($page_callback_result);
}
else
{
menu_execute_active_handler();
}
+7
View File
@@ -0,0 +1,7 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "html"}
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("."));
foreach ($it as $name => $entry) {
echo $name . "<br/>";
}
+27
View File
@@ -0,0 +1,27 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
$x = false;
a:
if(!$x)
{
goto b;
}
echo 'Foo';
goto c;
b:
echo 'Bar';
if(!$x)
{
$x = true;
goto a;
}
c:
echo 'Bar';
@@ -0,0 +1,3 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
echo "Hello, World!";
+7
View File
@@ -0,0 +1,7 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
$x = [
"id" => 1
];
var_dump(json_decode(json_encode($x)));
@@ -0,0 +1,2 @@
<?php // {"autorun":true, "persist":true, "single-expression": true, "render-as": "text"}
$c++; // run this over and over again
@@ -0,0 +1,2 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "html"}
phpinfo();
@@ -0,0 +1,23 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
$db = new PDO('sqlite:people.db');
$db->query('CREATE TABLE IF NOT EXISTS people (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);');
for($i = 0; $i < 10; $i++) {
$insert = $db->prepare('INSERT INTO people (name) VALUES(:name)');
$insert->bindParam(':name', str_repeat(chr($i+64), 10), SQLITE3_TEXT);
$insert->execute();
}
$results = $db->query('SELECT * FROM people');
$rows = [];
while ($row = $results->fetchObject()) {
print_r($row);
}
+22
View File
@@ -0,0 +1,22 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
$db = new SQLite3('people.db');
$db->query('CREATE TABLE IF NOT EXISTS people (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);');
for($i = 0; $i < 100; $i++) {
$insert = $db->prepare('INSERT INTO people (name) VALUES(:name)');
$insert->bindValue(':name', str_repeat(chr($i+64), 10), SQLITE3_TEXT);
$insert->execute();
}
$results = $db->query('SELECT * FROM people');
$rows = [];
while ($row = $results->fetchArray()) {
var_dump($row);
}
+16
View File
@@ -0,0 +1,16 @@
<?php // {"autorun":true, "persist":false, "single-expression": true, "render-as": "text"}
// Only "single" expressions can return strings directly
// So wrap the commands in an IFFE.
(function() {
global $persist;
fwrite(fopen('php://stdout', 'w'), "output\n");
fwrite(fopen('php://stdout', 'w'), sprintf(
"Ran %d times!\n", $persist++
));
fwrite(fopen('php://stderr', 'w'), 'error');
return 'return value';
})();
@@ -0,0 +1,3 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
include("/preload/Zend/bench.php");
+39 -7
View File
@@ -1,15 +1,15 @@
<?php
ini_set('session.save_path', '/home/web_user');
session_id('fake-cookie');
session_start();
$stdErr = fopen('php://stderr', 'w');
$errors = [];
register_shutdown_function(function() use($stdErr, &$errors){
fwrite($stdErr, json_encode(headers_list()) . "\n");
fwrite($stdErr, json_encode(['session_id' => session_id()]) . "\n");
fwrite($stdErr, print_r($errors,1));
fwrite($stdErr, print_r(error_get_last(),1));
fwrite($stdErr, json_encode(['headers'=>headers_list()]) . "\n");
fwrite($stdErr, json_encode(['errors' => error_get_last()]) . "\n");
});
set_error_handler(function(...$args) use($stdErr, &$errors){
@@ -17,11 +17,11 @@ set_error_handler(function(...$args) use($stdErr, &$errors){
});
$origin = 'http://localhost:3333';
$docroot = '/php-wasm/preload/drupal-7.59';
$docroot = '/preload/drupal-7.59';
$path = '/';
$script = 'index.php';
$_SERVER['REQUEST_URI'] = $docroot . $path;
$_SERVER['REQUEST_URI'] = $docroot;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_NAME'] = $origin;
$_SERVER['SERVER_PORT'] = 3333;
@@ -32,4 +32,36 @@ $_SERVER['PHP_SELF'] = $docroot . '/' . $script;
chdir($docroot);
require $script;
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$uid = 1;
$user = user_load($uid);
$account = array('uid' => $user->uid);
user_login_submit(array(), $account);
$itemPath = $path;
$itemPath = preg_replace('/^\\/preload/', '', $itemPath);
$itemPath = preg_replace('/^\\/drupal-7.59/', '', $itemPath);
$itemPath = preg_replace('/^\\//', '', $itemPath);
if($itemPath && (substr($itemPath, 0, 4) !== 'node' || substr($itemPath, -4) === 'edit'))
{
$router_item = menu_get_item($itemPath);
$router_item['access_callback'] = true;
$router_item['access'] = true;
if ($router_item['include_file']) {
require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
}
$page_callback_result = call_user_func_array($router_item['page_callback'], unserialize($router_item['page_arguments']));
drupal_deliver_page($page_callback_result);
}
else
{
menu_execute_active_handler();
}
+47 -14
View File
@@ -1,22 +1,26 @@
<?php
ini_set('session.save_path', '/home/web_user');
session_id('fake-cookie');
session_start();
session_id('${session_id}');
$stdErr = fopen('php://stderr', 'w');
$errors = [];
register_shutdown_function(function() use($stdErr, &$errors){
fwrite($stdErr, json_encode(['session_id' => session_id()]) . "\n" );
fwrite($stdErr, var_export($errors,1) . "\n");
fwrite($stdErr, json_encode(['session' => $_SESSION]) . "\n");
register_shutdown_function(function() use($stdErr){
fwrite($stdErr, json_encode(['session_id' => session_id()]) . "\n");
fwrite($stdErr, json_encode(['headers'=>headers_list()]) . "\n");
fwrite($stdErr, json_encode(['errors' => error_get_last()]) . "\n");
fwrite($stdErr, json_encode(['session' => $_SESSION]) . "\n");
});
set_error_handler(function(...$args) use($stdErr, &$errors){
$errors[] = $args;
fwrite($stdErr, json_encode($args, JSON_PRETTY_PRINT) . "\n" );
});
$request = (object) json_decode(
'${JSON.stringify(event.data)}'
'${ JSON.stringify({path, method, _GET, _POST}) }'
, JSON_OBJECT_AS_ARRAY
);
@@ -28,23 +32,52 @@ $origin = 'http://localhost:3333';
$docroot = '/preload/drupal-7.59';
$script = 'index.php';
$path = $request->path;
$path = $request->path;
$path = preg_replace('/^\\/php-wasm/', '', $path);
$_SERVER['REQUEST_URI'] = $path;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_NAME'] = $origin;
$_SERVER['SERVER_PORT'] = 3333;
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_METHOD'] = $request->method;
$_SERVER['SCRIPT_FILENAME'] = $docroot . '/' . $script;
$_SERVER['SCRIPT_NAME'] = $docroot . '/' . $script;
$_SERVER['PHP_SELF'] = $docroot . '/' . $script;
$_SERVER['DOCUMENT_ROOT'] = '/';
$databases['default']['default'] = array(
'database' => '/drupal-7.db'
, 'driver' => 'sqlite'
);
$_SERVER['HTTPS'] = '';
chdir($docroot);
require $script;
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$uid = 1;
$user = user_load($uid);
$account = array('uid' => $user->uid);
user_login_submit(array(), $account);
$itemPath = $path;
$itemPath = preg_replace('/^\\/preload/', '', $itemPath);
$itemPath = preg_replace('/^\\/drupal-7.59/', '', $itemPath);
$itemPath = preg_replace('/^\\//', '', $itemPath);
if($itemPath && (substr($itemPath, 0, 4) !== 'node' || substr($itemPath, -4) === 'edit'))
{
$router_item = menu_get_item($itemPath);
$router_item['access_callback'] = true;
$router_item['access'] = true;
if ($router_item['include_file']) {
require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
}
$page_callback_result = call_user_func_array($router_item['page_callback'], unserialize($router_item['page_arguments']));
drupal_deliver_page($page_callback_result);
}
else
{
menu_execute_active_handler();
}
+171 -83
View File
@@ -1,6 +1,6 @@
"use strict";
import { PhpWeb as PHP } from 'php-wasm/PhpWeb';
import { PhpWebDrupal as PHP } from 'php-wasm/PhpWebDrupal';
window.PHP = PHP;
const php = new PHP;
@@ -11,9 +11,9 @@ const serviceWorker = navigator.serviceWorker;
if(serviceWorker)
{
serviceWorker.register(`${location.pathname}DrupalWorker.js`).catch(error => {
console.log('Error, ', error);
});
serviceWorker.register(`${location.pathname}DrupalWorker.js`);
// .then(result => console.log('Result, ', result))
// .catch(error => console.log('Error, ', error));
}
document.addEventListener('DOMContentLoaded', () => {
@@ -24,6 +24,8 @@ document.addEventListener('DOMContentLoaded', () => {
const run = document.querySelector('[data-run]');
const token = document.querySelector('[data-tokenize]');
const status = document.querySelector('[data-status]');
const load = document.querySelector('[data-load-demo]')
const demo = document.querySelector('[data-select-demo]')
const editor = ace.edit(input);
const ret = document.querySelector('#ret');
@@ -51,6 +53,134 @@ document.addEventListener('DOMContentLoaded', () => {
});
const runCode = () => {
exitLabel.innerText = '_';
status.innerText = 'Executing...';
stdoutFrame.srcdoc = ' ';
stderrFrame.srcdoc = ' ';
stdretFrame.srcdoc = ' ';
while(stdout.firstChild)
{
stdout.firstChild.remove();
}
while(stderr.firstChild)
{
stderr.firstChild.remove();
}
while(stdret.firstChild)
{
stdret.firstChild.remove();
}
let code = editor.session.getValue();
if(code.length < 1024 * 2)
{
query.set('autorun', autorun.checked ? 1 : 0);
query.set('persist', persistBox.checked ? 1 : 0);
query.set('single-expression', singleBox.checked ? 1 : 0);
query.set('code', encodeURIComponent(code));
history.replaceState({}, document.title, "?" + query.toString());
}
const func = singleBox.checked
? 'exec'
: 'run';
if(singleBox.checked)
{
code = code.replace(/^\s*<\?php/, '');
code = code.replace(/\?>\s*/, '');
}
php[func](code).then(ret=>{
status.innerText = 'php-wasm ready!';
const content = String(ret);
stdret.innerText = content;
stdretFrame.srcdoc = content;
exitLabel.innerText = '_';
if(!singleBox.checked)
{
setTimeout(() => exitLabel.innerText = ret, 100);
}
}).finally(() => {
if(!persistBox.checked)
{
php.refresh();
}
});
};
load.addEventListener('click', event => {
if(!demo.value)
{
return;
}
fetch(`/scripts/${demo.value}`)
.then(r => r.text())
.then(php => {
const firstLine = String(php.split(/\n/).shift());
const settings = JSON.parse(firstLine.split('//').pop());
if('autorun' in settings)
{
autorun.checked = !!settings.autorun;
}
if('single-expression' in settings)
{
singleBox.checked = !!settings['single-expression'];
}
if('persist' in settings)
{
persistBox.checked = !!settings.persist;
}
if('render-as' in settings)
{
if(settings['render-as'] === 'text')
{
renderAs[0].checked = true;
renderAs[0].dispatchEvent(new Event('change'));
query.set('render-as', 'text');
}
else if(settings['render-as'] === 'html')
{
renderAs[1].checked = true;
renderAs[1].dispatchEvent(new Event('change'));
query.set('render-as', 'html');
}
}
persistBox.dispatchEvent(new Event('change'));
singleBox.dispatchEvent(new Event('input'));
autorun.dispatchEvent(new Event('change'));
history.replaceState({}, document.title, "?" + query.toString());
editor.getSession().setValue(php);
setTimeout(() => runCode(), 100);
});
});
const query = new URLSearchParams(location.search);
editor.setTheme('ace/theme/monokai');
@@ -85,16 +215,13 @@ document.addEventListener('DOMContentLoaded', () => {
stdret.firstChild.remove();
}
const code = `
<?php
const code = `<?php
ini_set('session.save_path', '/home/web_user');
session_id('fake-cookie');
session_start();
$stdErr = fopen('php://stderr', 'w');
$errors = [];
fwrite($stdErr, json_encode(['session' => $_SESSION]) . "\n");
fwrite($stdErr, isset($_SESSION) && json_encode(['session' => $_SESSION]) . "\n");
register_shutdown_function(function() use($stdErr){
fwrite($stdErr, json_encode(['session_id' => session_id()]) . "\n");
@@ -123,6 +250,7 @@ $script = 'index.php';
$path = $request->path;
$path = preg_replace('/^\\/php-wasm/', '', $path);
$_SERVER['SERVER_SOFTWARE'] = ${JSON.stringify(navigator.userAgent)};
$_SERVER['REQUEST_URI'] = $path;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_NAME'] = $origin;
@@ -146,8 +274,34 @@ $user = user_load($uid);
$account = array('uid' => $user->uid);
user_login_submit(array(), $account);
menu_execute_active_handler();
`;
$itemPath = $path;
$itemPath = preg_replace('/^\\/preload/', '', $itemPath);
$itemPath = preg_replace('/^\\/drupal-7.59/', '', $itemPath);
$itemPath = preg_replace('/^\\//', '', $itemPath);
if($itemPath && (substr($itemPath, 0, 4) !== 'node' || substr($itemPath, -4) === 'edit'))
{
$router_item = menu_get_item($itemPath);
$router_item['access_callback'] = true;
$router_item['access'] = true;
if ($router_item['include_file']) {
require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
}
$page_callback_result = call_user_func_array(
$router_item['page_callback']
, is_string($router_item['page_arguments'])
? unserialize($router_item['page_arguments'])
: $router_item['page_arguments']
);
drupal_deliver_page($page_callback_result);
}
else
{
menu_execute_active_handler();
}`;
php.run(code).then(exitCode => {
exitLabel.innerText = exitCode;
@@ -184,75 +338,6 @@ menu_execute_active_handler();
});
const runCode = () => {
exitLabel.innerText = '_';
status.innerText = 'Executing...';
stdoutFrame.srcdoc = ' ';
stderrFrame.srcdoc = ' ';
stdretFrame.srcdoc = ' ';
while(stdout.firstChild)
{
stdout.firstChild.remove();
}
while(stderr.firstChild)
{
stderr.firstChild.remove();
}
while(stdret.firstChild)
{
stdret.firstChild.remove();
}
let code = editor.session.getValue();
if(code.length < 1024 * 2)
{
query.set('autorun', autorun.checked ? 1 : 0);
query.set('persist', persistBox.checked ? 1 : 0);
query.set('single-expression', singleBox.checked ? 1 : 0);
query.set('code', encodeURIComponent(code));
history.replaceState({}, document.title, "?" + query.toString());
}
const func = singleBox.checked
? 'exec'
: 'run';
if(singleBox.checked)
{
code = code.replace(/^\s*<\?php/, '');
code = code.replace(/\?>\s*/, '');
}
php[func](code).then(ret=>{
status.innerText = 'php-wasm ready!';
const content = String(ret);
stdret.innerText = content;
stdretFrame.srcdoc = content;
exitLabel.innerText = '_';
if(!singleBox.checked)
{
setTimeout(() => exitLabel.innerText = ret, 100);
}
}).finally(() => {
if(!persistBox.checked)
{
php.refresh();
}
});
};
run.addEventListener('click', runCode);
if(query.get('autorun'))
@@ -270,13 +355,18 @@ menu_execute_active_handler();
outputBuffer.push(content);
setTimeout(()=>{
const chunk = outputBuffer.join('');
let chunk = outputBuffer.join('');
if(!outputBuffer || !chunk)
{
return;
}
if(location.hostname.match(/github.io$/))
{
chunk = chunk.replace(/\/preload/g, '/php-wasm/preload');
}
const node = document.createTextNode(chunk);
stdout.append(node);
@@ -299,8 +389,6 @@ menu_execute_active_handler();
session_id = headers.session_id;
}
console.log(session_id);
if(headers.headers)
{
for(const header of headers.headers)
+2 -2
View File
@@ -55,7 +55,7 @@ body {
flex: 1;
}
.row.toolbar button {
.row.toolbar button[data-run] {
padding: 0.75em;
font-weight: bold;
border: 2px solid;
@@ -79,7 +79,7 @@ button[data-run]:not([disabled])::after {
opacity: 0.5;
}
.header button {
.header button[data-run] {
position: relative;
font-weight: bold;
font-size: 13pt;
+18677 -8752
View File
File diff suppressed because it is too large. Load diff
+4 -5
View File
@@ -6,10 +6,9 @@
"author": "Sean Morris",
"license": "Apache-2.0",
"scripts": {
"postinstall": "cp -rfv node_modules/php-wasm/php-web.* app/assets/"
},
"dependencies": {
"postinstall": "cp -rfv node_modules/php-wasm/php-web.* app/assets/; cp -rfv node_modules/php-wasm/php-web-drupal.* app/assets/"
},
"dependencies": {},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.7",
@@ -20,7 +19,7 @@
"babel-preset-es2015": "^6.24.1",
"brunch": "^3.0.0",
"clean-css-brunch": "^3.0.0",
"raw-brunch": "^1.0.2",
"php-wasm": "^0.0.3"
"php-wasm": "^0.0.4-a",
"raw-brunch": "^1.0.2"
}
}
+3
View File
@@ -359,9 +359,11 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
self.addEventListener('install', function (event) {
console.log('Install');
self.skipWaiting();
});
self.addEventListener('activate', function (event) {
console.log('Activate');
event.waitUntil(clients.claim());
});
self.addEventListener('fetch', function (event) {
@@ -369,6 +371,7 @@ self.addEventListener('fetch', function (event) {
var url = new URL(event.request.url);
var pathname = url.pathname.replace(/^\//, '');
var path = pathname.split('/');
console.log(path);
if (!path[path.length - 1].match(/\.\w+$/) && (path[1] === 'drupal-7.59' || path[2] === 'drupal-7.59')) {
var getClient = self.clients.matchAll({
+1 -1
View File
@@ -1 +1 @@
@font-face{src:url(fsex302-webfont.woff) format('woff');font-weight:400;font-style:normal;font-family:fixedsys}body{font-family:fixedsys;display:flex;flex-direction:column;align-items:stretch;height:100vh;padding:0;margin:0;background-color:#aaa}.output .scroller{background-color:#eee}.output div.scroller{white-space:pre}.output .row{background-color:#fff;padding:.5em .5em;border-bottom:1px #fff solid}.row.toolbar{margin:.5em;padding:.5em 0;border:2px solid;border-image:url(border-inset.png) 2 2 2 2;align-items:center}.row.toolbar>div{display:flex;justify-content:flex-end;padding:0 .5em;flex:1;flex-direction:row}.row.toolbar>div .start{align-items:center;flex:1}.row.toolbar button{padding:.75em;font-weight:700;border:2px solid;align-self:center;margin-right:.5em}button{border-image:url(border.png) 2 2 2 2}button[data-run]:not([disabled])::after{position:absolute;top:-2px;left:-2px;bottom:-2px;right:-2px;content:'';background-color:red!important;mix-blend-mode:darken;opacity:.5}.header button{position:relative;font-weight:700;font-size:13pt;box-sizing:border-box}:focus{outline-style:dotted;outline-color:#000}.row:focus{background-color:#000082;border-bottom:1px #000082 solid;color:#fff}.row.toolbar.header{background-color:#bbb}.row.toolbar.status{padding:0}.row.toolbar.status>div{padding:.25em}h1{margin:0;margin:.25em;white-space:nowrap}.row{display:flex;flex-direction:row}body>div{display:flex;flex-direction:row}.row.body{flex-grow:1}.collapse{flex-grow:0;flex-shrink:1}div.column{position:relative;flex:1}div.column .scroller{position:absolute;top:0;left:0;bottom:0;right:0;width:100%;height:100%;overflow-y:auto;overflow-x:auto}div.panel{font-family:fixedsys;display:flex;position:relative;background-color:#aaa;flex-direction:column;box-sizing:border-box;margin:.5em;flex:1;border-right:1px solid rgba(0,0,0,.5);border-bottom:1px solid rgba(0,0,0,.5)}div.panel div.input{background-color:#272822}div.panel>div{background-color:#fff;border:2px solid;border-image:url(border-inset.png) 2 2 2 2;flex-direction:column;display:flex;flex:1}.liquid{display:flex;flex-direction:column;flex:1}.panel label,button{user-select:none;border:2px solid;border-image:url(border.png) 2 2 2 2!important;background-color:#c3c3c3;padding:.25em}.input,.output .scroller,iframe{user-select:normal}.panel .cols{margin-top:-1px}.panel label[tabindex]:first-child{margin-left:-1px}.panel .cols>label[tabindex]:last-child{margin-right:-3px}.ace_editor{margin-right:-2px}button:active,label[tabindex]:active{border:2px solid;border-image:url(border-inset.png) 2 2 2 2!important;position:relative;z-index:100}.header label{display:flex;align-items:center;justify-content:flex-end}.header label p{text-align:right}pre{flex:1;margin-top:0;margin-bottom:0}.round{border-radius:50%;height:49px;margin-right:5px}.credit{padding-right:.5em;padding-left:.5em}.column .row{white-space:pre}.cols{display:flex;flex-direction:row!important}.rows{display:flex;flex-direction:column!important}.cols label{flex:1}label{user-select:none}.collapse{flex:0!important;white-space:nowrap}.header.row{align-items:flex-start}iframe{border:none}input[type=file]{display:none}
@font-face{src:url(fsex302-webfont.woff) format('woff');font-weight:400;font-style:normal;font-family:fixedsys}body{font-family:fixedsys;display:flex;flex-direction:column;align-items:stretch;height:100vh;padding:0;margin:0;background-color:#aaa}.output .scroller{background-color:#eee}.output div.scroller{white-space:pre}.output .row{background-color:#fff;padding:.5em .5em;border-bottom:1px #fff solid}.row.toolbar{margin:.5em;padding:.5em 0;border:2px solid;border-image:url(border-inset.png) 2 2 2 2;align-items:center}.row.toolbar>div{display:flex;justify-content:flex-end;padding:0 .5em;flex:1;flex-direction:row}.row.toolbar>div .start{align-items:center;flex:1}.row.toolbar button[data-run]{padding:.75em;font-weight:700;border:2px solid;align-self:center;margin-right:.5em}button{border-image:url(border.png) 2 2 2 2}button[data-run]:not([disabled])::after{position:absolute;top:-2px;left:-2px;bottom:-2px;right:-2px;content:'';background-color:red!important;mix-blend-mode:darken;opacity:.5}.header button[data-run]{position:relative;font-weight:700;font-size:13pt;box-sizing:border-box}:focus{outline-style:dotted;outline-color:#000}.row:focus{background-color:#000082;border-bottom:1px #000082 solid;color:#fff}.row.toolbar.header{background-color:#bbb}.row.toolbar.status{padding:0}.row.toolbar.status>div{padding:.25em}h1{margin:0;margin:.25em;white-space:nowrap}.row{display:flex;flex-direction:row}body>div{display:flex;flex-direction:row}.row.body{flex-grow:1}.collapse{flex-grow:0;flex-shrink:1}div.column{position:relative;flex:1}div.column .scroller{position:absolute;top:0;left:0;bottom:0;right:0;width:100%;height:100%;overflow-y:auto;overflow-x:auto}div.panel{font-family:fixedsys;display:flex;position:relative;background-color:#aaa;flex-direction:column;box-sizing:border-box;margin:.5em;flex:1;border-right:1px solid rgba(0,0,0,.5);border-bottom:1px solid rgba(0,0,0,.5)}div.panel div.input{background-color:#272822}div.panel>div{background-color:#fff;border:2px solid;border-image:url(border-inset.png) 2 2 2 2;flex-direction:column;display:flex;flex:1}.liquid{display:flex;flex-direction:column;flex:1}.panel label,button{user-select:none;border:2px solid;border-image:url(border.png) 2 2 2 2!important;background-color:#c3c3c3;padding:.25em}.input,.output .scroller,iframe{user-select:normal}.panel .cols{margin-top:-1px}.panel label[tabindex]:first-child{margin-left:-1px}.panel .cols>label[tabindex]:last-child{margin-right:-3px}.ace_editor{margin-right:-2px}button:active,label[tabindex]:active{border:2px solid;border-image:url(border-inset.png) 2 2 2 2!important;position:relative;z-index:100}.header label{display:flex;align-items:center;justify-content:flex-end}.header label p{text-align:right}pre{flex:1;margin-top:0;margin-bottom:0}.round{border-radius:50%;height:49px;margin-right:5px}.credit{padding-right:.5em;padding-left:.5em}.column .row{white-space:pre}.cols{display:flex;flex-direction:row!important}.rows{display:flex;flex-direction:column!important}.cols label{flex:1}label{user-select:none}.collapse{flex:0!important;white-space:nowrap}.header.row{align-items:flex-start}iframe{border:none}input[type=file]{display:none}
+127 -9729
View File
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -150,11 +150,11 @@ var __makeRelativeRequire = function(require, mappings, pref) {
}
};
require.register("drupal-init.php", function(exports, require, module) {
module.exports = "<?php\n\nini_set('session.save_path', '/home/web_user');\n\n$stdErr = fopen('php://stderr', 'w');\n$errors = [];\n\nregister_shutdown_function(function() use($stdErr, &$errors){\n\tfwrite($stdErr, json_encode(headers_list()) . \"\\n\");\n fwrite($stdErr, json_encode(['session_id' => session_id()]) . \"\\n\");\n fwrite($stdErr, print_r($errors,1));\n fwrite($stdErr, print_r(error_get_last(),1));\n});\n\nset_error_handler(function(...$args) use($stdErr, &$errors){\n\tfwrite($stdErr, print_r($args,1));\n});\n\n$origin = 'http://localhost:3333';\n$docroot = '/php-wasm/preload/drupal-7.59';\n$path = '/';\n$script = 'index.php';\n\n$_SERVER['REQUEST_URI'] = $docroot . $path;\n$_SERVER['REMOTE_ADDR'] = '127.0.0.1';\n$_SERVER['SERVER_NAME'] = $origin;\n$_SERVER['SERVER_PORT'] = 3333;\n$_SERVER['REQUEST_METHOD'] = 'GET';\n$_SERVER['SCRIPT_FILENAME'] = $docroot . '/' . $script;\n$_SERVER['SCRIPT_NAME'] = $docroot . '/' . $script;\n$_SERVER['PHP_SELF'] = $docroot . '/' . $script;\n\nchdir($docroot);\n\nrequire $script;\n"
module.exports = "<?php\nini_set('session.save_path', '/home/web_user');\nsession_id('fake-cookie');\nsession_start();\n\n$stdErr = fopen('php://stderr', 'w');\n$errors = [];\n\nregister_shutdown_function(function() use($stdErr, &$errors){\n fwrite($stdErr, json_encode(['session_id' => session_id()]) . \"\\n\");\n fwrite($stdErr, json_encode(['headers'=>headers_list()]) . \"\\n\");\n fwrite($stdErr, json_encode(['errors' => error_get_last()]) . \"\\n\");\n});\n\nset_error_handler(function(...$args) use($stdErr, &$errors){\n\tfwrite($stdErr, print_r($args,1));\n});\n\n$origin = 'http://localhost:3333';\n$docroot = '/preload/drupal-7.59';\n$path = '/';\n$script = 'index.php';\n\n$_SERVER['REQUEST_URI'] = $docroot;\n$_SERVER['REMOTE_ADDR'] = '127.0.0.1';\n$_SERVER['SERVER_NAME'] = $origin;\n$_SERVER['SERVER_PORT'] = 3333;\n$_SERVER['REQUEST_METHOD'] = 'GET';\n$_SERVER['SCRIPT_FILENAME'] = $docroot . '/' . $script;\n$_SERVER['SCRIPT_NAME'] = $docroot . '/' . $script;\n$_SERVER['PHP_SELF'] = $docroot . '/' . $script;\n\nchdir($docroot);\n\ndefine('DRUPAL_ROOT', getcwd());\n\nrequire_once DRUPAL_ROOT . '/includes/bootstrap.inc';\ndrupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);\n\n$uid = 1;\n$user = user_load($uid);\n$account = array('uid' => $user->uid);\nuser_login_submit(array(), $account);\n\n$itemPath = $path;\n$itemPath = preg_replace('/^\\\\/preload/', '', $itemPath);\n$itemPath = preg_replace('/^\\\\/drupal-7.59/', '', $itemPath);\n$itemPath = preg_replace('/^\\\\//', '', $itemPath);\n\nif($itemPath && (substr($itemPath, 0, 4) !== 'node' || substr($itemPath, -4) === 'edit'))\n{\n $router_item = menu_get_item($itemPath);\n $router_item['access_callback'] = true;\n $router_item['access'] = true;\n\n if ($router_item['include_file']) {\n require_once DRUPAL_ROOT . '/' . $router_item['include_file'];\n }\n\n $page_callback_result = call_user_func_array($router_item['page_callback'], unserialize($router_item['page_arguments']));\n\n drupal_deliver_page($page_callback_result);\n}\nelse\n{\n menu_execute_active_handler();\n}\n"
});
;require.register("drupal-request.php", function(exports, require, module) {
module.exports = "<?php\nini_set('session.save_path', '/home/web_user');\nsession_start();\nsession_id('${session_id}');\n\n$stdErr = fopen('php://stderr', 'w');\n$errors = [];\n\nregister_shutdown_function(function() use($stdErr, &$errors){\n fwrite($stdErr, json_encode(['session_id' => session_id()]) . \"\\n\" );\n fwrite($stdErr, var_export($errors,1) . \"\\n\");\n});\n\nset_error_handler(function(...$args) use($stdErr, &$errors){\n\t$errors[] = $args;\n});\n\n$request = (object) json_decode(\n\t'${JSON.stringify(event.data)}'\n\t, JSON_OBJECT_AS_ARRAY\n);\n\nparse_str(substr($request->_GET, 1), $_GET);\n\n$_POST = $request->_POST;\n\n$origin = 'http://localhost:3333';\n$docroot = '/preload/drupal-7.59';\n$script = 'index.php';\n\n$path = $request->path;\n\n$_SERVER['REQUEST_URI'] = $path;\n$_SERVER['REMOTE_ADDR'] = '127.0.0.1';\n$_SERVER['SERVER_NAME'] = $origin;\n$_SERVER['SERVER_PORT'] = 3333;\n$_SERVER['REQUEST_METHOD'] = 'GET';\n$_SERVER['SCRIPT_FILENAME'] = $docroot . '/' . $script;\n$_SERVER['SCRIPT_NAME'] = $docroot . '/' . $script;\n$_SERVER['PHP_SELF'] = $docroot . '/' . $script;\n$_SERVER['DOCUMENT_ROOT'] = '/';\n\n$databases['default']['default'] = array(\n\t'database' => '/drupal-7.db'\n\t, 'driver' => 'sqlite'\n);\n\nchdir($docroot);\n\nrequire $script;\n"
module.exports = "<?php\nini_set('session.save_path', '/home/web_user');\nsession_id('fake-cookie');\nsession_start();\n\n$stdErr = fopen('php://stderr', 'w');\n$errors = [];\n\nfwrite($stdErr, json_encode(['session' => $_SESSION]) . \"\\n\");\n\nregister_shutdown_function(function() use($stdErr){\n\tfwrite($stdErr, json_encode(['session_id' => session_id()]) . \"\\n\");\n\tfwrite($stdErr, json_encode(['headers'=>headers_list()]) . \"\\n\");\n\tfwrite($stdErr, json_encode(['errors' => error_get_last()]) . \"\\n\");\n\tfwrite($stdErr, json_encode(['session' => $_SESSION]) . \"\\n\");\n});\n\nset_error_handler(function(...$args) use($stdErr, &$errors){\n\tfwrite($stdErr, json_encode($args, JSON_PRETTY_PRINT) . \"\\n\" );\n});\n\n$request = (object) json_decode(\n\t'${ JSON.stringify({path, method, _GET, _POST}) }'\n\t, JSON_OBJECT_AS_ARRAY\n);\n\nparse_str(substr($request->_GET, 1), $_GET);\n\n$_POST = $request->_POST;\n\n$origin = 'http://localhost:3333';\n$docroot = '/preload/drupal-7.59';\n$script = 'index.php';\n\n$path = $request->path;\n$path = preg_replace('/^\\\\/php-wasm/', '', $path);\n\n$_SERVER['REQUEST_URI'] = $path;\n$_SERVER['REMOTE_ADDR'] = '127.0.0.1';\n$_SERVER['SERVER_NAME'] = $origin;\n$_SERVER['SERVER_PORT'] = 3333;\n$_SERVER['REQUEST_METHOD'] = $request->method;\n$_SERVER['SCRIPT_FILENAME'] = $docroot . '/' . $script;\n$_SERVER['SCRIPT_NAME'] = $docroot . '/' . $script;\n$_SERVER['PHP_SELF'] = $docroot . '/' . $script;\n$_SERVER['DOCUMENT_ROOT'] = '/';\n$_SERVER['HTTPS'] = '';\n\nchdir($docroot);\n\ndefine('DRUPAL_ROOT', getcwd());\n\nrequire_once DRUPAL_ROOT . '/includes/bootstrap.inc';\ndrupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);\n\n$uid = 1;\n$user = user_load($uid);\n$account = array('uid' => $user->uid);\nuser_login_submit(array(), $account);\n\n$itemPath = $path;\n$itemPath = preg_replace('/^\\\\/preload/', '', $itemPath);\n$itemPath = preg_replace('/^\\\\/drupal-7.59/', '', $itemPath);\n$itemPath = preg_replace('/^\\\\//', '', $itemPath);\n\nif($itemPath && (substr($itemPath, 0, 4) !== 'node' || substr($itemPath, -4) === 'edit'))\n{\n $router_item = menu_get_item($itemPath);\n $router_item['access_callback'] = true;\n $router_item['access'] = true;\n\n if ($router_item['include_file']) {\n require_once DRUPAL_ROOT . '/' . $router_item['include_file'];\n }\n\n $page_callback_result = call_user_func_array($router_item['page_callback'], unserialize($router_item['page_arguments']));\n\n drupal_deliver_page($page_callback_result);\n}\nelse\n{\n menu_execute_active_handler();\n}\n"
});
;require.alias("process/browser.js", "process");process = require('process');require.register("___globals___", function(exports, require, module) {
+19 -1
View File
@@ -113,6 +113,24 @@ sso++++++///++//oyyyyhhhyyyyssoo+++syhhhdmNNNNmmmmmmmmdhhyhmNNNmddhhddmmmmmmmmNm
<img src = "sean-icon.png" />
</a>
<h1>php-wasm</h1>
<hr />
<select data-select-demo>
<option value>Select a Demo</option>
<option value = "hello-world.php">Hello, World!</option>
<option value = "phpinfo.php">phpinfo();</option>
<option value = "persistent-memory.php">Persistent Memory</option>
<option value = "dom-access.php">DOM Access</option>
<option value = "goto.php">GoTo</option>
<option value = "stdio.php">StdOut, StdIn, & Return</option>
<option value = "sqlite.php">SQLite</option>
<option value = "sqlite-pdo.php">SQLite (PDO)</option>
<option value = "json.php">JSON</option>
<option value = "closures.php">Closures</option>
<option value = "files.php">Files</option>
<option value = "zend-benchmark.php">Zend Benchmark</option>
<option value = "drupal.php">Drupal 7</option>
</select>
<button data-load-demo>load</button>
</div>
</div>
<div class = "separator">
@@ -180,7 +198,7 @@ sso++++++///++//oyyyyhhhyyyyssoo+++syhhhdmNNNNmmmmmmmmdhhyhmNNNmddhhddmmmmmmmmNm
</div>
<div class = "stdout output liquid">
<div class = "column">
<iframe class = "scroller" srcdoc=""></iframe>
<iframe sandbox = "allow-same-origin allow-scripts allow-forms" class = "scroller" srcdoc=""></iframe>
<div class = "scroller"></div>
</div>
</div>
File diff suppressed because it is too large. Load diff
+22
View File
@@ -0,0 +1,22 @@
var PHP = (function() {
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
return (
function(PHP) {
PHP = PHP || {};
var Module=typeof PHP!=="undefined"?PHP:{};var readyPromiseResolve,readyPromiseReject;Module["ready"]=new Promise(function(resolve,reject){readyPromiseResolve=resolve;readyPromiseReject=reject});if(!Module.expectedDataFileDownloads){Module.expectedDataFileDownloads=0}Module.expectedDataFileDownloads++;(function(){var loadPackage=function(metadata){var PACKAGE_PATH;if(typeof window==="object"){PACKAGE_PATH=window["encodeURIComponent"](window.location.pathname.toString().substring(0,window.location.pathname.toString().lastIndexOf("/"))+"/")}else if(typeof location!=="undefined"){PACKAGE_PATH=encodeURIComponent(location.pathname.toString().substring(0,location.pathname.toString().lastIndexOf("/"))+"/")}else{throw"using preloaded data can only be done on a web page or in a web worker"}var PACKAGE_NAME="../../build/php-web-drupal.data";var REMOTE_PACKAGE_BASE="php-web-drupal.data";if(typeof Module["locateFilePackage"]==="function"&&!Module["locateFile"]){Module["locateFile"]=Module["locateFilePackage"];err("warning: you defined Module.locateFilePackage, that has been renamed to Module.locateFile (using your locateFilePackage for now)")}var REMOTE_PACKAGE_NAME=Module["locateFile"]?Module["locateFile"](REMOTE_PACKAGE_BASE,""):REMOTE_PACKAGE_BASE;var REMOTE_PACKAGE_SIZE=metadata["remote_package_size"];var PACKAGE_UUID=metadata["package_uuid"];function fetchRemotePackage(packageName,packageSize,callback,errback){var xhr=new XMLHttpRequest;xhr.open("GET",packageName,true);xhr.responseType="arraybuffer";xhr.onprogress=function(event){var url=packageName;var size=packageSize;if(event.total)size=event.total;if(event.loaded){if(!xhr.addedTotal){xhr.addedTotal=true;if(!Module.dataFileDownloads)Module.dataFileDownloads={};Module.dataFileDownloads[url]={loaded:event.loaded,total:size}}else{Module.dataFileDownloads[url].loaded=event.loaded}var total=0;var loaded=0;var num=0;for(var download in Module.dataFileDownloads){var data=Module.dataFileDownloads[download];total+=data.total;loaded+=data.loaded;num++}total=Math.ceil(total*Module.expectedDataFileDownloads/num);if(Module["setStatus"])Module["setStatus"]("Downloading data... ("+loaded+"/"+total+")")}else if(!Module.dataFileDownloads){if(Module["setStatus"])Module["setStatus"]("Downloading data...")}};xhr.onerror=function(event){throw new Error("NetworkError for: "+packageName)};xhr.onload=function(event){if(xhr.status==200||xhr.status==304||xhr.status==206||xhr.status==0&&xhr.response){var packageData=xhr.response;callback(packageData)}else{throw new Error(xhr.statusText+" : "+xhr.responseURL)}};xhr.send(null)}function handleError(error){console.error("package error:",error)}var fetchedCallback=null;var fetched=Module["getPreloadedPackage"]?Module["getPreloadedPackage"](REMOTE_PACKAGE_NAME,REMOTE_PACKAGE_SIZE):null;if(!fetched)fetchRemotePackage(REMOTE_PACKAGE_NAME,REMOTE_PACKAGE_SIZE,function(data){if(fetchedCallback){fetchedCallback(data);fetchedCallback=null}else{fetched=data}},handleError);function runWithFS(){function assert(check,msg){if(!check)throw msg+(new Error).stack}Module["FS_createPath"]("/","preload",true,true);Module["FS_createPath"]("/preload","drupal-7.59",true,true);Module["FS_createPath"]("/preload/drupal-7.59","includes",true,true);Module["FS_createPath"]("/preload/drupal-7.59/includes","filetransfer",true,true);Module["FS_createPath"]("/preload/drupal-7.59/includes","database",true,true);Module["FS_createPath"]("/preload/drupal-7.59/includes/database","sqlite",true,true);Module["FS_createPath"]("/preload/drupal-7.59/includes/database","mysql",true,true);Module["FS_createPath"]("/preload/drupal-7.59/includes/database","pgsql",true,true);Module["FS_createPath"]("/preload/drupal-7.59","themes",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes","stark",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes","garland",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes/garland","images",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes/garland","color",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes","engines",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes/engines","phptemplate",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes","seven",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes/seven","images",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes","bartik",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes/bartik","images",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes/bartik","color",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes/bartik","css",true,true);Module["FS_createPath"]("/preload/drupal-7.59/themes/bartik","templates",true,true);Module["FS_createPath"]("/preload/drupal-7.59","scripts",true,true);Module["FS_createPath"]("/preload/drupal-7.59","modules",true,true);Module["FS_createPath"]("/preload/drupal-7.59/modules","simpletest",true,true);Module["FS_createPath"]("/preload/dLine truncated
return PHP.ready
}
);
})();
if (typeof exports === 'object' && typeof module === 'object')
module.exports = PHP;
else if (typeof define === 'function' && define['amd'])
define([], function() { return PHP; });
else if (typeof exports === 'object')
exports["PHP"] = PHP;
Binary file not shown.
+35 -330625
View File
File diff suppressed because it is too large. Load diff
+1 -9461
View File
File diff suppressed because it is too large. Load diff
BIN
View File
Binary file not shown.
+8 -8
View File
@@ -380651,14 +380651,14 @@ function drupal_environment_initialize() {
ini_set('magic_quotes_runtime', '0');
// Use session cookies, not transparent sessions that puts the session id in
// the query string.
ini_set('session.use_cookies', '1');
ini_set('session.use_only_cookies', '1');
ini_set('session.use_trans_sid', '0');
// Don't send HTTP headers using PHP's session handler.
// An empty string is used here to disable the cache limiter.
ini_set('session.cache_limiter', '');
// Use httponly session cookies.
ini_set('session.cookie_httponly', '1');
// ini_set('session.use_cookies', '1');
// ini_set('session.use_only_cookies', '1');
// ini_set('session.use_trans_sid', '0');
// // Don't send HTTP headers using PHP's session handler.
// // An empty string is used here to disable the cache limiter.
// ini_set('session.cache_limiter', '');
// // Use httponly session cookies.
// ini_set('session.cookie_httponly', '1');
// Set sane locale settings, to ensure consistent string, dates, times and
// numbers handling.
+1 -9461
View File
File diff suppressed because it is too large. Load diff
Binary file not shown.
+13
View File
@@ -0,0 +1,13 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
$x = 10;
function run(callable $f) {
$f();
}
run(function () use (&$x) {
$x = 9;
});
var_dump($x);
+20
View File
@@ -0,0 +1,20 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
$oldTitle = NULL;
$newTitle = 'Changed@' . date('h:i:s');
// Grab the current title
$oldTitle = vrzno_eval('document.title');
// Change the document title
$newTitle = vrzno_eval('document.title = "' . $newTitle . '"' );
printf(
'Title changed from "%s" to "%s".'
, $oldTitle
, $newTitle
);
// Show an alert
vrzno_run('alert', ['Hello, World!']);
+67
View File
@@ -0,0 +1,67 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "html"}
ini_set('session.save_path', '/home/web_user');
$stdErr = fopen('php://stderr', 'w');
$errors = [];
register_shutdown_function(function() use($stdErr, &$errors){
fwrite($stdErr, json_encode(['session_id' => session_id()]) . "\n");
fwrite($stdErr, json_encode(['headers'=>headers_list()]) . "\n");
fwrite($stdErr, json_encode(['errors' => error_get_last()]) . "\n");
});
set_error_handler(function(...$args) use($stdErr, &$errors){
fwrite($stdErr, print_r($args,1));
});
$docroot = '/preload/drupal-7.59';
$path = '/';
$script = 'index.php';
$_SERVER['REQUEST_URI'] = $docroot . $path;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_NAME'] = 'localhost';
$_SERVER['SERVER_PORT'] = 3333;
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SCRIPT_FILENAME'] = $docroot . '/' . $script;
$_SERVER['SCRIPT_NAME'] = $docroot . '/' . $script;
$_SERVER['PHP_SELF'] = $docroot . '/' . $script;
chdir($docroot);
ob_start();
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$uid = 1;
$user = user_load($uid);
$account = array('uid' => $user->uid);
user_login_submit(array(), $account);
$itemPath = $path;
$itemPath = preg_replace('/^\\/preload/', '', $itemPath);
$itemPath = preg_replace('/^\\/drupal-7.59/', '', $itemPath);
$itemPath = preg_replace('/^\//', '', $itemPath);
if($itemPath)
{
$router_item = menu_get_item($itemPath);
$router_item['access_callback'] = true;
$router_item['access'] = true;
if ($router_item['include_file']) {
require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
}
$page_callback_result = call_user_func_array($router_item['page_callback'], unserialize($router_item['page_arguments']));
drupal_deliver_page($page_callback_result);
}
else
{
menu_execute_active_handler();
}
+7
View File
@@ -0,0 +1,7 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "html"}
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("."));
foreach ($it as $name => $entry) {
echo $name . "<br/>";
}
+27
View File
@@ -0,0 +1,27 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
$x = false;
a:
if(!$x)
{
goto b;
}
echo 'Foo';
goto c;
b:
echo 'Bar';
if(!$x)
{
$x = true;
goto a;
}
c:
echo 'Bar';
+3
View File
@@ -0,0 +1,3 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
echo "Hello, World!";
+7
View File
@@ -0,0 +1,7 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
$x = [
"id" => 1
];
var_dump(json_decode(json_encode($x)));
+2
View File
@@ -0,0 +1,2 @@
<?php // {"autorun":true, "persist":true, "single-expression": true, "render-as": "text"}
$c++; // run this over and over again
+2
View File
@@ -0,0 +1,2 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "html"}
phpinfo();
+23
View File
@@ -0,0 +1,23 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
$db = new PDO('sqlite:people.db');
$db->query('CREATE TABLE IF NOT EXISTS people (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);');
for($i = 0; $i < 10; $i++) {
$insert = $db->prepare('INSERT INTO people (name) VALUES(:name)');
$insert->bindParam(':name', str_repeat(chr($i+64), 10), SQLITE3_TEXT);
$insert->execute();
}
$results = $db->query('SELECT * FROM people');
$rows = [];
while ($row = $results->fetchObject()) {
print_r($row);
}
+22
View File
@@ -0,0 +1,22 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
$db = new SQLite3('people.db');
$db->query('CREATE TABLE IF NOT EXISTS people (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);');
for($i = 0; $i < 100; $i++) {
$insert = $db->prepare('INSERT INTO people (name) VALUES(:name)');
$insert->bindValue(':name', str_repeat(chr($i+64), 10), SQLITE3_TEXT);
$insert->execute();
}
$results = $db->query('SELECT * FROM people');
$rows = [];
while ($row = $results->fetchArray()) {
var_dump($row);
}
+16
View File
@@ -0,0 +1,16 @@
<?php // {"autorun":true, "persist":false, "single-expression": true, "render-as": "text"}
// Only "single" expressions can return strings directly
// So wrap the commands in an IFFE.
(function() {
global $persist;
fwrite(fopen('php://stdout', 'w'), "output\n");
fwrite(fopen('php://stdout', 'w'), sprintf(
"Ran %d times!\n", $persist++
));
fwrite(fopen('php://stderr', 'w'), 'error');
return 'return value';
})();
+3
View File
@@ -0,0 +1,3 @@
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "text"}
include("/preload/Zend/bench.php");
+1
View File
@@ -11,6 +11,7 @@ RUN set -euxo pipefail;\
apt-get --no-install-recommends -y install \
build-essential \
automake-1.15 \
libxml2-dev \
autoconf \
libtool \
pkgconf \
Whitespace-only changes.
View File
Whitespace-only changes.
+4 -4
View File
@@ -327,8 +327,8 @@ $base_url = '/preload/drupal-7.59'; // NO trailing slash!
* PHP's garbage collection for clearing sessions, ensure that garbage
* collection occurs by using the most common settings.
*/
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 100);
// ini_set('session.gc_probability', 1);
// ini_set('session.gc_divisor', 100);
/**
* Set session lifetime (in seconds), i.e. the time from the user's last visit
@@ -336,14 +336,14 @@ ini_set('session.gc_divisor', 100);
* a session is deleted, authenticated users are logged out, and the contents
* of the user's $_SESSION variable is discarded.
*/
ini_set('session.gc_maxlifetime', 200000);
// ini_set('session.gc_maxlifetime', 200000);
/**
* Set session cookie lifetime (in seconds), i.e. the time from the session is
* created to the cookie expires, i.e. when the browser is expected to discard
* the cookie. The value 0 means "until the browser is closed".
*/
ini_set('session.cookie_lifetime', 2000000);
// ini_set('session.cookie_lifetime', 2000000);
/**
* If you encounter a situation where users post a large amount of text, and
+2 -2
View File
@@ -1,11 +1,11 @@
{
"name": "php-wasm",
"version": "0.0.4",
"version": "0.0.4-b",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "0.0.4",
"version": "0.0.4-b",
"license": "Apache-2.0",
"devDependencies": {
"@babel/cli": "^7.8.4",
+1 -1
View File
@@ -3,7 +3,7 @@
"description": "Run PHP right in the browser.",
"repository": "https://github.com/seanmorris/pib",
"author": "Oraoto <oraoto@outlook.com>",
"version": "0.0.4a",
"version": "0.0.4-b",
"license": "Apache-2.0",
"devDependencies": {
"@babel/cli": "^7.8.4",
+154
View File
@@ -0,0 +1,154 @@
diff --git a/third_party/drupal-7.59/includes/bootstrap.inc b/third_party/drupal-7.59/includes/bootstrap.inc
index a91c398..dc4b14d 100644
--- a/third_party/drupal-7.59/includes/bootstrap.inc
+++ b/third_party/drupal-7.59/includes/bootstrap.inc
@@ -692,14 +692,14 @@ function drupal_environment_initialize() {
ini_set('magic_quotes_runtime', '0');
// Use session cookies, not transparent sessions that puts the session id in
// the query string.
- ini_set('session.use_cookies', '1');
- ini_set('session.use_only_cookies', '1');
- ini_set('session.use_trans_sid', '0');
+ // ini_set('session.use_cookies', '1');
+ // ini_set('session.use_only_cookies', '1');
+ // ini_set('session.use_trans_sid', '0');
// Don't send HTTP headers using PHP's session handler.
// An empty string is used here to disable the cache limiter.
- ini_set('session.cache_limiter', '');
- // Use httponly session cookies.
- ini_set('session.cookie_httponly', '1');
+ // ini_set('session.cache_limiter', '');
+ // // Use httponly session cookies.
+ // ini_set('session.cookie_httponly', '1');
// Set sane locale settings, to ensure consistent string, dates, times and
// numbers handling.
@@ -784,26 +784,26 @@ function drupal_settings_initialize() {
$session_name = $cookie_domain;
}
else {
- // Otherwise use $base_url as session name, without the protocol
- // to use the same session identifiers across HTTP and HTTPS.
- list( , $session_name) = explode('://', $base_url, 2);
- // HTTP_HOST can be modified by a visitor, but we already sanitized it
- // in drupal_settings_initialize().
- if (!empty($_SERVER['HTTP_HOST'])) {
- $cookie_domain = $_SERVER['HTTP_HOST'];
- // Strip leading periods, www., and port numbers from cookie domain.
- $cookie_domain = ltrim($cookie_domain, '.');
- if (strpos($cookie_domain, 'www.') === 0) {
- $cookie_domain = substr($cookie_domain, 4);
- }
- $cookie_domain = explode(':', $cookie_domain);
- $cookie_domain = '.' . $cookie_domain[0];
- }
+ // // Otherwise use $base_url as session name, without the protocol
+ // // to use the same session identifiers across HTTP and HTTPS.
+ // list( , $session_name) = explode('://', $base_url, 2);
+ // // HTTP_HOST can be modified by a visitor, but we already sanitized it
+ // // in drupal_settings_initialize().
+ // if (!empty($_SERVER['HTTP_HOST'])) {
+ // $cookie_domain = $_SERVER['HTTP_HOST'];
+ // // Strip leading periods, www., and port numbers from cookie domain.
+ // $cookie_domain = ltrim($cookie_domain, '.');
+ // if (strpos($cookie_domain, 'www.') === 0) {
+ // $cookie_domain = substr($cookie_domain, 4);
+ // }
+ // $cookie_domain = explode(':', $cookie_domain);
+ // $cookie_domain = '.' . $cookie_domain[0];
+ // }
}
// Per RFC 2109, cookie domains must contain at least one dot other than the
// first. For hosts such as 'localhost' or IP Addresses we don't set a cookie domain.
if (count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) {
- ini_set('session.cookie_domain', $cookie_domain);
+ // ini_set('session.cookie_domain', $cookie_domain);
}
// To prevent session cookies from being hijacked, a user can configure the
// SSL version of their website to only transfer session cookies via SSL by
@@ -812,10 +812,10 @@ function drupal_settings_initialize() {
// must use different session identifiers for HTTPS and HTTP to prevent a
// cookie collision.
if ($is_https) {
- ini_set('session.cookie_secure', TRUE);
+ // ini_set('session.cookie_secure', TRUE);
}
- $prefix = ini_get('session.cookie_secure') ? 'SSESS' : 'SESS';
- session_name($prefix . substr(hash('sha256', $session_name), 0, 32));
+ // $prefix = ini_get('session.cookie_secure') ? 'SSESS' : 'SESS';
+ // session_name($prefix . substr(hash('sha256', $session_name), 0, 32));
}
/**
diff --git a/third_party/drupal-7.59/includes/common.inc b/third_party/drupal-7.59/includes/common.inc
index f61d1eb..bdbd4ac 100644
--- a/third_party/drupal-7.59/includes/common.inc
+++ b/third_party/drupal-7.59/includes/common.inc
@@ -391,7 +391,7 @@ function drupal_add_feed($url = NULL, $title = '') {
*/
function drupal_get_feeds($delimiter = "\n") {
$feeds = drupal_add_feed();
- return implode($feeds, $delimiter);
+ return implode($delimiter, $feeds);
}
/**
@@ -6592,6 +6592,6 @@ function element_children(&$elements, $sort = FALSE) {
$children = array();
$sortable = FALSE;
foreach ($elements as $key => $value) {
+ if ($key === '' || (is_int($key) || $key[0] !== '#')) {
- if ($key === '' || $key[0] !== '#') {
$children[$key] = $value;
if (is_array($value) && isset($value['#weight'])) {
diff --git a/third_party/drupal-7.59/includes/menu.inc b/third_party/drupal-7.59/includes/menu.inc
index 4664d27..96698df 100644
--- a/third_party/drupal-7.59/includes/menu.inc
+++ b/third_party/drupal-7.59/includes/menu.inc
@@ -520,6 +520,7 @@ function menu_execute_active_handler($path = NULL, $deliver = TRUE) {
// Only continue if the site status is not set.
if ($page_callback_result == MENU_SITE_ONLINE) {
if ($router_item = menu_get_item($path)) {
+ $router_item['access'] = TRUE;
if ($router_item['access']) {
if ($router_item['include_file']) {
require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
diff --git a/third_party/drupal-7.59/modules/system/system.module b/third_party/drupal-7.59/modules/system/system.module
index 53844d8..dee8808 100644
--- a/third_party/drupal-7.59/modules/system/system.module
+++ b/third_party/drupal-7.59/modules/system/system.module
@@ -2131,7 +2131,11 @@ function system_admin_menu_block($item) {
}
if (!isset($item['mlid'])) {
- $item += db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = :path AND module = 'system'", array(':path' => $item['path']))->fetchAssoc();
+ $res = db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = :path AND module = 'system'", array(':path' => $item['path']))->fetchAssoc();
+
+ if ($res) {
+ $item += $res;
+ }
}
if (isset($cache[$item['mlid']])) {
diff --git a/third_party/drupal-7.59/sites/default/files/.htaccess b/third_party/drupal-7.59/sites/default/files/.htaccess
new file mode 100644
index 0000000..7051eb8
--- /dev/null
+++ b/third_party/drupal-7.59/sites/default/files/.htaccess
@@ -0,0 +1,15 @@
+# Turn off all options we don't need.
+Options None
+Options +FollowSymLinks
+
+# Set the catch-all handler to prevent scripts from being executed.
+SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
+<Files *>
+ # Override the handler again if we're run later in the evaluation list.
+ SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003
+</Files>
+
+# If we know how to do it safely, disable the PHP engine entirely.
+<IfModule mod_php5.c>
+ php_flag engine off
+</IfModule>
\ No newline at end of file
+71
View File
@@ -0,0 +1,71 @@
import { PhpBase } from './PhpBase';
const PhpBinary = require('./php-web-drupal');
export class PhpWebDrupal extends PhpBase
{
constructor(args = {})
{
super(PhpBinary, args);
}
}
if(window && document)
{
const php = new PhpWebDrupal;
const runScriptTag = element => {
const src = element.getAttribute('src');
if(src)
{
fetch(src).then(r => r.text()).then(r => {
php.run(r).then(exit=>console.log(exit));
});
return;
}
const inlineCode = element.innerText.trim();
if(inlineCode)
{
php.run(inlineCode);
}
};
php.addEventListener('ready', () => {
const phpSelector = 'script[type="text/php"]';
const htmlNode = document.body.parentElement;
const observer = new MutationObserver((mutations, observer)=>{
for(const mutation of mutations)
{
for(const addedNode of mutation.addedNodes)
{
if(!addedNode.matches || !addedNode.matches(phpSelector))
{
continue;
}
runScriptTag(addedNode);
}
}
});
observer.observe(htmlNode, {childList: true, subtree: true});
const phpNodes = document.querySelectorAll(phpSelector);
for(const phpNode of phpNodes)
{
const code = phpNode.innerText.trim();
runScriptTag(phpNode);
}
});
}