Recent Posts

Pages: 1 2 [3] 4 5 ... 7
21
Dev Stuff / Re: New Dashboard Socket Server
« Last post by razwall on March 14, 2025, 12:56:51 PM »
Response output:

{ "cpu": "14.23" }
{ "network": { "eth0": { "download": 13456, "upload": 7890 } } }
{ "memory": "62.50" }
{ "connections": [
    "tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:*",
    "tcp ESTABLISHED 0 0 192.168.1.10:54321 192.168.1.20:80"
] }
{ "disk": [
    { "filesystem": "/dev/sda1", "used": "45%", "mount": "/" },
    { "filesystem": "/dev/sdb1", "used": "78%", "mount": "/data" }
] }
22
Dev Stuff / Re: New Dashboard Socket Server
« Last post by razwall on March 14, 2025, 12:56:03 PM »
Tick Polling Request:
{
  "cpu": 2,
  "memory": 5,
  "network": 3,
  "connections": 10,
  "disk": 15
}
23
Dev Stuff / New Dashboard Socket Server
« Last post by razwall on March 14, 2025, 12:54:55 PM »
Socket Service:

#!/usr/bin/perl
use strict;
use warnings;
use Net::WebSocket::Server;
use JSON;

# Store previous network stats
my %prev_net_stats = get_network_usage();

# Start WebSocket server
Net::WebSocket::Server->new(
    listen => 3000,
    on_connect => sub {
        my ($conn) = @_;
        my %last_check = (
            cpu => time(),
            memory => time(),
            network => time(),
            connections => time(),
            disk => time()
        );
        my %intervals = (
            cpu => 2,
            memory => 5,
            network => 3,
            connections => 10,
            disk => 10
        );

        $conn->on(utf8 => sub {
            my $msg = shift;
            my $config = eval { decode_json($msg) };
            return unless ref $config eq 'HASH';

            # Set custom intervals from the client
            $intervals{cpu}        = $config->{cpu}        if exists $config->{cpu};
            $intervals{memory}    = $config->{memory}    if exists $config->{memory};
            $intervals{network}    = $config->{network}    if exists $config->{network};
            $intervals{connections}= $config->{connections} if exists $config->{connections};
            $intervals{disk}      = $config->{disk}      if exists $config->{disk};
        });

        while ($conn->is_open) {
            my $now = time();

            # Check and send updates based on intervals
            if ($now - $last_check{cpu} >= $intervals{cpu}) {
                $conn->send(encode_json({ cpu => get_cpu_usage() }));
                $last_check{cpu} = $now;
            }
            if ($now - $last_check{memory} >= $intervals{memory}) {
                $conn->send(encode_json({ memory => get_memory_usage() }));
                $last_check{memory} = $now;
            }
            if ($now - $last_check{network} >= $intervals{network}) {
                $conn->send(encode_json({ network => get_network_stats() }));
                $last_check{network} = $now;
            }
            if ($now - $last_check{connections} >= $intervals{connections}) {
                $conn->send(encode_json({ connections => get_network_connections() }));
                $last_check{connections} = $now;
            }
            if ($now - $last_check{disk} >= $intervals{disk}) {
                $conn->send(encode_json({ disk => get_disk_usage() }));
                $last_check{disk} = $now;
            }

            # Sleep for a short time to prevent high CPU usage
            select(undef, undef, undef, 0.5);
        }
    }
)->start;

### **Helper Functions**
sub get_cpu_usage {
    open my $fh, '<', "/proc/stat" or return;
    my $line = <$fh>;
    close $fh;

    my @cpu_data = (split /\s+/, $line)[1..8];
    my $total = 0;
    my $idle = $cpu_data[3];

    $total += $_ for @cpu_data;

    state $prev_total = $total;
    state $prev_idle = $idle;

    my $diff_total = $total - $prev_total;
    my $diff_idle = $idle - $prev_idle;

    $prev_total = $total;
    $prev_idle = $idle;

    return sprintf("%.2f", 100 * (1 - $diff_idle / $diff_total));
}

