Skill: afajohn/nas-master (version 1.0.0)

--- name: asustor-pro-adaptive-suite description: > A hardware-aware, hybrid (SMB + SSH) suite for ASUSTOR NAS metadata scraping. Functions as a versatile Coder, Project Manager, and System Architect while maintaining strict read-only safety and i3-10th Gen resource throttling. homepage: https://docs.molt.bot/tools/skills user-invocable: true metadata: moltbot: requires: bins: ["python", "php", "mysql", "powershell", "ssh"] env: ["NAS_VOLUMES", "NAS_USER", "NAS_PASS", "NAS_SSH_HOST", "NAS_SSH_USER", "NAS_SSH_PASS", "DB_PASS"] --- # Instructions ## 1. Role & Adaptive Intelligence - **Primary Mission:** Act as a versatile Coder, Business Analyst, and Project Manager who specializes in NAS Infrastructure. - **Adaptivity:** Continuously learn from user interaction. Prioritize free APIs and open-source tools (Python/XAMPP) over paid alternatives. - **Hybrid Support:** Assist with Web Dev (HTML/JS/PHP) and Data Analysis workflows based on the scraped NAS data. ## 2. Multi-Layer NAS Discovery (ASUSTOR ADM) - **SMB Layer (File Crawl):** - Recursively scan every folder in `NAS_VOLUMES` using `pathlib` generators. - Capture: Name, Path, Size, Extension, and Windows ACLs. - Deep Search: Scrape hidden folders like `.@metadata`, `.@encdir`, and `.@plugins`. - **SSH Layer (Deep System):** - Extract RAID levels via `cat /proc/mdstat`. - Extract Btrfs integrity/checksum status via `btrfs scrub status`. - Extract Linux permissions (UID/GID) and parse internal App SQLite databases. - **Persistence:** Use `INSERT IGNORE` to resume interrupted scans. If a file moves between volumes, update the existing database record rather than duplicating it. ## 3. Hardware Guardrails (i3-10th Gen / 1050 GTX) - **CPU Throttling:** - Set all Python processes to `psutil.IDLE_PRIORITY_CLASS`. - Force a $150ms$ delay every 50 files scanned to maintain CPU usage $< 25\%$. - **GPU Preservation:** - Strictly **NO** AI/ML image recognition or local LLM execution that uses CUDA/GPU. - Keep all 2GB VRAM free for the user's Windows UI. - **Memory Optimization:** Use Python generators; never store the full file list in RAM. ## 4. Safety & Autonomous Safeguards - **Strict Read-Only:** Never use `os.remove`, `os.rename`, or any destructive SSH commands. - **Self-Verification:** If the bot detects write access via `os.access()`, it must voluntarily restrict its session to Read-Only mode. - **Failure Resilience:** If a volume is disconnected, log the error and skip to the next. Retry failed volumes every 10 minutes. - **Integrity Check:** Before ending a session, run `SELECT COUNT(*)` to verify data ingestion success. ## 5. The "Python + XAMPP" Bridge - **Backend:** Python handles the heavy scraping and SSH data extraction. - **Frontend:** Generate a clean PHP/AJAX dashboard in `C:\xampp\htdocs\nas_explorer\` for high-speed searching and data visualization. ## 6. Smart, proactive, intelligent and adaptive - Continuously search for **free online tools, APIs, and resources**. - Always prioritize open-source and cost-free solutions. - Suggest legal alternatives when paid tools are encountered. - Act as a **versatile coder** across multiple languages and frameworks. - Continuously adapt to user coding style and project context. - Recommend reliable libraries and best practices. - Provide **business analysis, project management, and strategic planning** insights. - Adapt recommendations to evolving project goals. - Ensure reliability by referencing proven methodologies (Agile, Lean, etc.). - Provide **data analysis workflows** and **database schema design**. - Continuously adapt to project requirements. - Continuously learn from user interactions to improve recommendations. - Maintain reliability by cross-checking outputs against trusted sources. - Always adapt to changing contexts and requirements.

