├── .gitattributes ├── .gitignore ├── LICENSE ├── Output ├── visualsyslog_setup.exe └── visualsyslog_setup.zip ├── README.md ├── changelog.txt ├── install ├── alarm.wav ├── cfg.xml ├── highlight.xml ├── libeay32.dll ├── libssl32.dll ├── process.xml └── ssleay32.dll ├── readme_rus.md ├── screens ├── ico.png ├── m.png ├── screen1.png ├── screen2.png ├── screen3.png ├── screen4.png ├── screen5.png └── screen6.png ├── source ├── AlarmForm.cpp ├── AlarmForm.dfm ├── AlarmForm.h ├── aboutbox.cpp ├── aboutbox.dfm ├── aboutbox.h ├── cfg.cpp ├── cfg.h ├── fdb.cpp ├── fdb.h ├── fileframe.cpp ├── fileframe.dfm ├── fileframe.h ├── formhl.cpp ├── formhl.dfm ├── formhl.h ├── formprocess.cpp ├── formprocess.dfm ├── formprocess.h ├── main.cpp ├── main.dfm ├── main.h ├── matchform.cpp ├── matchform.dfm ├── matchform.h ├── messhl.cpp ├── messhl.h ├── messmatch.cpp ├── messmatch.h ├── messmatchframe.cpp ├── messmatchframe.dfm ├── messmatchframe.h ├── messprocessframe.cpp ├── messprocessframe.dfm ├── messprocessframe.h ├── messprocessing.cpp ├── messprocessing.h ├── messstyle.cpp ├── messstyle.h ├── messstyleframe.cpp ├── messstyleframe.dfm ├── messstyleframe.h ├── server.cpp ├── server.h ├── setup.cpp ├── setup.dfm ├── setup.h ├── sound.cpp ├── sound.h ├── syslog.cpp ├── syslog.h ├── tcpcon.cpp ├── tcpcon.h ├── udpcon.cpp └── udpcon.h ├── sourcecommon ├── File.cpp ├── File.h ├── MibAccess.cpp ├── MibAccess.h ├── base64.cpp ├── base64.h ├── critsection.cpp ├── critsection.h ├── gr.cpp ├── gr.h ├── gridcolumns.cpp ├── gridcolumns.h ├── inif.cpp ├── inif.h ├── letter.cpp ├── letter.h ├── maxxml.cpp ├── maxxml.h ├── messageform.cpp ├── messageform.dfm ├── messageform.h ├── saveini.cpp ├── saveini.h ├── savepar.cpp ├── savepar.h ├── sendmail.cpp ├── sendmail.h ├── tcpserv.cpp ├── tcpserv.h ├── tinyxml2.cpp ├── tinyxml2.h ├── udp.cpp ├── udp.h ├── unilist.cpp ├── unilist.h ├── utils.cpp └── utils.h ├── visualsyslog.cbproj ├── visualsyslog.cpp ├── visualsyslog.ico ├── visualsyslog.iss └── visualsyslog.res /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.dfm merge=union 6 | *.cbproj binary 7 | 8 | # Standard to msysgit 9 | *.doc diff=astextplain 10 | *.DOC diff=astextplain 11 | *.docx diff=astextplain 12 | *.DOCX diff=astextplain 13 | *.dot diff=astextplain 14 | *.DOT diff=astextplain 15 | *.pdf diff=astextplain 16 | *.PDF diff=astextplain 17 | *.rtf diff=astextplain 18 | *.RTF diff=astextplain 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # CodeGear Builder C++ 2 | 3 | # Build results 4 | 5 | [Dd]ebug/ 6 | [Rr]elease/ 7 | __history/ 8 | not for git/ 9 | ico/ 10 | 11 | *.obj 12 | *.local 13 | *.dsk 14 | *.skincfg 15 | *.~* 16 | -------------------------------------------------------------------------------- /Output/visualsyslog_setup.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/Output/visualsyslog_setup.exe -------------------------------------------------------------------------------- /Output/visualsyslog_setup.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/Output/visualsyslog_setup.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://raw.githubusercontent.com/MaxBelkov/visualsyslog/master/screens/ico.png) Visual Syslog Server for Windows 2 | === 3 | Visual Syslog Server for Windows is a free open source program to receive and view syslog messages. 4 | Useful when setting up routers and systems based on Unix/Linux. 5 | 6 | Visual Syslog Server for Windows has a live messages view: switches to a new received message. Helpful color highlighting. 7 | Useful message filtering. Customizable notification and actions. 8 | 9 | [Read in Russian](readme_rus.md) 10 | 11 | ![Visual Syslog Server for Windows](https://github.com/MaxBelkov/visualsyslog/blob/master/screens/screen1.png?raw=true) 12 | 13 | Features 14 | === 15 | * Receive messages from various devices via UDP or TCP protocol (compliant to RFC 3164) 16 | * Syslog messages are displayed in real-time 17 | * Stores messages in files on disk 18 | * Log file rotation by size or by date 19 | * Filter displayed syslog messages based on facility, priority, host, source address, tag or message contents 20 | * Customizable color highlighting with nice 3D design 21 | * Generating notifications depending on the content of the received message: 22 | * Show alarms windows 23 | * Play sound file 24 | * Send e-mail notifications via smtp server 25 | * Customizable notices format 26 | * Performs actions depending on the content of the received message: 27 | * Run external program with params 28 | * Saving message to the specified file 29 | * Support for sending mail via SMTP server with authentication SSL / TLS 30 | (Support Gmail and iCloud mail smtp servers. You can use the push notifications on your mobile device for instant delivery of alarms.) 31 | * Lightweight and very fast 32 | * Run as a Windows application 33 | * Minimize to system tray 34 | * Support Windows XP/Vista/7/8/8.1, Windows Server 2003/2008/2012 35 | * Easy to install: adjustment is not required 36 | * Import historical syslog messages after the start of the program 37 | * View syslog messages from the file 38 | * The ability to receive messages encoded in UTF8 39 | * Free open source software, licensed under the GPL V2 40 | 41 | Download 42 | === 43 | Visual Syslog Server for Windows download installer: 44 | [Last developper snapshot 1.6.4](https://github.com/MaxBelkov/visualsyslog/blob/master/Output/visualsyslog_setup.exe?raw=true) 45 | [Latest stable release 1.6.4](https://github.com/MaxBelkov/visualsyslog/releases/latest) 46 | 47 | Installation 48 | === 49 | After installation Visual Syslog Server for Windows works immediately: adjustment is not required. 50 | Waiting for messages on the UDP and TCP port 514 (default setting). 51 | Visual Syslog Server is an Windows application (installing a system service is not required). 52 | Installer adds firewall exception. 53 | 54 | Building from sources 55 | === 56 | To build Windows Syslog Server from sources use CodeGear RAD Studio C++Builder 2007 57 | Main project file _visualsyslog.cbproj_ 58 | Required components: [Indy.Sockets (VCL) version 10](http://www.indyproject.org/Sockets/index.EN.aspx) 59 | 60 | To build the installer, use Inno Setup Compiler 5.5.1(a) 61 | Installer project file _visualsyslog.iss_ 62 | 63 | Support 64 | === 65 | Your questions and suggestions please send to ![](https://github.com/MaxBelkov/visualsyslog/blob/master/screens/m.png?raw=true) 66 | 67 | Future plans 68 | === 69 | * Message statistics 70 | 71 | If you need these or other functions let me know. 72 | 73 | Screenshots 74 | === 75 | 76 | Color highlighting setup 77 | 78 | ![Visual Syslog Server for Windows color highlighting](https://github.com/MaxBelkov/visualsyslog/blob/master/screens/screen2.png?raw=true) 79 | 80 | Message processing setup 81 | 82 | ![Visual Syslog Server for Windows message processing](https://github.com/MaxBelkov/visualsyslog/blob/master/screens/screen3.png?raw=true) 83 | 84 | Main setup 85 | 86 | ![Visual Syslog Server for Windows main setup](https://github.com/MaxBelkov/visualsyslog/blob/master/screens/screen6.png?raw=true) 87 | 88 | Files rotation setup 89 | 90 | ![Visual Syslog Server for Windows files rotation setup](https://github.com/MaxBelkov/visualsyslog/blob/master/screens/screen5.png?raw=true) 91 | 92 | Smtp server setup to send e-mail messages 93 | 94 | ![Visual Syslog Server for Windows smtp server setup](https://github.com/MaxBelkov/visualsyslog/blob/master/screens/screen4.png?raw=true) 95 | -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | Visual Syslog Server for Windows Version history 2 | 3 | 1.6.4 2015-11-23 4 | 5 | - Fixed bug with sending e-mail 6 | 7 | 1.6.3 2015-11-20 8 | 9 | - Fixed bug with file rotation by "New name" 10 | 11 | 1.6.2 2015-10-09 12 | 13 | - Fixed bug with some toolbar buttons in main window 14 | 15 | 1.6.1 2015-10-06 16 | 17 | - The ability to receive messages encoded in UTF8 18 | 19 | 1.6.0 2015-09-29 20 | 21 | - Log file rotation by size 22 | - Log file rotation by date 23 | - Renaming files after rotation 24 | - Improved performance 25 | 26 | 1.5.2 2015-09-25 27 | 28 | - The ability to change the default log file name "syslog" 29 | 30 | 1.5.1 2015-09-02 31 | 32 | - "Hide tool bars" context menu item 33 | - Invalid facility codes in the received messages replaced by "logalert" 34 | - Fixed bugs 35 | 36 | 1.5.0 2014-12-26 37 | 38 | - Improved interface 39 | - Improved performance 40 | - Improved filtering messages 41 | - Generating notifications depending on the content of the received message: 42 | Show alarms windows 43 | Play sound file 44 | Send e-mail notifications via smtp server 45 | Customizable notices format 46 | - Performs actions depending on the content of the received message: 47 | Run external program with params 48 | Saving message to the specified file 49 | - Support for sending mail via SMTP server with authentication SSL / TLS 50 | (support Gmail and iCloud mail smtp servers) 51 | - Installer adds firewall exception 52 | - 3D highlighting 53 | 54 | 1.4.1 2014-11-25 55 | 56 | - Fixed bugs 57 | 58 | 1.4.0 2014-11-11 59 | 60 | - Improved messages filtering 61 | - Customizable color highlighting 62 | 63 | 1.3 2014-10-16 64 | 65 | - Improved interface 66 | - TCP transport support 67 | - Increased speed of logging messages 68 | - View syslog messages from file 69 | - Write all internal error messages to a file: errors.txt 70 | - Write all received unprocessed messages to a temporary file: raw 71 | - Fixed bugs 72 | 73 | 1.2 2014-09-23 74 | 75 | - Add "Text to ignore" filter 76 | - Add "Automatic start with windows" option 77 | - Fixed bugs 78 | -------------------------------------------------------------------------------- /install/alarm.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/install/alarm.wav -------------------------------------------------------------------------------- /install/cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 1 5 | 0.0.0.0 6 | 514 7 | 1 8 | 0.0.0.0 9 | 514 10 |
11 | 12 | 13 | 25 14 | 15 | 595F36CEE356F25BAE17DFD26A6C7CAF04B25D87FB7E0BDDBC 16 | 0 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | syslog 26 | 0 27 | 28 | 29 |
30 | -------------------------------------------------------------------------------- /install/libeay32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/install/libeay32.dll -------------------------------------------------------------------------------- /install/libssl32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/install/libssl32.dll -------------------------------------------------------------------------------- /install/process.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 6 | 0 7 | 255 8 | 16777215 9 | 1 10 | 0 11 | 1 12 | 0 13 | 1 14 | 15 | 16 | 0 17 | 0 18 | {time} {message} 19 | 0 20 | alarm.wav 21 | 1 22 | 0 23 | 24 | 0 25 | 26 | 0 27 | 0 28 | -1 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /install/ssleay32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/install/ssleay32.dll -------------------------------------------------------------------------------- /readme_rus.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/readme_rus.md -------------------------------------------------------------------------------- /screens/ico.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/screens/ico.png -------------------------------------------------------------------------------- /screens/m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/screens/m.png -------------------------------------------------------------------------------- /screens/screen1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/screens/screen1.png -------------------------------------------------------------------------------- /screens/screen2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/screens/screen2.png -------------------------------------------------------------------------------- /screens/screen3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/screens/screen3.png -------------------------------------------------------------------------------- /screens/screen4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/screens/screen4.png -------------------------------------------------------------------------------- /screens/screen5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/screens/screen5.png -------------------------------------------------------------------------------- /screens/screen6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/screens/screen6.png -------------------------------------------------------------------------------- /source/AlarmForm.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "sound.h" // play sound thread 6 | #include "saveini.h" // TSaveParamsINI 7 | #include "AlarmForm.h" 8 | //--------------------------------------------------------------------------- 9 | #pragma package(smart_init) 10 | #pragma resource "*.dfm" 11 | 12 | TShowAlarmForm * ShowAlarmForm = NULL; 13 | extern TSaveParamsINI * AppParams; 14 | //--------------------------------------------------------------------------- 15 | __fastcall TShowAlarmForm::TShowAlarmForm(TComponent* Owner) 16 | : TForm(Owner) 17 | { 18 | ListBox->Color = (TColor)RGB(255,197,197); 19 | *AppParams >> this; 20 | } 21 | //--------------------------------------------------------------------------- 22 | void __fastcall TShowAlarmForm::FormDestroy(TObject *Sender) 23 | { 24 | *AppParams << this; 25 | } 26 | //--------------------------------------------------------------------------- 27 | void __fastcall TShowAlarmForm::ClearButtonClick(TObject *Sender) 28 | { 29 | ListBox->Items->Clear(); 30 | OKButtonClick(Sender); 31 | } 32 | //--------------------------------------------------------------------------- 33 | void __fastcall TShowAlarmForm::OKButtonClick(TObject *Sender) 34 | { 35 | if( TalkingThread ) 36 | TalkingThread->Stop(); 37 | Close(); 38 | } 39 | //--------------------------------------------------------------------------- 40 | -------------------------------------------------------------------------------- /source/AlarmForm.dfm: -------------------------------------------------------------------------------- 1 | object ShowAlarmForm: TShowAlarmForm 2 | Left = 0 3 | Top = 0 4 | BorderIcons = [] 5 | Caption = 'Visual syslog alarms' 6 | ClientHeight = 170 7 | ClientWidth = 553 8 | Color = clBtnFace 9 | Constraints.MinHeight = 120 10 | Constraints.MinWidth = 400 11 | Font.Charset = DEFAULT_CHARSET 12 | Font.Color = clWindowText 13 | Font.Height = -11 14 | Font.Name = 'Tahoma' 15 | Font.Style = [] 16 | FormStyle = fsStayOnTop 17 | Icon.Data = { 18 | 0000010001001010000001000800680500001600000028000000100000002000 19 | 0000010008000000000000010000000000000000000000000000000000000000 20 | 0000023E6E0002427A0002467E0012467A00024A8200024E860002528A000256 21 | 8E001A52820002529200025A920002629E0026669600166EA6000272AE001E76 22 | AA000276B2003276A6000E82C200128ACA00268EC6001A92EA00229AEE002A9E 23 | EE0036A6EE0032A6F2003AB2F2004AA6CE005AB6D60042B6F60042BAF60046BA 24 | F60042BAFA0046BEFA0046C2FA004EC2FA0052C2F6005EC6F60052C6FA0056CA 25 | FA005ACAFA005ECAFA005ECEFA0066D2FA0062D2FE006AD6FA0072DAFE0076DA 26 | FE007AE2FE007EE2FE007EEAFE008EC6E600AAD6F60082E2FE0086E6FE0086EA 27 | FE008EEAFE0092F2FE009AF2FE00A2F2FE00A6F2FE00A2F6FE00AAFAFE00AEFA 28 | FE00B6FEFE00DDDDDD00CAEAFE00D6EEFE00FEFEFE0002366600000000000000 29 | 0000000000000000000000000000000000000000000000000000000000000000 30 | 0000000000007C0DAF0000000000C805917C98200500480EAF005105917C7813 31 | 05006D05917C000000003D04917C000000000000000000000000000000000000 32 | 0000000000000000000000000000000000000000000000000000000000000000 33 | 0000000000000000000000000000000000000000000000000000000000000000 34 | 0000280200000000000000000000000000000000000000000000000000000000 35 | 0000D2690000980BAF00000005008010AF0018EE907CC040917CFFFFFFFFBB40 36 | 917C8ED60100450000008C0DAF00800010C08010AF0018EE907C7005917CFFFF 37 | FFFF000000003D04917CC00EAF00750B817C00000000021000005810AF000100 38 | 00001800000000000000A80EAF0042000000000000008C0EAF00000000000000 39 | 0000000000000C000000020000000101907C00FCFD7F44000000000000000200 40 | 00004C001A02A020050000000000A020050005000000DFE2807CE40EAF004F1A 41 | 807C30010000000000C000000000000000000200000080000000000000002810 42 | AF002F444D0088B01901000000C000000000140FAF0002000000800000000000 43 | 0000200000001000000065444D000C0000000000000001000000443A5C574F52 44 | 4B5C4C4D536572766572335C69636F5C616C61726D5F31362E69636F0000540F 45 | AF0000000000C805917C48AA19012010AF005105917C080838006D05917C1E00 46 | 000050AA19010000000078B01901000000000800000040000000BCE7007C0000 47 | 3800800DAF0069636C00CC0FAF0018EE907CF006917CFFFFFFFFEB06917C4E4C 48 | 4B00FFE9907C0E10817C30010000000000000000000000000000E80FAF006810 49 | AF0016000000000000002E10817C160000005810AF0010000000704C4B003300 50 | 00000000000016000000D40FAF00B8174D008010AF00F399837C3810817CFFFF 51 | FFFF2E10817CBC3D4D00300100006810AF00160000003810AF00000000000000 52 | 0000000000150C000000080A00000000000000001C1D1203020A350F00000000 53 | 00000000040D09070E1E440F00000000000000050C01462A1A18440F00000000 54 | 000B030C062622231B19440F0000000005071028212327282420440F0000000C 55 | 341A171A1F272B2D2B282515000000144345161920292C2F302C2A1500000000 56 | 1414454520282F3236312E150000000000001414452B2F373939331400000000 57 | 0000000014452F393B3C3A3A1400000000000000001445383D403F3A14000000 58 | 00000000000014453E41413A1400000000000000000000144545451414000000 59 | 000000000000000014141100140000000000000000000000000013131400FE73 60 | 0000FC030000FC030000F8030000E0030000C00300008003000080030000C003 61 | 0000F0030000FC010000FE010000FF010000FF810000FFC50000FFF10000} 62 | OldCreateOrder = False 63 | Position = poDesigned 64 | OnDestroy = FormDestroy 65 | DesignSize = ( 66 | 553 67 | 170) 68 | PixelsPerInch = 96 69 | TextHeight = 13 70 | object OKButton: TBitBtn 71 | Left = 130 72 | Top = 134 73 | Width = 113 74 | Height = 28 75 | Hint = 'Close alarms window and stop playing sound' 76 | Anchors = [akBottom] 77 | Cancel = True 78 | Caption = 'Close' 79 | Default = True 80 | ParentShowHint = False 81 | ShowHint = True 82 | TabOrder = 1 83 | OnClick = OKButtonClick 84 | Glyph.Data = { 85 | 36030000424D3603000000000000360000002800000010000000100000000100 86 | 18000000000000030000C40E0000C40E00000000000000000000FFFFFFFFFFFF 87 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 88 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 89 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 90 | FFFFFFFFFFFFFFFFFFB8D2B7357F33C8DCC7FFFFFFFFFFFFFFFFFFFFFFFFFFFF 91 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB9D8B7398E332BAE2041 92 | 963CD7E9D6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 93 | FFFFFFBADCB73C9B3333C32524CD132BBB1D4DA445E5F2E4FFFFFFFFFFFFFFFF 94 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBBDDB73D9F334ACC3A29C31839CC2828 95 | C21731B1235AAD51F0F8EFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBBDFB7 96 | 3EA43363DA5333BC2255D1453EA43334B6252CB81B36AC286AB861F7FBF7FFFF 97 | FFFFFFFFFFFFFFFFFFFFFFFFFF3FA83370E65F59D0486BE15A3FA83398D09243 98 | AB373AB62932B2213BAB2D7BC373FDFEFDFFFFFFFFFFFFFFFFFFFFFFFFBCE1B7 99 | 41AC3374EA6341AC33BCE1B7FFFFFFB8E0B340AE3340B72F38AF2740AE318CCD 100 | 84FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBCE3B741AF33BCE3B7FFFFFFFFFFFFFF 101 | FFFF9DD69645B73758CF4756CD4545B536A3D99CFFFFFFFFFFFFFFFFFFFFFFFF 102 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFE84CD7A4DC13D61D8505FD6 103 | 4F46B737B9E3B3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 104 | FFFFFFFFFFF9FDF96DC66156CC466BE25A72E96243B533FFFFFFFFFFFFFFFFFF 105 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0F9EF5DC24F77EE 106 | 6643B933BDE6B7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 107 | FFFFFFFFFFFFFFFFFFFFFFE3F5E044BB33BDE7B7FFFFFFFFFFFFFFFFFFFFFFFF 108 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 109 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 110 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF} 111 | end 112 | object ListBox: TListBox 113 | Left = 8 114 | Top = 8 115 | Width = 537 116 | Height = 116 117 | Anchors = [akLeft, akTop, akRight, akBottom] 118 | Font.Charset = DEFAULT_CHARSET 119 | Font.Color = clWindowText 120 | Font.Height = -11 121 | Font.Name = 'Tahoma' 122 | Font.Style = [] 123 | ItemHeight = 13 124 | ParentFont = False 125 | TabOrder = 0 126 | end 127 | object ClearButton: TBitBtn 128 | Left = 307 129 | Top = 134 130 | Width = 113 131 | Height = 28 132 | Hint = 'Clear all messages, close alarms window and stop playing sound' 133 | Anchors = [akBottom] 134 | Caption = 'Close && Clear' 135 | ParentShowHint = False 136 | ShowHint = True 137 | TabOrder = 2 138 | OnClick = ClearButtonClick 139 | Glyph.Data = { 140 | 36040000424D3604000000000000360000002800000010000000100000000100 141 | 2000000000000004000000000000000000000000000000000000000000000000 142 | 000000000000000000000824290009262B000A2D33000E363D000C2F36000823 143 | 2800081E230001090B0000000000000000000000000000000000000000000000 144 | 0000061619000103040001141700115C6A842E91A2BB229DB6CC34B6CDEE1967 145 | 7690000000000000000000000000000000000000000000000000000000001A68 146 | 7200031214001B73809154D2E3F73EC1D7FE27D1E6FF2CC9DFFF30C3D9FF33BA 147 | CFEB00060700000000000000000000000000000000000000000000000000268C 148 | 980021B9CCA759D7E9FE54DEF0FF59DAEBFF3FD1E5FF1ACCE3FF40CEE2FF32CC 149 | E0FE05374200061C1F00000507000000000000000000000000000000000026B8 150 | CB2964DFEEE856D9E9FE61DDEFFF5AE5F5FF62DCECFF28D3E8FF1AC7DFFF2DD2 151 | E5FF1490A7530000000000000000000000000000000000000000000000000000 152 | 000037CEE22F6DE4F2F283EBF8FF5EE2F3FF5BE4F4FF35D3E8FF1ECDE3FF28D1 153 | E5FF1AA8C15A0000000000000000000000000000000000000000000000000000 154 | 0000000000003ED2E45376EAF7FD77EBF9FF5DE7F6FF3ED7EBFF2ED6EAFF31D1 155 | E5FE26A5C0400000000000000000000000000000000000000000000000000000 156 | 0000000000000000000042D3E57D77ECFAFE6AEBFAFF50E0F1FF3CBDD1FF557B 157 | 99FE47819F300000000000000000000000000000000000000000000000000000 158 | 00000000000000000000000000003FC9DE746FA3BBFE7D85A3FF825E85FF6A7F 159 | A2FF349AB5740000000000000000000000000000000000000000000000000000 160 | 000000000000000000000000000000000000697694B173A7BFFF5DD0E3FF4AD4 161 | E7FF29A7C2A32F8AB00200000000000000000000000000000000000000000000 162 | 0000000000000000000000000000000000003FABC33547C7DCA0269AC1EA1384 163 | C2FF1E6D9CB82889B60100000000000000000000000000000000000000000000 164 | 00000000000000000000000000000000000000000000000000002980B0992C8D 165 | CCFF2787C4FE206FA06A00000000000000000000000000000000000000000000 166 | 00000000000000000000000000000000000000000000000000001F79AE424EA0 167 | D4FE419CD6FF3586BAF12373A616000000000000000000000000000000000000 168 | 00000000000000000000000000000000000000000000000000003184B9013E8A 169 | BAD03283B7CE3687BBD92674A67C000000000000000000000000000000000000 170 | 0000000000000000000000000000000000000000000000000000000000002677 171 | AB323D88B6E7519AC8E4307EAF9B000000000000000000000000000000000000 172 | 0000000000000000000000000000000000000000000000000000000000000000 173 | 00002978AB16196B9E502A79AB12000000000000000000000000} 174 | end 175 | end 176 | -------------------------------------------------------------------------------- /source/AlarmForm.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef AlarmFormH 3 | #define AlarmFormH 4 | //--------------------------------------------------------------------------- 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | //--------------------------------------------------------------------------- 11 | class TShowAlarmForm : public TForm 12 | { 13 | __published: // IDE-managed Components 14 | TBitBtn *OKButton; 15 | TListBox *ListBox; 16 | TBitBtn *ClearButton; 17 | void __fastcall FormDestroy(TObject *Sender); 18 | void __fastcall ClearButtonClick(TObject *Sender); 19 | void __fastcall OKButtonClick(TObject *Sender); 20 | private: // User declarations 21 | public: // User declarations 22 | __fastcall TShowAlarmForm(TComponent* Owner); 23 | }; 24 | //--------------------------------------------------------------------------- 25 | extern PACKAGE TShowAlarmForm *ShowAlarmForm; 26 | //--------------------------------------------------------------------------- 27 | #endif 28 | -------------------------------------------------------------------------------- /source/aboutbox.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "aboutbox.h" 6 | //--------------------------------------------------------------------------- 7 | #pragma package(smart_init) 8 | #pragma resource "*.dfm" 9 | 10 | String GetFullAppName(void); 11 | extern String ApplicationExeName; 12 | TAboutBoxForm * AboutBoxForm; 13 | //--------------------------------------------------------------------------- 14 | __fastcall TAboutBoxForm::TAboutBoxForm(TComponent* Owner) 15 | : TForm(Owner) 16 | { 17 | Caption = GetFullAppName() + " [" + __DATE__ + "]"; 18 | try 19 | { 20 | Memo->Lines->LoadFromFile(ExtractFilePath(ApplicationExeName) + "changelog.txt"); 21 | } 22 | catch (...) 23 | {} 24 | } 25 | //--------------------------------------------------------------------------- 26 | void __fastcall TAboutBoxForm::LabelClick(TObject * Sender) 27 | { 28 | switch( ((TLabel *)Sender)->Tag ) 29 | { 30 | case 1: ShellExecute(GetDesktopWindow(), "open", 31 | ((TLabel *)Sender)->Caption.c_str(), NULL, NULL, SW_SHOWNORMAL); 32 | break; 33 | case 2: ShellExecute(GetDesktopWindow(), "open", 34 | (AnsiString("mailto:") + ((TLabel *)Sender)->Caption).c_str(), NULL, NULL, SW_SHOWNORMAL); 35 | break; 36 | } 37 | } 38 | //--------------------------------------------------------------------------- 39 | 40 | -------------------------------------------------------------------------------- /source/aboutbox.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef aboutboxH 3 | #define aboutboxH 4 | //--------------------------------------------------------------------------- 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | //--------------------------------------------------------------------------- 14 | class TAboutBoxForm : public TForm 15 | { 16 | __published: // IDE-managed Components 17 | TBevel *Bevel3; 18 | TBevel *Bevel2; 19 | TLabel *Label; 20 | TImage *ProgramIcon; 21 | TLabel *Label3; 22 | TBitBtn *OKButton; 23 | TLabel *Label1; 24 | TLabel *Label2; 25 | TBevel *Bevel1; 26 | TMemo *Memo; 27 | TLabel *Label4; 28 | void __fastcall LabelClick(TObject *Sender); 29 | private: // User declarations 30 | public: // User declarations 31 | __fastcall TAboutBoxForm(TComponent* Owner); 32 | }; 33 | //--------------------------------------------------------------------------- 34 | extern PACKAGE TAboutBoxForm *AboutBoxForm; 35 | //--------------------------------------------------------------------------- 36 | #endif 37 | -------------------------------------------------------------------------------- /source/cfg.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "messageform.h" 6 | #include "maxxml.h" 7 | #include "cfg.h" 8 | 9 | //--------------------------------------------------------------------------- 10 | TMainCfg::TMainCfg() 11 | { 12 | UdpEnable = true; 13 | UdpInterface = "0.0.0.0"; 14 | UdpPort = 514; 15 | 16 | TcpEnable = false; 17 | TcpInterface = "0.0.0.0"; 18 | TcpPort = 514; 19 | 20 | b3D = true; 21 | bWriteRaw = false; 22 | bReceiveUTF8 = false; 23 | } 24 | //--------------------------------------------------------------------------- 25 | const char * szSetupNode = "setup"; 26 | const char * szMainNode = "main"; 27 | const char * szMailNode = "mail"; 28 | extern const char * szStorageFiles;// = "files"; 29 | 30 | //--------------------------------------------------------------------------- 31 | void TMainCfg::Save(String file, TStorageFileList * sfl) 32 | { 33 | tinyxml2::XMLDocument doc; 34 | doc.InsertEndChild( doc.NewDeclaration() ); 35 | 36 | XMLNode * hls = doc.InsertEndChild( doc.NewElement(szSetupNode) ); 37 | 38 | XMLElementEx * p; 39 | 40 | p = (XMLElementEx *)doc.NewElement(szMainNode); 41 | hls->InsertEndChild(p); 42 | p->wb("UdpEnable", UdpEnable); 43 | p->ws("UdpInterface", UdpInterface); 44 | p->wi("UdpPort", UdpPort); 45 | p->wb("TcpEnable", TcpEnable); 46 | p->ws("TcpInterface", TcpInterface); 47 | p->wi("TcpPort", TcpPort); 48 | p->wb("D3", b3D); 49 | p->wb("WriteRaw", bWriteRaw); 50 | p->wb("ReceiveUTF8", bReceiveUTF8); 51 | 52 | p = (XMLElementEx *)doc.NewElement(szMailNode); 53 | hls->InsertEndChild(p); 54 | Letter.Save(p); 55 | 56 | sfl->Save(hls); 57 | 58 | XMLError err = doc.SaveFile(file.c_str()); 59 | if( err != XML_SUCCESS ) 60 | { 61 | ReportError2("Error writing file: \"%s\" [%d]", file.c_str(), (int)err); 62 | } 63 | } 64 | //--------------------------------------------------------------------------- 65 | void TMainCfg::Load(String file, TStorageFileList * sfl) 66 | { 67 | XMLError err; 68 | try 69 | { 70 | tinyxml2::XMLDocument doc; 71 | err = doc.LoadFile(file.c_str()); 72 | if( err == XML_SUCCESS ) 73 | { 74 | XMLElement * hls; 75 | hls = doc.RootElement(); 76 | if( ! hls ) 77 | throw 1; 78 | if( strcmpi(hls->Name(), szSetupNode) != 0 ) 79 | throw 1; 80 | 81 | // 82 | for(XMLElementEx * p = (XMLElementEx *)hls->FirstChildElement(); 83 | p; 84 | p = (XMLElementEx *)p->NextSiblingElement()) 85 | { 86 | if( strcmpi(p->Name(), szMainNode)==0 ) 87 | { 88 | UdpEnable = p->rb("UdpEnable", true); 89 | UdpInterface = p->rs("UdpInterface", "0.0.0.0"); 90 | UdpPort = p->ri("UdpPort", 514); 91 | TcpEnable = p->rb("TcpEnable", false); 92 | TcpInterface = p->rs("TcpInterface", "0.0.0.0"); 93 | TcpPort = p->ri("TcpPort", 514); 94 | b3D = p->rb("D3", true); 95 | bWriteRaw = p->rb("WriteRaw", false); 96 | bReceiveUTF8 = p->rb("ReceiveUTF8", false); 97 | } 98 | else if( strcmpi(p->Name(), szMailNode)==0 ) 99 | { 100 | Letter.Load(p); 101 | } 102 | else if( strcmpi(p->Name(), szStorageFiles)==0 ) 103 | { 104 | sfl->Load(p); 105 | } 106 | } 107 | } 108 | else 109 | throw 0; 110 | } 111 | catch(int i) 112 | { 113 | if( i==0 ) 114 | ReportError2("Error reading file: \"%s\" [%d]", file.c_str(), err); 115 | else 116 | ReportError2("Incorrect format of file: \"%s\"", file.c_str()); 117 | } 118 | } 119 | //--------------------------------------------------------------------------- 120 | #pragma package(smart_init) 121 | -------------------------------------------------------------------------------- /source/cfg.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef cfgH 3 | #define cfgH 4 | 5 | #include "letter.h" 6 | #include "fdb.h" 7 | //--------------------------------------------------------------------------- 8 | class TMainCfg 9 | { 10 | public: 11 | // main 12 | bool UdpEnable; 13 | String UdpInterface; 14 | int UdpPort; 15 | bool TcpEnable; 16 | String TcpInterface; 17 | int TcpPort; 18 | bool b3D; 19 | 20 | bool bWriteRaw; 21 | bool bReceiveUTF8; 22 | 23 | // mail 24 | TLetter Letter; 25 | 26 | public: 27 | TMainCfg(); 28 | void Save(String file, TStorageFileList * sfl); 29 | void Load(String file, TStorageFileList * sfl); 30 | }; 31 | //--------------------------------------------------------------------------- 32 | #endif 33 | -------------------------------------------------------------------------------- /source/fdb.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef fdbH 3 | #define fdbH 4 | 5 | #include "maxxml.h" // work with xml 6 | #include "file.h" // work with files 7 | 8 | //--------------------------------------------------------------------------- 9 | // saving messages to file 10 | class TStorageFile 11 | { 12 | public: 13 | int number; // file number to link from TMessProcess::SaveFile 14 | String file; // log file name (if user specify the file name without path: 15 | // WorkDir will be added) 16 | 17 | // *** LogRotate *** 18 | int rotation_type; // file rotation: 0-disable, 1-by size, 2-by date [0] 19 | // rotation by size 20 | int rotation_size; // > 0 [10] 21 | int rotation_mult; // 0,1,2 (KBs,MBs,GBs) [MBs] 22 | // rotation by date 23 | int rotation_moment; // 0,1,2,3 (Day,Week,Month,Year) [Week] 24 | int rotation_hour; // 0..23 [0] 25 | // file name after rotation 26 | int rotation_renaming; // 0-file+number[rotation_count] 1-rename file to rotation_name 27 | String rotation_name; // new file name (without path!) after rotation {dd-mm-yyyy hh} 28 | int rotation_count; // total number of rotated files >= 1 [10] 29 | 30 | private: 31 | TFile out; // file write object 32 | 33 | public: 34 | ULONGLONG file_size; // for log rotatition by size 35 | int last_date; // for log rotatition by date 36 | 37 | public: 38 | TStorageFile(); 39 | TStorageFile(TStorageFile * p); 40 | void operator = (TStorageFile * p); 41 | // save data to file 42 | bool Save(AnsiString s); 43 | 44 | String GetDescription(void); 45 | // get log file name with full path 46 | String GetFileName(void); 47 | void SetFileName(String f); 48 | 49 | void Save(XMLElementEx * p); 50 | void Load(XMLElementEx * p); 51 | 52 | // *** LogRotate *** 53 | void RotateFile(void); 54 | 55 | String GetFileNameToRotate(int num); // for rotation_renaming==0 56 | String GetNewRotationName(void); // for rotation_renaming==1 57 | 58 | bool IsRotationEnable(void); 59 | bool IsNeedRenameAfterRotate(void); 60 | 61 | String GetRotationDescription(void); 62 | 63 | // *** Rotation names log *** 64 | // (It used to view file with buttons "View prev" "view next") 65 | String RotationLogFormatFileName(void); 66 | // fn - log file name 67 | void RotationLogAddItem(String fn, String & file_to_delete); 68 | // num: 0-GetFileName() >=1-read rotation name from file 69 | String RotationLogGetItem(int num); 70 | }; 71 | //--------------------------------------------------------------------------- 72 | // file list 73 | class TStorageFileList : public TList 74 | { 75 | public: 76 | __fastcall TStorageFileList(); 77 | __fastcall virtual ~TStorageFileList(void); 78 | 79 | void __fastcall Add(TStorageFile * p); 80 | TStorageFile * __fastcall Get(int index); 81 | void __fastcall Del(int index); 82 | 83 | void Save(XMLNode * p); 84 | void Load(XMLNode * p); 85 | 86 | void operator = (TStorageFileList * p); 87 | // getall: true - return default StorageFile 88 | void GetList(TStrings * s, bool getall=false); 89 | 90 | TStorageFile * __fastcall GetByNumber(int _number); 91 | int GetNewNumber(void); 92 | 93 | void CheckRotate(void); 94 | 95 | private: 96 | virtual void __fastcall Clear(void); 97 | }; 98 | //--------------------------------------------------------------------------- 99 | #endif 100 | -------------------------------------------------------------------------------- /source/fileframe.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "fileframe.h" 6 | //--------------------------------------------------------------------------- 7 | #pragma package(smart_init) 8 | #pragma resource "*.dfm" 9 | 10 | extern String WorkDir; 11 | TFileFr * FileFr; 12 | 13 | char szDateTimeFormatHint[] = 14 | "Specify a filename to rename the file after rotation\n" 15 | "Example: file name \"file_{yyyy-mm-dd}\" is converted to name \"file_2015-09-29\" using the current date\n" 16 | "\nAllowable substitutions:\n" 17 | "{d} the day as a number without a leading zero (1-31)\n" 18 | "{dd} the day as a number with a leading zero (01-31)\n" 19 | "{ddd} the day as an abbreviation (Sun-Sat)\n" 20 | "{dddd} the day as a full name (Sunday-Saturday)\n" 21 | "{m} the month as a number without a leading zero (1-12). If the m specifier immediately follows an h or hh specifier, the minute rather than the month is using\n" 22 | "{mm} the month as a number with a leading zero (01-12). If the mm specifier immediately follows an h or hh specifier, the minute rather than the month is using\n" 23 | "{mmm} the month as an abbreviation (Jan-Dec)\n" 24 | "{mmmm} the month as a full name (January-December)\n" 25 | "{yy} the year as a two-digit number (00-99)\n" 26 | "{yyyy} the year as a four-digit number (0000-9999)\n" 27 | "{h} the hour without a leading zero (0-23)\n" 28 | "{hh} the hour with a leading zero (00-23)\n" 29 | "{n} the minute without a leading zero (0-59)\n" 30 | "{nn} the minute with a leading zero (00-59)\n" 31 | "{s} the second without a leading zero (0-59)\n" 32 | "{ss} the second with a leading zero (00-59)\n" 33 | ; 34 | //--------------------------------------------------------------------------- 35 | __fastcall TFileFr::TFileFr(TComponent* Owner) 36 | : TFrame(Owner) 37 | { 38 | OpenDialog->InitialDir = WorkDir; 39 | HelpLabel->Hint = szDateTimeFormatHint; 40 | } 41 | //--------------------------------------------------------------------------- 42 | void __fastcall TFileFr::SpeedButton2Click(TObject *Sender) 43 | { 44 | OpenDialog->Title = "Select file"; 45 | OpenDialog->Filter = "All files (*.*)|*.*"; 46 | OpenDialog->DefaultExt = ""; 47 | if( OpenDialog->Execute() ) 48 | FileEdit->Text = OpenDialog->FileName; 49 | } 50 | //--------------------------------------------------------------------------- 51 | void TFileFr::ToDialog(TStorageFile * p) 52 | { 53 | bEnableValuesChange = false; 54 | 55 | FileEdit->Text = p->GetFileName(); 56 | 57 | switch( p->rotation_type ) 58 | { 59 | case 0: RotationRB1->Checked = true; break; 60 | case 1: RotationRB2->Checked = true; break; 61 | case 2: RotationRB3->Checked = true; break; 62 | } 63 | SizeEdit->Text = p->rotation_size; 64 | SizeEditUD->Position = p->rotation_size; 65 | MultCB->ItemIndex = p->rotation_mult; 66 | MomentCB->ItemIndex = p->rotation_moment; 67 | HourEdit->Text = p->rotation_hour; 68 | HourEditUD->Position = p->rotation_hour; 69 | 70 | switch( p->rotation_renaming ) 71 | { 72 | case 0: RenamingRB0->Checked = true; break; 73 | case 1: RenamingRB1->Checked = true; break; 74 | } 75 | NewNameEdit->Text = p->rotation_name; 76 | CountEdit->Text = p->rotation_count; 77 | CountEditUD->Position = p->rotation_count; 78 | 79 | RotationEnable(); 80 | 81 | bEnableValuesChange = true; 82 | } 83 | //--------------------------------------------------------------------------- 84 | void TFileFr::RotationEnable(void) 85 | { 86 | bool b2 = RotationRB2->Checked; 87 | bool b3 = RotationRB3->Checked; 88 | 89 | SizeEdit->Enabled = b2; 90 | MultCB->Enabled = b2; 91 | MomentCB->Enabled = b3; 92 | HourEdit->Enabled = b3; 93 | 94 | RenamingRB0->Enabled = b2 || b3; 95 | RenamingRB1->Enabled = b2 || b3; 96 | CountEdit->Enabled = b2 || b3; 97 | NewNameEdit->Enabled = b2 || b3; 98 | } 99 | //--------------------------------------------------------------------------- 100 | void TFileFr::FromDialog(TStorageFile * p) 101 | { 102 | p->SetFileName(FileEdit->Text); 103 | 104 | if( RotationRB2->Checked ) 105 | p->rotation_type = 1; 106 | else if( RotationRB3->Checked ) 107 | p->rotation_type = 2; 108 | else 109 | p->rotation_type = 0; 110 | 111 | p->rotation_size = StrToIntDef(SizeEdit->Text, 10); 112 | if( p->rotation_size < 1 ) 113 | p->rotation_size = 1; 114 | 115 | if( MultCB->ItemIndex == -1 ) 116 | p->rotation_mult = 1; 117 | else 118 | p->rotation_mult = MultCB->ItemIndex; 119 | 120 | if( MomentCB->ItemIndex == -1 ) 121 | p->rotation_moment = 1; 122 | else 123 | p->rotation_moment = MomentCB->ItemIndex; 124 | 125 | p->rotation_hour = StrToIntDef(HourEdit->Text, 0); 126 | if( p->rotation_hour < 0 || p->rotation_hour > 23 ) 127 | p->rotation_hour = 0; 128 | 129 | if( RenamingRB0->Checked ) 130 | p->rotation_renaming = 0; 131 | else 132 | p->rotation_renaming = 1; 133 | p->rotation_name = NewNameEdit->Text.Trim(); 134 | p->rotation_count = StrToIntDef(CountEdit->Text, 1); 135 | if( p->rotation_count < 1 ) 136 | p->rotation_count = 1; 137 | } 138 | //--------------------------------------------------------------------------- 139 | void __fastcall TFileFr::Change(TObject *Sender) 140 | { 141 | if( bEnableValuesChange ) 142 | { 143 | if( OnValuesChange ) 144 | OnValuesChange(this); 145 | RotationEnable(); 146 | } 147 | } 148 | //--------------------------------------------------------------------------- 149 | void TFileFr::SetDefaultFile(bool b) 150 | { 151 | if( b ) 152 | { 153 | GroupBox->Caption = "File settings for default file"; 154 | } 155 | else 156 | { 157 | GroupBox->Caption = "File settings"; 158 | } 159 | } 160 | //--------------------------------------------------------------------------- 161 | void __fastcall TFileFr::HelpLabelClick(TObject *Sender) 162 | { 163 | NewNameEdit->Text = ExtractFileName(FileEdit->Text) + "_{yyyy-mm-dd}"; 164 | } 165 | //--------------------------------------------------------------------------- 166 | 167 | -------------------------------------------------------------------------------- /source/fileframe.dfm: -------------------------------------------------------------------------------- 1 | object FileFr: TFileFr 2 | Left = 0 3 | Top = 0 4 | Width = 486 5 | Height = 261 6 | TabOrder = 0 7 | object GroupBox: TGroupBox 8 | Left = 0 9 | Top = 0 10 | Width = 486 11 | Height = 261 12 | Align = alClient 13 | Caption = 'File settings' 14 | TabOrder = 0 15 | DesignSize = ( 16 | 486 17 | 261) 18 | object Label11: TLabel 19 | Left = 11 20 | Top = 24 21 | Width = 27 22 | Height = 13 23 | Caption = 'Name' 24 | end 25 | object SpeedButton2: TSpeedButton 26 | Left = 455 27 | Top = 39 28 | Width = 25 29 | Height = 25 30 | Hint = 'Select log file' 31 | Anchors = [akTop, akRight] 32 | Flat = True 33 | Glyph.Data = { 34 | 36040000424D3604000000000000360000002800000010000000100000000100 35 | 2000000000000004000000000000000000000000000000000000000000000000 36 | 0000000000000000000000000000000000000000000000000000000000000000 37 | 0000000000000000000000000000000000000000000000000000000000300000 38 | 0033000000330000003300000033000000330000003300000033000000330000 39 | 00330000003300000033000000330000002F00000000000000004598D1F24398 40 | D2FF4094D0FF3E92CFFF3E92CEFF3F92CEFF3F92CEFF3F92CEFF3F92CEFF3F92 41 | CEFF3F92CEFF3F92CEFF3F93CFFF4194CEF00000000E000000004499D2FF3F94 42 | D0FFABFBFFFF9BF3FFFF92F1FFFF93F1FFFF93F1FFFF93F1FFFF93F1FFFF93F1 43 | FFFF93F1FFFF93F1FFFFA6F8FFFF65B8E3FF31709D5F000000004398D2FF4FA6 44 | D9FF8EDAF5FFA2EEFFFF82E5FEFF84E5FEFF84E5FEFF85E6FEFF85E6FEFF85E6 45 | FEFF85E6FEFF84E6FEFF96EBFFFF8CD8F5FF3985BCB8000000004296D1FF6BBE 46 | E8FF6DBDE6FFBBF2FFFF75DEFDFF77DEFCFF78DEFCFF7BDFFCFF7DDFFCFF7DDF 47 | FCFF7DDFFCFF7CDFFCFF80E0FDFFADF0FFFF4D9DD3FF0000000E4095D0FF8AD7 48 | F5FF44A1D8FFDDFDFFFFDAFAFFFFDBFAFFFFDEFAFFFF74DCFCFF76DBFAFF75DA 49 | FAFF74DAFAFF74DAFAFF72D9FAFFA1E8FFFF7CBFE6FF306F9C5E3E94D0FFABF0 50 | FFFF449DD6FF368CCBFF368CCBFF368CCBFF378BCBFF5CBEEAFF6FD9FBFF6AD6 51 | FAFF68D5F9FF67D4F9FF66D4F9FF82DEFCFFAAE0F6FF3885BCB93D92CFFFB9F4 52 | FFFF73DBFBFF6BCCF2FF6CCDF3FF6CCEF3FF6DCEF3FF479CD4FF56BAE9FFDAF8 53 | FFFFD7F6FFFFD6F6FFFFD5F6FFFFD5F7FFFFDBFCFFFF3E94D0FF3C92CFFFC0F3 54 | FFFF71DAFBFF74DBFBFF75DBFCFF75DBFCFF76DCFCFF73DAFAFF449CD4FF378C 55 | CBFF368CCBFF358CCCFF348DCCFF3890CEFF3D94D0FF4398D2EB3B92CFFFCAF6 56 | FFFF69D5F9FF6CD5F9FF6BD5F9FF69D5F9FF69D5FAFF6AD7FBFF68D4FAFF5EC7 57 | F1FF5EC7F2FF5DC8F2FFB4E3F8FF3D94D0FF3F8FC669000000003B92CFFFD5F7 58 | FFFF60D1F9FF61D0F8FFB4EBFDFFD9F6FFFFDAF8FFFFDAF8FFFFDBF9FFFFDCFA 59 | FFFFDCFAFFFFDCFBFFFFE0FFFFFF3E95D0FF4599D333000000003D94D0FFDCFC 60 | FFFFD8F7FFFFD8F7FFFFDBFAFFFF358ECDFF3991CEFF3A92CFFF3A92CFFF3A92 61 | CFFF3A92CFFF3B92CFFF3D94D0FF4398D2D700000000000000004398D2B03D94 62 | D0FF3A92CFFF3A92CFFF3D94D0FF4197D1D20000000000000000000000000000 63 | 0000000000000000000000000000000000000000000000000000000000000000 64 | 0000000000000000000000000000000000000000000000000000000000000000 65 | 0000000000000000000000000000000000000000000000000000000000000000 66 | 0000000000000000000000000000000000000000000000000000000000000000 67 | 0000000000000000000000000000000000000000000000000000} 68 | ParentShowHint = False 69 | ShowHint = True 70 | OnClick = SpeedButton2Click 71 | end 72 | object Label1: TLabel 73 | Left = 295 74 | Top = 135 75 | Width = 22 76 | Height = 13 77 | Caption = 'hour' 78 | end 79 | object FileEdit: TEdit 80 | Left = 11 81 | Top = 43 82 | Width = 440 83 | Height = 21 84 | Anchors = [akLeft, akTop, akRight] 85 | TabOrder = 0 86 | OnChange = Change 87 | end 88 | object RotationRB1: TRadioButton 89 | Left = 11 90 | Top = 76 91 | Width = 113 92 | Height = 17 93 | Caption = 'Rotation off' 94 | TabOrder = 1 95 | OnClick = Change 96 | end 97 | object RotationRB2: TRadioButton 98 | Left = 11 99 | Top = 103 100 | Width = 113 101 | Height = 17 102 | Caption = 'Rotation by size:' 103 | TabOrder = 2 104 | OnClick = Change 105 | end 106 | object RotationRB3: TRadioButton 107 | Left = 11 108 | Top = 130 109 | Width = 113 110 | Height = 17 111 | Caption = 'Rotation by date:' 112 | TabOrder = 3 113 | OnClick = Change 114 | end 115 | object SizeEdit: TEdit 116 | Left = 136 117 | Top = 101 118 | Width = 49 119 | Height = 21 120 | TabOrder = 4 121 | Text = '1' 122 | OnChange = Change 123 | end 124 | object MultCB: TComboBox 125 | Left = 217 126 | Top = 101 127 | Width = 49 128 | Height = 21 129 | Style = csDropDownList 130 | ItemHeight = 13 131 | ItemIndex = 0 132 | TabOrder = 6 133 | Text = 'KBs' 134 | OnSelect = Change 135 | Items.Strings = ( 136 | 'KBs' 137 | 'MBs' 138 | 'GBs') 139 | end 140 | object MomentCB: TComboBox 141 | Left = 136 142 | Top = 130 143 | Width = 66 144 | Height = 21 145 | Style = csDropDownList 146 | ItemHeight = 13 147 | ItemIndex = 2 148 | TabOrder = 7 149 | Text = 'Month' 150 | OnSelect = Change 151 | Items.Strings = ( 152 | 'Day' 153 | 'Week' 154 | 'Month' 155 | 'Year') 156 | end 157 | object HourEdit: TEdit 158 | Left = 216 159 | Top = 130 160 | Width = 49 161 | Height = 21 162 | TabOrder = 8 163 | Text = '0' 164 | OnChange = Change 165 | end 166 | object Panel1: TPanel 167 | Left = 11 168 | Top = 160 169 | Width = 466 170 | Height = 97 171 | Anchors = [akLeft, akTop, akRight] 172 | BevelOuter = bvNone 173 | TabOrder = 10 174 | DesignSize = ( 175 | 466 176 | 97) 177 | object Label4: TLabel 178 | Left = 0 179 | Top = 0 180 | Width = 139 181 | Height = 13 182 | Caption = 'After rotation rename file to:' 183 | end 184 | object HelpLabel: TLabel 185 | Left = 432 186 | Top = 46 187 | Width = 27 188 | Height = 16 189 | Cursor = crHandPoint 190 | Anchors = [akTop, akRight] 191 | Caption = 'help' 192 | Font.Charset = DEFAULT_CHARSET 193 | Font.Color = clNavy 194 | Font.Height = -13 195 | Font.Name = 'Tahoma' 196 | Font.Style = [fsBold, fsUnderline] 197 | ParentFont = False 198 | ParentShowHint = False 199 | ShowHint = True 200 | OnClick = HelpLabelClick 201 | ExplicitLeft = 435 202 | end 203 | object Label2: TLabel 204 | Left = 0 205 | Top = 76 206 | Width = 76 207 | Height = 13 208 | Caption = 'Number of files:' 209 | end 210 | object RenamingRB0: TRadioButton 211 | Left = 8 212 | Top = 22 213 | Width = 174 214 | Height = 17 215 | Caption = 'Name + number' 216 | Checked = True 217 | TabOrder = 0 218 | TabStop = True 219 | OnClick = Change 220 | end 221 | object RenamingRB1: TRadioButton 222 | Left = 8 223 | Top = 46 224 | Width = 97 225 | Height = 17 226 | Hint = 'File name without path' 227 | Caption = 'New name:' 228 | ParentShowHint = False 229 | ShowHint = True 230 | TabOrder = 1 231 | OnClick = Change 232 | end 233 | object CountEdit: TEdit 234 | Left = 109 235 | Top = 72 236 | Width = 70 237 | Height = 21 238 | TabOrder = 3 239 | Text = '1' 240 | OnChange = Change 241 | end 242 | object NewNameEdit: TEdit 243 | Left = 109 244 | Top = 45 245 | Width = 312 246 | Height = 21 247 | Anchors = [akLeft, akTop, akRight] 248 | TabOrder = 2 249 | OnChange = Change 250 | end 251 | object CountEditUD: TUpDown 252 | Left = 179 253 | Top = 72 254 | Width = 17 255 | Height = 21 256 | Associate = CountEdit 257 | Min = 1 258 | Max = 32767 259 | Position = 1 260 | TabOrder = 4 261 | Thousands = False 262 | end 263 | end 264 | object HourEditUD: TUpDown 265 | Left = 265 266 | Top = 130 267 | Width = 17 268 | Height = 21 269 | Associate = HourEdit 270 | Max = 23 271 | TabOrder = 9 272 | Thousands = False 273 | end 274 | object SizeEditUD: TUpDown 275 | Left = 185 276 | Top = 101 277 | Width = 17 278 | Height = 21 279 | Associate = SizeEdit 280 | Min = 1 281 | Max = 32767 282 | Position = 1 283 | TabOrder = 5 284 | Thousands = False 285 | end 286 | end 287 | object OpenDialog: TOpenDialog 288 | DefaultExt = 'wav' 289 | Filter = 'All files (*.*)|*.*' 290 | Options = [ofNoChangeDir, ofEnableSizing] 291 | Left = 156 292 | Top = 3 293 | end 294 | end 295 | -------------------------------------------------------------------------------- /source/fileframe.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef fileframeH 3 | #define fileframeH 4 | //--------------------------------------------------------------------------- 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "fdb.h" 13 | #include 14 | #include 15 | //--------------------------------------------------------------------------- 16 | class TFileFr : public TFrame 17 | { 18 | __published: // IDE-managed Components 19 | TGroupBox *GroupBox; 20 | TLabel *Label11; 21 | TOpenDialog *OpenDialog; 22 | TEdit *FileEdit; 23 | TSpeedButton *SpeedButton2; 24 | TRadioButton *RotationRB1; 25 | TRadioButton *RotationRB2; 26 | TRadioButton *RotationRB3; 27 | TEdit *SizeEdit; 28 | TComboBox *MultCB; 29 | TComboBox *MomentCB; 30 | TEdit *HourEdit; 31 | TLabel *Label1; 32 | TPanel *Panel1; 33 | TRadioButton *RenamingRB0; 34 | TRadioButton *RenamingRB1; 35 | TLabel *Label4; 36 | TEdit *CountEdit; 37 | TEdit *NewNameEdit; 38 | TLabel *HelpLabel; 39 | TUpDown *CountEditUD; 40 | TUpDown *HourEditUD; 41 | TUpDown *SizeEditUD; 42 | TLabel *Label2; 43 | void __fastcall SpeedButton2Click(TObject *Sender); 44 | void __fastcall Change(TObject *Sender); 45 | void __fastcall HelpLabelClick(TObject *Sender); 46 | private: // User declarations 47 | TForm * GetForm(void); 48 | bool bEnableValuesChange; 49 | String DefaultRecipient; 50 | public: 51 | TNotifyEvent OnValuesChange; 52 | public: // User declarations 53 | __fastcall TFileFr(TComponent* Owner); 54 | void ToDialog(TStorageFile * p); 55 | void FromDialog(TStorageFile * p); 56 | void SetDefaultFile(bool b); 57 | void RotationEnable(void); 58 | }; 59 | //--------------------------------------------------------------------------- 60 | extern PACKAGE TFileFr *FileFr; 61 | //--------------------------------------------------------------------------- 62 | #endif 63 | -------------------------------------------------------------------------------- /source/formhl.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "messageform.h" 6 | #include "messhl.h" 7 | #include "saveini.h" // TSaveParamsINI 8 | #include "cfg.h" // program config 9 | #include "gr.h" // 3D 10 | #include "formhl.h" 11 | //--------------------------------------------------------------------------- 12 | #pragma package(smart_init) 13 | #pragma link "messmatchframe" 14 | #pragma link "messstyleframe" 15 | #pragma resource "*.dfm" 16 | 17 | extern TSaveParamsINI * AppParams; 18 | extern String HighlightFile; 19 | extern TMainCfg MainCfg; 20 | int THighlightForm::LastRuleIndex = 0; 21 | THighlightForm * HighlightForm; 22 | //--------------------------------------------------------------------------- 23 | __fastcall THighlightForm::THighlightForm(TComponent* Owner, int CurrentProfile, 24 | int dummy) : TForm(Owner) 25 | { 26 | localHPL = new THighlightProfileList; 27 | localHPL->Load(HighlightFile); 28 | 29 | TMessHighlightList * p; 30 | 31 | ProfileCB->Items->BeginUpdate(); 32 | for(int i=0; iCount; i++) 33 | { 34 | p = (TMessHighlightList *)localHPL->Items[i]; 35 | ProfileCB->Items->Add(p->ProfileName); 36 | } 37 | ProfileCB->ItemIndex = CurrentProfile; 38 | ProfileCB->Items->EndUpdate(); 39 | 40 | FillRuleList(LastRuleIndex); 41 | 42 | *AppParams >> this; 43 | DrawGrid_LivingColumns = new TStringGridLivingColumns((TStringGrid *)DrawGrid); 44 | 45 | MessMatchFr->OnValuesChange = OnFrameValuesChange; 46 | MessStyleFr->OnValuesChange = OnFrameValuesChange; 47 | } 48 | //--------------------------------------------------------------------------- 49 | void __fastcall THighlightForm::FormDestroy(TObject *Sender) 50 | { 51 | *AppParams << this; 52 | if( DrawGrid->Row > 0 ) 53 | LastRuleIndex = DrawGrid->Row - 1; 54 | delete DrawGrid_LivingColumns; 55 | delete localHPL; 56 | localHPL = NULL; 57 | } 58 | //--------------------------------------------------------------------------- 59 | void __fastcall THighlightForm::ProfileCBSelect(TObject *Sender) 60 | { 61 | FillRuleList(0); 62 | } 63 | //--------------------------------------------------------------------------- 64 | void __fastcall THighlightForm::FillRuleList(int SelectedIndex) 65 | { 66 | localHPL->CurrentProfile = ProfileCB->ItemIndex; 67 | TMessHighlightList * p = localHPL->GetCurrentProfile(); 68 | if( p ) 69 | { 70 | DrawGrid->RowCount = 1 + p->Count; 71 | if( DrawGrid->RowCount > 1 ) 72 | { 73 | DrawGrid->FixedRows = 1; 74 | if( DrawGrid->RowCount > SelectedIndex + 1 ) 75 | DrawGrid->Row = SelectedIndex + 1; 76 | else if( DrawGrid->RowCount >= 2 ) 77 | DrawGrid->Row = 1; 78 | } 79 | DrawGrid->OnClick(this); 80 | DrawGrid->Invalidate(); 81 | } 82 | } 83 | //--------------------------------------------------------------------------- 84 | void __fastcall THighlightForm::OKButtonClick(TObject *Sender) 85 | { 86 | localHPL->Save(HighlightFile); 87 | ModalResult = mrOk; 88 | } 89 | //--------------------------------------------------------------------------- 90 | void __fastcall THighlightForm::AddButtonClick(TObject *Sender) 91 | { 92 | TMessHighlightList * p = localHPL->GetCurrentProfile(); 93 | if( p ) 94 | { 95 | TMessHighlight * mh = new TMessHighlight; 96 | p->Add(mh); 97 | DrawGrid->RowCount = 1 + p->Count; 98 | DrawGrid->Row = DrawGrid->RowCount - 1; 99 | DrawGrid->FixedRows = 1; 100 | } 101 | } 102 | //--------------------------------------------------------------------------- 103 | void __fastcall THighlightForm::DelButtonClick(TObject *Sender) 104 | { 105 | if( DrawGrid->RowCount < 2 ) 106 | return; 107 | int ARow = DrawGrid->Row - 1; 108 | TMessHighlightList * p = localHPL->GetCurrentProfile(); 109 | if( p ) 110 | { 111 | p->Del(ARow); 112 | DrawGrid->RowCount = 1 + p->Count; 113 | DrawGrid->OnClick(this); 114 | } 115 | } 116 | //--------------------------------------------------------------------------- 117 | void __fastcall THighlightForm::UpButtonClick(TObject *Sender) 118 | { 119 | if( DrawGrid->RowCount < 3 ) 120 | return; 121 | if( DrawGrid->Row == 1 ) 122 | return; 123 | int ARow = DrawGrid->Row - 1; 124 | TMessHighlightList * p = localHPL->GetCurrentProfile(); 125 | if( p ) 126 | { 127 | p->Exchange(ARow, ARow - 1); 128 | DrawGrid->Row = DrawGrid->Row - 1; 129 | DrawGrid->Invalidate(); 130 | } 131 | } 132 | //--------------------------------------------------------------------------- 133 | void __fastcall THighlightForm::DownButtonClick(TObject *Sender) 134 | { 135 | if( DrawGrid->RowCount < 3 ) 136 | return; 137 | if( DrawGrid->Row == DrawGrid->RowCount-1 ) 138 | return; 139 | int ARow = DrawGrid->Row - 1; 140 | TMessHighlightList * p = localHPL->GetCurrentProfile(); 141 | if( p ) 142 | { 143 | p->Exchange(ARow, ARow + 1); 144 | DrawGrid->Row = DrawGrid->Row + 1; 145 | DrawGrid->Invalidate(); 146 | } 147 | } 148 | //--------------------------------------------------------------------------- 149 | void __fastcall THighlightForm::DrawGridDrawCell(TObject *Sender, int ACol, 150 | int ARow, TRect &Rect, TGridDrawState State) 151 | { 152 | TCanvas * c = ((TStringGrid *)Sender)->Canvas; 153 | String s; 154 | 155 | if( ARow==0 ) // Grid title 156 | { 157 | switch( ACol ) 158 | { 159 | case 0: s = " Active"; break; 160 | case 1: s = " Match & Style preview"; break; 161 | } 162 | 163 | if( MainCfg.b3D ) 164 | { 165 | FillVolume(c, Rect, c->Brush->Color); 166 | c->Brush->Style = bsClear; 167 | } 168 | 169 | int x = Rect.Left + 2; 170 | int y = Rect.Top + ((Rect.Bottom - Rect.Top - c->TextHeight(s)) / 2); 171 | c->TextRect(Rect, x, y, s); 172 | } 173 | else 174 | { 175 | TMessHighlightList * p = localHPL->GetCurrentProfile(); 176 | if( p ) 177 | { 178 | TMessHighlight * mh = p->Get(ARow-1); 179 | if( mh ) 180 | { 181 | if( ACol == 0 ) 182 | { 183 | ImageList->Draw(c, 184 | Rect.Left + ((Rect.Right - Rect.Left - ImageList->Width) / 2), 185 | Rect.Top + ((Rect.Bottom - Rect.Top - ImageList->Height) / 2), 186 | mh->bEnable ? 0 : 1, true); 187 | } 188 | else // ACol == 1 189 | { 190 | s = String(" ") + mh->Match.GetDescription(); 191 | /* 192 | if( State.Contains(gdSelected) ) // Selected line 193 | { 194 | } 195 | else 196 | { 197 | */ 198 | c->Brush->Color = mh->Style.BackgroundColor; 199 | c->Font->Color = mh->Style.TextColor; 200 | //} 201 | 202 | mh->Style.SetFontStyle(c->Font); 203 | 204 | if( MainCfg.b3D ) 205 | { 206 | FillVolume(c, Rect, c->Brush->Color); 207 | c->Brush->Style = bsClear; 208 | } 209 | 210 | int x = Rect.Left + 2; 211 | int y = Rect.Top + ((Rect.Bottom - Rect.Top - c->TextHeight(s)) / 2); 212 | c->TextRect(Rect, x, y, s); 213 | } 214 | } 215 | } 216 | } 217 | 218 | } 219 | //--------------------------------------------------------------------------- 220 | // show params of current rule 221 | void __fastcall THighlightForm::DrawGridClick(TObject *Sender) 222 | { 223 | if( DrawGrid->Row < 1 ) 224 | { 225 | ActiveCB->Visible = false; 226 | MessMatchFr->Visible = false; 227 | MessStyleFr->Visible = false; 228 | return; 229 | } 230 | else 231 | { 232 | ActiveCB->Visible = true; 233 | MessMatchFr->Visible = true; 234 | MessStyleFr->Visible = true; 235 | } 236 | 237 | int ARow = DrawGrid->Row - 1; 238 | TMessHighlightList * p = localHPL->GetCurrentProfile(); 239 | if( p ) 240 | { 241 | TMessHighlight * mh = p->Get(ARow); 242 | if( mh ) 243 | { 244 | ActiveCB->OnClick = NULL; 245 | ActiveCB->Checked = mh->bEnable; 246 | ActiveCB->OnClick = OnFrameValuesChange; 247 | 248 | MessMatchFr->ToDialog(&mh->Match); 249 | MessStyleFr->ToDialog(&mh->Style); 250 | } 251 | } 252 | } 253 | //--------------------------------------------------------------------------- 254 | void __fastcall THighlightForm::DrawGridDblClick(TObject *Sender) 255 | { 256 | ActiveCB->Checked = ! ActiveCB->Checked; 257 | } 258 | //--------------------------------------------------------------------------- 259 | void __fastcall THighlightForm::OnFrameValuesChange(TObject *Sender) 260 | { 261 | if( DrawGrid->Row < 1 ) 262 | return; 263 | int ARow = DrawGrid->Row - 1; 264 | TMessHighlightList * p = localHPL->GetCurrentProfile(); 265 | if( p ) 266 | { 267 | TMessHighlight * mh = p->Get(ARow); 268 | if( mh ) 269 | { 270 | mh->bEnable = ActiveCB->Checked; 271 | MessMatchFr->FromDialog(&mh->Match); 272 | MessStyleFr->FromDialog(&mh->Style); 273 | DrawGrid->Invalidate(); 274 | } 275 | } 276 | } 277 | //--------------------------------------------------------------------------- 278 | void __fastcall THighlightForm::HelpButtonClick(TObject *Sender) 279 | { 280 | ReportMess2( 281 | "- Rules in the list are processed from top to bottom\n" 282 | "- Match rule \"Text contains\" searches for text in all fields of the message: " 283 | "Time, IP, Host, Facility, Priority, Tag, Message" 284 | ); 285 | } 286 | //--------------------------------------------------------------------------- 287 | 288 | -------------------------------------------------------------------------------- /source/formhl.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef formhlH 3 | #define formhlH 4 | //--------------------------------------------------------------------------- 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "messmatchframe.h" 13 | #include 14 | #include "messstyleframe.h" 15 | #include "gridcolumns.h" 16 | 17 | class THighlightProfileList; 18 | //--------------------------------------------------------------------------- 19 | class THighlightForm : public TForm 20 | { 21 | __published: // IDE-managed Components 22 | TGroupBox *GroupBox1; 23 | TComboBox *ProfileCB; 24 | TLabel *Label1; 25 | TGroupBox *GroupBox2; 26 | TGroupBox *OKGroupBox; 27 | TBitBtn *OKButton; 28 | TBitBtn *CancelButton; 29 | TDrawGrid *DrawGrid; 30 | TImageList *ImageList; 31 | TBitBtn *HelpButton; 32 | TSpeedButton *AddButton; 33 | TSpeedButton *DelButton; 34 | TSpeedButton *UpButton; 35 | TSpeedButton *DownButton; 36 | TScrollBox *ScrollBox1; 37 | TCheckBox *ActiveCB; 38 | TMessMatchFr *MessMatchFr; 39 | TMessStyleFr *MessStyleFr; 40 | void __fastcall AddButtonClick(TObject *Sender); 41 | void __fastcall DelButtonClick(TObject *Sender); 42 | void __fastcall FormDestroy(TObject *Sender); 43 | void __fastcall OKButtonClick(TObject *Sender); 44 | void __fastcall DrawGridDrawCell(TObject *Sender, int ACol, int ARow, 45 | TRect &Rect, TGridDrawState State); 46 | void __fastcall DrawGridClick(TObject *Sender); 47 | void __fastcall UpButtonClick(TObject *Sender); 48 | void __fastcall DownButtonClick(TObject *Sender); 49 | void __fastcall OnFrameValuesChange(TObject *Sender); 50 | void __fastcall ProfileCBSelect(TObject *Sender); 51 | void __fastcall DrawGridDblClick(TObject *Sender); 52 | void __fastcall HelpButtonClick(TObject *Sender); 53 | 54 | private: // User declarations 55 | TStringGridLivingColumns * DrawGrid_LivingColumns; 56 | THighlightProfileList * localHPL; 57 | static int LastRuleIndex; 58 | 59 | public: // User declarations 60 | __fastcall THighlightForm(TComponent* Owner, int CurrentProfile, int dummy=0); 61 | void __fastcall FillRuleList(int SelectedIndex); 62 | }; 63 | //--------------------------------------------------------------------------- 64 | extern PACKAGE THighlightForm *HighlightForm; 65 | //--------------------------------------------------------------------------- 66 | #endif 67 | -------------------------------------------------------------------------------- /source/formprocess.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "messageform.h" 6 | #include "messhl.h" 7 | #include "saveini.h" // TSaveParamsINI 8 | #include "formprocess.h" 9 | //--------------------------------------------------------------------------- 10 | #pragma package(smart_init) 11 | #pragma link "messmatchframe" 12 | #pragma link "messprocessframe" 13 | #pragma resource "*.dfm" 14 | 15 | extern TSaveParamsINI * AppParams; 16 | extern String ProcessFile; 17 | int TProcessForm::LastRuleIndex = 0; 18 | TProcessForm * ProcessForm; 19 | //--------------------------------------------------------------------------- 20 | __fastcall TProcessForm::TProcessForm(TComponent* Owner) : TForm(Owner) 21 | { 22 | localPRL = new TMessProcessRuleList; 23 | localPRL->Load(ProcessFile); 24 | 25 | FillRuleList(LastRuleIndex); 26 | 27 | *AppParams >> this >> (TStringGrid *)DrawGrid; 28 | DrawGrid_LivingColumns = new TStringGridLivingColumns((TStringGrid *)DrawGrid); 29 | 30 | MessMatchFr->OnValuesChange = OnFrameValuesChange; 31 | MessProcessFr->OnValuesChange = OnFrameValuesChange; 32 | } 33 | //--------------------------------------------------------------------------- 34 | void __fastcall TProcessForm::FormDestroy(TObject *Sender) 35 | { 36 | *AppParams << this << (TStringGrid *)DrawGrid; 37 | if( DrawGrid->Row > 0 ) 38 | LastRuleIndex = DrawGrid->Row - 1; 39 | delete DrawGrid_LivingColumns; 40 | delete localPRL; 41 | localPRL = NULL; 42 | } 43 | //--------------------------------------------------------------------------- 44 | void __fastcall TProcessForm::FillRuleList(int SelectedIndex) 45 | { 46 | DrawGrid->RowCount = 1 + localPRL->Count; 47 | if( DrawGrid->RowCount > 1 ) 48 | { 49 | DrawGrid->FixedRows = 1; 50 | if( DrawGrid->RowCount > SelectedIndex + 1 ) 51 | DrawGrid->Row = SelectedIndex + 1; 52 | else if( DrawGrid->RowCount >= 2 ) 53 | DrawGrid->Row = 1; 54 | } 55 | DrawGrid->OnClick(this); 56 | DrawGrid->Invalidate(); 57 | } 58 | //--------------------------------------------------------------------------- 59 | void __fastcall TProcessForm::OKButtonClick(TObject *Sender) 60 | { 61 | localPRL->Save(ProcessFile); 62 | ModalResult = mrOk; 63 | } 64 | //--------------------------------------------------------------------------- 65 | void __fastcall TProcessForm::AddButtonClick(TObject *Sender) 66 | { 67 | TMessProcessRule * p = new TMessProcessRule; 68 | localPRL->Add(p); 69 | DrawGrid->RowCount = 1 + localPRL->Count; 70 | DrawGrid->Row = DrawGrid->RowCount - 1; 71 | DrawGrid->FixedRows = 1; 72 | } 73 | //--------------------------------------------------------------------------- 74 | void __fastcall TProcessForm::DelButtonClick(TObject *Sender) 75 | { 76 | if( DrawGrid->RowCount < 2 ) 77 | return; 78 | int ARow = DrawGrid->Row - 1; 79 | localPRL->Del(ARow); 80 | DrawGrid->RowCount = 1 + localPRL->Count; 81 | DrawGrid->OnClick(this); 82 | } 83 | //--------------------------------------------------------------------------- 84 | void __fastcall TProcessForm::UpButtonClick(TObject *Sender) 85 | { 86 | if( DrawGrid->RowCount < 3 ) 87 | return; 88 | if( DrawGrid->Row == 1 ) 89 | return; 90 | int ARow = DrawGrid->Row - 1; 91 | localPRL->Exchange(ARow, ARow - 1); 92 | DrawGrid->Row = DrawGrid->Row - 1; 93 | DrawGrid->Invalidate(); 94 | } 95 | //--------------------------------------------------------------------------- 96 | void __fastcall TProcessForm::DownButtonClick(TObject *Sender) 97 | { 98 | if( DrawGrid->RowCount < 3 ) 99 | return; 100 | if( DrawGrid->Row == DrawGrid->RowCount-1 ) 101 | return; 102 | int ARow = DrawGrid->Row - 1; 103 | localPRL->Exchange(ARow, ARow + 1); 104 | DrawGrid->Row = DrawGrid->Row + 1; 105 | DrawGrid->Invalidate(); 106 | } 107 | //--------------------------------------------------------------------------- 108 | void __fastcall TProcessForm::DrawGridDrawCell(TObject *Sender, int ACol, 109 | int ARow, TRect &Rect, TGridDrawState State) 110 | { 111 | TCanvas * c = ((TStringGrid *)Sender)->Canvas; 112 | String s; 113 | 114 | if( ARow==0 ) // Grid title 115 | { 116 | switch( ACol ) 117 | { 118 | case 0: s = " Active"; break; 119 | case 1: s = " Match"; break; 120 | case 2: s = " Action"; break; 121 | } 122 | int x = Rect.Left + 2; 123 | int y = Rect.Top + ((Rect.Bottom - Rect.Top - c->TextHeight(s)) / 2); 124 | c->TextRect(Rect, x, y, s); 125 | } 126 | else 127 | { 128 | TMessProcessRule * p = localPRL->Get(ARow-1); 129 | if( p ) 130 | { 131 | if( ACol == 0 ) 132 | { 133 | ImageList->Draw(c, 134 | Rect.Left + ((Rect.Right - Rect.Left - ImageList->Width) / 2), 135 | Rect.Top + ((Rect.Bottom - Rect.Top - ImageList->Height) / 2), 136 | p->bEnable ? 0 : 1, true); 137 | } 138 | else if( ACol == 1 ) 139 | { 140 | s = String(" ") + p->Match.GetDescription(); 141 | 142 | int x = Rect.Left + 2; 143 | int y = Rect.Top + ((Rect.Bottom - Rect.Top - c->TextHeight(s)) / 2); 144 | c->TextRect(Rect, x, y, s); 145 | } 146 | else // ACol == 2 147 | { 148 | s = String(" ") + p->Process.GetDescription(); 149 | //if( State.Contains(gdSelected) ) // Selected line 150 | //{ 151 | //} 152 | //else 153 | //{ 154 | //c->Brush->Color = p->Style.BackgroundColor; 155 | //c->Font->Color = p->Style.TextColor; 156 | //} 157 | 158 | //p->Style.SetFontStyle(c->Font); 159 | 160 | int x = Rect.Left + 2; 161 | int y = Rect.Top + ((Rect.Bottom - Rect.Top - c->TextHeight(s)) / 2); 162 | c->TextRect(Rect, x, y, s); 163 | } 164 | } 165 | } 166 | } 167 | //--------------------------------------------------------------------------- 168 | // show params of current rule 169 | void __fastcall TProcessForm::DrawGridClick(TObject *Sender) 170 | { 171 | if( DrawGrid->Row < 1 ) 172 | { 173 | ActiveCB->Visible = false; 174 | MessMatchFr->Visible = false; 175 | MessProcessFr->Visible = false; 176 | return; 177 | } 178 | else 179 | { 180 | ActiveCB->Visible = true; 181 | MessMatchFr->Visible = true; 182 | MessProcessFr->Visible = true; 183 | } 184 | 185 | int ARow = DrawGrid->Row - 1; 186 | TMessProcessRule * p = localPRL->Get(ARow); 187 | if( p ) 188 | { 189 | ActiveCB->OnClick = NULL; 190 | ActiveCB->Checked = p->bEnable; 191 | ActiveCB->OnClick = OnFrameValuesChange; 192 | 193 | MessMatchFr->ToDialog(&p->Match); 194 | MessProcessFr->ToDialog(&p->Process); 195 | } 196 | } 197 | //--------------------------------------------------------------------------- 198 | void __fastcall TProcessForm::DrawGridDblClick(TObject *Sender) 199 | { 200 | ActiveCB->Checked = ! ActiveCB->Checked; 201 | } 202 | //--------------------------------------------------------------------------- 203 | void __fastcall TProcessForm::OnFrameValuesChange(TObject *Sender) 204 | { 205 | if( DrawGrid->Row < 1 ) 206 | return; 207 | int ARow = DrawGrid->Row - 1; 208 | TMessProcessRule * p = localPRL->Get(ARow); 209 | if( p ) 210 | { 211 | p->bEnable = ActiveCB->Checked; 212 | MessMatchFr->FromDialog(&p->Match); 213 | MessProcessFr->FromDialog(&p->Process); 214 | DrawGrid->Invalidate(); 215 | } 216 | } 217 | //--------------------------------------------------------------------------- 218 | void __fastcall TProcessForm::HelpButtonClick(TObject *Sender) 219 | { 220 | ReportMess2( 221 | "Each message always goes all the actions in the list\n" 222 | ); 223 | } 224 | //--------------------------------------------------------------------------- 225 | 226 | -------------------------------------------------------------------------------- /source/formprocess.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef formprocessH 3 | #define formprocessH 4 | //--------------------------------------------------------------------------- 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "gridcolumns.h" 14 | #include "messmatchframe.h" 15 | #include "messprocessframe.h" 16 | 17 | class THighlightProfileList; 18 | //--------------------------------------------------------------------------- 19 | class TProcessForm : public TForm 20 | { 21 | __published: // IDE-managed Components 22 | TGroupBox *GroupBox2; 23 | TGroupBox *GroupBox4; 24 | TBitBtn *OKButton; 25 | TBitBtn *CancelButton; 26 | TDrawGrid *DrawGrid; 27 | TImageList *ImageList; 28 | TBitBtn *HelpButton; 29 | TSpeedButton *AddButton; 30 | TSpeedButton *DelButton; 31 | TSpeedButton *UpButton; 32 | TSpeedButton *DownButton; 33 | TScrollBox *ScrollBox1; 34 | TCheckBox *ActiveCB; 35 | TMessMatchFr *MessMatchFr; 36 | TMessProcessFr *MessProcessFr; 37 | void __fastcall AddButtonClick(TObject *Sender); 38 | void __fastcall DelButtonClick(TObject *Sender); 39 | void __fastcall FormDestroy(TObject *Sender); 40 | void __fastcall OKButtonClick(TObject *Sender); 41 | void __fastcall DrawGridDrawCell(TObject *Sender, int ACol, int ARow, 42 | TRect &Rect, TGridDrawState State); 43 | void __fastcall DrawGridClick(TObject *Sender); 44 | void __fastcall UpButtonClick(TObject *Sender); 45 | void __fastcall DownButtonClick(TObject *Sender); 46 | void __fastcall OnFrameValuesChange(TObject *Sender); 47 | void __fastcall DrawGridDblClick(TObject *Sender); 48 | void __fastcall HelpButtonClick(TObject *Sender); 49 | 50 | private: // User declarations 51 | TStringGridLivingColumns * DrawGrid_LivingColumns; 52 | TMessProcessRuleList * localPRL; 53 | static int LastRuleIndex; 54 | 55 | public: // User declarations 56 | __fastcall TProcessForm(TComponent* Owner); 57 | void __fastcall FillRuleList(int SelectedIndex); 58 | }; 59 | //--------------------------------------------------------------------------- 60 | extern PACKAGE TProcessForm * ProcessForm; 61 | //--------------------------------------------------------------------------- 62 | #endif 63 | -------------------------------------------------------------------------------- /source/main.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef mainH 3 | #define mainH 4 | //--------------------------------------------------------------------------- 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include // Change TStringGrid columns width 18 | #include "gridcolumns.h" 19 | 20 | //--------------------------------------------------------------------------- 21 | // override standart component class for preventing flicker 22 | class TDrawGrid2 : public TDrawGrid 23 | { 24 | public: 25 | bool bAllowUpdate; 26 | 27 | public: 28 | #pragma option push -w-inl 29 | __fastcall virtual TDrawGrid2(Classes::TComponent* AOwner); 30 | #pragma option pop 31 | virtual void __fastcall Update(void); 32 | }; 33 | //--------------------------------------------------------------------------- 34 | class TMainForm : public TForm 35 | { 36 | __published: // IDE-managed Components 37 | TTimer *Timer; 38 | TGroupBox *GroupBox1; 39 | TGroupBox *GroupBox2; 40 | TPopupMenu *ClipboardPM; 41 | TMenuItem *mCopyToClipboard; 42 | TLabel *Label2; 43 | TFontDialog *FontDialog; 44 | TImageList *ImageList; 45 | TStatusBar *StatusBar; 46 | TTimer *NetTimer; 47 | TMenuItem *N1; 48 | TImageList *TrayImageList; 49 | TPopupMenu *TrayPopupMenu; 50 | TMenuItem *mOpenMainForm; 51 | TMenuItem *N_1; 52 | TMenuItem *mExit; 53 | TTrayIcon *TrayIcon; 54 | TMenuItem *N2; 55 | TOpenDialog *OpenDialog; 56 | TMenuItem *N3; 57 | TImageList *ImageList32; 58 | TActionList *ActionList; 59 | TAction *aSetup; 60 | TMenuItem *Setup1; 61 | TAction *aFont; 62 | TMenuItem *Font1; 63 | TAction *aAbout; 64 | TMenuItem *About1; 65 | TAction *aViewFile; 66 | TMenuItem *Viewfile1; 67 | TAction *aMoreLines; 68 | TMenuItem *Readpreviouslines1; 69 | TAction *mOpenFilesLoc; 70 | TMenuItem *Openfileslocation1; 71 | TAction *aClear; 72 | TMenuItem *Clearscreen1; 73 | TAction *aExit; 74 | TMenuItem *erminate1; 75 | TToolBar *ToolBar; 76 | TToolButton *ToolButton1; 77 | TToolButton *ToolButton2; 78 | TToolButton *ToolButton3; 79 | TToolButton *ToolButton4; 80 | TToolButton *ToolButton5; 81 | TToolButton *ToolButton6; 82 | TToolButton *ToolButton8; 83 | TToolButton *ToolButton9; 84 | TToolButton *ToolButton10; 85 | TAction *aGotoNewLine; 86 | TMenuItem *Gotonewline1; 87 | TToolButton *ToolButton11; 88 | TAction *aCancelViewFile; 89 | TToolButton *ToolButton12; 90 | TMenuItem *Cancelviewfile1; 91 | TAction *aRunIE; 92 | TMenuItem *RunInternetExplorer1; 93 | TAction *aPing; 94 | TMenuItem *Ping1; 95 | TAction *aFilterByIP; 96 | TAction *aFilterByHost; 97 | TMenuItem *N4; 98 | TMenuItem *FilteringbyIP1; 99 | TMenuItem *FilteringbyHost1; 100 | TAction *aHighlightingSetup; 101 | TToolButton *ToolButton13; 102 | TPopupMenu *HighlightingProfilesPM; 103 | TMenuItem *HighlightingSetup1; 104 | TAction *aShowAlarms; 105 | TMenuItem *Showalarmswindow1; 106 | TAction *aProcessSetup; 107 | TToolButton *ToolButton14; 108 | TMenuItem *Messageprocessingsetup1; 109 | TComboBox *SelectFileCB; 110 | TLabel *MessMatchLabel; 111 | TSpeedButton *FilterButton; 112 | TSpeedButton *ClearFilterButton2; 113 | TLabel *Label1; 114 | TLabel *ViewFileInfoLabel; 115 | TAction *aDisplayFilter; 116 | TMenuItem *Displayfilter1; 117 | TAction *aFilterByTag; 118 | TMenuItem *FilteringbyTag1; 119 | TAction *aHideBars; 120 | TMenuItem *Hidetoolbars1; 121 | TAction *aRotatePrev; 122 | TAction *aRotateNext; 123 | TMenuItem *Viewpreviouspart1; 124 | TMenuItem *Viewnextpart1; 125 | TToolButton *ToolButton7; 126 | TToolButton *ToolButton15; 127 | void __fastcall TimerTimer(TObject *Sender); 128 | void __fastcall mCopyToClipboardClick(TObject *Sender); 129 | void __fastcall LogSGDblClick(TObject *Sender); 130 | void __fastcall LogSGDrawCell(TObject *Sender, int ACol, int ARow, 131 | TRect &Rect, TGridDrawState State); 132 | void __fastcall FormDestroy(TObject *Sender); 133 | void __fastcall FormCreate(TObject *Sender); 134 | void __fastcall NetTimerTimer(TObject *Sender); 135 | void __fastcall mOpenMainFormClick(TObject *Sender); 136 | void __fastcall FormClose(TObject *Sender, TCloseAction &Action); 137 | void __fastcall aSetupExecute(TObject *Sender); 138 | void __fastcall aFontExecute(TObject *Sender); 139 | void __fastcall aAboutExecute(TObject *Sender); 140 | void __fastcall aViewFileExecute(TObject *Sender); 141 | void __fastcall aMoreLinesExecute(TObject *Sender); 142 | void __fastcall mOpenFilesLocExecute(TObject *Sender); 143 | void __fastcall aClearExecute(TObject *Sender); 144 | void __fastcall aExitExecute(TObject *Sender); 145 | void __fastcall aGotoNewLineExecute(TObject *Sender); 146 | void __fastcall aCancelViewFileExecute(TObject *Sender); 147 | void __fastcall aRunIEExecute(TObject *Sender); 148 | void __fastcall aPingExecute(TObject *Sender); 149 | void __fastcall aFilterByIPExecute(TObject *Sender); 150 | void __fastcall aFilterByHostExecute(TObject *Sender); 151 | void __fastcall aHighlightingSetupExecute(TObject *Sender); 152 | void __fastcall aShowAlarmsExecute(TObject *Sender); 153 | void __fastcall aProcessSetupExecute(TObject *Sender); 154 | void __fastcall SelectFileCBSelect(TObject *Sender); 155 | void __fastcall ClearFilterButton2Click(TObject *Sender); 156 | void __fastcall aDisplayFilterExecute(TObject *Sender); 157 | void __fastcall aFilterByTagExecute(TObject *Sender); 158 | void __fastcall aHideBarsExecute(TObject *Sender); 159 | void __fastcall aRotatePrevExecute(TObject *Sender); 160 | void __fastcall aRotateNextExecute(TObject *Sender); 161 | 162 | public: 163 | // Main grid 164 | TDrawGrid2 * LogSG; 165 | 166 | private: // User declarations 167 | // Change LogSG columns width 168 | TStringGridLivingColumns * LogSG_LivingColumns; 169 | 170 | TList * MessList; // List of messages to dislpay 171 | 172 | BYTE * FileReadBuffer; // buffer for file reading 173 | TFile in; // current viewed syslog file 174 | DWORD SizeToRead; // size to read from syslog file 175 | 176 | int FileNumber; // Current viewed file number (TStorageFileList::GetByNumber) 177 | int FileRotationNumber; // Current viewed file rotation number 178 | String fFile; // Current viewed file name 179 | bool bLive; // Live view ? (yes by default) 180 | TMessMatch MessMatch; // Display filter 181 | 182 | ULONGLONG FileSize; // Size of fFile when open 183 | DWORD ReadedSize; // Bytes read from fFile 184 | int TotalLines; // Total lines readed from file 185 | 186 | DWORD LastBalloonShowTime; 187 | 188 | // View file mode 189 | bool ViewFileMode; 190 | String ViewFileName; 191 | String TmpViewFileName; 192 | 193 | bool bFirstTimerTick; 194 | 195 | private: 196 | // Clear string grig 197 | // Set working file name to f 198 | // Read maxsize bytes from the end of file f and show in the string grid 199 | void __fastcall SetFile(String f); 200 | // Rotation 201 | friend void __fastcall PreRotateFile(String FileName); 202 | friend void __fastcall PostRotateFile(void); 203 | // Read protocol text file again 204 | // Called when filters changes 205 | void __fastcall RedrawProto(void); 206 | // Positioning to the new line in the text file 207 | void __fastcall GotoNewLine(void); 208 | // Clear string grig 209 | void __fastcall Clear(void); 210 | // Read the tail of the syslog file 211 | void __fastcall Read(bool bAllowAddVisibleLines); 212 | // Print captions of string grig and view file info 213 | void __fastcall UpdateDislpayInfo(void); 214 | // Set lines height when change font 215 | void __fastcall SetLinesHeight(void); 216 | // Initialization code 217 | // Called once when program start 218 | void __fastcall Init(bool _bLive); 219 | // Get file to view by number 220 | String GetFileName(int number); 221 | // apply MessMatch 222 | void ApplyFilter(void); 223 | 224 | public: // User declarations 225 | __fastcall TMainForm(TComponent* Owner); 226 | void __fastcall CreateGrid(void); 227 | 228 | // Change icons and hint (State: 0-ok 1-warning 2-error) 229 | void __fastcall TrayChangeIcon(int State); 230 | void __fastcall SetViewFileMode(bool b); 231 | 232 | // Get display message by index 233 | TSyslogMessage * __fastcall GetMessageByIndex(int i); 234 | 235 | void __fastcall FillProfilePopupMenu(void); 236 | void __fastcall ChangeProfileClick(TObject *Sender); 237 | 238 | void __fastcall UpdateRotationViewControl(void); 239 | }; 240 | //--------------------------------------------------------------------------- 241 | extern PACKAGE TMainForm * MainForm; 242 | 243 | void AlarmShow(String s); 244 | 245 | bool WriteToLogRawMessage(char * p); 246 | // Write message to errors.txt & Print in the status bar 247 | bool WriteToLogError(String fmt, ...); 248 | 249 | // where = CSIDL_STARTUP 250 | void __fastcall CreateShortcut(int where); 251 | void __fastcall DeleteShortcut(int where); 252 | bool __fastcall IsShortcutExist(int where); 253 | //--------------------------------------------------------------------------- 254 | #endif 255 | 256 | -------------------------------------------------------------------------------- /source/matchform.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "matchform.h" 6 | //--------------------------------------------------------------------------- 7 | #pragma package(smart_init) 8 | #pragma link "messmatchframe" 9 | #pragma resource "*.dfm" 10 | TFilterForm *FilterForm; 11 | //--------------------------------------------------------------------------- 12 | __fastcall TFilterForm::TFilterForm(TComponent* Owner) 13 | : TForm(Owner) 14 | { 15 | } 16 | //--------------------------------------------------------------------------- 17 | -------------------------------------------------------------------------------- /source/matchform.dfm: -------------------------------------------------------------------------------- 1 | object FilterForm: TFilterForm 2 | Left = 0 3 | Top = 0 4 | BorderStyle = bsDialog 5 | Caption = 'Message Match' 6 | ClientHeight = 397 7 | ClientWidth = 383 8 | Color = clBtnFace 9 | Font.Charset = DEFAULT_CHARSET 10 | Font.Color = clWindowText 11 | Font.Height = -11 12 | Font.Name = 'Tahoma' 13 | Font.Style = [] 14 | OldCreateOrder = False 15 | Position = poOwnerFormCenter 16 | DesignSize = ( 17 | 383 18 | 397) 19 | PixelsPerInch = 96 20 | TextHeight = 13 21 | inline MessMatchFr: TMessMatchFr 22 | Left = 8 23 | Top = 8 24 | Width = 366 25 | Height = 340 26 | TabOrder = 0 27 | ExplicitLeft = 8 28 | ExplicitTop = 8 29 | inherited GroupBox1: TGroupBox 30 | ExplicitHeight = 340 31 | end 32 | end 33 | object OKButton: TBitBtn 34 | Left = 59 35 | Top = 361 36 | Width = 113 37 | Height = 28 38 | Anchors = [akBottom] 39 | Caption = 'OK' 40 | Default = True 41 | ModalResult = 1 42 | TabOrder = 1 43 | Glyph.Data = { 44 | 36030000424D3603000000000000360000002800000010000000100000000100 45 | 18000000000000030000C40E0000C40E00000000000000000000FFFFFFFFFFFF 46 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 47 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 48 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 49 | FFFFFFFFFFFFFFFFFFB8D2B7357F33C8DCC7FFFFFFFFFFFFFFFFFFFFFFFFFFFF 50 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB9D8B7398E332BAE2041 51 | 963CD7E9D6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 52 | FFFFFFBADCB73C9B3333C32524CD132BBB1D4DA445E5F2E4FFFFFFFFFFFFFFFF 53 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBBDDB73D9F334ACC3A29C31839CC2828 54 | C21731B1235AAD51F0F8EFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBBDFB7 55 | 3EA43363DA5333BC2255D1453EA43334B6252CB81B36AC286AB861F7FBF7FFFF 56 | FFFFFFFFFFFFFFFFFFFFFFFFFF3FA83370E65F59D0486BE15A3FA83398D09243 57 | AB373AB62932B2213BAB2D7BC373FDFEFDFFFFFFFFFFFFFFFFFFFFFFFFBCE1B7 58 | 41AC3374EA6341AC33BCE1B7FFFFFFB8E0B340AE3340B72F38AF2740AE318CCD 59 | 84FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBCE3B741AF33BCE3B7FFFFFFFFFFFFFF 60 | FFFF9DD69645B73758CF4756CD4545B536A3D99CFFFFFFFFFFFFFFFFFFFFFFFF 61 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFE84CD7A4DC13D61D8505FD6 62 | 4F46B737B9E3B3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 63 | FFFFFFFFFFF9FDF96DC66156CC466BE25A72E96243B533FFFFFFFFFFFFFFFFFF 64 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0F9EF5DC24F77EE 65 | 6643B933BDE6B7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 66 | FFFFFFFFFFFFFFFFFFFFFFE3F5E044BB33BDE7B7FFFFFFFFFFFFFFFFFFFFFFFF 67 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 68 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 69 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF} 70 | end 71 | object CancelButton: TBitBtn 72 | Left = 205 73 | Top = 361 74 | Width = 113 75 | Height = 28 76 | Anchors = [akBottom] 77 | Cancel = True 78 | Caption = 'Cancel' 79 | ModalResult = 2 80 | TabOrder = 2 81 | Glyph.Data = { 82 | 36030000424D3603000000000000360000002800000010000000100000000100 83 | 18000000000000030000C40E0000C40E00000000000000000000FFFFFFFFFFFF 84 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 85 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 86 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 87 | FFFFFFB7B7D233337FB7B7D2FFFFFFFFFFFFFFFFFFFFFFFFB7B7D233337FB7B7 88 | D2FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB7B7D833338E1111D833338EB7B7D8FF 89 | FFFFFFFFFFB7B7D833338E1111D833338EB7B7D8FFFFFFFFFFFFFFFFFFFFFFFF 90 | 33339B1111D01111D01111D033339BB7B7DCB7B7DC33339B1111D01111D01111 91 | D033339BFFFFFFFFFFFFFFFFFFFFFFFFB7B7DD33339F1111C41111C41111C433 92 | 339F33339F1111C41111C41111C433339FB7B7DDFFFFFFFFFFFFFFFFFFFFFFFF 93 | FFFFFFB7B7DF3333A41111B81111B81111B81111B81111B81111B83333A4B7B7 94 | DFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB7B7E03333A81515AF11 95 | 11AC1111AC1111AC3333A8B7B7E0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 96 | FFFFFFFFFFFFB7B7E23333AC2525B41111A21111A21414A53333ACB7B7E2FFFF 97 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB7B7E33333AF5353DB2E2EB73D 98 | 3DC63131BA15159F1E1EA83333AFB7B7E3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 99 | B7B7E43333B36767EF3636BE5E5EE63333B33333B34F4FD73636BE4545CD3333 100 | B3B7B7E4FFFFFFFFFFFFFFFFFFFFFFFF3333B57676FE4C4CD47272FA3333B5B7 101 | B7E5B7B7E53333B56262EA4C4CD45C5CE43333B5FFFFFFFFFFFFFFFFFFFFFFFF 102 | B7B7E63333B97777FF3333B9B7B7E6FFFFFFFFFFFFB7B7E63333B97070F83333 103 | B9B7B7E6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB7B7E73333BBB7B7E7FFFFFFFF 104 | FFFFFFFFFFFFFFFFB7B7E73333BBB7B7E7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 105 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 106 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 107 | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF} 108 | end 109 | end 110 | -------------------------------------------------------------------------------- /source/matchform.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | 3 | #ifndef matchformH 4 | #define matchformH 5 | //--------------------------------------------------------------------------- 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "messmatchframe.h" 11 | #include 12 | //--------------------------------------------------------------------------- 13 | class TFilterForm : public TForm 14 | { 15 | __published: // IDE-managed Components 16 | TMessMatchFr *MessMatchFr; 17 | TBitBtn *OKButton; 18 | TBitBtn *CancelButton; 19 | private: // User declarations 20 | public: // User declarations 21 | __fastcall TFilterForm(TComponent* Owner); 22 | }; 23 | //--------------------------------------------------------------------------- 24 | extern PACKAGE TFilterForm *FilterForm; 25 | //--------------------------------------------------------------------------- 26 | #endif 27 | -------------------------------------------------------------------------------- /source/messhl.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "messageform.h" 6 | #include "messhl.h" 7 | 8 | const char * szHighlightsNode = "highlights"; 9 | const char * szProfileNode = "profile"; 10 | const char * szHighlightNode = "highlight"; 11 | const char * szMatchNode = "match"; 12 | const char * szStyleNode = "style"; 13 | //--------------------------------------------------------------------------- 14 | TMessHighlight::TMessHighlight() 15 | { 16 | bEnable = true; 17 | } 18 | //--------------------------------------------------------------------------- 19 | void TMessHighlight::Save(XMLElementEx * p) 20 | { 21 | tinyxml2::XMLDocument * d = p->GetDocument(); 22 | XMLElement * e; 23 | 24 | p->wb("enable", bEnable); 25 | 26 | e = d->NewElement(szMatchNode); 27 | p->InsertEndChild(e); 28 | Match.Save((XMLElementEx *)e); 29 | 30 | e = d->NewElement(szStyleNode); 31 | p->InsertEndChild(e); 32 | Style.Save((XMLElementEx *)e); 33 | } 34 | //--------------------------------------------------------------------------- 35 | bool TMessHighlight::Load(XMLElementEx * p) 36 | { 37 | bool rv = true; 38 | bEnable = p->rb("enable", true); 39 | const XMLElement * e; 40 | e = p->FirstChildElement(szMatchNode); 41 | if( e ) Match.Load((XMLElementEx *)e); 42 | else rv = false; 43 | e = p->FirstChildElement(szStyleNode); 44 | if( e ) Style.Load((XMLElementEx *)e); 45 | else rv = false; 46 | return rv; 47 | } 48 | //--------------------------------------------------------------------------- 49 | //--------------------------------------------------------------------------- 50 | //--------------------------------------------------------------------------- 51 | __fastcall TMessHighlightList::TMessHighlightList() 52 | { 53 | 54 | } 55 | //--------------------------------------------------------------------------- 56 | __fastcall TMessHighlightList::~TMessHighlightList(void) 57 | { 58 | Clear(); 59 | } 60 | //--------------------------------------------------------------------------- 61 | void __fastcall TMessHighlightList::Clear(void) 62 | { 63 | for(int i=0; i= 0 && index < Count ) 76 | return (TMessHighlight *)Items[index]; 77 | return NULL; 78 | } 79 | //--------------------------------------------------------------------------- 80 | void __fastcall TMessHighlightList::Del(int index) 81 | { 82 | if( index >= 0 && index < Count ) 83 | { 84 | delete (TMessHighlight *)Items[index]; 85 | TList::Delete(index); 86 | } 87 | } 88 | //--------------------------------------------------------------------------- 89 | TMessStyle * TMessHighlightList::FindStyleForMessage(TSyslogMessage * p) 90 | { 91 | TMessHighlight * mh; 92 | for(int i=0; ibEnable ) 96 | if( mh->Match.Match(p) ) 97 | return &(mh->Style); 98 | } 99 | return NULL; 100 | } 101 | //--------------------------------------------------------------------------- 102 | void TMessHighlightList::Save(XMLElementEx * p) 103 | { 104 | p->ws("name", ProfileName); 105 | 106 | tinyxml2::XMLDocument * d = p->GetDocument(); 107 | XMLElement * e; 108 | 109 | TMessHighlight * mh; 110 | for(int i=0; iNewElement(szHighlightNode); 114 | p->InsertEndChild(e); 115 | mh->Save((XMLElementEx *)e); 116 | } 117 | } 118 | //--------------------------------------------------------------------------- 119 | void TMessHighlightList::Load(XMLElementEx * p) 120 | { 121 | Clear(); 122 | 123 | ProfileName = p->rs("name"); 124 | 125 | TMessHighlight * mh; 126 | // highlight 127 | for(const XMLElement * hl = p->FirstChildElement(szHighlightNode); 128 | hl; 129 | hl = hl->NextSiblingElement(szHighlightNode)) 130 | { 131 | mh = new TMessHighlight; 132 | mh->Load((XMLElementEx *)hl); 133 | Add(mh); 134 | } 135 | } 136 | //--------------------------------------------------------------------------- 137 | //--------------------------------------------------------------------------- 138 | //--------------------------------------------------------------------------- 139 | __fastcall THighlightProfileList::THighlightProfileList() 140 | { 141 | 142 | } 143 | //--------------------------------------------------------------------------- 144 | __fastcall THighlightProfileList::~THighlightProfileList(void) 145 | { 146 | Clear(); 147 | } 148 | //--------------------------------------------------------------------------- 149 | void __fastcall THighlightProfileList::Clear(void) 150 | { 151 | for(int i=0; i= 0 && CurrentProfile < Count ) 164 | return (TMessHighlightList *)Items[CurrentProfile]; 165 | return NULL; 166 | } 167 | //--------------------------------------------------------------------------- 168 | void THighlightProfileList::Save(String file) 169 | { 170 | tinyxml2::XMLDocument doc; 171 | doc.InsertEndChild( doc.NewDeclaration() ); 172 | 173 | XMLNode * hls = doc.InsertEndChild( doc.NewElement(szHighlightsNode) ); 174 | 175 | XMLElement * e; 176 | TMessHighlightList * mhl; 177 | for(int i=0; iInsertEndChild(e); 182 | mhl->Save((XMLElementEx *)e); 183 | } 184 | 185 | doc.SaveFile(file.c_str()); 186 | } 187 | //--------------------------------------------------------------------------- 188 | void THighlightProfileList::Load(String file) 189 | { 190 | try 191 | { 192 | Clear(); 193 | tinyxml2::XMLDocument doc; 194 | XMLError err = doc.LoadFile(file.c_str()); 195 | if( err == XML_SUCCESS ) 196 | { 197 | XMLElement * hls; 198 | hls = doc.RootElement(); 199 | if( ! hls ) 200 | throw 1; 201 | if( strcmpi(hls->Name(), szHighlightsNode) != 0 ) 202 | throw 1; 203 | 204 | TMessHighlightList * mhl; 205 | // profiles 206 | for(const XMLElement * pr = hls->FirstChildElement(szProfileNode); 207 | pr; 208 | pr = pr->NextSiblingElement(szProfileNode)) 209 | { 210 | mhl = new TMessHighlightList; 211 | mhl->Load((XMLElementEx *)pr); 212 | Add(mhl); 213 | } 214 | } 215 | else 216 | throw 0; 217 | } 218 | catch(int i) 219 | { 220 | if( i==0 ) 221 | ReportError2("Error reading file: \"%s\"", file.c_str()); 222 | else 223 | ReportError2("Incorrect format of file: \"%s\"", file.c_str()); 224 | } 225 | } 226 | //--------------------------------------------------------------------------- 227 | #pragma package(smart_init) 228 | -------------------------------------------------------------------------------- /source/messhl.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef messhlH 3 | #define messhlH 4 | 5 | #include "messmatch.h" 6 | #include "messstyle.h" 7 | //--------------------------------------------------------------------------- 8 | // message highlight item 9 | class TMessHighlight 10 | { 11 | public: 12 | bool bEnable; 13 | TMessMatch Match; 14 | TMessStyle Style; 15 | 16 | public: 17 | TMessHighlight(); 18 | void Save(XMLElementEx * p); 19 | bool Load(XMLElementEx * p); 20 | }; 21 | //--------------------------------------------------------------------------- 22 | // message highlight item list (profile) 23 | class TMessHighlightList : public TList 24 | { 25 | public: 26 | String ProfileName; 27 | 28 | public: 29 | __fastcall TMessHighlightList(); 30 | __fastcall virtual ~TMessHighlightList(void); 31 | void __fastcall Add(TMessHighlight * p); 32 | TMessHighlight * __fastcall Get(int index); 33 | void __fastcall Del(int index); 34 | 35 | // if not found - return NULL 36 | TMessStyle * FindStyleForMessage(TSyslogMessage * p); 37 | 38 | void Save(XMLElementEx * p); 39 | void Load(XMLElementEx * p); 40 | 41 | private: 42 | virtual void __fastcall Clear(void); 43 | }; 44 | //--------------------------------------------------------------------------- 45 | // message highlight profile list 46 | class THighlightProfileList : public TList 47 | { 48 | public: 49 | int CurrentProfile; // index of current profile 50 | 51 | public: 52 | __fastcall THighlightProfileList(); 53 | __fastcall virtual ~THighlightProfileList(void); 54 | void __fastcall Add(TMessHighlightList * p); 55 | 56 | TMessHighlightList * GetCurrentProfile(void); 57 | void Save(String file); 58 | void Load(String file); 59 | 60 | private: 61 | virtual void __fastcall Clear(void); 62 | }; 63 | //--------------------------------------------------------------------------- 64 | #endif 65 | 66 | -------------------------------------------------------------------------------- /source/messmatch.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef messmatchH 3 | #define messmatchH 4 | 5 | #include "server.h" 6 | #include "maxxml.h" 7 | #include "syslog.h" 8 | 9 | #define PriorityMaskAll 0xFF 10 | #define FacilityMaskAll 0x00FFFFFF // 24 facilities 11 | //--------------------------------------------------------------------------- 12 | class TMessMatch 13 | { 14 | public: 15 | bool bNot; // true --> Negate (apply logical NOT) 16 | BYTE PriorityMask; // 8 priorities (LOG_) 17 | DWORD FacilityMask; // 24 facilities (LOG_) 18 | 19 | // rule 1 20 | int Field1; // 0-Text, 1-Message, 2-IP, 3-Host, 4-Facility, 5-Tag 21 | bool Contains1; // true(1) - Contains or = Text1 22 | // false(0) - NOT Contains or <> Text1 23 | TStringList * Text1; // text strings to find in message 24 | 25 | // AND 26 | 27 | // rule 2 28 | int Field2; 29 | bool Contains2; 30 | TStringList * Text2; 31 | 32 | bool MatchCase; // default true 33 | 34 | public: 35 | TMessMatch(); 36 | ~TMessMatch(); 37 | void Clear(void); 38 | // return true if match Priority AND Text1 AND Text2 39 | bool Match(TSyslogMessage * p); 40 | String GetDescription(void); 41 | bool IsAllMatch(void); 42 | 43 | void Save(XMLElementEx * p); 44 | void Load(XMLElementEx * p); 45 | void Save(String file, bool bShowMessage=true); 46 | void Load(String file, bool bShowMessage=true); 47 | 48 | void DeleteEmptyLines(void); 49 | 50 | private: 51 | bool LocalMatch(TSyslogMessage * p); 52 | bool MatchAllFilds(TSyslogMessage * p, int Field, bool Contains, String Text); 53 | bool FieldContains(String & FieldText, String & Text); 54 | String GetDelimitedText(TStringList * p, String delimstr); 55 | }; 56 | //--------------------------------------------------------------------------- 57 | #endif 58 | -------------------------------------------------------------------------------- /source/messmatchframe.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "messmatchframe.h" 6 | //--------------------------------------------------------------------------- 7 | #pragma package(smart_init) 8 | #pragma resource "*.dfm" 9 | TMessMatchFr *MessMatchFr; 10 | //--------------------------------------------------------------------------- 11 | __fastcall TMessMatchFr::TMessMatchFr(TComponent* Owner) 12 | : TFrame(Owner) 13 | { 14 | OnValuesChange = NULL; 15 | GetPriorities(PriorityLB->Items); 16 | GetFacilities(FacilityLB->Items); 17 | } 18 | //--------------------------------------------------------------------------- 19 | void TMessMatchFr::ToDialog(TMessMatch * p) 20 | { 21 | bEnableValuesChange = false; 22 | 23 | NotCB->Checked = p->bNot; 24 | 25 | for(int i=0; iChecked[i] = p->PriorityMask & (1<Checked[i] = p->FacilityMask & (1<ItemIndex = p->Field1 * 2 + (p->Contains1 ? 0 : 1); 31 | Memo1->Lines = p->Text1; 32 | FieldCB2->ItemIndex = p->Field2 * 2 + (p->Contains2 ? 0 : 1); 33 | Memo2->Lines = p->Text2; 34 | MatchCaseCB->Checked = p->MatchCase; 35 | bEnableValuesChange = true; 36 | } 37 | //--------------------------------------------------------------------------- 38 | void TMessMatchFr::FromDialog(TMessMatch * p) 39 | { 40 | p->bNot = NotCB->Checked; 41 | 42 | p->PriorityMask = 0; 43 | for(int i=0; iPriorityMask |= PriorityLB->Checked[i] ? (1<FacilityMask = 0; 46 | for(int i=0; iFacilityMask |= FacilityLB->Checked[i] ? (1<Field1 = FieldCB1->ItemIndex / 2; 50 | p->Contains1 = (FieldCB1->ItemIndex & 1) == 0; 51 | p->Text1->Assign(Memo1->Lines); 52 | p->Field2 = FieldCB2->ItemIndex / 2; 53 | p->Contains2 = (FieldCB2->ItemIndex & 1) == 0; 54 | p->Text2->Assign(Memo2->Lines); 55 | p->MatchCase = MatchCaseCB->Checked; 56 | 57 | p->DeleteEmptyLines(); 58 | } 59 | //--------------------------------------------------------------------------- 60 | void __fastcall TMessMatchFr::MatchChange(TObject *Sender) 61 | { 62 | if( bEnableValuesChange ) 63 | { 64 | if( OnValuesChange ) 65 | OnValuesChange(this); 66 | } 67 | } 68 | //--------------------------------------------------------------------------- 69 | void __fastcall TMessMatchFr::CheckAllFacButtonClick(TObject *Sender) 70 | { 71 | for(int i=0; iItems->Count; i++) 72 | FacilityLB->Checked[i] = true; 73 | MatchChange(Sender); 74 | } 75 | //--------------------------------------------------------------------------- 76 | void __fastcall TMessMatchFr::UncheckAllFacButtonClick(TObject *Sender) 77 | { 78 | for(int i=0; iItems->Count; i++) 79 | FacilityLB->Checked[i] = false; 80 | MatchChange(Sender); 81 | } 82 | //--------------------------------------------------------------------------- 83 | void __fastcall TMessMatchFr::CheckAllPriButtonClick(TObject *Sender) 84 | { 85 | for(int i=0; iItems->Count; i++) 86 | PriorityLB->Checked[i] = true; 87 | MatchChange(Sender); 88 | } 89 | //--------------------------------------------------------------------------- 90 | void __fastcall TMessMatchFr::UncheckAllPriButtonClick(TObject *Sender) 91 | { 92 | for(int i=0; iItems->Count; i++) 93 | PriorityLB->Checked[i] = false; 94 | MatchChange(Sender); 95 | } 96 | //--------------------------------------------------------------------------- 97 | 98 | -------------------------------------------------------------------------------- /source/messmatchframe.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef messmatchframeH 3 | #define messmatchframeH 4 | //--------------------------------------------------------------------------- 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "messmatch.h" 10 | #include 11 | #include 12 | 13 | //--------------------------------------------------------------------------- 14 | class TMessMatchFr : public TFrame 15 | { 16 | __published: // IDE-managed Components 17 | TGroupBox *GroupBox1; 18 | TLabel *Label1; 19 | TCheckBox *MatchCaseCB; 20 | TLabel *Label3; 21 | TComboBox *FieldCB1; 22 | TComboBox *FieldCB2; 23 | TMemo *Memo1; 24 | TMemo *Memo2; 25 | TCheckListBox *PriorityLB; 26 | TCheckListBox *FacilityLB; 27 | TCheckBox *NotCB; 28 | TLabel *Label2; 29 | TLabel *Label4; 30 | TSpeedButton *CheckAllFacButton; 31 | TSpeedButton *UncheckAllFacButton; 32 | TSpeedButton *UncheckAllPriButton; 33 | TSpeedButton *CheckAllPriButton; 34 | void __fastcall MatchChange(TObject *Sender); 35 | void __fastcall CheckAllFacButtonClick(TObject *Sender); 36 | void __fastcall UncheckAllFacButtonClick(TObject *Sender); 37 | void __fastcall CheckAllPriButtonClick(TObject *Sender); 38 | void __fastcall UncheckAllPriButtonClick(TObject *Sender); 39 | private: // User declarations 40 | bool bEnableValuesChange; 41 | public: 42 | TNotifyEvent OnValuesChange; 43 | public: // User declarations 44 | __fastcall TMessMatchFr(TComponent* Owner); 45 | void ToDialog(TMessMatch * p); 46 | void FromDialog(TMessMatch * p); 47 | }; 48 | //--------------------------------------------------------------------------- 49 | extern PACKAGE TMessMatchFr *MessMatchFr; 50 | //--------------------------------------------------------------------------- 51 | #endif 52 | -------------------------------------------------------------------------------- /source/messprocessframe.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include 6 | #include "cfg.h" 7 | #include "utils.h" 8 | #include "messageform.h" 9 | #include "messprocessframe.h" 10 | //--------------------------------------------------------------------------- 11 | #pragma package(smart_init) 12 | #pragma resource "*.dfm" 13 | 14 | extern TStorageFileList * fdb; 15 | extern String WorkDir; 16 | extern TMainCfg MainCfg; 17 | void RunSetup(int SelectedTabIndex); 18 | TMessProcessFr * MessProcessFr; 19 | //--------------------------------------------------------------------------- 20 | __fastcall TMessProcessFr::TMessProcessFr(TComponent* Owner) 21 | : TFrame(Owner) 22 | { 23 | DefaultRecipient = MainCfg.Letter.recipient; 24 | OpenDialog->InitialDir = WorkDir; 25 | fdb->GetList(SaveFileCB->Items); 26 | 27 | TStorageFile * p = fdb->Get(0); 28 | if( p ) 29 | { 30 | IgnoreCB->Caption = String("Ignore (do not save to the default file \"") + 31 | p->GetDescription() + "\")"; 32 | } 33 | } 34 | //--------------------------------------------------------------------------- 35 | TForm * TMessProcessFr::GetForm(void) 36 | { 37 | if( Parent ) 38 | { 39 | if( dynamic_cast(Parent) ) 40 | return (TForm *)Parent; 41 | if( dynamic_cast(Parent->Parent) ) 42 | return (TForm *)(Parent->Parent); 43 | } 44 | return NULL; 45 | } 46 | //--------------------------------------------------------------------------- 47 | void __fastcall TMessProcessFr::InsertAlarmMessButtonClick(TObject *Sender) 48 | { 49 | POINT p = InsertAlarmMessButton->ClientOrigin; 50 | InsertPopupMenu->Popup(p.x, p.y + InsertAlarmMessButton->Height); 51 | if( GetForm() ) 52 | GetForm()->ActiveControl = AlarmMessEdit; 53 | } 54 | //--------------------------------------------------------------------------- 55 | void __fastcall TMessProcessFr::pmInsertClick(TObject *Sender) 56 | { 57 | String s; 58 | switch( ((TMenuItem *)Sender)->Tag ) 59 | { 60 | case 0: s = "{time}"; break; 61 | case 1: s = "{ip}"; break; 62 | case 2: s = "{host}"; break; 63 | case 3: s = "{facility}"; break; 64 | case 4: s = "{priority}"; break; 65 | case 5: s = "{tag}"; break; 66 | case 6: s = "{message}"; break; 67 | } 68 | 69 | if( GetForm() ) 70 | { 71 | if( dynamic_cast(GetForm()->ActiveControl) ) 72 | { 73 | TEdit * p = (TEdit *)(GetForm()->ActiveControl); 74 | p->Text = p->Text + s; 75 | } 76 | } 77 | } 78 | //--------------------------------------------------------------------------- 79 | void __fastcall TMessProcessFr::SelWavCommonButtonClick(TObject *Sender) 80 | { 81 | OpenDialog->Title = "Open sound file"; 82 | OpenDialog->Filter = "Sound files (*.wav)|*.wav|All files (*.*)|*.*"; 83 | OpenDialog->DefaultExt = "wav"; 84 | if( OpenDialog->Execute() ) 85 | SoundFileEdit->Text = OpenDialog->FileName; 86 | } 87 | //--------------------------------------------------------------------------- 88 | void __fastcall TMessProcessFr::PlayButtonClick(TObject *Sender) 89 | { 90 | String f = SoundFileEdit->Text; 91 | 92 | if( f.Length() == 0 ) 93 | return; 94 | 95 | if( f.Length() > 0 && ExtractFilePath(f).Length() == 0 ) 96 | f = WorkDir + f; 97 | 98 | if( FileExists(f) ) 99 | { 100 | if( ::PlaySound(f.c_str(), NULL, SND_FILENAME | SND_NODEFAULT | 101 | SND_NOWAIT | SND_ASYNC) == FALSE ) 102 | ReportError2("Error play sound file: \"%s\"", FormatLastError2(GetLastError()).c_str()); 103 | } 104 | else 105 | { 106 | ReportError2("File \"%s\" not found!", f.c_str()); 107 | } 108 | } 109 | //--------------------------------------------------------------------------- 110 | void __fastcall TMessProcessFr::SpeedButton1Click(TObject *Sender) 111 | { 112 | OpenDialog->Title = "Open program"; 113 | OpenDialog->Filter = "Program (*.exe)|*.exe|All files (*.*)|*.*"; 114 | OpenDialog->DefaultExt = "exe"; 115 | if( OpenDialog->Execute() ) 116 | ProgFileEdit->Text = OpenDialog->FileName; 117 | } 118 | //--------------------------------------------------------------------------- 119 | void __fastcall TMessProcessFr::InsertProgramButtonClick(TObject *Sender) 120 | { 121 | POINT p = InsertProgramButton->ClientOrigin; 122 | InsertPopupMenu->Popup(p.x, p.y + InsertProgramButton->Height); 123 | if( GetForm() ) 124 | GetForm()->ActiveControl = ProgFileEdit; 125 | } 126 | //--------------------------------------------------------------------------- 127 | void TMessProcessFr::ToDialog(TMessProcess * p) 128 | { 129 | bEnableValuesChange = false; 130 | 131 | IgnoreCB->Checked = p->bIgnore; 132 | AlarmCB->Checked = p->bAlarm; 133 | AlarmMessEdit->Text = p->AlarmMess; 134 | SoundCB->Checked = p->bSound; 135 | SoundFileEdit->Text = p->SoundFile; 136 | PlayCountEdit->Text = IntToStr(p->PlayCount); 137 | SendMailCB->Checked = p->bSendMail; 138 | RecipientEdit->Text = p->Recipient; 139 | RecipientEditExit(RecipientEdit); 140 | RunProgCB->Checked = p->bRunProg; 141 | ProgFileEdit->Text = p->ProgFile; 142 | ProgHideCB->Checked = p->bProgHide; 143 | SaveToFileCB->Checked = p->bSaveToFile; 144 | SaveFileCB->ItemIndex = SaveFileCB->Items->IndexOfObject((TObject *)p->SaveFile); 145 | 146 | bEnableValuesChange = true; 147 | } 148 | //--------------------------------------------------------------------------- 149 | void TMessProcessFr::FromDialog(TMessProcess * p) 150 | { 151 | p->bIgnore = IgnoreCB->Checked; 152 | p->bAlarm = AlarmCB->Checked; 153 | p->AlarmMess = AlarmMessEdit->Text; 154 | p->bSound = SoundCB->Checked; 155 | p->SoundFile = SoundFileEdit->Text; 156 | p->PlayCount = StrToIntDef(PlayCountEdit->Text, 1); 157 | p->bSendMail = SendMailCB->Checked; 158 | if( RecipientEdit->Text == DefaultRecipient ) 159 | p->Recipient = ""; 160 | else 161 | p->Recipient = RecipientEdit->Text; 162 | p->bRunProg = RunProgCB->Checked; 163 | p->ProgFile = ProgFileEdit->Text; 164 | p->bProgHide = ProgHideCB->Checked; 165 | p->bSaveToFile = SaveToFileCB->Checked; 166 | int i = SaveFileCB->ItemIndex; 167 | if( i == -1 ) 168 | p->SaveFile = i; 169 | else 170 | p->SaveFile = (int)SaveFileCB->Items->Objects[i]; 171 | } 172 | //--------------------------------------------------------------------------- 173 | void __fastcall TMessProcessFr::Change(TObject *Sender) 174 | { 175 | if( bEnableValuesChange ) 176 | { 177 | if( OnValuesChange ) 178 | OnValuesChange(this); 179 | } 180 | } 181 | //--------------------------------------------------------------------------- 182 | void __fastcall TMessProcessFr::RecipientEditEnter(TObject *Sender) 183 | { 184 | TEdit * p = (TEdit *)Sender; 185 | if( p->Text == DefaultRecipient ) 186 | { 187 | p->Text = ""; 188 | p->Font->Color = clWindowText; 189 | } 190 | } 191 | //--------------------------------------------------------------------------- 192 | void __fastcall TMessProcessFr::RecipientEditExit(TObject *Sender) 193 | { 194 | TEdit * p = (TEdit *)Sender; 195 | if( p->Text.IsEmpty() ) 196 | { 197 | p->Text = DefaultRecipient; 198 | p->Font->Color = clGrayText; 199 | } 200 | else if( p->Text == DefaultRecipient ) 201 | { 202 | p->Font->Color = clGrayText; 203 | } 204 | } 205 | //--------------------------------------------------------------------------- 206 | void __fastcall TMessProcessFr::SpeedButton2Click(TObject *Sender) 207 | { 208 | int number = -1; 209 | int i = SaveFileCB->ItemIndex; 210 | if( i >= 0 ) 211 | number = (int)SaveFileCB->Items->Objects[i]; 212 | 213 | RunSetup(1); 214 | fdb->GetList(SaveFileCB->Items); 215 | 216 | SaveFileCB->ItemIndex = SaveFileCB->Items->IndexOfObject((TObject *)number); 217 | } 218 | //--------------------------------------------------------------------------- 219 | 220 | -------------------------------------------------------------------------------- /source/messprocessframe.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef messprocessframeH 3 | #define messprocessframeH 4 | //--------------------------------------------------------------------------- 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "messprocessing.h" 13 | //--------------------------------------------------------------------------- 14 | class TMessProcessFr : public TFrame 15 | { 16 | __published: // IDE-managed Components 17 | TGroupBox *GroupBox1; 18 | TCheckBox *IgnoreCB; 19 | TCheckBox *AlarmCB; 20 | TLabel *Label11; 21 | TEdit *AlarmMessEdit; 22 | TPopupMenu *InsertPopupMenu; 23 | TMenuItem *time1; 24 | TMenuItem *ip1; 25 | TMenuItem *host1; 26 | TMenuItem *facility1; 27 | TMenuItem *priority1; 28 | TMenuItem *tag1; 29 | TMenuItem *message1; 30 | TCheckBox *SoundCB; 31 | TEdit *SoundFileEdit; 32 | TLabel *Label2; 33 | TEdit *PlayCountEdit; 34 | TOpenDialog *OpenDialog; 35 | TSpeedButton *SelWavCommonButton; 36 | TSpeedButton *PlayButton; 37 | TCheckBox *SendMailCB; 38 | TCheckBox *RunProgCB; 39 | TEdit *ProgFileEdit; 40 | TSpeedButton *SpeedButton1; 41 | TCheckBox *ProgHideCB; 42 | TSpeedButton *InsertProgramButton; 43 | TSpeedButton *InsertAlarmMessButton; 44 | TCheckBox *SaveToFileCB; 45 | TEdit *RecipientEdit; 46 | TComboBox *SaveFileCB; 47 | TSpeedButton *SpeedButton2; 48 | void __fastcall InsertAlarmMessButtonClick(TObject *Sender); 49 | void __fastcall pmInsertClick(TObject *Sender); 50 | void __fastcall SelWavCommonButtonClick(TObject *Sender); 51 | void __fastcall PlayButtonClick(TObject *Sender); 52 | void __fastcall SpeedButton1Click(TObject *Sender); 53 | void __fastcall InsertProgramButtonClick(TObject *Sender); 54 | void __fastcall Change(TObject *Sender); 55 | void __fastcall RecipientEditEnter(TObject *Sender); 56 | void __fastcall RecipientEditExit(TObject *Sender); 57 | void __fastcall SpeedButton2Click(TObject *Sender); 58 | private: // User declarations 59 | TForm * GetForm(void); 60 | bool bEnableValuesChange; 61 | String DefaultRecipient; 62 | public: 63 | TNotifyEvent OnValuesChange; 64 | public: // User declarations 65 | __fastcall TMessProcessFr(TComponent* Owner); 66 | void ToDialog(TMessProcess * p); 67 | void FromDialog(TMessProcess * p); 68 | }; 69 | //--------------------------------------------------------------------------- 70 | extern PACKAGE TMessProcessFr *MessProcessFr; 71 | //--------------------------------------------------------------------------- 72 | #endif 73 | -------------------------------------------------------------------------------- /source/messprocessing.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "messageform.h" 6 | #include "messprocessing.h" 7 | #include "fdb.h" 8 | 9 | const char * szProcessRuleNodes = "processrules"; 10 | const char * szProcessRuleNode = "processrule"; 11 | extern const char * szMatchNode; //= "match"; 12 | const char * szProcessNode = "process"; 13 | 14 | extern String WorkDir; 15 | extern TStorageFileList * fdb; 16 | 17 | //--------------------------------------------------------------------------- 18 | TMessProcess::TMessProcess() 19 | { 20 | bIgnore = false; 21 | bAlarm = false; 22 | AlarmMess = "{time} {message}"; 23 | bSound = false; 24 | SoundFile = "alarm.wav"; 25 | PlayCount = 1; 26 | bSendMail = false; 27 | bRunProg = false; 28 | bProgHide = false; 29 | bSaveToFile = false; 30 | SaveFile = -1; 31 | } 32 | //--------------------------------------------------------------------------- 33 | String TMessProcess::GetSoundFileName(void) 34 | { 35 | if( SoundFile.Length() > 0 && ExtractFilePath(SoundFile).Length() == 0 ) 36 | return WorkDir + SoundFile; 37 | return SoundFile; 38 | } 39 | //--------------------------------------------------------------------------- 40 | String TMessProcess::GetDescription(void) 41 | { 42 | String rv; 43 | char * a = " AND "; 44 | 45 | if( bIgnore ) 46 | rv += "Ignore"; 47 | if( bAlarm ) 48 | { 49 | if( ! rv.IsEmpty() ) rv += a; 50 | rv += "Show alarm"; 51 | } 52 | if( bSound ) 53 | { 54 | if( ! rv.IsEmpty() ) rv += a; 55 | rv += "Play sound"; 56 | } 57 | if( bSendMail ) 58 | { 59 | if( ! rv.IsEmpty() ) rv += a; 60 | rv += "Send e-mail"; 61 | } 62 | if( bRunProg ) 63 | { 64 | if( ! rv.IsEmpty() ) rv += a; 65 | rv += "Run program"; 66 | } 67 | if( bSaveToFile ) 68 | { 69 | if( ! rv.IsEmpty() ) rv += a; 70 | rv += "Save to file \""; 71 | 72 | TStorageFile * sf = fdb->GetByNumber( SaveFile ); 73 | if( sf ) 74 | rv += sf->file + "\""; 75 | } 76 | return rv; 77 | } 78 | //--------------------------------------------------------------------------- 79 | void TMessProcess::Save(XMLElementEx * p) 80 | { 81 | p->wb("ignore", bIgnore); 82 | p->wb("alarm", bAlarm); 83 | p->ws("alarmmess", AlarmMess); 84 | p->wb("sound", bSound); 85 | p->ws("soundfile", SoundFile); 86 | p->wi("playcount", PlayCount); 87 | p->wb("sendmail", bSendMail); 88 | p->ws("recipient", Recipient); 89 | p->wb("runprog", bRunProg); 90 | p->ws("progfile", ProgFile); 91 | p->wb("proghide", bProgHide); 92 | p->wb("savetofile", bSaveToFile); 93 | p->wi("savefile", SaveFile); 94 | } 95 | //--------------------------------------------------------------------------- 96 | void TMessProcess::Load(XMLElementEx * p) 97 | { 98 | bIgnore = p->rb("ignore"); 99 | bAlarm = p->rb("alarm"); 100 | AlarmMess = p->rs("alarmmess"); 101 | bSound = p->rb("sound"); 102 | SoundFile = p->rs("soundfile", "alarm.wav"); 103 | PlayCount = p->ri("playcount"); 104 | bSendMail = p->rb("sendmail"); 105 | Recipient = p->rs("recipient"); 106 | bRunProg = p->rb("runprog"); 107 | ProgFile = p->rs("progfile"); 108 | bProgHide = p->rb("proghide"); 109 | bSaveToFile = p->rb("savetofile"); 110 | SaveFile = p->ri("savefile", -1); 111 | } 112 | //--------------------------------------------------------------------------- 113 | //--------------------------------------------------------------------------- 114 | //--------------------------------------------------------------------------- 115 | TMessProcessRule::TMessProcessRule() 116 | { 117 | bEnable = true; 118 | } 119 | //--------------------------------------------------------------------------- 120 | void TMessProcessRule::Save(XMLElementEx * p) 121 | { 122 | tinyxml2::XMLDocument * d = p->GetDocument(); 123 | XMLElement * e; 124 | 125 | p->wb("enable", bEnable); 126 | 127 | e = d->NewElement(szMatchNode); 128 | p->InsertEndChild(e); 129 | Match.Save((XMLElementEx *)e); 130 | 131 | e = d->NewElement(szProcessNode); 132 | p->InsertEndChild(e); 133 | Process.Save((XMLElementEx *)e); 134 | } 135 | //--------------------------------------------------------------------------- 136 | bool TMessProcessRule::Load(XMLElementEx * p) 137 | { 138 | bool rv = true; 139 | bEnable = p->rb("enable", true); 140 | const XMLElement * e; 141 | e = p->FirstChildElement(szMatchNode); 142 | if( e ) Match.Load((XMLElementEx *)e); 143 | else rv = false; 144 | e = p->FirstChildElement(szProcessNode); 145 | if( e ) Process.Load((XMLElementEx *)e); 146 | else rv = false; 147 | return rv; 148 | } 149 | //--------------------------------------------------------------------------- 150 | //--------------------------------------------------------------------------- 151 | //--------------------------------------------------------------------------- 152 | __fastcall TMessProcessRuleList::TMessProcessRuleList() 153 | { 154 | 155 | } 156 | //--------------------------------------------------------------------------- 157 | __fastcall TMessProcessRuleList::~TMessProcessRuleList(void) 158 | { 159 | Clear(); 160 | } 161 | //--------------------------------------------------------------------------- 162 | void __fastcall TMessProcessRuleList::Clear(void) 163 | { 164 | for(int i=0; i= 0 && index < Count ) 177 | return (TMessProcessRule *)Items[index]; 178 | return NULL; 179 | } 180 | //--------------------------------------------------------------------------- 181 | void __fastcall TMessProcessRuleList::Del(int index) 182 | { 183 | if( index >= 0 && index < Count ) 184 | { 185 | delete (TMessProcessRule *)Items[index]; 186 | TList::Delete(index); 187 | } 188 | } 189 | //--------------------------------------------------------------------------- 190 | void TMessProcessRuleList::Save(String file) 191 | { 192 | tinyxml2::XMLDocument doc; 193 | doc.InsertEndChild( doc.NewDeclaration() ); 194 | 195 | XMLNode * hls = doc.InsertEndChild( doc.NewElement(szProcessRuleNodes) ); 196 | 197 | XMLElement * e; 198 | TMessProcessRule * p; 199 | for(int i=0; iInsertEndChild(e); 204 | p->Save((XMLElementEx *)e); 205 | } 206 | 207 | XMLError err = doc.SaveFile(file.c_str()); 208 | if( err != XML_SUCCESS ) 209 | ReportError2("Error saving file: \"%s\" [%d]", file.c_str(), err); 210 | } 211 | //--------------------------------------------------------------------------- 212 | void TMessProcessRuleList::Load(String file) 213 | { 214 | XMLError err; 215 | try 216 | { 217 | Clear(); 218 | tinyxml2::XMLDocument doc; 219 | err = doc.LoadFile(file.c_str()); 220 | if( err == XML_SUCCESS ) 221 | { 222 | XMLElement * hls; 223 | hls = doc.RootElement(); 224 | if( ! hls ) 225 | throw 1; 226 | if( strcmpi(hls->Name(), szProcessRuleNodes) != 0 ) 227 | throw 1; 228 | 229 | TMessProcessRule * mh; 230 | // process rules 231 | for(const XMLElement * pr = hls->FirstChildElement(szProcessRuleNode); 232 | pr; 233 | pr = pr->NextSiblingElement(szProcessRuleNode)) 234 | { 235 | mh = new TMessProcessRule; 236 | mh->Load((XMLElementEx *)pr); 237 | Add(mh); 238 | } 239 | } 240 | else 241 | throw 0; 242 | } 243 | catch(int i) 244 | { 245 | if( i==0 ) 246 | ReportError2("Error reading file: \"%s\" [%d]", file.c_str(), err); 247 | else 248 | ReportError2("Incorrect format of file: \"%s\"", file.c_str()); 249 | } 250 | } 251 | //--------------------------------------------------------------------------- 252 | #pragma package(smart_init) 253 | -------------------------------------------------------------------------------- /source/messprocessing.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef messprocessingH 3 | #define messprocessingH 4 | 5 | #include "maxxml.h" 6 | #include "messmatch.h" 7 | //--------------------------------------------------------------------------- 8 | // message process item 9 | class TMessProcess 10 | { 11 | public: 12 | bool bIgnore; // Ignore (do not save to the default file "syslog") 13 | bool bAlarm; // 14 | String AlarmMess; // 15 | bool bSound; // 16 | String SoundFile; // 17 | int PlayCount; // 18 | bool bSendMail; // 19 | String Recipient; // 20 | bool bRunProg; // 21 | String ProgFile; // 22 | bool bProgHide; // 23 | bool bSaveToFile; // 24 | int SaveFile; // link to TStorageFile::number (-1 file not selected) 25 | 26 | public: 27 | TMessProcess(); 28 | String GetDescription(void); 29 | String GetSoundFileName(void); 30 | void Save(XMLElementEx * p); 31 | void Load(XMLElementEx * p); 32 | }; 33 | //--------------------------------------------------------------------------- 34 | // message process rule item 35 | class TMessProcessRule 36 | { 37 | public: 38 | bool bEnable; 39 | TMessMatch Match; 40 | TMessProcess Process; 41 | 42 | public: 43 | TMessProcessRule(); 44 | void Save(XMLElementEx * p); 45 | bool Load(XMLElementEx * p); 46 | }; 47 | //--------------------------------------------------------------------------- 48 | // message process rule list 49 | class TMessProcessRuleList : public TList 50 | { 51 | public: 52 | __fastcall TMessProcessRuleList(); 53 | __fastcall virtual ~TMessProcessRuleList(void); 54 | void __fastcall Add(TMessProcessRule * p); 55 | TMessProcessRule * __fastcall Get(int index); 56 | void __fastcall Del(int index); 57 | 58 | void Save(String file); 59 | void Load(String file); 60 | 61 | private: 62 | virtual void __fastcall Clear(void); 63 | }; 64 | //--------------------------------------------------------------------------- 65 | #endif 66 | -------------------------------------------------------------------------------- /source/messstyle.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "messstyle.h" 6 | 7 | //--------------------------------------------------------------------------- 8 | TMessStyle::TMessStyle() 9 | { 10 | TextColor = clBlack; 11 | BackgroundColor = clWhite; 12 | bBold = false; 13 | bItalic = false; 14 | bUnderline = false; 15 | } 16 | //--------------------------------------------------------------------------- 17 | void TMessStyle::Save(XMLElementEx * p) 18 | { 19 | p->wi("textColor", (int)TextColor); 20 | p->wi("backgroundColor", (int)BackgroundColor); 21 | p->wb("bold", bBold); 22 | p->wb("italic", bItalic); 23 | p->wb("underline", bUnderline); 24 | } 25 | //--------------------------------------------------------------------------- 26 | void TMessStyle::Load(XMLElementEx * p) 27 | { 28 | TextColor = (TColor)p->ri("textColor", (int)clBlack); 29 | BackgroundColor = (TColor)p->ri("backgroundColor", (int)clWhite); 30 | bBold = p->rb("bold", false); 31 | bItalic = p->rb("italic", false); 32 | bUnderline = p->rb("underline", false); 33 | } 34 | //--------------------------------------------------------------------------- 35 | void TMessStyle::SetFontStyle(TFont * p) 36 | { 37 | TFontStyles s = p->Style; 38 | if( bBold ) s << fsBold; 39 | else s >> fsBold; 40 | if( bItalic ) s << fsItalic; 41 | else s >> fsItalic; 42 | if( bUnderline ) s << fsUnderline; 43 | else s >> fsUnderline; 44 | p->Style = s; 45 | } 46 | //--------------------------------------------------------------------------- 47 | #pragma package(smart_init) 48 | 49 | -------------------------------------------------------------------------------- /source/messstyle.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef messstyleH 3 | #define messstyleH 4 | 5 | #include "maxxml.h" 6 | //--------------------------------------------------------------------------- 7 | class TMessStyle 8 | { 9 | public: 10 | TColor TextColor; // font color 11 | TColor BackgroundColor; 12 | bool bBold; // font style 13 | bool bItalic; 14 | bool bUnderline; 15 | 16 | public: 17 | TMessStyle(); 18 | void Save(XMLElementEx * p); 19 | void Load(XMLElementEx * p); 20 | void SetFontStyle(TFont * p); 21 | }; 22 | //--------------------------------------------------------------------------- 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /source/messstyleframe.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "messstyleframe.h" 6 | //--------------------------------------------------------------------------- 7 | #pragma package(smart_init) 8 | #pragma resource "*.dfm" 9 | TMessStyleFr *MessStyleFr; 10 | //--------------------------------------------------------------------------- 11 | __fastcall TMessStyleFr::TMessStyleFr(TComponent* Owner) 12 | : TFrame(Owner) 13 | { 14 | OnValuesChange = NULL; 15 | } 16 | //--------------------------------------------------------------------------- 17 | void TMessStyleFr::ToDialog(TMessStyle * p) 18 | { 19 | EnableStyleChange = false; 20 | TextColorBox->Selected = p->TextColor; 21 | BackgroundColorBox->Selected = p->BackgroundColor; 22 | BoldCB->Checked = p->bBold; 23 | ItalicCB->Checked = p->bItalic; 24 | UnderlineCB->Checked = p->bUnderline; 25 | EnableStyleChange = true; 26 | //UpdatePreview(); 27 | } 28 | //--------------------------------------------------------------------------- 29 | void TMessStyleFr::FromDialog(TMessStyle * p) 30 | { 31 | p->TextColor = TextColorBox->Selected; 32 | p->BackgroundColor = BackgroundColorBox->Selected; 33 | p->bBold = BoldCB->Checked; 34 | p->bItalic = ItalicCB->Checked; 35 | p->bUnderline = UnderlineCB->Checked; 36 | } 37 | //--------------------------------------------------------------------------- 38 | /* 39 | void TMessStyleFr::UpdatePreview(void) 40 | { 41 | PreviewLabel->Font->Color = TextColorBox->Selected; 42 | PreviewLabel->Color = BackgroundColorBox->Selected; 43 | 44 | TFontStyles s = PreviewLabel->Font->Style; 45 | if( BoldCB->Checked ) s << fsBold; 46 | else s >> fsBold; 47 | if( ItalicCB->Checked ) s << fsItalic; 48 | else s >> fsItalic; 49 | if( UnderlineCB->Checked ) s << fsUnderline; 50 | else s >> fsUnderline; 51 | PreviewLabel->Font->Style = s; 52 | } 53 | */ 54 | //--------------------------------------------------------------------------- 55 | void __fastcall TMessStyleFr::StyleChange(TObject *Sender) 56 | { 57 | if( EnableStyleChange ) 58 | { 59 | //UpdatePreview(); 60 | if( OnValuesChange ) 61 | OnValuesChange(this); 62 | } 63 | } 64 | //--------------------------------------------------------------------------- 65 | 66 | -------------------------------------------------------------------------------- /source/messstyleframe.dfm: -------------------------------------------------------------------------------- 1 | object MessStyleFr: TMessStyleFr 2 | Left = 0 3 | Top = 0 4 | Width = 333 5 | Height = 132 6 | TabOrder = 0 7 | object GroupBox1: TGroupBox 8 | Left = 0 9 | Top = 0 10 | Width = 333 11 | Height = 132 12 | Align = alClient 13 | Caption = 'Style' 14 | TabOrder = 0 15 | ExplicitHeight = 190 16 | object Label1: TLabel 17 | Left = 16 18 | Top = 19 19 | Width = 48 20 | Height = 13 21 | Caption = 'Text color' 22 | end 23 | object Label2: TLabel 24 | Left = 16 25 | Top = 75 26 | Width = 82 27 | Height = 13 28 | Caption = 'Background color' 29 | end 30 | object Label3: TLabel 31 | Left = 208 32 | Top = 21 33 | Width = 45 34 | Height = 13 35 | Caption = 'Text font' 36 | end 37 | object TextColorBox: TColorBox 38 | Left = 16 39 | Top = 38 40 | Width = 155 41 | Height = 22 42 | Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbCustomColor, cbPrettyNames] 43 | ItemHeight = 16 44 | TabOrder = 0 45 | OnSelect = StyleChange 46 | end 47 | object BackgroundColorBox: TColorBox 48 | Left = 16 49 | Top = 94 50 | Width = 155 51 | Height = 22 52 | Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbCustomColor, cbPrettyNames] 53 | ItemHeight = 16 54 | TabOrder = 1 55 | OnSelect = StyleChange 56 | end 57 | object BoldCB: TCheckBox 58 | Left = 208 59 | Top = 40 60 | Width = 97 61 | Height = 17 62 | Caption = 'Bold' 63 | Font.Charset = DEFAULT_CHARSET 64 | Font.Color = clWindowText 65 | Font.Height = -11 66 | Font.Name = 'Tahoma' 67 | Font.Style = [fsBold] 68 | ParentFont = False 69 | TabOrder = 2 70 | OnClick = StyleChange 71 | end 72 | object ItalicCB: TCheckBox 73 | Left = 208 74 | Top = 63 75 | Width = 97 76 | Height = 17 77 | Caption = 'Italic' 78 | Font.Charset = DEFAULT_CHARSET 79 | Font.Color = clWindowText 80 | Font.Height = -11 81 | Font.Name = 'Tahoma' 82 | Font.Style = [fsItalic] 83 | ParentFont = False 84 | TabOrder = 3 85 | OnClick = StyleChange 86 | end 87 | object UnderlineCB: TCheckBox 88 | Left = 208 89 | Top = 86 90 | Width = 97 91 | Height = 17 92 | Caption = 'Underline' 93 | Font.Charset = DEFAULT_CHARSET 94 | Font.Color = clWindowText 95 | Font.Height = -11 96 | Font.Name = 'Tahoma' 97 | Font.Style = [fsUnderline] 98 | ParentFont = False 99 | TabOrder = 4 100 | OnClick = StyleChange 101 | end 102 | end 103 | end 104 | -------------------------------------------------------------------------------- /source/messstyleframe.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef messstyleframeH 3 | #define messstyleframeH 4 | //--------------------------------------------------------------------------- 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "messstyle.h" 11 | 12 | //--------------------------------------------------------------------------- 13 | class TMessStyleFr : public TFrame 14 | { 15 | __published: // IDE-managed Components 16 | TGroupBox *GroupBox1; 17 | TColorBox *TextColorBox; 18 | TLabel *Label1; 19 | TLabel *Label2; 20 | TColorBox *BackgroundColorBox; 21 | TCheckBox *BoldCB; 22 | TLabel *Label3; 23 | TCheckBox *ItalicCB; 24 | TCheckBox *UnderlineCB; 25 | void __fastcall StyleChange(TObject *Sender); 26 | private: // User declarations 27 | bool EnableStyleChange; 28 | public: 29 | TNotifyEvent OnValuesChange; 30 | public: // User declarations 31 | __fastcall TMessStyleFr(TComponent* Owner); 32 | void ToDialog(TMessStyle * p); 33 | void FromDialog(TMessStyle * p); 34 | //void UpdatePreview(void); 35 | }; 36 | //--------------------------------------------------------------------------- 37 | extern PACKAGE TMessStyleFr *MessStyleFr; 38 | //--------------------------------------------------------------------------- 39 | #endif 40 | -------------------------------------------------------------------------------- /source/server.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "cfg.h" 6 | #include "syslog.h" 7 | #include "server.h" 8 | 9 | extern TMainCfg MainCfg; 10 | 11 | //--------------------------------------------------------------------------- 12 | TSyslogMessage::TSyslogMessage() 13 | { 14 | PRI = -1; // not exist 15 | } 16 | //--------------------------------------------------------------------------- 17 | void TSyslogMessage::Clear() 18 | { 19 | SourceAddr = ""; 20 | PRI = -1; 21 | Facility = ""; 22 | Priority = ""; 23 | DateStr = ""; 24 | HostName = ""; 25 | Tag = ""; 26 | Msg = ""; 27 | } 28 | //--------------------------------------------------------------------------- 29 | bool TSyslogMessage::FromStringSyslogd(char * p, int size, sockaddr_in * from_addr) 30 | { 31 | if( from_addr ) 32 | SourceAddr = inet_ntoa(from_addr->sin_addr); 33 | else 34 | SourceAddr = ""; 35 | 36 | PRI = -1; // not exist 37 | if( *p == '<' ) 38 | { 39 | for(int i=1; i<5 && p[i]; i++) 40 | { 41 | if( p[i] == '>' ) 42 | { 43 | PRI = atoi(p+1); 44 | p += i + 1; 45 | break; 46 | } 47 | if( ! isdigit(p[i]) ) 48 | break; 49 | } 50 | } 51 | if( PRI >= 0 ) 52 | { 53 | // invalid facility number not allowed: message filtering mechanism will fail 54 | // replace invalid facility number by LOGALERT 55 | if( LOG_FAC(PRI) >= LOG_NFACILITIES ) 56 | PRI = LOG_PRI(PRI) | LOG_LOGALERT; 57 | 58 | Facility = getcodetext(LOG_FAC(PRI) << 3, facilitynames); 59 | Priority = getcodetext(LOG_PRI(PRI), prioritynames); 60 | } 61 | 62 | if( IsValidSyslogDate(p) ) 63 | { 64 | DateStr = String(p, 15); 65 | p += 16; // including space 66 | } 67 | else 68 | { 69 | // month names in english in compliance to syslog rfc 70 | TFormatSettings fs; 71 | GetLocaleFormatSettings(0x0409, fs); // usa 72 | DateStr = FormatDateTime("mmm dd hh:nn:ss", Now(), fs); 73 | } 74 | 75 | // try to find host name 76 | for(int i=0; i<255 && p[i]; i++) 77 | { 78 | if( p[i] == ' ' ) 79 | { 80 | // found 81 | HostName = String(p, i); 82 | p += i + 1; 83 | break; 84 | } 85 | else if( p[i] == ':' || p[i] == '[' || p[i] == ']' ) 86 | { 87 | // host name not exist - this is program name 88 | break; 89 | } 90 | } 91 | 92 | // try to find program name 93 | for(int i=0; i<(48+2) && p[i]; i++) 94 | { 95 | if( p[i] == ':' && p[i+1] == ' ' ) 96 | { 97 | // found 98 | Tag = String(p, i); 99 | p += i + 2; 100 | break; 101 | } 102 | } 103 | 104 | // and now - process message 105 | // Replace all tabs by spaces, 106 | // cut all carriage returns and line feeds, 107 | // replace all chars 0..32 by '.' 108 | Msg = ""; 109 | for(int i=0; p[i]; i++) 110 | { 111 | if( p[i] == '\t' || p[i] == '\n' ) 112 | Msg += ' '; 113 | else if( p[i] == '\r' ) 114 | ; 115 | else if( p[i] >= 0 && p[i] < 32 ) 116 | Msg += '.'; 117 | else 118 | Msg += p[i]; 119 | } 120 | 121 | if( MainCfg.bReceiveUTF8 ) 122 | Msg = Utf8ToAnsi(Msg); 123 | 124 | return true; 125 | } 126 | //--------------------------------------------------------------------------- 127 | AnsiString TSyslogMessage::ToString(void) 128 | { 129 | return SourceAddr + '\t' + DateStr + '\t' + HostName + '\t' + 130 | ((PRI >= 0) ? (Facility + '\t' + Priority) : AnsiString('\t')) + '\t' + 131 | Tag + '\t' + Msg + CR; 132 | } 133 | //--------------------------------------------------------------------------- 134 | void TSyslogMessage::FromString(char * p, int len) 135 | { 136 | // SourceAddr = String(p, int count) 5 time faster than 137 | // String SourceAddr += *p 138 | 139 | if( ! p ) 140 | return; 141 | if( ! *p ) 142 | return; 143 | 144 | int i=0, c; 145 | 146 | for(c=0; p[i]!='\t' && i= 0 ) 176 | { 177 | int i = gettextcode(Facility.c_str(), facilitynames); 178 | if( i >= 0 ) 179 | PRI |= i; 180 | } 181 | } 182 | //--------------------------------------------------------------------------- 183 | /* 184 | bool TSyslogMessage::SaveToFile(const String & file) 185 | { 186 | TFile out(file, GENERIC_WRITE, 187 | FILE_SHARE_READ | FILE_SHARE_WRITE, 188 | OPEN_ALWAYS, 189 | FILE_ATTRIBUTE_NORMAL); 190 | if( ! out ) 191 | return false; 192 | out.ToEnd(); 193 | 194 | return Save(out); 195 | } 196 | */ 197 | /* 198 | //--------------------------------------------------------------------------- 199 | bool TSyslogMessage::SaveToFile(TFile & out) 200 | { 201 | out << ToString(); 202 | return ! out.GetError(); 203 | } 204 | */ 205 | /* 206 | //--------------------------------------------------------------------------- 207 | bool TSyslogMessage::SaveToFile(const String & file, TFile & out) 208 | { 209 | if( ! out.IsOpen() ) 210 | { 211 | out.Open(file, GENERIC_WRITE, 212 | FILE_SHARE_READ | FILE_SHARE_WRITE, 213 | OPEN_ALWAYS, 214 | FILE_ATTRIBUTE_NORMAL); 215 | if( ! out ) 216 | return false; 217 | out.ToEnd(); 218 | } 219 | return Save(out); 220 | } 221 | */ 222 | //--------------------------------------------------------------------------- 223 | String TSyslogMessage::ToStringClipboard(void) 224 | { 225 | return 226 | DateStr + '\t' + SourceAddr + '\t' + HostName + '\t' + 227 | ((PRI >= 0) ? (Facility + '\t' + Priority) : String('\t')) + '\t' + 228 | Tag + '\t' + Msg + CR; 229 | } 230 | //--------------------------------------------------------------------------- 231 | // {time} {ip} {host} {facility} {priority} {tag} {message} 232 | String TSyslogMessage::Format(String fmt) 233 | { 234 | int i; 235 | if( (i = fmt.Pos("{time}")) > 0 ) 236 | { 237 | fmt.Delete(i, 6); 238 | fmt.Insert(DateStr, i); 239 | } 240 | if( (i = fmt.Pos("{ip}")) > 0 ) 241 | { 242 | fmt.Delete(i, 4); 243 | fmt.Insert(SourceAddr, i); 244 | } 245 | if( (i = fmt.Pos("{host}")) > 0 ) 246 | { 247 | fmt.Delete(i, 6); 248 | fmt.Insert(HostName, i); 249 | } 250 | if( (i = fmt.Pos("{facility}")) > 0 ) 251 | { 252 | fmt.Delete(i, 10); 253 | fmt.Insert(Facility, i); 254 | } 255 | if( (i = fmt.Pos("{priority}")) > 0 ) 256 | { 257 | fmt.Delete(i, 10); 258 | fmt.Insert(Priority, i); 259 | } 260 | if( (i = fmt.Pos("{tag}")) > 0 ) 261 | { 262 | fmt.Delete(i, 5); 263 | fmt.Insert(Tag, i); 264 | } 265 | if( (i = fmt.Pos("{message}")) > 0 ) 266 | { 267 | fmt.Delete(i, 9); 268 | fmt.Insert(Msg, i); 269 | } 270 | return fmt; 271 | } 272 | //--------------------------------------------------------------------------- 273 | // sample: "Sep 2 09:46:37" 274 | bool IsValidSyslogDate(const char * p) 275 | { 276 | char * szMonths[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", 277 | "Aug", "Sep", "Oct", "Nov", "Dec" }; 278 | int Month = 0; 279 | for(int i=0; i<12; i++) 280 | { 281 | if( strncmp(p, szMonths[i], 3) == 0 ) 282 | Month = i + 1; 283 | } 284 | if( Month == 0 ) 285 | return false; 286 | p += 3; 287 | 288 | // space 289 | if( *p++ != ' ' ) 290 | return false; 291 | 292 | // day 293 | if( *p != ' ' && ! isdigit(*p) ) 294 | return false; 295 | if( ! isdigit(*(p+1)) ) 296 | return false; 297 | p += 2; 298 | 299 | // space 300 | if( *p++ != ' ' ) 301 | return false; 302 | 303 | // hour 304 | if( ! isdigit(*p) ) 305 | return false; 306 | if( ! isdigit(*(p+1)) ) 307 | return false; 308 | p += 2; 309 | 310 | // : 311 | if( *p++ != ':' ) 312 | return false; 313 | 314 | // min 315 | if( ! isdigit(*p) ) 316 | return false; 317 | if( ! isdigit(*(p+1)) ) 318 | return false; 319 | p += 2; 320 | 321 | // : 322 | if( *p++ != ':' ) 323 | return false; 324 | 325 | // sec 326 | if( ! isdigit(*p) ) 327 | return false; 328 | if( ! isdigit(*(p+1)) ) 329 | return false; 330 | p += 2; 331 | 332 | // space 333 | if( *p++ != ' ' ) 334 | return false; 335 | 336 | return true; 337 | } 338 | //--------------------------------------------------------------------------- 339 | #pragma package(smart_init) 340 | -------------------------------------------------------------------------------- /source/server.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef serverH 3 | #define serverH 4 | 5 | #include "udp.h" 6 | #include "file.h" 7 | //--------------------------------------------------------------------------- 8 | class TSyslogMessage 9 | { 10 | public: 11 | String SourceAddr; // IP 12 | int PRI; // -1: PRI not exist in message 13 | String Facility; 14 | String Priority; // also called Severity 15 | String DateStr; 16 | String HostName; 17 | String Tag; 18 | String Msg; 19 | 20 | public: 21 | TSyslogMessage(); 22 | void Clear(); 23 | 24 | // Read message from string p (string must be in syslog RFC 3164 format), 25 | // p must be null terminated 26 | bool FromStringSyslogd(char * p, int size, sockaddr_in * from_addr); 27 | 28 | // Format message to string (saving to file) 29 | AnsiString ToString(void); 30 | // Read message from string p[len] 31 | void FromString(char * p, int len); 32 | 33 | // Convert message to text string in clipboard format 34 | String ToStringClipboard(void); 35 | 36 | // Convert message to text string in custom format 37 | // fmt may contains: {time} {ip} {host} {facility} {priority} {tag} {message} 38 | String Format(String fmt); 39 | 40 | // Write to file 41 | //bool SaveToFile(const String & file); 42 | //bool SaveToFile(TFile & out); 43 | //bool SaveToFile(const String & file, TFile & out); 44 | }; 45 | //--------------------------------------------------------------------------- 46 | bool IsValidSyslogDate(const char * p); 47 | //--------------------------------------------------------------------------- 48 | #endif 49 | -------------------------------------------------------------------------------- /source/setup.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "sendmail.h" 6 | #include "MibAccess.h" 7 | #include "utils.h" // common functions 8 | #include "cfg.h" 9 | #include "messageform.h" // cool message box 10 | #include "server.h" 11 | #include "saveini.h" // TSaveParamsINI 12 | #include "setup.h" 13 | //--------------------------------------------------------------------------- 14 | #pragma package(smart_init) 15 | #pragma link "fileframe" 16 | #pragma resource "*.dfm" 17 | 18 | extern TStorageFileList * fdb; 19 | extern TMainCfg MainCfg; 20 | extern TSaveParamsINI * AppParams; 21 | extern TSendmailThread * SendmailThread; 22 | 23 | int TSetupForm::LastTabIndex = 0; 24 | int TSetupForm::LastFileIndex = 0; 25 | TSetupForm * SetupForm = NULL; 26 | //--------------------------------------------------------------------------- 27 | __fastcall TSetupForm::TSetupForm(TComponent* Owner) 28 | : TForm(Owner) 29 | { 30 | // main 31 | bUdpRestart = false; 32 | bTcpRestart = false; 33 | 34 | MibII m; 35 | UINT IPArray[20]; 36 | UINT IPArraySize = 20; 37 | m.Init(); 38 | UdpInterfaceCB->Items->BeginUpdate(); 39 | UdpInterfaceCB->Items->Add("0.0.0.0"); 40 | if( m.GetIPAddress(IPArray, IPArraySize) ) 41 | { 42 | for(UINT i=0; iItems->Add(IPAddrToString(IPArray[i])); 48 | } 49 | } 50 | UdpInterfaceCB->Items->EndUpdate(); 51 | 52 | TcpInterfaceCB->Items = UdpInterfaceCB->Items; 53 | 54 | EnableUdpCB->Checked = MainCfg.UdpEnable; 55 | UdpInterfaceCB->Text = MainCfg.UdpInterface; 56 | UdpPortEdit->Text = MainCfg.UdpPort; 57 | 58 | EnableTcpCB->Checked = MainCfg.TcpEnable; 59 | TcpInterfaceCB->Text = MainCfg.TcpInterface; 60 | TcpPortEdit->Text = MainCfg.TcpPort; 61 | 62 | D3CB->Checked = MainCfg.b3D; 63 | WriteRawCB->Checked = MainCfg.bWriteRaw; 64 | ReceiveUTF8CB->Checked = MainCfg.bReceiveUTF8; 65 | 66 | // files 67 | localSFL = new TStorageFileList; 68 | *localSFL = fdb; 69 | FillRuleList(LastFileIndex); 70 | FileFr->OnValuesChange = OnFrameValuesChange; 71 | 72 | // mail 73 | ToInterface(&MainCfg.Letter); 74 | 75 | PageControl->TabIndex = LastTabIndex; 76 | 77 | *AppParams >> (TStringGrid *)DrawGrid; 78 | } 79 | //--------------------------------------------------------------------------- 80 | void __fastcall TSetupForm::FormDestroy(TObject *Sender) 81 | { 82 | SetupForm = NULL; 83 | 84 | LastTabIndex = PageControl->TabIndex; 85 | if( DrawGrid->Row > 0 ) 86 | LastFileIndex = DrawGrid->Row - 1; 87 | delete localSFL; 88 | localSFL = NULL; 89 | *AppParams << (TStringGrid *)DrawGrid; 90 | } 91 | //--------------------------------------------------------------------------- 92 | void __fastcall TSetupForm::FillRuleList(int SelectedIndex) 93 | { 94 | DrawGrid->RowCount = 1 + localSFL->Count; 95 | if( DrawGrid->RowCount > 1 ) 96 | { 97 | DrawGrid->FixedRows = 1; 98 | if( DrawGrid->RowCount > SelectedIndex + 1 ) 99 | DrawGrid->Row = SelectedIndex + 1; 100 | else if( DrawGrid->RowCount >= 2 ) 101 | DrawGrid->Row = 1; 102 | } 103 | DrawGrid->OnClick(this); 104 | DrawGrid->Invalidate(); 105 | } 106 | //--------------------------------------------------------------------------- 107 | void __fastcall TSetupForm::OKButtonClick(TObject *Sender) 108 | { 109 | // main 110 | int port; 111 | 112 | if( ! TryStrToInt(UdpPortEdit->Text, port) ) 113 | { 114 | ReportMess2("Invalid udp port number"); 115 | return; 116 | } 117 | if( port < 0 || port >= 65535 ) 118 | { 119 | ReportMess2("Invalid udp port number"); 120 | return; 121 | } 122 | if( UdpInterfaceCB->Text.Length() == 0 ) 123 | { 124 | ReportMess2("Invalid udp listener interface"); 125 | return; 126 | } 127 | if( port != MainCfg.UdpPort ) 128 | bUdpRestart = true; 129 | if( MainCfg.UdpInterface != UdpInterfaceCB->Text ) 130 | bUdpRestart = true; 131 | if( MainCfg.UdpEnable != EnableUdpCB->Checked ) 132 | bUdpRestart = true; 133 | MainCfg.UdpEnable = EnableUdpCB->Checked; 134 | MainCfg.UdpInterface = UdpInterfaceCB->Text; 135 | MainCfg.UdpPort = port; 136 | 137 | if( ! TryStrToInt(TcpPortEdit->Text, port) ) 138 | { 139 | ReportMess2("Invalid tcp port number"); 140 | return; 141 | } 142 | if( port < 0 || port >= 65535 ) 143 | { 144 | ReportMess2("Invalid tcp port number"); 145 | return; 146 | } 147 | if( TcpInterfaceCB->Text.Length() == 0 ) 148 | { 149 | ReportMess2("Invalid tcp listener interface"); 150 | return; 151 | } 152 | if( port != MainCfg.TcpPort ) 153 | bTcpRestart = true; 154 | if( MainCfg.TcpInterface != TcpInterfaceCB->Text ) 155 | bTcpRestart = true; 156 | if( MainCfg.TcpEnable != EnableTcpCB->Checked ) 157 | bTcpRestart = true; 158 | MainCfg.TcpEnable = EnableTcpCB->Checked; 159 | MainCfg.TcpInterface = TcpInterfaceCB->Text; 160 | MainCfg.TcpPort = port; 161 | 162 | MainCfg.b3D = D3CB->Checked; 163 | MainCfg.bWriteRaw = WriteRawCB->Checked; 164 | MainCfg.bReceiveUTF8 = ReceiveUTF8CB->Checked; 165 | 166 | // files 167 | *fdb = localSFL; 168 | 169 | // mail 170 | if( ! FromInterface(&MainCfg.Letter) ) 171 | return; 172 | 173 | ModalResult = mrOk; 174 | } 175 | //--------------------------------------------------------------------------- 176 | bool TSetupForm::FromInterface(TLetter * p) 177 | { 178 | p->server = serverEdit->Text; 179 | 180 | int port; 181 | if( ! TryStrToInt(portEdit->Text, port) ) 182 | { 183 | ReportMess2("Invalid smtp server port number"); 184 | return false; 185 | } 186 | if( port < 0 || port >= 65535 ) 187 | { 188 | ReportMess2("Invalid smtp server port number"); 189 | return false; 190 | } 191 | 192 | p->port = port; 193 | p->username = usernameEdit->Text; 194 | p->password = passwordEdit->Text; 195 | p->ssl = (TSmtpSSLType)sslComboBox->ItemIndex; 196 | 197 | p->sender = senderEdit->Text; 198 | p->sender_name = sender_nameEdit->Text; 199 | p->recipient = recipientEdit->Text; 200 | p->subject = subjectEdit->Text; 201 | p->message = messageMemo->Text; 202 | return true; 203 | } 204 | //--------------------------------------------------------------------------- 205 | void TSetupForm::ToInterface(TLetter * p) 206 | { 207 | serverEdit->Text = p->server; 208 | portEdit->Text = p->port; 209 | usernameEdit->Text = p->username; 210 | passwordEdit->Text = p->password; 211 | sslComboBox->ItemIndex = p->ssl; 212 | 213 | senderEdit->Text = p->sender; 214 | sender_nameEdit->Text = p->sender_name; 215 | recipientEdit->Text = p->recipient; 216 | subjectEdit->Text = p->subject; 217 | messageMemo->Text = p->message; 218 | } 219 | //--------------------------------------------------------------------------- 220 | void __fastcall TSetupForm::SmtpSelClick(TObject *Sender) 221 | { 222 | TLetter l; 223 | l.SetPredefinedServer( (TSmtpServerType)((TSpeedButton *)Sender)->Tag ); 224 | serverEdit->Text = l.server; 225 | portEdit->Text = l.port; 226 | sslComboBox->ItemIndex = l.ssl; 227 | } 228 | //--------------------------------------------------------------------------- 229 | void __fastcall TSetupForm::pmInsertClick(TObject *Sender) 230 | { 231 | String s; 232 | switch( ((TMenuItem *)Sender)->Tag ) 233 | { 234 | case 0: s = "{time}"; break; 235 | case 1: s = "{ip}"; break; 236 | case 2: s = "{host}"; break; 237 | case 3: s = "{facility}"; break; 238 | case 4: s = "{priority}"; break; 239 | case 5: s = "{tag}"; break; 240 | case 6: s = "{message}"; break; 241 | } 242 | 243 | if( ActiveControl == messageMemo ) 244 | messageMemo->Text = messageMemo->Text + s; 245 | 246 | if( ActiveControl == subjectEdit ) 247 | subjectEdit->Text = subjectEdit->Text + s; 248 | } 249 | //--------------------------------------------------------------------------- 250 | void __fastcall TSetupForm::InsertToMessageButtonClick(TObject *Sender) 251 | { 252 | POINT p = InsertMemoButton->ClientOrigin; 253 | InsertPopupMenu->Popup(p.x, p.y + InsertMemoButton->Height); 254 | ActiveControl = messageMemo; 255 | } 256 | //--------------------------------------------------------------------------- 257 | void __fastcall TSetupForm::InsertSubjectButtonClick(TObject *Sender) 258 | { 259 | POINT p = InsertSubjectButton->ClientOrigin; 260 | InsertPopupMenu->Popup(p.x, p.y + InsertSubjectButton->Height); 261 | ActiveControl = subjectEdit; 262 | } 263 | //--------------------------------------------------------------------------- 264 | static void OnTestSendMail(TLetter * l) 265 | { 266 | if( l->result ) 267 | ReportMess2("Test message sent successfully"); 268 | else 269 | ReportError2(String("Error sent test message:\n") + l->error); 270 | 271 | if( SetupForm ) 272 | { 273 | SetupForm->TestButton->Enabled = true; 274 | SetupForm->TestButton->Caption = "Send test message"; 275 | } 276 | } 277 | //--------------------------------------------------------------------------- 278 | void __fastcall TSetupForm::TestButtonClick(TObject *Sender) 279 | { 280 | TSyslogMessage m; 281 | m.SourceAddr = "127.0.0.1"; 282 | m.Facility = "daemon"; 283 | m.Priority = "err"; 284 | m.DateStr = "Dec 1 13:56:04"; 285 | m.HostName = "host1"; 286 | m.Tag = "proxy[6452]"; 287 | m.Msg = "Host or domain name not found"; 288 | 289 | TLetter l; 290 | if( ! FromInterface(&l) ) 291 | return; 292 | l.subject = m.Format(l.subject); 293 | l.message = m.Format(l.message); 294 | l.callback = OnTestSendMail; 295 | TSendmailThread::Send(&SendmailThread, &l); 296 | 297 | SetupForm->TestButton->Enabled = false; 298 | SetupForm->TestButton->Caption = "waiting for smtp server answer..."; 299 | } 300 | //--------------------------------------------------------------------------- 301 | void __fastcall TSetupForm::FormCloseQuery(TObject *Sender, bool &CanClose) 302 | { 303 | CanClose = CancelButton->Enabled; 304 | } 305 | //--------------------------------------------------------------------------- 306 | void __fastcall TSetupForm::AddFileButtonClick(TObject *Sender) 307 | { 308 | TStorageFile * p = new TStorageFile; 309 | p->number = localSFL->GetNewNumber(); 310 | localSFL->Add(p); 311 | DrawGrid->RowCount = 1 + localSFL->Count; 312 | DrawGrid->Row = DrawGrid->RowCount - 1; 313 | DrawGrid->FixedRows = 1; 314 | } 315 | //--------------------------------------------------------------------------- 316 | void __fastcall TSetupForm::DelFileButtonClick(TObject *Sender) 317 | { 318 | if( DrawGrid->RowCount < 2 ) 319 | return; 320 | int ARow = DrawGrid->Row - 1; 321 | // Deleting default file "syslog" not allowed 322 | if( ARow == 0 ) 323 | return; 324 | localSFL->Del(ARow); 325 | DrawGrid->RowCount = 1 + localSFL->Count; 326 | DrawGrid->OnClick(this); 327 | } 328 | //--------------------------------------------------------------------------- 329 | void __fastcall TSetupForm::DrawGridClick(TObject *Sender) 330 | { 331 | if( DrawGrid->Row < 1 ) 332 | { 333 | FileFr->Visible = false; 334 | } 335 | else 336 | { 337 | FileFr->Visible = true; 338 | FileFr->SetDefaultFile(DrawGrid->Row == 1); 339 | 340 | int ARow = DrawGrid->Row - 1; 341 | TStorageFile * p = localSFL->Get(ARow); 342 | if( p ) 343 | FileFr->ToDialog(p); 344 | } 345 | } 346 | //--------------------------------------------------------------------------- 347 | void __fastcall TSetupForm::DrawGridDrawCell(TObject *Sender, int ACol, 348 | int ARow, TRect &Rect, TGridDrawState State) 349 | { 350 | TCanvas * c = ((TStringGrid *)Sender)->Canvas; 351 | String s; 352 | 353 | if( ARow==0 ) // Grid title 354 | { 355 | switch( ACol ) 356 | { 357 | case 0: s = " File"; break; 358 | case 1: s = " Rotation"; break; 359 | } 360 | } 361 | else 362 | { 363 | TStorageFile * p = localSFL->Get(ARow-1); 364 | if( p ) 365 | { 366 | if( ACol == 0 ) 367 | s = String(" ") + p->GetDescription(); 368 | else if( ACol == 1 ) 369 | s = String(" ") + p->GetRotationDescription(); 370 | } 371 | } 372 | int x = Rect.Left + 2; 373 | int y = Rect.Top + ((Rect.Bottom - Rect.Top - c->TextHeight(s)) / 2); 374 | c->TextRect(Rect, x, y, s); 375 | } 376 | //--------------------------------------------------------------------------- 377 | void __fastcall TSetupForm::OnFrameValuesChange(TObject *Sender) 378 | { 379 | if( DrawGrid->Row < 1 ) 380 | return; 381 | int ARow = DrawGrid->Row - 1; 382 | TStorageFile * p = localSFL->Get(ARow); 383 | if( p ) 384 | { 385 | FileFr->FromDialog(p); 386 | DrawGrid->Invalidate(); 387 | } 388 | } 389 | //--------------------------------------------------------------------------- 390 | 391 | -------------------------------------------------------------------------------- /source/setup.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef setupH 3 | #define setupH 4 | //--------------------------------------------------------------------------- 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "fileframe.h" 14 | //--------------------------------------------------------------------------- 15 | class TSetupForm : public TForm 16 | { 17 | __published: // IDE-managed Components 18 | TBitBtn *OKButton; 19 | TBitBtn *CancelButton; 20 | TPageControl *PageControl; 21 | TTabSheet *TabSheet1; 22 | TTabSheet *TabSheet2; 23 | TGroupBox *GroupBox1; 24 | TCheckBox *AutoStartCB; 25 | TGroupBox *GroupBox2; 26 | TLabel *Label3; 27 | TEdit *serverEdit; 28 | TLabel *Label4; 29 | TEdit *portEdit; 30 | TLabel *Label5; 31 | TEdit *usernameEdit; 32 | TLabel *Label6; 33 | TEdit *passwordEdit; 34 | TComboBox *sslComboBox; 35 | TLabel *Label7; 36 | TGroupBox *GroupBox3; 37 | TLabel *Label8; 38 | TEdit *senderEdit; 39 | TEdit *sender_nameEdit; 40 | TLabel *Label9; 41 | TLabel *Label10; 42 | TEdit *recipientEdit; 43 | TLabel *Label11; 44 | TEdit *subjectEdit; 45 | TMemo *messageMemo; 46 | TLabel *Label12; 47 | TLabel *Label13; 48 | TSpeedButton *SpeedButton1; 49 | TSpeedButton *SpeedButton2; 50 | TSpeedButton *SpeedButton3; 51 | TSpeedButton *SpeedButton4; 52 | TSpeedButton *InsertMemoButton; 53 | TPopupMenu *InsertPopupMenu; 54 | TMenuItem *time1; 55 | TMenuItem *ip1; 56 | TMenuItem *host1; 57 | TMenuItem *facility1; 58 | TMenuItem *priority1; 59 | TMenuItem *tag1; 60 | TMenuItem *message1; 61 | TSpeedButton *TestButton; 62 | TSpeedButton *InsertSubjectButton; 63 | TGroupBox *UdpGroupBox; 64 | TCheckBox *EnableUdpCB; 65 | TLabel *Label1; 66 | TComboBox *UdpInterfaceCB; 67 | TEdit *UdpPortEdit; 68 | TGroupBox *TcpGroupBox; 69 | TCheckBox *EnableTcpCB; 70 | TLabel *Label2; 71 | TComboBox *TcpInterfaceCB; 72 | TEdit *TcpPortEdit; 73 | TTabSheet *TabSheet3; 74 | TGroupBox *FilesGB; 75 | TSpeedButton *AddFileButton; 76 | TSpeedButton *DelFileButton; 77 | TDrawGrid *DrawGrid; 78 | TFileFr *FileFr; 79 | TGroupBox *GroupBox4; 80 | TCheckBox *D3CB; 81 | TGroupBox *GroupBox5; 82 | TCheckBox *WriteRawCB; 83 | TCheckBox *ReceiveUTF8CB; 84 | void __fastcall OKButtonClick(TObject *Sender); 85 | void __fastcall SmtpSelClick(TObject *Sender); 86 | void __fastcall pmInsertClick(TObject *Sender); 87 | void __fastcall InsertToMessageButtonClick(TObject *Sender); 88 | void __fastcall TestButtonClick(TObject *Sender); 89 | void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose); 90 | void __fastcall InsertSubjectButtonClick(TObject *Sender); 91 | void __fastcall AddFileButtonClick(TObject *Sender); 92 | void __fastcall DelFileButtonClick(TObject *Sender); 93 | void __fastcall DrawGridClick(TObject *Sender); 94 | void __fastcall DrawGridDrawCell(TObject *Sender, int ACol, int ARow, 95 | TRect &Rect, TGridDrawState State); 96 | void __fastcall FormDestroy(TObject *Sender); 97 | private: // User declarations 98 | TStorageFileList * localSFL; 99 | static int LastFileIndex; 100 | 101 | public: 102 | bool bUdpRestart; 103 | bool bTcpRestart; 104 | static int LastTabIndex; 105 | 106 | public: // User declarations 107 | __fastcall TSetupForm(TComponent* Owner); 108 | bool FromInterface(TLetter * p); 109 | void ToInterface(TLetter * p); 110 | void __fastcall FillRuleList(int SelectedIndex); 111 | void __fastcall OnFrameValuesChange(TObject *Sender); 112 | }; 113 | //--------------------------------------------------------------------------- 114 | extern PACKAGE TSetupForm *SetupForm; 115 | //--------------------------------------------------------------------------- 116 | #endif 117 | -------------------------------------------------------------------------------- /source/sound.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/source/sound.cpp -------------------------------------------------------------------------------- /source/sound.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/source/sound.h -------------------------------------------------------------------------------- /source/syslog.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "syslog.h" 6 | 7 | CODE prioritynames[] = 8 | { 9 | { "alert", LOG_ALERT }, 10 | { "crit", LOG_CRIT }, 11 | { "debug", LOG_DEBUG }, 12 | { "emerg", LOG_EMERG }, 13 | { "err", LOG_ERR }, 14 | { "error", LOG_ERR }, /* DEPRECATED */ 15 | { "info", LOG_INFO }, 16 | { "none", INTERNAL_NOPRI }, /* INTERNAL */ 17 | { "notice", LOG_NOTICE }, 18 | { "panic", LOG_EMERG }, /* DEPRECATED */ 19 | { "warning", LOG_WARNING }, 20 | { "warn", LOG_WARNING }, /* DEPRECATED */ 21 | { NULL, -1 } 22 | }; 23 | 24 | 25 | CODE facilitynames[] = 26 | { 27 | { "auth", LOG_AUTH }, 28 | { "authpriv", LOG_AUTHPRIV }, 29 | { "cron", LOG_CRON }, 30 | { "daemon", LOG_DAEMON }, 31 | { "ftp", LOG_FTP }, 32 | { "kern", LOG_KERN }, 33 | { "lpr", LOG_LPR }, 34 | { "mail", LOG_MAIL }, 35 | { "mark", INTERNAL_MARK }, /* INTERNAL */ 36 | { "news", LOG_NEWS }, 37 | { "security", LOG_AUTH }, /* DEPRECATED */ 38 | { "syslog", LOG_SYSLOG }, 39 | { "user", LOG_USER }, 40 | { "uucp", LOG_UUCP }, 41 | { "ntp", LOG_NTP }, 42 | { "logaudit", LOG_LOGAUDIT }, 43 | { "logalert", LOG_LOGALERT }, 44 | { "clock", LOG_CLOCK }, 45 | { "local0", LOG_LOCAL0 }, 46 | { "local1", LOG_LOCAL1 }, 47 | { "local2", LOG_LOCAL2 }, 48 | { "local3", LOG_LOCAL3 }, 49 | { "local4", LOG_LOCAL4 }, 50 | { "local5", LOG_LOCAL5 }, 51 | { "local6", LOG_LOCAL6 }, 52 | { "local7", LOG_LOCAL7 }, 53 | { NULL, -1 } 54 | }; 55 | 56 | //--------------------------------------------------------------------------- 57 | const char * getcodetext(int value, CODE * codetable) 58 | { 59 | CODE *i; 60 | if (value >= 0) 61 | for (i = codetable; i->c_val != -1; i++) 62 | if (i->c_val == value) 63 | return (i->c_name); 64 | return ""; 65 | }; 66 | //--------------------------------------------------------------------------- 67 | int gettextcode(const char * value, CODE * codetable) 68 | { 69 | CODE *i; 70 | if (value) 71 | for (i = codetable; i->c_val != -1; i++) 72 | if (strcmp(i->c_name, value)==0) 73 | return (i->c_val); 74 | return -1; 75 | } 76 | //--------------------------------------------------------------------------- 77 | void GetPriorities(TStrings * s) 78 | { 79 | s->BeginUpdate(); 80 | s->Clear(); 81 | for(int pri=0; priAddObject(getcodetext(pri, prioritynames), (TObject *)pri); 83 | s->EndUpdate(); 84 | } 85 | //--------------------------------------------------------------------------- 86 | void GetFacilities(TStrings * s) 87 | { 88 | s->BeginUpdate(); 89 | s->Clear(); 90 | for(int fac=0; facAddObject(getcodetext(fac<<3, facilitynames), (TObject *)fac); 92 | s->EndUpdate(); 93 | } 94 | //--------------------------------------------------------------------------- 95 | #pragma package(smart_init) 96 | -------------------------------------------------------------------------------- /source/syslog.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef syslogH 3 | #define syslogH 4 | 5 | /* 6 | * priorities/facilities are encoded into a single 32-bit quantity, where the 7 | * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility 8 | * (0-big number). Both the priorities and the facilities map roughly 9 | * one-to-one to strings in the syslogd(8) source code. This mapping is 10 | * included in this file. 11 | * 12 | * priorities (these are ordered) 13 | */ 14 | #define LOG_EMERG 0 /* system is unusable */ 15 | #define LOG_ALERT 1 /* action must be taken immediately */ 16 | #define LOG_CRIT 2 /* critical conditions */ 17 | #define LOG_ERR 3 /* error conditions */ 18 | #define LOG_WARNING 4 /* warning conditions */ 19 | #define LOG_NOTICE 5 /* normal but significant condition */ 20 | #define LOG_INFO 6 /* informational */ 21 | #define LOG_DEBUG 7 /* debug-level messages */ 22 | 23 | #define LOG_NPRIORITIES 8 /* current number of priorities */ 24 | 25 | #define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ 26 | /* extract priority number */ 27 | #define LOG_PRI(p) ((p) & LOG_PRIMASK) 28 | #define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) 29 | 30 | #define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ 31 | 32 | /* facility codes */ 33 | #define LOG_KERN (0<<3) /* kernel messages */ 34 | #define LOG_USER (1<<3) /* random user-level messages */ 35 | #define LOG_MAIL (2<<3) /* mail system */ 36 | #define LOG_DAEMON (3<<3) /* system daemons */ 37 | #define LOG_AUTH (4<<3) /* security/authorization messages */ 38 | #define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ 39 | #define LOG_LPR (6<<3) /* line printer subsystem */ 40 | #define LOG_NEWS (7<<3) /* network news subsystem */ 41 | #define LOG_UUCP (8<<3) /* UUCP subsystem */ 42 | #define LOG_CRON (9<<3) /* clock daemon */ 43 | #define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ 44 | #define LOG_FTP (11<<3) /* ftp daemon */ 45 | #define LOG_NTP (12<<3) /* NTP subsystem */ 46 | #define LOG_LOGAUDIT (13<<3) /* log audit */ 47 | #define LOG_LOGALERT (14<<3) /* log alert */ 48 | #define LOG_CLOCK (15<<3) /* clock daemon */ 49 | #define LOG_LOCAL0 (16<<3) /* reserved for local use */ 50 | #define LOG_LOCAL1 (17<<3) /* reserved for local use */ 51 | #define LOG_LOCAL2 (18<<3) /* reserved for local use */ 52 | #define LOG_LOCAL3 (19<<3) /* reserved for local use */ 53 | #define LOG_LOCAL4 (20<<3) /* reserved for local use */ 54 | #define LOG_LOCAL5 (21<<3) /* reserved for local use */ 55 | #define LOG_LOCAL6 (22<<3) /* reserved for local use */ 56 | #define LOG_LOCAL7 (23<<3) /* reserved for local use */ 57 | 58 | #define LOG_NFACILITIES 24 /* current number of facilities */ 59 | #define LOG_FACMASK 0x03f8 /* mask to extract facility part */ 60 | /* extract facility number */ 61 | #define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) 62 | 63 | /* mark "facility" */ 64 | #define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) 65 | 66 | typedef struct _code { 67 | char *c_name; 68 | int c_val; 69 | } CODE; 70 | 71 | extern CODE prioritynames[]; 72 | extern CODE facilitynames[]; 73 | 74 | const char * getcodetext(int value, CODE * codetable); 75 | int gettextcode(const char * value, CODE * codetable); 76 | 77 | void GetPriorities(TStrings * s); 78 | void GetFacilities(TStrings * s); 79 | //--------------------------------------------------------------------------- 80 | #endif 81 | -------------------------------------------------------------------------------- /source/tcpcon.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "tcpcon.h" 6 | #include "cfg.h" 7 | #include "messageform.h" 8 | #include "server.h" 9 | #include "fdb.h" 10 | 11 | //--------------------------------------------------------------------------- 12 | TSyslogdTcpConn::TSyslogdTcpConn(MSocket * p) 13 | { 14 | Socket = p; 15 | Data = NULL; 16 | Size = 0; 17 | DataSize = 0; 18 | } 19 | //--------------------------------------------------------------------------- 20 | TSyslogdTcpConn::~TSyslogdTcpConn() 21 | { 22 | if( Data ) 23 | delete [] Data; 24 | if( Socket ) 25 | { 26 | Socket->Close(); 27 | delete Socket; 28 | } 29 | } 30 | //--------------------------------------------------------------------------- 31 | BYTE * TSyslogdTcpConn::GetBufferSize(int NeedFreeSize) 32 | { 33 | if( Size - DataSize < NeedFreeSize ) 34 | { 35 | Size = NeedFreeSize + DataSize; 36 | BYTE * p = new BYTE[Size]; 37 | if( Data ) 38 | { 39 | memmove(p, Data, DataSize); 40 | delete [] Data; 41 | } 42 | Data = p; 43 | } 44 | return Data + DataSize; 45 | } 46 | //--------------------------------------------------------------------------- 47 | //--------------------------------------------------------------------------- 48 | //--------------------------------------------------------------------------- 49 | 50 | extern TStorageFileList * fdb; 51 | extern TMainCfg MainCfg; 52 | bool WriteToLogError(String fmt, ...); 53 | bool WriteToLogRawMessage(char * p); 54 | void PrintSB(int i, String s); 55 | bool ProcessMessageRules(TSyslogMessage * p); 56 | 57 | MTCPServer * tcp = NULL; 58 | TList * tcp_cons = NULL; 59 | //--------------------------------------------------------------------------- 60 | bool TcpServerCreate(void) 61 | { 62 | tcp_cons = new TList(); 63 | tcp = new MTCPServer(); 64 | if( tcp->GetError() ) 65 | { 66 | String err = String("Error tcp: ") + tcp->GetErrorMessageEng(); 67 | WriteToLogError(String("ERROR\t") + err); 68 | ReportError2(err); 69 | return false; 70 | } 71 | else 72 | return true; 73 | } 74 | //--------------------------------------------------------------------------- 75 | void TcpServerDestroy(void) 76 | { 77 | delete tcp; 78 | tcp = NULL; 79 | delete tcp_cons; 80 | tcp_cons = NULL; 81 | } 82 | //--------------------------------------------------------------------------- 83 | void TcpServerStart(void) 84 | { 85 | if( ! MainCfg.TcpEnable ) 86 | { 87 | TcpPrintStatus(); 88 | return; 89 | } 90 | 91 | if( tcp->Open(MainCfg.TcpInterface.c_str(), MainCfg.TcpPort) ) 92 | { 93 | TcpPrintStatus(); 94 | } 95 | else 96 | { 97 | TcpPrintStatus(); 98 | String err = String("Error tcp: ") + tcp->GetErrorMessageEng() + 99 | " [tcp port " + IntToStr(MainCfg.TcpPort) + "]"; 100 | WriteToLogError(String("ERROR\t") + err); 101 | ReportError2(err); 102 | } 103 | } 104 | //--------------------------------------------------------------------------- 105 | void TcpServerStop(void) 106 | { 107 | if( tcp->IsOpen() ) 108 | { 109 | TcpCloseAllConnections(); 110 | tcp->Close(); 111 | TcpPrintStatus(); 112 | } 113 | } 114 | //--------------------------------------------------------------------------- 115 | void TcpAccept(void) 116 | { 117 | // Have new TCP connection ? 118 | MSocket * p = tcp->GetClient(1); // 1 msec 119 | if( p ) 120 | { 121 | // yes 122 | TcpAddConnection(p); 123 | } 124 | else 125 | { 126 | if( tcp->errcode ) 127 | WriteToLogError("ERROR\tTCP connection: %s code=%ld", 128 | tcp->GetErrorMessageEng().c_str(), tcp->errcode); 129 | } 130 | } 131 | //--------------------------------------------------------------------------- 132 | void TcpAddConnection(MSocket * p) 133 | { 134 | tcp_cons->Add( new TSyslogdTcpConn(p) ); 135 | TcpPrintStatus(); 136 | } 137 | //--------------------------------------------------------------------------- 138 | void TcpDeleteConnection(int index) 139 | { 140 | if( index<0 || index>=tcp_cons->Count ) 141 | return; 142 | delete (TSyslogdTcpConn *)tcp_cons->Items[index]; 143 | tcp_cons->Delete(index); 144 | TcpPrintStatus(); 145 | } 146 | //--------------------------------------------------------------------------- 147 | void TcpCloseAllConnections(void) 148 | { 149 | // Close all existing connections 150 | for(int i=0; iCount; i++) 151 | { 152 | delete (TSyslogdTcpConn *)tcp_cons->Items[i]; 153 | } 154 | tcp_cons->Clear(); 155 | } 156 | //--------------------------------------------------------------------------- 157 | int TcpGetConnectionsCount(void) 158 | { 159 | return tcp_cons->Count; 160 | } 161 | //--------------------------------------------------------------------------- 162 | void TcpPrintStatus(void) 163 | { 164 | if( ! MainCfg.TcpEnable ) 165 | { 166 | PrintSB(1, "TCP: server disabled"); 167 | } 168 | else 169 | { 170 | if( tcp->IsOpen() ) 171 | PrintSB(1, String("TCP ") + tcp->GetLocalAddrPort() + 172 | " [" + IntToStr(TcpGetConnectionsCount()) + "]"); 173 | else 174 | PrintSB(1, "TCP: server not started"); 175 | } 176 | } 177 | //--------------------------------------------------------------------------- 178 | void TcpReceiveMessage(void) 179 | { 180 | int rl; 181 | TSyslogdTcpConn * c; 182 | MSocket * p; 183 | for(int i=0; iCount; i++) 184 | { 185 | c = (TSyslogdTcpConn *)tcp_cons->Items[i]; 186 | p = c->Socket; 187 | 188 | if( p->Poll(true, false, false, 0) ) // wait 0 msec 189 | { 190 | rl = p->ReadLength(); 191 | 192 | if( rl > 0 ) 193 | { 194 | // Ready to receive rl bytes 195 | if( p->Read(c->GetBufferSize(rl), rl) ) 196 | { 197 | c->DataSize += rl; 198 | } 199 | else 200 | { 201 | if( p->bytes > 0 && p->bytes < rl ) 202 | { 203 | c->DataSize += p->bytes; 204 | WriteToLogError("WARNING\tTCP received %ld, wait %ld, error=%ld", p->bytes, rl, p->errcode); 205 | } 206 | else 207 | { 208 | if( p->errcode==WSAESHUTDOWN ) 209 | { 210 | WriteToLogError("WARNING\tTCP shutdown from %s", p->GetRemoteAddrPort().c_str()); 211 | TcpDeleteConnection(i--); 212 | continue; 213 | } 214 | else 215 | { 216 | WriteToLogError("ERROR\tTCP read(rl=%ld) from %s\tbytes=%ld error=%ld", 217 | p->GetRemoteAddrPort().c_str(), rl, p->bytes, p->errcode); 218 | } 219 | } 220 | } 221 | } 222 | else // Readed 0 bytes ! 223 | { 224 | BYTE b; 225 | if( ! p->Read(&b, 1) ) 226 | { 227 | if( p->errcode==0 && p->bytes==0 ) 228 | { 229 | // Good disconnect 230 | TcpDeleteConnection(i--); 231 | continue; 232 | } 233 | else 234 | { 235 | WriteToLogError("ERROR\tTCP error from %s: %s [%d]", 236 | p->GetRemoteAddrPort().c_str(), p->GetErrorMessageEng().c_str(), p->errcode); 237 | TcpDeleteConnection(i--); 238 | continue; 239 | } 240 | } 241 | } 242 | } // Poll 243 | if( c->DataSize > 0 ) 244 | { 245 | int i, start; 246 | for(i=start=0; iDataSize; i++) 247 | { 248 | // find end of message 249 | if( c->Data[i]==0 || c->Data[i]=='\n' || c->Data[i]=='\r' ) 250 | { 251 | if( start < i ) 252 | { 253 | // process messages 254 | 255 | // NULL terminate syslog message 256 | c->Data[i] = 0; 257 | 258 | WriteToLogRawMessage((char *)(c->Data + start)); 259 | 260 | TSyslogMessage sm; 261 | sm.FromStringSyslogd((char *)(c->Data + start), i - start, &c->Socket->destAddr); 262 | if( ProcessMessageRules(&sm) ) 263 | { 264 | // option is not set: "Ignore (do not save to the default file "syslog")" 265 | TStorageFile * sf = fdb->Get(0); 266 | if( sf ) 267 | if( ! sf->Save( sm.ToString() ) ) 268 | WriteToLogError("ERROR\tSave message to file: %s", sf->GetFileName().c_str()); 269 | } 270 | } 271 | start = i + 1; 272 | } 273 | } 274 | // half of syslog message in c->Data ? 275 | if( start < i ) 276 | { 277 | // Save to buffer start 278 | memmove(c->Data, c->Data + start, i - start); 279 | c->DataSize = i - start; 280 | } 281 | else 282 | { 283 | c->DataSize = 0; 284 | } 285 | } 286 | } // End for 287 | } 288 | //--------------------------------------------------------------------------- 289 | #pragma package(smart_init) 290 | 291 | -------------------------------------------------------------------------------- /source/tcpcon.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef tcpconH 3 | #define tcpconH 4 | #include "tcpserv.h" 5 | 6 | //--------------------------------------------------------------------------- 7 | class TSyslogdTcpConn 8 | { 9 | public: 10 | MSocket * Socket; 11 | BYTE * Data; 12 | int Size; // Total buffer size 13 | int DataSize; // Data size in buffer 14 | 15 | public: 16 | TSyslogdTcpConn(MSocket * p); 17 | ~TSyslogdTcpConn(); 18 | BYTE * GetBufferSize(int NeedFreeSize); 19 | }; 20 | //--------------------------------------------------------------------------- 21 | extern MTCPServer * tcp; 22 | extern TList * tcp_cons; 23 | 24 | // server control 25 | bool TcpServerCreate(void); 26 | void TcpServerDestroy(void); 27 | void TcpServerStart(void); 28 | void TcpServerStop(void); 29 | void TcpAccept(void); 30 | void TcpPrintStatus(void); 31 | 32 | // connection control 33 | void TcpAddConnection(MSocket * p); 34 | void TcpDeleteConnection(int index); 35 | void TcpCloseAllConnections(void); 36 | int TcpGetConnectionsCount(void); 37 | 38 | void TcpReceiveMessage(void); 39 | //--------------------------------------------------------------------------- 40 | #endif 41 | -------------------------------------------------------------------------------- /source/udpcon.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "udp.h" // udp server 6 | #include "cfg.h" 7 | #include "messageform.h" 8 | #include "server.h" 9 | #include "udpcon.h" 10 | #include "fdb.h" 11 | 12 | TUDP * udp = NULL; 13 | 14 | extern TStorageFileList * fdb; 15 | extern TMainCfg MainCfg; 16 | bool WriteToLogError(String fmt, ...); 17 | bool WriteToLogRawMessage(char * p); 18 | void PrintSB(int i, String s); 19 | bool ProcessMessageRules(TSyslogMessage * p); 20 | 21 | //--------------------------------------------------------------------------- 22 | bool UdpServerCreate(void) 23 | { 24 | udp = new TUDP(); 25 | if( udp->GetError() ) 26 | { 27 | String err = String("Error udp: ") + udp->GetErrorMessageEng(); 28 | WriteToLogError(String("ERROR\t") + err); 29 | ReportError2(err); 30 | return false; 31 | } 32 | else 33 | return true; 34 | } 35 | //--------------------------------------------------------------------------- 36 | void UdpServerDestroy(void) 37 | { 38 | delete udp; 39 | udp = NULL; 40 | } 41 | //--------------------------------------------------------------------------- 42 | void UdpServerStart(void) 43 | { 44 | if( ! MainCfg.UdpEnable ) 45 | { 46 | PrintSB(0, "UDP: server disabled"); 47 | return; 48 | } 49 | 50 | if( udp->Open(MainCfg.UdpInterface.c_str(), MainCfg.UdpPort, "0.0.0.0", 0) ) 51 | { 52 | PrintSB(0, String("UDP ") + udp->GetLocalAddrPort()); 53 | } 54 | else 55 | { 56 | PrintSB(0, "UDP: server not started"); 57 | String err = String("Error udp: ") + udp->GetErrorMessageEng() + 58 | " [udp port " + IntToStr(MainCfg.UdpPort) + "]"; 59 | WriteToLogError(String("ERROR\t") + err); 60 | ReportError2(err); 61 | } 62 | } 63 | //--------------------------------------------------------------------------- 64 | void UdpServerStop(void) 65 | { 66 | if( udp->IsOpen() ) 67 | { 68 | PrintSB(0, "UDP: server not started"); 69 | udp->Close(); 70 | } 71 | } 72 | //--------------------------------------------------------------------------- 73 | void UdpReceiveMessage(void) 74 | { 75 | if( ! udp ) 76 | return; 77 | if( ! udp->IsOpen() ) 78 | return; 79 | 80 | struct sockaddr_in a; 81 | DWORD rl; 82 | while( (rl = udp->ReadLength()) > 0 ) 83 | { 84 | BYTE * ReceiveBuffer = new BYTE[rl + 1]; 85 | if( ! udp->ReadFrom(ReceiveBuffer, rl, (struct sockaddr *)&a) ) 86 | { 87 | if( udp->GetWSAError() == MYERROR_READCOUNT ) 88 | ; // Good error :) In the receive buffer still have UDP packets 89 | else 90 | { 91 | WriteToLogError(String("ERROR\tudp: ") + udp->GetErrorMessageEng()); 92 | } 93 | } 94 | 95 | if( udp->bytes > 0 ) 96 | { 97 | // NULL terminate syslog message 98 | ReceiveBuffer[udp->bytes] = 0; 99 | 100 | WriteToLogRawMessage((char *)ReceiveBuffer); 101 | 102 | TSyslogMessage sm; 103 | sm.FromStringSyslogd((char *)ReceiveBuffer, udp->bytes, &a); 104 | 105 | if( ProcessMessageRules(&sm) ) 106 | { 107 | // option is not set: "Ignore (do not save to the default file "syslog")" 108 | TStorageFile * sf = fdb->Get(0); 109 | if( sf ) 110 | if( ! sf->Save( sm.ToString() ) ) 111 | WriteToLogError("ERROR\tSave message to file: %s", sf->GetFileName().c_str()); 112 | } 113 | } 114 | delete [] ReceiveBuffer; 115 | } 116 | } 117 | //--------------------------------------------------------------------------- 118 | #pragma package(smart_init) 119 | -------------------------------------------------------------------------------- /source/udpcon.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef udpconH 3 | #define udpconH 4 | 5 | //--------------------------------------------------------------------------- 6 | bool UdpServerCreate(void); 7 | void UdpServerDestroy(void); 8 | void UdpServerStart(void); 9 | void UdpServerStop(void); 10 | void UdpReceiveMessage(void); 11 | //--------------------------------------------------------------------------- 12 | #endif 13 | -------------------------------------------------------------------------------- /sourcecommon/File.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/File.cpp -------------------------------------------------------------------------------- /sourcecommon/File.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/File.h -------------------------------------------------------------------------------- /sourcecommon/MibAccess.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/MibAccess.cpp -------------------------------------------------------------------------------- /sourcecommon/MibAccess.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////// 2 | // FILE : MibAccess.h 3 | // 4 | // 5 | 6 | #ifndef _SNMP_ACCESS_H_ 7 | #define _SNMP_ACCESS_H_ 8 | 9 | #include "snmp.h" 10 | 11 | ////////////////////////////////////////////////////////////// 12 | // Defenitoin of pointers to the four functions in the Mib Dll 13 | // 14 | typedef BOOL (WINAPI *pSnmpExtensionInit)( 15 | IN DWORD dwTimeZeroReference, 16 | OUT HANDLE *hPollForTrapEvent, 17 | OUT AsnObjectIdentifier *supportedView); 18 | 19 | typedef BOOL (WINAPI *pSnmpExtensionTrap)( 20 | OUT AsnObjectIdentifier *enterprise, 21 | OUT AsnInteger *genericTrap, 22 | OUT AsnInteger *specificTrap, 23 | OUT AsnTimeticks *timeStamp, 24 | OUT RFC1157VarBindList *variableBindings); 25 | 26 | typedef BOOL (WINAPI *pSnmpExtensionQuery)( 27 | IN BYTE requestType, 28 | IN OUT RFC1157VarBindList *variableBindings, 29 | OUT AsnInteger *errorStatus, 30 | OUT AsnInteger *errorIndex); 31 | 32 | typedef BOOL (WINAPI *pSnmpExtensionInitEx)(OUT AsnObjectIdentifier *supportedView); 33 | 34 | 35 | class MibExtLoad 36 | { 37 | public: 38 | MibExtLoad(LPSTR MibDllName); 39 | ~MibExtLoad(); 40 | BOOL Init(DWORD dwTimeZeroReference,HANDLE *hPollForTrapEvent,AsnObjectIdentifier *supportedView); 41 | BOOL InitEx(AsnObjectIdentifier *supportedView); 42 | BOOL Query(BYTE requestType,OUT RFC1157VarBindList *variableBindings, 43 | AsnInteger *errorStatus,AsnInteger *errorIndex); 44 | 45 | BOOL Trap(AsnObjectIdentifier *enterprise, AsnInteger *genericTrap, 46 | AsnInteger *specificTrap, AsnTimeticks *timeStamp, 47 | RFC1157VarBindList *variableBindings); 48 | 49 | private: 50 | HINSTANCE m_hInst; 51 | pSnmpExtensionInit m_Init; 52 | pSnmpExtensionInitEx m_InitEx; 53 | pSnmpExtensionQuery m_Query; 54 | pSnmpExtensionTrap m_Trap; 55 | }; 56 | 57 | 58 | class MibII: public MibExtLoad 59 | { 60 | public: 61 | MibII(); 62 | ~MibII(); 63 | Init(); 64 | BOOL GetIPAddress(UINT IpArray[],UINT &IpArraySize); 65 | BOOL GetIPMask(UINT IpArray[],UINT &IpArraySize); 66 | }; 67 | 68 | 69 | #endif -------------------------------------------------------------------------------- /sourcecommon/base64.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "base64.h" 4 | 5 | static const char base64_chars[] = 6 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 7 | "abcdefghijklmnopqrstuvwxyz" 8 | "0123456789+/"; 9 | 10 | char * 11 | base64_encode(const unsigned char *input, int length) 12 | { 13 | /* http://www.adp-gmbh.ch/cpp/common/base64.html */ 14 | int i=0, j, s=0; 15 | unsigned char char_array_3[3], char_array_4[4]; 16 | 17 | int b64len = (length+2 - ((length+2)%3))*4/3; 18 | char *b64str = new char[b64len + 1]; 19 | 20 | while (length--) { 21 | char_array_3[i++] = *(input++); 22 | if (i == 3) { 23 | char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; 24 | char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); 25 | char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); 26 | char_array_4[3] = char_array_3[2] & 0x3f; 27 | 28 | for (i = 0; i < 4; i++) 29 | b64str[s++] = base64_chars[char_array_4[i]]; 30 | 31 | i = 0; 32 | } 33 | } 34 | if (i) { 35 | for (j = i; j < 3; j++) 36 | char_array_3[j] = '\0'; 37 | 38 | char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; 39 | char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); 40 | char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); 41 | char_array_4[3] = char_array_3[2] & 0x3f; 42 | 43 | for (j = 0; j < i + 1; j++) 44 | b64str[s++] = base64_chars[char_array_4[j]]; 45 | 46 | while (i++ < 3) 47 | b64str[s++] = '='; 48 | } 49 | b64str[b64len] = '\0'; 50 | 51 | return b64str; 52 | } 53 | 54 | static inline bool is_base64(unsigned char c) { 55 | return (isalnum(c) || (c == '+') || (c == '/')); 56 | } 57 | 58 | unsigned char * 59 | base64_decode(const char *input, int length, int *outlen) 60 | { 61 | int i = 0; 62 | int j; 63 | int r = 0; 64 | int idx = 0; 65 | unsigned char char_array_4[4], char_array_3[3]; 66 | unsigned char *output = new unsigned char[length*3/4]; 67 | 68 | while (length-- && input[idx] != '=') { 69 | //skip invalid or padding based chars 70 | if (!is_base64(input[idx])) { 71 | idx++; 72 | continue; 73 | } 74 | char_array_4[i++] = input[idx++]; 75 | if (i == 4) { 76 | for (i = 0; i < 4; i++) 77 | char_array_4[i] = strchr(base64_chars, char_array_4[i]) - base64_chars; 78 | 79 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 80 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 81 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 82 | 83 | for (i = 0; (i < 3); i++) 84 | output[r++] = char_array_3[i]; 85 | i = 0; 86 | } 87 | } 88 | 89 | if (i) { 90 | for (j = i; j <4; j++) 91 | char_array_4[j] = 0; 92 | 93 | for (j = 0; j <4; j++) 94 | char_array_4[j] = strchr(base64_chars, char_array_4[j]) - base64_chars; 95 | 96 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 97 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 98 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 99 | 100 | for (j = 0; (j < i - 1); j++) 101 | output[r++] = char_array_3[j]; 102 | } 103 | 104 | *outlen = r; 105 | 106 | return output; 107 | } 108 | -------------------------------------------------------------------------------- /sourcecommon/base64.h: -------------------------------------------------------------------------------- 1 | #ifndef base64H 2 | #define base64H 3 | 4 | char * base64_encode(const unsigned char *input, int length); 5 | unsigned char * base64_decode(const char *input, int length, int *outlen); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /sourcecommon/critsection.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "critsection.h" 3 | 4 | //--------------------------------------------------------------------------- 5 | TCritSection::TCritSection() 6 | { 7 | InitializeCriticalSection( &busy ); 8 | } 9 | //--------------------------------------------------------------------------- 10 | TCritSection::~TCritSection() 11 | { 12 | DeleteCriticalSection( &busy ); 13 | } 14 | //--------------------------------------------------------------------------- 15 | void TCritSection::Enter(void) 16 | { 17 | EnterCriticalSection( &busy ); 18 | } 19 | //--------------------------------------------------------------------------- 20 | BOOL TCritSection::TryEnter(void) 21 | { 22 | return TryEnterCriticalSection( &busy ); 23 | } 24 | //--------------------------------------------------------------------------- 25 | void TCritSection::Leave(void) 26 | { 27 | LeaveCriticalSection( &busy ); 28 | } 29 | //--------------------------------------------------------------------------- 30 | //--------------------------------------------------------------------------- 31 | //--------------------------------------------------------------------------- 32 | TCritSectionEnter::TCritSectionEnter(TCritSection * _pcs) : pcs(_pcs) 33 | { 34 | if( pcs ) 35 | pcs->Enter(); 36 | } 37 | //--------------------------------------------------------------------------- 38 | TCritSectionEnter::~TCritSectionEnter() 39 | { 40 | if( pcs ) 41 | pcs->Leave(); 42 | } 43 | //--------------------------------------------------------------------------- 44 | 45 | -------------------------------------------------------------------------------- /sourcecommon/critsection.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/critsection.h -------------------------------------------------------------------------------- /sourcecommon/gr.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "gr.h" 6 | 7 | //--------------------------------------------------------------------------- 8 | static double hue2rgb(double p, double q, double t){ 9 | if(t < 0) t += 1; 10 | if(t > 1) t -= 1; 11 | if(t < 1.0/6) return p + (q - p) * 6 * t; 12 | if(t < 1.0/2) return q; 13 | if(t < 2.0/3) return p + (q - p) * (2.0/3 - t) * 6; 14 | return p; 15 | } 16 | //--------------------------------------------------------------------------- 17 | TColor fromHSL(double h,double s,double l){ 18 | double r, g, b; 19 | 20 | if(s == 0){ 21 | r = g = b = l; 22 | } else{ 23 | double q = l < 0.5 ? l * (s + 1) : l + s - l * s; 24 | double p = 2 * l - q; 25 | r = hue2rgb(p, q, h + 1.0/3); 26 | g = hue2rgb(p, q, h); 27 | b = hue2rgb(p, q, h - 1.0/3); 28 | } 29 | 30 | int rr=r*255+0.5; 31 | int gg=g*255+0.5; 32 | int bb=b*255+0.5; 33 | 34 | return (TColor) RGB(rr, gg, bb); 35 | } 36 | //--------------------------------------------------------------------------- 37 | void toHSL(TColor color,double *hh,double *ss,double *ll){ 38 | try // catch division by zero 39 | { 40 | double r=1.0*GetRValue(color)/255; 41 | double g=1.0*GetGValue(color)/255; 42 | double b=1.0*GetBValue(color)/255; 43 | 44 | double max=r; if(g>max) max=g; if(b>max) max=b; 45 | double min=r; if(g 0.5 ? d / (2 - max - min) : d / (max + min); 54 | 55 | if(max==r) h = (g - b) / d + (g < b ? 6 : 0); 56 | else if(max==g) h = (b - r) / d + 2; 57 | else h = (r - g) / d + 4; 58 | 59 | h /= 6; 60 | } 61 | 62 | if(hh) *hh=h; 63 | if(ss) *ss=s; 64 | if(ll) *ll=l; 65 | } 66 | catch(...) 67 | {} 68 | } 69 | //--------------------------------------------------------------------------- 70 | void __fastcall FillVolume(TCanvas * c, TRect rect, TColor color, 71 | double brightness_range_koeff) 72 | { 73 | int w = rect.right - rect.left; 74 | int h = rect.bottom - rect.top; 75 | 76 | if( ! c || h == 0 ) 77 | return; 78 | 79 | double hh, ss, ll; 80 | // ColorToRGB: clBtnFace const to color value 81 | toHSL((TColor)ColorToRGB(color), &hh, &ss, &ll); 82 | 83 | double brightness_range = (ll > 0.5) ? (1.0 - ll) : ll; 84 | brightness_range *= brightness_range_koeff; 85 | 86 | double brightness_step = brightness_range * 2 / h; 87 | 88 | // save 89 | TBrushStyle bs = c->Brush->Style; 90 | TColor bc = c->Brush->Color; 91 | 92 | c->Brush->Style = bsSolid; 93 | 94 | for(int i=0; iBrush->Color = fromHSL(hh, ss, ll + brightness_range - brightness_step * i); 97 | c->FillRect(Rect(rect.Left, rect.Top + i, rect.Left + w, rect.Top + i + 1)); 98 | } 99 | 100 | // restore 101 | c->Brush->Color = bc; 102 | c->Brush->Style = bs; 103 | } 104 | //--------------------------------------------------------------------------- 105 | #pragma package(smart_init) 106 | -------------------------------------------------------------------------------- /sourcecommon/gr.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef grH 3 | #define grH 4 | 5 | //--------------------------------------------------------------------------- 6 | // gradient fill 7 | void __fastcall FillVolume(TCanvas * c, TRect rect, TColor color, double brightness_range_koeff=0.5); 8 | //--------------------------------------------------------------------------- 9 | #endif 10 | -------------------------------------------------------------------------------- /sourcecommon/gridcolumns.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/gridcolumns.cpp -------------------------------------------------------------------------------- /sourcecommon/gridcolumns.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/gridcolumns.h -------------------------------------------------------------------------------- /sourcecommon/inif.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/inif.cpp -------------------------------------------------------------------------------- /sourcecommon/inif.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/inif.h -------------------------------------------------------------------------------- /sourcecommon/letter.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "utils.h" 6 | #include "letter.h" 7 | 8 | //--------------------------------------------------------------------------- 9 | TLetter::TLetter() 10 | { 11 | port = 25; 12 | ssl = SMTP_SSL_OFF; 13 | callback = NULL; 14 | closure = NULL; 15 | data = NULL; 16 | } 17 | //--------------------------------------------------------------------------- 18 | TLetter::TLetter(const TLetter & l) 19 | { 20 | *this = l; 21 | } 22 | //--------------------------------------------------------------------------- 23 | void TLetter::operator = (const TLetter & l) 24 | { 25 | server = l.server; 26 | port = l.port; 27 | username = l.username; 28 | password = l.password; 29 | ssl = l.ssl; 30 | 31 | sender = l.sender; 32 | sender_name = l.sender_name; 33 | recipient = l.recipient; 34 | subject = l.subject; 35 | message = l.message; 36 | 37 | data = l.data; 38 | 39 | callback = l.callback; 40 | closure = l.closure; 41 | 42 | error = l.error; 43 | result = l.result; 44 | } 45 | //--------------------------------------------------------------------------- 46 | void TLetter::SetPredefinedServer(TSmtpServerType st) 47 | { 48 | switch( st ) 49 | { 50 | case SMTP_MAIL_RU: 51 | server = "smtp.mail.ru"; 52 | port = 465; 53 | ssl = SMTP_SSL_ON; 54 | break; 55 | case SMTP_YANDEX_RU: 56 | server = "smtp.yandex.ru"; 57 | port = 465; 58 | ssl = SMTP_SSL_ON; 59 | break; 60 | case SMTP_ICLOUD: 61 | server = "smtp.mail.me.com"; 62 | port = 587; 63 | ssl = SMTP_SSL_TLS; 64 | break; 65 | case SMTP_GOOGLE: 66 | server = "smtp.gmail.com"; 67 | port = 465; 68 | ssl = SMTP_SSL_ON; 69 | break; 70 | } 71 | } 72 | //--------------------------------------------------------------------------- 73 | void TLetter::Save(XMLElementEx * p) 74 | { 75 | // smtp server params 76 | p->ws("server", server); 77 | p->wi("port", port); 78 | p->ws("username", username); 79 | p->ws("password", SecurePassword(password)); 80 | p->wi("ssl", ssl); 81 | 82 | // message params 83 | p->ws("sender", sender); 84 | p->ws("sender_name", sender_name); 85 | p->ws("recipient", recipient); 86 | p->ws("subject", subject); 87 | p->ws("message", message); 88 | } 89 | //--------------------------------------------------------------------------- 90 | void TLetter::Load(XMLElementEx * p) 91 | { 92 | // smtp server params 93 | server = p->rs("server"); 94 | port = p->ri("port", 25); 95 | username = p->rs("username"); 96 | password = UnsecurePassword(p->rs("password")); 97 | ssl = (TSmtpSSLType)p->ri("ssl", SMTP_SSL_OFF); 98 | 99 | // message params 100 | sender = p->rs("sender"); 101 | sender_name = p->rs("sender_name"); 102 | recipient = p->rs("recipient"); 103 | subject = p->rs("subject"); 104 | message = p->rs("message"); 105 | } 106 | //--------------------------------------------------------------------------- 107 | #pragma package(smart_init) 108 | -------------------------------------------------------------------------------- /sourcecommon/letter.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef letterH 3 | #define letterH 4 | 5 | #include "maxxml.h" 6 | 7 | // Predefined smtp server profiles: 8 | enum TSmtpServerType { SMTP_MAIL_RU, SMTP_YANDEX_RU, SMTP_ICLOUD, SMTP_GOOGLE }; 9 | // SMTP server type 10 | enum TSmtpSSLType { 11 | SMTP_SSL_OFF, // do not use ssl 12 | SMTP_SSL_ON, // use ssl immediately (usually port 465) 13 | SMTP_SSL_TLS // use TLS after the server allowed (usually port 587) 14 | }; 15 | 16 | //--------------------------------------------------------------------------- 17 | class TLetter 18 | { 19 | public: 20 | // smtp server params 21 | String server; 22 | int port; 23 | String username; 24 | String password; 25 | TSmtpSSLType ssl; 26 | 27 | // message params 28 | String sender; 29 | String sender_name; 30 | String recipient; 31 | String subject; 32 | String message; 33 | 34 | // user data 35 | void * data; 36 | 37 | public: 38 | void (* callback)(TLetter * self); 39 | void __fastcall (__closure * closure)(TLetter * self); 40 | 41 | // The result of sending a letter 42 | bool result; // true - sent false - NOT sent 43 | String error; // description of the error 44 | 45 | public: 46 | TLetter(); 47 | TLetter(const TLetter & l); 48 | void operator = (const TLetter & l); 49 | void SetPredefinedServer(TSmtpServerType st); 50 | void Save(XMLElementEx * p); 51 | void Load(XMLElementEx * p); 52 | }; 53 | //--------------------------------------------------------------------------- 54 | #endif 55 | -------------------------------------------------------------------------------- /sourcecommon/maxxml.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | 5 | #include "maxxml.h" 6 | 7 | //--------------------------------------------------------------------------- 8 | AnsiString XMLElementEx::ConvertToSave(const String s) 9 | { 10 | String rv; 11 | for(int i=1, l=s.Length(); i<=l; i++) 12 | { 13 | if( s[i] != '\r' ) 14 | rv += s[i]; 15 | } 16 | return UTF8Encode(rv); 17 | } 18 | //--------------------------------------------------------------------------- 19 | String XMLElementEx::ConvertAfterLoad(const AnsiString s) 20 | { 21 | String rv = UTF8Decode(s); 22 | // add carriage return to all line feed 23 | String rv2; 24 | for(int i=1, l=rv.Length(); i<=l; i++) 25 | { 26 | if( rv[i]=='\n' ) 27 | rv2 += '\r'; 28 | rv2 += rv[i]; 29 | } 30 | return rv2; 31 | } 32 | //--------------------------------------------------------------------------- 33 | bool XMLElementEx::exist(const AnsiString name) 34 | { 35 | return FirstChildElement(name.c_str()) != NULL; 36 | } 37 | //--------------------------------------------------------------------------- 38 | String XMLElementEx::rs(const AnsiString name, String defval) 39 | { 40 | XMLElement * p = FirstChildElement(name.c_str()); 41 | if( p ) 42 | { 43 | return ConvertAfterLoad(AnsiString(p->GetText())); 44 | } 45 | return defval; 46 | } 47 | //--------------------------------------------------------------------------- 48 | void XMLElementEx::rs(const AnsiString name, TStrings * val) 49 | { 50 | val->Clear(); 51 | for(XMLElement * p = FirstChildElement(name.c_str()); 52 | p; 53 | p = p->NextSiblingElement(name.c_str())) 54 | { 55 | val->Add( ConvertAfterLoad(AnsiString(p->GetText())) ); 56 | } 57 | } 58 | //--------------------------------------------------------------------------- 59 | int XMLElementEx::ri(const AnsiString name, int defval) 60 | { 61 | int rv; 62 | XMLElement * p = FirstChildElement(name.c_str()); 63 | if( p ) if( p->QueryIntText(&rv) == XML_SUCCESS ) return rv; 64 | return defval; 65 | } 66 | //--------------------------------------------------------------------------- 67 | double XMLElementEx::rd(const AnsiString name, double defval) 68 | { 69 | double rv; 70 | XMLElement * p = FirstChildElement(name.c_str()); 71 | if( p ) if( p->QueryDoubleText(&rv) == XML_SUCCESS ) return rv; 72 | return defval; 73 | } 74 | //--------------------------------------------------------------------------- 75 | bool XMLElementEx::rb(const AnsiString name, bool defval) 76 | { 77 | bool rv; 78 | XMLElement * p = FirstChildElement(name.c_str()); 79 | if( p ) if( p->QueryBoolText(&rv) == XML_SUCCESS ) return rv; 80 | return defval; 81 | } 82 | //--------------------------------------------------------------------------- 83 | void XMLElementEx::ws(const AnsiString name, String val) 84 | { 85 | XMLElement * p = FirstChildElement(name.c_str()); 86 | if( ! p ) 87 | { 88 | p = GetDocument()->NewElement(name.c_str()); 89 | InsertEndChild(p); 90 | } 91 | p->SetText( ConvertToSave(val).c_str() ); 92 | } 93 | //--------------------------------------------------------------------------- 94 | void XMLElementEx::ws(const AnsiString name, TStrings * val) 95 | { 96 | XMLElement * p; 97 | while( (p = FirstChildElement(name.c_str())) != NULL ) 98 | DeleteChild(p); 99 | 100 | for(int i=0, l=val->Count; iNewElement(name.c_str()); 103 | InsertEndChild(p); 104 | p->SetText( ConvertToSave(val->Strings[i]).c_str() ); 105 | } 106 | } 107 | //--------------------------------------------------------------------------- 108 | void XMLElementEx::wi(const AnsiString name, int val) 109 | { 110 | XMLElement * p = FirstChildElement(name.c_str()); 111 | if( ! p ) 112 | { 113 | XMLElement * e = GetDocument()->NewElement(name.c_str()); 114 | InsertEndChild(e); 115 | e->SetText(val); 116 | } 117 | else 118 | { 119 | p->SetText(val); 120 | } 121 | } 122 | //--------------------------------------------------------------------------- 123 | void XMLElementEx::wd(const AnsiString name, double val) 124 | { 125 | XMLElement * p = FirstChildElement(name.c_str()); 126 | if( ! p ) 127 | { 128 | XMLElement * e = GetDocument()->NewElement(name.c_str()); 129 | InsertEndChild(e); 130 | e->SetText(val); 131 | } 132 | else 133 | { 134 | p->SetText(val); 135 | } 136 | } 137 | //--------------------------------------------------------------------------- 138 | void XMLElementEx::wb(const AnsiString name, bool val) 139 | { 140 | XMLElement * p = FirstChildElement(name.c_str()); 141 | if( ! p ) 142 | { 143 | XMLElement * e = GetDocument()->NewElement(name.c_str()); 144 | InsertEndChild(e); 145 | e->SetText(val); 146 | } 147 | else 148 | { 149 | p->SetText(val); 150 | } 151 | } 152 | //--------------------------------------------------------------------------- 153 | #pragma package(smart_init) 154 | -------------------------------------------------------------------------------- /sourcecommon/maxxml.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef maxxmlH 3 | #define maxxmlH 4 | 5 | #include "tinyxml2.h" 6 | using namespace tinyxml2; 7 | 8 | // xml read / write helper class 9 | class XMLElementEx : public XMLElement 10 | { 11 | private: 12 | // delete all carriage returns \r from string s 13 | // convert to utf8 14 | AnsiString ConvertToSave(const String s); 15 | // add carriage return to all line feed 16 | // convert from utf8 17 | String ConvertAfterLoad(const AnsiString s); 18 | 19 | public: 20 | bool exist(const AnsiString name); 21 | 22 | // Read value from element named name 23 | String rs(const AnsiString name, String defval=String()); 24 | void rs(const AnsiString name, TStrings * val); 25 | int ri(const AnsiString name, int defval=0); 26 | double rd(const AnsiString name, double defval=0.0); 27 | bool rb(const AnsiString name, bool defval=false); 28 | 29 | // Write value to element named name 30 | void ws(const AnsiString name, String val); 31 | void ws(const AnsiString name, TStrings * val); 32 | void wi(const AnsiString name, int val); 33 | void wd(const AnsiString name, double val); 34 | void wb(const AnsiString name, bool val); 35 | }; 36 | //--------------------------------------------------------------------------- 37 | #endif 38 | -------------------------------------------------------------------------------- /sourcecommon/messageform.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/messageform.cpp -------------------------------------------------------------------------------- /sourcecommon/messageform.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/messageform.h -------------------------------------------------------------------------------- /sourcecommon/saveini.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/saveini.cpp -------------------------------------------------------------------------------- /sourcecommon/saveini.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/saveini.h -------------------------------------------------------------------------------- /sourcecommon/savepar.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/savepar.cpp -------------------------------------------------------------------------------- /sourcecommon/savepar.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/savepar.h -------------------------------------------------------------------------------- /sourcecommon/sendmail.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/sendmail.cpp -------------------------------------------------------------------------------- /sourcecommon/sendmail.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/sendmail.h -------------------------------------------------------------------------------- /sourcecommon/tcpserv.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/tcpserv.cpp -------------------------------------------------------------------------------- /sourcecommon/tcpserv.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/tcpserv.h -------------------------------------------------------------------------------- /sourcecommon/udp.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/udp.cpp -------------------------------------------------------------------------------- /sourcecommon/udp.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/udp.h -------------------------------------------------------------------------------- /sourcecommon/unilist.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | template 3 | TUniList::TUniList(void) 4 | { 5 | l = new TList; 6 | pcs = NULL; 7 | } 8 | //--------------------------------------------------------------------------- 9 | template 10 | TUniList::~TUniList(void) 11 | { 12 | Clear(); 13 | delete l; 14 | l = NULL; 15 | if( pcs ) 16 | { 17 | delete pcs; 18 | pcs = NULL; 19 | } 20 | } 21 | //--------------------------------------------------------------------------- 22 | template 23 | void TUniList::EnableMultiTreading(void) 24 | { 25 | if( pcs ) 26 | return; 27 | pcs = new TCritSection(); 28 | } 29 | //--------------------------------------------------------------------------- 30 | template 31 | void TUniList::Clear(void) 32 | { 33 | TCritSectionEnter cse(pcs); 34 | /* 35 | for(int i=0, c=l->Count; iItems[i]; 37 | */ 38 | l->Clear(); 39 | } 40 | //--------------------------------------------------------------------------- 41 | template 42 | int TUniList::Add(T * p) 43 | { 44 | TCritSectionEnter cse(pcs); 45 | return l->Add(p); 46 | } 47 | //--------------------------------------------------------------------------- 48 | template 49 | void TUniList::Insert(int i, T * p) 50 | { 51 | TCritSectionEnter cse(pcs); 52 | l->Insert(i, p); 53 | } 54 | //--------------------------------------------------------------------------- 55 | template 56 | void TUniList::Delete(T * p) 57 | { 58 | TCritSectionEnter cse(pcs); 59 | l->Remove(p); 60 | /* 61 | delete p; 62 | */ 63 | } 64 | //--------------------------------------------------------------------------- 65 | template 66 | T * TUniList::Extract(int i) 67 | { 68 | TCritSectionEnter cse(pcs); 69 | T * rv = NULL; 70 | if( i>=0 && iCount ) 71 | { 72 | rv = (T *)l->Items[i]; 73 | l->Delete(i); 74 | } 75 | return rv; 76 | } 77 | //--------------------------------------------------------------------------- 78 | template 79 | T * TUniList::ExtractLast(void) 80 | { 81 | TCritSectionEnter cse(pcs); 82 | T * rv = NULL; 83 | int c = l->Count; 84 | if( c > 0 ) 85 | { 86 | rv = (T *)l->Items[c-1]; 87 | l->Delete(c-1); 88 | } 89 | return rv; 90 | } 91 | //--------------------------------------------------------------------------- 92 | template 93 | bool TUniList::Contains(T * p) 94 | { 95 | TCritSectionEnter cse(pcs); 96 | return l->IndexOf(p) >= 0; 97 | } 98 | //--------------------------------------------------------------------------- 99 | template 100 | T * TUniList::Get(int i) 101 | { 102 | TCritSectionEnter cse(pcs); 103 | //return GetNB(i); 104 | if( i>=0 && iCount ) 105 | return (T *)l->Items[i]; 106 | return NULL; 107 | } 108 | //--------------------------------------------------------------------------- 109 | template 110 | void TUniList::Set(int i, T * p) 111 | { 112 | TCritSectionEnter cse(pcs); 113 | if( i>=0 && iCount ) 114 | l->Items[i] = p; 115 | } 116 | //--------------------------------------------------------------------------- 117 | template 118 | int TUniList::GetCount(void) 119 | { 120 | TCritSectionEnter cse(pcs); 121 | return l->Count; 122 | } 123 | //--------------------------------------------------------------------------- 124 | template 125 | T * TUniList::GetNB(int i) 126 | { 127 | if( i>=0 && iCount ) 128 | return (T *)l->Items[i]; 129 | return NULL; 130 | } 131 | //--------------------------------------------------------------------------- 132 | template 133 | void TUniList::SetNB(int i, T * p) 134 | { 135 | if( i>=0 && iCount ) 136 | l->Items[i] = p; 137 | } 138 | //--------------------------------------------------------------------------- 139 | template 140 | int TUniList::GetCountNB(void) 141 | { 142 | return l->Count; 143 | } 144 | //--------------------------------------------------------------------------- 145 | template 146 | bool TUniList::SetBusy(bool b) 147 | { 148 | if( ! pcs ) 149 | return false; 150 | if( b ) 151 | pcs->Enter(); 152 | else 153 | pcs->Leave(); 154 | return true; 155 | } 156 | //--------------------------------------------------------------------------- 157 | 158 | -------------------------------------------------------------------------------- /sourcecommon/unilist.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/unilist.h -------------------------------------------------------------------------------- /sourcecommon/utils.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/utils.cpp -------------------------------------------------------------------------------- /sourcecommon/utils.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/sourcecommon/utils.h -------------------------------------------------------------------------------- /visualsyslog.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | //--------------------------------------------------------------------------- 5 | USEFORM("sourcecommon\messageform.cpp", MessageForm); 6 | USEFORM("source\main.cpp", MainForm); 7 | USEFORM("source\setup.cpp", SetupForm); 8 | USEFORM("source\aboutbox.cpp", AboutBoxForm); 9 | USEFORM("source\messmatchframe.cpp", MessMatchFr); /* TFrame: File Type */ 10 | USEFORM("source\messstyleframe.cpp", MessStyleFr); /* TFrame: File Type */ 11 | USEFORM("source\formhl.cpp", HighlightForm); 12 | USEFORM("source\AlarmForm.cpp", ShowAlarmForm); 13 | USEFORM("source\messprocessframe.cpp", MessProcessFr); /* TFrame: File Type */ 14 | USEFORM("source\formprocess.cpp", ProcessForm); 15 | USEFORM("source\fileframe.cpp", FileFr); /* TFrame: File Type */ 16 | USEFORM("source\matchform.cpp", FilterForm); 17 | //--------------------------------------------------------------------------- 18 | extern bool bHideToTray; 19 | //--------------------------------------------------------------------------- 20 | WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR ParamStr, int) 21 | { 22 | bHideToTray = SameText(ParamStr, "tray"); 23 | try 24 | { 25 | Application->Initialize(); 26 | SetApplicationMainFormOnTaskBar(Application, true); 27 | Application->Title = "Visual Syslog Server"; 28 | Application->CreateForm(__classid(TMainForm), &MainForm); 29 | Application->Run(); 30 | } 31 | catch (Exception &exception) 32 | { 33 | Application->ShowException(&exception); 34 | } 35 | catch (...) 36 | { 37 | try 38 | { 39 | throw Exception(""); 40 | } 41 | catch (Exception &exception) 42 | { 43 | Application->ShowException(&exception); 44 | } 45 | } 46 | return 0; 47 | } 48 | //--------------------------------------------------------------------------- 49 | -------------------------------------------------------------------------------- /visualsyslog.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/visualsyslog.ico -------------------------------------------------------------------------------- /visualsyslog.iss: -------------------------------------------------------------------------------- 1 | #define pname 'Visual Syslog Server' 2 | #define pver GetFileVersion('Release\visualsyslog.exe') 3 | 4 | [Setup] 5 | AppName={#pname} 6 | AppVerName={#pname} {#pver} 7 | VersionInfoVersion={#pver} 8 | 9 | AppPublisher=Max Belkov 10 | AppPublisherURL=https://github.com/MaxBelkov/visualsyslog 11 | AppComments=Syslog Server for Windows with a graphical user interface 12 | AppCopyright=GNU GENERAL PUBLIC LICENSE Version 2 13 | DefaultDirName={pf}\visualsyslog\ 14 | DefaultGroupName=Visual Syslog 15 | OutputBaseFilename=visualsyslog_setup 16 | Compression=lzma/max 17 | SolidCompression=yes 18 | SetupIconFile=visualsyslog.ico 19 | 20 | [Tasks] 21 | Name: Firewall; Description: "Add an exception to the Windows Firewall"; 22 | 23 | [Files] 24 | Source: "Release\visualsyslog.exe"; DestDir: "{app}"; 25 | Source: "changelog.txt"; DestDir: "{app}"; 26 | ; ssl/tls support for smtp server 27 | Source: "install\libeay32.dll"; DestDir: "{app}"; 28 | Source: "install\libssl32.dll"; DestDir: "{app}"; 29 | Source: "install\ssleay32.dll"; DestDir: "{app}"; 30 | ; default config files 31 | Source: "install\highlight.xml"; DestDir: "{localappdata}\visualsyslog"; Flags: onlyifdoesntexist 32 | Source: "install\cfg.xml"; DestDir: "{localappdata}\visualsyslog"; Flags: onlyifdoesntexist 33 | Source: "install\process.xml"; DestDir: "{localappdata}\visualsyslog"; Flags: onlyifdoesntexist 34 | Source: "install\alarm.wav"; DestDir: "{localappdata}\visualsyslog"; Flags: onlyifdoesntexist 35 | 36 | [Icons] 37 | Name: "{group}\Visual Syslog server"; Filename: "{app}\visualsyslog.exe"; WorkingDir: "{app}"; 38 | Name: "{userdesktop}\Visual Syslog server"; Filename: "{app}\visualsyslog.exe"; WorkingDir: "{app}"; 39 | 40 | [Run] 41 | ; Below vista 42 | Filename: "{sys}\netsh.exe"; Parameters: "firewall delete allowedprogram ""{app}\visualsyslog.exe"""; Flags: runhidden; OnlyBelowVersion: 0,6.0; Tasks: Firewall; 43 | Filename: "{sys}\netsh.exe"; Parameters: "firewall add allowedprogram ""{app}\visualsyslog.exe"" ""Visual Syslog Server"" ENABLE"; Flags: runhidden; OnlyBelowVersion: 0,6.0; Tasks: Firewall; 44 | ; Vista and later 45 | Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall delete rule name=""Visual Syslog Server"" program=""{app}\visualsyslog.exe"""; Flags: runhidden; MinVersion: 0,6.0.6000; Tasks: Firewall; 46 | Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""Visual Syslog Server"" program=""{app}\visualsyslog.exe"" dir=in action=allow enable=yes"; Flags: runhidden; MinVersion: 0,6.0.6000; Tasks: Firewall; 47 | 48 | Filename: "{app}\visualsyslog.exe"; Description: "Launch Visual Syslog Server"; Flags: postinstall nowait skipifsilent 49 | 50 | [UninstallRun] 51 | ; Below vista 52 | Filename: "{sys}\netsh.exe"; Parameters: "firewall delete allowedprogram ""{app}\visualsyslog.exe"""; Flags: runhidden; OnlyBelowVersion: 0,6.0; Tasks: Firewall; 53 | ; Vista and later 54 | Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall delete rule name=""Visual Syslog Server"" program=""{app}\visualsyslog.exe"""; Flags: runhidden; MinVersion: 0,6.0.6000; Tasks: Firewall; 55 | -------------------------------------------------------------------------------- /visualsyslog.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxBelkov/visualsyslog/af0900313bfdc1faca335eef0db9d093c114520c/visualsyslog.res --------------------------------------------------------------------------------