Skip to content

01_main_application_orchestrator_.md

Arnab Nandy edited this page Oct 25, 2025 · 2 revisions

Chapter 1: Main Application Orchestrator

Imagine you're in a big control room with many buttons, each launching a different part of a complex system. How do you know where to start? How do you ensure only authorized people can use it? And how do all those different parts work together smoothly?

In the shellnetbuilder project, the Main Application Orchestrator is that central control room. It's like the conductor of an orchestra, making sure everything starts correctly and guiding you to the right tools when you need them.

What Problem Does It Solve?

The core problem the Main Application Orchestrator solves is providing a single, secure, and intuitive entry point to the entire Network Builder application. Without it, you'd have to know exactly which program to run for each network task, which could be confusing and error-prone.

Let's think of a concrete use case: Use Case: Setting up a DHCP server

  1. You want to configure a DHCP server for your network.
  2. You launch the Network Builder application.
  3. The Main Application Orchestrator first checks if you have the necessary permissions (are you a "root" user?).
  4. Once authorized, it shows you a friendly menu with options like "Automatic DHCP", "Setup Name Server", "Setup File Server", and more.
  5. You click on "Automatic DHCP".
  6. The Main Application Orchestrator then launches the specific tool for DHCP configuration, letting you set up your server.

This chapter will guide you through how this initial orchestration happens.

The Conductor's Role: How it Works

The Main Application Orchestrator has a few key responsibilities:

  1. Security Check: It performs an initial login check to ensure only privileged users (like 'root' on Linux systems) can access the powerful network configuration tools. This is crucial for system security.
  2. Main Menu: It presents the main graphical interface, displaying all the available network management tasks in an organized way.
  3. Tool Launcher: When you select a task (e.g., "Setup Name Server"), it acts as a launcher, starting the specific graphical tool designed for that task. These individual tools are examples of Graphical User Interface (GUI) Frames.
  4. Overall Flow: It manages the overall user experience, guiding you from the start to the specific tool you need.

A Look Under the Hood (Non-Code Walkthrough)

Let's trace what happens when you launch the Network Builder application:

sequenceDiagram
    participant User as User
    participant OS as Operating System
    participant MainOrchestrator as Main Orchestrator (mainwindow.java)
    participant PermissionChecker as Permission Checker
    participant DHCPTool as DHCP Configuration Tool (dhcpframe)

    User->>OS: Launch Network Builder
    OS->>MainOrchestrator: Start `mainwindow.java`
    MainOrchestrator->>PermissionChecker: Check user permissions
    PermissionChecker-->>MainOrchestrator: Is user 'root'? (Yes/No)
    alt User is NOT 'root'
        MainOrchestrator->>User: Display "Root User LOGIN Must Required" message
        MainOrchestrator->>OS: Exit Application
    else User IS 'root'
        MainOrchestrator->>User: Display Main Menu
        User->>MainOrchestrator: Click "Automatic DHCP" button
        MainOrchestrator->>DHCPTool: Launch DHCP Configuration Tool
        DHCPTool->>User: Display DHCP Setup Screen
    end
Loading

Explanation of the Flow: When you start the shellnetbuilder application, the mainwindow.java program takes charge. Its first job is to verify your identity. If you're not the designated "root" user, it immediately stops, preventing unauthorized changes. If you pass this security check, it then presents you with the main interface. From there, your clicks on various buttons tell the Orchestrator to launch the specific network configuration tools.

Code Spotlight: mainwindow.java

The mainwindow.java file is the heart of our Main Application Orchestrator. It's a Java Swing application, meaning it creates the windows and buttons you see on your screen.

Let's break down some key parts of its code.

1. The Entry Point

Like any Java application, the Orchestrator starts with the main method. This method sets up the visual style of the application and then makes the main window visible.

// ... (imports and other code) ...
public class mainwindow extends javax.swing.JFrame {

    // ... (constructor and other methods) ...

    public static void main(String args[]) {
        // This part tries to make the application look nice on your computer
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (/* ... */) {
            // Error handling for look and feel
        }

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new mainwindow().setVisible(true); // This creates and shows our main window!
            }
        });
    }
    // ... (variables declaration) ...
}

What this code does: When you run mainwindow.java, the main method is the very first thing that executes. It ensures the application has a consistent look across different operating systems (Nimbus is a standard Java look and feel). Most importantly, new mainwindow().setVisible(true) creates an instance of our mainwindow class (which is a graphical window) and makes it appear on your screen.

