mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-11-27 12:21:56 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7bdb99c066 | |||
| e07755f3b9 | |||
| 9b7a7632e6 | |||
| 8c8671908c | |||
| 288baf0217 | |||
| 647dfe3e9e | |||
| b0452aa82d | |||
| b5258bbb03 | |||
| f77c2c0146 | |||
| b68bb20e06 |
@@ -8,8 +8,9 @@
|
||||
<a target="_blank" href="https://github.com/seriousm4x/upsnap"><img src="https://img.shields.io/github/stars/seriousm4x/upsnap" /></a>
|
||||
<a target="_blank" href="https://github.com/seriousm4x/UpSnap/releases"><img src="https://img.shields.io/github/downloads/seriousm4x/upsnap/total" /></a>
|
||||
<a target="_blank" href="https://github.com/seriousm4x/UpSnap/releases"><img src="https://img.shields.io/github/v/release/seriousm4x/upsnap?display_name=tag" /></a>
|
||||
<a target="_blank" href="https://github.com/seriousm4x/UpSnap/actions"><img src="https://img.shields.io/github/actions/workflow/status/seriousm4x/upsnap/deploy.yml" /></a>
|
||||
<a target="_blank" href="https://github.com/seriousm4x/UpSnap/actions"><img src="https://github.com/seriousm4x/upsnap/actions/workflows/deploy.yml/badge.svg?event=push" /></a>
|
||||
<a target="_blank" href="https://github.com/seriousm4x/UpSnap/commits/master"><img src="https://img.shields.io/github/last-commit/seriousm4x/upsnap" /></a>
|
||||
<h3><a href="https://github.com/seriousm4x/UpSnap/releases/tag/3.0.0">v3 is here! 🤩 Check it out</a></h3>
|
||||
</div>
|
||||
|
||||
## ✨ Features
|
||||
@@ -31,11 +32,11 @@
|
||||
|
||||
## 🚀 Run the binary
|
||||
|
||||
Just download the latest binary from the [release page](https://github.com/seriousm4x/UpSnap/releases) and run it.
|
||||
Just download the latest binary from the [release page](https://github.com/seriousm4x/UpSnap/releases) and run it `./upsnap serve --http=0.0.0.0:8090`.
|
||||
|
||||
Run `./upsnap serve --http=0.0.0.0:8090`. For more options check `./upsnap --help`.
|
||||
For more options check `./upsnap --help` or visit [PocketBase documentation](https://pocketbase.io/docs).
|
||||
|
||||
If you need network discovery, make sure to have nmap installed and run upsnap as root/admin.
|
||||
If you need network discovery, make sure to have `nmap` installed and run upsnap as root/admin.
|
||||
|
||||
## 🐳 Run in docker
|
||||
|
||||
@@ -51,7 +52,7 @@ upsnap.example.com {
|
||||
}
|
||||
```
|
||||
|
||||
## Help developing
|
||||
## 🔧 Help developing
|
||||
|
||||
Fork this branch and clone it.
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
faLock
|
||||
} from '@fortawesome/free-solid-svg-icons';
|
||||
import Fa from 'svelte-fa';
|
||||
import { sortPorts } from '../sorts';
|
||||
|
||||
export let device;
|
||||
export let now;
|
||||
@@ -21,10 +22,6 @@
|
||||
function wake() {
|
||||
fetch(`${dev ? 'http://localhost:8090' : ''}/api/upsnap/wake/${device.id}`);
|
||||
}
|
||||
|
||||
function sortPorts(a, b) {
|
||||
return a.number - b.number;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 g-4">
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { pocketbase } from '@stores/pocketbase';
|
||||
import { pocketbase, devices } from '@stores/pocketbase';
|
||||
import { faEye, faEyeSlash, faPlus, faTrashCan } from '@fortawesome/free-solid-svg-icons';
|
||||
import Fa from 'svelte-fa';
|
||||
|
||||
export let device;
|
||||
export let mode;
|
||||
|
||||
let pb;
|
||||
let timeout;
|
||||
let button = {
|
||||
state: 'none',
|
||||
@@ -25,12 +23,6 @@
|
||||
let passwordShow = false;
|
||||
$: passwordType = passwordShow ? 'text' : 'password';
|
||||
|
||||
onMount(async () => {
|
||||
pocketbase.subscribe((conn) => {
|
||||
pb = conn;
|
||||
});
|
||||
});
|
||||
|
||||
async function addOrUpdateDevice() {
|
||||
button.state = 'waiting';
|
||||
try {
|
||||
@@ -47,16 +39,18 @@
|
||||
for (let i = 0; i < device.expand.ports.length; i++) {
|
||||
const port = device.expand.ports[i];
|
||||
if (!port.id) {
|
||||
const result = await pb.collection('ports').create(port);
|
||||
const result = await $pocketbase.collection('ports').create(port);
|
||||
device.ports = [...device.ports, result.id];
|
||||
} else {
|
||||
await $pocketbase.collection('ports').update(port.id, port);
|
||||
}
|
||||
}
|
||||
|
||||
// create or update device
|
||||
if (mode === 'add') {
|
||||
await pb.collection('devices').create(device);
|
||||
await $pocketbase.collection('devices').create(device);
|
||||
} else {
|
||||
await pb.collection('devices').update(device.id, device);
|
||||
await $pocketbase.collection('devices').update(device.id, device);
|
||||
}
|
||||
|
||||
// show button with timeout
|
||||
@@ -79,10 +73,11 @@
|
||||
async function deleteDevice() {
|
||||
deleteButton.state = 'waiting';
|
||||
try {
|
||||
await $pocketbase.collection('devices').delete(device.id);
|
||||
device.ports.forEach(async (port) => {
|
||||
await pb.collection('ports').delete(port);
|
||||
await $pocketbase.collection('ports').delete(port);
|
||||
});
|
||||
await pb.collection('devices').delete(device.id);
|
||||
delete $devices[device.id];
|
||||
goto('/');
|
||||
} catch (error) {
|
||||
clearTimeout(timeout);
|
||||
@@ -100,7 +95,7 @@
|
||||
// ports with id exist in db, ports without id are not created yet
|
||||
const port = device.expand.ports[idx];
|
||||
if (port.id) {
|
||||
await pb.collection('ports').delete(port.id);
|
||||
await $pocketbase.collection('ports').delete(port.id);
|
||||
const i = device.ports.indexOf(port.id);
|
||||
if (i !== -1) {
|
||||
device.ports.splice(i, 1);
|
||||
|
||||
@@ -1,31 +1,22 @@
|
||||
<script>
|
||||
import { page } from '$app/stores';
|
||||
import { theme } from '@stores/theme';
|
||||
import { pocketbase } from '@stores/pocketbase';
|
||||
import { pocketbase, settings } from '@stores/pocketbase';
|
||||
import { faSun, faMoon, faCircleHalfStroke, faBrush } from '@fortawesome/free-solid-svg-icons';
|
||||
import Fa from 'svelte-fa';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let pb;
|
||||
let website_title = '';
|
||||
|
||||
onMount(async () => {
|
||||
pocketbase.subscribe((conn) => {
|
||||
pb = conn;
|
||||
});
|
||||
const result = await pb.collection('settings').getList(1, 1);
|
||||
website_title = result.items[0].website_title;
|
||||
|
||||
pb.collection('settings').subscribe('*', function (e) {
|
||||
website_title = e.record.website_title;
|
||||
document.title = website_title;
|
||||
$pocketbase.collection('settings').subscribe('*', function (e) {
|
||||
settings.set(e.record);
|
||||
document.title = $settings.website_title;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
{#if website_title !== ''}
|
||||
<title>{website_title}</title>
|
||||
{#if $settings.website_title !== ''}
|
||||
<title>{$settings.website_title}</title>
|
||||
{:else}
|
||||
<title>UpSnap</title>
|
||||
{/if}
|
||||
@@ -39,8 +30,8 @@
|
||||
alt="UpSnap"
|
||||
width="30"
|
||||
height="30"
|
||||
class:me-2={website_title !== ''}
|
||||
/>{website_title ? website_title : ''}
|
||||
class:me-2={$settings.website_title !== ''}
|
||||
/>{$settings.website_title ? $settings.website_title : ''}
|
||||
</a>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav">
|
||||
|
||||
@@ -4,9 +4,26 @@
|
||||
import { theme } from '@stores/theme';
|
||||
import Navbar from '@components/Navbar.svelte';
|
||||
import Transition from '@components/Transition.svelte';
|
||||
import { pocketbase, settings, devices } from '@stores/pocketbase';
|
||||
|
||||
let preferesDark;
|
||||
|
||||
onMount(async () => {
|
||||
let settingsRes = {};
|
||||
settingsRes = await $pocketbase.collection('settings').getList(1, 1);
|
||||
settings.set(settingsRes.items[0]);
|
||||
|
||||
let tempDevices = {};
|
||||
const devicesRes = await $pocketbase.collection('devices').getFullList(200, {
|
||||
sort: 'name',
|
||||
expand: 'ports'
|
||||
});
|
||||
devicesRes.forEach((device) => {
|
||||
tempDevices[device.id] = device;
|
||||
});
|
||||
devices.set(tempDevices);
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
// import bootstrap js
|
||||
import('bootstrap/js/dist/dropdown');
|
||||
|
||||
@@ -1,46 +1,35 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import DeviceCard from '@components/DeviceCard.svelte';
|
||||
import { pocketbase } from '@stores/pocketbase';
|
||||
|
||||
let devices = {};
|
||||
import { pocketbase, devices } from '@stores/pocketbase';
|
||||
import { sortDevices } from '../sorts';
|
||||
|
||||
onMount(async () => {
|
||||
let pb;
|
||||
pocketbase.subscribe((conn) => {
|
||||
pb = conn;
|
||||
});
|
||||
|
||||
// get all devices in pocketbase
|
||||
const result = await pb.collection('devices').getFullList(200, {
|
||||
expand: 'ports',
|
||||
sort: 'name'
|
||||
});
|
||||
result.forEach((device) => {
|
||||
devices[device.id] = device;
|
||||
});
|
||||
|
||||
// subscribe to database events
|
||||
pb.collection('devices').subscribe('*', async (e) => {
|
||||
$pocketbase.collection('devices').subscribe('*', async (e) => {
|
||||
if (e.action === 'create') {
|
||||
devices[e.record.id] = e.record;
|
||||
$devices[e.record.id] = e.record;
|
||||
} else if (e.action === 'update') {
|
||||
const device = await pb.collection('devices').getOne(e.record.id, {
|
||||
const device = await $pocketbase.collection('devices').getOne(e.record.id, {
|
||||
expand: 'ports'
|
||||
});
|
||||
devices[device.id] = device;
|
||||
$devices[device.id] = device;
|
||||
} else if (e.action === 'delete') {
|
||||
delete devices[e.record.id];
|
||||
delete $devices[e.record.id];
|
||||
}
|
||||
});
|
||||
pb.collection('ports').subscribe('*', async (e) => {
|
||||
$pocketbase.collection('ports').subscribe('*', async (e) => {
|
||||
if (e.action === 'update') {
|
||||
const device = await pb
|
||||
.collection('devices')
|
||||
.getFirstListItem(`ports.id ?= "${e.record.id}"`, {
|
||||
expand: 'ports'
|
||||
});
|
||||
devices[device.id] = device;
|
||||
const device = Object.values($devices).find((dev) =>
|
||||
dev.ports.includes(e.record.id)
|
||||
);
|
||||
if (!device) {
|
||||
return;
|
||||
}
|
||||
|
||||
// replace device.expand.ports with updated record
|
||||
const portIdx = device.expand.ports.findIndex((port) => port.id === e.record.id);
|
||||
$devices[device.id].expand.ports[portIdx] = e.record;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -56,10 +45,10 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="container text-body-emphasis">
|
||||
{#if Object.keys(devices).length > 0}
|
||||
<div class="container text-body-emphasis mb-4">
|
||||
{#if Object.keys($devices).length > 0}
|
||||
<div class="row">
|
||||
{#each Object.entries(devices) as [_, device]}
|
||||
{#each Object.values($devices).sort(sortDevices) as device}
|
||||
<DeviceCard {device} {now} />
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { pocketbase } from '@stores/pocketbase';
|
||||
import { devices } from '@stores/pocketbase';
|
||||
import DeviceForm from '@components/DeviceForm.svelte';
|
||||
|
||||
export let data;
|
||||
const id = data.params.id;
|
||||
let pb;
|
||||
let device = {
|
||||
id: id
|
||||
};
|
||||
let device;
|
||||
|
||||
onMount(async () => {
|
||||
pocketbase.subscribe((conn) => {
|
||||
pb = conn;
|
||||
});
|
||||
|
||||
const result = await pb.collection('devices').getOne(id, {
|
||||
expand: 'ports'
|
||||
});
|
||||
if (!result.expand.ports) {
|
||||
result.expand.ports = [];
|
||||
$: {
|
||||
device = $devices[data.params.id];
|
||||
if (device && !device?.expand?.ports) {
|
||||
device.expand.ports = [];
|
||||
}
|
||||
device = result;
|
||||
});
|
||||
}
|
||||
$:;
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<DeviceForm bind:device mode="edit" />
|
||||
</div>
|
||||
{#if device}
|
||||
<div class="container">
|
||||
<DeviceForm bind:device mode="edit" />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { dev } from '$app/environment';
|
||||
import { pocketbase } from '@stores/pocketbase';
|
||||
import { pocketbase, settings, devices } from '@stores/pocketbase';
|
||||
import DeviceForm from '@components/DeviceForm.svelte';
|
||||
import { faPlus } from '@fortawesome/free-solid-svg-icons';
|
||||
import Fa from 'svelte-fa';
|
||||
|
||||
let version = import.meta.env.UPSNAP_VERSION;
|
||||
|
||||
let pb;
|
||||
let files;
|
||||
let settings = {};
|
||||
let timeout;
|
||||
let buttons = {
|
||||
settings: {
|
||||
@@ -45,22 +42,13 @@
|
||||
};
|
||||
let scannedDevices = {};
|
||||
|
||||
onMount(async () => {
|
||||
pocketbase.subscribe((conn) => {
|
||||
pb = conn;
|
||||
});
|
||||
|
||||
const result = await pb.collection('settings').getList(1, 1);
|
||||
settings = result.items[0];
|
||||
});
|
||||
|
||||
async function saveSettings() {
|
||||
buttons.settings.state = 'waiting';
|
||||
try {
|
||||
if (settings.interval === '') {
|
||||
settings.interval = '@every 3s';
|
||||
if ($settings.interval === '') {
|
||||
$settings.interval = '@every 3s';
|
||||
}
|
||||
await pb.collection('settings').update(settings.id, settings);
|
||||
await $pocketbase.collection('settings').update($settings.id, $settings);
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
buttons.settings.state = 'none';
|
||||
@@ -79,7 +67,7 @@
|
||||
|
||||
async function scanDevices() {
|
||||
buttons.scan.state = 'waiting';
|
||||
await pb.collection('settings').update(settings.id, settings);
|
||||
await $pocketbase.collection('settings').update($settings.id, $settings);
|
||||
|
||||
fetch(`${dev ? 'http://localhost:8090' : ''}/api/upsnap/scan`)
|
||||
.then((res) => res.json())
|
||||
@@ -113,7 +101,8 @@
|
||||
}
|
||||
|
||||
async function addDevice(device) {
|
||||
await pb.collection('devices').create(device);
|
||||
await $pocketbase.collection('devices').create(device);
|
||||
$devices[device.id] = device;
|
||||
}
|
||||
|
||||
async function restoreV2Backup() {
|
||||
@@ -121,14 +110,14 @@
|
||||
|
||||
try {
|
||||
// delete all devices in pocketbase
|
||||
let result = await pb.collection('devices').getFullList();
|
||||
let result = await $pocketbase.collection('devices').getFullList();
|
||||
for (let index = 0; index < result.length; index++) {
|
||||
pb.collection('devices').delete(result[index].id);
|
||||
$pocketbase.collection('devices').delete(result[index].id);
|
||||
}
|
||||
// delete all ports in pocketbase
|
||||
result = await pb.collection('ports').getFullList();
|
||||
result = await $pocketbase.collection('ports').getFullList();
|
||||
for (let index = 0; index < result.length; index++) {
|
||||
await pb.collection('ports').delete(result[index].id);
|
||||
await $pocketbase.collection('ports').delete(result[index].id);
|
||||
}
|
||||
|
||||
let reader = new FileReader();
|
||||
@@ -148,7 +137,7 @@
|
||||
let thisDevicePorts = [];
|
||||
for (let index = 0; index < device.ports.length; index++) {
|
||||
const port = device.ports[index];
|
||||
const record = await pb.collection('ports').create({
|
||||
const record = await $pocketbase.collection('ports').create({
|
||||
name: port.name,
|
||||
number: port.number
|
||||
});
|
||||
@@ -156,7 +145,7 @@
|
||||
}
|
||||
|
||||
// create device
|
||||
await pb.collection('devices').create({
|
||||
await $pocketbase.collection('devices').create({
|
||||
name: device.name,
|
||||
ip: device.ip,
|
||||
mac: device.mac,
|
||||
@@ -201,7 +190,7 @@
|
||||
aria-label="Interval"
|
||||
aria-describedby="addon-wrapping"
|
||||
type="text"
|
||||
bind:value={settings.interval}
|
||||
bind:value={$settings.interval}
|
||||
/>
|
||||
</div>
|
||||
<h3 class="my-3">Website title</h3>
|
||||
@@ -214,7 +203,7 @@
|
||||
placeholder="e.g. 'UpSnap'"
|
||||
aria-label="Website title"
|
||||
aria-describedby="website-title"
|
||||
bind:value={settings.website_title}
|
||||
bind:value={$settings.website_title}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -275,7 +264,7 @@
|
||||
placeholder="e.g. '192.168.1.0/24'"
|
||||
aria-label="ip-range"
|
||||
aria-describedby="ip-range"
|
||||
bind:value={settings.scan_range}
|
||||
bind:value={$settings.scan_range}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
@@ -284,7 +273,7 @@
|
||||
class:btn-success={buttons.scan.state === 'success' ? true : false}
|
||||
class:btn-warning={buttons.scan.state === 'waiting' ? true : false}
|
||||
class:btn-danger={buttons.scan.state === 'failed' ? true : false}
|
||||
disabled={settings.scan_range === '' || buttons.scan.state !== 'none'
|
||||
disabled={$settings.scan_range === '' || buttons.scan.state !== 'none'
|
||||
? true
|
||||
: false}
|
||||
>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export function sortDevices(a, b) {
|
||||
return a.name > b.name;
|
||||
}
|
||||
|
||||
export function sortPorts(a, b) {
|
||||
return a.number - b.number;
|
||||
}
|
||||
@@ -1,14 +1,20 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
let backend_url;
|
||||
// set backend url based on environment
|
||||
let backend_url = '/';
|
||||
let isDevMode = import.meta.env.DEV;
|
||||
if (isDevMode) {
|
||||
backend_url = 'http://localhost:8090';
|
||||
} else {
|
||||
backend_url = '/';
|
||||
backend_url = 'http://127.0.0.1:8090';
|
||||
}
|
||||
|
||||
// get default values for stores
|
||||
const pb = new PocketBase(backend_url);
|
||||
pb.autoCancellation(false);
|
||||
|
||||
// export stores
|
||||
export const pocketbase = writable(pb);
|
||||
export const settings = writable({
|
||||
website_title: ''
|
||||
});
|
||||
export const devices = writable({});
|
||||
|
||||
Reference in New Issue
Block a user