diff --git a/.gitea/workflows/release_build.yml b/.gitea/workflows/release_build.yml new file mode 100644 index 0000000..6a6ca31 --- /dev/null +++ b/.gitea/workflows/release_build.yml @@ -0,0 +1,383 @@ +name: Build, Push, Publish + +on: + push: + branches: + - main + workflow_dispatch: + schedule: + - cron: '28 5 * * *' + # workflow_run support in Gitea can be tricky, keeping it but might need adjustment + workflow_run: + workflows: ["Sync Repo"] + types: + - completed + +jobs: + release: + name: Build & Release + runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest + + permissions: + contents: write + packages: write + + steps: + - name: πŸ“₯ Checkout code with full history and tags + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check for Dockerargs and Upstream Updates + id: check_upstream + run: | + if [ -f Dockerargs ]; then + echo "Dockerargs found. Checking upstream..." + echo "Dockerargs found. Checking upstream..." + # Parse repo info using awk to avoid git config restrictions on underscores in keys elsewhere in the file + REPO_URL=$(awk -F '=' '/\[repo\]/{flag=1; next} /\[/{flag=0} flag && /^url=/{print $2}' Dockerargs | tr -d ' \r\n') + REPO_BRANCH=$(awk -F '=' '/\[repo\]/{flag=1; next} /\[/{flag=0} flag && /^branch=/{print $2}' Dockerargs | tr -d ' \r\n') + if [ -z "$REPO_BRANCH" ]; then REPO_BRANCH="main"; fi + + # Fetch upstream SHA + if [ -n "$REPO_URL" ]; then + UPSTREAM_SHA=$(git ls-remote "$REPO_URL" "$REPO_BRANCH" | awk '{ print $1 }' | head -c 7) + echo "Upstream SHA: $UPSTREAM_SHA" + + if [ -f manifest.json ]; then + LOCAL_SHA=$(jq -r '.upstream_sha // empty' manifest.json) + else + LOCAL_SHA="" + fi + + if [ "$LOCAL_SHA" != "$UPSTREAM_SHA" ]; then + echo "Upstream changed ($LOCAL_SHA -> $UPSTREAM_SHA)." + echo "upstream_needs_update=true" >> "$GITHUB_OUTPUT" + echo "upstream_sha=$UPSTREAM_SHA" >> "$GITHUB_OUTPUT" + echo "repo_url=$REPO_URL" >> "$GITHUB_OUTPUT" + echo "repo_branch=$REPO_BRANCH" >> "$GITHUB_OUTPUT" + else + echo "Upstream up to date." + echo "upstream_needs_update=false" >> "$GITHUB_OUTPUT" + fi + + # Parse Build Args + echo "Parsing [args] from Dockerargs..." + ARGS_CONTENT=$(sed -n '/^\[args\]/,/^\[/p' Dockerargs | grep -v '^\[' | grep '=' || true) + if [ -n "$ARGS_CONTENT" ]; then + echo "Found args:" + echo "$ARGS_CONTENT" + echo "build_args<> "$GITHUB_OUTPUT" + echo "$ARGS_CONTENT" >> "$GITHUB_OUTPUT" + echo "EOF" >> "$GITHUB_OUTPUT" + else + echo "No args found." + echo "build_args=" >> "$GITHUB_OUTPUT" + fi + else + echo "Repo URL not found in Dockerargs." + echo "upstream_needs_update=false" >> "$GITHUB_OUTPUT" + echo "build_args=" >> "$GITHUB_OUTPUT" + fi + else + echo "No Dockerargs found." + echo "upstream_needs_update=false" >> "$GITHUB_OUTPUT" + echo "build_args=" >> "$GITHUB_OUTPUT" + fi + + - name: Check if any tags exist + id: check_tags_exist + run: | + git fetch --tags + TAG_COUNT=$(git tag | wc -l) + if [ "$TAG_COUNT" -eq 0 ]; then + echo "has_tags=false" >> "$GITHUB_OUTPUT" + echo "latest_tag=v0.0.0" >> "$GITHUB_OUTPUT" + else + echo "has_tags=true" >> "$GITHUB_OUTPUT" + LATEST_TAG=$(git describe --tags --abbrev=0) + echo "latest_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT" + fi + + - name: Check if meaningful commits exist since latest tag + id: check_commits + run: | + UPSTREAM_UPDATE="${{ steps.check_upstream.outputs.upstream_needs_update }}" + if [ "$UPSTREAM_UPDATE" == "true" ]; then + echo "commit_count=1" >> "$GITHUB_OUTPUT" + echo "changed_files=Upstream Update to ${{ steps.check_upstream.outputs.upstream_sha }}" >> "$GITHUB_OUTPUT" + elif [ "${{ steps.check_tags_exist.outputs.has_tags }}" = "false" ]; then + # No tags exist, so we should create first release + echo "commit_count=1" >> "$GITHUB_OUTPUT" + CHANGED_FILES=$(git ls-files | grep -v '^manifest.json$' || true) + if [ -n "$CHANGED_FILES" ]; then + echo "changed_files<> "$GITHUB_OUTPUT" + printf '%s\n' "$CHANGED_FILES" >> "$GITHUB_OUTPUT" + echo "EOF" >> "$GITHUB_OUTPUT" + else + echo "changed_files=Initial release" >> "$GITHUB_OUTPUT" + fi + else + LATEST_TAG="${{ steps.check_tags_exist.outputs.latest_tag }}" + CHANGED_FILES="$(git diff --name-only "${LATEST_TAG}..HEAD" | grep -v '^manifest.json$' || true)" + if [ -n "$CHANGED_FILES" ]; then + echo "commit_count=1" >> "$GITHUB_OUTPUT" + echo "changed_files<> "$GITHUB_OUTPUT" + printf '%s\n' "$CHANGED_FILES" >> "$GITHUB_OUTPUT" + echo "EOF" >> "$GITHUB_OUTPUT" + else + echo "commit_count=0" >> "$GITHUB_OUTPUT" + fi + fi + + - name: Get latest release tag (from Gitea API) + id: get_latest_release + run: | + # Using Gitea API + LATEST_RELEASE_TAG=$(curl -sL -H "Accept: application/json" \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "${{ gitea.api_url }}/repos/${{ gitea.repository }}/releases/latest" | jq -r .tag_name) + + if [ -z "$LATEST_RELEASE_TAG" ] || [ "$LATEST_RELEASE_TAG" = "null" ]; then + LATEST_RELEASE_TAG="v1.0.0" + fi + echo "latest_release_tag=$LATEST_RELEASE_TAG" >> "$GITHUB_OUTPUT" + echo "latest_release_version=${LATEST_RELEASE_TAG#v}" >> "$GITHUB_OUTPUT" + + # ------------------------------- + # Sync manifest.json to last release version if behind (only when no meaningful commits) + # ------------------------------- + - name: πŸ›  Ensure manifest.json matches latest release version + if: steps.check_commits.outputs.commit_count == '0' + run: | + if [ -f manifest.json ]; then + MANIFEST_VERSION=$(jq -r '.version // empty' manifest.json) + else + MANIFEST_VERSION="" + fi + LATEST_RELEASE_VERSION="${{ steps.get_latest_release.outputs.latest_release_version }}" + PYTHON_CODE="from packaging import version; \ + print(version.parse('$LATEST_RELEASE_VERSION') > version.parse('$MANIFEST_VERSION') if '$MANIFEST_VERSION' else True)" + # Python3 is available in catthehacker/ubuntu:act-latest + NEED_UPDATE=$(python3 -c "$PYTHON_CODE") + if [ "$NEED_UPDATE" = "True" ]; then + echo "Updating manifest.json to version $LATEST_RELEASE_VERSION (sync with release)" + jq --arg v "$LATEST_RELEASE_VERSION" '.version = $v' manifest.json > tmp.json && mv tmp.json manifest.json + git config user.name "Gitea Actions" + git config user.email "actions@git.icc.gg" + git add manifest.json + git commit -m "Sync manifest.json to release $LATEST_RELEASE_VERSION [πŸ”„]" || echo "Nothing to commit" + git push origin main || true + else + echo "Manifest.json is already up-to-date with the latest release." + fi + + # ------------------------------- + # Continue normal workflow if commits exist + # ------------------------------- + - name: πŸ“ƒ Get list of changed files (Markdown bullet list) + if: steps.check_commits.outputs.commit_count != '0' + id: changed_files + run: | + BULLET_LIST="$(printf '%s\n' "${{ steps.check_commits.outputs.changed_files }}" | sed 's/^/- /')" + echo "CHANGED<> "$GITHUB_OUTPUT" + printf '%s\n' "$BULLET_LIST" >> "$GITHUB_OUTPUT" + echo "EOF" >> "$GITHUB_OUTPUT" + COUNT="$(printf '%s\n' "${{ steps.check_commits.outputs.changed_files }}" | wc -l)" + echo "COUNT=$COUNT" >> "$GITHUB_OUTPUT" + + - name: Get manifest version + if: steps.check_commits.outputs.commit_count != '0' + id: get_manifest_version + run: | + if [ -f manifest.json ]; then + MANIFEST_VERSION=$(jq -r '.version // empty' manifest.json) + if [ -z "$MANIFEST_VERSION" ] || [ "$MANIFEST_VERSION" = "null" ]; then + MANIFEST_VERSION="1.0.0" + fi + else + MANIFEST_VERSION="1.0.0" + fi + echo "manifest_version=$MANIFEST_VERSION" >> "$GITHUB_OUTPUT" + + - name: Pick base version + if: steps.check_commits.outputs.commit_count != '0' + id: pick_base_version + run: | + LATEST_RELEASE="${{ steps.get_latest_release.outputs.latest_release_version }}" + MANIFEST="${{ steps.get_manifest_version.outputs.manifest_version }}" + BASE_VERSION=$(python3 -c "from packaging import version; \ + print(str(max(version.parse('$LATEST_RELEASE'), version.parse('$MANIFEST'))))") + echo "base_version=$BASE_VERSION" >> "$GITHUB_OUTPUT" + + - name: πŸ”’ Determine version + if: steps.check_commits.outputs.commit_count != '0' + id: version + run: | + BASE_VERSION="${{ steps.pick_base_version.outputs.base_version }}" + MAJOR=$(echo "$BASE_VERSION" | cut -d. -f1) + MINOR=$(echo "$BASE_VERSION" | cut -d. -f2) + PATCH=$(echo "$BASE_VERSION" | cut -d. -f3) + COUNT="${{ steps.changed_files.outputs.COUNT }}" + if [ "$COUNT" -ge 5 ]; then + MAJOR=$((MAJOR + 1)) + MINOR=0 + PATCH=0 + elif [ "$COUNT" -ge 3 ]; then + MINOR=$((MINOR + 1)) + PATCH=0 + else + PATCH=$((PATCH + 1)) + fi + NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" + REPO_NAME="$(basename "$GITHUB_REPOSITORY")" + ZIP_NAME="${REPO_NAME}-${NEW_VERSION}.zip" + echo "VERSION=$NEW_VERSION" >> "$GITHUB_OUTPUT" + echo "ZIP_NAME=$ZIP_NAME" >> "$GITHUB_OUTPUT" + echo "REPO_NAME=$REPO_NAME" >> "$GITHUB_OUTPUT" + + - name: πŸ›  Update or create manifest.json + if: steps.check_commits.outputs.commit_count != '0' + run: | + VERSION="${{ steps.version.outputs.VERSION }}" + AUTHOR="Ivan Carlos" + VERSION_FILE="manifest.json" + UPSTREAM_SHA="${{ steps.check_upstream.outputs.upstream_sha }}" + + if [ -f "$VERSION_FILE" ]; then + jq --arg v "$VERSION" \ + --arg a "$AUTHOR" \ + --arg u "$UPSTREAM_SHA" \ + '.version = $v | .author = $a | if $u != "" and $u != null then .upstream_sha = $u else . end' \ + "$VERSION_FILE" > tmp.json && mv tmp.json "$VERSION_FILE" + else + echo "{ \"version\": \"$VERSION\", \"author\": \"$AUTHOR\", \"upstream_sha\": \"$UPSTREAM_SHA\" }" > "$VERSION_FILE" + fi + + - name: πŸ’Ύ Commit and push updated manifest.json + if: steps.check_commits.outputs.commit_count != '0' + run: | + git config user.name "Gitea Actions" + git config user.email "actions@git.icc.gg" + git add manifest.json + git commit -m "Update manifest version to ${{ steps.version.outputs.VERSION }} [▢️]" || echo "Nothing to commit" + git push origin main + + - name: πŸ“¦ Create ZIP package (excluding certain files) + if: steps.check_commits.outputs.commit_count != '0' + run: | + ZIP_NAME="${{ steps.version.outputs.ZIP_NAME }}" + zip -r "$ZIP_NAME" . -x ".git/*" ".github/*" "docker/*" ".dockerignore" "CNAME" "Dockerfile" "README.md" "LICENSE" ".gitea/*" + + - name: πŸš€ Create Gitea Release + if: steps.check_commits.outputs.commit_count != '0' + id: create_release + env: + CHANGELOG_LIST: ${{ steps.changed_files.outputs.CHANGED }} + run: | + TAG_NAME="v${{ steps.version.outputs.VERSION }}" + RELEASE_NAME="${{ steps.version.outputs.REPO_NAME }} v${{ steps.version.outputs.VERSION }}" + + # Construct Markdown body safely using env var + # We use printf to avoid interpreting backslashes in the file list + BODY=$(printf "### Changelog\nFiles changed in this release:\n%s" "$CHANGELOG_LIST") + + # Create JSON payload using jq + jq -n \ + --arg tag_name "$TAG_NAME" \ + --arg name "$RELEASE_NAME" \ + --arg body "$BODY" \ + '{tag_name: $tag_name, name: $name, body: $body, draft: false, prerelease: false}' > release_payload.json + + echo "DEBUG: Generated Payload:" + cat release_payload.json + + # Create Release + curl -s -X POST "${{ gitea.api_url }}/repos/${{ gitea.repository }}/releases" \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d @release_payload.json > api_response.json + + echo "DEBUG: API Response:" + cat api_response.json || true + + RELEASE_ID=$(jq -r .id api_response.json) + echo "RELEASE_ID=$RELEASE_ID" >> "$GITHUB_OUTPUT" + + if [ "$RELEASE_ID" == "null" ] || [ -z "$RELEASE_ID" ]; then + echo "Failed to create release. Response content:" + cat api_response.json + exit 1 + fi + + - name: πŸ“€ Upload Release Asset + if: steps.check_commits.outputs.commit_count != '0' + run: | + RELEASE_ID="${{ steps.create_release.outputs.RELEASE_ID }}" + ZIP_NAME="${{ steps.version.outputs.ZIP_NAME }}" + FILE_PATH="./$ZIP_NAME" + + curl -s -X POST "${{ gitea.api_url }}/repos/${{ gitea.repository }}/releases/$RELEASE_ID/assets" \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/zip" \ + --data-binary @"$FILE_PATH" \ + -o /dev/null + + # ----- Docker steps ----- + - name: Clone Upstream Code (if needed) + if: steps.check_commits.outputs.commit_count != '0' && (steps.check_upstream.outputs.upstream_needs_update == 'true' || steps.check_upstream.outputs.repo_url != '') + run: | + rm -rf upstream_src + git clone --depth 1 --branch ${{ steps.check_upstream.outputs.repo_branch }} ${{ steps.check_upstream.outputs.repo_url }} upstream_src + + - name: πŸ” Check if Dockerfile exists + if: steps.check_commits.outputs.commit_count != '0' || steps.check_upstream.outputs.upstream_needs_update == 'true' + id: dockerfile_check + run: | + if [ -n "${{ steps.check_upstream.outputs.repo_url }}" ]; then + if [ -f upstream_src/Dockerfile ]; then + echo "exists=true" >> "$GITHUB_OUTPUT" + else + # Fallback or error? User said "ignore", but we need a dockerfile to build. + # Assuming if upstream_src is present, we trust it, or fail at build time. + # Let's say exists=true and let build fail if missing, per user hint. + echo "exists=true" >> "$GITHUB_OUTPUT" + fi + elif [ -f Dockerfile ]; then + echo "exists=true" >> "$GITHUB_OUTPUT" + else + echo "exists=false" >> "$GITHUB_OUTPUT" + fi + + - name: πŸ” Login to Gitea Container Registry + if: steps.check_commits.outputs.commit_count != '0' && steps.dockerfile_check.outputs.exists == 'true' + uses: docker/login-action@v3 + with: + registry: git.icc.gg + username: ${{ gitea.actor }} + password: ${{ secrets.CR_PAT }} + + - name: πŸ›  Set up QEMU + if: steps.check_commits.outputs.commit_count != '0' && steps.dockerfile_check.outputs.exists == 'true' + uses: docker/setup-qemu-action@v3 + + - name: πŸ›  Set up Docker Buildx + if: steps.check_commits.outputs.commit_count != '0' && steps.dockerfile_check.outputs.exists == 'true' + uses: docker/setup-buildx-action@v3 + + - name: 🐳 Build and Push Docker image + if: steps.check_commits.outputs.commit_count != '0' && steps.dockerfile_check.outputs.exists == 'true' + uses: docker/build-push-action@v5 + id: docker_build + with: + context: ${{ steps.check_upstream.outputs.repo_url != '' && './upstream_src' || '.' }} + platforms: linux/amd64,linux/arm64 + file: ${{ steps.check_upstream.outputs.repo_url != '' && './upstream_src/Dockerfile' || './Dockerfile' }} + push: true + build-args: | + ${{ steps.check_upstream.outputs.build_args }} + tags: | + git.icc.gg/${{ gitea.repository }}:latest + git.icc.gg/${{ gitea.repository }}:${{ steps.version.outputs.VERSION }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9d174f1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM nginx:alpine + +COPY public/ /usr/share/nginx/html + +# Install wget and download jQuery +RUN apk add --no-cache wget && \ + mkdir -p /usr/share/nginx/html/jquery && \ + wget https://code.jquery.com/jquery-3.5.1.slim.min.js -O /usr/share/nginx/html/jquery/jquery-3.5.1.slim.min.js diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6603463 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Ivan Carlos + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..eca6cda --- /dev/null +++ b/manifest.json @@ -0,0 +1,4 @@ +{ + "version": "1.0.0", + "author": "Ivan Carlos" +} diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..ae37945 Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/images/icons/icon-128x128.png b/public/images/icons/icon-128x128.png new file mode 100644 index 0000000..855c723 Binary files /dev/null and b/public/images/icons/icon-128x128.png differ diff --git a/public/images/icons/icon-144x144.png b/public/images/icons/icon-144x144.png new file mode 100644 index 0000000..461a687 Binary files /dev/null and b/public/images/icons/icon-144x144.png differ diff --git a/public/images/icons/icon-152x152.png b/public/images/icons/icon-152x152.png new file mode 100644 index 0000000..cf9b173 Binary files /dev/null and b/public/images/icons/icon-152x152.png differ diff --git a/public/images/icons/icon-192x192.png b/public/images/icons/icon-192x192.png new file mode 100644 index 0000000..06d4ca3 Binary files /dev/null and b/public/images/icons/icon-192x192.png differ diff --git a/public/images/icons/icon-384x384.png b/public/images/icons/icon-384x384.png new file mode 100644 index 0000000..fe02b54 Binary files /dev/null and b/public/images/icons/icon-384x384.png differ diff --git a/public/images/icons/icon-512x512.png b/public/images/icons/icon-512x512.png new file mode 100644 index 0000000..f7e4be8 Binary files /dev/null and b/public/images/icons/icon-512x512.png differ diff --git a/public/images/icons/icon-72x72.png b/public/images/icons/icon-72x72.png new file mode 100644 index 0000000..27d0760 Binary files /dev/null and b/public/images/icons/icon-72x72.png differ diff --git a/public/images/icons/icon-96x96.png b/public/images/icons/icon-96x96.png new file mode 100644 index 0000000..cba8d85 Binary files /dev/null and b/public/images/icons/icon-96x96.png differ diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..6b3a951 --- /dev/null +++ b/public/index.html @@ -0,0 +1,263 @@ + + + + + + + + + Wifi no QR + + + + + + + + + + + +
+
+ + + + + +
+
+ +
+ + + +
+
+ +
+ +
+ + +
+
+ +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + + Download PNG + Print +
+
+ +
+

