Problème dans la programmation java

[Fermé]
Signaler
-
 mm -
Bonjour,
je suis vraiment bloqué svp qui peut m'aider ma soutenance la semaine prochaine et mon application n'est pas encore terminé j'ai un problème.
je travaille sous eclipse mon application présente une interface qui permet de gérer les règle de filtrage d'un pare-feu alors j'ai une classe visuel principale contient les différentes composants dans j'ai une autre classe règle contient les set et les get de ces composant et toString qui permet de m'afficher la règle suivant un syntaxe le problème c que j'ai une autre classe avancer qui est utile que dans le cas ou je choisi le protocole tcp cette classe me permet de choisir les flags alors je veut dans ce cas d'afficher la règle avec les flags et l'option --tcp-flags cette règle sera afficher dans la jList dans la fenêtre principale
svvvvvvp qui peut m'aider et merci d'avance
voilà mon projet
la fenêtre principale :
import javax.swing.JFrame;
import javax.swing.JPanel;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;

import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.util.regex.Pattern;

import javax.swing.JFileChooser;
import javax.swing.JList;
import java.io.BufferedWriter;
import javax.swing.DefaultListModel;
import java.awt.FileDialog;



public class fenetre {

Vector<Regle> vect =new Vector<Regle>(); // @jve:decl-index=0:

Vector <ACL> vect_ACL = new Vector<ACL>(); // @jve:decl-index=0:

public Regle r = new Regle(); // @jve:decl-index=0:

avancer f2= new avancer(); // @jve:decl-index=0:

public void jButtonImport(ActionEvent e)
{
try
{
JFileChooser fc = new JFileChooser();

int returnVal = fc.showOpenDialog(jContentPane);


if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();


BufferedReader br = new BufferedReader(new FileReader(file));


String ch="";

while ((ch=br.readLine())!= null){

if (ch.equals("")){

}
else {
Regle r_import = new Regle();



StringTokenizer Tz = new StringTokenizer (ch, " ");

while (Tz.hasMoreTokens ()) {

String suivant = Tz.nextToken ();
if (( suivant.equals("filter"))||( suivant.equals("mangle"))||( suivant.equals("nat"))){
r_import.table=suivant;

}
if (( suivant.equals("-A"))||( suivant.equals("-I"))||( suivant.equals("-D"))){
r_import.commande=suivant;

}


if (( suivant.equals("INPUT"))||( suivant.equals("OUTPUT"))||( suivant.equals("FORWARD"))||( suivant.equals("POSTROUTING"))||( suivant.equals("PREROUTING"))){
r_import.chaine=suivant;
}


if (( suivant.equals("tcp"))||( suivant.equals("udp"))||( suivant.equals("icmp"))||( suivant.equals("limit"))||( suivant.equals("state"))){
r_import.protocole=suivant;
}

if (( suivant.equals("ACCEPT"))||( suivant.equals("DROP"))||( suivant.equals("REJECT"))){
r_import.action=suivant;
}

if (suivant.equals("-s")) {
int ind1=ch.indexOf("-s");
int ind2=ch.indexOf("-d");
if ((ind1!=-1)&& (ind2!=-1)){
if ((ind1>0)&& (ind2>0)){
String adrS=ch.substring(ind1+2,ind2-1);
r_import.adr_src=adrS;
}
else System.out.println("err");
}
}

if (suivant.equals("-d")){
int indx1=ch.indexOf("-d");
int indx2=ch.indexOf("--sport");

if ((indx1!=-1)&& (indx2!=-1)){
if ((indx1>0)&& (indx2>0)){
String adrD=ch.substring(indx1+2,indx2-1);
r_import.adr_dest=adrD;

}
else System.out.println("err");
}
}

if (suivant.equals("--sport")){
int indx1=ch.indexOf("--sport");
int indx2=ch.indexOf("--dport");
if ((indx1!=-1)&& (indx2!=-1)){
if ((indx1>0)&& (indx2>0)){
String portS=ch.substring(indx1+8,indx2-1);
r_import.port_src=portS;
}
else System.out.println("err");
}
}

if (suivant.equals("--dport")){
int indx1=ch.indexOf("--dport");
int indx2=ch.indexOf("-j");
if ((indx1!=-1)&& (indx2!=-1)){
if ((indx1>0)&& (indx2>0)){
String portD=ch.substring(indx1+8,indx2-1);
r_import.port_dest=portD;

}
else System.out.println("err");
}
}


}//while




boolean non_trouver=true;
int i=0;
while ((non_trouver)&&(i<vect_ACL.size())){


if(r_import.chaine.compareTo(vect_ACL.elementAt(i).nom)==0) {
non_trouver=false;
vect_ACL.elementAt(i).vect_regle.addElement(r_import);

}
else {
i++;
}
}
if (non_trouver==true){

ACL A=new ACL();

A.nom=r_import.chaine;
A.vect_regle.addElement(r_import);
vect_ACL.addElement(A);
}
jList1.setListData(vect_ACL);

}//else
}//while


jList.setListData(vect);

br.close();


}
}
catch (FileNotFoundException F){
System.out.println("fichier non trouver");}
catch(IOException err){
System.out.println(err.getMessage());
}
}


