/* SYSCMD — arbre avec sections en sous-niveaux */ function t(fr, en) { return { fr: fr, en: en }; } let currentNode = null; const TREE = { id: 'root', label: t('OS', 'OS'), children: [ { id: 'linux', label: t('Linux', 'Linux'), children: [ { id: 'ubuntu', label: t('Ubuntu', 'Ubuntu'), children: [ { id: 'ubuntu-2004', label: t('20.04', '20.04'), osKey: 'ubuntu', sectionIds: ['sys','apt','users'] }, { id: 'ubuntu-2204', label: t('22.04', '22.04'), osKey: 'ubuntu', sectionIds: ['sys','apt','users'] }, { id: 'ubuntu-2404', label: t('24.04', '24.04'), osKey: 'ubuntu', sectionIds: ['sys','apt','users','systemd'] }, ]}, { id: 'debian', label: t('Debian', 'Debian'), osKey: 'debian', sectionIds: ['sys','apt','users','systemd'] }, { id: 'oracle', label: t('Oracle Linux', 'Oracle Linux'), osKey: 'oracle', sectionIds: ['oracle-dnf','oracle-spec','oracle-selinux','oracle-fw','systemd'] }, { id: 'rhel', label: t('RHEL / CentOS', 'RHEL / CentOS') }, { id: 'fedora', label: t('Fedora', 'Fedora') }, ]}, { id: 'windows', label: t('Windows', 'Windows'), children: [ { id: 'win-client', label: t('Client', 'Client'), children: [ { id: 'win-xp', label: t('XP', 'XP') }, { id: 'win-10', label: t('10', '10'), osKey: 'windows', sectionIds: ['win-sys','win-files','win-process','win-network'] }, { id: 'win-11', label: t('11', '11'), osKey: 'windows', sectionIds: ['win-sys','win-files','win-process','win-network'] }, ]}, { id: 'win-server', label: t('Server', 'Server'), children: [ { id: 'win-2016', label: t('2016', '2016'), osKey: 'windows-server', sectionIds: ['win-sys','win-files','win-process','win-network'] }, { id: 'win-2019', label: t('2019', '2019'), osKey: 'windows-server', sectionIds: ['win-sys','win-files','win-process','win-network'] }, ]}, ]}, { id: 'solaris', label: t('Solaris / illumos', 'Solaris / illumos'), osKey: 'solaris', sectionIds: ['solaris-ips','solaris-smf','solaris-zfs','solaris-zones'] }, { id: 'macos', label: t('macOS', 'macOS') }, { id: 'docker', label: t('Docker', 'Docker') }, { id: 'other', label: t('Other', 'Other') }, ] }; // ── SECTIONS ── const SEC = {}; SEC.sys = { label: t('syst\u00e8me', 'system'), commands: [ { d: t('Version du noyau', 'Kernel version'), c: 'uname -r' }, { d: t('Version OS', 'OS version'), c: 'lsb_release -a' }, { d: t('Memoire dispo', 'Memory available'), c: 'free -h' }, { d: t("Nom d'hote", 'Hostname'), c: 'hostnamectl' }, { d: t('Uptime', 'Uptime'), c: 'uptime' }, { d: t('Infos CPU', 'CPU info'), c: 'lscpu' }, { d: t('Date / heure', 'Date / time'), c: 'timedatectl' }, ]}; SEC.apt = { label: t('APT', 'APT'), commands: [ { d: t('Synchro depots', 'Sync repos'), c: 'sudo apt update' }, { d: t('Mise a jour', 'Full upgrade'), c: 'sudo apt full-upgrade -y' }, { d: t('Installer', 'Install'), c: 'sudo apt install [package]' }, { d: t('Purge', 'Purge'), c: 'sudo apt purge [package]' }, { d: t('Chercher', 'Search'), c: 'apt search [keyword]' }, { d: t('Paquets installes', 'Installed'), c: 'apt list --installed' }, { d: t('Fichiers fournis', 'Package files'), c: 'dpkg -L [package]' }, ]}; SEC.users = { label: t('utilisateurs', 'users'), commands: [ { d: t('Ajouter', 'Add user'), c: 'sudo adduser [name]' }, { d: t('Supprimer', 'Delete user'), c: 'sudo deluser --remove-home [name]' }, { d: t('Groupe sudo', 'Sudo group'), c: 'sudo usermod -aG sudo [name]' }, { d: t('Permissions', 'Permissions'), c: 'chmod 755 [file]' }, { d: t('Root', 'Root shell'), c: 'sudo -i' }, ]}; SEC.systemd = { label: t('systemd', 'systemd'), commands: [ { d: t('Start/Stop', 'Start/Stop'), c: 'sudo systemctl start|stop [service]' }, { d: t('Restart', 'Restart'), c: 'sudo systemctl restart [service]' }, { d: t('Enable', 'Enable'), c: 'sudo systemctl enable [service]' }, { d: t('Statut', 'Status'), c: 'systemctl status [service]' }, { d: t('Logs', 'Logs'), c: 'journalctl -u [service] -n 50' }, { d: t('Purger logs', 'Purge logs'), c: 'sudo journalctl --vacuum-time=7d' }, ]}; SEC['win-sys'] = { label: t('systeme', 'system'), commands: [ { d: t('(CMD) Version', '(CMD) Version'), c: 'ver' }, { d: t('(CMD) systeminfo', '(CMD) systeminfo'), c: 'systeminfo' }, { d: t('(PS) Get-ComputerInfo', '(PS) Get-ComputerInfo'), c: 'Get-ComputerInfo' }, ]}; SEC['win-files'] = { label: t('fichiers', 'files'), commands: [ { d: t('(CMD) dir', '(CMD) dir'), c: 'dir /s' }, { d: t('(CMD) rmdir', '(CMD) rmdir'), c: 'rmdir /s [folder]' }, { d: t('(PS) Get-ChildItem', '(PS) Get-ChildItem'), c: 'Get-ChildItem -Recurse -Filter *.txt' }, ]}; SEC['win-process'] = { label: t('processus', 'processes'), commands: [ { d: t('(CMD) tasklist', '(CMD) tasklist'), c: 'tasklist' }, { d: t('(CMD) taskkill', '(CMD) taskkill'), c: 'taskkill /IM notepad.exe /F' }, { d: t('(PS) Get-Process', '(PS) Get-Process'), c: 'Get-Process' }, ]}; SEC['win-network'] = { label: t('reseau', 'network'), commands: [ { d: t('(CMD) ipconfig', '(CMD) ipconfig'), c: 'ipconfig /all' }, { d: t('(CMD) netstat', '(CMD) netstat'), c: 'netstat -an | findstr LISTEN' }, { d: t('(PS) Test-NetConnection', '(PS) Test-NetConnection'), c: 'Test-NetConnection [ip] -Port [port]' }, ]}; SEC['oracle-dnf'] = { label: t('DNF', 'DNF'), commands: [ { d: t('Synchro', 'Sync'), c: 'sudo dnf check-update' }, { d: t('Upgrade', 'Upgrade'), c: 'sudo dnf upgrade -y' }, { d: t('Install', 'Install'), c: 'sudo dnf install [package]' }, { d: t('Remove', 'Remove'), c: 'sudo dnf remove [package]' }, ]}; SEC['oracle-spec'] = { label: t('Oracle spec.', 'Oracle spec.'), commands: [ { d: t('Ksplice status', 'Ksplice status'), c: 'sudo uptrack-status' }, { d: t('Ksplice upgrade', 'Ksplice upgrade'), c: 'sudo uptrack-upgrade' }, { d: t('Changer noyau', 'Switch kernel'), c: 'sudo grubby --set-default /boot/vmlinuz-[ver]' }, ]}; SEC['oracle-selinux'] = { label: t('SELinux', 'SELinux'), commands: [ { d: t('Statut', 'Status'), c: 'getenforce' }, { d: t('Permissif', 'Permissive'), c: 'sudo setenforce 0' }, { d: t('Logs AVC', 'AVC logs'), c: 'sudo ausearch -m avc -ts recent' }, ]}; SEC['oracle-fw'] = { label: t('firewalld', 'firewalld'), commands: [ { d: t('Status', 'Status'), c: 'sudo firewall-cmd --state' }, { d: t('Ouvrir port', 'Open port'), c: 'sudo firewall-cmd --permanent --add-port=22/tcp' }, ]}; SEC['solaris-ips'] = { label: t('IPS', 'IPS'), commands: [ { d: t('Refresh', 'Refresh'), c: 'sudo pkg refresh' }, { d: t('Update', 'Update'), c: 'sudo pkg update' }, { d: t('Install', 'Install'), c: 'sudo pkg install [package]' }, { d: t('Remove', 'Remove'), c: 'sudo pkg uninstall [package]' }, ]}; SEC['solaris-smf'] = { label: t('SMF', 'SMF'), commands: [ { d: t('Liste', 'List'), c: 'svcs -a' }, { d: t('Enable', 'Enable'), c: 'sudo svcadm enable [service]' }, { d: t('Disable', 'Disable'), c: 'sudo svcadm disable [service]' }, { d: t('Restart', 'Restart'), c: 'sudo svcadm restart [service]' }, ]}; SEC['solaris-zfs'] = { label: t('ZFS', 'ZFS'), commands: [ { d: t('Pool status', 'Pool status'), c: 'zpool status' }, { d: t('Scrub', 'Scrub'), c: 'sudo zpool scrub [pool]' }, { d: t('Snapshot', 'Snapshot'), c: 'sudo zfs snapshot [pool]/[ds]@[name]' }, { d: t('Send/Receive', 'Send/Receive'), c: 'zfs send [pool]/[ds]@snap | zfs receive [dest]' }, ]}; SEC['solaris-zones'] = { label: t('Zones', 'Zones'), commands: [ { d: t('Liste', 'List'), c: 'zoneadm list -cv' }, { d: t('Boot', 'Boot'), c: 'sudo zoneadm -z [zone] boot' }, { d: t('Halt', 'Halt'), c: 'sudo zoneadm -z [zone] halt' }, { d: t('Console', 'Console'), c: 'sudo zlogin -C [zone]' }, ]}; // ── RENDER TREE ── function renderTree() { const el = document.getElementById('tree'); el.innerHTML = ''; renderNode(el, TREE, 0); } function renderNode(container, node, depth) { const isBranch = node.children && node.children.length > 0; const isVersion = !!node.sectionIds; const isEmpty = !isBranch && !isVersion; const div = document.createElement('div'); if (depth === 0) { const label = document.createElement('div'); label.className = 'group-label'; label.textContent = node.label.fr; div.appendChild(label); } else { const row = document.createElement('div'); let cls = 'sidebar-link'; if (depth === 2) cls += ' sidebar-link-3'; if (depth === 3) cls += ' sidebar-link-4'; if (node === currentNode) cls += ' active'; row.className = cls; // Toggle or spacer if (isBranch) { const tgl = document.createElement('span'); tgl.className = 'tree-toggle open'; tgl.innerHTML = ''; row.appendChild(tgl); } else { const sp = document.createElement('span'); sp.style.cssText = 'width:16px;flex-shrink:0;display:inline-block'; row.appendChild(sp); } // Dot const dot = document.createElement('span'); if (isVersion || (node._parent && node._parent.sectionIds)) dot.className = 'dot-green'; else if (isBranch) dot.className = 'dot-orange'; else dot.className = 'dot-gray'; row.appendChild(dot); // Label const lbl = document.createElement('span'); lbl.textContent = node.label.fr; row.appendChild(lbl); // Count (only for non-section leaves that have data) let cnt = 0; if (node.sectionIds) { cnt = node.sectionIds.reduce(function(a, id) { return a + (SEC[id] ? SEC[id].commands.length : 0); }, 0); } if (cnt > 0) { const b = document.createElement('span'); b.className = 'ml-auto text-[0.625rem] text-[#94a3b8]'; b.textContent = '' + cnt; row.appendChild(b); } // Click row.onclick = function(e) { if (isBranch && (e.target.closest('.tree-toggle') || e.target.closest('[data-toggle]'))) { const tg = row.querySelector('.tree-toggle'); if (tg) { tg.classList.toggle('open'); row.nextElementSibling.classList.toggle('open'); e.stopPropagation(); } return; } selectNode(node); }; div.appendChild(row); } // Enfants if (isBranch) { const kids = document.createElement('div'); kids.className = 'tree-children open'; for (const ch of node.children) { ch._parent = node; renderNode(kids, ch, depth + 1); } div.appendChild(kids); } // Si c'est une version avec sectionIds, on ajoute les sections comme enfants if (isVersion && node.sectionIds) { const kids = document.createElement('div'); kids.className = 'tree-children'; // On déplie si c'est le noeud actif if (node === currentNode || (currentNode && currentNode._parent === node)) { kids.className = 'tree-children open'; } node.sectionIds.forEach(function(sid) { const sec = SEC[sid]; if (!sec) return; const snode = { id: node.id + '-' + sid, label: sec.label, _sectionId: sid, _parent: node }; renderNode(kids, snode, depth + 1); }); div.appendChild(kids); } container.appendChild(div); } // ── SELECT NODE ── function selectNode(node) { currentNode = node; renderTree(); const titleEl = document.getElementById('os-title'); const subEl = document.getElementById('os-sub'); const cmdsEl = document.getElementById('cmds'); const searchEl = document.getElementById('search'); searchEl.value = ''; // Cas 1: c'est une section (a _sectionId) if (node._sectionId) { const sec = SEC[node._sectionId]; if (sec) { titleEl.textContent = sec.label.fr; subEl.textContent = sec.commands.length + ' commandes'; showCmds(sec.commands); } return; } // Cas 2: c'est une version ou OS avec sectionIds (on affiche la première section) if (node.sectionIds && node.sectionIds.length > 0) { const sid = node.sectionIds[0]; const sec = SEC[sid]; if (sec) { titleEl.textContent = node.label.fr; subEl.textContent = sec.commands.length + ' commandes'; showCmds(sec.commands); } return; } // Cas 3: pas de données titleEl.textContent = node.label.fr; subEl.textContent = 'Aucune donnee'; cmdsEl.innerHTML = '
Pas encore de commandes pour cet OS.