Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ ENV WPR_APP_SERVER_DIR=${WPR_APP_SERVER_DIR}
ARG WPR_PROTOCOL=2
# Web port outside the container. If value isn't specified (e.g. empty), the default value will be used (443 for HTTPS and 80 for HTTP).
ARG WPR_WEB_PORT
ARG WPR_DOMAIN_NAME=localhost
# Domain name for NGINX server_name directive. Default '_' accepts any domain. Set to specific domain to restrict access.
ARG WPR_DOMAIN_NAME=_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing WPR_DOMAIN_NAME default to _ affects files/startService.sh. In the recently merged PR #85, we added self-signed certificate generation that uses WPR_DOMAIN_NAME for the certificate CN:

-subj "/CN=${WPR_DOMAIN_NAME:-localhost}"

With _ as the new default, the cert would get CN=_ instead of CN=localhost.

We need update there code in files/startService.sh after the line 30 on something like that:

CERT_CN="${WPR_DOMAIN_NAME}"                                                                                                                                
[ -z "$CERT_CN" ] || [ "$CERT_CN" = "_" ] && CERT_CN="localhost"                                                                                            
echo "$(date '+%m/%d/%y:%H:%M:%S.%3N')   No SSL certificates found. Generating self-signed certificate for CN=${CERT_CN}..."
...
-subj "/CN=${CERT_CN}" 2>/dev/null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

ARG WPR_VIRTUAL_DIR=wscservice
# Specify license ticket ID to activate the license during the image build. For example, WPR_LICENSE_TICKET_ID = 6u*************ZO
ARG WPR_LICENSE_TICKET_ID
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.redhat
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ ENV WPR_APP_SERVER_DIR=${WPR_APP_SERVER_DIR}
ARG WPR_PROTOCOL=2
# Web port outside the container. If value isn't specified (e.g. empty), the default value will be used (443 for HTTPS and 80 for HTTP).
ARG WPR_WEB_PORT
ARG WPR_DOMAIN_NAME=localhost
# Domain name for NGINX server_name directive. Default '_' accepts any domain. Set to specific domain to restrict access.
ARG WPR_DOMAIN_NAME=_
ARG WPR_VIRTUAL_DIR=wscservice
# Specify license ticket ID to activate the license during the image build. For example, WPR_LICENSE_TICKET_ID = 6u*************ZO
ARG WPR_LICENSE_TICKET_ID
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.ubuntu-prebuilt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ ENV WPR_APP_SERVER_DIR=${WPR_APP_SERVER_DIR}
ARG WPR_PROTOCOL=2
# Web port outside the container. If value isn't specified (e.g. empty), the default value will be used (443 for HTTPS and 80 for HTTP).
ARG WPR_WEB_PORT
ARG WPR_DOMAIN_NAME=localhost
# Domain name for NGINX server_name directive. Default '_' accepts any domain. Set to specific domain to restrict access.
ARG WPR_DOMAIN_NAME=_
ARG WPR_VIRTUAL_DIR=wscservice
ARG WPR_LICENSE_TICKET_ID

