Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.
fix: ensure a user always has an api key generated
Miguel Ribeiroe276147cab1f
diff --git a/.github/workflows/build-release.yaml b/.github/workflows/build-release.yamlindex 77a9c7c..66dcc9e 100644--- a/.github/workflows/build-release.yaml+++ b/.github/workflows/build-release.yaml@@ -18,9 +18,13 @@ env:IMAGE_NAME: ${{ vars.DOCKERHUB_TAG }}# For release-please, see available types at https://github.com/google-github-actions/release-please-action/tree/v4/?tab=readme-ov-file#release-types-supportedPROJECT_TYPE: simple+jobs:release:runs-on: ubuntu-latest+ outputs:+ release_created: ${{ steps.rp.outputs.release_created }}+ tag_patterns: ${{ steps.tags.outputs.tags }}steps:- uses: actions/checkout@v4- id: rp@@ -28,18 +32,6 @@ jobs:uses: google-github-actions/release-please-action@v4with:release-type: ${{ env.PROJECT_TYPE }}- - name: Log into registry ${{ env.REGISTRY }}- uses: docker/login-action@v3- with:- registry: ${{ env.REGISTRY }}- username: ${{ env.REGISTRY_USERNAME }}- password: ${{ env.REGISTRY_PASSWORD }}- - name: Login to GitHub Container Registry- uses: docker/login-action@v3- with:- registry: ghcr.io- username: ${{ github.actor }}- password: ${{ secrets.GITHUB_TOKEN }}- name: Prepare tags for Docker metaid: tagsenv:@@ -60,6 +52,31 @@ jobs:echo "$tags"echo EOF} >> "$GITHUB_OUTPUT"++ build:+ runs-on: ubuntu-latest+ needs: release+ strategy:+ fail-fast: false+ matrix:+ platform:+ - linux/amd64+ - linux/arm64+ - linux/arm/v7+ steps:+ - uses: actions/checkout@v4+ - name: Log into registry ${{ env.REGISTRY }}+ uses: docker/login-action@v3+ with:+ registry: ${{ env.REGISTRY }}+ username: ${{ env.REGISTRY_USERNAME }}+ password: ${{ env.REGISTRY_PASSWORD }}+ - name: Login to GitHub Container Registry+ uses: docker/login-action@v3+ with:+ registry: ghcr.io+ username: ${{ github.actor }}+ password: ${{ secrets.GITHUB_TOKEN }}- name: Docker metaid: metauses: docker/metadata-action@v5@@ -67,27 +84,88 @@ jobs:images: |${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}ghcr.io/ellite/wallos- tags: ${{ steps.tags.outputs.tags }}+ tags: ${{ needs.release.outputs.tag_patterns }}# necessary for multi-platform images- name: Set up QEMUuses: docker/setup-qemu-action@v3# necessary for multi-platform images- name: Set up Docker Buildxuses: docker/setup-buildx-action@v3- - name: Build and push- uses: docker/build-push-action@v5+ - name: Build and push by digest+ id: build+ uses: docker/build-push-action@v6with:context: .- push: ${{ github.event_name != 'pull_request' }}- tags: ${{ steps.meta.outputs.tags }}+ platforms: ${{ matrix.platform }}labels: ${{ steps.meta.outputs.labels }}- platforms: linux/amd64,linux/arm64,linux/arm/v7- cache-from: type=gha- cache-to: type=gha,mode=max- - name: Send notification to Discord+ outputs: type=image,"name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},ghcr.io/ellite/wallos",push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}+ # Scope cache per platform to prevent architecture-mismatched layers+ cache-from: type=gha,scope=${{ github.workflow }}-${{ matrix.platform }}+ cache-to: type=gha,mode=max,scope=${{ github.workflow }}-${{ matrix.platform }}+ - name: Export digest+ if: github.event_name != 'pull_request'+ run: |+ mkdir -p /tmp/digests+ digest="${{ steps.build.outputs.digest }}"+ touch "/tmp/digests/${digest#sha256:}"+ - name: Upload digestif: github.event_name != 'pull_request'+ uses: actions/upload-artifact@v4+ with:+ name: digests-${{ matrix.platform == 'linux/amd64' && 'amd64' || matrix.platform == 'linux/arm64' && 'arm64' || 'armv7' }}+ path: /tmp/digests/*+ if-no-files-found: error+ retention-days: 1++ merge:+ runs-on: ubuntu-latest+ needs: [release, build]+ if: github.event_name != 'pull_request'+ steps:+ - name: Download digests+ uses: actions/download-artifact@v4+ with:+ path: /tmp/digests+ pattern: digests-*+ merge-multiple: true+ - name: Log into registry ${{ env.REGISTRY }}+ uses: docker/login-action@v3+ with:+ registry: ${{ env.REGISTRY }}+ username: ${{ env.REGISTRY_USERNAME }}+ password: ${{ env.REGISTRY_PASSWORD }}+ - name: Login to GitHub Container Registry+ uses: docker/login-action@v3+ with:+ registry: ghcr.io+ username: ${{ github.actor }}+ password: ${{ secrets.GITHUB_TOKEN }}+ - name: Set up Docker Buildx+ uses: docker/setup-buildx-action@v3+ - name: Docker meta+ id: meta+ uses: docker/metadata-action@v5+ with:+ images: |+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}+ ghcr.io/ellite/wallos+ tags: ${{ needs.release.outputs.tag_patterns }}+ - name: Create manifest list and push to Docker Hub+ working-directory: /tmp/digests+ run: |+ docker buildx imagetools create \+ $(jq -cr '.tags | map(select(startswith("${{ env.REGISTRY }}")) | "-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \+ $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)+ - name: Create manifest list and push to GHCR+ working-directory: /tmp/digests+ run: |+ docker buildx imagetools create \+ $(jq -cr '.tags | map(select(startswith("ghcr.io")) | "-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \+ $(printf 'ghcr.io/ellite/wallos@sha256:%s ' *)+ - name: Send notification to Discord+ if: needs.release.outputs.release_created == 'true'uses: Ilshidur/action-discord@masterwith:- args: "A new release has been created: ${{ steps.meta.outputs.tags }}"+ args: "A new release has been created: ${{ needs.release.outputs.tag_patterns }}"env:DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}diff --git a/.gitignore b/.gitignoreindex 60c1b97..8f39a25 100644--- a/.gitignore+++ b/.gitignore@@ -5,4 +5,5 @@.DS_Store.idea/.vscode/-AGENTS.md+AGENTS.md+.antigravityclidiff --git a/endpoints/admin/adduser.php b/endpoints/admin/adduser.phpindex 4190edd..50d71a3 100644--- a/endpoints/admin/adduser.php+++ b/endpoints/admin/adduser.php@@ -146,7 +146,7 @@ $stmt->bindValue(':id', $currency, SQLITE3_TEXT);$row = $stmt->execute();$main_currency = $row->fetchArray()['code'];-$query = "INSERT INTO user (username, email, password, main_currency, avatar, language, budget) VALUES (:username, :email, :password, :main_currency, :avatar, :language, :budget)";+$query = "INSERT INTO user (username, email, password, main_currency, avatar, language, budget, api_key) VALUES (:username, :email, :password, :main_currency, :avatar, :language, :budget, :api_key)";$stmt = $db->prepare($query);$hashedPassword = password_hash($password, PASSWORD_DEFAULT);$stmt->bindValue(':username', $username, SQLITE3_TEXT);@@ -156,6 +156,7 @@ $stmt->bindValue(':main_currency', 1, SQLITE3_TEXT);$stmt->bindValue(':avatar', $avatar, SQLITE3_TEXT);$stmt->bindValue(':language', $language, SQLITE3_TEXT);$stmt->bindValue(':budget', 0, SQLITE3_INTEGER);+$stmt->bindValue(':api_key', bin2hex(random_bytes(32)), SQLITE3_TEXT);$result = $stmt->execute();if ($result) {diff --git a/endpoints/currency/update_exchange.php b/endpoints/currency/update_exchange.phpindex 494dfc6..f44a6e1 100644--- a/endpoints/currency/update_exchange.php+++ b/endpoints/currency/update_exchange.php@@ -26,8 +26,10 @@ if (isset($_POST['force']) && $_POST['force'] === "true") {}}-$query = "SELECT api_key, provider FROM fixer";-$result = $db->query($query);+$query = "SELECT api_key, provider FROM fixer WHERE user_id = :userId";+$stmt = $db->prepare($query);+$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);+$result = $stmt->execute();if ($result) {$row = $result->fetchArray(SQLITE3_ASSOC);diff --git a/endpoints/subscription/add.php b/endpoints/subscription/add.phpindex 727fc50..b7e0a23 100644--- a/endpoints/subscription/add.php+++ b/endpoints/subscription/add.php@@ -249,6 +249,16 @@ if ($replacementSubscriptionId == 0 || $inactive == 0) {$replacementSubscriptionId = null;}+if ($replacementSubscriptionId !== null) {+ $ownerCheck = $db->prepare("SELECT id FROM subscriptions WHERE id = :id AND user_id = :userId");+ $ownerCheck->bindParam(':id', $replacementSubscriptionId, SQLITE3_INTEGER);+ $ownerCheck->bindParam(':userId', $userId, SQLITE3_INTEGER);+ $ownerResult = $ownerCheck->execute();+ if (!$ownerResult || !$ownerResult->fetchArray()) {+ $replacementSubscriptionId = null;+ }+}+if ($logoUrl !== "") {$result = getLogoFromUrl($logoUrl, '../../images/uploads/logos/', $name, $settings, $i18n);if ($result['success']) {diff --git a/includes/currency_formatter.php b/includes/currency_formatter.phpindex c4dd1e1..9872f06 100644--- a/includes/currency_formatter.php+++ b/includes/currency_formatter.php@@ -19,6 +19,6 @@ final class CurrencyFormatterpublic static function format($amount, $currency){- return self::getInstance()->formatCurrency($amount, $currency);+ return self::getInstance()->formatCurrency((float) $amount, $currency);}}diff --git a/includes/oidc/oidc_create_user.php b/includes/oidc/oidc_create_user.phpindex 8e1a72b..0214ea2 100644--- a/includes/oidc/oidc_create_user.php+++ b/includes/oidc/oidc_create_user.php@@ -15,8 +15,8 @@ $password = bin2hex(random_bytes(16)); // 32-character random password$hashedPassword = password_hash($password, PASSWORD_DEFAULT);// Insert user-$query = "INSERT INTO user (username, email, oidc_sub, main_currency, avatar, language, budget, firstname, lastname, password)- VALUES (:username, :email, :oidc_sub, :main_currency, :avatar, :language, :budget, :firstname, :lastname, :password)";+$query = "INSERT INTO user (username, email, oidc_sub, main_currency, avatar, language, budget, firstname, lastname, password, api_key)+ VALUES (:username, :email, :oidc_sub, :main_currency, :avatar, :language, :budget, :firstname, :lastname, :password, :api_key)";$stmt = $db->prepare($query);$stmt->bindValue(':username', $username, SQLITE3_TEXT);$stmt->bindValue(':email', $email, SQLITE3_TEXT);@@ -28,6 +28,7 @@ $stmt->bindValue(':budget', $budget, SQLITE3_INTEGER);$stmt->bindValue(':firstname', $firstname, SQLITE3_TEXT);$stmt->bindValue(':lastname', $lastname, SQLITE3_TEXT);$stmt->bindValue(':password', $hashedPassword, SQLITE3_TEXT);+$stmt->bindValue(':api_key', bin2hex(random_bytes(32)), SQLITE3_TEXT);if (!$stmt->execute()) {die("Failed to create user");diff --git a/includes/stats_calculations.php b/includes/stats_calculations.phpindex 2589978..760cac3 100644--- a/includes/stats_calculations.php+++ b/includes/stats_calculations.php@@ -236,9 +236,10 @@ if ($result) {// Check if it has a replacement subscription and if it was not already countedif ($replacementSubscriptionId && !in_array($replacementSubscriptionId, $replacementSubscriptions)) {- $query = "SELECT price, currency_id, cycle, frequency FROM subscriptions WHERE id = :replacementSubscriptionId";+ $query = "SELECT price, currency_id, cycle, frequency FROM subscriptions WHERE id = :replacementSubscriptionId AND user_id = :userId";$stmt = $db->prepare($query);$stmt->bindValue(':replacementSubscriptionId', $replacementSubscriptionId, SQLITE3_INTEGER);+ $stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);$result = $stmt->execute();$replacementSubscription = $result->fetchArray(SQLITE3_ASSOC);if ($replacementSubscription) {diff --git a/profile.php b/profile.phpindex 0e7e5bc..e494879 100644--- a/profile.php+++ b/profile.php@@ -269,7 +269,7 @@ while ($row = $result->fetchArray(SQLITE3_ASSOC)) {</header><div class="account-api-key"><div class="form-group-inline">- <input type="text" id="apikey" name="apikey" value="<?= htmlspecialchars($userData['api_key']) ?>" placeholder="API Key" readonly>+ <input type="text" id="apikey" name="apikey" value="<?= htmlspecialchars($userData['api_key'] ?? '') ?>" placeholder="API Key" readonly><input type="submit" value="<?= translate('regenerate', $i18n) ?>" id="regenerateApiKey" onClick="regenerateApiKey()" /></div><div class="settings-notes">diff --git a/registration.php b/registration.phpindex 7c07205..5baec3c 100644--- a/registration.php+++ b/registration.php@@ -199,7 +199,7 @@ if (isset($_POST['username'])) {$requireValidation = false;if ($hasErrors == false) {- $query = "INSERT INTO user (username, firstname, lastname, email, password, main_currency, avatar, language, budget) VALUES (:username, :firstname, :lastname, :email, :password, :main_currency, :avatar, :language, :budget)";+ $query = "INSERT INTO user (username, firstname, lastname, email, password, main_currency, avatar, language, budget, api_key) VALUES (:username, :firstname, :lastname, :email, :password, :main_currency, :avatar, :language, :budget, :api_key)";$stmt = $db->prepare($query);$hashedPassword = password_hash($password, PASSWORD_DEFAULT);$stmt->bindValue(':username', $username, SQLITE3_TEXT);@@ -211,6 +211,7 @@ if (isset($_POST['username'])) {$stmt->bindValue(':avatar', $avatar, SQLITE3_TEXT);$stmt->bindValue(':language', $language, SQLITE3_TEXT);$stmt->bindValue(':budget', 0, SQLITE3_INTEGER);+ $stmt->bindValue(':api_key', bin2hex(random_bytes(32)), SQLITE3_TEXT);$result = $stmt->execute();if ($result) {