Hash :
de7c675e
Author :
Thomas de Grivel
Date :
2022-12-31T19:47:14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
## kmxgit
## Copyright 2022 kmx.io <contact@kmx.io>
##
## Permission is hereby granted to use this software granted
## the above copyright notice and this permission paragraph
## are included in all copies and substantial portions of this
## software.
##
## THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
## PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
## THIS SOFTWARE.
defmodule KmxgitWeb.Router do
use KmxgitWeb, :router
import KmxgitWeb.UserAuth
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, {KmxgitWeb.LayoutView, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :fetch_current_user
end
pipeline :api do
plug :accepts, ["json"]
end
pipeline :recaptcha do
plug PlugRecaptcha2, recaptcha_secret: Application.compile_env(:kmxgit, :recaptcha_secret)
end
pipeline :admin do
plug Kmxgit.Plug.EnsureAdmin
plug :put_root_layout, {KmxgitWeb.LayoutView, "admin.html"}
end
# maybe logged in
scope "/", KmxgitWeb do
pipe_through [:browser]
get "/", PageController, :index
get "/_etc/git/auth.conf", PageController, :auth
get "/_etc/ssh/authorized_keys", PageController, :keys
get "/_new_admin", PageController, :new_admin
post "/_new_admin", PageController, :new_admin_post
get "/_privacy", PageController, :privacy
get "/robots.txt", PageController, :robots
get "/_sitemap.txt", PageController, :sitemap
get "/_user_agreement", PageController, :user_agreement
delete "/_log_out", UserSessionController, :delete
get "/_confirm", UserConfirmationController, :new
post "/_confirm", UserConfirmationController, :create
get "/_confirm/:token", UserConfirmationController, :edit
post "/_confirm/:token", UserConfirmationController, :update
get "/_avatar/:login/:size/avatar.png", UserController, :avatar
scope "/_doc" do
scope "/git" do
get "/install", PageController, :doc_git_install
end
end
scope "/_error" do
get "/*code", ErrorController, :show
end
end
## Authentication routes
scope "/", KmxgitWeb do
pipe_through [:browser, :redirect_if_user_is_authenticated]
get "/_log_in", UserSessionController, :new
get "/_register", UserRegistrationController, :new
get "/_reset_password", UserResetPasswordController, :new
get "/_reset_password/:token", UserResetPasswordController, :edit
put "/_reset_password/:token", UserResetPasswordController, :update
pipe_through :recaptcha
post "/_log_in", UserSessionController, :create
post "/_register", UserRegistrationController, :create
post "/_reset_password", UserResetPasswordController, :create
end
scope "/", KmxgitWeb do
pipe_through [:browser, :require_authenticated_user]
get "/_settings", UserSettingsController, :edit
put "/_settings", UserSettingsController, :update
get "/_settings/confirm_email/:token", UserSettingsController, :confirm_email
scope "/_new" do
get "/organisation", OrganisationController, :new
post "/organisation", OrganisationController, :create
get "/repository/:owner", RepositoryController, :new
post "/repository/:owner", RepositoryController, :create
end
scope "/_edit/" do
get "/organisation/:slug", OrganisationController, :edit
put "/organisation/:slug", OrganisationController, :update
get "/user/:login", UserController, :edit
put "/user/:login", UserController, :update
get "/user/:login/totp", UserController, :totp
put "/user/:login/totp", UserController, :totp_update
delete "/user/:login/totp", UserController, :totp_delete
get "/repository/:owner/*slug", RepositoryController, :edit
put "/repository/:owner/*slug", RepositoryController, :update
end
scope "/_add_user/" do
get "/:slug", OrganisationController, :add_user
post "/:slug", OrganisationController, :add_user_post
get "/:owner/*slug", RepositoryController, :add_user
post "/:owner/*slug", RepositoryController, :add_user_post
end
scope "/_remove_user/" do
get "/:slug", OrganisationController, :remove_user
post "/:slug", OrganisationController, :remove_user_post
get "/:owner/*slug", RepositoryController, :remove_user
post "/:owner/*slug", RepositoryController, :remove_user_post
end
scope "/_delete/" do
delete "/organisation/:slug", OrganisationController, :delete
delete "/user/:login", UserController, :delete
delete "/repository/:owner/*slug", RepositoryController, :delete
end
scope "/_fork/" do
get "/:owner/*slug", RepositoryController, :fork
post "/:owner/*slug", RepositoryController, :fork_post
end
scope "/_admin", Admin, as: "admin" do
pipe_through :admin
get "/", DashboardController, :index
resources "/organisations", OrganisationController do
get "/add_user/", OrganisationController, :add_user, as: :""
post "/add_user", OrganisationController, :add_user_post, as: :""
get "/remove_user", OrganisationController, :remove_user, as: :""
post "/remove_user", OrganisationController, :remove_user_post, as: :""
end
resources "/repositories", RepositoryController do
get "/add_user", RepositoryController, :add_user, as: :""
post "/add_user", RepositoryController, :add_user_post, as: :""
get "/remove_user", RepositoryController, :remove_user, as: :""
post "/remove_user", RepositoryController, :remove_user_post, as: :""
end
resources "/users", UserController do
get "/password/edit", UserController, :edit_password, as: :""
put "/password", UserController, :update_password, as: :""
end
import Phoenix.LiveDashboard.Router
live_dashboard "/dashboard", metrics: KmxgitWeb.Telemetry
end
end
if Mix.env() == :dev do
scope "/_dev" do
pipe_through :browser
forward "/mailbox", Plug.Swoosh.MailboxPreview
scope "/test_git_nif", KmxgitWeb do
get "/:fun/:count", TestGitNifController, :test
end
end
end
scope "/", KmxgitWeb do
pipe_through [:browser]
get "/:slug", SlugController, :show
get "/:login/_ssh_keys", UserController, :ssh_keys
get "/:owner/*slug", RepositoryController, :show
match :*, "/*path", PageController, :not_found
end
if Mix.env() != :dev do
use Plug.ErrorHandler
@impl Plug.ErrorHandler
def handle_errors(conn, %{kind: :error, reason: %Elixir.Plug.CSRFProtection.InvalidCSRFTokenError{}}) do
send_resp(conn, conn.status, "Error !")
end
def handle_errors(conn, params) do
IO.inspect(params)
Discord.error(conn, params)
send_resp(conn, conn.status, "Error ! We have been notified, please retry later.")
end
end
end