public void jButtonadd(ActionEvent e) throws IOException
{
Regle r1 = new Regle(); // @jve:decl-index=0:
r1.table=(String)jComboBox1.getSelectedItem();
r1.commande = (String)jComboBox.getSelectedItem();
r1.chaine= ((ACL)jList1.getSelectedValue()).nom;
r1.protocole = (String)jComboBox2.getSelectedItem();
r1.adr_src= jTextField.getText();
r1.adr_dest = jTextField1.getText();
r1.port_src= jTextField2.getText();
r1.port_dest= jTextField3.getText();
r1.action=(String)jComboBox3.getSelectedItem();
r1.flg1=f2.getflg1();
r1.flg2=f2.getflg2();
r1.pos= Integer.parseInt(jTextField4.getText());

vect_ACL.elementAt(jList1.getSelectedIndex()).vect_regle.addElement(r1);
jList.setListData(vect_ACL.elementAt(jList1.getSelectedIndex()).vect_regle);

}

public void jButtonSupprimer(ActionEvent e)
{

vect_ACL.elementAt(jList1.getSelectedIndex()).vect_regle.removeElementAt(jList.getSelectedIndex());
jList.setListData(vect_ACL.elementAt(jList1.getSelectedIndex()).vect_regle);





}

public void jButtonModifier(ActionEvent e){

Regle r2 = new Regle();
r2.table=(String)jComboBox1.getSelectedItem();
r2.commande = (String)jComboBox.getSelectedItem();
r2.chaine= ((ACL)jList1.getSelectedValue()).nom;
r2.protocole = (String)jComboBox2.getSelectedItem();
r2.adr_src= jTextField.getText();
r2.adr_dest = jTextField1.getText();
r2.port_src= jTextField2.getText();
r2.port_dest= jTextField3.getText();
r2.action=(String)jComboBox3.getSelectedItem();
r2.flg1=f2.getflg1();
r2.flg2=f2.getflg2();
r2.pos= Integer.parseInt(jTextField4.getText());

vect_ACL.elementAt(jList1.getSelectedIndex()).vect_regle.set(r2.getpos(), r2);
jList.setListData(vect_ACL.elementAt(jList1.getSelectedIndex()).vect_regle);


}
Vector<String> v=new Vector<String>(); // @jve:decl-index=0:

public void jButtonVerifier(ActionEvent e){
try{
File f=new File("file.txt" );
FileWriter fw= new FileWriter(f);
BufferedWriter bf=new BufferedWriter (fw);


for (int i = 0; i <vect_ACL.elementAt(jList1.getSelectedIndex()).vect_regle.size(); i++){
System.out.println(vect_ACL.elementAt(jList1.getSelectedIndex()).vect_regle.elementAt(i).toString_verif());
bf.append(vect_ACL.elementAt(jList1.getSelectedIndex()).vect_regle.elementAt(i).toString_verif());
bf.append("\n\r");
}//for





bf.close();

/* ****************************** */
try {


String[]cmd = {"fw_anomalies.exe", "rule4.txt"};
Process process = Runtime.getRuntime().exec(cmd);
BufferedReader ds = new BufferedReader(new InputStreamReader(process.getInputStream()));
String lineCourante = ds.readLine();

File fres=new File("fresultat.txt" );
FileWriter fww= new FileWriter(fres);
BufferedWriter bfw=new BufferedWriter (fww);
while (lineCourante != null) {
System.out.println(lineCourante);
Pattern p = Pattern.compile("^Number.*");
Pattern p1 = Pattern.compile("^ Number.*");
Pattern p2 = Pattern.compile("^ Number.*");
Pattern p3 = Pattern.compile("^searching.*");
Pattern p4 = Pattern.compile("^1.*");
Pattern p5 = Pattern.compile("^2.*");
Pattern p6 = Pattern.compile("^3.*");
if((p.matcher(lineCourante).matches())||(p1.matcher(lineCourante).matches())||(p2.matcher(lineCourante).matches())||(p3.matcher(lineCourante).matches())||(p4.matcher(lineCourante).matches())||(p5.matcher(lineCourante).matches())||(p6.matcher(lineCourante).matches())){
System.out.println(lineCourante+" *********");

bfw.append(lineCourante);
bfw.append("\n\r");
}
lineCourante = ds.readLine();
}
bfw.close();
/* ******************************** */
resultat res= new resultat();
res.getJFrame();
try{
BufferedReader bfr = new BufferedReader(new FileReader("fresultat.txt"));


String SL;
while ((SL=bfr.readLine())!=null){


res.jTextArea.append(SL);
res.jTextArea.append("\n\r");

}

bfr.close();
res.getJFrame();
res.jFrame.setVisible(true);
}
catch (FileNotFoundException F){
System.out.println("fichier non trouver");}
catch(IOException er1){
er1.getMessage();
}

}

catch (IOException ioe){
ioe.getMessage();
}


}
catch (FileNotFoundException F){
System.out.println("fichier non trouver");}
catch(IOException err){
System.out.println(err.getMessage());
}

}

JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="38,15"
private JPanel jContentPane = null;
private JButton jButton = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JLabel jLabel3 = null;
private JLabel jLabel4 = null;
private JLabel jLabel5 = null;
private JLabel jLabel6 = null;
private JLabel jLabel7 = null;
private JTextField jTextField = null;
private JTextField jTextField1 = null;
private JTextField jTextField2 = null;
private JTextField jTextField3 = null;
private JButton jButton1 = null;
private JButton jButton2 = null;
private JList jList = null;
private JButton jButton4 = null;
private JComboBox jComboBox = null;
public JComboBox jComboBox2 = null;
private JComboBox jComboBox3 = null;
private JLabel jLabel8 = null;
private JTextField jTextField4 = null;
private JButton jButton5 = null;
public JList jList1 = null;

/**
* This method initializes jFrame
*
* @return javax.swing.JFrame
* @throws IOException
*/
JFrame getJFrame() throws IOException {
if (jFrame == null) {
jFrame = new JFrame();
jFrame.setSize(new Dimension(1003, 520));
jFrame.setTitle("Gérer et vérfier les règles de filtrage d'un pare-feu");
jFrame.setContentPane(getJContentPane());
}
return jFrame;
}

/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
* @throws IOException
*/
private JPanel getJContentPane() throws IOException {
if (jContentPane == null) {
jLabel9 = new JLabel();
jLabel9.setBounds(new Rectangle(12, 15, 108, 17));
jLabel9.setText("table");
jLabel8 = new JLabel();
jLabel8.setBounds(new Rectangle(13, 375, 108, 18));
jLabel8.setText("position");
jLabel7 = new JLabel();
jLabel7.setBounds(new Rectangle(14, 345, 108, 20));
jLabel7.setText("action");
jLabel6 = new JLabel();
jLabel6.setBounds(new Rectangle(15, 314, 107, 19));
jLabel6.setText("port destination");
jLabel5 = new JLabel();
jLabel5.setBounds(new Rectangle(15, 285, 108, 17));
jLabel5.setText("port source");
jLabel4 = new JLabel();
jLabel4.setBounds(new Rectangle(15, 255, 107, 17));
jLabel4.setText("adress destination");
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(15, 223, 109, 19));
jLabel3.setText("adress source");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(15, 195, 108, 19));
jLabel2.setText("protocole");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(13, 71, 109, 112));
jLabel1.setText("chaine");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(13, 43, 108, 18));
jLabel.setText("commande");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButton(), null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(jLabel2, null);
jContentPane.add(jLabel3, null);
jContentPane.add(jLabel4, null);
jContentPane.add(jLabel5, null);
jContentPane.add(jLabel6, null);
jContentPane.add(jLabel7, null);
jContentPane.add(getJTextField(), null);
jContentPane.add(getJTextField1(), null);
jContentPane.add(getJTextField2(), null);
jContentPane.add(getJTextField3(), null);
jContentPane.add(getJButton1(), null);
jContentPane.add(getJButton2(), null);

