urania-dev / snapp

Yet Another Url Shortner. A simple excercise to learn Svelte.
https://snapp.li
MIT License
210 stars 11 forks source link

ENV values #45

Closed caglaryalcin closed 2 months ago

caglaryalcin commented 2 months ago

I've been trying to find all docker variables in the repo for half an hour :) I think all ENV values should be written in the README section.

I mean, the following values are not used?

ADMIN_EMAIL: ENABLED_SIGNUP: DISABLE_HOME: SMTP_HOST: SMTP_USER: SMTP_PASS: SMTP_FROM: SMTP_PORT: VIRUSTOTAL_API_KEY:

urania-dev commented 2 months ago

If i recall correctly the env.example should have the inital value of envs actually in use.

There has been some change here and there through the versions, so some may slipped.

urania-dev commented 2 months ago
private init = async () => {

        const admin_username = env.ADMIN_USERNAME || 'admin';
        const admin_password = env.ADMIN_PASSWORD || 'password';
        const admin_email = env.ADMIN_EMAIL || 'admin@example.com';

        const [user, error] = await this.users.create(
            admin_username,
            admin_email,
            admin_password,
            undefined,
            'root'
        );
        await this.settings.set(ENABLED_SIGNUP, 'false');

        const ENV_UMAMI_URL = publicEnv.PUBLIC_UMAMI_URL
        const ENV_UMAMI_WEBSITE_ID = publicEnv.PUBLIC_UMAMI_WEBSITE_ID

        if (ENV_UMAMI_URL !== undefined && ENV_UMAMI_WEBSITE_ID !== undefined) {
            await this.settings.set(UMAMI_URL, ENV_UMAMI_URL)
            await this.settings.set(UMAMI_WEBSITE_ID, ENV_UMAMI_WEBSITE_ID)
            console.log("UMAMI Integration: configuration added to the database.")
        }   
    };

SO: Admin_Email, enabled_signup and umamis, are set as default on first launch.

SMTP, DISABLE_HOME and VTAPIKEY are now set from settings instead of env vars to improve qol

so the one missing from env.example is actually admin_email, set but not declared to final user

edit: Fixed, now readme shows env.example content, and it has been updated with missing admin_email, thank you for taking the time to let me know :)

caglaryalcin commented 2 months ago

I would love to use these settings as environment. This is important as I do everything with automation. Is there any way to set these settings outside the interface?

urania-dev commented 2 months ago

i can set them back in 0.8.6

caglaryalcin commented 2 months ago

That would be great, looking forward to it. Thank you for your interest :)

urania-dev commented 2 months ago

try version 0.8.6 // now live (remember to start with a blank db or set initialized_db settings IN DB to false.

initalization is now setting: DISABLE_HOME=false ENABLE_SIGNUP=false VTAPI_KEY= # VIRUSTOTAL API KEY SMTP_HOST= # host smtp.example.com SMTP_USER= # info@example.com SMTP_PASS= # openssl rand -base64 32 SMTP_FROM= # no-reply@example.com SMTP_PORT= # 465

in addition to previously mentioned one in .env.example :)

caglaryalcin commented 2 months ago

I used exactly the following compose.yml file.

version: "3.9"
services:
  snapp:
    container_name: snapp
    image: uraniadev/snapp:0.8.6
    mem_limit: 4g
    cpu_shares: 1024
    security_opt:
      - no-new-privileges:false
    restart: always
    ports:
      - 6421:3000
    depends_on: 
     redis: 
      condition: service_healthy
    environment:
      ORIGIN: https://mywebsite.com
      PUBLIC_URL: https://mywebsite.com
      ADMIN_USERNAME: myusername
      ADMIN_PASSWORD: mypassword
      ADMIN_EMAIL: my@mail.com
      DEFAULT_THEME: light
      ENABLE_SIGNUP: false
      DISABLE_HOME: false
      SMTP_HOST: smtp.gmail.com
      SMTP_USER: mygmail@gmail.com
      SMTP_PASS: 16-character application password
      SMTP_FROM: my@mail.com
      SMTP_PORT: 587
      VTAPI_KEY: 'myvirustotalapikey'
      NODE_ENV: development
      TIMEZONE: Europe/Istanbul
      DB_HOST: redis
      DB_PORT: 6379
      AUTH_SECRET: 'authsecret'
      TOKEN_SECRET: 'tokensecret'

  redis:
    image: redis/redis-stack:latest
    container_name: snapp-redis
    volumes:
      - /volume1/docker/snapp:/data:rw
    environment:
      REDIS_ARGS: '--save 60 1 --appendonly yes'
    healthcheck:
      test: ["CMD-SHELL", "redis-cli ping || exit 1"]
    restart: always
    networks:
      - snapp_network

