Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

cli.js 3.6 KiB

8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env node
  2. 'use strict';
  3. const copyPaste = require('copy-paste');
  4. const meow = require('meow');
  5. const LessPass = require('lesspass');
  6. const read = require('read');
  7. const chalk = require('chalk');
  8. const cli = meow(`
  9. Usage
  10. $ lesspass <site> <login> [masterPassword] [options]
  11. Options
  12. -l add lowercase in password
  13. -u add uppercase in password
  14. -d add digits in password
  15. -s add symbols in password
  16. --no-lowercase remove lowercase from password
  17. --no-uppercase remove uppercase from password
  18. --no-digits remove digits from password
  19. --no-symbols remove symbols from password
  20. --length, -L int (default 16)
  21. --counter, -c int (default 1)
  22. --clipboard, -C copy generated password to clipboard rather than displaying it.
  23. Need pbcopy (OSX), xclip (Linux) or clip (Windows).
  24. Examples
  25. # no symbols
  26. $ lesspass lesspass.com contact@lesspass.com password --no-symbols
  27. OlfK63bmUhqrGODR
  28. # no symbols shortcut
  29. $ lesspass lesspass.com contact@lesspass.com password -lud
  30. OlfK63bmUhqrGODR
  31. # only digits and length of 8
  32. $ lesspass lesspass.com contact@lesspass.com -d -L8
  33. master password:
  34. 75837019`, {alias: {L: 'length', c: 'counter', C: 'clipboard'}});
  35. function calcPassword(site, login, masterPassword, passwordProfile) {
  36. LessPass.generatePassword(site, login, masterPassword, passwordProfile)
  37. .then(function (generatedPassword) {
  38. if (passwordProfile.clipboard) {
  39. copyPaste.copy(generatedPassword, function () {
  40. console.log("Copied to clipboard");
  41. process.exit();
  42. });
  43. } else {
  44. console.log(generatedPassword);
  45. process.exit();
  46. }
  47. });
  48. }
  49. function hasNoShortOption(options) {
  50. let hasShortOption = false;
  51. ['l', 'u', 'd', 's'].forEach(function (shortOption) {
  52. if (typeof options[shortOption] !== 'undefined' && options[shortOption]) {
  53. hasShortOption = true;
  54. }
  55. });
  56. return !hasShortOption;
  57. }
  58. function getOptionBoolean(options, optionString) {
  59. let shortOption = optionString.substring(0, 1);
  60. if (options[shortOption]) {
  61. return true;
  62. }
  63. if (typeof options[optionString] === 'undefined') {
  64. return hasNoShortOption(options);
  65. }
  66. return options[optionString]
  67. }
  68. const lowercase = getOptionBoolean(cli.flags, 'lowercase');
  69. const uppercase = getOptionBoolean(cli.flags, 'uppercase');
  70. const symbols = getOptionBoolean(cli.flags, 'symbols');
  71. const digits = getOptionBoolean(cli.flags, 'digits');
  72. const passwordProfile = {
  73. lowercase: lowercase,
  74. uppercase: uppercase,
  75. symbols: symbols,
  76. numbers: digits,
  77. clipboard: cli.flags.clipboard || false,
  78. length: cli.flags.length || 16,
  79. counter: cli.flags.counter || 1
  80. };
  81. const site = cli.input[0];
  82. const login = cli.input[1];
  83. if (typeof site === 'undefined' && typeof login === 'undefined') {
  84. console.log(chalk.red('site or login cannot be empty'));
  85. console.log('type lesspass --help');
  86. process.exit(-1);
  87. }
  88. if (cli.input.length === 3) {
  89. const masterPassword = cli.input[2];
  90. calcPassword(site, login, masterPassword, passwordProfile)
  91. } else {
  92. read({prompt: 'master password: ', silent: true}, function (er, password) {
  93. calcPassword(site, login, password, passwordProfile)
  94. });
  95. }