diff options
-rw-r--r-- | Cargo.lock | 252 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/render/mod.rs | 183 | ||||
-rw-r--r-- | src/server.rs | 106 |
5 files changed, 443 insertions, 102 deletions
@@ -9,6 +9,8 @@ dependencies = [ "iron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "iron-sessionstorage 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "params 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "persistent 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "router 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -83,6 +85,23 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "bodyparser" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "iron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "persistent 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "buf_redux" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "byteorder" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -146,6 +165,11 @@ dependencies = [ ] [[package]] +name = "dtoa" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "env_logger" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -268,6 +292,11 @@ dependencies = [ ] [[package]] +name = "itoa" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "kernel32-sys" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -325,6 +354,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "memchr" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "memchr" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ @@ -340,6 +377,17 @@ dependencies = [ ] [[package]] +name = "mime_guess" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "mime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", + "phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "modifier" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -354,6 +402,86 @@ dependencies = [ ] [[package]] +name = "multipart" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "buf_redux 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "mime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "mime_guess 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-bigint 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-complex 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", + "num-rational 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-bigint" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-complex" +version = "0.1.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-integer" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-iter" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-rational" +version = "0.1.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-bigint 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-traits" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "num_cpus" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -386,6 +514,65 @@ dependencies = [ ] [[package]] +name = "params" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bodyparser 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "iron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "multipart 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "urlencoded 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "persistent" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "iron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "phf" +version = "0.7.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "phf_codegen" +version = "0.7.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", + "phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "phf_generator" +version = "0.7.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "phf_shared" +version = "0.7.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "pkg-config" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -506,6 +693,27 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "serde" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "serde_json" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dtoa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "siphasher" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "staticfile" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -522,6 +730,14 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "tempdir" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "term_size" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -643,6 +859,17 @@ dependencies = [ ] [[package]] +name = "urlencoded" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bodyparser 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "iron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "user32-sys" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -690,6 +917,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557" "checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" +"checksum bodyparser 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6928e817538b74a73d1dd6e9a942a2a35c632a597b6bb14fd009480f859a6bf5" +"checksum buf_redux 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "861b9d19b9f5cb40647242d10d0cb0a13de0a96d5ff8c8a01ea324fa3956eb7d" "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" "checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" "checksum clap 2.24.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b8f69e518f967224e628896b54e41ff6acfb4dcfefc5076325c36525dac900f" @@ -697,6 +926,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cookie 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8d12191219481eb202e05529f646f9af8d1ecfcd53bbf3997d4a4b15ca095cf8" "checksum cpp_demangle 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b28212beade1937ba9ab786e67e902e73e0e77427278368ee876a6d9f70507c" "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" +"checksum dtoa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0dd841b58510c9618291ffa448da2e4e0f699d984d436122372f446dae62263d" "checksum env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e3856f1697098606fc6cb97a93de88ca3f3bc35bb878c725920e6e82ecf05e83" "checksum error 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "a6e606f14042bb87cc02ef6a14db6c90ab92ed6f62d87e69377bc759fd7987cc" "checksum error-chain 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "318cb3c71ee4cdea69fdc9e15c173b245ed6063e1709029e8fd32525a881120f" @@ -711,6 +941,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum idna 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6ac85ec3f80c8e4e99d9325521337e14ec7555c458a14e377d189659a427f375" "checksum iron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2440ae846e7a8c7f9b401db8f6e31b4ea5e7d3688b91761337da7e054520c75b" "checksum iron-sessionstorage 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "e609d6824dbc56e514638d22fa23bf3745d9257d066f664a3f930623bfa49d57" +"checksum itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae3088ea4baeceb0284ee9eea42f591226e6beaecf65373e41b38d95a1b8e7a1" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" @@ -720,13 +951,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5141eca02775a762cc6cd564d8d2c50f67c0ea3a372cbf1c51592b3e029e10ad" "checksum lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4d06ff7ff06f729ce5f4e227876cb88d10bc59cd4ae1e09fbb2bde15c850dc21" "checksum matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efd7622e3022e1a6eaa602c4cea8912254e5582c9c692e9167714182244801b1" +"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" "checksum mime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9d69889cdc6336ed56b174514ce876c4c3dc564cc23dd872e7bca589bb2a36c8" +"checksum mime_guess 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76da6df85047af8c0edfa53f48eb1073012ce1cc95c8fedc0a374f659a89dd65" "checksum modifier 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "41f5c9112cb662acd3b204077e0de5bc66305fa8df65c8019d5adb10e9ab6e58" "checksum mount 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32245731923cd096899502fc4c4317cfd09f121e80e73f7f576cf3777a824256" +"checksum multipart 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b16d6498fe5b0c2f6d973fd9753da099948834f96584d628e44a75f0d2955b03" +"checksum num 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "2c3a3dc9f30bf824141521b30c908a859ab190b76e20435fcd89f35eb6583887" +"checksum num-bigint 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "6361748d02e5291c72a422dc8ed4d8464a80cb1e618971f6fffe6d52d97e3286" +"checksum num-complex 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "412dfc143c56579aa6a22c574e38ddbf724522f1280ae2b257498cccff3fb6af" +"checksum num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "ef1a4bf6f9174aa5783a9b4cc892cacd11aebad6c69ad027a0b65c6ca5f8aa37" +"checksum num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d1891bd7b936f12349b7d1403761c8a0b85a18b148e9da4429d5d102c1a41e" +"checksum num-rational 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "33c881e104a26e1accc09449374c095ff2312c8e0c27fab7bbefe16eac7c776d" +"checksum num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "1708c0628602a98b52fad936cf3edb9a107af06e52e49fdf0707e884456a6af6" "checksum num_cpus 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca313f1862c7ec3e0dfe8ace9fa91b1d9cb5c84ace3d00f5ec4216238e93c167" "checksum openssl 0.9.12 (registry+https://github.com/rust-lang/crates.io-index)" = "bb5d1663b73d10c6a3eda53e2e9d0346f822394e7b858d7257718f65f61dfbe2" "checksum openssl-sys 0.9.12 (registry+https://github.com/rust-lang/crates.io-index)" = "3a5886d87d3e2a0d890bf62dc8944f5e3769a405f7e1e9ef6e517e47fd7a0897" +"checksum params 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "421e9f2c30e80365c9672709be664bfc84f73b088720d1cc1f4e99675814bb37" +"checksum persistent 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c9c94f2ef72dc272c6bcc8157ccf2bc7da14f4c58c69059ac2fc48492d6916" +"checksum phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "cb325642290f28ee14d8c6201159949a872f220c62af6e110a56ea914fbe42fc" +"checksum phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "d62594c0bb54c464f633175d502038177e90309daf2e0158be42ed5f023ce88f" +"checksum phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6b07ffcc532ccc85e3afc45865469bf5d9e4ef5bfcf9622e3cfe80c2d275ec03" +"checksum phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "07e24b0ca9643bdecd0632f2b3da6b1b89bbb0030e0b992afc1113b23a7bc2f2" "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" "checksum plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a6a0dc3910bc8db877ffed8e457763b317cf880df4ae19109b9f77d277cf6e0" "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" @@ -743,8 +990,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" "checksum sequence_trie 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c915714ca833b1d4d6b8f6a9d72a3ff632fe45b40a8d184ef79c81bec6327eed" +"checksum serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8" +"checksum serde_json 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "67f7d2e9edc3523a9c8ec8cd6ec481b3a27810aafee3e625d311febd3e656b4c" +"checksum siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0df90a788073e8d0235a67e50441d47db7c8ad9debd91cbf43736a2a92d36537" "checksum staticfile 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "31493480e073d52522a94cdf56269dd8eb05f99549effd1826b0271690608878" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" +"checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6" "checksum term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b6b55df3198cc93372e85dd2ed817f0e38ce8cc0f22eb32391bfad9c4bf209" "checksum termios 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d9cf598a6d7ce700a4e6a9199da127e6819a61e64b68609683cc9a01b5683a" "checksum thread-id 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8df7875b676fddfadffd96deea3b1124e5ede707d4884248931077518cf1f773" @@ -761,6 +1012,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91" "checksum unsafe-any 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b351086021ebc264aea3ab4f94d61d889d98e5e9ec2d985d993f50133537fd3a" "checksum url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5ba8a749fb4479b043733416c244fa9d1d3af3d7c23804944651c8a448cb87e" +"checksum urlencoded 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8c28708636d6f7298a53b1cdb6af40f1ab523209a7cb83cf4d41b3ebc671d319" "checksum user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ef4711d107b21b410a3a974b1204d9accc8b10dad75d8324b5d755de1617d47" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b" @@ -17,3 +17,5 @@ rust-crypto = "*" base64 = "*" clap = "*" rpassword = "*" +params = "*" +persistent = "*" @@ -13,6 +13,8 @@ extern crate env_logger; extern crate iron_sessionstorage; extern crate staticfile; extern crate regex; +extern crate params; +extern crate persistent; pub mod systemd; pub mod render; diff --git a/src/render/mod.rs b/src/render/mod.rs index a824bd6..8575e9b 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -3,103 +3,128 @@ use systemd::unit; use horrorshow::prelude::*; use horrorshow::Raw; -fn render_in_page<'a>(content: Box<RenderBox + 'a>) -> String { - (html!{ - : Raw("<!DOCTYPE html>"); - html { - head { - title: "Systemhttpd"; - link(rel="stylesheet", type="text/css", href="/static/main.css"); +#[derive(Debug)] +pub struct Renderer { + pub user: Option<String> +} + +impl Renderer { + fn render_in_page<'a>(&self, content: Box<RenderBox + 'a>) -> String { + info!("Rendering page with context: {:?}", self); + let login_box: Box<RenderBox> = match self.user { + Some(ref user) => box_html!{ + : user; + : " ("; + a(href="logout") { // TODO get base url from context + : "log out" + } + : ")"; + }, + None => box_html! { + a(href="login") { // TODO Get base url from context + : "Login" + } } - body { - nav { - ul { - li { - p { : "SystemHttpd" } + }; + + (html!{ + : Raw("<!DOCTYPE html>"); + html { + head { + title: "Systemhttpd"; + link(rel="stylesheet", type="text/css", href="/static/main.css"); + } + body { + nav { + ul { + li { + p { : "SystemHttpd" } + } } - } - ul(class="right") { - li { - p { : "Login" } + ul(class="right") { + li { + p { + : login_box + } + } } } - } - main { - : content + main { + : content + } } } - } - }).into_string().unwrap() -} + }).into_string().unwrap() + } -pub fn login_page() -> String { - render_in_page(box_html! { - h1 { : "Log in" } - form(method="post") { - p { : "Username" } - input(type="text", name="username") {} - p { : "Password" } - input(type="text", name="password") {} - p {} - input(type="submit", value="Log in") {} - } - }) -} + pub fn login_page(&self) -> String { + self.render_in_page(box_html! { + h1 { : "Log in" } + form(method="post") { + p { : "Username" } + input(type="text", name="username") {} + p { : "Password" } + input(type="text", name="password") {} + p {} + input(type="submit", value="Log in") {} + } + }) + } -fn unit_table<'a>(units: &'a [&unit::Unit]) -> Box<RenderBox + 'a> { - fn render_unit<'a>(unit: &'a unit::Unit) -> Box<RenderBox + 'a> { - box_html! { - tr { - td { - a(href=format_args!("/status/{}", &unit.name)) { - : &unit.name + fn unit_table<'a>(&self, units: &'a [&unit::Unit]) -> Box<RenderBox + 'a> { + fn render_unit<'a>(unit: &'a unit::Unit) -> Box<RenderBox + 'a> { + box_html! { + tr { + td { + a(href=format_args!("/status/{}", &unit.name)) { + : &unit.name + } + } + td { + : format_args!("{} ({})", + &unit.active_state, + &unit.sub_state) } - } - td { - : format_args!("{} ({})", - &unit.active_state, - &unit.sub_state) } } } - } - box_html! { - table { - tr { - th { - : "Unit" + box_html! { + table { + tr { + th { + : "Unit" + } + th { + : "Active" + } } - th { - : "Active" + @ for unit in units { + : render_unit(unit) } } - @ for unit in units { - : render_unit(unit) - } } } -} -pub fn system_status(sections: &[(String, Vec<&unit::Unit>)]) -> String { - let b = - box_html! { - @ for &(ref type_, ref units) in sections { - h1 { - : type_ - } - : unit_table(&units) - } - }; - render_in_page(b) -} + pub fn system_status(&self, sections: &[(String, Vec<&unit::Unit>)]) + -> String { + self.render_in_page(box_html! { + @ for &(ref type_, ref units) in sections { + h1 { + : type_ + } + : self.unit_table(&units) + } + }) + } -pub fn unit_status(unit: &unit::Unit, log: &str) -> String { - render_in_page(box_html! { - h1 { :&unit.name } - p { : format_args!("{} ({})", &unit.active_state, &unit.sub_state) } - pre { - : log - } - }) + pub fn unit_status(&self, unit: &unit::Unit, log: &str) -> String { + self.render_in_page(box_html! { + h1 { :&unit.name } + p { : format_args!("{} ({})", &unit.active_state, &unit.sub_state) } + pre { + : log + } + }) + } } diff --git a/src/server.rs b/src/server.rs index f34489f..2ab4f75 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,19 +1,31 @@ -extern crate iron_sessionstorage; -use iron_sessionstorage::traits::*; +use iron; +use iron::error::{HttpResult}; +use iron::headers::ContentType; +use iron::modifiers::{Header, Redirect}; +use iron::status; +use iron::{Iron, IronError, Request, IronResult, Response, Chain, Listening, Plugin, Url}; use iron_sessionstorage::SessionStorage; use iron_sessionstorage::backends::SignedCookieBackend; -use iron::status; -use iron::modifiers::Header; -use iron::headers::ContentType; -use iron::{Iron, IronError, Request, IronResult, Response, Chain, Listening}; -use iron::error::{HttpResult}; -use router::Router; -use systemd::unit; -use systemd::journal; +use iron_sessionstorage::traits::*; +use iron_sessionstorage; +use params::{Params, Value}; +use regex::Regex; use render; +use router::Router; use staticfile::Static; -use regex::Regex; +use systemd::journal; +use systemd::unit; +use persistent::Read; +#[derive(Clone, Default, Debug)] +struct Context { + base_url: String +} +impl iron::typemap::Key for Context { + type Value = Context; +} + +#[derive(Default, Debug, Clone)] struct Login { user: String, } @@ -52,9 +64,10 @@ fn overview(r: &mut Request) -> IronResult<Response> { // info!("Updating session value. Current value: {}", session_value.0); // session_value.0.push('a'); // try!(r.session().set(session_value)); + let renderer = make_renderer(r)?; Ok(Response::with((status::Ok, Header(ContentType::html()), - render::system_status(&units_by_section)))) + renderer.system_status(&units_by_section)))) } fn journal(r: &mut Request) -> IronResult<Response> { @@ -77,47 +90,94 @@ fn unit_status(r: &mut Request) -> IronResult<Response> { let unit_name = iexpect!(r.extensions .get::<Router>() .unwrap() - .find("unit"), status::BadRequest); + .find("unit"), status::BadRequest).to_string(); let re = Regex::new(r"[-_\w\d]*").unwrap(); - if !re.is_match(unit_name) { + if !re.is_match(&unit_name) { return Ok(Response::with( (status::BadRequest, format!("Unit ({}) does not match {}", unit_name, re)))); } - let ref unit = itry!(unit::get_units(unit_name))[0]; - let log = itry!(journal::get_log(unit_name, 15)); + let ref unit = itry!(unit::get_units(&unit_name))[0]; + let log = itry!(journal::get_log(&unit_name, 15)); + let renderer = make_renderer(r)?; Ok(Response::with((status::Ok, Header(ContentType::html()), - render::unit_status(&unit, &log)))) + renderer.unit_status(&unit, &log)))) +} + +fn get_logged_in_user(r: &mut Request) -> IronResult<Option<Login>> { + let login = r.session().get::<Login>()?; + // Session storage doesn't have a way to delete its cookie, + // so we set the username to empty on logout. + if let &Some(Login { ref user }) = &login { + if user.is_empty() { + return Ok(None) + } + } + Ok(login) } fn login(r: &mut Request) -> IronResult<Response> { + let renderer = make_renderer(r)?; Ok(Response::with((status::Ok, Header(ContentType::html()), - render::login_page()))) + renderer.login_page()))) } fn login_submit(r: &mut Request) -> IronResult<Response> { - Ok(Response::with((status::Ok, - Header(ContentType::plaintext()), - "login"))) - // TODO: Need this to get params: - // https://github.com/iron/params + let login = { + let map = r.get_ref::<Params>().unwrap(); + let user = match map.get("username") { + Some(&Value::String(ref v)) => v, + _ => panic!("no username in params: {:?}", map) + }; + let password = match map.get("password") { + Some(&Value::String(ref v)) => v, + _ => panic!("no password in params: {:?}", map) + }; + Login { user: user.clone() } + }; + + info!("User logged in: {:?}", login); + r.session().set(login)?; + let url = Url::parse("http://localhost:8080/").unwrap(); + Ok(Response::with((status::Found, + Redirect(url)))) +} + +fn logout(r: &mut Request) -> IronResult<Response> { + r.session().set::<Login>(Default::default()); + let url = Url::parse("http://localhost:8080/").unwrap(); + Ok(Response::with((status::Found, + Redirect(url)))) +} + +fn make_renderer(r: &mut Request) -> IronResult<render::Renderer> { + let user = get_logged_in_user(r)?.map(|u| u.user); + Ok(render::Renderer { + user: user + }) } pub fn serve(port: u16) -> HttpResult<Listening> { + // TODO: Use a real secret. let secret = b"secret2".to_vec(); let router = router!( root: get "/" => overview, login: get "/login" => login, login_submit: post "/login" => login_submit, + logout: get "/logout" => logout, details: get "/status/:unit" => unit_status, journal: get "/journal/:unit" => journal, css: get "/static/main.css" => Static::new(""), ); let mut chain = Chain::new(router); + let context = Context { + base_url: String::from("http://localhost:8080/"), + }; chain.link_around(SessionStorage::new(SignedCookieBackend::new(secret))); + chain.link(Read::<Context>::both(context)); let bind_address = format!("{}:{}", "::", port); Iron::new(chain).http(bind_address.as_str()) } |