networks:
  snapp_network:
    name: snapp
    ipam:
      config:
        - subnet: 172.49.0.0/24

DEFAULT_THEME: light > I didn't tell you that, I just hoped it would work :) ENABLE_SIGNUP: false > worked DISABLE_HOME: false > worked VTAPI_KEY: 'myvirustotalapikey' > worked SMTP's > The settings I wrote in ENV appeared in the interface but did not work. The status light is not green, but I am sure the settings are correct (I use other images)

image

urania-dev commented 2 months ago

do you get green light setting them via UI?

to be honest i'm using my own hosted smtp, and works like a charm, i don't know if google maybe require a different type of SSL or TSL to be accessed by?

urania-dev commented 2 months ago

i confirm, https://nodemailer.com/usage/using-gmail/

looks like we should turn authentication into OAuth and provide correct user flow in order to use gmail as a smtp

urania-dev commented 2 months ago

also redis is no longer supported as a database, i think it doesn't makes that much difference having it into your docker compose

you're actually using sqlite in your instance, as DB_URL is no longer a valid env variable

an updated version would be


version: "3.9"
services:
  snapp:
    container_name: snapp
    image: uraniadev/snapp:0.8.6 
    mem_limit: 4g
    cpu_shares: 1024
    security_opt:
      - no-new-privileges:false
    restart: always
    ports:
      - 6421:3000
    # depends_on: 
    #  redis: 
    # condition: service_healthy
    environment:
      ORIGIN: https://mywebsite.com
      # PUBLIC_URL: https://mywebsite.com -- is no longer used we rely on origin
      ADMIN_USERNAME: myusername
      ADMIN_PASSWORD: mypassword
      ADMIN_EMAIL: my@mail.com
      # DEFAULT_THEME: light -- yeah i didn't tought about it sorry 
      ENABLE_SIGNUP: false
      DISABLE_HOME: false
      SMTP_HOST: smtp.gmail.com ## you could try resend as a free limited option | or mailgun | or any other smtp i presume
      SMTP_USER: mygmail@gmail.com
      SMTP_PASS: 16-character application password
      SMTP_FROM: my@mail.com
      SMTP_PORT: 587
      VTAPI_KEY: 'myvirustotalapikey'
      NODE_ENV: development
      TIMEZONE: Europe/Istanbul
      DATABASE_PROVIDER: sqlite # as default is what you're using
      DATABASE_URL: "file:./db.sqlite" #  implicite use as above
      # DB_HOST: redis -- is no longer used
      # DB_PORT: 6379 -- is no longer used
      # AUTH_SECRET: 'authsecret' -- is no longer used
      TOKEN_SECRET: 'tokensecret'

  # redis:
  #   image: redis/redis-stack:latest
  #   container_name: snapp-redis
  #   volumes:
  #     - /volume1/docker/snapp:/data:rw
  #   environment:
  #     REDIS_ARGS: '--save 60 1 --appendonly yes'
  #   healthcheck:
  #     test: ["CMD-SHELL", "redis-cli ping || exit 1"]
  #   restart: always
  #   networks:
  #     - snapp_network

  # networks:
  #   snapp_network:
  #     name: snapp
  #     ipam:
  #       config:
  #         - subnet: 172.49.0.0/24

if you want more specific docker compose or different db look at the example in release or in code :)

caglaryalcin commented 2 months ago

When I try the same settings in my smtp test function, it works. Am I doing something wrong?

image

urania-dev commented 2 months ago

is your endpoint using nodemailer? trying to use mine on snapp would not work either, i can confirm that,

const smtp = {
        host: await database.settings.get(SMTP_HOST).then((res) => res?.value),
        port: await database.settings.get(SMTP_PORT).then((res) => res?.value),
        secure: true,

        auth: {
            user: await database.settings.get(SMTP_USER).then((res) => res?.value),
            pass: await database.settings.get(SMTP_PASS).then((res) => res?.value)
        }
    } as TransportOptions;

