Skip to content

Commit

Permalink
Added --password option to nscp web install to directly set the password
Browse files Browse the repository at this point in the history
  • Loading branch information
mickem committed Jul 28, 2017
1 parent 238c608 commit 3add470
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
29 changes: 21 additions & 8 deletions docs/docs/api/index.md
Expand Up @@ -20,22 +20,37 @@ You can enable the WEBServer module during the package installation.
Alternatively you can enable the WEBServer module on the CLI afterwards:

```
nscp web install
nscp web install --password <MY SECRET PASSWORD>
```

### Configuration

Edit the `/settings/WEB/server` section in the `nsclient.ini`
configuration file.
The default values `password` and `allowed hosts` (`/settings/default`) are shared by all modules (i.e. NRPEServer and NSClientServer) if you want to have separate values for the WEBServer you can override them under `/settings/WEB/server`.

```
[/settings/WEB/server]
; MODULES - A list of modules.
[/modules]
; WEBServer - A server that listens for incoming HTTP connection and processes incoming requests. It provides both a WEB UI as well as a REST API in addition to simplifying configuration of WEB Server module.
WEBServer = enabled
[/settings/default]
; PASSWORD - Password used to authenticate against server
password = <MY SECRET PASSWORD>
; ALLOWED HOSTS - A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges. parent for this key is found under: /settings/default this is marked as advanced in favor of the parent.
allowed hosts = 127.0.0.1,192.168.2.0/24
; PASSWORD - Password used to authenticate against server parent for this key is found under: /settings/default this is marked as advanced in favor of the parent.
password = icinga
[/settings/WEB/server]
; PORT NUMBER - Port to use for WEB server.
port = 8443s
; CERTIFICATE - Ssl certificate to use for the ssl server
certificate = ${certificate-path}/certificate.pem
```

Restart the `nscp` service afterwards.
Expand All @@ -45,12 +60,10 @@ net stop nscp
net start nscp
```

You can also specify global settings in the `/settings/default` section.

Alternatively you can specify the password on the shell:
You can change the password from the command line using the following command:

```
nscp web password - -set icinga
nscp web password --set icinga
```

The next chapter provides a quick overview of how you can use the API.
Expand Down
12 changes: 10 additions & 2 deletions modules/WEBServer/WEBServer.cpp
Expand Up @@ -897,11 +897,12 @@ bool WEBServer::install_server(const Plugin::ExecuteRequestMessage::Request &req
namespace pf = nscapi::protobuf::functions;
po::variables_map vm;
po::options_description desc;
std::string allowed_hosts, cert, key, port;
std::string allowed_hosts, cert, key, port, password;
const std::string path = "/settings/WEB/server";

pf::settings_query q(get_id());
q.get("/settings/default", "allowed hosts", "127.0.0.1");
q.get("/settings/default", "password", "");
q.get(path, "certificate", "${certificate-path}/certificate.pem");
q.get(path, "certificate key", "");
q.get(path, "port", "8443s");
Expand All @@ -914,6 +915,8 @@ bool WEBServer::install_server(const Plugin::ExecuteRequestMessage::Request &req
BOOST_FOREACH(const pf::settings_query::key_values &val, q.get_query_key_response()) {
if (val.matches("/settings/default", "allowed hosts"))
allowed_hosts = val.get_string();
else if (val.matches("/settings/default", "password"))
password = val.get_string();
else if (val.matches(path, "certificate"))
cert = val.get_string();
else if (val.matches(path, "certificate key"))
Expand All @@ -935,7 +938,10 @@ bool WEBServer::install_server(const Plugin::ExecuteRequestMessage::Request &req
"Client certificate to use")

("port", po::value<std::string>(&port)->default_value(port),
"Port to use suffix with s for ssl")
"Port to use suffix with s for ssl")

("password", po::value<std::string>(&password)->default_value(password),
"Password to use to authenticate")

;

Expand Down Expand Up @@ -974,6 +980,8 @@ bool WEBServer::install_server(const Plugin::ExecuteRequestMessage::Request &req
if (https)
result << "Point your browser to https://localhost:" << boost::replace_all_copy(port, "s", "") << std::endl;
result << "Point your browser to http://localhost:" << boost::replace_all_copy(port, "s", "") << std::endl;
result << "Login using:" << password << std::endl;
s.set("/settings/default", "password", password);
s.set(path, "port", port);
s.save();
get_core()->settings_query(s.request(), s.response());
Expand Down

0 comments on commit 3add470

Please sign in to comment.