aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md15
-rw-r--r--cli/Main.hs24
-rw-r--r--src/ZeroBin.hs29
3 files changed, 37 insertions, 31 deletions
diff --git a/README.md b/README.md
index d0f43b6..1f389b4 100644
--- a/README.md
+++ b/README.md
@@ -37,15 +37,17 @@ Type `zerobin --help` to see usage summary:
zerobin [options] TEXT
Options:
- -e, --expire=E Set expiration of paste: once, day, week, month [default: week]
+ -b, --bin=BIN 0bin service [default: https://paste.ec]
-f, --file Paste the content of file TEXT instead of plain TEXT
+ -e, --expire=E Set expiration of paste: once, day, week, month [default: day]
-h, --help Show this message
Examples:
- zerobin hello paste "hello" for a week
- zerobin -f /etc/fstab paste file /etc/fstab for a week
- zerobin -e once hello paste "hello", it will burn after reading
+ zerobin hello paste "hello" for a day
+ zerobin -f /etc/fstab paste file /etc/fstab for a day
+ zerobin -e once hello paste "hello", it will burn after reading
+ zerobin -b http://0bin.net hello paste to 0bin.net
Hacking
@@ -65,10 +67,11 @@ running by [Node.js](https://nodejs.org) to decrypt:
Features/Bugs/TODOs
===================
-1. https://paste.ec supports images, `zerobin` can encrypt anything,
- but only plain text will be decrypted.
+1. [0bin](https://github.com/sametmax/0bin) supports images,
+ `zerobin` can encrypt anything, but only plain text will be decrypted.
2. "Burn after reading" (`-e once`) really means "burn after two readings",
because we do not redirect like browser does.
You can verify your paste before sharing the link ;-)
+3. http://0bin.net does not support `-e week`
diff --git a/cli/Main.hs b/cli/Main.hs
index e32a78f..81dda44 100644
--- a/cli/Main.hs
+++ b/cli/Main.hs
@@ -8,29 +8,32 @@ import System.Environment (getArgs)
import System.Exit (exitFailure)
import System.IO (stderr, hPutStrLn)
import Text.RawString.QQ (r)
-import ZeroBin (share, Expiration(..), pasteEc)
+import ZeroBin (share, Expiration(..))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as C
import qualified System.Console.Docopt.NoTH as O
usage :: String
usage = "zerobin " ++ showVersion version
- ++ " pastes to " ++ pasteEc ++ [r|
+ ++ " pastes to 0bin services" ++ [r|
zerobin prints URI to be shared or error message
+See http://0bin.net and https://paste.ec
Usage:
zerobin [options] TEXT
Options:
- -e, --expire=E Set expiration of paste: once, day, week, month [default: week]
+ -b, --bin=BIN 0bin service [default: https://paste.ec]
-f, --file Paste the content of file TEXT instead of plain TEXT
+ -e, --expire=E Set expiration of paste: once, day, week, month [default: day]
-h, --help Show this message
Examples:
- zerobin hello paste "hello" for a week
- zerobin -f /etc/fstab paste file /etc/fstab for a week
- zerobin -e once hello paste "hello", it will burn after reading
+ zerobin hello paste "hello" for a day
+ zerobin -f /etc/fstab paste file /etc/fstab for a day
+ zerobin -e once hello paste "hello", it will burn after reading
+ zerobin -b http://0bin.net hello paste to 0bin.net
|]
@@ -58,18 +61,19 @@ getContent asFile text =
main :: IO ()
main = do
doco <- O.parseUsageOrExit usage
- args <- O.parseArgsOrExit doco =<< getArgs
+ args <- O.parseArgsOrExit doco =<< getArgs
if args `O.isPresent` O.longOption "help"
then putStrLn $ O.usage doco
else do
let get = O.getArgOrExitWith doco
+ bin <- args `get` O.longOption "bin"
expire <- args `get` O.longOption "expire"
text <- args `get` O.argument "TEXT"
cnt <- getContent (args `O.isPresent` O.longOption "file") text
case getExpiration expire of
- Nothing -> die "invalid value for expiration"
- Just e -> do
- rc <- share e cnt
+ Nothing -> die "invalid value for expiration"
+ Just e -> do
+ rc <- share bin e cnt
case rc of
Left err -> die err
Right uri -> putStrLn uri
diff --git a/src/ZeroBin.hs b/src/ZeroBin.hs
index 13c229e..fac93a5 100644
--- a/src/ZeroBin.hs
+++ b/src/ZeroBin.hs
@@ -2,7 +2,6 @@
module ZeroBin (
Expiration(..),
- pasteEc,
share
) where
@@ -17,9 +16,6 @@ import qualified Data.ByteString.Char8 as C
import qualified Data.ByteString.Lazy as L
import qualified Network.HTTP.Conduit as HTTP
-pasteEc :: String
-pasteEc = "https://paste.ec"
-
data Response = Response {
status :: String
, message :: Maybe String
@@ -41,25 +37,28 @@ instance Show Expiration where
show Month = "1_month"
show Never = "never"
-post :: Expiration -> Content -> IO Response
-post ex ct = do
- req' <- HTTP.parseUrl $ pasteEc ++ "/paste/create"
+post :: String -> Expiration -> Content -> IO (Either String String)
+post bin ex ct = do
+ req' <- HTTP.parseUrl $ bin ++ "/paste/create"
let req = HTTP.urlEncodedBody
[ (C.pack "expiration" , C.pack $ show ex)
, (C.pack "content" , L.toStrict $ JSON.encode ct)
] req'
manager <- HTTP.newManager HTTP.tlsManagerSettings
response <- HTTP.httpLbs req manager
- return . fromJust . JSON.decode $ HTTP.responseBody response
-
-share :: Expiration -> ByteString -> IO (Either String String)
-share ex txt = do
- pwd <- makePassword 33
- c <- encrypt pwd (encode txt)
- resp <- post ex c
+ let resp = fromJust . JSON.decode $ HTTP.responseBody response
case status resp of
"ok" -> return . Right $
- pasteEc ++ "/paste/" ++ (fromJust . paste) resp ++ "#" ++ pwd
+ bin ++ "/paste/" ++ (fromJust . paste) resp
_ -> return . Left $
(fromJust . message) resp
+share :: String -> Expiration -> ByteString -> IO (Either String String)
+share bin ex txt = do
+ pwd <- makePassword 33
+ c <- encrypt pwd (encode txt)
+ append pwd `fmap` post bin ex c
+ where
+ append _ (Left e) = Left e
+ append p (Right u) = Right $ u ++ "#" ++ p
+