self-hosted icon indicating copy to clipboard operation
self-hosted copied to clipboard

Selfhost extension don't work anymore? Why?

Open BobWs opened this issue 3 years ago • 11 comments

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 avatar Feb 22 '22 14:02 BobWs

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 https://github.com/standardnotes/snjs/issues/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" }

jackyzy823 avatar Mar 11 '22 02:03 jackyzy823

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 avatar Mar 11 '22 07:03 BobWs

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

BobWs avatar Mar 11 '22 09:03 BobWs

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

jackyzy823 avatar Mar 11 '22 12:03 jackyzy823

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;

BobWs avatar Mar 11 '22 14:03 BobWs

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

Yes and als yes for offline repo code

jackyzy823 avatar Mar 11 '22 15:03 jackyzy823

@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.

moughxyz avatar Mar 11 '22 15:03 moughxyz

Yes and als yes for offline repo code

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

BobWs avatar Mar 11 '22 15:03 BobWs

@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 https://github.com/standardnotes/snjs/issues/582 , this workaround will be not necessary then.

jackyzy823 avatar Mar 11 '22 16:03 jackyzy823

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

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

moughxyz avatar Mar 11 '22 17:03 moughxyz

Ok, should be fixed by https://github.com/standardnotes/snjs/commit/326c05aa71fd4dfd5ca6789f2f8edff15121fd7d

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

moughxyz avatar Mar 11 '22 17:03 moughxyz