Κεφάλαιο 3 Firewall 3.1 Εισαγωγή
4.5 Πέμπτη φόρμα – Firewall Control Panel
Μπαμπέκος Χρήστος Α.Ε.Μ.:1904 Βουλγαράκη Φωτεινή Α.Ε.Μ:1912 97
Μπαμπέκος Χρήστος Α.Ε.Μ.:1904 Βουλγαράκη Φωτεινή Α.Ε.Μ:1912 98 Σχήμα 4.5(α): Εγγραφή ιστοσελίδας προς αποκλεισμό
Κάτω αριστερά της φόρμας διακρίνει κανείς την επιλογή Run, για να δοθεί σε real time λειτουργία το ανάχωμα ασφαλείας θα πρέπει να είναι ενεργοποιημένη αυτή η επιλογή(σχήμα 4.5(β)).
Μπαμπέκος Χρήστος Α.Ε.Μ.:1904 Βουλγαράκη Φωτεινή Α.Ε.Μ:1912 99 Σχήμα 4.5(β)
Ο κώδικας της φόρμας:
Firewall.h
713. //---
714. #ifndef FirewallH 715. #define FirewallH
716. //--- 717. #include <Classes.hpp>
718. #include <Controls.hpp>
719. #include <StdCtrls.hpp>
720. #include <Forms.hpp>
721. #include <ExtCtrls.hpp>
722. #include <jpeg.hpp>
723. #include <GIFImg.hpp>
724. #include <DBCtrls.hpp>
725. #include <DBGrids.hpp>
726. #include <Grids.hpp>
727. //--- 728. class TForm6 : public TForm
729. {
730. __published: // IDE-managed Components 731. TTimer *Timer1;
732. TRadioGroup *RadioGroup1;
733. TRadioGroup *RadioGroup2;
734. TRadioGroup *RadioGroup3;
Μπαμπέκος Χρήστος Α.Ε.Μ.:1904 Βουλγαράκη Φωτεινή Α.Ε.Μ:1912 100 735. TCheckBox *CheckBox1;
736. TEdit *Edit4;
737. TGroupBox *GroupBox1;
738. TCheckBox *CheckBox2;
739. TCheckBox *CheckBox3;
740. TCheckBox *CheckBox4;
741. TCheckBox *CheckBox5;
742. TCheckBox *CheckBox6;
743. TCheckBox *CheckBox7;
744. TImage *Image1;
745. TGroupBox *GroupBox2;
746. TButton *Button1;
747. TButton *Button2;
748. TEdit *Edit1;
749. TDBGrid *DBGrid1;
750. void __fastcall Timer1Timer(TObject *Sender);
751. void __fastcall CheckBox1Click(TObject *Sender);
752. void __fastcall CheckBox2Click(TObject *Sender);
753. void __fastcall CheckBox3Click(TObject *Sender);
754. void __fastcall CheckBox4Click(TObject *Sender);
755. void __fastcall CheckBox5Click(TObject *Sender);
756. void __fastcall CheckBox6Click(TObject *Sender);
757. void __fastcall CheckBox7Click(TObject *Sender);
758. void __fastcall Button1Click(TObject *Sender);
759. void __fastcall Button2Click(TObject *Sender);
760. private: // User declarations
761. public: // User declarations 762. __fastcall TForm6(TComponent* Owner);
763. int iduser;
764. bool openbrowser;
765. bool openmail;
766. bool openftp;
767. int dmz;
768. bool initializeobj; //epanaferei to eikonidio sthn arxikh tou thesh 769. String str1,str2,str3,str4,str5,str6;
770. bool runfile;
771. };
772. //--- 773. extern PACKAGE TForm6 *Form6;
774. //--- 775. #endif
Firewall.cpp
776. //---
Μπαμπέκος Χρήστος Α.Ε.Μ.:1904 Βουλγαράκη Φωτεινή Α.Ε.Μ:1912 101 777. #include <vcl.h>
778. #pragma hdrstop
779. #include "Firewall.h"
780. #include "ibrowser.h"
781. #include "afterlog.h"
782. #include "LoginPanel.h"
783. #include "Login.h"
784. #include "Policy1.h"
785. #include "ftp.h"
786. #include "mail.h"
787. #include "mailservercp.h"
788. USEFORM("Login.cpp",Form1);
789. USEFORM("Policy1.cpp",Form4);
790. USEFORM("ibrowser.cpp",Form7);
791. USEFORM("LoginPanel.cpp",Form5);
792. USEFORM("afterlog.cpp",Frame2);
793. USEFORM("ftp.cpp",Form8);
794. USEFORM("mail.cpp",Form12);
795. USEFORM("mailservercp.cpp",Form14);
796. //--- 797. #pragma package(smart_init)
798. #pragma resource "*.dfm"
799. TForm6 *Form6;
800. //--- 801. __fastcall TForm6::TForm6(TComponent* Owner)
802. : TForm(Owner) 803. {
804. RadioGroup1->ItemIndex=2; //Αρχικοποίηση της επιλογής block all http service
805. RadioGroup2->ItemIndex=2; //Αρχικοποίηση της επιλογής block all ftp service
806. RadioGroup3->ItemIndex=2; //Αρχικοποίηση της επιλογής block all mail service
807. }
808. //--- 809. void __fastcall TForm6::Timer1Timer(TObject *Sender) 810. {
811. Timer1->Interval=100;
812. if(CheckBox1->Checked) //start or stop firewall 813. {
814. if (RadioGroup1->ItemIndex==0) { 815. //allow code
Μπαμπέκος Χρήστος Α.Ε.Μ.:1904 Βουλγαράκη Φωτεινή Α.Ε.Μ:1912 102 816. if(RadioGroup1->ItemIndex==0 && openbrowser==true)
817. {
818. Form7->Show();
819. } 820. }
821. if (RadioGroup2->ItemIndex==0) { 822. //allow code
823. if(RadioGroup2->ItemIndex==0 && openftp==true) 824. {
825. Form8->Show();
826. } 827. }
828. if (RadioGroup1->ItemIndex==0) { 829. //allow code
830. if(RadioGroup1->ItemIndex==0 && openmail==true) 831. {
832. //mail form 833. }
834. }
835. //end of allow code
836. if(RadioGroup1->ItemIndex==1) 837. {
838. int httpservice=1;
839. if(openbrowser==true && RadioGroup1->ItemIndex==1) 840. {
841. if(Form1->ADOTable2->FieldByName("ID Http")->AsInteger == httpservice) 842. {
843. Form7->Show();
844. openbrowser=false; // emfanizei thn forma p einai o internet explorer 845. }
846. else
847. Form5->Frame21->Edit2->Text="Http Srv not Available";
848. openbrowser=false;
849. } 850. }
851. if(RadioGroup2->ItemIndex==1) 852. {
853. int ftpservice=2;
854. if(openftp==true && RadioGroup2->ItemIndex==1)
Μπαμπέκος Χρήστος Α.Ε.Μ.:1904 Βουλγαράκη Φωτεινή Α.Ε.Μ:1912 103 855. {
856. if(Form1->ADOTable2->FieldByName("ID Ftp")->AsInteger == ftpservice) 857. {
858. //forma ftp service 859. Form8->Show();
860. } 861. else
862. Form5->Frame21->Edit2->Text="FTP Srv not Available";
863. openftp=false;
864. } 865. }
866. if(RadioGroup3->ItemIndex==1) 867. {
868. int mailservice=3;
869. if(openmail==true && RadioGroup3->ItemIndex==1) 870. {
871. if(Form1->ADOTable2->FieldByName("ID Pop3")->AsInteger == mailservice
&& Form14->online == true) 872. {
873. //forma mail service 874. Form12->Show();
875. } 876. else
877. Form5->Frame21->Edit2->Text="Mail Srv not Available or MailSrv is offline ";
878. openmail=false;
879. }
880. }
881. if (RadioGroup1->ItemIndex==2 || RadioGroup2->ItemIndex==2 ||
RadioGroup3->ItemIndex==2 ) 882. {
883. if(RadioGroup1->ItemIndex==2 && openbrowser==true) 884. {
885. Form5->Frame21->Edit2->Text="HTTP Blocked";
886. openbrowser=false;
887. }
888. if(RadioGroup2->ItemIndex==2 && openftp==true) 889. {
890. Form5->Frame21->Edit2->Text="FTP Blocked";
891. openftp=false;
892. }
893. if(RadioGroup3->ItemIndex==2 && openmail==true)
Μπαμπέκος Χρήστος Α.Ε.Μ.:1904 Βουλγαράκη Φωτεινή Α.Ε.Μ:1912 104 894. {
895. Form5->Frame21->Edit2->Text="Mail Blocked";
896. openmail=false;
897. }
898. }
899. if( Form1->ADOTable2->FieldByName("DMZ")->AsString == 1) 900. {
901. int x,y;
902. x=Form4->getX();
903. //y=Form4->getY();
904. if(x<551 && x>718) 905. {
906. Form4->Edit6->Text = " Not DMZ Zone ";
907. initializeobj=true;
908. }
909. if(x>551 && x<718) 910. {
911. Form4->Edit6->Text = " DMZ Zone ";
912. initializeobj=false;
913. }
914. if(x>640) 915. {
916. Form4->Edit6->Text = " ";
917. } 918. }
919. if(Form1->ADOTable2->FieldByName("DMZ")->AsString == 0) 920. {
921. int x=Form4->getX();
922. if(x>392) 923. {
924. Form4->Edit6->Text = " Not Internal Network ";
925. initializeobj=true;
926. }
927. if(x<398) 928. {
929. Form4->Edit6->Text = " Internal Network ";
930. initializeobj=false;
931. }
932. if(x>421 && x<607) 933. {
934. Form4->Edit6->Text = " ";
935. }
Μπαμπέκος Χρήστος Α.Ε.Μ.:1904 Βουλγαράκη Φωτεινή Α.Ε.Μ:1912 105 936. }
937. /*
938. if(Form6->CheckBox2->Checked) 939. {
940. if(Form8->fextention == str1) 941. {
942. Form8->Edit1->Text=".exe files blocked";
943. runfile=false;
944. } 945. else
946. Form8->Edit1->Text=" ";
947. runfile=true;
948. } 949. */
950. }// end of run firewall
951. }
952. //--- 953. void __fastcall TForm6::CheckBox1Click(TObject *Sender) 954. {
955. if (CheckBox1->Checked) { 956. Edit4->Text="Run";
957. Edit4->Color=clLime;
958. }
959. else if (!CheckBox1->Checked) {
960. Edit4->Text="Stop";
961. Edit4->Color=clRed;
962. } 963. }
964. //---
965. void __fastcall TForm6::CheckBox2Click(TObject *Sender) 966. {
967. str1 = ".exe";
968. }
969. //---
970. void __fastcall TForm6::CheckBox3Click(TObject *Sender) 971. {
972. str2 = ".dll";
973. }
974. //---
975. void __fastcall TForm6::CheckBox4Click(TObject *Sender)
Μπαμπέκος Χρήστος Α.Ε.Μ.:1904 Βουλγαράκη Φωτεινή Α.Ε.Μ:1912 106 976. {
977. str3 = ".com";
978. }
979. //---
980. void __fastcall TForm6::CheckBox5Click(TObject *Sender) 981. {
982. str4 = ".bat";
983. }
984. //---
985. void __fastcall TForm6::CheckBox6Click(TObject *Sender) 986. {
987. str5 = ".bmp";
988. }
989. //---
990. void __fastcall TForm6::CheckBox7Click(TObject *Sender) 991. {
992. str6 = ".jpeg";
993. }
994. //--- 995. void __fastcall TForm6::Button1Click(TObject *Sender) 996. {
997. Form1->ADOTable3->Insert();
998. Form1->ADOTable3->FieldByName("Rule")->AsString = Edit1->Text;
999. Form1->ADOTable3->Post();
1000. Edit1->Clear();
1001. }
1002. //---
1003. void __fastcall TForm6::Button2Click(TObject *Sender) 1004. {
1005. Form1->ADOTable3->Delete();
1006. Edit1->Clear();
1007. }
1008. //---
Μπαμπέκος Χρήστος Α.Ε.Μ.:1904 Βουλγαράκη Φωτεινή Α.Ε.Μ:1912 107