jContentPane.add(getJButton4(), null);
jContentPane.add(getJComboBox(), null);
jContentPane.add(getJComboBox2(), null);
jContentPane.add(getJComboBox3(), null);
jContentPane.add(jLabel8, null);
jContentPane.add(getJTextField4(), null);
jContentPane.add(getJButton5(), null);


jContentPane.add(getJButton6(), null);
jContentPane.add(getJButton3(), null);
jContentPane.add(jLabel9, null);
jContentPane.add(getJComboBox1(), null);
jContentPane.add(getJButton7(), null);
jContentPane.add(getJButton8(), null);
jContentPane.add(getJButton9(), null);
JScrollPane scrollPane = null;

if (jList == null) {
jList = new JList();
scrollPane = new JScrollPane(jList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setBounds(new Rectangle(390, 15, 595, 327));
jList.setBounds(new Rectangle(387, 16, 676, 333));
jList.addMouseListener(new java.awt.event.MouseAdapter(){
public void mouseClicked(java.awt.event.MouseEvent e) {

if ((e.getClickCount() == 2)){

r=vect_ACL.elementAt(jList1.getSelectedIndex()).vect_regle.elementAt(jList.getSelectedIndex());

if ( r.table.equals("filter")){
jComboBox1.setSelectedIndex(1);
}

else if ( r.commande.equals("mangle")){
jComboBox1.setSelectedIndex(2);

}
else if ( r.commande.equals("nat")){
jComboBox1.setSelectedIndex(3);
}

if ( r.commande.equals("-A")){
jComboBox.setSelectedIndex(1);
}

else if ( r.commande.equals("-I")){
jComboBox.setSelectedIndex(2);

}
else if ( r.commande.equals("-D")){
jComboBox.setSelectedIndex(3);
}

if ( r.chaine.equals("INPUT")){

jList1.setSelectedIndex(0);

}
else if ( r.chaine.equals("OUTPUT")){
jList1.setSelectedIndex(1);

}
else if ( r.chaine.equals("FORWARD")){
jList1.setSelectedIndex(2);

}


if ( r.protocole.equals("tcp")){
jComboBox2.setSelectedIndex(1);
}
else if ( r.protocole.equals("udp")){
jComboBox2.setSelectedIndex(2);
}
else if ( r.protocole.equals("icmp")){
jComboBox2.setSelectedIndex(3);
}



if ( r.action.equals("ACCEPT")){
jComboBox3.setSelectedIndex(1);
}
else if ( r.action.equals("DROP")){
jComboBox3.setSelectedIndex(2);
}
else if ( r.action.equals("REJECT")){
jComboBox3.setSelectedIndex(3);
}

jTextField.setText(r.adr_src);

jTextField1.setText(r.adr_dest);

jTextField2.setText(r.port_src);

jTextField3.setText(r.port_dest);

r.pos=jList.getSelectedIndex();
jTextField4.setText(String.valueOf(r.getpos()));
}



}



});
}
JScrollPane scrollPane1 = null;
if (jList1 == null) {
jList1 = new JList();
scrollPane1 = new JScrollPane(jList1,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane1.setBounds(new Rectangle(137, 72, 115, 114));
jList1.setBounds(new Rectangle(134, 69, 122, 113));
jList1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {

boolean non_trouver=true;
int i=0;
while((non_trouver)&&(i<vect_ACL.size())){

if ((e.getClickCount() == 2)&& (jList1.getSelectedValue().toString().compareTo((vect_ACL.elementAt(i).nom))==0)){
non_trouver=false;
jList.setListData(vect_ACL.elementAt(i).vect_regle);

}//if
else {
i++;
}

}//while



}
});
}
jContentPane.add(scrollPane1, null);
jContentPane.add(scrollPane, null);
}
return jContentPane;
}

/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(376, 373, 116, 33));
jButton.setText("importer ");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {

if (e.getSource()==jButton){
System.out.println("lolol" + vect_ACL.size());
vect_ACL.clear();
System.out.println(vect_ACL.size());
jButtonImport(e); // TODO Auto-generated Event stub actionPerformed()
}



}
});
}
return jButton;
}

/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
public JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(133, 223, 124, 19));
}
return jTextField;
}

