NginxProxyManager / nginx-proxy-manager

Docker container for managing Nginx proxy hosts with a simple, powerful interface
https://nginxproxymanager.com
MIT License
22.32k stars 2.58k forks source link

NPM CLI/API? #1976

Open doofusdavid opened 2 years ago

doofusdavid commented 2 years ago

I'm moving from a self-hosted nginx/let's encrypt server housing about 100 redirects to using NPM. I chose NPM because it's easier for my coworkers to create their own redirects without going through me. (why so many redirects? We're a university with always changing domains, sites, URLs, etc, and we've been asked to enable SSL on all of them.)

Is your feature request related to a problem? Please describe. Describe the solution you'd like I'm comfortable with the command line, and it's easy enough for me to get all existing ones as a list, but entering all of them into the GUI feels overwhelming for that many. I'd love a CLI, through docker, so that I could do something like, "nodepm create redirect --url=xxx --ssl=true --redirect_location=xxx"

Even creating the nginx/lets encrypt manually and getting those values into the database would be great.

Describe alternatives you've considered Hand entering through GUI

embold-given commented 2 years ago

I would also like to see this feature added. I work in a dev shop and we're (finally) looking to dockerize our staging environment. Our current process to provision a new site on our server is a custom script that handles all the cert and nginx configs (as well as setting up the db and directory structure, but that's not something that y'all need to worry about :P ) for us. We've considered just using that (or a slight alteration) anyway, but we really like the idea of having the dashboard for management once things are set up. If there was a CLI component to NPM, it would be a no-brainer to add it to our server.

kmanwar89 commented 2 years ago

Adding my +1 here - I have a constantly-refreshing list of self-hosted services I'd like to test. Even within my home environment, I don't run them without an SSL cert, so there's a lot of work with adding/removing hosts through the GUI. All my options are the same (Base domain name, check box options, etc), so really the only thing I need to change is host IP (maybe), port and the sub-domain name.

I'm working on some automation using Selenium now, but it's not the best - there's lots of messy XPATH's to navigate since not all elements have names or ID's. Honestly, just having the option to select "default" base options for each entry, and only entering the options that need changing, would be a huge boon. If this isn't possible, then some type of CLI or API would be really appreciated!

I'd love to contribute if I can, though programming is not my profession so my knowledge is limited, but always willing to grow :)

laurnts commented 2 years ago

+1 here. Currently I am managing alot of the nginx config using Ansible. It would be nice if there is a cli / api so I can replace nginx with npm. Thus I keep everything automated through Ansible while having the ability to modify and see an overview with the gui.

kmanwar89 commented 2 years ago

I've spent some time working on documenting the API, and have had some success, but the API itself isn't....complete...

If you do a GET to <domain/IP where NPM is hosted>/api/schema, you'll get the API schema presented. I use editor.swagger.io to parse this into an easy to use format.

From there, the logic is:

I'm working on a Python library now that'll interact with NPM via this API, but what I'm finding is portions of the internal API that the application uses (such as calls needed to add custom locations, or generally modify an entries' properties) don't seem to be documented anywhere, so I'm partially reverse-engineering it using the Developer Tools from my browser and watching the Network tab. I'm a network engineer, not a web developer, so this is a learning experience and, as such, might take a bit of time.

DenAV commented 1 year ago

Hi, I started a project for Ansible. Maybe it will help. https://github.com/DenAV/nginx-proxy-manager-ansible

godsgood33 commented 1 year ago

@kmanwar89 were you able to release something? I'd love to see a cli option for when I want to add a host, but I'm not home. I tried added one directly to the database, but that didn't work.

kmanwar89 commented 1 year ago

@kmanwar89 were you able to release something? I'd love to see a cli option for when I want to add a host, but I'm not home. I tried added one directly to the database, but that didn't work.

Wow, I can't believe my last comment was almost a year ago!

