u2a 3.2.6 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "u2a",
3
- "version": "3.2.6",
3
+ "version": "3.3.1",
4
4
  "description": "URL to App - Turn any URL into a desktop application",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -29,7 +29,8 @@
29
29
  "inquirer": "^8.2.5",
30
30
  "open": "^8.4.0",
31
31
  "png-to-ico": "^2.1.8",
32
- "sharp": "^0.33.5"
32
+ "sharp": "^0.33.5",
33
+ "is-admin": "^3.0.0"
33
34
  },
34
35
  "homepage": "https://urltoapp.xyz",
35
36
  "repository": {
@@ -6,9 +6,11 @@ const { getFavicon, processFavicon } = require('../utils/favicon');
6
6
  const { APPS_DIR, readDB, writeDB } = require('../utils/config');
7
7
  const Logger = require('../utils/logger');
8
8
  const os = require('os');
9
+ const { sanitizeInput } = require('../utils/sanitize');
9
10
 
10
11
  const logger = new Logger('create');
11
12
 
13
+
12
14
  function createWindowsShortcut(appInfo) {
13
15
  try {
14
16
  const { appName, appDir, iconPath } = appInfo;
@@ -673,8 +675,8 @@ async function createApp(url, options) {
673
675
 
674
676
  try {
675
677
  url = await normalizeUrl(url);
676
- const domain = getDomainName(url);
677
- const appName = options.name || domain;
678
+ const domain = sanitizeInput(getDomainName(url));
679
+ const appName = sanitizeInput(options.name || domain);
678
680
 
679
681
  const db = readDB();
680
682
  if (db.hasOwnProperty(appName)) {
@@ -1,14 +1,14 @@
1
1
  const fs = require('fs');
2
2
  const inquirer = require('inquirer');
3
- const { normalizeUrl, getDomainName } = require('../utils/url');
4
3
  const { readDB, writeDB, APPS_DIR } = require('../utils/config');
5
4
  const Logger = require('../utils/logger');
6
5
  const { removeAppFromOS } = require('./create');
7
6
  const path = require('path');
7
+ const { sanitizeInput } = require('../utils/sanitize');
8
8
 
9
9
  const logger = new Logger('remove');
10
10
 
11
- async function removeApp(appName) {
11
+ async function processRemoval(appName) {
12
12
  try {
13
13
  const db = readDB();
14
14
 
@@ -53,6 +53,11 @@ async function removeApp(appName) {
53
53
  }
54
54
  }
55
55
 
56
+ async function removeApp(appName) {
57
+ const sAppName = sanitizeInput(appName);
58
+ await processRemoval(sAppName);
59
+ }
60
+
56
61
  module.exports = {
57
62
  removeApp
58
63
  };
package/src/index.js CHANGED
@@ -1,58 +1,62 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- ver = process.versions.node;
3
+ const ver = process.versions.node;
4
4
 
5
5
  if (ver < '22.0.0') {
6
6
  console.error("You need a nodejs installation equal or superior to 22.0.0. Please upgrade your node installation and retry.");
7
7
  process.exit(1);
8
8
  }
9
9
 
10
-
11
10
  const { program } = require('commander');
12
11
  const { createApp } = require('./commands/create');
13
12
  const { listApps } = require('./commands/list');
14
13
  const { removeApp } = require('./commands/remove');
15
14
  const { version } = require('../package.json');
16
15
  const { setupConfig } = require('./utils/config');
16
+ const { checkNotRoot } = require('./utils/noroot');
17
17
 
18
- setupConfig();
18
+ (async () => {
19
+ await checkNotRoot();
19
20
 
20
- program
21
- .name('u2a')
22
- .description('Convert websites into desktop applications')
23
- .version(version);
21
+ setupConfig();
24
22
 
25
23
  program
26
- .command('create <url>')
27
- .description('Create a new application from a URL')
28
- .option('--name <name>', 'Specify the application name')
29
- .option('--width <width>', 'Specify the window width', parseInt)
30
- .option('--height <height>', 'Specify the window height', parseInt)
31
- .option('--executable [windows|darwin|linux]', 'Create a single executable for the target system')
32
- .option('--arch [x64|armv7l|arm64|universal]', 'Specify the target architecture for the executable')
33
- .option('--setup', 'Creates a setup file for the executable')
34
- .action((url, options) => {
35
- createApp(url, options);
36
- });
24
+ .name('u2a')
25
+ .description('Convert websites into desktop applications')
26
+ .version(version);
37
27
 
38
- program
39
- .command('list')
40
- .description('List all available applications')
41
- .action(listApps);
28
+ program
29
+ .command('create <url>')
30
+ .description('Create a new application from a URL')
31
+ .option('--name <name>', 'Specify the application name')
32
+ .option('--width <width>', 'Specify the window width', parseInt)
33
+ .option('--height <height>', 'Specify the window height', parseInt)
34
+ .option('--executable [windows|darwin|linux]', 'Create a single executable for the target system')
35
+ .option('--arch [x64|armv7l|arm64|universal]', 'Specify the target architecture for the executable')
36
+ .option('--setup', 'Creates a setup file for the executable')
37
+ .action((url, options) => {
38
+ createApp(url, options);
39
+ });
42
40
 
43
- program
44
- .command('remove <url>')
45
- .description('Remove an existing application')
46
- .action(removeApp);
41
+ program
42
+ .command('list')
43
+ .description('List all available applications')
44
+ .action(listApps);
47
45
 
48
- program.on('command:*', () => {
49
- console.error(`\nInvalid command: ${program.args.join(' ')}`);
50
- console.log(`\nUse --help to see the list of available commands.`);
51
- process.exit(1);
52
- });
46
+ program
47
+ .command('remove <url>')
48
+ .description('Remove an existing application')
49
+ .action(removeApp);
50
+
51
+ program.on('command:*', () => {
52
+ console.error(`\nInvalid command: ${program.args.join(' ')}`);
53
+ console.log(`\nUse --help to see the list of available commands.`);
54
+ process.exit(1);
55
+ });
53
56
 
54
- program.parse(process.argv);
57
+ program.parse(process.argv);
55
58
 
56
- if (process.argv.length <= 2) {
57
- program.help();
58
- }
59
+ if (process.argv.length <= 2) {
60
+ program.help();
61
+ }
62
+ })();
@@ -0,0 +1,32 @@
1
+ const os = require('os');
2
+ const isAdmin = require('is-admin');
3
+ const Logger = require('./logger')
4
+
5
+ const logger = new Logger('noroot');
6
+
7
+ async function checkNotRoot() {
8
+ const platform = os.platform();
9
+
10
+ switch (platform) {
11
+ case 'win32':
12
+ if (await isAdmin()) {
13
+ logger.error('This application should not be run as an administrator.', '');
14
+ process.exit(1);
15
+ }
16
+ break;
17
+
18
+ case 'darwin':
19
+ case 'linux':
20
+ if (process.getuid() === 0) {
21
+ logger.error('This application should not be run as root.', '');
22
+ process.exit(1);
23
+ }
24
+ break;
25
+
26
+ default:
27
+ logger.error('Unsupported platform:', platform);
28
+ process.exit(1);
29
+ }
30
+ }
31
+
32
+ module.exports = { checkNotRoot };
@@ -0,0 +1,7 @@
1
+ function sanitizeInput(userInput) {
2
+ return userInput.replace(/[^a-zA-Z0-9_-\s.]/g, '_');
3
+ }
4
+
5
+ module.exports = {
6
+ sanitizeInput
7
+ }