diff --git a/package/contents/code/nas.js b/package/contents/code/nas.js new file mode 100644 index 0000000..23b4350 --- /dev/null +++ b/package/contents/code/nas.js @@ -0,0 +1,181 @@ +/* + * nas.js — command builders + output parsers for the Synology NAS plasmoid. + * + * These functions are pure: they build shell command strings and parse the + * text those commands produce. The QML layer owns a Plasma5Support executable + * DataSource and actually runs them. + * + * Security model: + * - The plasma5support "executable" engine does NOT use a shell; it tokenises + * with KShell and runs the program directly. So every command is wrapped as + * `sh -c '' _ ...`. The script text is constant + * (no interpolation) and all dynamic, possibly-hostile values arrive as + * positional parameters ($1, $2, ...). This makes shell injection via a + * share/host/user name impossible. + * - Passwords live in KWallet. On mount we read the password *inside* the + * shell straight into a 0600 credentials file — it never appears in QML, + * in argv, or in `ps`. (The one exception is the initial save in the config + * page, where the freshly-typed password is handed to kwallet-query.) + */ + +// KWallet folder + wallet used for all stored NAS passwords. +var WALLET = "kdewallet"; +var WALLET_FOLDER = "Synology NAS"; +var HELPER = "/usr/lib/synology-nas/helper"; + +// POSIX single-quote escaping: wrap in '...' and replace ' with '\''. +function sq(s) { + return "'" + String(s).replace(/'/g, "'\\''") + "'"; +} + +// Build `sh -c '