ramm 0.0.24 → 0.0.26

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/dist/ramm.js CHANGED
@@ -171,6 +171,10 @@ var installPodman = async () => {
171
171
  };
172
172
  var createNetwork = async () => {
173
173
  const netwroks = await execCommand("podman network inspect $(podman network ls -q) -f '{{.NetworkInterface}}'");
174
+ const podmanNetworks = await execCommand("podman network ls");
175
+ if (podmanNetworks.output.includes("ramm")) {
176
+ return;
177
+ }
174
178
  if (netwroks.output.includes("podman_ramm")) {
175
179
  return;
176
180
  }
@@ -208,22 +212,27 @@ var addNftPodmanRule = async () => {
208
212
  await execCommand("nft insert rule inet ramm prerouting iifname @podman_interfaces accept");
209
213
  };
210
214
  // src/nft.ts
211
- var createNftTable = (allowed_ssh_ipv4) => {
215
+ var createNftTable = ({ allowedIpV4 }) => {
212
216
  const nftTable = `table inet ramm {
213
- set allowed_ssh_ipv4 {
217
+ set allowed_ipv4 {
214
218
  type ipv4_addr
215
219
  flags dynamic
216
- elements = { ${allowed_ssh_ipv4} }
220
+ elements = { ${allowedIpV4.join(`
221
+ `)} }
217
222
  }
218
223
 
219
- chain local_chain {
220
- iif "lo" accept
224
+ chain local_chain_base {
225
+ iif "lo" accept
221
226
  ct state established,related accept
222
- ip saddr @allowed_ssh_ipv4 tcp dport 22 accept
227
+ ip saddr @allowed_ipv4 tcp dport 22 accept
223
228
  tcp dport 22 ct state new limit rate over 700/minute burst 5 packets drop
224
229
  tcp dport 22 accept
225
230
  tcp dport 80 accept
226
231
  tcp dport 443 accept
232
+ }
233
+
234
+ chain local_chain {
235
+ jump local_chain_base
227
236
  drop
228
237
  }
229
238
 
@@ -235,12 +244,14 @@ var createNftTable = (allowed_ssh_ipv4) => {
235
244
  `;
236
245
  return nftTable;
237
246
  };
238
- var setupNftable = async (allowedIpSsh) => {
247
+ var setupNftable = async ({
248
+ allowedIpV4
249
+ }) => {
239
250
  const listTable = await execCommand("nft list table inet ramm");
240
251
  if (listTable.spawnResult.exitCode === 0) {
241
252
  await execCommand("nft delete table inet ramm");
242
253
  }
243
- const nftTable = createNftTable(allowedIpSsh);
254
+ const nftTable = createNftTable({ allowedIpV4 });
244
255
  await execCommand(`nft -f - <<EOF
245
256
  ${nftTable}
246
257
  EOF`);
@@ -319,7 +330,7 @@ var writeFile = async (pathToFile, str) => {
319
330
  debugApiCall(`write(${normalizedPath})`);
320
331
  await write(normalizedPath, str);
321
332
  };
322
- var writeFileIfNotMatch = async (pathToFile, str) => {
333
+ var writeIfNewCompletely = async (pathToFile, str) => {
323
334
  const normalizedPath = normalizePath(pathToFile);
324
335
  await createFileIfNeed(normalizedPath);
325
336
  debugApiCall(`file(${normalizedPath}).text()`);
@@ -361,7 +372,7 @@ async function createSshKey(pathToKey, comment) {
361
372
  const pubKey = await Bun.file(pathToKeyPub).text();
362
373
  return pubKey;
363
374
  }
364
- var addSshKey = async (pubKey, context) => {
375
+ var addSshKeyToAuthorized = async (pubKey, context) => {
365
376
  const { output: keys } = await execBySsh("cat .ssh/authorized_keys", context);
366
377
  if (keys.includes(pubKey)) {
367
378
  return;
@@ -371,7 +382,7 @@ var addSshKey = async (pubKey, context) => {
371
382
  var createAndAddSshKey = async (pathToKey, comment, context) => {
372
383
  const pubKey = await createSshKey(pathToKey, comment);
373
384
  debug(`Key is: ${pubKey}`);
374
- await addSshKey(pubKey, context);
385
+ await addSshKeyToAuthorized(pubKey, context);
375
386
  };
376
387
  // src/cron.ts
377
388
  var createCron = async ({
@@ -433,7 +444,7 @@ var passVarsServer = async () => {
433
444
  };
434
445
  export {
435
446
  writeIfNew,
436
- writeFileIfNotMatch,
447
+ writeIfNewCompletely as writeFileIfNotMatch,
437
448
  writeFile,
438
449
  setupNftable,
439
450
  runPodmanContainerService,
@@ -1,4 +1,4 @@
1
1
  export declare const normalizeFileContent: (str: string) => string;
2
2
  export declare const writeIfNew: (rawFilePath: string, str: string) => Promise<void>;
3
3
  export declare const writeFile: (pathToFile: string, str: string) => Promise<void>;
4
- export declare const writeFileIfNotMatch: (pathToFile: string, str: string) => Promise<void>;
4
+ export declare const writeIfNewCompletely: (pathToFile: string, str: string) => Promise<void>;
@@ -1,2 +1,4 @@
1
1
  export declare const localNftChainName = "local_chain";
2
- export declare const setupNftable: (allowedIpSsh: string) => Promise<void>;
2
+ export declare const setupNftable: ({ allowedIpV4, }: {
3
+ allowedIpV4: string[];
4
+ }) => Promise<void>;
@@ -7,7 +7,7 @@ export { restartSystemdService } from "./systemd.ts";
7
7
  export { installSystemPackage } from "./packages.ts";
8
8
  export { debugBlock } from "./debug.ts";
9
9
  export { setupNftable } from "./nft.ts";
10
- export { writeIfNew, writeFile, writeFileIfNotMatch, normalizeFileContent, } from "./files.ts";
10
+ export { writeIfNew, writeFile, writeIfNewCompletely as writeFileIfNotMatch, normalizeFileContent, } from "./files.ts";
11
11
  export { createAndAddSshKey, getServerFingerprintBySsh, addKeyToHostConfig, } from "./ssh.ts";
12
12
  export { normalizePath } from "./path.ts";
13
13
  export { createCron } from "./cron.ts";
@@ -2,3 +2,9 @@ import type { Context } from "./context.ts";
2
2
  export declare const addKeyToHostConfig: (pathToHost: string, address: string, pathToKey: string) => Promise<void>;
3
3
  export declare const getServerFingerprintBySsh: (context: Context) => Promise<string>;
4
4
  export declare const createAndAddSshKey: (pathToKey: string, comment: string, context: Context) => Promise<void>;
5
+ export declare const setupSshKey: ({ key, fingerprint, pathToFile, server, }: {
6
+ key: string;
7
+ fingerprint: string;
8
+ pathToFile: string;
9
+ server: string;
10
+ }) => Promise<void>;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "ramm",
3
3
  "type": "module",
4
- "version": "0.0.24",
4
+ "version": "0.0.26",
5
5
  "scripts": {
6
- "build": "bun build ./src/ramm.ts --target bun --outdir ./dist && cp ./src/bun.sh ./dist/bun.sh && bun run types",
6
+ "build": "bun build ./src/ramm.ts --target bun --outdir ./dist && cp ./src/bun.sh ./dist/bun.sh",
7
7
  "types": "tsc --project tsconfig.types.json"
8
8
  },
9
9
  "main": "dist/ramm.js",
@@ -19,6 +19,7 @@
19
19
  "typescript": "^5.8.2"
20
20
  },
21
21
  "dependencies": {
22
+ "dapes": "^0.0.26",
22
23
  "desy": "^0.0.14"
23
24
  }
24
- }
25
+ }