Expand Down
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ If, on the other hand, you would like to use a prebuilt Docker image, choose the
```
ARG WPR_PROTOCOL=2
ARG WPR_WEB_PORT
ARG WPR_DOMAIN_NAME=localhost
ARG WPR_DOMAIN_NAME=_
ARG WPR_VIRTUAL_DIR=wscservice
ARG WPR_LICENSE_TICKET_ID
```
Expand All @@ -47,12 +47,21 @@ English language and autocomplete models are available for en_US (American Engli
```
ARG WPR_LICENSE_TICKET_ID=6u*************ZO
```
* Specify `DOMAIN_NAME` which will be used for the setup of demo samples with WProofreader. By default, `localhost` will be used if nothing is specified.
* Configure domain name for NGINX `server_name` directive. By default, `_` (underscore) is used, which accepts requests from any domain. To restrict access to a specific domain, set this to your domain name (e.g., `example.com`).

```
ARG WPR_DOMAIN_NAME = DOMAIN_NAME
ARG WPR_DOMAIN_NAME=_
```

* Configure virtual directory for the service. By default, `wscservice` is used, making the service accessible at `/wscservice/` (e.g., `http://localhost/wscservice/`). To deploy at the root path, set this to `/` or leave it empty:

```
ARG WPR_VIRTUAL_DIR=wscservice # Service at /wscservice/ (default)
ARG WPR_VIRTUAL_DIR=/ # Service at root / (captures all requests)
```

**Note:** Using root path (`/`) configures NGINX to serve the application at the domain root, which may not be suitable for shared web servers where multiple applications need different paths.

If `WPR_LICENSE_TICKET_ID` was specified during the image creation, you don't need to specify it during the launch of `docker run` command.

* If using a proxy server for network traffic, add the following proxy settings for automated license activation:
Expand Down Expand Up @@ -167,9 +176,9 @@ docker run -d -p 443:8443 --env WPR_PROTOCOL=1 --env WPR_DOMAIN_NAME=localhost -
where:

* `--env WPR_PROTOCOL=1` start a container on HTTPS protocol
* `--env WPR_DOMAIN_NAME=localhost` start a container on `localhost` domain name
* `--env WPR_DOMAIN_NAME=localhost` configure NGINX to accept requests only from `localhost` domain. Use `_` to accept requests from any domain.
* `--env WPR_WEB_PORT=443` configure `443` port to be an external port of a container
* `--env WPR_VIRTUAL_DIR=wscservice` start a container with `wscservice` as virtual dir
* `--env WPR_VIRTUAL_DIR=wscservice` start a container with `wscservice` as virtual directory. Use `/` or empty string for root path.
* `--env WPR_LICENSE_TICKET_ID=6u*************ZO` activate license on container start with `6u*************ZO` license ticket id

Additional parameters:
Expand Down
51 changes: 10 additions & 41 deletions files/configureFiles.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
my $installPath = "$serverPath/..";
my $server_config_path = "$serverPath/AppServerX.xml";

configureSamplesAndVirtualDir();
printStartEndpoint();
configureUserAndCustomDictionaries();

sub configureSamplesAndVirtualDir
sub printStartEndpoint
{
my $protocol = $ENV{'WPR_PROTOCOL'} eq '1' ? 'https' : 'http';
my $host = $ENV{'WPR_DOMAIN_NAME'};
Expand All @@ -16,46 +16,15 @@ sub configureSamplesAndVirtualDir
my $web_port = $ENV{'WPR_WEB_PORT'} eq "" ? ($protocol eq "https" ? "443" : "80") : $ENV{'WPR_WEB_PORT'};
my $virtual_dir = $ENV{'WPR_VIRTUAL_DIR'};

configureVirtualDir($protocol, $host, $web_port, $virtual_dir);

configureSamples($protocol, $host, $web_port, $virtual_dir);
}
# Normalize virtual_dir for display
my $is_root_path = ($virtual_dir eq '/' || $virtual_dir eq '');
my $vdir_part = $is_root_path ? '' : $virtual_dir;
$vdir_part =~ s/^\///; # Remove leading slash if present
$vdir_part = '/' . $vdir_part if $vdir_part ne ''; # Add it back with proper formatting

sub configureSamples()
{
my ($protocol, $host, $web_port, $virtual_dir) = @_;

my $samples_dir_path = "$installPath/WebComponents/Samples/";
opendir my $dir, $samples_dir_path or return;
my @files = readdir $dir;
closedir $dir;

foreach ( @files )
{
if ( $_ eq '.' || $_ eq '..' ) { next; }

my %pairs = (
'serviceProtocol: \'((http)|(https))\'' => "serviceProtocol: '$protocol'",
'servicePort: \'\d*\'' => "servicePort: '$web_port'",
'serviceHost: \'[\w.-]*\'' => "serviceHost: '$host'",
'servicePath: \'.*?\/api\'' => "servicePath: '$virtual_dir/api'",
'((http)|(https)):\/\/[\w.-]*:\d*\/.*?\/wscbundle\/wscbundle.js' => "$protocol://$host:$web_port/$virtual_dir/wscbundle/wscbundle.js",
'((http)|(https)):\/\/[\w.-]*:\d*\/.*?\/samples\/' => "$protocol://$host:$web_port/$virtual_dir/samples/"
);
replaceFileContent(\%pairs, "$samples_dir_path/$_");
}
}

sub configureVirtualDir()
{
my ($protocol, $host, $web_port, $virtual_dir) = @_;

my $virtual_dir_file = "$installPath/WebComponents/WebInterface/index.html";

replaceFileContent({'((http)|(https)):\/\/[\w.-]*:\d*\/.*?\/api\?cmd' => "$protocol://$host:$web_port/$virtual_dir/api?cmd"}, $virtual_dir_file);
replaceFileContent({'((http)|(https)):\/\/[\w.-]*:\d*\/.*?\/samples\/' => "$protocol://$host:$web_port/$virtual_dir/samples/"}, $virtual_dir_file);

print "Verify the WSC Application Operability: $protocol://$host:$web_port/$virtual_dir/ \n";
# Print verification message
my $display_host = ($host eq '_') ? '<host>' : $host;
print "Verify the WSC Application Operability: $protocol://$display_host:$web_port$vdir_part/ \n";
}

sub configureUserAndCustomDictionaries
Expand Down
25 changes: 15 additions & 10 deletions files/configureWebServer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,28 @@ sub configureNginxConfig

my $host = $ENV{'WPR_DOMAIN_NAME'};
my $virtual_dir = $ENV{'WPR_VIRTUAL_DIR'};

my $is_root_path = ($virtual_dir eq '/' || $virtual_dir eq '');

if (-e $nginxConf)
{
if ($host ne "")
{
# Change server name inside NGINX config
replaceFileContent('server_name [\w.-]*;', "server_name $host;", $nginxConf);
}

if ($virtual_dir ne "")
{
# Change virtual dir inside NGINX config
replaceFileContent('location \/.*? {', "location /$virtual_dir {", $nginxConf);
replaceFileContent('location \/.*?/samples {', "location /$virtual_dir/samples {", $nginxConf);
replaceFileContent('location \/.*?/wscbundle/ {', "location /$virtual_dir/wscbundle/ {", $nginxConf);
replaceFileContent('location \/.*?/api {', "location /$virtual_dir/api {", $nginxConf);
}

# Normalize virtual_dir: remove leading/trailing slashes
$virtual_dir =~ s/^\///;
$virtual_dir =~ s/\/$//;

my $vdir = $is_root_path ? '' : '/' . $virtual_dir;

# Change virtual dir inside NGINX config
my $main_location = $is_root_path ? '/' : $vdir;
replaceFileContent('location \/.*? {', "location $main_location {", $nginxConf);
replaceFileContent('location \/.*?/samples {', "location ${vdir}/samples {", $nginxConf);
replaceFileContent('location \/.*?/wscbundle/ {', "location ${vdir}/wscbundle/ {", $nginxConf);
replaceFileContent('location \/.*?/api {', "location ${vdir}/api {", $nginxConf);
}
}

