summaryrefslogtreecommitdiffstats
path: root/src/knmap.cpp
blob: 1400710e171a048e11cc8c7ae26754f762e1e4d3 (plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/***************************************************************************
 *                                                                         *
 *   Copyright (C) 2005, 2006 by Kevin Gilbert                             *
 *   kev.gilbert@cdu.edu.au                                                *
 *                                                                         *
 *   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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   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, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 *                                                                         *
 ***************************************************************************/

#include <tqdir.h>
#include <tqlineedit.h>

#include <tdeaction.h>
#include <tdeapplication.h>
#include <tdeconfig.h>
#include <kdebug.h>
#include <kedittoolbar.h>
#include <tdefiledialog.h>
#include <tdeglobalsettings.h>
#include <kinputdialog.h>
#include <kkeydialog.h>
#include <tdelocale.h>
#include <tdemainwindow.h>
#include <tdemessagebox.h>
#include <kstandarddirs.h>
#include <kstatusbar.h>
#include <kstdaction.h>

#include "htmlwidget.h"
#include "knmap.h"
#include "mainwidget.h"
#include "scanwidget.h"

//	constructor
//	===========

Knmap::Knmap( )
: TDEMainWindow( NULL, "knmap" ),
  m_mainWidget( new MainWidget( this, "main widget" ))
{	findNmap( );
	setCentralWidget( m_mainWidget );
	readSettings(  );
	createMenu( );
	setAutoSaveSettings( );

	connect( m_mainWidget,
			 TQ_SIGNAL( outputAvailable( const bool, const bool )),
			 TQ_SLOT( slotOutputAvailable( const bool, const bool)));

	connect( m_mainWidget,
			 TQ_SIGNAL( setManPageActionStuff( const bool )),
			 TQ_SLOT( slotSetManPageActionStuff( const bool )));

	connect( m_mainWidget,
			 TQ_SIGNAL( setCaption( const TQString& )),
			 TQ_SLOT( slotSetCaption( const TQString& )));

	connect( m_mainWidget,
			 TQ_SIGNAL( statusBarText( const TQString& )), statusBar( ),
			 TQ_SLOT( message( const TQString& )));

	connect( m_mainWidget,
			 TQ_SIGNAL( visibleScanWidgetChanged( ScanWidget* )),
			 TQ_SLOT( slotVisibleScanWidgetChanged( ScanWidget* )));
}

//	createMenu
//	==========

void Knmap::createMenu( )
{	KStdAction::configureToolbars( this, TQ_SLOT( slotConfigureToolbars( )), actionCollection( ));
	KStdAction::keyBindings( this, TQ_SLOT( slotConfigureShortcuts( )), actionCollection( ));
	KStdAction::quit( kapp, TQ_SLOT( quit( )), actionCollection( ));

	m_fileSaveAction = KStdAction::save( m_mainWidget,
										 TQ_SLOT( slotFileSave( )),
										 actionCollection( ));

	m_fileSaveAsAction = KStdAction::saveAs( m_mainWidget,
											 TQ_SLOT( slotFileSaveAs( )),
											 actionCollection( ));

	m_settingsManAction = new TDEAction( i18n( "&Use local man page" ),
										"localman.png",
										0,
										m_mainWidget,
										TQ_SLOT( slotSwitchManPages( )),
										actionCollection( ),
										"settings_local" );

	m_useTargetHostAction = new TDEToggleAction( i18n( "Use target host name" ),
											   NULL,
											   0,
											   m_mainWidget,
											   TQ_SLOT( slotUseTargetHost( )),
											   actionCollection( ),
											   "scan_use" );

	m_wrapTextAction = new TDEToggleAction( i18n( "Wrap text" ),
										  NULL,
										  0,
										  m_mainWidget,
										  TQ_SLOT( slotWrapText( )),
										  actionCollection( ),
										  "settings_wrap_text" );

	new TDEAction( i18n( "Close scan" ),
				 "scanclose",
				 CTRL+Key_W,
				 m_mainWidget,
				 TQ_SLOT( slotScanClose( )),
				 actionCollection( ),
				 "scan_close" );

	new TDEAction( i18n( "Copy profile..." ),
				 "profilecopy",
				 0,
				 m_mainWidget,
				 TQ_SLOT( slotProfileCopy( )),
				 actionCollection( ),
				 "profile_copy" );

	new TDEAction( i18n( "Delete profile..." ),
				 "profiledelete",
				 0,
				 m_mainWidget,
				 TQ_SLOT( slotProfileDelete( )),
				 actionCollection( ),
				 "profile_delete" );

	new TDEAction( i18n( "Display nmap man page" ),
				 "manpage",
				 0,
				 m_mainWidget,
				 TQ_SLOT( slotShowManPage( )),
				 actionCollection( ),
				 "help_man_page" );

	new TDEAction( i18n( "Duplicate scan" ),
				 "scanduplicate",
				 CTRL+Key_C,
				 m_mainWidget,
				 TQ_SLOT( slotScanDuplicate( )),
				 actionCollection( ),
				 "scan_duplicate" );

	new TDEAction( i18n( "Load profile..." ),
				 "profileload",
				 0,
				 m_mainWidget,
				 TQ_SLOT( slotProfileLoad( )),
				 actionCollection( ),
				 "profile_load" );

	new TDEAction( i18n( "man page stylesheet..." ),
				 "manstylesheet",
				 0,
				 m_mainWidget,
				 TQ_SLOT( slotSetStylesheet( )),
				 actionCollection( ),
				 "settings_stylesheet" );

	new TDEAction( i18n( "New scan..." ),
				 "scannew",
				 CTRL+Key_N,
				 m_mainWidget,
				 TQ_SLOT( slotScanNew( )),
				 actionCollection( ),
				 "scan_new" );

	new TDEAction( i18n( "Rename profile..." ),
				 "profilerename",
				 0,
				 m_mainWidget,
				 TQ_SLOT( slotProfileRename( )),
				 actionCollection( ),
				 "profile_rename" );

	new TDEAction( i18n( "Rename scan..." ),
				 "scanrename",
				 Key_F2,
				 m_mainWidget,
				 TQ_SLOT( slotScanRename( )),
				 actionCollection( ),
				 "scan_rename" );

	new TDEAction( i18n( "Save profile..." ),
				 "profilesave",
				 0,
				 m_mainWidget,
				 TQ_SLOT( slotProfileSave( )),
				 actionCollection( ),
				 "profile_save" );

	new TDEAction( i18n( "Save profile as..." ),
				 "profilesaveas",
				 0,
				 m_mainWidget,
				 TQ_SLOT( slotProfileSaveAs( )),
				 actionCollection( ),
				 "profile_save_as" );

	new TDEAction( i18n( "Zoom custom"  ),
				 "zoomcustom",
				 0,
				 m_mainWidget,
				 TQ_SLOT( slotZoomCustom( )),
				 actionCollection( ),
				 "settings_zoom_custom"  );

	new TDEAction( i18n( "Zoom in"  ),
				 "zoomin",
				 0,
				 m_mainWidget,
				 TQ_SLOT( slotZoomIn( )),
				 actionCollection( ),
				 "settings_zoom_in"  );

	new TDEAction( i18n( "Zoom out" ),
				 "zoomout",
				 0,
				 m_mainWidget,
				 TQ_SLOT( slotZoomOut( )),
				 actionCollection( ),
				 "settings_zoom_out" );

	m_fileSaveAction->setEnabled( false );
	m_fileSaveAsAction->setEnabled( false );
	m_wrapTextAction->setChecked( m_mainWidget->wrapText( ));

	createStandardStatusBarAction( );
	setStandardToolBarMenuEnabled( true );

	createGUI( );
}

//	findNmap
//	========

void Knmap::findNmap( )
{	TQString nmapPath = TDEStandardDirs::findExe( "nmap" );

	if( nmapPath.isEmpty( ))
	{	KMessageBox::error( this,
							i18n( "nmap is not installed on the computer - we cannot proceed without it. To download nmap go to \"http://www.insecure.org/nmap\"" ),
							i18n( "nmap not found" ));
		kapp->quit( );
	}
}

//	getDirPath
//	==========

bool Knmap::getDirPath( const TQString& caption, TQString& path )
{	TQString startDir = (path.isEmpty( )) ? TDEGlobalSettings::documentPath( ) : path;
	TQString tempPath = KFileDialog::getExistingDirectory( startDir, NULL, caption );

	if( tempPath.isEmpty( ))
		return false;

	path = tempPath;
	return true;
}

//	getDirPath
//	==========

void Knmap::getDirPath( const TQString& caption, TQString& path, TQLineEdit* lineEdit )
{	if( getDirPath( caption, path ))
		lineEdit->setText( path );
}

//	getFilePath
//	===========

bool Knmap::getFilePath( const TQString& caption, TQString& path, const bool save )
{	TQString filter   = "*.txt|Text files\n*.*|All files";
	TQString startDir = (path.isEmpty( )) ? TDEGlobalSettings::documentPath( ) : path;
	TQString tempPath = KFileDialog::getSaveFileName( startDir, filter, NULL, caption );

	if( tempPath.isEmpty( ))
		return false;

	if( save && TQFile::exists( tempPath ))
	{	if( KMessageBox::Yes != KMessageBox::questionYesNo( NULL, TQString( i18n( "File \"%1\" exists.\nOverwrite?" )).arg( tempPath ), i18n( "File exists" )))
			return false;
	}

	path = tempPath;
	return true;
}

//	getFilePath
//	===========

void Knmap::getFilePath( const TQString& caption, TQString& path, TQLineEdit* lineEdit, const bool save )
{	if( getFilePath( caption, path, save ))
		lineEdit->setText( path );
}

//	queryExit
//	=========

bool Knmap::queryExit( )
{	if( m_mainWidget->isDirty( ) && KMessageBox::Yes == KMessageBox::questionYesNo( this, i18n( "Some profiles has been updated - save them now?" ), i18n( "Profile data updated" )))
		m_mainWidget->saveAllDirtyProfiles( );

	saveSettings( );
	return true;
}

//	readSettings
//	============

void Knmap::readSettings( )
{	m_mainWidget->readSettings( );
}

//	saveSettings
//	============

void Knmap::saveSettings( )
{	m_mainWidget->saveSettings( );
}

//	slotConfigureShortcuts
//	======================

void Knmap::slotConfigureShortcuts( )
{	KKeyDialog::configure( actionCollection( ), this);
}

//	slotConfigureToolbars
//	=====================

void Knmap::slotConfigureToolbars( )
{	saveMainWindowSettings( TDEGlobal::config( ), autoSaveGroup( ));

	KEditToolbar dlg( actionCollection( ));
	connect( &dlg, TQ_SIGNAL( newToolbarConfig( )),this, TQ_SLOT( slotNewToolbarConfig( )));
	dlg.exec( );
}

//	slotNewToolbarConfig
//	====================

void Knmap::slotNewToolbarConfig( )
{
	createGUI( );

	applyMainWindowSettings( TDEGlobal::config( ), autoSaveGroup( ));
}

//	slotOutputAvailable
//	===================

void Knmap::slotOutputAvailable( const bool saveState, const bool saveAsState )
{	m_fileSaveAction->setEnabled( saveState );
	m_fileSaveAsAction->setEnabled( saveAsState );
}

//	slotSetCaption
//	==============

void Knmap::slotSetCaption( const TQString& caption )
{	setCaption( caption );
}

//	slotSetManPageActionStuff
//	=========================

void Knmap::slotSetManPageActionStuff( const bool useLocalManPage )
{	m_settingsManAction->setIcon( useLocalManPage ? "knmapman.png" : "localman.png" );
	m_settingsManAction->setText( useLocalManPage ? i18n( "&Use Knmap man page" ) : i18n( "&Use local man page" ));
}

//	slotVisibleScanWidgetChanged
//	============================

void Knmap::slotVisibleScanWidgetChanged( ScanWidget* scanWidget )
{	m_useTargetHostAction->setChecked( scanWidget->useTargetHost( ));
}

#include "knmap.moc"