/**
* This method initializes jTextField1
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
jTextField1.setBounds(new Rectangle(133, 255, 122, 17));
}
return jTextField1;
}

/**
* This method initializes jTextField2
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField2() {
if (jTextField2 == null) {
jTextField2 = new JTextField();
jTextField2.setBounds(new Rectangle(133, 285, 124, 18));
}
return jTextField2;
}

/**
* This method initializes jTextField3
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField3() {
if (jTextField3 == null) {
jTextField3 = new JTextField();
jTextField3.setBounds(new Rectangle(132, 314, 123, 21));
}
return jTextField3;
}

/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(525, 373, 117, 33));
jButton1.setText("ajouter");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {

jButtonadd(e);

} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // TODO Auto-generated Event stub actionPerformed()
}
});
}
return jButton1;
}

/**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setBounds(new Rectangle(691, 372, 114, 33));
jButton2.setText("modifier");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {

jButtonModifier(e);

// TODO Auto-generated Event stub actionPerformed()
}
});
}
return jButton2;
}

/**
* This method initializes jList
*
* @return javax.swing.JList
*/


private JButton getJButton4() {
if (jButton4 == null) {
jButton4 = new JButton();
jButton4.setBounds(new Rectangle(840, 436, 108, 30));
jButton4.setText("quitter");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(0); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return jButton4;
}
/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox() {
if (jComboBox == null) {
jComboBox = new JComboBox();
jComboBox.setBounds(new Rectangle(135, 43, 121, 19));
jComboBox.addItem("");
jComboBox.addItem("-A");
jComboBox.addItem("-I");
jComboBox.addItem("-D");
jComboBox.addItem("-N");
}
return jComboBox;
}

/**
* This method initializes jComboBox2
*
* @return javax.swing.JComboBox
*/
public JComboBox getJComboBox2() {
if (jComboBox2 == null) {
jComboBox2 = new JComboBox();
jComboBox2.setBounds(new Rectangle(133, 196, 123, 19));
jComboBox2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {

getJButton7();
if(jComboBox2.getSelectedIndex()==1){
jButton7.setEnabled(true);
}
else {
jButton7.setEnabled(false);
}

}
});
jComboBox2.addItem("");
jComboBox2.addItem("tcp");
jComboBox2.addItem("udp");
jComboBox2.addItem("icmp");

}
return jComboBox2;
}

/**
* This method initializes jComboBox3
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox3() {
if (jComboBox3 == null) {
jComboBox3 = new JComboBox();
jComboBox3.setBounds(new Rectangle(133, 345, 122, 21));
jComboBox3.addItem("");
jComboBox3.addItem("ACCEPT");
jComboBox3.addItem("DROP");
jComboBox3.addItem("REJECT");

}
return jComboBox3;
}

/**
* This method initializes jTextField4
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField4() {
if (jTextField4 == null) {
jTextField4 = new JTextField();
jTextField4.setBounds(new Rectangle(133, 375, 122, 18));
}
return jTextField4;
}

/**
* This method initializes jButton5
*
* @return javax.swing.JButton
*/
private JButton getJButton5() {
if (jButton5 == null) {
jButton5 = new JButton();
jButton5.setBounds(new Rectangle(841, 374, 108, 35));
jButton5.setText("supprimer");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jButtonSupprimer(e);

}
});
}
return jButton5;
}

private JButton jButton3 = null;
DefaultListModel dlm = new DefaultListModel();
private JButton jButton6 = null;
private JLabel jLabel9 = null;
private JComboBox jComboBox1 = null;
public JButton jButton7 = null;

private JButton jButton8 = null;

private JButton jButton9 = null;
/*public JList getJList1() throws IOException {
if (jList1 == null) {
jList1 = new JList();

jList1.setBounds(new Rectangle(134, 69, 122, 113));
jList1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {

boolean non_trouver=true;
int i=0;
while((non_trouver)&&(i<vect_ACL.size())){

if ((e.getClickCount() == 2)&& (jList1.getSelectedValue().toString().compareTo((vect_ACL.elementAt(i).nom))==0)){
non_trouver=false;
jList.setListData(vect_ACL.elementAt(i).vect_regle);

}//if
else {
i++;
}

}//while



}
});
}
return jList1;
}

*/
private JButton getJButton6() {
if (jButton6 == null) {
jButton6 = new JButton();
jButton6.setBounds(new Rectangle(691, 433, 113, 34));
jButton6.setText("vider");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jComboBox.setSelectedIndex(0);
jComboBox2.setSelectedIndex(0);
jTextField.setText("");
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jComboBox3.setSelectedIndex(0);
jComboBox1.setSelectedIndex(0);



// TODO Auto-generated Event stub actionPerformed()
}
});
}
return jButton6;
}