2. The Root User Check

Before showing you any network configuration options, the Orchestrator performs a crucial security check. It reads a file to confirm you are the root user.

// ... (start of initComponents method) ...
    private void initComponents() {
        String usr_nm = "root"; // The expected username for root access
        String str_nm;
        try {
            // Reads the username from a specific file
            BufferedReader bru = new BufferedReader(new FileReader("/etc/Network_Builder_V0.1/user.usr"));
            str_nm = bru.readLine(); // Get the username from the file
            if (!str_nm.equals(usr_nm)) { // Compare it with "root"
                // If not root, show an error and prevent further access
                JLabel errorFields = new JLabel("<HTML><FONT COLOR = RED>Root User LOGIN Must Required.</FONT></HTML>");
                JOptionPane.showMessageDialog(null, errorFields);
                // The application effectively halts here or closes implicitly
            } else {
                // If root, proceed to initialize all the GUI components (buttons, labels, etc.)
                jLabel1 = new javax.swing.JLabel();
                // ... many more button and label initializations ...
            }
        } catch (Exception ee) {
            // Handle any file reading errors
        }
    }
// ... (rest of the GUI component setup) ...

What this code does: This part is a security gate. It reads a username from a specific system file (/etc/Network_Builder_V0.1/user.usr). If the username in that file isn't "root", a pop-up message appears, reminding the user that root access is required. This prevents anyone without the right permissions from accidentally (or intentionally) making critical changes to your network settings. If the user is root, the application continues to build the main window's visual elements.

3. Launching Other Tools

Each button on the main window is responsible for launching another tool, which is a separate graphical window (or "frame"). This is how the Orchestrator delegates tasks.

Let's look at the "Automatic DHCP" button as an example:

// ... (code for other buttons and labels) ...
        jButton1.setFont(new java.awt.Font("Century Schoolbook L", 1, 14)); // Set font
        jButton1.setText("Automatic DHCP"); // Button text
        // ... (other button properties) ...
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt); // Calls an internal method (usually empty)
                final String dir = System.getProperty("user.dir"); // Get current directory
                try {
                    // Decrypt a shell script and run it (More on this in a later chapter!)
                    String unixCommand = "java Decrypter dhcp.sh.des " + dir;
                    runShellScript(unixCommand);
                    unixCommand = "rm -f dhcp.sh.des"; // Clean up the decrypted file
                    runShellScript(unixCommand);
                } catch (Exception e) {
                }
                new dhcpframe().setVisible(true); // THIS IS WHERE THE NEW TOOL IS LAUNCHED!
            }
        });
// ... (more buttons and layout code) ...

What this code does: When you click the "Automatic DHCP" button (jButton1), the actionPerformed method runs.

  1. It first prepares to execute some behind-the-scenes magic: it uses a Decrypter tool (which we'll explore in the Secure Script Execution Layer chapter) to decrypt a hidden script (dhcp.sh.des).
  2. Then, it runs this script to get things ready for DHCP configuration.
  3. Finally, and most importantly for this chapter, it creates and displays a new window using new dhcpframe().setVisible(true). This dhcpframe is a separate GUI dedicated solely to DHCP setup. This demonstrates the Orchestrator's role in launching specific Graphical User Interface (GUI) Frames.

The tool.java file you saw in the code snippets works in a similar way, acting as an orchestrator for a specific set of client-side networking tools. It also has buttons that launch other GUI frames (like new wlp().setVisible(true) for Wellknown Port analysis or new nfsclient().setVisible(true) for NFS Client setup). This shows that while mainwindow.java is the primary orchestrator for the entire application, smaller modules can also have their own orchestrator-like behaviors for a focused set of tasks.

Summary and What's Next

In this chapter, we learned that the Main Application Orchestrator is the central brain of shellnetbuilder. It's responsible for:

  • Ensuring secure access through a root user check.
  • Presenting a clear, user-friendly main menu.
  • Launching specific tools (other GUI frames) to perform different network configuration tasks.

It makes the application easy to use by providing a structured way to interact with various network services.

Now that we understand how the main application starts and directs you to different tools, the next logical step is to explore these individual tools themselves. How are these windows and buttons created? How do they gather information from you?

Let's move on to the next chapter, where we will dive into the details of these individual graphical interfaces.

Chapter 2: Graphical User Interface (GUI) Frames


References: [1], [2], [3]