1b53fa1b8SSui Chenconst { ipcRenderer } = require('electron'); 2b65280ffSSui Chenconst { spawnSync } = require('child_process'); 3b65280ffSSui Chenconst md5File = require('md5-file'); 4b65280ffSSui Chenconst https = require('https'); 5b65280ffSSui Chen 6b53fa1b8SSui ChenipcRenderer.on('filename', (event, x) => { 7b65280ffSSui Chen // Determine file type 8b65280ffSSui Chen let is_asio_log = false; 9b65280ffSSui Chen const data = fs.readFileSync(x, {encoding: 'utf-8'}); 10b65280ffSSui Chen let lines = data.split('\n'); 11b65280ffSSui Chen for (let i = 0; i < lines.length; i++) { 12b65280ffSSui Chen if (lines[i].indexOf('@asio') == 0) { 13b65280ffSSui Chen is_asio_log = true; 14b65280ffSSui Chen break; 15b65280ffSSui Chen } 16b65280ffSSui Chen } 17b65280ffSSui Chen 18b65280ffSSui Chen if (is_asio_log) { 19b65280ffSSui Chen ShowBlocker('Loading Boost ASIO handler tracking log'); 20b65280ffSSui Chen console.log('This file is a Boost Asio handler tracking log'); 21b65280ffSSui Chen ParseBoostHandlerTimeline(data); 22b65280ffSSui Chen OnGroupByConditionChanged_ASIO(); 23b65280ffSSui Chen if (boost_asio_handler_timeline_view.IsEmpty() == false) { 24b65280ffSSui Chen boost_asio_handler_timeline_view.CurrentFileName = x; 25b65280ffSSui Chen HideWelcomeScreen(); 26b65280ffSSui Chen ShowASIOTimeline(); 27b65280ffSSui Chen ShowNavigation(); 28b65280ffSSui Chen UpdateFileNamesString(); 29b65280ffSSui Chen } 30b65280ffSSui Chen HideBlocker(); 31b65280ffSSui Chen return; 32b65280ffSSui Chen } 33b65280ffSSui Chen 34b65280ffSSui Chen OpenDBusPcapFile(x); 35b65280ffSSui Chen UpdateLayout(); 36b53fa1b8SSui Chen}); 37b53fa1b8SSui Chen 38b53fa1b8SSui Chenfunction OpenFileHandler() { 39b53fa1b8SSui Chen ipcRenderer.send('file-request'); 40b65280ffSSui Chen} 41b65280ffSSui Chen 42b65280ffSSui Chen// The file may be either DBus dump or Boost Asio handler log 43b65280ffSSui Chendocument.getElementById('btn_open_file') 44b65280ffSSui Chen .addEventListener('click', OpenFileHandler); 45b65280ffSSui Chendocument.getElementById('btn_open_file2') 46b65280ffSSui Chen .addEventListener('click', OpenFileHandler); 47b65280ffSSui Chen 48b65280ffSSui Chendocument.getElementById('bah1').addEventListener( 49b65280ffSSui Chen 'click', OnGroupByConditionChanged_ASIO); 50b65280ffSSui Chendocument.getElementById('bah2').addEventListener( 51b65280ffSSui Chen 'click', OnGroupByConditionChanged_ASIO); 52b65280ffSSui Chendocument.getElementById('bah3').addEventListener( 53b65280ffSSui Chen 'click', OnGroupByConditionChanged_ASIO); 54b65280ffSSui Chen 55b65280ffSSui Chen// UI elements 56b65280ffSSui Chenvar g_group_by_dbus = document.getElementById('span_group_by_dbus'); 57b65280ffSSui Chenvar g_group_by_ipmi = document.getElementById('span_group_by_ipmi'); 58b65280ffSSui Chenvar g_group_by_asio = 59b65280ffSSui Chen document.getElementById('span_group_by_boost_asio_handler') 60b65280ffSSui Chenvar g_canvas_ipmi = document.getElementById('my_canvas_ipmi'); 61b65280ffSSui Chenvar g_canvas_dbus = document.getElementById('my_canvas_dbus'); 62b65280ffSSui Chenvar g_canvas_asio = document.getElementById('my_canvas_boost_asio_handler'); 63b65280ffSSui Chen 64b65280ffSSui Chenvar g_dbus_pcap_status_content = document.getElementById('dbus_pcap_status_content'); 65b65280ffSSui Chenvar g_dbus_pcap_error_content = document.getElementById('dbus_pcap_error_content'); 66b65280ffSSui Chenvar g_btn_download_dbus_pcap = document.getElementById('btn_download_dbus_pcap'); 67b65280ffSSui Chenvar g_welcome_screen_content = document.getElementById('welcome_screen_content'); 68b65280ffSSui Chenvar g_scapy_error_content = document.getElementById('scapy_error_content'); 69b65280ffSSui Chen 70b65280ffSSui Chenvar g_btn_zoom_reset = document.getElementById('btn_zoom_reset'); 71b65280ffSSui Chen 72b65280ffSSui Chenfunction DownloadDbusPcap() { 73b65280ffSSui Chen const url = 'https://raw.githubusercontent.com/openbmc/openbmc-tools/08ce0a5bad2b5c970af567c2e9888d444afe3946/dbus-pcap/dbus-pcap'; 74b65280ffSSui Chen 75b65280ffSSui Chen https.get(url, (res) => { 76b65280ffSSui Chen const path = 'dbus-pcap'; 77b65280ffSSui Chen const file_path = fs.createWriteStream(path); 78b65280ffSSui Chen res.pipe(file_path); 79b65280ffSSui Chen file_path.on('finish', () => { 80b65280ffSSui Chen file_path.close(); 81b65280ffSSui Chen alert("dbus-pcap download complete!"); 82b65280ffSSui Chen CheckDbusPcapPresence(); 83b65280ffSSui Chen }); 84b65280ffSSui Chen }); 85b65280ffSSui Chen} 86b65280ffSSui Chen 87b65280ffSSui Cheng_btn_download_dbus_pcap.addEventListener( 88b65280ffSSui Chen 'click', DownloadDbusPcap); 89b65280ffSSui Chen 90b65280ffSSui Chenfunction ShowDBusTimeline() { 91b65280ffSSui Chen g_canvas_dbus.style.display = 'block'; 92b65280ffSSui Chen g_group_by_dbus.style.display = 'block'; 93b65280ffSSui Chen} 94b65280ffSSui Chenfunction ShowIPMITimeline() { 95b65280ffSSui Chen g_canvas_ipmi.style.display = 'block'; 96b65280ffSSui Chen g_group_by_ipmi.style.display = 'block'; 97b65280ffSSui Chen} 98b65280ffSSui Chenfunction ShowASIOTimeline() { 99b65280ffSSui Chen g_canvas_asio.style.display = 'block'; 100b65280ffSSui Chen g_group_by_asio.style.display = 'block'; 101b65280ffSSui Chen} 102b65280ffSSui Chen 103b65280ffSSui Chen// Make sure the user has scapy.all installed 104b65280ffSSui Chenfunction IsPythonInstallationOK() { 105b65280ffSSui Chen const x = spawnSync('python3', ['-m', 'scapy.all']); 106b65280ffSSui Chen return (x.status == 0); 107b65280ffSSui Chen} 108b65280ffSSui Chen 109b65280ffSSui Chenfunction IsDbusPcapPresent() { 110b65280ffSSui Chen // This should exist if the openbmc-tools repository 111b65280ffSSui Chen // is checked out as a whole 112b65280ffSSui Chen const dbus_pcap = '../dbus-pcap/dbus-pcap'; 113b65280ffSSui Chen 114b65280ffSSui Chen if (fs.existsSync('dbus-pcap')) { 115b65280ffSSui Chen return true; 116b65280ffSSui Chen } else if (fs.existsSync(dbus_pcap)) { // Create symlink 117b65280ffSSui Chen fs.symlinkSync(dbus_pcap, './dbus-pcap'); 118b65280ffSSui Chen return true; 119b65280ffSSui Chen } else { 120b65280ffSSui Chen return false; 121b65280ffSSui Chen } 122b65280ffSSui Chen} 123b65280ffSSui Chen 124b65280ffSSui Chenfunction CheckDependencies() { 125b65280ffSSui Chen g_dbus_pcap_status_content.style.display = 'none'; 126b65280ffSSui Chen g_dbus_pcap_error_content.style.display = 'none'; 127b65280ffSSui Chen g_scapy_error_content.style.display = 'none'; 128b65280ffSSui Chen g_welcome_screen_content.style.display = 'none'; 129b65280ffSSui Chen 130b65280ffSSui Chen const dbus_pcap_ok = IsDbusPcapPresent(); 131b65280ffSSui Chen if (!dbus_pcap_ok) { 132b65280ffSSui Chen g_dbus_pcap_error_content.style.display = 'block'; 133b65280ffSSui Chen } 134b65280ffSSui Chen 135b65280ffSSui Chen const scapy_ok = IsPythonInstallationOK(); 136b65280ffSSui Chen if (!scapy_ok) { 137b65280ffSSui Chen g_scapy_error_content.style.display = 'block'; 138b65280ffSSui Chen } 139b65280ffSSui Chen 140b65280ffSSui Chen let msg = ""; 141b65280ffSSui Chen if (dbus_pcap_ok) { 142b65280ffSSui Chen msg += 'dbus-pcap found, md5sum: ' + 143b65280ffSSui Chen md5File.sync('dbus-pcap'); 144b65280ffSSui Chen g_dbus_pcap_status_content.style.display = 'block'; 145b65280ffSSui Chen g_dbus_pcap_status_content.textContent = msg; 146b65280ffSSui Chen } 147b65280ffSSui Chen 148b65280ffSSui Chen if (dbus_pcap_ok && scapy_ok) { 149b65280ffSSui Chen g_welcome_screen_content.style.display = 'block'; 150b65280ffSSui Chen } 151b65280ffSSui Chen} 152b65280ffSSui Chen 153b65280ffSSui Chenfunction Init() { 154b65280ffSSui Chen console.log('[Init] Initialization'); 155b65280ffSSui Chen ipmi_timeline_view.Canvas = document.getElementById('my_canvas_ipmi'); 156b65280ffSSui Chen dbus_timeline_view.Canvas = document.getElementById('my_canvas_dbus'); 157b65280ffSSui Chen boost_asio_handler_timeline_view.Canvas = 158b65280ffSSui Chen document.getElementById('my_canvas_boost_asio_handler'); 159b65280ffSSui Chen 160b65280ffSSui Chen // Hide all canvases until the user loads files 161b65280ffSSui Chen ipmi_timeline_view.Canvas.style.display = 'none'; 162b65280ffSSui Chen dbus_timeline_view.Canvas.style.display = 'none'; 163b65280ffSSui Chen boost_asio_handler_timeline_view.Canvas.style.display = 'none'; 164b65280ffSSui Chen 165b65280ffSSui Chen let v1 = ipmi_timeline_view; 166b65280ffSSui Chen let v2 = dbus_timeline_view; 167b65280ffSSui Chen let v3 = boost_asio_handler_timeline_view; 168b65280ffSSui Chen 169b65280ffSSui Chen // Link views 170b65280ffSSui Chen v1.linked_views = [v2, v3]; 171b65280ffSSui Chen v2.linked_views = [v1, v3]; 172b65280ffSSui Chen v3.linked_views = [v1, v2]; 173b65280ffSSui Chen 174b65280ffSSui Chen // Set accent color 175b65280ffSSui Chen v1.AccentColor = 'rgba(0,224,224,0.5)'; 176b65280ffSSui Chen v2.AccentColor = 'rgba(0,128,0, 0.5)'; 177b65280ffSSui Chen v3.AccentColor = '#E22'; 178b65280ffSSui Chen 179b65280ffSSui Chen CheckDependencies(); 180*c403b037SSui Chen 181*c403b037SSui Chen DragElement(document.getElementById("highlighted_messages")); 182b65280ffSSui Chen} 183b65280ffSSui Chen 184b65280ffSSui Chenvar g_WelcomeScreen = document.getElementById('welcome_screen'); 185b65280ffSSui Chenfunction HideWelcomeScreen() { 186b65280ffSSui Chen g_WelcomeScreen.style.display = 'none'; 187b65280ffSSui Chen} 188b65280ffSSui Chen 189b65280ffSSui Chenvar g_Blocker = document.getElementById('blocker'); 190b65280ffSSui Chenvar g_BlockerCaption = document.getElementById('blocker_caption'); 191b65280ffSSui Chenfunction HideBlocker() { 192b65280ffSSui Chen g_Blocker.style.display = 'none'; 193b65280ffSSui Chen} 194b65280ffSSui Chenfunction ShowBlocker(msg) { 195b65280ffSSui Chen g_Blocker.style.display = 'block'; 196b65280ffSSui Chen g_BlockerCaption.textContent = msg; 197b65280ffSSui Chen} 198b65280ffSSui Chen 199b65280ffSSui Chenvar g_Navigation = document.getElementById('div_navi_and_replay'); 200b65280ffSSui Chenfunction ShowNavigation() { 201b65280ffSSui Chen g_Navigation.style.display = 'block'; 202b65280ffSSui Chen} 203b65280ffSSui Chen 204b65280ffSSui Chenfunction UpdateFileNamesString() { 205b65280ffSSui Chen let tmp = []; 206b65280ffSSui Chen if (ipmi_timeline_view.CurrentFileName != '') { 207b65280ffSSui Chen tmp.push('IPMI timeline: ' + ipmi_timeline_view.CurrentFileName) 208b65280ffSSui Chen } 209b65280ffSSui Chen if (dbus_timeline_view.CurrentFileName != '') { 210b65280ffSSui Chen tmp.push('DBus timeline: ' + dbus_timeline_view.CurrentFileName) 211b65280ffSSui Chen } 212b65280ffSSui Chen if (boost_asio_handler_timeline_view.CurrentFileName != '') { 213b65280ffSSui Chen tmp.push( 214b65280ffSSui Chen 'ASIO timeline: ' + boost_asio_handler_timeline_view.CurrentFileName); 215b65280ffSSui Chen } 216b65280ffSSui Chen let s = tmp.join('<br/>'); 217b65280ffSSui Chen document.getElementById('capture_info').innerHTML = s; 218b65280ffSSui Chen} 219b65280ffSSui Chen 220b65280ffSSui Chenvar g_cb_debug_info = document.getElementById('cb_debuginfo'); 221b65280ffSSui Chen 222b65280ffSSui Chen 223b65280ffSSui ChenInit(); 224