SSID: none

+

Passphrase: none

+
+
+ + +
+
+ + + + + + + + + + diff --git a/public/jquery-qrcode/.gitignore b/public/jquery-qrcode/.gitignore new file mode 100644 index 0000000..8d4ae25 --- /dev/null +++ b/public/jquery-qrcode/.gitignore @@ -0,0 +1 @@ +bower_components diff --git a/public/jquery-qrcode/MIT-LICENSE.txt b/public/jquery-qrcode/MIT-LICENSE.txt new file mode 100644 index 0000000..6d32551 --- /dev/null +++ b/public/jquery-qrcode/MIT-LICENSE.txt @@ -0,0 +1,20 @@ +Copyright (c) 2011 Jerome Etienne, http://jetienne.com + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/public/jquery-qrcode/Makefile b/public/jquery-qrcode/Makefile new file mode 100644 index 0000000..9f7320f --- /dev/null +++ b/public/jquery-qrcode/Makefile @@ -0,0 +1,32 @@ +PROJECT_NAME=jquery-qrcode + +all: + +server: + python -m SimpleHTTPServer + +build: minify + +minify: + echo > /tmp/jquery.qrcode.tmp.js + head -2 src/jquery.qrcode.js >> /tmp/jquery.qrcode.tmp.js + cat src/qrcode.js >> /tmp/jquery.qrcode.tmp.js + tail -n +3 src/jquery.qrcode.js >> /tmp/jquery.qrcode.tmp.js + curl --data-urlencode "js_code@/tmp/jquery.qrcode.tmp.js" \ + -d "output_format=text&output_info=compiled_code&compilation_level=SIMPLE_OPTIMIZATIONS" \ + http://closure-compiler.appspot.com/compile \ + > jquery.qrcode.min.js + +homepage_build: + pandoc -A ~/.pandoc.header.html -s README.md -o index.html + sed -i "s/github.com\/you/github.com\/jeromeetienne\/$(PROJECT_NAME)/g" index.html + +################################################################################# +# deploy # +################################################################################# + +deploy: build + # assume there is something to commit + # use "git diff --exit-code HEAD" to know if there is something to commit + # so two lines: one if no commit, one if something to commit + git commit -a -m "New deploy" && git push -f origin HEAD:gh-pages && git reset HEAD~ \ No newline at end of file diff --git a/public/jquery-qrcode/bower.json b/public/jquery-qrcode/bower.json new file mode 100644 index 0000000..d62f5ff --- /dev/null +++ b/public/jquery-qrcode/bower.json @@ -0,0 +1,26 @@ +{ + "name": "jquery-qrcode", + "version": "1.0.0", + "homepage": "http://www.d-project.com/", + "authors": [ + "jeromeetienne" + ], + "description": "It allow you to easily add qrcode to your webpages. It is standalone, less than 4k after minify+gzip, no image download", + "main": "jquery.qrcode.min.js", + "keywords": [ + "QR", + "jQuery", + "standalone" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "dependencies": { + "jquery": "~1.9" + } +} diff --git a/public/jquery-qrcode/examples/basic.html b/public/jquery-qrcode/examples/basic.html new file mode 100644 index 0000000..5213bc3 --- /dev/null +++ b/public/jquery-qrcode/examples/basic.html @@ -0,0 +1,29 @@ + + + +basic example + + + + + + + +

