Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Selfhost extension don't work anymore? Why? #64

Open
BobWs opened this issue Feb 22, 2022 · 11 comments
Open

Selfhost extension don't work anymore? Why? #64

BobWs opened this issue Feb 22, 2022 · 11 comments
Labels
help wanted Extra attention is needed

Comments

@BobWs
Copy link

BobWs commented Feb 22, 2022

Hi,
Why can I not use my selfhosted extensions anymore?
After updating to the latest versions of Standardnotes my extensions stopped working and I'm getting a message that it is only for paid subscriptions.

If you guys want to ask money for everything than you should make it a close source thing and not publish everything here on Github.
First everything is free and one can selfhost and than the shit begins...

@BobWs BobWs added the help wanted Extra attention is needed label Feb 22, 2022
@jackyzy823
Copy link

jackyzy823 commented Mar 11, 2022

I partially agree with you . Although according to this comment you could modify DB to have a subscription , however they will not tell you how to achieve this and how many issues you'll encounter, because of modifying db only is insufficient.

I have managed to make new feature work on self-hosted finally.

Here's the steps and remember to backup your database first then do under your own risk.

  1. Do database modification to make user Pro Plan.
    Enter mysql cli : docker-compose exec db sh -c 'MYSQL_PWD=$MYSQL_ROOT_PASSWORD mysql $MYSQL_DATABASE'
    Replace EMAIL@ADDR with your real one.
INSERT INTO user_roles (role_uuid , user_uuid) VALUES ( ( select uuid from roles where name="PRO_USER" order by version desc limit 1 ) ,( select uuid from users where email="<EMAIL@ADDR>" )  ) ON DUPLICATE KEY UPDATE role_uuid = VALUES(`role_uuid`);

insert into user_subscriptions set uuid = UUID() , plan_name="PRO_PLAN" , ends_at = 8640000000000000, created_at = 0 , updated_at = 0,user_uuid= (select uuid from users where email="<EMAIL@ADDR>") , subscription_id=1;
  1. (optional) Host a payment server (just a fake/a proxy) and set api-gateway's PAYMENTS_SERVER_URL=http://<nginx>:3000 to this server
    I use nginx for this, conf like:
server{
  listen 3000;
  # THis is a fake Payment server
  location /api/subscriptions/features {
      proxy_pass https://api.standardnotes.com/v2/subscriptions;
  }
}
  1. Add offline repo code (could be invalid extensionKey . but featuresUrl must in trusted servers) in preferences -> General -> Advanced Settings -> Offline Subscription TO bypass snjs' checking, because self hosted one is not treated as firstparty it cannout use feature (which is decided by snjs) . I opened an issue in make DEFAULT_SYNC_SERVER first party too. snjs#582 , if they changed this, then this step is not necessary.

offline repo code: eyJmZWF0dXJlc1VybCI6Imh0dHBzOi8vYXBpLnN0YW5kYXJkbm90ZXMuY29tL3YxL29mZmxpbmUvZmVhdHVyZXMiLCJleHRlbnNpb25LZXkiOiJmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmIn0=

It is from here with base64
{
"featuresUrl": "https://api.standardnotes.com/v1/offline/features",
"extensionKey": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
}

@BobWs
Copy link
Author

BobWs commented Mar 11, 2022

Thanks for sharing!
Just a view questions for me to understand everything.
Can this also be modified with phpmyadmin?
And for the payment server as I understand it I have to create another nginx container?

@BobWs
Copy link
Author

BobWs commented Mar 11, 2022

So I have mange to import the changes into the database with myphpadmin without any errors (guess that is a good thing!)
But I'm a bit lost on the nginx part as I don't know much about nginx. I'm running this repo for the extensions which has a nginx server https://github.com/iganeshk/standardnotes-extensions

Can I combine your your config for the fake/proxy with this one? if so how do I do that?
And where do I add this set api-gateway's PAYMENTS_SERVER_URL=http://:3000 to this server
Sorry for all the noob questions.

TIA

@jackyzy823
Copy link

And for the payment server as I understand it I have to create another nginx container?

Yes

Can I combine your your config for the fake/proxy with this one? if so how do I do that?

Yes

If you're using this nginx https://github.com/iganeshk/standardnotes-extensions#setup-with-nginx
just append

 location /api/subscriptions/features {
      proxy_pass https://api.standardnotes.com/v2/subscriptions;
  }

after previous location.

And where do I add this set api-gateway's PAYMENTS_SERVER_URL=http://:3000 to this server

After here https://github.com/standardnotes/standalone/blob/e522ef4ebc0fa4be541ed6ba7ee17628c0935990/docker-compose.yml#L50-L52 or in here https://github.com/standardnotes/standalone/blob/main/docker/api-gateway.env.sample

@BobWs
Copy link
Author

BobWs commented Mar 11, 2022

Thanks for explaining I have manage to get it working! I installed a new nginx container and that is working for me as I couldn't manage to get it working with the existing extensions-nginx container. But it is working so I'm fine with it ;-)

One question though
Do I need to repeat this step for all my users?:

INSERT INTO user_roles (role_uuid , user_uuid) VALUES ( ( select uuid from roles where name="PRO_USER" order by version desc limit 1 ) ,( select uuid from users where email="<EMAIL@ADDR>" )  ) ON DUPLICATE KEY UPDATE role_uuid = VALUES(`role_uuid`);

insert into user_subscriptions set uuid = UUID() , plan_name="PRO_PLAN" , ends_at = 8640000000000000, created_at = 0 , updated_at = 0,user_uuid= (select uuid from users where email="<EMAIL@ADDR>") , subscription_id=1;

@jackyzy823
Copy link

Do I need to repeat this step for all my users?:

Yes and als yes for offline repo code

@moughxyz
Copy link
Member

@jackyzy823 thanks for creating these instructions, made my job easier 😄

Instructions added here: https://docs.standardnotes.com/self-hosting/subscriptions

You don't need to go the offline repo route. That's only if you're not using an account.

I tested the instructions in the link above on a new standalone server and it worked perfectly fine as-is without needing to stub the payments server or anything like that.

@BobWs
Copy link
Author

BobWs commented Mar 11, 2022

Yes and als yes for offline repo code

Super it is working! Thanks for your hard work and patience with a noob like me;-)

@jackyzy823
Copy link

jackyzy823 commented Mar 11, 2022

@BobWs @moughxyz
I remember now that the step 2 is not quite necessary. I just do not like a 404 request to v2/subscriptions. So you can ignore this. Sorry for letting you waste time on this.

@moughxyz
Nope. I guess you're testing under domain localhost which could pass snjs' checking ?

offline repo route is just a workaround. You need it to let snjs pass checking to use features. otherwise standardnote will warning subscrption is expired and extendsions are read-only state

If you fix the issue in standardnotes/snjs#582 , this workaround will be not necessary then.

@moughxyz
Copy link
Member

I guess you're testing under domain localhost which could pass snjs' checking

Ah, indeed. Let me take a look at this.

@moughxyz
Copy link
Member

Ok, should be fixed by standardnotes/snjs@326c05a

This will go out in the next desktop/web release, but not exactly sure when that will be. Probably 1-2 weeks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants