1+ #!/usr/bin/env python
2+
3+ """
4+ Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
5+ See the file 'LICENSE' for copying permission
6+ """
7+
8+ def runGui (parser ):
9+ import re
10+ import tkinter as tk
11+ from tkinter import ttk
12+
13+ from lib .core .defaults import defaults
14+
15+ # Reference: https://www.reddit.com/r/learnpython/comments/985umy/limit_user_input_to_only_int_with_tkinter/e4dj9k9?utm_source=share&utm_medium=web2x
16+ class ConstrainedEntry (tk .Entry ):
17+ def __init__ (self , master = None , ** kwargs ):
18+ self .var = tk .StringVar ()
19+ self .regex = kwargs ["regex" ]
20+ del kwargs ["regex" ]
21+ tk .Entry .__init__ (self , master , textvariable = self .var , ** kwargs )
22+ self .old_value = ''
23+ self .var .trace ('w' , self .check )
24+ self .get , self .set = self .var .get , self .var .set
25+
26+ def check (self , * args ):
27+ if re .search (self .regex , self .get ()):
28+ self .old_value = self .get ()
29+ else :
30+ self .set (self .old_value )
31+
32+ # Reference: https://code.activestate.com/recipes/580726-tkinter-notebook-that-fits-to-the-height-of-every-/
33+ class AutoresizableNotebook (ttk .Notebook ):
34+ def __init__ (self , master = None , ** kw ):
35+ ttk .Notebook .__init__ (self , master , ** kw )
36+ self .bind ("<<NotebookTabChanged>>" , self ._on_tab_changed )
37+
38+ def _on_tab_changed (self ,event ):
39+ event .widget .update_idletasks ()
40+
41+ tab = event .widget .nametowidget (event .widget .select ())
42+ event .widget .configure (height = tab .winfo_reqheight ())
43+
44+ window = tk .Tk ()
45+ window .title ("sqlmap" )
46+
47+ # Reference: https://www.holadevs.com/pregunta/64750/change-selected-tab-color-in-ttknotebook
48+ style = ttk .Style ()
49+ settings = {"TNotebook.Tab" : {"configure" : {"padding" : [5 , 1 ], "background" : "#fdd57e" }, "map" : {"background" : [("selected" , "#C70039" ), ("active" , "#fc9292" )], "foreground" : [("selected" , "#ffffff" ), ("active" , "#000000" )]}}}
50+ style .theme_create ("custom" , parent = "alt" , settings = settings )
51+ style .theme_use ("custom" )
52+
53+ def dummy ():
54+ pass
55+
56+ menubar = tk .Menu (window )
57+
58+ filemenu = tk .Menu (menubar , tearoff = 0 )
59+ filemenu .add_command (label = "Open" , command = dummy )
60+ filemenu .add_command (label = "Save" , command = dummy )
61+ filemenu .add_separator ()
62+ filemenu .add_command (label = "Exit" , command = window .quit )
63+ menubar .add_cascade (label = "File" , menu = filemenu )
64+
65+ runmenu = tk .Menu (menubar , tearoff = 0 )
66+ runmenu .add_command (label = "Start" , command = dummy )
67+ runmenu .add_command (label = "Stop" , command = dummy )
68+ menubar .add_cascade (label = "Run" , menu = runmenu )
69+
70+ helpmenu = tk .Menu (menubar , tearoff = 0 )
71+ helpmenu .add_command (label = "Wiki pages" , command = dummy )
72+ helpmenu .add_command (label = "Official site" , command = dummy )
73+ helpmenu .add_separator ()
74+ helpmenu .add_command (label = "About" , command = dummy )
75+ menubar .add_cascade (label = "Help" , menu = helpmenu )
76+
77+ window .config (menu = menubar )
78+
79+ notebook = AutoresizableNotebook (window )
80+
81+ frames = {}
82+ for group in parser .option_groups :
83+ frame = frames [group .title ] = tk .Frame (notebook , width = 200 , height = 200 )
84+ notebook .add (frames [group .title ], text = group .title )
85+
86+ tk .Label (frame ).grid (column = 0 , row = 0 , sticky = tk .W )
87+
88+ row = 1
89+ for option in group .option_list :
90+ tk .Label (frame , text = parser .formatter ._format_option_strings (option )).grid (column = 0 , row = row , sticky = tk .W )
91+
92+ if option .type == "string" :
93+ widget = tk .Entry (frame )
94+ elif option .type == "float" :
95+ widget = ConstrainedEntry (frame , regex = r"\A\d*\.?\d*\Z" )
96+ elif option .type == "int" :
97+ widget = ConstrainedEntry (frame , regex = r"\A\d*\Z" )
98+ else :
99+ var = tk .IntVar ()
100+ widget = tk .Checkbutton (frame , variable = var )
101+ widget .var = var
102+
103+ widget .grid (column = 1 , row = row , sticky = tk .W )
104+
105+ default = defaults .get (option .dest )
106+ if default :
107+ if hasattr (widget , "insert" ):
108+ widget .insert (0 , default )
109+
110+ tk .Label (frame , text = " " ).grid (column = 3 , row = row , sticky = tk .W )
111+ tk .Label (frame , text = option .help ).grid (column = 4 , row = row , sticky = tk .W )
112+
113+ row += 1
114+
115+ tk .Label (frame ).grid (column = 0 , row = row , sticky = tk .W )
116+
117+ notebook .pack (expand = 1 , fill = "both" )
118+
119+ notebook .enable_traversal ()
120+
121+ window .mainloop ()
0 commit comments