diff --git a/Makefile b/Makefile index 832af07..1b2e0b3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # starts the app in :dev mode run: - @DEVMODE=1 lein run + @DEVMODE=1 lein ring server server: redis-server & diff --git a/project.clj b/project.clj index 0b07866..517c701 100644 --- a/project.clj +++ b/project.clj @@ -1,10 +1,13 @@ (defproject NoteHub "2.0.0" - :description "A free and anonymous hosting for markdown pages." - :dependencies [[org.clojure/clojure "1.5.1"] - [hiccup "1.0.0"] - [cheshire "5.3.1"] - [ring/ring-core "1.1.0"] - [com.taoensso/carmine "2.4.4"] - [noir "1.3.0-beta1"]] - :jvm-opts ["-Dfile.encoding=utf-8"] - :main NoteHub.server) + :description "A free and anonymous hosting for markdown pages." + :dependencies [[org.clojure/clojure "1.5.1"] + [hiccup "1.0.0"] + [cheshire "5.3.1"] + [ring/ring-core "1.1.0"] + [com.taoensso/carmine "2.4.4"] + [compojure "1.1.6"]] + :plugins [[lein-ring "0.8.10"]] + :ring {:handler notehub.handler/app} + :profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"] + [ring-mock "0.1.5"]]}} + :jvm-opts ["-Dfile.encoding=utf-8"]) diff --git a/src/NoteHub/api.clj b/src/NoteHub/api.clj index e0d1f33..52af85c 100644 --- a/src/NoteHub/api.clj +++ b/src/NoteHub/api.clj @@ -1,15 +1,15 @@ -(ns NoteHub.api +(ns notehub.api (:import [java.util Calendar]) (:use - [NoteHub.settings] + [notehub.settings] [ring.util.codec :only [url-encode]] [clojure.string :rename {replace sreplace} :only [replace blank? lower-case split-lines split]]) (:require [ring.util.codec] [hiccup.util :as util] - [NoteHub.storage :as storage])) + [notehub.storage :as storage])) (def version "1.1") @@ -60,15 +60,6 @@ (str domain "/" (storage/create-short-url token {:year year :month month :day day :title title})) (str domain (url year month day title)))))) -(let [md5Instance (java.security.MessageDigest/getInstance "MD5")] - (defn get-signature - "Returns the MD5 hash for the concatenation of all passed parameters" - [& args] - (let [input (sreplace (apply str args) #"[\r\n]" "")] - (do (.reset md5Instance) - (.update md5Instance (.getBytes input)) - (.toString (new java.math.BigInteger 1 (.digest md5Instance)) 16))))) - (defn get-note [noteID] (if (storage/note-exists? noteID) (let [note (storage/get-note noteID)] @@ -87,7 +78,7 @@ ;(log "post-note: %s" {:pid pid :signature signature :password password :note note}) (let [errors (filter identity [(when-not (storage/valid-publisher? pid) "pid invalid") - (when-not (= signature (get-signature pid (storage/get-psk pid) note)) + (when-not (= signature (storage/sign pid (storage/get-psk pid) note)) "signature invalid") (when (blank? note) "note is empty")])] (if (empty? errors) @@ -121,7 +112,7 @@ ;(log "update-note: %s" {:pid pid :noteID noteID :signature signature :password password :note note}) (let [errors (filter identity [(when-not (storage/valid-publisher? pid) "pid invalid") - (when-not (= signature (get-signature pid (storage/get-psk pid) noteID note password)) + (when-not (= signature (storage/sign pid (storage/get-psk pid) noteID note password)) "signature invalid") (when (blank? note) "note is empty") (when-not (storage/valid-password? noteID password) "password invalid")])] diff --git a/src/NoteHub/views/pages.clj b/src/NoteHub/handler.clj similarity index 79% rename from src/NoteHub/views/pages.clj rename to src/NoteHub/handler.clj index fe4362a..5b766b8 100644 --- a/src/NoteHub/views/pages.clj +++ b/src/NoteHub/handler.clj @@ -1,28 +1,24 @@ -(ns NoteHub.views.pages - (:require [hiccup.util :as util] - [NoteHub.api :as api] - [NoteHub.storage :as storage] - [cheshire.core :refer :all]) - (:use - [NoteHub.settings] - [clojure.string :rename {replace sreplace} - :only [escape split replace blank? split-lines lower-case]] - [clojure.core.incubator :only [-?>]] - [noir.util.crypt :only [encrypt]] - [hiccup.form] - [hiccup.core] - [hiccup.element] - [hiccup.util :only [escape-html]] - [hiccup.page :only [include-js html5]] - [noir.response :only [redirect status content-type]] - [noir.core :only [defpage defpartial]] - [noir.statuses])) +(ns notehub.handler + (:use compojure.core + [notehub.settings] + [clojure.string :rename {replace sreplace} + :only [escape split replace blank? split-lines lower-case]] + [clojure.core.incubator :only [-?>]] + [hiccup.form] + [hiccup.core] + [hiccup.element] + [hiccup.util :only [escape-html]] + [hiccup.page :only [include-js html5]]) + (:require [compojure.handler :as handler] + [compojure.route :as route] + [hiccup.util :as util] + [notehub.api :as api] + [notehub.storage :as storage] + [cheshire.core :refer :all])) -(when-not (storage/valid-publisher? "NoteHub") - (storage/register-publisher "NoteHub")) ; Creates the main html layout -(defpartial layout +(defn layout [title & content] (html5 [:head @@ -40,6 +36,32 @@ (if-not (get-setting :dev-mode) (include-js "/js/google-analytics.js"))] [:body {:onload "onLoad()"} content])) + +(defn md-node + "Returns an HTML element with a textarea inside + containing the markdown text (to keep all chars unescaped)" + ([cls input] (md-node cls {} input)) + ([cls opts input] + [(keyword (str (name cls) ".markdown")) opts + [:textarea input]])) + +#_ ( + + ; ######## OLD CODE START + +(ns NoteHub.views.pages + (:require ) + (:use + + + [noir.response :only [redirect status content-type]] + [noir.core :only [defpage defpartial]] + [noir.statuses] + [noir.util.crypt :only [encrypt]])) + +(when-not (storage/valid-publisher? "NoteHub") + (storage/register-publisher "NoteHub")) + (defn sanitize "Breakes all usages of