this is how nodemailer is configured in snapp, and by the documentation provided before it seems is not enough to get throgh google smtps, im honestly curious.

caglaryalcin commented 2 months ago

It sends email using Windows' built-in Send-MailMessage cmdlet. https://github.com/caglaryalcin/smtp-check/blob/main/smtp-test.psm1

urania-dev commented 2 months ago

I can only imagine is as i said before then, google smtp won't allow snapp to passthrough because is considered less secure (nodemailer offers a oauth flow to allow it but would require rewrite the entire authentication process of snapp, sorry)

caglaryalcin commented 2 months ago

I updated compose as you said above. now I get a “user not found” error. what's going on? :)

version: "3.9"
services:
  snapp:
    container_name: snapp
    image: uraniadev/snapp:0.8.6 
    mem_limit: 4g
    cpu_shares: 1024
    security_opt:
      - no-new-privileges:false
    restart: always
    ports:
      - 6421:3000
    environment:
      ORIGIN: https://mywebsite.me
      ADMIN_USERNAME: Alpha
      ADMIN_PASSWORD: mypassword
      ADMIN_EMAIL: test@mywebsite.com
      ENABLE_SIGNUP: false
      DISABLE_HOME: false
      SMTP_HOST: smtp.gmail.com
      SMTP_USER: mygmail@gmail.com
      SMTP_PASS: asdfasdfasdfasdf
      SMTP_FROM: test@mywebsite.com
      SMTP_PORT: 587
      VTAPI_KEY: 'vtkey'
      NODE_ENV: development
      TIMEZONE: Europe/Istanbul
      DATABASE_PROVIDER: sqlite
      DATABASE_URL: "file:./db.sqlite"
      TOKEN_SECRET: 'tokenkey'

networks:
  snapp_network:
    name: snapp
    ipam:
      config:
        - subnet: 172.49.0.0/24

image

image

urania-dev commented 2 months ago

try remove the database declaration, also i was wrong, i found a way to allow snapp and gmail to comunicate.

caglaryalcin commented 2 months ago

By the way, I use gmail's application password for SMTP, 16 characters. I think this should be ok?

SMTP_PASS= # openssl rand -base64 32

urania-dev commented 2 months ago

Going with order, 1: remove the declaration of db type and url from compose, that would use default one, hence recovering previous one if set.

Also you would specify a mount point or a volume for the db in order to use it on the same volume every time.

services:
  snapp:
    image: uraniadev/snapp:latest
    ports:
      - 3000:3000
    environment:
      TOKEN_SECRET: # openssl rand -base64 32
      ORIGIN: https://example.com
   volumes: 
      - /home/your-account/folder/db.sqlite:/app/prisma/db.sqlite

2: In order to use your gmail account it look likes you need to:

caglaryalcin commented 2 months ago

Yes, when I removed the DATABASE_PROVIDER and DATABASE_URL environments, I did not get the “user not found” error. The only problem now is SMTP. Gmail settings are 2fa open as I said and I use app password.

urania-dev commented 2 months ago

try with port 465

caglaryalcin commented 2 months ago

Yes! it should be port 465 :) Actually, it would be better if there was a SEND TEST button in the smtp settings instead of the password reset button after logging in.

image

urania-dev commented 2 months ago

yeah, i can see the usefulness in that :D i think i'll plan it for 0.8.6.1 with also the typo in APP_NAME APPNAME that doesn't fix the app name in sent email.

I assume you manage to get it to work, right? :)

caglaryalcin commented 2 months ago

Yes, it's working great now, thank you!

urania-dev commented 2 months ago

building 0.8.6.1 now :) stay tuned 🚀

caglaryalcin commented 2 months ago

If you want to add the DEFAULT_THEME environment :)

urania-dev commented 2 months ago

kind of added in v.0.8.6.3, it now check for cookie, then for settings in db, then for default_theme, then dark if nothing is set. So basically should be cookie not set, hence default theme until you change in frontend.

then at this point i'm not sure of which prevails, but in the end the db setting should win.

Notice that is not set until done from frontend.

:)

caglaryalcin commented 2 months ago

Everything is great right now and working as it should. Thank you!