~ubuntu-branches/ubuntu/natty/knetfilter/natty

« back to all changes in this revision

Viewing changes to src/knat_route.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Angel Ramos
  • Date: 2005-03-17 17:40:18 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050317174018-qychsdv5ifzdmblo
Tags: 3.3.1-3
Renamed mark.xpm icon. Solved conflict with kxsldbg. Thanks again
Javier. (Closes: #301886, #302534).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
  /*
 
2
 
 
3
  knetfilter v 3.0.3
 
4
 
 
5
  Copyright (C) 2002 Luigi Genoni
 
6
                     venom@sns.it
 
7
  */
 
8
  
 
9
 
 
10
#include <qlayout.h>
 
11
#include <qmultilinedit.h>
 
12
#include <qkeycode.h>
 
13
#include <qbuttongroup.h>
 
14
#include <qlabel.h>
 
15
#include <qstring.h>
 
16
#include <qstrlist.h>
 
17
#include <strings.h>
 
18
 
 
19
#include "knat.h"
 
20
 
 
21
// List Rotes
 
22
 
 
23
void knetfilter::startlistRoutes() {
 
24
 
 
25
  routes.clearArguments();
 
26
 
 
27
  if ( system_has_tc == 1 )
 
28
    {
 
29
      routes << "ip" << "route" << "show";
 
30
    }
 
31
  else
 
32
    {
 
33
      routes << "route" << "-n";
 
34
    }
 
35
 
 
36
  bool success=routes.start(KProcess::NotifyOnExit,
 
37
                            KProcess::AllOutput);
 
38
  if (success)
 
39
    {
 
40
      statusbar->message(i18n("Running..."), 2000);
 
41
    }
 
42
  else
 
43
    {
 
44
      if ( system_has_tc == 1 )
 
45
        {
 
46
          statusbar->message(i18n("Couldn't start ip"), 2000);
 
47
        }
 
48
      else
 
49
        {
 
50
          statusbar->message(i18n("Couldn't start route"), 2000);
 
51
        }
 
52
    };
 
53
 
 
54
};
 
55
 
 
56
// List Addresses
 
57
 
 
58
void knetfilter::startlistAddr() {
 
59
 
 
60
  addr.clearArguments();
 
61
 
 
62
  if ( system_has_tc == 1 )
 
63
    {
 
64
      addr << "ip" << "addr" << "show";
 
65
    }
 
66
  else
 
67
    {
 
68
      addr << "ifconfig";
 
69
    }
 
70
 
 
71
  bool success=addr.start(KProcess::NotifyOnExit,
 
72
                         KProcess::AllOutput);
 
73
 
 
74
  if (success)
 
75
    {
 
76
      statusbar->message(i18n("Running..."), 2000);
 
77
    }
 
78
  else
 
79
    {
 
80
      if ( system_has_tc == 1 )
 
81
        {
 
82
          statusbar->message(i18n("Couldn't start ip"), 2000);
 
83
        }
 
84
      else
 
85
        {
 
86
          statusbar->message(i18n("Couldn't start route"), 2000);
 
87
        }
 
88
    };
 
89
 
 
90
};
 
91
 
 
92
//List Route Cache
 
93
 
 
94
void knetfilter::startlistrouteCache() {
 
95
 
 
96
  routecache.clearArguments();
 
97
 
 
98
  routecache << "route" << "-C" << "-n";
 
99
 
 
100
  bool success=routecache.start(KProcess::NotifyOnExit,
 
101
                                KProcess::AllOutput);
 
102
  if (success)
 
103
    {
 
104
      statusbar->message(i18n("Running..."), 2000);
 
105
    }
 
106
  else
 
107
    {
 
108
      statusbar->message(i18n("Couldn't start route"), 2000);
 
109
    };
 
110
  
 
111
};
 
112
 
 
113
void knetfilter::routeRules() {
 
114
  if ( routeList == NULL )
 
115
    {
 
116
      setupConnect();
 
117
 
 
118
      routeList = new KNFWidget();
 
119
      routeList->resize(480,320);
 
120
      routeList->setCaption("Show Routes, IpAddrs, Route Cache");
 
121
 
 
122
      QBoxLayout *top = new QBoxLayout(routeList, QBoxLayout::LeftToRight, 7);
 
123
      QGridLayout *grid = new QGridLayout(7,5);
 
124
      top->addLayout(grid,5);
 
125
 
 
126
      routeBox = new QListBox(routeList);
 
127
      grid->addMultiCellWidget(routeBox,0,5,0,5);
 
128
 
 
129
      QPushButton *btnRoutes = new QPushButton(routeList);
 
130
      btnRoutes->setText("Routes");
 
131
      btnRoutes->setFixedHeight(btnRoutes->sizeHint().height());
 
132
      connect(btnRoutes,SIGNAL(clicked()), this, SLOT(startlistRoutes()));
 
133
      grid->addWidget(btnRoutes,7,0);
 
134
 
 
135
      QPushButton *btnAddr = new QPushButton(routeList);
 
136
      btnAddr->setText("IpAddr");
 
137
      btnAddr->setFixedHeight(btnAddr->sizeHint().height());
 
138
      connect(btnAddr,SIGNAL(clicked()), this, SLOT(startlistAddr()));
 
139
      grid->addWidget(btnAddr,7,1);
 
140
 
 
141
      QPushButton *btnrouteCache = new QPushButton(routeList);
 
142
      btnrouteCache->setText("RT-cache");
 
143
      btnrouteCache->setFixedHeight(btnrouteCache->sizeHint().height());
 
144
      connect(btnrouteCache,SIGNAL(clicked()), this, SLOT(startlistrouteCache()));
 
145
      grid->addWidget(btnrouteCache,7,2);
 
146
 
 
147
      QPushButton *btnClose = new QPushButton(routeList);
 
148
      btnClose->setText("Close");
 
149
      btnClose->setFixedHeight(btnClose->sizeHint().height());
 
150
      connect(btnClose,SIGNAL(clicked()), this, SLOT(closerouteRules()));
 
151
      grid->addWidget(btnClose,7,5);
 
152
      
 
153
            routeList->show();
 
154
            setCentralWidget(routeList);
 
155
    }
 
156
  else
 
157
    {
 
158
      if ( !routeList->isVisible() )
 
159
        {
 
160
          routeList->show();
 
161
        }
 
162
      else
 
163
        {
 
164
          QMessageBox::critical(0,"Warning", "Already Running\n");
 
165
        }
 
166
    }  
 
167
};
 
168
 
 
169
// And so we can also close everything ;)
 
170
 
 
171
void knetfilter::closerouteRules() {
 
172
 
 
173
  routeList->close();
 
174
 
 
175
};
 
176
 
 
177
 
 
178
void knetfilter::listRoutesDone() {
 
179
 
 
180
  if (routes.normalExit() && (routes.exitStatus()==0))
 
181
    statusbar->message(i18n("Listing Routes..."), 2000);
 
182
  else
 
183
    statusbar->message(i18n("Couldn't list Routes"), 2000);
 
184
 
 
185
};
 
186
 
 
187
 
 
188
void knetfilter::listAddrDone() {
 
189
 
 
190
  if (addr.normalExit() && (addr.exitStatus()==0))
 
191
    statusbar->message(i18n("Listing Ip Addresses..."), 2000);
 
192
  else
 
193
    statusbar->message(i18n("Couldn't list Ip Addresses"), 2000);
 
194
 
 
195
};
 
196
 
 
197
 
 
198
void knetfilter::listrouteCacheDone() {
 
199
 
 
200
  if (routecache.normalExit() && (routecache.exitStatus()==0))
 
201
    statusbar->message(i18n("Listing Route Cache..."), 2000);
 
202
  else
 
203
    statusbar->message(i18n("Couldn't list Route Chache"), 2000);
 
204
 
 
205
};
 
206
 
 
207
 
 
208
// set up output
 
209
 
 
210
void knetfilter::listRoutes(KProcess *, char *data, int len) {
 
211
 
 
212
  if (len<0)
 
213
    return;
 
214
  static QString remainder;
 
215
  QString list;
 
216
 
 
217
  char dst[len+1];
 
218
  memmove(dst,data,len);
 
219
  dst[len]=0;
 
220
 
 
221
  list=remainder+dst;
 
222
  QStrList lines;
 
223
  int index=0;
 
224
  int newindex=0;
 
225
 
 
226
  while (1)
 
227
  {
 
228
    newindex=list.find('\n',index);
 
229
    if(newindex==-1) {
 
230
      remainder=list.right(list.length()-index);
 
231
      break;
 
232
    } else {
 
233
      lines.append(list.mid(index,newindex-index));
 
234
      index=newindex+1;
 
235
    };
 
236
  };
 
237
 
 
238
  if(lines.count()>0){
 
239
    routeBox->insertStrList(&lines);
 
240
  };
 
241
 
 
242
  routeBox->insertItem(remainder.data());
 
243
  routeBox->setTopItem(routeBox->count()-routeBox->numItemsVisible());
 
244
};