Moved passwd out of resources/public, which was wantonly insecure, into

resources.
This commit is contained in:
Simon Brooke 2015-01-10 08:18:25 +00:00
parent 4444664bdf
commit eb5b82fbca
4 changed files with 27 additions and 5 deletions

View file

@ -1,4 +1,7 @@
(ns smeagol.authenticate (:require [noir.io :as io])) (ns smeagol.authenticate
(:use clojure.walk)
(:require [taoensso.timbre :as timbre]
[noir.io :as io]))
;; Smeagol: a very simple Wiki engine ;; Smeagol: a very simple Wiki engine
;; Copyright (C) 2014 Simon Brooke ;; Copyright (C) 2014 Simon Brooke
@ -20,9 +23,10 @@
(defn authenticate (defn authenticate
"Return `true` if this `username`/`password` pair match, `false` otherwise" "Return `true` if this `username`/`password` pair match, `false` otherwise"
[username password] [username password]
(let [path (str (io/resource-path) "passwd") (let [path (str (io/resource-path) "../passwd")
users (read-string (slurp path)) users (read-string (slurp path))
user (keyword username)] user (keyword username)]
(timbre/info (str "Authenticating " username " against " path))
(.equals (:password (user users)) password))) (.equals (:password (user users)) password)))
(defn get-email (defn get-email

View file

@ -2,6 +2,23 @@
(:require [clj-jgit.porcelain :as git] (:require [clj-jgit.porcelain :as git]
[clj-jgit.querying :as q])) [clj-jgit.querying :as q]))
;; Smeagol: a very simple Wiki engine
;; Copyright (C) 2014 Simon Brooke
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 2
;; of the License, or (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
(defn entry-contains (defn entry-contains
"If this `log-entry` contains a reference to this `file-path`, return the entry; "If this `log-entry` contains a reference to this `file-path`, return the entry;
else nil." else nil."

View file

@ -23,6 +23,7 @@
[noir.response :as response] [noir.response :as response]
[noir.util.route :as route] [noir.util.route :as route]
[noir.session :as session] [noir.session :as session]
[taoensso.timbre :as timbre]
[smeagol.authenticate :as auth] [smeagol.authenticate :as auth]
[smeagol.layout :as layout] [smeagol.layout :as layout]
[smeagol.util :as util] [smeagol.util :as util]
@ -49,6 +50,7 @@
user (session/get :user) user (session/get :user)
email (auth/get-email user) email (auth/get-email user)
summary (:summary params)] summary (:summary params)]
(timbre/info (str "Saving " user "'s changes (" summary ") to " file-name))
(spit file-path source-text) (spit file-path source-text)
(if (not exists?) (git/git-add git-repo file-name)) (if (not exists?) (git/git-add git-repo file-name))
(git/git-commit git-repo summary {:name user :email email}) (git/git-commit git-repo summary {:name user :email email})
@ -106,12 +108,10 @@
:header (local-links (util/md->html "/content/_header.md")) :header (local-links (util/md->html "/content/_header.md"))
:history (hist/find-history (io/resource-path) file-name)}))) :history (hist/find-history (io/resource-path) file-name)})))
(defn auth-page (defn auth-page
"Render the auth page" "Render the auth page"
[request] [request]
(let [params (keywordize-keys (:params request)) (let [params (keywordize-keys (:form-params request))
username (:username params) username (:username params)
password (:password params) password (:password params)
action (:action params) action (:action params)
@ -119,6 +119,7 @@
(cond (cond
(= action "Logout!") (= action "Logout!")
(do (do
(timbre/info (str "User " user " logging out"))
(session/remove! :user) (session/remove! :user)
(response/redirect "/wiki")) (response/redirect "/wiki"))
(and username password (auth/authenticate username password)) (and username password (auth/authenticate username password))