Add :code-block/command-whitelist option

This commit is contained in:
Tienson Qin
2022-11-25 17:15:47 +08:00
parent 629358f845
commit 6a4fbaa9da
4 changed files with 14 additions and 2 deletions

View File

@@ -32,7 +32,7 @@
[:div
[:h1.title
"Input command"]
[:div.mt-4.mb-4.relative.rounded-md.shadow-sm.max-w-xs
[:div.mt-4.mb-4.relative.rounded-md.shadow-sm
[:input#run-command.form-input.font-mono.block.w-full.sm:text-sm.sm:leading-5
{:autoFocus true
:on-key-down util/stop-propagation

View File

@@ -306,7 +306,7 @@
(when-not (= mode "calc")
[:div
[:div.extensions__code-lang
(if (contains? (shell-handler/get-commands) (string/lower-case mode))
(if (contains? (shell-handler/get-code-block-commands) (string/lower-case mode))
[:a {:title (str "Run command " mode)
:on-click (fn [_e]
(let [editor-atom (:editor-atom state)]

View File

@@ -42,12 +42,21 @@
(def dangerous-commands
#{"rm" "mv" "rename" "dd" ">" "command" "sudo"})
(def code-block-commands-whitelist
#{"alda"})
(defn get-commands
[]
(set/union (map (comp #(remove string/blank? %) string/lower-case str)
(:commands-whitelist (state/get-config)))
commands-whitelist))
(defn get-code-block-commands
[]
(set/union (map (comp #(remove string/blank? %) string/lower-case str)
(:code-block/command-whitelist (state/get-config)))
code-block-commands-whitelist))
(defn run-command!
[command]
(let [[command args] (gp-util/split-first " " command)

View File

@@ -299,4 +299,7 @@
;; Commands that are allowed to be invoked from Logseq.
:shell/command-whitelist #{}
;; Commands that could be executed in code blocks, e.g. alda, dot
:code-block/command-whitelist #{}
}