diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..a041dd0 Binary files /dev/null and b/.DS_Store differ diff --git a/conf/config.conf.example b/conf/config.conf.example new file mode 100644 index 0000000..c61ea25 --- /dev/null +++ b/conf/config.conf.example @@ -0,0 +1,128 @@ +# 1 = Debug; 2 = Info; 3 = Warn; +logLevel = 3 + +# Enable the built in identd server (listens on port 113) +identd = false + +# The name of this gateway as reported in WEBIRC to IRC servers +gateway_name = "webircgateway" + +# A secret string used for generating client JWT tokens. Do not share this! +secret = "" + +# Send the server a quit message when the client is closed +# Comment out to disable +send_quit_on_client_close = "Client closed" + +[verify] +recaptcha_url = "https://www.google.com/recaptcha/api/siteverify" +#recaptcha_url = "https://hcaptcha.com/siteverify" +recaptcha_secret = "" +recaptcha_key = "" + +# If required, a client must always pass a captcha challenge before making an IRC connection +required = false + +[clients] +# Default username / realname for IRC connections. If disabled it will use +# the values provided from the IRC client itself. +# %a will be replaced with the users ip address +# %h will be replaced with the users hostname +# %i will be replaced with a hexed value of the users IP +# %n will be replaced with the client provided nick +username = "%i" +realname = "I am a webchat user" + +# This hostname value will only be used when using a WEBIRC password +#hostname = "%h" + +# The websocket / http server +[server.1] +bind = "0.0.0.0" +port = 80 + +# Example TLS server +#[server.2] +#bind = "0.0.0.0" +#port = 443 +#tls = true +#cert = server.crt +#key = server.key +# If you don't have a certificate, uncomment the below line to automatically generate a +# free certificate using letsencrypt.com (overrides the above cert/key options). This requires +# a server running on port 80 to initially generate the certificate. +#letsencrypt_cache = ./certs + +# Example unix socket server +#[server.3] +#bind = unix:/tmp/webircgateway.sock +#bind_mode = 0777 + +# Serve static files from a web root folder. +# Optional, but handy for serving the Kiwi IRC client if no other webserver is available +[fileserving] +enabled = true +webroot = www/ + +[transports] +websocket +sockjs +kiwiirc + +# Websites (hostnames) that are allowed to connect here +# No entries here will allow any website to connect. +# Origins do not include a trailing / after the host and optional port +[allowed_origins] +#*://example.com + +# If using a reverse proxy, it must be whitelisted for the client +# hostnames to be read correctly. In CIDR format. +# The user IPs are read from the standard X-Forwarded-For HTTP header +[reverse_proxies] +127.0.0.0/8 +10.0.0.0/8 +172.16.0.0/12 +192.168.0.0/16 +"::1/128" +"fd00::/8" + +# Connections will be sent to a random upstream +[upstream.1] +hostname = "irc.kiwiirc.com" +port = 6667 +tls = false +# Connection timeout in seconds +timeout = 5 +# Throttle the lines being written by X per second +throttle = 2 +# Webirc password as set in the IRC server config +webirc = "" +serverpassword = "" + + +# A public gateway to any IRC network +# If enabled, Kiwi IRC clients may connect to any IRC network (or a whitelisted +# network below) through the kiwiirc engine +[gateway] +enabled = false +timeout = 5 +throttle = 2 + +# Whitelisted IRC networks while in public gateway mode +# If any networks are in this list then connections can only be made to these +[gateway.whitelist] +#irc.example.com +#*.example2.com + +# Webirc passwords used when running in the public gateway mode +[gateway.webirc] +irc.network.org = webirc_password +irc.network2.org = webirc_password + +[dnsbl] +# "verify" - if the client supports it, tell it to show a captcha +# "deny" - deny the connection entirely +action = deny + +[dnsbl.servers] +dnsbl.dronebl.org diff --git a/conf/config.json.example b/conf/config.json.example index cbb6d92..c8fa37c 100644 --- a/conf/config.json.example +++ b/conf/config.json.example @@ -1,7 +1,7 @@ { "windowTitle": "Kiwi IRC - The web IRC client", "startupScreen": "welcome", - "kiwiServer": "https://localdev.clients.kiwiirc.com/webirc/kiwiirc/", + "kiwiServer": "https://__DOMAIN__/webirc/kiwiirc/", "restricted": false, "theme": "Default", "themes": [ diff --git a/conf/systemd.service b/conf/systemd.service new file mode 100644 index 0000000..cb2dbb9 --- /dev/null +++ b/conf/systemd.service @@ -0,0 +1,14 @@ +[Unit] +Description=Websocket gateway to IRC networks +Documentation=https://github.com/kiwiirc/webircgateway +After=network.target + +[Service] +User=http +Group=http +ExecStart=/var/www/webircgateway/webircgateway --config=/var/www/webircgateway/config.conf +ExecReload=/usr/bin/kill -USR1 $MAINPID +LimitNOFILE=1048576 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index 5def960..248181b 100644 --- a/scripts/backup +++ b/scripts/backup @@ -46,6 +46,12 @@ ynh_backup --src_path="$final_path" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup --src_path="/etc/systemd/system/$app.service" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index 7437741..1e7004e 100644 --- a/scripts/install +++ b/scripts/install @@ -40,6 +40,8 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url +webircgateway_path=/var/www/webircgateway + #================================================= # STORE SETTINGS FROM MANIFEST #================================================= @@ -67,6 +69,8 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" +mv ../sources/webircgateway/* $webircgateway_path + #================================================= # NGINX CONFIGURATION #================================================= @@ -83,21 +87,28 @@ ynh_script_progression --message="Configuring system user..." --weight=3 # Create a system user ynh_system_user_create --username=$app --home_dir=$final_path -# #================================================= -# # MODIFY A CONFIG FILE -# #================================================= -# ynh_script_progression --message="Modifying a config file..." +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Configuring a systemd service..." --weight=1 -# cp ../conf/config.json.example "$final_path/static/config.json" +# Create a dedicated systemd config +ynh_add_systemd_config -# # Main config File -# ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/config.json" -# ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/config.json" -# ynh_replace_string --match_string="__PATH__" --replace_string="${path_url:1}" --target_file="$final_path/config.json" +#================================================= +# MODIFY A CONFIG FILE +#================================================= +ynh_script_progression --message="Modifying a config file..." -# ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$final_path/config.json" +cp ../conf/config.json.example "$final_path/static/config.json" -# ynh_store_file_checksum --file="$final_path/config.json" +# Main config File +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/config.json" + +cp ../conf/config.conf.example "$webircgateway_path/config.conf" + +ynh_store_file_checksum --file="$final_path/config.json" +ynh_store_file_checksum --file="$webircgateway_path/config.conf" #================================================= # SECURE FILES AND DIRECTORIES @@ -107,6 +118,21 @@ ynh_script_progression --message="Securing files and directories..." # Set permissions to app files chown -R $app:$app $final_path +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1 + +yunohost service add $app --description "A short description of the app" --log "/var/log/$app/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + #================================================= # SETUP SSOWAT #================================================= diff --git a/scripts/remove b/scripts/remove index be7dda3..622cfa6 100644 --- a/scripts/remove +++ b/scripts/remove @@ -20,6 +20,26 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) port=$(ynh_app_setting_get --app=$app --key=port) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +#================================================= +# STANDARD REMOVE +#================================================= +# REMOVE SERVICE INTEGRATION IN YUNOHOST +#================================================= + +if ynh_exec_warn_less yunohost service status $app >/dev/null +then + ynh_script_progression --message="Removing $app service integration..." --weight=1 + yunohost service remove $app +fi + +#================================================= +# STOP AND REMOVE SERVICE +#================================================= +ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 + +# Remove the dedicated systemd config +ynh_remove_systemd_config + #================================================= # REMOVE APP MAIN DIR #================================================= diff --git a/scripts/restore b/scripts/restore index f36582a..f5481c0 100644 --- a/scripts/restore +++ b/scripts/restore @@ -70,6 +70,28 @@ ynh_script_progression --message="Restoring user rights..." --weight=1 # Restore permissions on app files chown -R $app:$app $final_path +#================================================= +# RESTORE SYSTEMD +#================================================= +ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 + +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +systemctl enable $app.service + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 + +yunohost service add $app --description "A short description of the app" --log "/var/log/$app/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + #================================================= # RELOAD NGINX #=================================================