sub get_memory_usage {
    open my $fh, '<', "/proc/meminfo" or return;
    my %mem;
   
    while (<$fh>) {
        if (/^(MemTotal|MemAvailable):\s+(\d+)/) {
            $mem{$1} = $2;
        }
    }
    close $fh;

    return sprintf("%.2f", 100 * (1 - $mem{MemAvailable} / $mem{MemTotal}));
}

sub get_network_usage {
    open my $fh, '<', "/proc/net/dev" or return;
    my %stats;

    while (<$fh>) {
        if (/^\s*(\w+):\s*(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+(\d+)/) {
            my ($iface, $rx_bytes, $tx_bytes) = ($1, $2, $3);
            $stats{$iface} = { download => $rx_bytes, upload => $tx_bytes };
        }
    }
    close $fh;
   
    return %stats;
}

sub get_network_stats {
    my %current = get_network_usage();
    my %stats_diff;

    foreach my $iface (keys %current) {
        if (exists $prev_net_stats{$iface}) {
            $stats_diff{$iface} = {
                download => $current{$iface}{download} - $prev_net_stats{$iface}{download},
                upload => $current{$iface}{upload} - $prev_net_stats{$iface}{upload},
            };
        } else {
            $stats_diff{$iface} = { download => 0, upload => 0 };
        }
    }

    %prev_net_stats = %current;
    return \%stats_diff;
}

sub get_network_connections {
    my @connections;
    my $cmd = `ss -tan 2>/dev/null` || `netstat -tan 2>/dev/null`;

    foreach my $line (split /\n/, $cmd) {
        if ($line =~ /\b(LISTEN|ESTABLISHED|TIME_WAIT|CLOSE_WAIT|SYN_SENT)\b/) {
            push @connections, $line;
        }
    }

    return \@connections;
}

sub get_disk_usage {
    my @disks;
    my $cmd = `df -h --output=source,pcent,target | tail -n +2`;

    foreach my $line (split /\n/, $cmd) {
        if ($line =~ /^(\S+)\s+(\d+%)\s+(\S+)/) {
            push @disks, { filesystem => $1, used => $2, mount => $3 };
        }
    }

    return \@disks;
}
24
General Discussion / SPAM
« Last post by razwall on March 11, 2025, 05:28:01 PM »
I was hoping it wouldn't come to this, due to spammers I had to enable email confirmations and privacy acceptance etc. I have blocked a few users and IPs. Cant seem to get away from these dang robot spammers. Can't say the I miss forum moderation..
25
General Discussion / Re: Back at it again
« Last post by razwall on March 11, 2025, 05:13:09 PM »
I have a working razwall package for the installer but I still need to add some additional setup scripts to get things working right away. First is enable httpd by default, second is to generate an SSL certificate, next is to start the ip_forwarding services and begin WAN/LAN setup. It's a lot to get done, but I'm till going to push for some type of release by friday no matter how unstable.
26
General Discussion / Back at it again
« Last post by razwall on March 07, 2025, 08:55:30 AM »
I have been putting a lot of force behind this project this past week. Working on these config details for clean install:

Building a razwall package for Slackware custom "R" package library
Creating ISO doint.sh setup script for ISO install
Building initial firewall rule sets for new installation
Create a new ISO including the razwall package
Adding setup features to ConsoleUI

27
Dev Stuff / DHCP rc script from ISO README
« Last post by razwall on March 07, 2025, 08:47:25 AM »
RC script for DHCP
------------------

A Slackware start/stop script for the DHCP server that you can save as
"/etc/rc.d/rc.dhcpd".

Don't forget to make the script executable:

  chmod +x /etc/rc.d/rc.dhcpd

You can add the following lines to /etc/rc.d/rc.local so that the DHCP
service starts when your server boots:

if [ -x /etc/rc.d/rc.dhcpd ]; then
  # Start the DHCP server:
  /etc/rc.d/rc.dhcpd start
fi

This is the content of the file "/etc/rc.d/rc.dhcpd":

#!/bin/sh
#
# /etc/rc.d/rc.dhcpd
#      This shell script takes care of starting and stopping
#      the ISC DHCPD service
#

# Put the command line options here that you want to pass to dhcpd:
DHCPD_OPTIONS="-q eth0"

[ -x /usr/sbin/dhcpd ] || exit 0

[ -f /etc/dhcpd.conf ] || exit 0

start() {
      # Start daemons.
      echo -n "Starting dhcpd:  /usr/sbin/dhcpd $DHCPD_OPTIONS "
      /usr/sbin/dhcpd $DHCPD_OPTIONS
      echo
}
stop() {
      # Stop daemons.
      echo -n "Shutting down dhcpd: "
      killall -TERM dhcpd
      echo
}
status() {
  PIDS=$(pidof dhcpd)
  if [ "$PIDS" == "" ]; then
    echo "dhcpd is not running!"
  else
    echo "dhcpd is running at pid(s) ${PIDS}."
  fi
}
restart() {
      stop
      start
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        ;;
  status)
        status
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart}"
        ;;
