-
Notifications
You must be signed in to change notification settings - Fork 0
/
ventanaprincipal.cpp
executable file
·491 lines (418 loc) · 14.5 KB
/
ventanaprincipal.cpp
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
#include "ventanaprincipal.h"
#include "ui_ventanaprincipal.h"
#include "QStringList"
#include "QDebug"
#include "QTextCodec"
#include "manejo_string.cpp"
#include "QAbstractItemModel"
#include "QInputDialog"
#include "QThread"
VentanaPrincipal::VentanaPrincipal(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::VentanaPrincipal)
{
QStringList totalCanales2_4={"1","2","3","4","5","6","7","8","9","10","11","12","13","14"};
QStringList wifi;
QStringList interfaces;
QSettings settings("Paketo", "Visual_create_ap");
ui->setupUi(this);
ui->ckbCanal->addItems(totalCanales2_4);
bool ok;
contrasena = QInputDialog::getText(this, "Autorizacion",
"Se necesita autorizacion ADMINISTRADOR (sudo) para iniciar algunos procesos\nContraseña:", QLineEdit::Password, "", &ok);
//if (ok && !text.isEmpty())
QProcess process1;
QProcess process2;
QProcess process3;
QProcess process4;
process1.setStandardOutputProcess(&process2);
process3.setStandardOutputProcess(&process4);
process1.start("echo "+contrasena);
process2.start("sudo -S ifconfig");
process2.setProcessChannelMode(QProcess::ForwardedChannels);
// Wait for it to start
if(!process1.waitForStarted()) {
qDebug() << "No se pueden abrir los procesos";
return ;
}
QByteArray buffer;
if(!process2.waitForFinished()){
qDebug() << "Problemas con los procesos";
return ;
}
QByteArray response = process2.readAll();
process1.close();
process2.close();
QString textIfconfig = response.data();
interfaces=getInterf(textIfconfig);
process3.start("echo "+contrasena);
process4.start("sudo -S iwconfig");
process4.setProcessChannelMode(QProcess::ForwardedChannels);
// Wait for it to start
if(!process3.waitForStarted()) {
qDebug() << "No se pueden abrir los procesos";
return ;
}
if(!process4.waitForFinished()){
qDebug() << "Problemas con los procesos";
return ;
}
response = process4.readAll();
process4.close();
process3.close();
textIfconfig = response.data();
qDebug() <<textIfconfig;
wifi=getInterf(textIfconfig);
ui->internet->addItems(interfaces);
ui->wifi->addItems(wifi);
qDebug() << wifi;
qDebug()<<interfaces;
/*
proceso.start("gksudo ifconfig");
if(!proceso.waitForStarted()){
qDebug() << "NO RULA";
return ;
}
//bash.closeWriteChannel();
if(!proceso.waitForFinished()){
qDebug() << "NO RULA";
return ;
}
QByteArray response = proceso.readAll();
proceso.close();
QString textIfconfig = response.data();
//qDebug()<<textIfconfig;
interfaces=getInterf(textIfconfig);
proceso.start("gksudo iwconfig");
if(!proceso.waitForStarted()){
qDebug() << "No se pueden abrir los procesos";
return ;
}
//bash.closeWriteChannel();
if(!proceso.waitForFinished()){
qDebug() << "Problemas con los procesos";
return ;
}
response = proceso.readAll();
proceso.close();
*/
//TOMAR LOS AJUSTES DE LA SECION ANTERIOR
QString interfazGuardada=settings.value("wifi","wlo1").toString();
if(wifi.contains(interfazGuardada))
ui->wifi->setCurrentIndex(wifi.indexOf(interfazGuardada));
interfazGuardada=settings.value("interfaces","wlo1").toString();
if(interfaces.contains(interfazGuardada))
ui->internet->setCurrentIndex(interfaces.indexOf(interfazGuardada));
ui->ckbCanal->setCurrentIndex(ui->ckbCanal->findText(settings.value("canal","1").toString()));
ui->leMacClonada->setText(settings.value("mac","62:D9:DF:02:ED:E3").toString());
ui->ckbOcultarWifi->setChecked(settings.value("ocultarWifi",false).toBool());
ui->ckbDesabilitarComClientes->setChecked(settings.value("desabilitarComClientes",false).toBool());
ui->ckbInterfazVirtual->setChecked(settings.value("interfazVirtual",true).toBool());
ui->leNombrePunto->setText(settings.value("nombrePunto","Mi_Punto").toString());
ui->leContrasena->setText(settings.value("contrasena","").toString());
connect(ui->btRefrescar,SIGNAL(clicked()),SLOT(refrescarLista()));
connect(ui->btSegundoPlano,SIGNAL(clicked()),SLOT(iniciar()));
connect(ui->btDetenerSegPlano,SIGNAL(clicked()),SLOT(detener()));
connect(ui->ckbMostrar,SIGNAL(stateChanged(int)),SLOT(mostrarContrasena(int)));
connect(ui->btRepararWifi,SIGNAL(clicked()),SLOT(repararWifi()));
connect(ui->wifi,SIGNAL(currentIndexChanged(int)),SLOT(comprobarVirtual(int)));
connect(ui->internet,SIGNAL(currentIndexChanged(int)),SLOT(comprobarVirtual(int)));
connect(ui->btClientes,SIGNAL(clicked()),SLOT(verClientes()));
connect(ui->leContrasena,SIGNAL(editingFinished()),SLOT(verificarContrasena()));
connect(ui->leMacClonada,SIGNAL(editingFinished()),SLOT(verificarMac()));
refrescarLista();
}
VentanaPrincipal::~VentanaPrincipal()
{
QSettings settings("Paketo", "Visual_create_ap");
settings.setValue("wifi",ui->wifi->currentText());
settings.setValue("interfaces",ui->internet->currentText());
settings.setValue("canal",ui->ckbCanal->currentText());
settings.setValue("mac",ui->leMacClonada->text());
settings.setValue("ocultarWifi",ui->ckbOcultarWifi->isChecked());
settings.setValue("desabilitarComClientes",ui->ckbDesabilitarComClientes->isChecked());
settings.setValue("interfazVirtual",ui->ckbInterfazVirtual->isChecked());
settings.setValue("nombrePunto",ui->leNombrePunto->text());
settings.setValue("contrasena",ui->leContrasena->text());
delete ui;
}
/////////////////////////////////////////////
/// \brief VentanaPrincipal::iniciar
///
void VentanaPrincipal::iniciar(){
QString modoComexion;
if(ui->nat->isChecked())
modoComexion="nat";
else if(ui->bridge->isChecked())
modoComexion="bridge";
else if(ui->bridge->isChecked())
modoComexion="none";
else {
modoComexion="none";
}
QString opciones;
if(ui->ckbOcultarWifi->isChecked())
opciones.append("--hidden ");
if(ui->ckbDesabilitarComClientes->isChecked())
opciones.append("--isolate-clients ");
if(!ui->ckbInterfazVirtual->isChecked())
opciones.append("--no-virt ");
QProcess process1;
process1.startDetached("/bin/sh", QStringList()<< "-c"
<<"echo "
+contrasena
+" |sudo -S create_ap --daemon -c "
+ui->ckbCanal->currentText()+" --mac "
+ui->leMacClonada->text()+" -m "
+ modoComexion+" "
+opciones
+ui->wifi->currentText()+" "
+ ui->internet->currentText()+" "
+ui->leNombrePunto->text()+" "
+(ui->leContrasena->text().isEmpty()?"":ui->leContrasena->text())
);
// Wait for it to start
if(!process1.waitForStarted()) {
qDebug() << "No se pueden abrir los procesos";
return ;
}
QByteArray response = process1.readAll();
QString textIfconfig = response.data();
//qDebug()<<textIfconfig;
if(!process1.waitForFinished()){
qDebug() << "Problemas con los procesos";
return ;
}
process1.close();
}
void VentanaPrincipal::detener(){
int objeto=0;
QProcess process1;
if(ui->lvProcesos->selectedItems().length()==0)
return;
QString interfaz = ui->lvProcesos->selectedItems()[0]->text();
if(interfaz.isEmpty())
return;
QStringList interfazList=interfaz.split(" ");
if(interfazList.length()==3)
objeto=2;
else if(interfazList.length()==2)
objeto=1;
else {
return;
}
if(interfazList[1].isEmpty())
return;
interfazList[objeto].remove("(");
interfazList[objeto].remove(")");
process1.startDetached("/bin/sh", QStringList()<< "-c"
<<"echo "
+contrasena
+" |sudo -S create_ap --stop "
+interfazList[objeto]);
// Wait for it to start
if(!process1.waitForStarted()) {
return ;
}
QByteArray response = process1.readAll();
QString textIfconfig = response.data();
//qDebug()<<textIfconfig;
process1.close();
QThread::sleep(2);
refrescarLista();
}
void VentanaPrincipal::refrescarLista(){
QProcess process1;
QProcess process2;
process1.setStandardOutputProcess(&process2);
process1.start("echo "+contrasena);
process2.start("sudo -S create_ap --list-running");
process2.setProcessChannelMode(QProcess::ForwardedChannels);
// Wait for it to start
if(!process1.waitForStarted()) {
qDebug() << "No se pueden abrir los procesos";
return ;
}
QByteArray buffer;
if(!process2.waitForFinished()){
qDebug() << "Problemas con los procesos";
return ;
}
QByteArray response = process2.readAll();
process1.close();
process2.close();
QString textIfconfig = response.data();
QStringList lineas=textIfconfig.split('\n');
QStringList procesos;
for(int a=2;a<lineas.length();a++){
if(!lineas[a].isEmpty())
procesos.append(lineas[a]);
}
qDebug()<<procesos;
ui->lvProcesos->clear();
ui->lvProcesos->insertItems(1,procesos);
process1.close();
process2.close();
ui->lvClientes->clear();
refrescarInterfaces();
}
void VentanaPrincipal::refrescarInterfaces(){
QProcess process1;
QProcess process2;
QProcess process3;
QProcess process4;
QStringList wifi;
QStringList interfaces;
process1.setStandardOutputProcess(&process2);
process3.setStandardOutputProcess(&process4);
process1.start("echo "+contrasena);
process2.start("sudo -S ifconfig");
process2.setProcessChannelMode(QProcess::ForwardedChannels);
// Wait for it to start
if(!process1.waitForStarted()) {
return ;
}
QByteArray buffer;
if(!process2.waitForFinished()){
qDebug() << "Problemas con los procesos";
return ;
}
QByteArray response = process2.readAll();
process1.close();
process2.close();
QString textIfconfig = response.data();
interfaces=getInterf(textIfconfig);
process3.start("echo "+contrasena);
process4.start("sudo -S iwconfig");
process4.setProcessChannelMode(QProcess::ForwardedChannels);
// Wait for it to start
if(!process3.waitForStarted()) {
return ;
}
if(!process4.waitForFinished()){
qDebug() << "Problemas con los procesos";
return ;
}
response = process4.readAll();
process4.close();
process3.close();
textIfconfig = response.data();
qDebug() <<textIfconfig;
wifi=getInterf(textIfconfig);
QString wifiGuardada=ui->wifi->currentText();
QString internetGuardada=ui->internet->currentText();
ui->internet->clear();
ui->internet->addItems(interfaces);
ui->wifi->clear();
ui->wifi->addItems(wifi);
if(wifi.contains(wifiGuardada))
ui->wifi->setCurrentIndex(wifi.indexOf(wifiGuardada));
if(interfaces.contains(internetGuardada))
ui->internet->setCurrentIndex(interfaces.indexOf(internetGuardada));
}
void VentanaPrincipal::mostrarContrasena(int mostrar){
if(mostrar==Qt::Checked)
ui->leContrasena->setEchoMode(QLineEdit::Normal);
else
ui->leContrasena->setEchoMode(QLineEdit::Password);
}
void VentanaPrincipal::repararWifi(){
QProcess process1;
process1.startDetached("/bin/sh", QStringList()<< "-c"
<<"echo "
+contrasena
+" |sudo -S create_ap --fix-unmanaged"
);
// Wait for it to start
if(!process1.waitForStarted()) {
qDebug() << "No se pueden abrir los procesos";
return ;
}
QByteArray response = process1.readAll();
QString textIfconfig = response.data();
//qDebug()<<textIfconfig;
if(!process1.waitForFinished()){
qDebug() << "Problemas con los procesos";
return ;
}
process1.close();
refrescarLista();
}
void VentanaPrincipal::comprobarVirtual(int estado){
if(ui->wifi->currentText()==ui->internet->currentText()){
ui->ckbInterfazVirtual->setCheckState(Qt::Checked);
ui->ckbInterfazVirtual->setEnabled(false);
}
else {
ui->ckbInterfazVirtual->setEnabled(true);
}
}
void VentanaPrincipal::verClientes(){
int objeto=0;
if(ui->lvProcesos->selectedItems().length()==0)
return;
QString interfaz = ui->lvProcesos->selectedItems()[0]->text();
if(interfaz.isEmpty())
return;
QStringList interfazList=interfaz.split(" ");
if(interfazList.length()==3)
objeto=2;
else if(interfazList.length()==2)
objeto=1;
else {
return;
}
if(interfazList[1].isEmpty())
return;
interfazList[objeto].remove("(");
interfazList[objeto].remove(")");
QProcess process1;
QProcess process2;
process1.setStandardOutputProcess(&process2);
process1.start("echo "+contrasena);
process2.start("sudo -S create_ap --list-clients "
+interfazList[objeto]);
process2.setProcessChannelMode(QProcess::ForwardedChannels);
// Wait for it to start
if(!process1.waitForStarted()) {
qDebug() << "No se pueden abrir los procesos";
return ;
}
QByteArray buffer;
if(!process2.waitForFinished()){
qDebug() << "Problemas con los procesos";
return ;
}
QByteArray response = process2.readAll();
process1.close();
process2.close();
QString textIfconfig = response.data();
QStringList lineas=textIfconfig.split('\n');
ui->lvClientes->clear();
ui->lvClientes->insertItems(1,lineas);
process1.close();
}
void VentanaPrincipal::verificarContrasena(){
if(ui->leContrasena->text().length()>0 && ui->leContrasena->text().length()<8)
ui->leContrasena->setText("");
}
//Ejemplo de Mac 62:D9:DF:02:ED:E3
// 01234567890123456
void VentanaPrincipal::verificarMac(){
QString caracPermitido="0123456789ABCDEFabcdef";
QString texto=ui->leMacClonada->text();
for(int a=0;a<17;a++){
if(a==2 || a==5 || a==8 || a==11 || a==14){
if(!(texto[a]==':')){
//return;//reportar la mac incorrecta
ui->leMacClonada->setFocus();
}
}
else{
if(!caracPermitido.contains(texto[a])){
//return; //reportar la mac incorrecta
ui->leMacClonada->setFocus();
}
}
}
}