-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrsview.c
139 lines (132 loc) · 4.76 KB
/
rsview.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
*License:
*“Remote Syslog” is a free application what can be used to view syslog messages.
*Copyright (C) 2017 Tom Slenter
*
*This program is free software: you can redistribute it and/or modify
*it under the terms of the GNU General Public License as published by
*the Free Software Foundation, either version 3 of the License.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*For more information contact the author:
*Name author: Tom Slenter
*E-mail: info@remotesyslog.com
*/
#include <unistd.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <string>
static void show_usage(std::string name)
{
std::cerr << "Usage rsview:\n"
<< "\n"
<< "\t-h,--help\t\t\t\t Display help\n"
<< "\t-s,--search <search string>\t\t Search through logging\n"
<< "\t-v,--view\t\t\t\t View logging\n"
<< "\t-l,--live\t\t\t\t View live logging\n"
<< "\t-ls,--livesearch <search string>\t Search through live logging\n"
<< "\t-t,--testmessage\t\t\t Send a test message\n"
<< "\t-c,--clearlog\t\t\t\t Clear total log archive\n"
<< "\n"
<< "Remote Syslog v1.1.3.3 by T.Slenter\n"
<< "More information: remotesyslog.com\n"
<< std::endl;
}
int setversion ()
{
printf("#Version: 1.1.3.3 #\n");
return(0);
}
int donate ()
{
printf("#Donate XRP: rHdkpJr3qYqBYY3y3S9ZMr4cFGpgP1eM6B #\n");
return(0);
}
inline bool livebanner () {
printf("#################################################\n");
printf("#Remote Syslog by T.Slenter #\n");
printf("#More information: remotesyslog.com #\n");
setversion ();
donate ();
printf("#################################################\n");
printf("\n");
printf("Press ctrl + c to quit\n");
printf("\n");
}
inline bool logbanner () {
printf("#################################################\n");
printf("#Remote Syslog by T.Slenter #\n");
printf("#More information: remotesyslog.com #\n");
setversion ();
donate ();
printf("#################################################\n");
printf("\n");
}
int main(int argc, char* argv[])
{
if (argc < 2) {
show_usage(argv[0]);
return 1;
}
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if ((arg == "-h") || (arg == "--help")) {
show_usage(argv[0]);
return 0;
} else if ((arg == "-s") || (arg == "--search")) {
if (i + 1 < argc) {
logbanner();
printf ("This program was called with search string: \"%s\".\n",argv[++i]);
std::string const command = std::string( "cat /var/log/remote_syslog/remote_syslog.log | grep --color=always " ) + argv[i];
system( command.c_str() );
return 0;
}
} else if ((arg == "-l") || (arg == "--live")) {
livebanner();
system("colortail -n 30 -f /var/log/remote_syslog/remote_syslog.log");
return 0;
} else if ((arg == "-ls") || (arg == "--livesearch")) {
if (i + 1 < argc) {
livebanner();
printf ("This program was called with search string: \"%s\".\n",argv[++i]);
std::string const command = std::string( "tail -n 30 -f /var/log/remote_syslog/remote_syslog.log | grep --color=always " ) + argv[i];
system( command.c_str() );
return 0;
}
} else if ((arg == "-v") || (arg == "--view")) {
logbanner();
system("colortail -n 3000 /var/log/remote_syslog/remote_syslog.log");
return 0;
} else if ((arg == "-t") || (arg == "--testmessage")) {
logbanner();
system("logger -n 127.0.0.1 -d 'This is a UDP test message!'; logger -T -P 514 -n 127.0.0.1 'This is a TCP test message!'");
printf ("Sending test message! Check logging!\n");
printf ("\n");
return 0;
} else if ((arg == "-c") || (arg == "--clearlog")) {
logbanner();
if (getuid()) {
printf("%s", "You must be root!\n");
printf ("\n");
} else {
system("rm -rf /var/log/remote_syslog/remote_syslog.log.*");
printf ("Total logging archive cleared!\n");
printf ("\n");
return 0;
}
} else {
show_usage(argv[0]);
return 1;
}
}
}