esac

exit 0
28
Dev Stuff / razwall package build instructions - test 1
« Last post by razwall on March 07, 2025, 08:46:17 AM »
Slackware package step‐by‐step guide:

1. Create a Temporary Packaging Directory
Set up a directory that mirrors where your files will be installed. For example, if files need to go in /razwall and your configuration files in /etc/razconfig and /var/razlib something like:
mkdir -p razwallpkg/razwall
mkdir -p razwallpkg/etc/razconfig..
mkdir -p razwallpkg/var/razlib..
Then copy your files into these directories.

2. Create the Package Metadata
Inside your package root, create an install directory (if it doesn’t already exist) and add a slack-desc file. This file is a plain-text description of your package. A minimal example might look like:
                    |-----handy-ruler------------------------------------------------------|

razwall: RazWall Firewall - Simple is Safe
razwall:
razwall: RazWall Firewall is a small linux firewall package built
razwall: on Slackware 15. This release uses iptables, OpenVPN, bind9
razwall: isc-dhcp-server, and Apache.
razwall:
razwall: Homepage:  https://razwall.com
razwall: Support:  https://razwall.com/forum
razwall: Download:  https://sourceforge.com/projects/razwall
razwall: Source:    https://github.com/p3rlphr33k/razwall
razwall:

Maximum of 11 lines! – Ruler just for line length, do not include.
Place this file at razwallpkg/install/slack-desc.
3. (Optional) Add Installation Scripts
If you need to run any pre- or post-install to update configurations or set permissions, you can include scripts like doinst.sh in the razwallpkg/install directory. However, this isn’t necessary.
4. Build the Package
Change to your package root directory and use Slackware’s makepkg tool to create your package archive. For example:
cd razwallpkg
makepkg -l y -c n ../razwall-1.0.txz
Here:
• -l y tells makepkg to preserve the file permissions.
• -c n tells it not to compress the package contents (you can adjust these flags as needed).
This command creates a Slackware package (either .txz or .tgz, depending on your system’s default) in the parent directory.

5. Test Your Package
Finally, install your package on a test system using Slackware’s installpkg:
installpkg razwall-1.0.txz
29
News / Re: SourceForge
« Last post by razwall on February 23, 2025, 03:16:21 PM »
This is just another piece to the puzzle, the next step is packaging what I do have and including it in the iso. But I have to make sure everything is working properly. Almost there!
30
News / Re: SourceForge
« Last post by razwall on February 23, 2025, 03:14:30 PM »
Yup, the post says this does not install razwall. It's just a custom iso I will use to build the installer on.
Pages: 1 2 [3] 4 5 ... 7