Render in table

+
+

Render in canvas

+
+ + + + diff --git a/public/jquery-qrcode/examples/demo.html b/public/jquery-qrcode/examples/demo.html new file mode 100644 index 0000000..66bfc13 --- /dev/null +++ b/public/jquery-qrcode/examples/demo.html @@ -0,0 +1,24 @@ + + + +Demo page + + + +

+ TODO make a nice looking pure client qrcode generator + even allow download of the image +

+ +
+ + + + + + + diff --git a/public/jquery-qrcode/jquery.qrcode.min.js b/public/jquery-qrcode/jquery.qrcode.min.js new file mode 100644 index 0000000..fe9680e --- /dev/null +++ b/public/jquery-qrcode/jquery.qrcode.min.js @@ -0,0 +1,28 @@ +(function(r){r.fn.qrcode=function(h){var s;function u(a){this.mode=s;this.data=a}function o(a,c){this.typeNumber=a;this.errorCorrectLevel=c;this.modules=null;this.moduleCount=0;this.dataCache=null;this.dataList=[]}function q(a,c){if(void 0==a.length)throw Error(a.length+"/"+c);for(var d=0;da||this.moduleCount<=a||0>c||this.moduleCount<=c)throw Error(a+","+c);return this.modules[a][c]},getModuleCount:function(){return this.moduleCount},make:function(){if(1>this.typeNumber){for(var a=1,a=1;40>a;a++){for(var c=p.getRSBlocks(a,this.errorCorrectLevel),d=new t,b=0,e=0;e=d;d++)if(!(-1>=a+d||this.moduleCount<=a+d))for(var b=-1;7>=b;b++)-1>=c+b||this.moduleCount<=c+b||(this.modules[a+d][c+b]= +0<=d&&6>=d&&(0==b||6==b)||0<=b&&6>=b&&(0==d||6==d)||2<=d&&4>=d&&2<=b&&4>=b?!0:!1)},getBestMaskPattern:function(){for(var a=0,c=0,d=0;8>d;d++){this.makeImpl(!0,d);var b=j.getLostPoint(this);if(0==d||a>b)a=b,c=d}return c},createMovieClip:function(a,c,d){a=a.createEmptyMovieClip(c,d);this.make();for(c=0;c=f;f++)for(var i=-2;2>=i;i++)this.modules[b+f][e+i]=-2==f||2==f||-2==i||2==i||0==f&&0==i?!0:!1}},setupTypeNumber:function(a){for(var c= +j.getBCHTypeNumber(this.typeNumber),d=0;18>d;d++){var b=!a&&1==(c>>d&1);this.modules[Math.floor(d/3)][d%3+this.moduleCount-8-3]=b}for(d=0;18>d;d++)b=!a&&1==(c>>d&1),this.modules[d%3+this.moduleCount-8-3][Math.floor(d/3)]=b},setupTypeInfo:function(a,c){for(var d=j.getBCHTypeInfo(this.errorCorrectLevel<<3|c),b=0;15>b;b++){var e=!a&&1==(d>>b&1);6>b?this.modules[b][8]=e:8>b?this.modules[b+1][8]=e:this.modules[this.moduleCount-15+b][8]=e}for(b=0;15>b;b++)e=!a&&1==(d>>b&1),8>b?this.modules[8][this.moduleCount- +b-1]=e:9>b?this.modules[8][15-b-1+1]=e:this.modules[8][15-b-1]=e;this.modules[this.moduleCount-8][8]=!a},mapData:function(a,c){for(var d=-1,b=this.moduleCount-1,e=7,f=0,i=this.moduleCount-1;0g;g++)if(null==this.modules[b][i-g]){var n=!1;f>>e&1));j.getMask(c,b,i-g)&&(n=!n);this.modules[b][i-g]=n;e--; -1==e&&(f++,e=7)}b+=d;if(0>b||this.moduleCount<=b){b-=d;d=-d;break}}}};o.PAD0=236;o.PAD1=17;o.createData=function(a,c,d){for(var c=p.getRSBlocks(a, +c),b=new t,e=0;e8*a)throw Error("code length overflow. ("+b.getLengthInBits()+">"+8*a+")");for(b.getLengthInBits()+4<=8*a&&b.put(0,4);0!=b.getLengthInBits()%8;)b.putBit(!1);for(;!(b.getLengthInBits()>=8*a);){b.put(o.PAD0,8);if(b.getLengthInBits()>=8*a)break;b.put(o.PAD1,8)}return o.createBytes(b,c)};o.createBytes=function(a,c){for(var d= +0,b=0,e=0,f=Array(c.length),i=Array(c.length),g=0;g>>=1;return c},getPatternPosition:function(a){return j.PATTERN_POSITION_TABLE[a-1]},getMask:function(a,c,d){switch(a){case 0:return 0==(c+d)%2;case 1:return 0==c%2;case 2:return 0==d%3;case 3:return 0==(c+d)%3;case 4:return 0==(Math.floor(c/2)+Math.floor(d/3))%2;case 5:return 0==c*d%2+c*d%3;case 6:return 0==(c*d%2+c*d%3)%2;case 7:return 0==(c*d%3+(c+d)%2)%2;default:throw Error("bad maskPattern:"+ +a);}},getErrorCorrectPolynomial:function(a){for(var c=new q([1],0),d=0;dc)switch(a){case 1:return 10;case 2:return 9;case s:return 8;case 8:return 8;default:throw Error("mode:"+a);}else if(27>c)switch(a){case 1:return 12;case 2:return 11;case s:return 16;case 8:return 10;default:throw Error("mode:"+a);}else if(41>c)switch(a){case 1:return 14;case 2:return 13;case s:return 16;case 8:return 12;default:throw Error("mode:"+ +a);}else throw Error("type:"+c);},getLostPoint:function(a){for(var c=a.getModuleCount(),d=0,b=0;b=g;g++)if(!(0>b+g||c<=b+g))for(var h=-1;1>=h;h++)0>e+h||c<=e+h||0==g&&0==h||i==a.isDark(b+g,e+h)&&f++;5a)throw Error("glog("+a+")");return l.LOG_TABLE[a]},gexp:function(a){for(;0>a;)a+=255;for(;256<=a;)a-=255;return l.EXP_TABLE[a]},EXP_TABLE:Array(256), +LOG_TABLE:Array(256)},m=0;8>m;m++)l.EXP_TABLE[m]=1<m;m++)l.EXP_TABLE[m]=l.EXP_TABLE[m-4]^l.EXP_TABLE[m-5]^l.EXP_TABLE[m-6]^l.EXP_TABLE[m-8];for(m=0;255>m;m++)l.LOG_TABLE[l.EXP_TABLE[m]]=m;q.prototype={get:function(a){return this.num[a]},getLength:function(){return this.num.length},multiply:function(a){for(var c=Array(this.getLength()+a.getLength()-1),d=0;d +this.getLength()-a.getLength())return this;for(var c=l.glog(this.get(0))-l.glog(a.get(0)),d=Array(this.getLength()),b=0;b>>7-a%8&1)},put:function(a,c){for(var d=0;d>>c-d-1&1))},getLengthInBits:function(){return this.length},putBit:function(a){var c=Math.floor(this.length/8);this.buffer.length<=c&&this.buffer.push(0);a&&(this.buffer[c]|=128>>>this.length%8);this.length++}};"string"===typeof h&&(h={text:h});h=r.extend({},{render:"canvas",width:256,height:256,typeNumber:-1, +correctLevel:2,background:"#ffffff",foreground:"#000000"},h);return this.each(function(){var a;if("canvas"==h.render){a=new o(h.typeNumber,h.correctLevel);a.addData(h.text);a.make();var c=document.createElement("canvas");c.width=h.width;c.height=h.height;for(var d=c.getContext("2d"),b=h.width/a.getModuleCount(),e=h.height/a.getModuleCount(),f=0;f").css("width",h.width+"px").css("height",h.height+"px").css("border","0px").css("border-collapse","collapse").css("background-color",h.background);d=h.width/a.getModuleCount();b=h.height/a.getModuleCount();for(e=0;e").css("height",b+"px").appendTo(c);for(i=0;i").css("width", +d+"px").css("background-color",a.isDark(e,i)?h.foreground:h.background).appendTo(f)}}a=c;jQuery(a).appendTo(this)})}})(jQuery); diff --git a/public/jquery-qrcode/src/jquery.qrcode.js b/public/jquery-qrcode/src/jquery.qrcode.js new file mode 100644 index 0000000..d329934 --- /dev/null +++ b/public/jquery-qrcode/src/jquery.qrcode.js @@ -0,0 +1,89 @@ +(function( $ ){ + $.fn.qrcode = function(options) { + // if options is string, + if( typeof options === 'string' ){ + options = { text: options }; + } + + // set default values + // typeNumber < 1 for automatic calculation + options = $.extend( {}, { + render : "canvas", + width : 256, + height : 256, + typeNumber : -1, + correctLevel : QRErrorCorrectLevel.H, + background : "#ffffff", + foreground : "#000000" + }, options); + + var createCanvas = function(){ + // create the qrcode itself + var qrcode = new QRCode(options.typeNumber, options.correctLevel); + qrcode.addData(options.text); + qrcode.make(); + + // create canvas element + var canvas = document.createElement('canvas'); + canvas.width = options.width; + canvas.height = options.height; + var ctx = canvas.getContext('2d'); + + // compute tileW/tileH based on options.width/options.height + var tileW = options.width / qrcode.getModuleCount(); + var tileH = options.height / qrcode.getModuleCount(); + + // draw in the canvas + for( var row = 0; row < qrcode.getModuleCount(); row++ ){ + for( var col = 0; col < qrcode.getModuleCount(); col++ ){ + ctx.fillStyle = qrcode.isDark(row, col) ? options.foreground : options.background; + var w = (Math.ceil((col+1)*tileW) - Math.floor(col*tileW)); + var h = (Math.ceil((row+1)*tileH) - Math.floor(row*tileH)); + ctx.fillRect(Math.round(col*tileW),Math.round(row*tileH), w, h); + } + } + // return just built canvas + return canvas; + } + + // from Jon-Carlos Rivera (https://github.com/imbcmdth) + var createTable = function(){ + // create the qrcode itself + var qrcode = new QRCode(options.typeNumber, options.correctLevel); + qrcode.addData(options.text); + qrcode.make(); + + // create table element + var $table = $('
') + .css("width", options.width+"px") + .css("height", options.height+"px") + .css("border", "0px") + .css("border-collapse", "collapse") + .css('background-color', options.background); + + // compute tileS percentage + var tileW = options.width / qrcode.getModuleCount(); + var tileH = options.height / qrcode.getModuleCount(); + + // draw in the table + for(var row = 0; row < qrcode.getModuleCount(); row++ ){ + var $row = $('').css('height', tileH+"px").appendTo($table); + + for(var col = 0; col < qrcode.getModuleCount(); col++ ){ + $('') + .css('width', tileW+"px") + .css('background-color', qrcode.isDark(row, col) ? options.foreground : options.background) + .appendTo($row); + } + } + // return just built canvas + return $table; + } + + + return this.each(function(){ + var element = options.render == "canvas" ? createCanvas() : createTable(); + $(element).appendTo(this); + }); + }; +})( jQuery ); diff --git a/public/jquery-qrcode/src/qrcode.js b/public/jquery-qrcode/src/qrcode.js new file mode 100644 index 0000000..5cbe0f6 --- /dev/null +++ b/public/jquery-qrcode/src/qrcode.js @@ -0,0 +1,1237 @@ +//--------------------------------------------------------------------- +// QRCode for JavaScript +// +// Copyright (c) 2009 Kazuhiko Arase +// +// URL: http://www.d-project.com/ +// +// Licensed under the MIT license: +// http://www.opensource.org/licenses/mit-license.php +// +// The word "QR Code" is registered trademark of +// DENSO WAVE INCORPORATED +// http://www.denso-wave.com/qrcode/faqpatent-e.html +// +//--------------------------------------------------------------------- + +//--------------------------------------------------------------------- +// QR8bitByte +//--------------------------------------------------------------------- + +function QR8bitByte(data) { + this.mode = QRMode.MODE_8BIT_BYTE; + this.data = data; +} + +QR8bitByte.prototype = { + + getLength : function(buffer) { + return this.data.length; + }, + + write : function(buffer) { + for (var i = 0; i < this.data.length; i++) { + // not JIS ... + buffer.put(this.data.charCodeAt(i), 8); + } + } +}; + +//--------------------------------------------------------------------- +// QRCode +//--------------------------------------------------------------------- + +function QRCode(typeNumber, errorCorrectLevel) { + this.typeNumber = typeNumber; + this.errorCorrectLevel = errorCorrectLevel; + this.modules = null; + this.moduleCount = 0; + this.dataCache = null; + this.dataList = new Array(); +} + +QRCode.prototype = { + + addData : function(data) { + var newData = new QR8bitByte(data); + this.dataList.push(newData); + this.dataCache = null; + }, + + isDark : function(row, col) { + if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) { + throw new Error(row + "," + col); + } + return this.modules[row][col]; + }, + + getModuleCount : function() { + return this.moduleCount; + }, + + make : function() { + // Calculate automatically typeNumber if provided is < 1 + if (this.typeNumber < 1 ){ + var typeNumber = 1; + for (typeNumber = 1; typeNumber < 40; typeNumber++) { + var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel); + + var buffer = new QRBitBuffer(); + var totalDataCount = 0; + for (var i = 0; i < rsBlocks.length; i++) { + totalDataCount += rsBlocks[i].dataCount; + } + + for (var i = 0; i < this.dataList.length; i++) { + var data = this.dataList[i]; + buffer.put(data.mode, 4); + buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber) ); + data.write(buffer); + } + if (buffer.getLengthInBits() <= totalDataCount * 8) + break; + } + this.typeNumber = typeNumber; + } + this.makeImpl(false, this.getBestMaskPattern() ); + }, + + makeImpl : function(test, maskPattern) { + + this.moduleCount = this.typeNumber * 4 + 17; + this.modules = new Array(this.moduleCount); + + for (var row = 0; row < this.moduleCount; row++) { + + this.modules[row] = new Array(this.moduleCount); + + for (var col = 0; col < this.moduleCount; col++) { + this.modules[row][col] = null;//(col + row) % 3; + } + } + + this.setupPositionProbePattern(0, 0); + this.setupPositionProbePattern(this.moduleCount - 7, 0); + this.setupPositionProbePattern(0, this.moduleCount - 7); + this.setupPositionAdjustPattern(); + this.setupTimingPattern(); + this.setupTypeInfo(test, maskPattern); + + if (this.typeNumber >= 7) { + this.setupTypeNumber(test); + } + + if (this.dataCache == null) { + this.dataCache = QRCode.createData(this.typeNumber, this.errorCorrectLevel, this.dataList); + } + + this.mapData(this.dataCache, maskPattern); + }, + + setupPositionProbePattern : function(row, col) { + + for (var r = -1; r <= 7; r++) { + + if (row + r <= -1 || this.moduleCount <= row + r) continue; + + for (var c = -1; c <= 7; c++) { + + if (col + c <= -1 || this.moduleCount <= col + c) continue; + + if ( (0 <= r && r <= 6 && (c == 0 || c == 6) ) + || (0 <= c && c <= 6 && (r == 0 || r == 6) ) + || (2 <= r && r <= 4 && 2 <= c && c <= 4) ) { + this.modules[row + r][col + c] = true; + } else { + this.modules[row + r][col + c] = false; + } + } + } + }, + + getBestMaskPattern : function() { + + var minLostPoint = 0; + var pattern = 0; + + for (var i = 0; i < 8; i++) { + + this.makeImpl(true, i); + + var lostPoint = QRUtil.getLostPoint(this); + + if (i == 0 || minLostPoint > lostPoint) { + minLostPoint = lostPoint; + pattern = i; + } + } + + return pattern; + }, + + createMovieClip : function(target_mc, instance_name, depth) { + + var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth); + var cs = 1; + + this.make(); + + for (var row = 0; row < this.modules.length; row++) { + + var y = row * cs; + + for (var col = 0; col < this.modules[row].length; col++) { + + var x = col * cs; + var dark = this.modules[row][col]; + + if (dark) { + qr_mc.beginFill(0, 100); + qr_mc.moveTo(x, y); + qr_mc.lineTo(x + cs, y); + qr_mc.lineTo(x + cs, y + cs); + qr_mc.lineTo(x, y + cs); + qr_mc.endFill(); + } + } + } + + return qr_mc; + }, + + setupTimingPattern : function() { + + for (var r = 8; r < this.moduleCount - 8; r++) { + if (this.modules[r][6] != null) { + continue; + } + this.modules[r][6] = (r % 2 == 0); + } + + for (var c = 8; c < this.moduleCount - 8; c++) { + if (this.modules[6][c] != null) { + continue; + } + this.modules[6][c] = (c % 2 == 0); + } + }, + + setupPositionAdjustPattern : function() { + + var pos = QRUtil.getPatternPosition(this.typeNumber); + + for (var i = 0; i < pos.length; i++) { + + for (var j = 0; j < pos.length; j++) { + + var row = pos[i]; + var col = pos[j]; + + if (this.modules[row][col] != null) { + continue; + } + + for (var r = -2; r <= 2; r++) { + + for (var c = -2; c <= 2; c++) { + + if (r == -2 || r == 2 || c == -2 || c == 2 + || (r == 0 && c == 0) ) { + this.modules[row + r][col + c] = true; + } else { + this.modules[row + r][col + c] = false; + } + } + } + } + } + }, + + setupTypeNumber : function(test) { + + var bits = QRUtil.getBCHTypeNumber(this.typeNumber); + + for (var i = 0; i < 18; i++) { + var mod = (!test && ( (bits >> i) & 1) == 1); + this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod; + } + + for (var i = 0; i < 18; i++) { + var mod = (!test && ( (bits >> i) & 1) == 1); + this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod; + } + }, + + setupTypeInfo : function(test, maskPattern) { + + var data = (this.errorCorrectLevel << 3) | maskPattern; + var bits = QRUtil.getBCHTypeInfo(data); + + // vertical + for (var i = 0; i < 15; i++) { + + var mod = (!test && ( (bits >> i) & 1) == 1); + + if (i < 6) { + this.modules[i][8] = mod; + } else if (i < 8) { + this.modules[i + 1][8] = mod; + } else { + this.modules[this.moduleCount - 15 + i][8] = mod; + } + } + + // horizontal + for (var i = 0; i < 15; i++) { + + var mod = (!test && ( (bits >> i) & 1) == 1); + + if (i < 8) { + this.modules[8][this.moduleCount - i - 1] = mod; + } else if (i < 9) { + this.modules[8][15 - i - 1 + 1] = mod; + } else { + this.modules[8][15 - i - 1] = mod; + } + } + + // fixed module + this.modules[this.moduleCount - 8][8] = (!test); + + }, + + mapData : function(data, maskPattern) { + + var inc = -1; + var row = this.moduleCount - 1; + var bitIndex = 7; + var byteIndex = 0; + + for (var col = this.moduleCount - 1; col > 0; col -= 2) { + + if (col == 6) col--; + + while (true) { + + for (var c = 0; c < 2; c++) { + + if (this.modules[row][col - c] == null) { + + var dark = false; + + if (byteIndex < data.length) { + dark = ( ( (data[byteIndex] >>> bitIndex) & 1) == 1); + } + + var mask = QRUtil.getMask(maskPattern, row, col - c); + + if (mask) { + dark = !dark; + } + + this.modules[row][col - c] = dark; + bitIndex--; + + if (bitIndex == -1) { + byteIndex++; + bitIndex = 7; + } + } + } + + row += inc; + + if (row < 0 || this.moduleCount <= row) { + row -= inc; + inc = -inc; + break; + } + } + } + + } + +}; + +QRCode.PAD0 = 0xEC; +QRCode.PAD1 = 0x11; + +QRCode.createData = function(typeNumber, errorCorrectLevel, dataList) { + + var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel); + + var buffer = new QRBitBuffer(); + + for (var i = 0; i < dataList.length; i++) { + var data = dataList[i]; + buffer.put(data.mode, 4); + buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber) ); + data.write(buffer); + } + + // calc num max data. + var totalDataCount = 0; + for (var i = 0; i < rsBlocks.length; i++) { + totalDataCount += rsBlocks[i].dataCount; + } + + if (buffer.getLengthInBits() > totalDataCount * 8) { + throw new Error("code length overflow. (" + + buffer.getLengthInBits() + + ">" + + totalDataCount * 8 + + ")"); + } + + // end code + if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) { + buffer.put(0, 4); + } + + // padding + while (buffer.getLengthInBits() % 8 != 0) { + buffer.putBit(false); + } + + // padding + while (true) { + + if (buffer.getLengthInBits() >= totalDataCount * 8) { + break; + } + buffer.put(QRCode.PAD0, 8); + + if (buffer.getLengthInBits() >= totalDataCount * 8) { + break; + } + buffer.put(QRCode.PAD1, 8); + } + + return QRCode.createBytes(buffer, rsBlocks); +} + +QRCode.createBytes = function(buffer, rsBlocks) { + + var offset = 0; + + var maxDcCount = 0; + var maxEcCount = 0; + + var dcdata = new Array(rsBlocks.length); + var ecdata = new Array(rsBlocks.length); + + for (var r = 0; r < rsBlocks.length; r++) { + + var dcCount = rsBlocks[r].dataCount; + var ecCount = rsBlocks[r].totalCount - dcCount; + + maxDcCount = Math.max(maxDcCount, dcCount); + maxEcCount = Math.max(maxEcCount, ecCount); + + dcdata[r] = new Array(dcCount); + + for (var i = 0; i < dcdata[r].length; i++) { + dcdata[r][i] = 0xff & buffer.buffer[i + offset]; + } + offset += dcCount; + + var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount); + var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1); + + var modPoly = rawPoly.mod(rsPoly); + ecdata[r] = new Array(rsPoly.getLength() - 1); + for (var i = 0; i < ecdata[r].length; i++) { + var modIndex = i + modPoly.getLength() - ecdata[r].length; + ecdata[r][i] = (modIndex >= 0)? modPoly.get(modIndex) : 0; + } + + } + + var totalCodeCount = 0; + for (var i = 0; i < rsBlocks.length; i++) { + totalCodeCount += rsBlocks[i].totalCount; + } + + var data = new Array(totalCodeCount); + var index = 0; + + for (var i = 0; i < maxDcCount; i++) { + for (var r = 0; r < rsBlocks.length; r++) { + if (i < dcdata[r].length) { + data[index++] = dcdata[r][i]; + } + } + } + + for (var i = 0; i < maxEcCount; i++) { + for (var r = 0; r < rsBlocks.length; r++) { + if (i < ecdata[r].length) { + data[index++] = ecdata[r][i]; + } + } + } + + return data; + +} + +//--------------------------------------------------------------------- +// QRMode +//--------------------------------------------------------------------- + +var QRMode = { + MODE_NUMBER : 1 << 0, + MODE_ALPHA_NUM : 1 << 1, + MODE_8BIT_BYTE : 1 << 2, + MODE_KANJI : 1 << 3 +}; + +//--------------------------------------------------------------------- +// QRErrorCorrectLevel +//--------------------------------------------------------------------- + +var QRErrorCorrectLevel = { + L : 1, + M : 0, + Q : 3, + H : 2 +}; + +//--------------------------------------------------------------------- +// QRMaskPattern +//--------------------------------------------------------------------- + +var QRMaskPattern = { + PATTERN000 : 0, + PATTERN001 : 1, + PATTERN010 : 2, + PATTERN011 : 3, + PATTERN100 : 4, + PATTERN101 : 5, + PATTERN110 : 6, + PATTERN111 : 7 +}; + +//--------------------------------------------------------------------- +// QRUtil +//--------------------------------------------------------------------- + +var QRUtil = { + + PATTERN_POSITION_TABLE : [ + [], + [6, 18], + [6, 22], + [6, 26], + [6, 30], + [6, 34], + [6, 22, 38], + [6, 24, 42], + [6, 26, 46], + [6, 28, 50], + [6, 30, 54], + [6, 32, 58], + [6, 34, 62], + [6, 26, 46, 66], + [6, 26, 48, 70], + [6, 26, 50, 74], + [6, 30, 54, 78], + [6, 30, 56, 82], + [6, 30, 58, 86], + [6, 34, 62, 90], + [6, 28, 50, 72, 94], + [6, 26, 50, 74, 98], + [6, 30, 54, 78, 102], + [6, 28, 54, 80, 106], + [6, 32, 58, 84, 110], + [6, 30, 58, 86, 114], + [6, 34, 62, 90, 118], + [6, 26, 50, 74, 98, 122], + [6, 30, 54, 78, 102, 126], + [6, 26, 52, 78, 104, 130], + [6, 30, 56, 82, 108, 134], + [6, 34, 60, 86, 112, 138], + [6, 30, 58, 86, 114, 142], + [6, 34, 62, 90, 118, 146], + [6, 30, 54, 78, 102, 126, 150], + [6, 24, 50, 76, 102, 128, 154], + [6, 28, 54, 80, 106, 132, 158], + [6, 32, 58, 84, 110, 136, 162], + [6, 26, 54, 82, 110, 138, 166], + [6, 30, 58, 86, 114, 142, 170] + ], + + G15 : (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0), + G18 : (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0), + G15_MASK : (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1), + + getBCHTypeInfo : function(data) { + var d = data << 10; + while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) { + d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) ) ); + } + return ( (data << 10) | d) ^ QRUtil.G15_MASK; + }, + + getBCHTypeNumber : function(data) { + var d = data << 12; + while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) { + d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) ) ); + } + return (data << 12) | d; + }, + + getBCHDigit : function(data) { + + var digit = 0; + + while (data != 0) { + digit++; + data >>>= 1; + } + + return digit; + }, + + getPatternPosition : function(typeNumber) { + return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1]; + }, + + getMask : function(maskPattern, i, j) { + + switch (maskPattern) { + + case QRMaskPattern.PATTERN000 : return (i + j) % 2 == 0; + case QRMaskPattern.PATTERN001 : return i % 2 == 0; + case QRMaskPattern.PATTERN010 : return j % 3 == 0; + case QRMaskPattern.PATTERN011 : return (i + j) % 3 == 0; + case QRMaskPattern.PATTERN100 : return (Math.floor(i / 2) + Math.floor(j / 3) ) % 2 == 0; + case QRMaskPattern.PATTERN101 : return (i * j) % 2 + (i * j) % 3 == 0; + case QRMaskPattern.PATTERN110 : return ( (i * j) % 2 + (i * j) % 3) % 2 == 0; + case QRMaskPattern.PATTERN111 : return ( (i * j) % 3 + (i + j) % 2) % 2 == 0; + + default : + throw new Error("bad maskPattern:" + maskPattern); + } + }, + + getErrorCorrectPolynomial : function(errorCorrectLength) { + + var a = new QRPolynomial([1], 0); + + for (var i = 0; i < errorCorrectLength; i++) { + a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0) ); + } + + return a; + }, + + getLengthInBits : function(mode, type) { + + if (1 <= type && type < 10) { + + // 1 - 9 + + switch(mode) { + case QRMode.MODE_NUMBER : return 10; + case QRMode.MODE_ALPHA_NUM : return 9; + case QRMode.MODE_8BIT_BYTE : return 8; + case QRMode.MODE_KANJI : return 8; + default : + throw new Error("mode:" + mode); + } + + } else if (type < 27) { + + // 10 - 26 + + switch(mode) { + case QRMode.MODE_NUMBER : return 12; + case QRMode.MODE_ALPHA_NUM : return 11; + case QRMode.MODE_8BIT_BYTE : return 16; + case QRMode.MODE_KANJI : return 10; + default : + throw new Error("mode:" + mode); + } + + } else if (type < 41) { + + // 27 - 40 + + switch(mode) { + case QRMode.MODE_NUMBER : return 14; + case QRMode.MODE_ALPHA_NUM : return 13; + case QRMode.MODE_8BIT_BYTE : return 16; + case QRMode.MODE_KANJI : return 12; + default : + throw new Error("mode:" + mode); + } + + } else { + throw new Error("type:" + type); + } + }, + + getLostPoint : function(qrCode) { + + var moduleCount = qrCode.getModuleCount(); + + var lostPoint = 0; + + // LEVEL1 + + for (var row = 0; row < moduleCount; row++) { + + for (var col = 0; col < moduleCount; col++) { + + var sameCount = 0; + var dark = qrCode.isDark(row, col); + + for (var r = -1; r <= 1; r++) { + + if (row + r < 0 || moduleCount <= row + r) { + continue; + } + + for (var c = -1; c <= 1; c++) { + + if (col + c < 0 || moduleCount <= col + c) { + continue; + } + + if (r == 0 && c == 0) { + continue; + } + + if (dark == qrCode.isDark(row + r, col + c) ) { + sameCount++; + } + } + } + + if (sameCount > 5) { + lostPoint += (3 + sameCount - 5); + } + } + } + + // LEVEL2 + + for (var row = 0; row < moduleCount - 1; row++) { + for (var col = 0; col < moduleCount - 1; col++) { + var count = 0; + if (qrCode.isDark(row, col ) ) count++; + if (qrCode.isDark(row + 1, col ) ) count++; + if (qrCode.isDark(row, col + 1) ) count++; + if (qrCode.isDark(row + 1, col + 1) ) count++; + if (count == 0 || count == 4) { + lostPoint += 3; + } + } + } + + // LEVEL3 + + for (var row = 0; row < moduleCount; row++) { + for (var col = 0; col < moduleCount - 6; col++) { + if (qrCode.isDark(row, col) + && !qrCode.isDark(row, col + 1) + && qrCode.isDark(row, col + 2) + && qrCode.isDark(row, col + 3) + && qrCode.isDark(row, col + 4) + && !qrCode.isDark(row, col + 5) + && qrCode.isDark(row, col + 6) ) { + lostPoint += 40; + } + } + } + + for (var col = 0; col < moduleCount; col++) { + for (var row = 0; row < moduleCount - 6; row++) { + if (qrCode.isDark(row, col) + && !qrCode.isDark(row + 1, col) + && qrCode.isDark(row + 2, col) + && qrCode.isDark(row + 3, col) + && qrCode.isDark(row + 4, col) + && !qrCode.isDark(row + 5, col) + && qrCode.isDark(row + 6, col) ) { + lostPoint += 40; + } + } + } + + // LEVEL4 + + var darkCount = 0; + + for (var col = 0; col < moduleCount; col++) { + for (var row = 0; row < moduleCount; row++) { + if (qrCode.isDark(row, col) ) { + darkCount++; + } + } + } + + var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5; + lostPoint += ratio * 10; + + return lostPoint; + } + +}; + + +//--------------------------------------------------------------------- +// QRMath +//--------------------------------------------------------------------- + +var QRMath = { + + glog : function(n) { + + if (n < 1) { + throw new Error("glog(" + n + ")"); + } + + return QRMath.LOG_TABLE[n]; + }, + + gexp : function(n) { + + while (n < 0) { + n += 255; + } + + while (n >= 256) { + n -= 255; + } + + return QRMath.EXP_TABLE[n]; + }, + + EXP_TABLE : new Array(256), + + LOG_TABLE : new Array(256) + +}; + +for (var i = 0; i < 8; i++) { + QRMath.EXP_TABLE[i] = 1 << i; +} +for (var i = 8; i < 256; i++) { + QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] + ^ QRMath.EXP_TABLE[i - 5] + ^ QRMath.EXP_TABLE[i - 6] + ^ QRMath.EXP_TABLE[i - 8]; +} +for (var i = 0; i < 255; i++) { + QRMath.LOG_TABLE[QRMath.EXP_TABLE[i] ] = i; +} + +//--------------------------------------------------------------------- +// QRPolynomial +//--------------------------------------------------------------------- + +function QRPolynomial(num, shift) { + + if (num.length == undefined) { + throw new Error(num.length + "/" + shift); + } + + var offset = 0; + + while (offset < num.length && num[offset] == 0) { + offset++; + } + + this.num = new Array(num.length - offset + shift); + for (var i = 0; i < num.length - offset; i++) { + this.num[i] = num[i + offset]; + } +} + +QRPolynomial.prototype = { + + get : function(index) { + return this.num[index]; + }, + + getLength : function() { + return this.num.length; + }, + + multiply : function(e) { + + var num = new Array(this.getLength() + e.getLength() - 1); + + for (var i = 0; i < this.getLength(); i++) { + for (var j = 0; j < e.getLength(); j++) { + num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i) ) + QRMath.glog(e.get(j) ) ); + } + } + + return new QRPolynomial(num, 0); + }, + + mod : function(e) { + + if (this.getLength() - e.getLength() < 0) { + return this; + } + + var ratio = QRMath.glog(this.get(0) ) - QRMath.glog(e.get(0) ); + + var num = new Array(this.getLength() ); + + for (var i = 0; i < this.getLength(); i++) { + num[i] = this.get(i); + } + + for (var i = 0; i < e.getLength(); i++) { + num[i] ^= QRMath.gexp(QRMath.glog(e.get(i) ) + ratio); + } + + // recursive call + return new QRPolynomial(num, 0).mod(e); + } +}; + +//--------------------------------------------------------------------- +// QRRSBlock +//--------------------------------------------------------------------- + +function QRRSBlock(totalCount, dataCount) { + this.totalCount = totalCount; + this.dataCount = dataCount; +} + +QRRSBlock.RS_BLOCK_TABLE = [ + + // L + // M + // Q + // H + + // 1 + [1, 26, 19], + [1, 26, 16], + [1, 26, 13], + [1, 26, 9], + + // 2 + [1, 44, 34], + [1, 44, 28], + [1, 44, 22], + [1, 44, 16], + + // 3 + [1, 70, 55], + [1, 70, 44], + [2, 35, 17], + [2, 35, 13], + + // 4 + [1, 100, 80], + [2, 50, 32], + [2, 50, 24], + [4, 25, 9], + + // 5 + [1, 134, 108], + [2, 67, 43], + [2, 33, 15, 2, 34, 16], + [2, 33, 11, 2, 34, 12], + + // 6 + [2, 86, 68], + [4, 43, 27], + [4, 43, 19], + [4, 43, 15], + + // 7 + [2, 98, 78], + [4, 49, 31], + [2, 32, 14, 4, 33, 15], + [4, 39, 13, 1, 40, 14], + + // 8 + [2, 121, 97], + [2, 60, 38, 2, 61, 39], + [4, 40, 18, 2, 41, 19], + [4, 40, 14, 2, 41, 15], + + // 9 + [2, 146, 116], + [3, 58, 36, 2, 59, 37], + [4, 36, 16, 4, 37, 17], + [4, 36, 12, 4, 37, 13], + + // 10 + [2, 86, 68, 2, 87, 69], + [4, 69, 43, 1, 70, 44], + [6, 43, 19, 2, 44, 20], + [6, 43, 15, 2, 44, 16], + + // 11 + [4, 101, 81], + [1, 80, 50, 4, 81, 51], + [4, 50, 22, 4, 51, 23], + [3, 36, 12, 8, 37, 13], + + // 12 + [2, 116, 92, 2, 117, 93], + [6, 58, 36, 2, 59, 37], + [4, 46, 20, 6, 47, 21], + [7, 42, 14, 4, 43, 15], + + // 13 + [4, 133, 107], + [8, 59, 37, 1, 60, 38], + [8, 44, 20, 4, 45, 21], + [12, 33, 11, 4, 34, 12], + + // 14 + [3, 145, 115, 1, 146, 116], + [4, 64, 40, 5, 65, 41], + [11, 36, 16, 5, 37, 17], + [11, 36, 12, 5, 37, 13], + + // 15 + [5, 109, 87, 1, 110, 88], + [5, 65, 41, 5, 66, 42], + [5, 54, 24, 7, 55, 25], + [11, 36, 12], + + // 16 + [5, 122, 98, 1, 123, 99], + [7, 73, 45, 3, 74, 46], + [15, 43, 19, 2, 44, 20], + [3, 45, 15, 13, 46, 16], + + // 17 + [1, 135, 107, 5, 136, 108], + [10, 74, 46, 1, 75, 47], + [1, 50, 22, 15, 51, 23], + [2, 42, 14, 17, 43, 15], + + // 18 + [5, 150, 120, 1, 151, 121], + [9, 69, 43, 4, 70, 44], + [17, 50, 22, 1, 51, 23], + [2, 42, 14, 19, 43, 15], + + // 19 + [3, 141, 113, 4, 142, 114], + [3, 70, 44, 11, 71, 45], + [17, 47, 21, 4, 48, 22], + [9, 39, 13, 16, 40, 14], + + // 20 + [3, 135, 107, 5, 136, 108], + [3, 67, 41, 13, 68, 42], + [15, 54, 24, 5, 55, 25], + [15, 43, 15, 10, 44, 16], + + // 21 + [4, 144, 116, 4, 145, 117], + [17, 68, 42], + [17, 50, 22, 6, 51, 23], + [19, 46, 16, 6, 47, 17], + + // 22 + [2, 139, 111, 7, 140, 112], + [17, 74, 46], + [7, 54, 24, 16, 55, 25], + [34, 37, 13], + + // 23 + [4, 151, 121, 5, 152, 122], + [4, 75, 47, 14, 76, 48], + [11, 54, 24, 14, 55, 25], + [16, 45, 15, 14, 46, 16], + + // 24 + [6, 147, 117, 4, 148, 118], + [6, 73, 45, 14, 74, 46], + [11, 54, 24, 16, 55, 25], + [30, 46, 16, 2, 47, 17], + + // 25 + [8, 132, 106, 4, 133, 107], + [8, 75, 47, 13, 76, 48], + [7, 54, 24, 22, 55, 25], + [22, 45, 15, 13, 46, 16], + + // 26 + [10, 142, 114, 2, 143, 115], + [19, 74, 46, 4, 75, 47], + [28, 50, 22, 6, 51, 23], + [33, 46, 16, 4, 47, 17], + + // 27 + [8, 152, 122, 4, 153, 123], + [22, 73, 45, 3, 74, 46], + [8, 53, 23, 26, 54, 24], + [12, 45, 15, 28, 46, 16], + + // 28 + [3, 147, 117, 10, 148, 118], + [3, 73, 45, 23, 74, 46], + [4, 54, 24, 31, 55, 25], + [11, 45, 15, 31, 46, 16], + + // 29 + [7, 146, 116, 7, 147, 117], + [21, 73, 45, 7, 74, 46], + [1, 53, 23, 37, 54, 24], + [19, 45, 15, 26, 46, 16], + + // 30 + [5, 145, 115, 10, 146, 116], + [19, 75, 47, 10, 76, 48], + [15, 54, 24, 25, 55, 25], + [23, 45, 15, 25, 46, 16], + + // 31 + [13, 145, 115, 3, 146, 116], + [2, 74, 46, 29, 75, 47], + [42, 54, 24, 1, 55, 25], + [23, 45, 15, 28, 46, 16], + + // 32 + [17, 145, 115], + [10, 74, 46, 23, 75, 47], + [10, 54, 24, 35, 55, 25], + [19, 45, 15, 35, 46, 16], + + // 33 + [17, 145, 115, 1, 146, 116], + [14, 74, 46, 21, 75, 47], + [29, 54, 24, 19, 55, 25], + [11, 45, 15, 46, 46, 16], + + // 34 + [13, 145, 115, 6, 146, 116], + [14, 74, 46, 23, 75, 47], + [44, 54, 24, 7, 55, 25], + [59, 46, 16, 1, 47, 17], + + // 35 + [12, 151, 121, 7, 152, 122], + [12, 75, 47, 26, 76, 48], + [39, 54, 24, 14, 55, 25], + [22, 45, 15, 41, 46, 16], + + // 36 + [6, 151, 121, 14, 152, 122], + [6, 75, 47, 34, 76, 48], + [46, 54, 24, 10, 55, 25], + [2, 45, 15, 64, 46, 16], + + // 37 + [17, 152, 122, 4, 153, 123], + [29, 74, 46, 14, 75, 47], + [49, 54, 24, 10, 55, 25], + [24, 45, 15, 46, 46, 16], + + // 38 + [4, 152, 122, 18, 153, 123], + [13, 74, 46, 32, 75, 47], + [48, 54, 24, 14, 55, 25], + [42, 45, 15, 32, 46, 16], + + // 39 + [20, 147, 117, 4, 148, 118], + [40, 75, 47, 7, 76, 48], + [43, 54, 24, 22, 55, 25], + [10, 45, 15, 67, 46, 16], + + // 40 + [19, 148, 118, 6, 149, 119], + [18, 75, 47, 31, 76, 48], + [34, 54, 24, 34, 55, 25], + [20, 45, 15, 61, 46, 16] +]; + +QRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) { + + var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel); + + if (rsBlock == undefined) { + throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel); + } + + var length = rsBlock.length / 3; + + var list = new Array(); + + for (var i = 0; i < length; i++) { + + var count = rsBlock[i * 3 + 0]; + var totalCount = rsBlock[i * 3 + 1]; + var dataCount = rsBlock[i * 3 + 2]; + + for (var j = 0; j < count; j++) { + list.push(new QRRSBlock(totalCount, dataCount) ); + } + } + + return list; +} + +QRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) { + + switch(errorCorrectLevel) { + case QRErrorCorrectLevel.L : + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0]; + case QRErrorCorrectLevel.M : + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1]; + case QRErrorCorrectLevel.Q : + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2]; + case QRErrorCorrectLevel.H : + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3]; + default : + return undefined; + } +} + +//--------------------------------------------------------------------- +// QRBitBuffer +//--------------------------------------------------------------------- + +function QRBitBuffer() { + this.buffer = new Array(); + this.length = 0; +} + +QRBitBuffer.prototype = { + + get : function(index) { + var bufIndex = Math.floor(index / 8); + return ( (this.buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1; + }, + + put : function(num, length) { + for (var i = 0; i < length; i++) { + this.putBit( ( (num >>> (length - i - 1) ) & 1) == 1); + } + }, + + getLengthInBits : function() { + return this.length; + }, + + putBit : function(bit) { + + var bufIndex = Math.floor(this.length / 8); + if (this.buffer.length <= bufIndex) { + this.buffer.push(0); + } + + if (bit) { + this.buffer[bufIndex] |= (0x80 >>> (this.length % 8) ); + } + + this.length++; + } +}; diff --git a/public/jquery.storage.js/.gitattributes b/public/jquery.storage.js/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/public/jquery.storage.js/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/public/jquery.storage.js/.gitignore b/public/jquery.storage.js/.gitignore new file mode 100644 index 0000000..b9d6bd9 --- /dev/null +++ b/public/jquery.storage.js/.gitignore @@ -0,0 +1,215 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg diff --git a/public/jquery.storage.js/jquery.storage.js b/public/jquery.storage.js/jquery.storage.js new file mode 100644 index 0000000..4894610 --- /dev/null +++ b/public/jquery.storage.js/jquery.storage.js @@ -0,0 +1,82 @@ +/*! + * jquery.storage.js 0.0.3 - https://github.com/yckart/jquery.storage.js + * The client-side storage for every browser, on any device. + * + * Copyright (c) 2012 Yannick Albert (http://yckart.com) + * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php). + * 2013/02/10 + **/ +;(function($, window, document) { + 'use strict'; + + $.map(['localStorage', 'sessionStorage'], function( method ) { + var defaults = { + cookiePrefix : 'fallback:' + method + ':', + cookieOptions : { + path : '/', + domain : document.domain, + expires : ('localStorage' === method) ? { expires: 365 } : undefined + } + }; + + try { + $.support[method] = method in window && window[method] !== null; + } catch (e) { + $.support[method] = false; + } + + $[method] = function(key, value) { + var options = $.extend({}, defaults, $[method].options); + + this.getItem = function( key ) { + var returns = function(key){ + return JSON.parse($.support[method] ? window[method].getItem(key) : $.cookie(options.cookiePrefix + key)); + }; + if(typeof key === 'string') return returns(key); + + var arr = [], + i = key.length; + while(i--) arr[i] = returns(key[i]); + return arr; + }; + + this.setItem = function( key, value ) { + value = JSON.stringify(value); + return $.support[method] ? window[method].setItem(key, value) : $.cookie(options.cookiePrefix + key, value, options.cookieOptions); + }; + + this.removeItem = function( key ) { + return $.support[method] ? window[method].removeItem(key) : $.cookie(options.cookiePrefix + key, null, $.extend(options.cookieOptions, { + expires: -1 + })); + }; + + this.clear = function() { + if($.support[method]) { + return window[method].clear(); + } else { + var reg = new RegExp('^' + options.cookiePrefix, ''), + opts = $.extend(options.cookieOptions, { + expires: -1 + }); + + if(document.cookie && document.cookie !== ''){ + $.map(document.cookie.split(';'), function( cookie ){ + if(reg.test(cookie = $.trim(cookie))) { + $.cookie( cookie.substr(0,cookie.indexOf('=')), null, opts); + } + }); + } + } + }; + + if (typeof key !== "undefined") { + return typeof value !== "undefined" ? ( value === null ? this.removeItem(key) : this.setItem(key, value) ) : this.getItem(key); + } + + return this; + }; + + $[method].options = defaults; + }); +}(jQuery, window, document)); \ No newline at end of file diff --git a/public/jquery.storage.js/localstorage.jquery.json b/public/jquery.storage.js/localstorage.jquery.json new file mode 100644 index 0000000..9eb4402 --- /dev/null +++ b/public/jquery.storage.js/localstorage.jquery.json @@ -0,0 +1,31 @@ +{ + "name": "localstorage", + "title": "jQuery Localstorage", + "description": "The client-side storage for every browser, on any device.", + "keywords": [ + "cookie", + "storage", + "localstorage", + "save", + "yckart", + "yannick", + "albert" + ], + "version": "0.0.3", + "author": { + "name": "Yannick Albert", + "email": "mail@yckart.com", + "url": "https://github.com/yckart" + }, + "licenses": [{ + "type": "MIT", + "url": "http://yckart.com/mit/" + }], + "homepage": "http://yckart.github.com/jquery.storage.js", + "demo": "http://yckart.github.com/jquery.storage.js", + "docs": "https://github.com/yckart/jquery.storage.js", + "bugs": "https://github.com/yckart/jquery.storage.js/issues", + "dependencies": { + "jquery": ">=1.6.4" + } +} \ No newline at end of file diff --git a/public/jquery.storage.js/sessionstorage.jquery.json b/public/jquery.storage.js/sessionstorage.jquery.json new file mode 100644 index 0000000..5817b37 --- /dev/null +++ b/public/jquery.storage.js/sessionstorage.jquery.json @@ -0,0 +1,31 @@ +{ + "name": "sessionstorage", + "title": "jQuery Sessionstorage", + "description": "The client-side storage for every browser, on any device.", + "keywords": [ + "cookie", + "storage", + "localstorage", + "save", + "yckart", + "yannick", + "albert" + ], + "version": "0.0.3", + "author": { + "name": "Yannick Albert", + "email": "mail@yckart.com", + "url": "https://github.com/yckart" + }, + "licenses": [{ + "type": "MIT", + "url": "http://yckart.com/mit/" + }], + "homepage": "http://yckart.github.com/jquery.storage.js", + "demo": "http://yckart.github.com/jquery.storage.js", + "docs": "https://github.com/yckart/jquery.storage.js", + "bugs": "https://github.com/yckart/jquery.storage.js/issues", + "dependencies": { + "jquery": ">=1.6.4" + } +} \ No newline at end of file diff --git a/public/jquery.storage.js/storage.jquery.json b/public/jquery.storage.js/storage.jquery.json new file mode 100644 index 0000000..296742c --- /dev/null +++ b/public/jquery.storage.js/storage.jquery.json @@ -0,0 +1,31 @@ +{ + "name": "storage", + "title": "jQuery Storage", + "description": "The client-side storage for every browser, on any device.", + "keywords": [ + "cookie", + "storage", + "localstorage", + "save", + "yckart", + "yannick", + "albert" + ], + "version": "0.0.3", + "author": { + "name": "Yannick Albert", + "email": "mail@yckart.com", + "url": "https://github.com/yckart" + }, + "licenses": [{ + "type": "MIT", + "url": "http://yckart.com/mit/" + }], + "homepage": "http://yckart.github.com/jquery.storage.js", + "demo": "http://yckart.github.com/jquery.storage.js", + "docs": "https://github.com/yckart/jquery.storage.js", + "bugs": "https://github.com/yckart/jquery.storage.js/issues", + "dependencies": { + "jquery": ">=1.6.4" + } +} \ No newline at end of file diff --git a/public/manifest.json b/public/manifest.json new file mode 100644 index 0000000..e6a1acb --- /dev/null +++ b/public/manifest.json @@ -0,0 +1,56 @@ +{ + "name": "QiFi - WiFi QR Code Generator", + "short_name": "QiFi", + "theme_color": "#101010", + "background_color": "#101010", + "description": "WiFi no QR", + "display": "standalone", + "orientation": "portrait", + "start_url": "/", + "Scope": "/", + "icons": [ + { + "src": "images/icons/icon-72x72.png", + "sizes": "72x72", + "type": "image/png" + }, + { + "src": "images/icons/icon-96x96.png", + "sizes": "96x96", + "type": "image/png" + }, + { + "src": "images/icons/icon-128x128.png", + "sizes": "128x128", + "type": "image/png" + }, + { + "src": "images/icons/icon-144x144.png", + "sizes": "144x144", + "type": "image/png" + }, + { + "src": "images/icons/icon-152x152.png", + "sizes": "152x152", + "type": "image/png" + }, + { + "src": "images/icons/icon-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "images/icons/icon-384x384.png", + "sizes": "384x384", + "type": "image/png" + }, + { + "src": "images/icons/icon-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "splash_pages": null, + "version": "1.1.39", + "author": "Ivan Carlos" +} diff --git a/public/print.css b/public/print.css new file mode 100644 index 0000000..99103cd --- /dev/null +++ b/public/print.css @@ -0,0 +1,17 @@ +.navbar, +#generator .page-header, +#about, +#history, +#form, +#github, +#contact, +.footer { + display: none; +} + +#showssid, +#showkey { + display: block; + word-wrap: break-word; + font-family: Consolas, Menlo, "DejaVu Sans Mono", monospace; +} diff --git a/public/qifi-small.png b/public/qifi-small.png new file mode 100644 index 0000000..209e4d0 Binary files /dev/null and b/public/qifi-small.png differ diff --git a/public/qifi.png b/public/qifi.png new file mode 100644 index 0000000..c03cb25 Binary files /dev/null and b/public/qifi.png differ diff --git a/public/qifi.svg b/public/qifi.svg new file mode 100644 index 0000000..274246d --- /dev/null +++ b/public/qifi.svg @@ -0,0 +1,93 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + QiFi + + diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..c2a49f4 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Allow: / diff --git a/public/style.css b/public/style.css new file mode 100644 index 0000000..4daf98f --- /dev/null +++ b/public/style.css @@ -0,0 +1,304 @@ +:root { + --primary-color: #0070f3; + --primary-hover: #0366d6; + --bg-gradient-start: #f5f7fa; + --bg-gradient-end: #c3cfe2; + --card-bg: #ffffff; + --text-main: #333; + --text-muted: #666; + --border-color: #eaeaea; + --input-bg: #f9f9f9; + --radius: 8px; +} + +body { + font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; + margin: 0; + min-height: 100vh; + background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%); + color: var(--text-main); + display: flex; + justify-content: center; + align-items: flex-start; + padding: 40px 20px; + box-sizing: border-box; +} + +.container { + width: 100%; + max-width: 480px; +} + +.card { + background: var(--card-bg); + padding: 40px; + border-radius: 16px; + box-shadow: 0 20px 40px rgba(0,0,0,0.1); +} + +.page-header { + text-align: center; + margin-bottom: 30px; +} + +h1#title { + margin: 0 0 10px; + font-size: 1.8rem; + font-weight: 700; +} + +.subtitle { + font-size: 0.95rem; + color: var(--text-muted); + line-height: 1.5; + margin: 0; +} + +.form-group { + margin-bottom: 20px; +} + +label { + display: block; + margin-bottom: 8px; + font-weight: 500; + font-size: 0.9rem; +} + +.input-wrapper { + position: relative; + display: flex; + align-items: center; +} + +.input-icon { + position: absolute; + left: 12px; + width: 20px; + height: 20px; + color: var(--text-muted); + pointer-events: none; +} + +input[type="text"], +input[type="password"], +select { + width: 100%; + padding: 12px 12px 12px 40px; /* Space for icon */ + border: 1px solid var(--border-color); + border-radius: var(--radius); + background: var(--input-bg); + font-size: 1rem; + color: var(--text-main); + transition: all 0.2s; + box-sizing: border-box; + -webkit-appearance: none; +} + +select { + padding-left: 12px; +} + +/* Adjust padding if no icon wrapper used for select */ +.input-wrapper select { + padding-right: 35px; +} + +.select-arrow { + position: absolute; + right: 12px; + pointer-events: none; + color: var(--text-muted); +} + +input:focus, select:focus { + outline: none; + border-color: var(--primary-color); + background: #fff; + box-shadow: 0 0 0 3px rgba(0,112,243,0.1); +} + +.icon-btn { + background: none; + border: none; + position: absolute; + right: 8px; + cursor: pointer; + color: var(--text-muted); + display: flex; + align-items: center; + padding: 4px; +} + +.checkbox-group { + display: flex; + align-items: center; + gap: 8px; +} + +.checkbox-group input { + width: 16px; + height: 16px; + margin: 0; +} + +.checkbox-group label { + margin: 0; + font-weight: 400; +} + +.button-group { + display: flex; + flex-direction: column; + gap: 10px; + margin-top: 30px; +} + +.btn { + display: block; + width: 100%; + padding: 12px; + border-radius: var(--radius); + font-size: 1rem; + font-weight: 600; + text-align: center; + cursor: pointer; + border: none; + transition: all 0.2s; + text-decoration: none; + box-sizing: border-box; +} + +.btn-primary { + background: var(--primary-color); + color: white; +} + +.btn-primary:hover { + background: var(--primary-hover); +} + +.btn-secondary { + background: #e2e8f0; + color: #4a5568; +} + +.btn-secondary:hover { + background: #cbd5e0; +} + +.btn-outline { + background: transparent; + border: 1px solid var(--border-color); + color: var(--text-muted); + font-weight: 500; +} + +.btn-outline:hover { + border-color: var(--text-muted); + color: var(--text-main); +} + +#result-area { + margin-top: 40px; + text-align: center; +} + +#showssid, #showkey { + display: none; /* hidden by default */ + margin: 5px 0; +} + +#showssid { font-size: 1.1rem; } +#showkey { font-size: 0.9rem; font-weight: 400; color: var(--text-muted); } + +#qrcode { + margin-top: 20px; +} + +#qrcode canvas { + border-radius: 8px; + box-shadow: 0 4px 12px rgba(0,0,0,0.1); +} + +/* History Dropdown Styles */ +.history-dropdown { + margin-bottom: 20px; + text-align: right; + position: relative; +} + +.history-btn { + background: none; + border: none; + font-size: 0.85rem; + color: var(--primary-color); + cursor: pointer; + font-weight: 500; +} + +.dropdown-menu { + position: absolute; + right: 0; + top: 100%; + background: white; + border: 1px solid var(--border-color); + border-radius: 8px; + list-style: none; + padding: 0; + margin: 5px 0 0; + box-shadow: 0 4px 12px rgba(0,0,0,0.1); + width: 200px; + z-index: 10; + display: none; +} + +.dropdown-menu li { + border-bottom: 1px solid #f0f0f0; +} + +.dropdown-menu li:last-child { + border-bottom: none; +} + +.dropdown-menu a { + display: block; + padding: 10px 15px; + text-decoration: none; + color: var(--text-main); + font-size: 0.9rem; + text-align: left; +} + +.dropdown-menu a:hover { + background: #f9f9f9; +} + +/* Hide extra buttons initially */ +#save, #export, #print { + display: none; +} + +footer { + margin-top: 30px; + text-align: center; + font-size: 0.8rem; + color: #999; +} + +footer a { + color: #999; + text-decoration: none; +} +footer a:hover { + text-decoration: underline; +} + +@media print { + body { background: white; padding: 0; } + .card { box-shadow: none; padding: 0; } + .page-header, #form, #history-drop, footer, .btn { display: none !important; } + #result-area { display: block !important; margin: 0; } + #qrcode canvas { box-shadow: none; } + #showssid, #showkey { display: block !important; color: black; } +} diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 0000000..9640a59 --- /dev/null +++ b/public/sw.js @@ -0,0 +1,126 @@ +var CACHE_VERSION = 1; +var CURRENT_CACHES = { + prefetch: 'prefetch-cache-v' + CACHE_VERSION +}; + +self.addEventListener('install', function(event) { + var now = Date.now(); + // Here are all the current files QiFi caches while Service Worker installation. + // Add files as needed and change CACHE_VERSION at the top of the file. + var urlsToPrefetch = [ + '/', + '/index.html', + '/style.css', + '/style-responsive.css', + '/bootstrap/dist/css/bootstrap.css', + '/qifi.png', + '/qifi-small.png', + '/manifest.json', + '/jquery/jquery-3.3.1.min.js', + '/bootstrap/dist/js/bootstrap.min.js', + '/jquery-qrcode/jquery.qrcode.min.js', + '/jquery.storage.js/jquery.storage.js', + '/print.css', + '/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2', + '/bootstrap/dist/fonts/glyphicons-halflings-regular.eot', + '/bootstrap/dist/fonts/glyphicons-halflings-regular.svg', + '/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf', + '/bootstrap/dist/fonts/glyphicons-halflings-regular.woff', + '/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2' + ]; + + // All of these logging statements should be visible via the "Inspect" interface + // for the relevant SW accessed via chrome://serviceworker-internals + console.log('[Service Worker] Handling install event. Resources to prefetch:', urlsToPrefetch); + + event.waitUntil( + caches.open(CURRENT_CACHES.prefetch).then(function(cache) { + var cachePromises = urlsToPrefetch.map(function(urlToPrefetch) { + // This constructs a new URL object using the service worker's script location as the base + // for relative URLs. + var url = new URL(urlToPrefetch, location.href); + // Append a cache-bust=TIMESTAMP URL parameter to each URL's query string. + // This is particularly important when precaching resources that are later used in the + // fetch handler as responses directly, without consulting the network (i.e. cache-first). + // If we were to get back a response from the HTTP browser cache for this precaching request + // then that stale response would be used indefinitely, or at least until the next time + // the service worker script changes triggering the install flow. + url.search += (url.search ? '&' : '?') + 'cache-bust=' + now; + // It's very important to use {mode: 'no-cors'} if there is any chance that + // the resources being fetched are served off of a server that doesn't support + // CORS (http://en.wikipedia.org/wiki/Cross-origin_resource_sharing). + // The drawback of hardcoding {mode: 'no-cors'} is that the response from all + // cross-origin hosts will always be opaque + // (https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#cross-origin-resources) + // and it is not possible to determine whether an opaque response represents a success or failure + // (https://github.com/whatwg/fetch/issues/14). + var request = new Request(url, {mode: 'no-cors'}); + return fetch(request).then(function(response) { + if (response.status >= 400) { + throw new Error('request for ' + urlToPrefetch + + ' failed with status ' + response.statusText); + } + // Use the original URL without the cache-busting parameter as the key for cache.put(). + return cache.put(urlToPrefetch, response); + }).catch(function(error) { + console.error('[Service Worker] Not caching ' + urlToPrefetch + ' due to ' + error); + }); + }); + return Promise.all(cachePromises).then(function() { + console.log('[Service Worker] Pre-fetching complete.'); + }); + }).catch(function(error) { + console.error('[Service Worker] Pre-fetching failed:', error); + }) + ); +}); + +self.addEventListener('activate', function(event) { + // Delete all caches that aren't named in CURRENT_CACHES. + // While there is only one cache in this example, the same logic will handle the case where + // there are multiple versioned caches. + var expectedCacheNames = Object.keys(CURRENT_CACHES).map(function(key) { + return CURRENT_CACHES[key]; + }); + + event.waitUntil( + caches.keys().then(function(cacheNames) { + return Promise.all( + cacheNames.map(function(cacheName) { + if (expectedCacheNames.indexOf(cacheName) === -1) { + // If this cache name isn't present in the array of "expected" cache names, then delete it. + console.log('[Service Worker] Deleting out of date cache:', cacheName); + return caches.delete(cacheName); + } + }) + ); + }) + ); +}); + +self.addEventListener('fetch', function(event) { + console.log('[Service Worker] Handling fetch event for', event.request.url); + event.respondWith( + // caches.match() will look for a cache entry in all of the caches available to the service worker. + // It's an alternative to first opening a specific named cache and then matching on that. + caches.match(event.request).then(function(response) { + if (response) { + console.log('[Service Worker] Found response in cache:', response); + return response; + } + console.log('[Service Worker] No response found in cache. About to fetch from network...'); + // event.request will always have the proper mode set ('cors, 'no-cors', etc.) so we don't + // have to hardcode 'no-cors' like we do when fetch()ing in the install handler. + return fetch(event.request).then(function(response) { + console.log('[Service Worker] Response from network is:', response); + return response; + }).catch(function(error) { + // This catch() will handle exceptions thrown from the fetch() operation. + // Note that a HTTP error response (e.g. 404) will NOT trigger an exception. + // It will return a normal response object that has the appropriate error code set. + console.error('[Service Worker] Fetching failed:', error); + throw error; + }); + }) + ); +}); \ No newline at end of file