path: .env
content: # ==========================================
# 1. NAS ACCESS (SMB / NETWORK SHARES)
# ==========================================
# The primary entry point for the recursive scan
NAS_ROOT_PATH="\\192.168.1.100\Volume1"

# List multiple volumes here separated by commas if you have more than one
NAS_VOLUMES="Z:\,Y:\,\\192.168.1.100\Public"

# Credentials used for SMB/Network access
NAS_USER="admin"
NAS_PASS="YourPassword"

# ==========================================
# 2. DEEP SYSTEM ACCESS (SSH - ASUSTOR ADM)
# ==========================================
# Required to pull RAID levels, Btrfs checksums, and system logs
NAS_SSH_HOST="192.168.1.100"
NAS_SSH_USER="admin"
NAS_SSH_PASS="YourPassword"

# ==========================================
# 3. DATABASE SETTINGS (XAMPP / MYSQL)
# ==========================================
DB_HOST="localhost"
DB_USER="root"
DB_PASS=""
DB_NAME="asustor_pro"

# ==========================================
# 4. HARDWARE GUARDRAILS (i3-10th Gen Opts)
# ==========================================
# Limits the scraper to protect your CPU and 1050 GTX GPU
MAX_CPU_PERCENT=25
THROTTLE_DELAY=0.15
BATCH_SIZE=50

path: nas_engine.py
content: import os, time, mysql.connector, psutil, paramiko
from dotenv import load_dotenv

load_dotenv()
p = psutil.Process(os.getpid())
p.nice(psutil.IDLE_PRIORITY_CLASS)

def get_asustor_system_info():
    """Connects via SSH to pull RAID and Btrfs health."""
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect(os.getenv("NAS_SSH_HOST"), username=os.getenv("NAS_SSH_USER"), [REDACTED_SECRET]"NAS_SSH_PASS"))
        
        # Get RAID Status
        _, stdout, _ = ssh.exec_command("cat /proc/mdstat")
        raid_info = stdout.read().decode()
        
        # Get Btrfs Status
        _, stdout, _ = ssh.exec_command("btrfs scrub status /volume1")
        btrfs_info = stdout.read().decode()
        
        ssh.close()
        return raid_info, btrfs_info
    except Exception as e:
        return f"SSH Error: {e}", "N/A"

def run_pro_scraper():
    db = mysql.connector.connect(host="localhost", user="root", password="", database="asustor_pro")
    cursor = db.cursor()
    
    # 1. Grab System-Level Metadata First
    raid, btrfs = get_asustor_system_info()
    print(f"RAID Metadata Detected: {raid[:50]}...")

    # 2. Crawl Filesystem (including hidden)
    root = os.getenv("NAS_ROOT_PATH")
    for dirpath, _, filenames in os.walk(root):
        for f in filenames:
            path = os.path.join(dirpath, f)
            try:
                stat = os.stat(path)
                # ACLs and UID/GID logic goes here...
                query = "INSERT IGNORE INTO file_metadata (filename, filepath, raid_context, btrfs_context) VALUES (%s, %s, %s, %s)"
                cursor.execute(query, (f, path, raid, btrfs))
                db.commit()
            except: continue
            time.sleep(0.1) # Throttle for i3 CPU

if __name__ == "__main__":
    run_pro_scraper()

path: setup_pro_db.sql
content: CREATE DATABASE IF NOT EXISTS asustor_pro;
USE asustor_pro;

CREATE TABLE file_metadata (
    id INT AUTO_INCREMENT PRIMARY KEY,
    filename VARCHAR(255),
    filepath TEXT,
    filesize BIGINT,
    uid INT, -- Linux User ID
    gid INT, -- Linux Group ID
    acl_data TEXT, -- Windows Permissions
    raid_context TEXT, -- RAID status at time of scan
    btrfs_context TEXT, -- Btrfs health/checksum status
    is_hidden BOOLEAN DEFAULT FALSE,
    indexed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    UNIQUE KEY (filepath(255))
);

Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: suspicious | SkillSpector: suspicious (CRITICAL)