|
18 | 18 | use strict; |
19 | 19 | use File::Find; |
20 | 20 |
|
21 | | -# Extract the address from the config file |
| 21 | +# Extract address and port |
22 | 22 | my $address; |
23 | 23 | my $port; |
24 | 24 | open my $fh, '<', '/opt/ermis-server/configs/server-settings/general-settings.cnf' or die "Cannot open config file: $!\n"; |
|
35 | 35 | # Ensure address is not empty |
36 | 36 | die "Error: Could not extract address from config file!\n" unless $address; |
37 | 37 |
|
38 | | -# Ensure address is invalid |
| 38 | +# Ensure address is valid |
39 | 39 | if ($address eq " ------") { |
40 | 40 | die "Error: Address is invalid!\n"; |
41 | 41 | } |
42 | 42 |
|
43 | | -# Ensure address is not empty |
| 43 | +# Ensure port is not empty |
44 | 44 | die "Error: Could not extract port from config file!\n" unless $port; |
45 | 45 |
|
46 | | -# Ensure address is invalid |
| 46 | +# Ensure port is valid |
47 | 47 | if ($port eq " ------") { |
48 | 48 | die "Error: Port is invalid!\n"; |
49 | 49 | } |
50 | 50 |
|
| 51 | +# Extract donation data |
51 | 52 | my $paypal_client_id; |
52 | 53 | my $bitcoin_address; |
53 | 54 | my $monero_address; |
54 | 55 | open $fh, '<', '/opt/ermis-server/configs/donation-settings/general-settings.cnf' or die "Cannot open config file: $!\n"; |
55 | 56 | while (my $line = <$fh>) { |
56 | 57 | if ($line =~ /^paypal-client-id=(.*)$/) { |
57 | | - $paypal_client_id= $1; |
| 58 | + $paypal_client_id= $1; |
58 | 59 | } |
59 | 60 | if ($line =~ /^bitcoin-address=(.*)$/) { |
60 | 61 | $bitcoin_address = $1; |
|
65 | 66 | } |
66 | 67 | close $fh; |
67 | 68 |
|
| 69 | +# Unlike a priori - do not perform checks to validate |
| 70 | +# donation data integrity since it isn't sine qua non. |
| 71 | + |
| 72 | + |
68 | 73 | # Find all files in the target directories |
69 | | -my @dirs = ('/opt/ermis-server/configs/', '/var/ermis-server/www', '/etc/nginx/'); |
| 74 | +my @dirs = ('/var/ermis-server/www', '/etc/nginx/'); |
70 | 75 | find(sub { |
71 | 76 | return unless -f $_; # Only process files |
72 | | - # Replace SERVER_ADDRESS and SERVER_PORT with the extracted address |
| 77 | + # Replace placeholders with the extracted values |
73 | 78 | open my $in, '<', $_ or die "Cannot open file $_: $!\n"; |
74 | 79 | my @lines = <$in>; |
75 | 80 | close $in; |
76 | | - |
| 81 | + |
77 | 82 | open my $out, '>', $_ or die "Cannot write to file $_: $!\n"; |
78 | 83 | foreach my $line (@lines) { |
79 | 84 | $line =~ s/SERVER_ADDRESS/$address/g; |
|
85 | 90 | $line =~ s/XMR_ADDRESS/$monero_address/g; |
86 | 91 | print $out $line; |
87 | 92 | } |
| 93 | + |
88 | 94 | close $out; |
89 | 95 | }, @dirs); |
90 | 96 |
|
0 commit comments