No, I haven't really worked on it. Life has gotten in the way, and it seems when it rains, it pours :(

I won't realistically commit to something I can't deliver, and given that I'm not really a developer, just a networking nerd with a penchant for occasional deep-dives into topics out of my realm of expertise, I really don't know if anything I released would be considered complete/accurate.

Perhaps we can ask the developer to release more documentation around the API? I know there's lots of undocumented endpoints, and really without some additional guidance anything myself or others release would be a "best effort" type endeavour.

I do have the program I began writing a year ago - I'll have to find it, and when I do I will link the repo here.

godsgood33 commented 1 year ago

@kmanwar89 were you able to release something? I'd love to see a cli option for when I want to add a host, but I'm not home. I tried added one directly to the database, but that didn't work.

Wow, I can't believe my last comment was almost a year ago!

No, I haven't really worked on it. Life has gotten in the way, and it seems when it rains, it pours :(

I won't realistically commit to something I can't deliver, and given that I'm not really a developer, just a networking nerd with a penchant for occasional deep-dives into topics out of my realm of expertise, I really don't know if anything I released would be considered complete/accurate.

Perhaps we can ask the developer to release more documentation around the API? I know there's lots of undocumented endpoints, and really without some additional guidance anything myself or others release would be a "best effort" type endeavour.

I do have the program I began writing a year ago - I'll have to find it, and when I do I will link the repo here.

Totally get it! Happens to me to. I'm a dev so maybe I can help out, so I'll take a look at the repo when you get it posted.

github-actions[bot] commented 7 months ago

Issue is now considered stale. If you want to keep it open, please comment :+1:

kmanwar89 commented 4 months ago

@kmanwar89 were you able to release something? I'd love to see a cli option for when I want to add a host, but I'm not home. I tried added one directly to the database, but that didn't work.

Wow, I can't believe my last comment was almost a year ago! No, I haven't really worked on it. Life has gotten in the way, and it seems when it rains, it pours :( I won't realistically commit to something I can't deliver, and given that I'm not really a developer, just a networking nerd with a penchant for occasional deep-dives into topics out of my realm of expertise, I really don't know if anything I released would be considered complete/accurate. Perhaps we can ask the developer to release more documentation around the API? I know there's lots of undocumented endpoints, and really without some additional guidance anything myself or others release would be a "best effort" type endeavour. I do have the program I began writing a year ago - I'll have to find it, and when I do I will link the repo here.

Totally get it! Happens to me to. I'm a dev so maybe I can help out, so I'll take a look at the repo when you get it posted.

Hi there @godsgood33. Well, life's finally let up a little bit, so I can finally reply to this issue :)

I do plan on creating a repo with a custom Python program to help quickly create hosts (read in a .csv w/ required information and programmatically create each host via the API), but that's a WIP. For the API side of things, I found this discussion on Reddit helpful; specifically, someone mentioned you can point to < npmurl>/api/schema and retrieve the OpenAPI standard schema.

Take that URL (assuming it's publicly-accessible) and point it to Postman, and you'll be able to import the entire collection. Then, create an environment with two values:

baseUrl - your npm url with /api on the end bearerToken - auth token, see below:

Send a PUT to /api/tokens with the following body (raw or key:value):

key: identity value: your admin password

This will return an auth token. It's only valid for 24 hours, but someone in this GitHub issue claims you can increase the length of this token; this, however, is not documented anywhere I can find.

Hope this helps!

Edit It looks like user @davidindra did a great job with a commit into NPM's repo (though it hasn't been pulled yet, I think?) with a fully-documented schema/Postman collection. Sharing it here:

Collection JSON: Nginx Proxy Manager.postman_collection.json

Commit: https://github.com/NginxProxyManager/nginx-proxy-manager/pull/3726/commits/133c355deafc5927d2ee987390f34ea6a5ee7a4c

and

https://documenter.getpostman.com/view/4475423/2sA3BuV8Qg