Expand Down
9 changes: 7 additions & 2 deletions files/startService.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ fi
# Generate self-signed certificates if HTTPS is enabled and no certs are provided
if [ "$WPR_PROTOCOL" = "1" ]; then
if [ ! -f "${WPR_CERT_DIR}/${WPR_CERT_FILE_NAME}" ] || [ ! -f "${WPR_CERT_DIR}/${WPR_CERT_KEY_NAME}" ]; then
echo "$(date '+%m/%d/%y:%H:%M:%S.%3N') No SSL certificates found. Generating self-signed certificate for CN=${WPR_DOMAIN_NAME:-localhost}..."
# Use localhost as CN when WPR_DOMAIN_NAME is unset, empty, or '_' (NGINX catch-all)
CERT_CN="${WPR_DOMAIN_NAME:-localhost}"
if [ "$CERT_CN" = "_" ]; then
CERT_CN="localhost"
fi
echo "$(date '+%m/%d/%y:%H:%M:%S.%3N') No SSL certificates found. Generating self-signed certificate for CN=${CERT_CN}..."
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout "${WPR_CERT_DIR}/${WPR_CERT_KEY_NAME}" \
-out "${WPR_CERT_DIR}/${WPR_CERT_FILE_NAME}" \
-subj "/CN=${WPR_DOMAIN_NAME:-localhost}" 2>/dev/null
-subj "/CN=${CERT_CN}" 2>/dev/null
echo "$(date '+%m/%d/%y:%H:%M:%S.%3N') Self-signed certificate created: ${WPR_CERT_DIR}/${WPR_CERT_FILE_NAME}, ${WPR_CERT_DIR}/${WPR_CERT_KEY_NAME}"
echo "$(date '+%m/%d/%y:%H:%M:%S.%3N') For production, mount real certificates to ${WPR_CERT_DIR}/"
fi
Expand Down