Skip to content

Instantly share code, notes, and snippets.

/*
* Copyright (C) 2009-2016 Realtek Semiconductor Corp.
* All Rights Reserved.
*
* This program is the proprietary software of Realtek Semiconductor
* Corporation and/or its licensors, and only be used, duplicated,
* modified or distributed under the authorized license from Realtek.
*
* ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
* THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
/*
* Copyright (C) 2009-2016 Realtek Semiconductor Corp.
* All Rights Reserved.
*
* This program is the proprietary software of Realtek Semiconductor
* Corporation and/or its licensors, and only be used, duplicated,
* modified or distributed under the authorized license from Realtek.
*
* ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
* THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
// Global variables
// const BASE_URL = 'http://192.168.2.1:8443/api';
const BASE_URL = 'http://localhost:8443/api';
// const ip = '192.168.2.1'; // Hardcoded IP, mirroring original code's approach
let refreshInterval; // For port status polling
// Utility function to render content into main container
const express = require('express');
const cors = require('cors');
let systemConfig = {
description: "Managed Switch 7.4.8",
objectId: "1.3.6.1.4.1.12284.1",
version: "Managed Switch 7.4.8",
interfaces: 10,
async function showVlanPortConfig() {
showContent('<p>Loading VLAN Port Configuration...</p>');
try {
const response = await fetch(`${BASE_URL}/get-vlan-information`);
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
await response.json(); // Optional: response not used
const portOptions = Array.from({ length: 10 }, (_, i) => `<option value="${i + 1}">${i + 1}</option>`).join('');
this.app.post('/api/set_vlan_port', (req, res) => {
const { port, vlan: vlanStr, mode, action } = req.body;
const vlan = parseInt(vlanStr, 10);
if (!vports.includes(port)) {
return res.status(400).json({ error: 'Invalid port' });
}
if (!vlans.hasOwnProperty(vlan)) {
return res.status(400).json({ error: 'Invalid VLAN' });
async function showVlanPortConfig() {
showContent('<p>Loading VLAN Port Configuration...</p>');
try {
const response = await fetch(`${BASE_URL}/get-vlan-information`);
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
const data = await response.json(); // not used for now
const portOptions = Array.from({ length: 10 }, (_, i) => `<option value="${i + 1}">${i + 1}</option>`).join('');
let macAutoData = [
{ macAddress: 'AA:BB:CC:DD:EE:01', vlanId: 10, port: '1' },
{ macAddress: 'AA:BB:CC:DD:EE:02', vlanId: 20, port: '2' },
{ macAddress: 'AA:BB:CC:DD:EE:03', vlanId: 30, port: '3' },
{ macAddress: 'AA:BB:CC:DD:EE:04', vlanId: 10, port: '1' },
{ macAddress: 'AA:BB:CC:DD:EE:05', vlanId: 20, port: '2' },
{ macAddress: 'AA:BB:CC:DD:EE:06', vlanId: 30, port: '3' },
// Add more as needed
];
async function showMacAddressTable() {
showContent('<p>Loading MAC address table...</p>');
try {
const response = await fetch(`${BASE_URL}/mac-address-table`);
const data = await response.json();
// Extract unique ports from data as strings directly
const uniquePorts = [...new Set(data.map(entry => (entry.port ?? '').trim()))];
const portOptions = ['<option value="All">All</option>', ...uniquePorts.map(port => `<option value="${port}">${port}</option>`)].join('');
async function showMacBindTable() {
try {
const response = await fetch(`${BASE_URL}/mac-bind-table`);
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
const data = await response.json();
const portOptions = Array.from({ length: 10 }, (_, i) => `<option value="${i + 1}">${i + 1}</option>`).join('');
// Render form and table
showContent(`