/**
* This method initializes jButton3
*
* @return javax.swing.JButton
*/
private JButton getJButton3() {
if (jButton3 == null) {
jButton3 = new JButton();
jButton3.setBounds(new Rectangle(376, 435, 114, 33));
jButton3.setText("enregistrer");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try{
JFileChooser fs = new JFileChooser();

int returnVal = fs.showSaveDialog(jContentPane);


if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fs.getSelectedFile();


FileWriter fw= new FileWriter(file);
BufferedWriter bf=new BufferedWriter (fw);

for (int i = 0; i <vect_ACL.size(); i++){
for (int j = 0; j <vect_ACL.elementAt(i).vect_regle.size(); j++){
bf.append(vect_ACL.elementAt(i).vect_regle.elementAt(j).toString());
bf.append("\n\r");
}
}
bf.close();
}
}
catch (FileNotFoundException F){
System.out.println("fichier non trouver");}
catch(IOException err){
System.out.println(err.getMessage());
}

}
});
}
return jButton3;
}


/**
* This method initializes jComboBox1
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox1() {
if (jComboBox1 == null) {
jComboBox1 = new JComboBox();
jComboBox1.setBounds(new Rectangle(135, 14, 119, 18));
jComboBox1.addItem("");
jComboBox1.addItem("filter");
jComboBox1.addItem("mangle");
jComboBox1.addItem("nat");


// TODO Auto-generated Event stub actionPerformed()

}

return jComboBox1;
}

/**
* This method initializes jButton7
*
* @return javax.swing.JButton
*/

public JButton getJButton7() {
if (jButton7 == null) {
jButton7 = new JButton();
jButton7.setBounds(new Rectangle(262, 194, 119, 21));
jButton7.setText("avancee");
jButton7.setEnabled(true);
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
f2.getJFrame();
f2.getJFrame().setVisible(true);



}


});


jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return jButton7;
}



/**
* This method initializes jButton8
*
* @return javax.swing.JButton
*/
private JButton getJButton8() {
if (jButton8 == null) {
jButton8 = new JButton();
jButton8.setBounds(new Rectangle(261, 71, 119, 27));
jButton8.setText("ajouter chaine");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
chaineNommee f3= new chaineNommee(vect_ACL,jList1);
//System.out.println("ytyty"+vect_ACL.size());
//jList1.setListData(vect_ACL);
f3.getJFrame();
f3.getJFrame().setVisible(true); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return jButton8;
}

/**
* This method initializes jButton9
*
* @return javax.swing.JButton
*/
private JButton getJButton9() {
if (jButton9 == null) {
jButton9 = new JButton();
jButton9.setBounds(new Rectangle(524, 434, 120, 33));
jButton9.setText("vérifier");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jButtonVerifier(e);// TODO Auto-generated Event stub actionPerformed()
}
});
}
return jButton9;
}


/**
* This method initializes jList1
*
* @return javax.swing.JList
* @throws IOException
*/


public static void main(String[] args) throws IOException {

fenetre f1= new fenetre();
f1.getJFrame();

f1.jFrame.setVisible(true);

}
}

