Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b33e18be5 | |||
| 173793caa3 | |||
| 01842dbc8d | |||
| cec35fc16b | |||
| e5fb6e7231 | |||
| 6c017b3262 | |||
| 2e64c26a0a | |||
| c8b9556bcd | |||
| 5c93f4e570 | |||
| dfc3d4e579 | |||
| e7b2683d2c | |||
| 8698e6b57b | |||
| 3dd79af7de |
@@ -145,11 +145,16 @@ clj-totp.sh import <alias> "<url>"
|
||||
- [x] Show several OTPs at once
|
||||
|
||||
### v1.2
|
||||
- [x] Show progress bar
|
||||
- [x] Styles for progress bar
|
||||
- [x] Native compilation script corrections
|
||||
|
||||
### v2
|
||||
- [ ] REST API
|
||||
- [ ] User management
|
||||
- [ ] Robust BD backend (H2, datomic, or similar)
|
||||
|
||||
### v1.3
|
||||
### v3
|
||||
- [ ] Simple web connected to REST API
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
(:require [clojure.tools.build.api :as b]))
|
||||
|
||||
(def lib 'es.rcorral/clj-totp)
|
||||
(def version (format "1.1.%s" (b/git-count-revs nil)))
|
||||
(def version (format "1.2.%s" (b/git-count-revs nil)))
|
||||
(def target-dir "target")
|
||||
(def class-dir (str target-dir "/classes"))
|
||||
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))
|
||||
|
||||
6
deps.edn
6
deps.edn
@@ -3,10 +3,12 @@
|
||||
io.github.clojure/tools.build {:mvn/version "0.10.10"}
|
||||
mvxcvi/alphabase {:mvn/version "3.0.185"} ;; https://github.com/greglook/alphabase
|
||||
cli-matic/cli-matic {:mvn/version "0.5.4"} ;; https://github.com/l3nz/cli-matic
|
||||
;; Native image (GraalVM)
|
||||
com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"} ;; Tutorial: https://shagunagrawal.me/posts/setup-clojure-with-graalvm-for-native-image/
|
||||
;; Protobuf for java
|
||||
com.google.protobuf/protobuf-java {:mvn/version "3.25.8"}}
|
||||
com.google.protobuf/protobuf-java {:mvn/version "3.25.8"}
|
||||
;; Progress bar
|
||||
com.github.pmonks/spinner {:mvn/version "2.0.284"}
|
||||
}
|
||||
|
||||
:aliases {;; Execute the app
|
||||
:run {:main-opts ["-m" "totp.app"]}
|
||||
|
||||
33
native.cmd
Normal file
33
native.cmd
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
@echo off
|
||||
|
||||
setlocal
|
||||
|
||||
REM YOUR LOCAL GRAAL VM INSTALLATION
|
||||
set JAVA_HOME=D:\programas\graalvm-jdk-21.0.7+8.1
|
||||
REM generated file
|
||||
set BIN_FILE=totp
|
||||
|
||||
set DEST_DIR=C:\Users\rubencj\util
|
||||
|
||||
set PATH=%JAVA_HOME%\bin;%CLOJURE_HOME%;%PATH%
|
||||
set NATIVE=%JAVA_HOME%\bin\native-image.cmd
|
||||
|
||||
|
||||
echo Using GraalVM native compiler: %NATIVE%
|
||||
|
||||
echo Creating uberjar
|
||||
clojure -T:build uber
|
||||
|
||||
set UBERJAR=
|
||||
for /f "delims=" %%a in ('dir /b /s target\clj-totp-*-standalone.jar') do @set UBERJAR=%%a
|
||||
echo Created uberjar: %UBERJAR%
|
||||
|
||||
echo "Creating native image"
|
||||
cmd /c %NATIVE% -jar %UBERJAR% -o target\%BIN_FILE% -H:+ReportExceptionStackTraces --features=clj_easy.graal_build_time.InitClojureClasses --report-unsupported-elements-at-runtime --verbose --no-fallback -H:ReflectionConfigurationFiles=reflect_config.json -H:-CheckToolchain
|
||||
|
||||
|
||||
echo Executable created: target\%BIN_FILE%.exe
|
||||
|
||||
copy target\%BIN_FILE%.exe %DEST_DIR%
|
||||
echo Native image copied to %DEST_DIR%\%BIN_FILE%.exe
|
||||
@@ -8,7 +8,14 @@ clojure -T:build uber
|
||||
UBERJAR=$(realpath --relative-to=target target/clj-totp-*-standalone.jar)
|
||||
|
||||
echo "Creating native image"
|
||||
$NATIVE -jar target/$UBERJAR -o target/$BIN_FILE -H:+ReportExceptionStackTraces --features=clj_easy.graal_build_time.InitClojureClasses --report-unsupported-elements-at-runtime --verbose --no-fallback -H:ReflectionConfigurationFiles=./reflect_config.json
|
||||
$NATIVE -jar target/$UBERJAR -o target/$BIN_FILE\
|
||||
-H:+ReportExceptionStackTraces\
|
||||
-H:ReflectionConfigurationFiles=./reflect_config.json\
|
||||
--verbose --no-fallback\
|
||||
--features=clj_easy.graal_build_time.InitClojureClasses\
|
||||
--report-unsupported-elements-at-runtime\
|
||||
--initialize-at-build-time=org.fusesource.jansi.Ansi\
|
||||
#--trace-class-initialization=org.fusesource.jansi.Ansi
|
||||
|
||||
echo "Executable created on target/$BIN_FILE"
|
||||
cp target/$BIN_FILE ~/bin
|
||||
|
||||
@@ -4,33 +4,63 @@
|
||||
[totp.data :refer :all]
|
||||
[cli-matic.core :refer [run-cmd]]
|
||||
[clojure.pprint :as pp]
|
||||
[clojure.string :as str])
|
||||
[clojure.string :as str]
|
||||
[progress.determinate :as pd])
|
||||
(:import [java.util TimerTask Timer])
|
||||
(:gen-class))
|
||||
|
||||
(def DEFAULT_BAR_STYLE :coloured-ascii-boxes)
|
||||
|
||||
(defn print-timer
|
||||
([] (print-timer 1 30 DEFAULT_BAR_STYLE))
|
||||
([bar-style] (print-timer 1 30 bar-style))
|
||||
([start period bar-style]
|
||||
(let [a (atom start)]
|
||||
(pd/animate! a :opts {:total period
|
||||
;:line 1
|
||||
:label "Next TOTP: "
|
||||
;:redraw-rate 60 ;; updates per second
|
||||
:style (get pd/styles bar-style)}
|
||||
;(println)
|
||||
(run! (fn [_] (Thread/sleep 1000) (swap! a inc)) (range start (inc period)))
|
||||
;(println)
|
||||
))))
|
||||
|
||||
|
||||
(defn- print-confinuous
|
||||
([secret] (print-confinuous secret "sha1" 6 30))
|
||||
([secret algorithm digits period]
|
||||
([secret] (print-confinuous secret "sha1" 6 30 true DEFAULT_BAR_STYLE))
|
||||
([secret algorithm digits period bar bar-style]
|
||||
(let [step-millis (* 1000 period)
|
||||
now (System/currentTimeMillis)
|
||||
delay (int (- step-millis (rem now step-millis)))
|
||||
fn-show (fn [s] (println (format "[%d] %s" (System/currentTimeMillis) (get-otp s algorithm digits period))))
|
||||
delay-sec (int (/ delay 1000))
|
||||
fn-show (fn [s] (println (format "%n[%d] %s%n"
|
||||
(System/currentTimeMillis)
|
||||
(get-otp s algorithm digits period))))
|
||||
task (proxy [TimerTask] []
|
||||
(run [] (fn-show secret)))]
|
||||
(run [] (println) (fn-show secret)))
|
||||
task-bar (proxy [TimerTask] []
|
||||
(run [] (print-timer bar-style)))
|
||||
task-init (proxy [TimerTask] []
|
||||
(run [] (print-timer (- period delay-sec) period bar-style)))]
|
||||
(println "\n <Generating continuosly, press enter to stop>\n")
|
||||
;; (println "Now:" now ", Delay:" delay ", Next execution: " (+ now delay))
|
||||
(println "Refresing in" (int (/ delay 1000)) "seconds")
|
||||
(println "Refresing in" delay-sec "seconds")
|
||||
(fn-show secret)
|
||||
;; Now, start the tasks
|
||||
(when bar
|
||||
(. (new Timer) (schedule task-init 0))
|
||||
(. (new Timer) (scheduleAtFixedRate task-bar delay step-millis)))
|
||||
(. (new Timer) (scheduleAtFixedRate task delay step-millis)))
|
||||
(read-line))) ;; Waits for a key press
|
||||
;; Waits for a key press
|
||||
(read-line)))
|
||||
|
||||
|
||||
(defn cmd-generate
|
||||
[& {:keys [secret continuous algorithm digits period]}]
|
||||
[& {:keys [secret continuous algorithm digits period bar bar-style]}]
|
||||
;;(pp/pprint opts)
|
||||
(if continuous
|
||||
(print-confinuous secret algorithm digits period)
|
||||
(print-confinuous secret algorithm digits period bar bar-style)
|
||||
(println (get-otp secret algorithm digits period))))
|
||||
|
||||
|
||||
@@ -49,28 +79,45 @@
|
||||
(let [step-millis (* 1000 period)
|
||||
now (System/currentTimeMillis)
|
||||
delay (int (- step-millis (rem now step-millis)))
|
||||
delay-sec (int (/ delay 1000))
|
||||
fn-show (fn [s]
|
||||
(println "\n")
|
||||
(dorun (map print-app s))
|
||||
(println "")) ;; Separate each
|
||||
(println) ;; Separate each
|
||||
)
|
||||
task (proxy [TimerTask] []
|
||||
(run [] (fn-show apps)))]
|
||||
(println "\n <Generating continuosly, press enter to stop>\n")
|
||||
;; (println "Now:" now ", Delay:" delay ", Next execution: " (+ now delay))
|
||||
(println "Refresing in" (int (/ delay 1000)) "seconds")
|
||||
(println "Refresing in" delay-sec "seconds")
|
||||
(fn-show apps)
|
||||
;; Now, start the tasks
|
||||
(. (new Timer) (scheduleAtFixedRate task delay step-millis)))
|
||||
(read-line))) ;; Waits for a key press
|
||||
)) ;; Waits for a key press
|
||||
|
||||
|
||||
(defn cmd-get-multi
|
||||
[& {:keys [continuous _arguments]}]
|
||||
[& {:keys [continuous bar bar-style _arguments]}]
|
||||
;(pp/pprint opts)
|
||||
(with-config
|
||||
(let [apps (filter some? #_{:clj-kondo/ignore [:unresolved-symbol]}
|
||||
(map #(get-app cfg %) _arguments))]
|
||||
;(println "found apps: " apps)
|
||||
(if continuous
|
||||
(print-app-continuous 30 apps)
|
||||
(let [period 30
|
||||
step-millis (* 1000 period)
|
||||
now (System/currentTimeMillis)
|
||||
delay (int (- step-millis (rem now step-millis)))
|
||||
delay-sec (int (/ delay 1000))
|
||||
task-bar (proxy [TimerTask] []
|
||||
(run [] (print-timer bar-style)))
|
||||
task-init (proxy [TimerTask] []
|
||||
(run [] (print-timer (- period delay-sec) period bar-style)))]
|
||||
(print-app-continuous period apps)
|
||||
(when bar
|
||||
(. (new Timer) (schedule task-init 0))
|
||||
(. (new Timer) (scheduleAtFixedRate task-bar delay step-millis)))
|
||||
(read-line))
|
||||
(dorun (map #(print-app %) apps))))))
|
||||
|
||||
|
||||
@@ -153,7 +200,7 @@
|
||||
|
||||
(def cli-options
|
||||
{:app {:command "totp"
|
||||
:version "1.1"
|
||||
:version "1.2"
|
||||
:description ["Generate a TOTP"]}
|
||||
|
||||
:commands [;; Generate a TOTP with given params
|
||||
@@ -182,7 +229,15 @@
|
||||
{:option "period" :short "p"
|
||||
:as "Validity time in seconds"
|
||||
:type :int
|
||||
:default 30}]
|
||||
:default 30}
|
||||
{:option "bar" :short "b"
|
||||
:as "Show progress bar"
|
||||
:type :with-flag
|
||||
:default true}
|
||||
{:option "bar-style" :short "s"
|
||||
:as "Progress bar style"
|
||||
:type #{:ascii-basic :ascii-boxes :coloured-ascii-boxes :emoji-circles :emoji-boxes}
|
||||
:default :coloured-ascii-boxes}]
|
||||
:runs cmd-generate}
|
||||
;; Generate a TOTP for a configured app
|
||||
{:command "get" :short "g"
|
||||
@@ -198,7 +253,15 @@
|
||||
{:option "continuous" :short "c"
|
||||
:as "Contiuous mode"
|
||||
:type :with-flag
|
||||
:default false}]
|
||||
:default false}
|
||||
{:option "bar" :short "b"
|
||||
:as "Show progress bar"
|
||||
:type :with-flag
|
||||
:default true}
|
||||
{:option "bar-style" :short "s"
|
||||
:as "Progress bar style"
|
||||
:type #{:ascii-basic :ascii-boxes :coloured-ascii-boxes :emoji-circles :emoji-boxes}
|
||||
:default :coloured-ascii-boxes}]
|
||||
:runs cmd-get-multi}
|
||||
;; Check and init your config file
|
||||
{:command "config" :short "c"
|
||||
|
||||
Reference in New Issue
Block a user