generated from NethServer/ns8-kickstart
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sftpgo container and configuration
- Loading branch information
Showing
6 changed files
with
119 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import json | ||
import os | ||
import sys | ||
import agent | ||
import subprocess | ||
|
||
|
||
sftpgo_config_path = "sftpgo.conf.d/sftpgo.json" | ||
# Read the current configuration | ||
with open(sftpgo_config_path, 'r') as file: | ||
config = json.load(file) | ||
|
||
#update sftp server bind address port | ||
config['server']['protocols']['sftp']['bind_arrd'] = "0.0.0.0:" + os.environ['ASTERISK_RECORDING_SFTP_PORT'] | ||
|
||
# get NethVoice password from mariadb | ||
mariadb_root_passwd = agent.read_envfile("passwords.env")['MARIADB_ROOT_PASSWORD'] | ||
command = [ | ||
"/usr/bin/podman", "exec", "-it", "mariadb", | ||
"mysql", "-uroot", f"-p{mariadb_root_passwd}", "asterisk", | ||
"-e", | ||
"SELECT password_sha1 FROM ampusers WHERE username = 'admin';" | ||
] | ||
|
||
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||
if result.returncode != 0: | ||
print(f"Failed to execute command: {result.stderr}") | ||
sys.exit(1) | ||
|
||
# Update the password | ||
for user in config['users']: | ||
if user['username'] == 'nethvoice': | ||
user['password'] = '$pbkdf2-sha1$' + result.stdout.strip() | ||
|
||
|
||
# Write the updated configuration back to the file | ||
with open(sftpgo_config_path, 'w') as file: | ||
json.dump(config, file, indent=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"server": { | ||
"protocols": { | ||
"sftp": { | ||
"enabled": true, | ||
"bind_addr": "0.0.0.0:22" | ||
} | ||
} | ||
}, | ||
"users": [ | ||
{ | ||
"username": "nethvoice", | ||
"password": "", | ||
"home_dir": "/srv/sftpgo/moh", | ||
"permissions": { | ||
"/srv/sftpgo/moh": ["*"] | ||
}, | ||
"filesystem": { | ||
"provider": "local", | ||
"params": { | ||
"base_directory": "/srv/sftpgo/moh" | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[Unit] | ||
Description=Podman sftpgo.service | ||
After=nginx.service | ||
|
||
[Service] | ||
Environment=PODMAN_SYSTEMD_UNIT=%n | ||
EnvironmentFile=%S/state/environment | ||
WorkingDirectory=%S/state | ||
Restart=always | ||
TimeoutStopSec=70 | ||
ExecStartPre=/bin/rm -f %t/sftpgo.pid %t/sftpgo.ctr-id | ||
ExecStart=/usr/bin/podman run --conmon-pidfile %t/sftpgo.pid \ | ||
--cidfile %t/sftpgo.ctr-id --cgroups=no-conmon \ | ||
--replace \ | ||
--detach \ | ||
--name sftpgo \ | ||
--volume moh:/srv/sftpgo/data:z \ | ||
--volume sftpgo_config:/var/lib/sftpgo:Z \ | ||
--volume %S/state/sftpgo.conf.d/admin.json:/etc/sftpgo/admin.json:Z \ | ||
--env SFTPGO_LOADDATA_FROM=/etc/sftpgo/admin.json \ | ||
--env SFTPGO_HTTPD__WEB_ROOT=${TRAEFIK_PATH}\ | ||
--env-file=%S/state/passwords.env \ | ||
--user 0:0 \ | ||
${SFTPGO_IMAGE} | ||
ExecStartPost=/usr/bin/bash -c "while [[ $(curl --request GET --url http://localhost:${SFTPGO_TCP_PORT}/healthz --header 'Accept: text/plain; charset=utf-8') != ok ]]; do sleep 3 ; done" | ||
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/sftpgo.ctr-id -t 10 | ||
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/sftpgo.ctr-id | ||
PIDFile=%t/sftpgo.pid | ||
Type=forking | ||
|
||
[Install] | ||
WantedBy=default.target |