*****************
classe règle:
public class Regle {
public String table;
public String commande;
public String chaine;
public String protocole;
public String adr_src;
public String adr_dest;
public String port_src;
public String port_dest;
public String action;
public int pos;
public String flg1;
public String flg2;






public Regle(){

};

public Regle(String table, String commande,String chaine,String protocole,String adr_src,String adr_dest,String port_src,String port_dest,String action,int pos,String flg1,String flg2) {
super();
this.table=table;
this.commande = commande;
this.chaine=chaine;
this.protocole = protocole;
this.adr_src = adr_src;
this.adr_dest = adr_dest;
this.port_src = port_src;
this.port_dest = port_dest;
this.action = action;
this.pos=pos;
this.flg1=flg1;
this.flg2=flg2;
}

public String getflg1() {
return flg1 ;
}

public void setflg1(String flg1) {
this.flg1= flg1;
}

public String getflg2() {
return flg2 ;
}

public void setflg2(String flg2) {
this.flg2 = flg2;
}

//**************************

public String gettable() {
return table ;
}

public void settype(String table) {
this.table = table;
}

public String getcommande() {
return commande ;
}

public void setcommande(String commande) {
this.commande = commande;
}
public String getchaine() {
return chaine ;
}

public void setchaine(String chaine) {
this.chaine = chaine;
}
public String getprotocole() {
return protocole ;
}

public void setprotocole(String protocole) {
this.protocole = protocole;
}

public String getadr_src() {
return adr_src ;
}

public void setadr_src(String adr_src) {
this.adr_src = adr_src;
}
public String getadr_dest() {
return adr_dest ;
}

public void setadr_dest(String adr_dest) {
this.adr_dest = adr_dest;
}
public String getport_src() {
return port_src ;
}

public void setport_src(String port_src) {
this.port_src = port_src;
}

public String getport_dest() {
return port_dest ;
}

public void setport_dest(String port_dest) {
this.port_dest = port_dest;
}

public String getaction() {
return action ;
}

public void setaction(String action) {
this.action = action;
}

public int getpos() {
return pos ;
}

public void setpos(int pos) {
this.pos = pos;
}


public String toString(){

return("iptables"+" "+"-t"+" "+table+" "+commande+" "+chaine+" "+"-p"+" "+protocole+" "+"-s"+" "+adr_src+" "+"-d"+" "+adr_dest+" "+"--sport"+" "+port_src+" "+"--dport"+" "+port_dest+" "+"-j"+" "+action);

}
public String toString_flag(){

return("iptables"+" "+"-t"+" "+table+" "+commande+" "+chaine+" "+"-p"+" "+protocole+" "+"--tcp_flag"+" "+flg1+" "+flg2+" "+"-s"+" "+adr_src+" "+"-d"+" "+adr_dest+" "+"--sport"+" "+port_src+" "+"--dport"+" "+port_dest+" "+"-j"+" "+action);

}

public String toString_verif(){

String ps= Integer.toBinaryString(Integer.parseInt(port_src));
System.out.println(ps);
String pd=Integer.toBinaryString(Integer.parseInt(port_dest));
System.out.println(pd);

String a="";
String b="";
String c="";
String d="";

if (ps.length()>=9){
for (int i=0;i<=ps.length()-9;i++){
a=a+ps.charAt(i);
}

int e=0;

if (e<ps.length()-8){
e=ps.length()-8;
}

for (int j=e;j<=ps.length()-1;j++){
b=b+ps.charAt(j);
}
}
else {
a=a+"0";
int e=0;
if (e>ps.length()-8){
e=ps.length()-8;
}
for (int j=e;j<=ps.length()-1;j++){
b=b+ps.charAt(j);
}
}


if (pd.length()>=9){
for (int i=0;i<=pd.length()-9;i++){
c=c+pd.charAt(i);
}

int e=0;

if (e<pd.length()-8){
e=pd.length()-8;
}

for (int j=e;j<=pd.length()-1;j++){
d=d+pd.charAt(j);
}
}
else {
c=c+"0";
int e=0;
if (e<pd.length()-8){
e=pd.length()-8;
}
for (int j=e;j<=pd.length()-1;j++){
d=d+pd.charAt(j);
}
}

/*int puisa = 1;
int deca = 0;


for (int i = a.length(); i >= 0; i--)
{
deca = deca+ a.charAt(i)*puisa;
puisa =puisa*2;
}


System.out.println(deca+"???????????????????????");

*/



return(adr_src+" "+adr_dest+" "+a+"."+b+"."+"*"+" "+c+"."+d+"."+"*"+" "+" "+"80"+" "+action);

}

}
***********************
classer avancer:
public class Regle {
public String table;
public String commande;
public String chaine;
public String protocole;
public String adr_src;
public String adr_dest;
public String port_src;
public String port_dest;
public String action;
public int pos;
public String flg1;
public String flg2;






public Regle(){

};

public Regle(String table, String commande,String chaine,String protocole,String adr_src,String adr_dest,String port_src,String port_dest,String action,int pos,String flg1,String flg2) {
super();
this.table=table;
this.commande = commande;
this.chaine=chaine;
this.protocole = protocole;
this.adr_src = adr_src;
this.adr_dest = adr_dest;
this.port_src = port_src;
this.port_dest = port_dest;
this.action = action;
this.pos=pos;
this.flg1=flg1;
this.flg2=flg2;
}

public String getflg1() {
return flg1 ;
}

public void setflg1(String flg1) {
this.flg1= flg1;
}

public String getflg2() {
return flg2 ;
}

public void setflg2(String flg2) {
this.flg2 = flg2;
}

//**************************

public String gettable() {
return table ;
}

public void settype(String table) {
this.table = table;
}

public String getcommande() {
return commande ;
}

public void setcommande(String commande) {
this.commande = commande;
}
public String getchaine() {
return chaine ;
}

public void setchaine(String chaine) {
this.chaine = chaine;
}
public String getprotocole() {
return protocole ;
}

public void setprotocole(String protocole) {
this.protocole = protocole;
}

public String getadr_src() {
return adr_src ;
}

public void setadr_src(String adr_src) {
this.adr_src = adr_src;
}
public String getadr_dest() {
return adr_dest ;
}

public void setadr_dest(String adr_dest) {
this.adr_dest = adr_dest;
}
public String getport_src() {
return port_src ;
}

public void setport_src(String port_src) {
this.port_src = port_src;
}

public String getport_dest() {
return port_dest ;
}

public void setport_dest(String port_dest) {
this.port_dest = port_dest;
}

public String getaction() {
return action ;
}

public void setaction(String action) {
this.action = action;
}

public int getpos() {
return pos ;
}

public void setpos(int pos) {
this.pos = pos;
}


public String toString(){

return("iptables"+" "+"-t"+" "+table+" "+commande+" "+chaine+" "+"-p"+" "+protocole+" "+"-s"+" "+adr_src+" "+"-d"+" "+adr_dest+" "+"--sport"+" "+port_src+" "+"--dport"+" "+port_dest+" "+"-j"+" "+action);

}
public String toString_flag(){

return("iptables"+" "+"-t"+" "+table+" "+commande+" "+chaine+" "+"-p"+" "+protocole+" "+"--tcp_flag"+" "+flg1+" "+flg2+" "+"-s"+" "+adr_src+" "+"-d"+" "+adr_dest+" "+"--sport"+" "+port_src+" "+"--dport"+" "+port_dest+" "+"-j"+" "+action);

}

public String toString_verif(){

String ps= Integer.toBinaryString(Integer.parseInt(port_src));
System.out.println(ps);
String pd=Integer.toBinaryString(Integer.parseInt(port_dest));
System.out.println(pd);

String a="";
String b="";
String c="";
String d="";

if (ps.length()>=9){
for (int i=0;i<=ps.length()-9;i++){
a=a+ps.charAt(i);
}

int e=0;

if (e<ps.length()-8){
e=ps.length()-8;
}

for (int j=e;j<=ps.length()-1;j++){
b=b+ps.charAt(j);
}
}
else {
a=a+"0";
int e=0;
if (e>ps.length()-8){
e=ps.length()-8;
}
for (int j=e;j<=ps.length()-1;j++){
b=b+ps.charAt(j);
}
}


if (pd.length()>=9){
for (int i=0;i<=pd.length()-9;i++){
c=c+pd.charAt(i);
}

int e=0;

if (e<pd.length()-8){
e=pd.length()-8;
}

for (int j=e;j<=pd.length()-1;j++){
d=d+pd.charAt(j);
}
}
else {
c=c+"0";
int e=0;
if (e<pd.length()-8){
e=pd.length()-8;
}
for (int j=e;j<=pd.length()-1;j++){
d=d+pd.charAt(j);
}
}

/*int puisa = 1;
int deca = 0;


for (int i = a.length(); i >= 0; i--)
{
deca = deca+ a.charAt(i)*puisa;
puisa =puisa*2;
}


System.out.println(deca+"???????????????????????");

*/



return(adr_src+" "+adr_dest+" "+a+"."+b+"."+"*"+" "+c+"."+d+"."+"*"+" "+" "+"80"+" "+action);

}

}

1 réponse

Messages postés
352
Date d'inscription
mercredi 12 octobre 2011
Statut
Membre
Dernière intervention
18 juillet 2020
6
c'est un sacré code
indique nous ou est le problème dans ce code
le problème :
la règle est sous la forme :
iptables -t filter -A INPUT udp -s 0.0.22.3 -d 12.3.22.11 --sport 525 --dport 5 -j ACCEPT
et quand je choisi le protocole tcp et je clic sur un bouton avancer elle soit sous la forme
iptables -t filter -A INPUT tcp --tcp-flags ACK,SYN ACK -s 0.0.22.3 -d 12.3.22.11 --sport 525 --dport 5 -j ACCEPT
RQ:
ACK,SYN viennent de la classe avancer sous forme d'une chaine de caractère flag1 et ACK la mm chose sous forme d'ne chaine flag2
le probleme quand je choisi le tcp et les flag je suis pas capable d'afficher la règle correctement
svpp j'ai besoin de votre aide