# caddyfile for omv
# 2022-04 add domain sites
# 2022-03 init
{
	admin 0.0.0.0:2015
	email bunce.andy@gmail.com
}

# Physical
(omv) { 
	reverse_proxy 192.168.1.6:{args[0]}
}
(n2) {
	reverse_proxy 192.168.1.4:{args[0]}
}
(n2plus) {
	reverse_proxy 192.168.1.10:{args[0]}
}
(xu4) {
	reverse_proxy 192.168.1.5:{args[0]}
}
(fins) {
	reverse_proxy 192.168.1.9:{args[0]}
}
(evo-x2) {
	reverse_proxy 192.168.1.11:{args[0]}
}
# DNS
(duckdns) {
	tls {
		dns duckdns {
		    api_token 428a1b3b-bc1d-4906-a230-9cd0a72fd06b
		}
    }
}

# Auth
(auth_quodatum) {
	basic_auth bcrypt "Quodatum domain access" {
		andy JDJhJDE0JDFHeUJHdGdZalFRdDg0cWhsRTFXeXU0cWZqZDNCNVV1d2gyRUlaNXhBMDFiZEFBZk5zM2RD
    	guest JDJhJDE0JDVYTENVREtLbG5xdzUyNXFGdm56Ti5rVmFSZ3VoOEZQR015V0F6VjdaMk1SeGM1NXVVeWR1
	}	
}
(auth) {
	basic_auth bcrypt "Orlop domain" {
		andy JDJhJDE0JDFHeUJHdGdZalFRdDg0cWhsRTFXeXU0cWZqZDNCNVV1d2gyRUlaNXhBMDFiZEFBZk5zM2RD
    	solange JDJhJDE0JE9kcjNWY1U4VS54M2IwUmJuV1UwYS41SDRQQi9Kc2lDUDBKUkpkVjNVc1I2dUNyYzl5MU9x
	}	
}
# quodatum domain -------------------------------
quodatum.duckdns.org {
	redir https://about.quodatum.duckdns.org
}

*.quodatum.duckdns.org {
	import duckdns
#	import auth_quodatum

	@quodatum host about.quodatum.duckdns.org 
	handle @quodatum {
		import auth_quodatum	
		encode zstd gzip
		root * quodatum
		file_server browse
	}
	
	@git host git.quodatum.duckdns.org
	handle @git {
		import omv 8300
	}

	@wiki host wiki.quodatum.duckdns.org
	handle @wiki {
#		import auth_quodatum
		import xu4 8088
	}
	@wiki_alt host wiki-alt.quodatum.duckdns.org
	handle @wiki_alt {
#		import auth_quodatum	
		import n2plus 8088
	}

	@code host code.quodatum.duckdns.org
	handle @code {
		import auth_quodatum
		import n2plus 8444
	}
	
	@code-alt host code-alt.quodatum.duckdns.org
	handle @code-alt {
		import auth_quodatum
		import omv 8444
	}

	@warden host warden.quodatum.duckdns.org:443
	handle @warden {
        reverse_proxy /notifications/hub 0.0.0.0:3012
        reverse_proxy 0.0.0.0:8882 {
           header_up X-Real-IP {remote_host}
        }
	}
	
	@nextcloud host nextcloud.quodatum.duckdns.org
	handle @nextcloud {
		import auth_quodatum
		import omv 8090
	}
	
	@code-bmy host code-bmy.quodatum.duckdns.org
    handle @code-bmy {
		import auth_quodatum
		import omv 8448
	}
	@shark host shark.quodatum.duckdns.org
    handle @shark {
		import auth_quodatum
	    import xu4 4000
	}
	@oi host oi.quodatum.duckdns.org
    handle @oi {
#		import auth_quodatum
		import fins 3001
	}
	@ai host ai.quodatum.duckdns.org
    handle @ai {
#		import auth_quodatum
		import evo-x2 3001
	}
	@comfy host comfy.quodatum.duckdns.org
    handle @comfy {
#		import auth_quodatum
		import evo-x2 8188
	}			
    # Fallback for otherwise unhandled domains
	handle {
		abort
	}
}
# orlop domain ------------------------------------
orlop.duckdns.org {
	redir https://about.orlop.duckdns.org
}

*.orlop.duckdns.org {
   import duckdns
#  import auth
   
    @orlop host about.orlop.duckdns.org 
	handle @orlop {
		import auth	
		encode zstd gzip
		root * orlop
		file_server browse
	}

	@jellyfin host jellyfin.orlop.duckdns.org
	handle @jellyfin {
		import omv 8096
	}
	@emby host emby.orlop.duckdns.org
	handle @emby {
		import omv 8097
	}
	@immich host immich.orlop.duckdns.org
	handle @immich {
		 import omv 2283
	}
	@tvheadend host tvheadend.orlop.duckdns.org
	handle @tvheadend {
		 import n2plus 9981
	}
	@kodi host kodi.orlop.duckdns.org
	handle @kodi {
		 import n2 8080
	}
	@recipe host recipes.orlop.duckdns.org
	handle @recipe {
		 import n2plus 9925
	}
	
	@test host test.orlop.duckdns.org
	handle @test {
		respond "test, test. Hello, world!"
	}
	# Fallback for otherwise unhandled domains
	handle {
		abort
	}
}
# local domain
odroid.lan {
	tls internal
	import auth

	encode zstd gzip
    root .
    file_server browse
}
xu4.lan {
	tls internal
	import auth

	encode zstd gzip
    root * links
    file_server browse
}
warden.lan:443 {
	tls "bunce.andy@gmail.com"
	reverse_proxy 0.0.0.0:8882
    reverse_proxy /notifications/hub 0.0.0.0:3012
}