/* * Localwebfaker - Web sites faker for LAN * Copyright (C) 2007-2009 Lucas J. González * * 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, 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, see AppName()); winSize = new QSize(0, 0); winSizeZero = new QSize(0, 0); winSizeExpand = new QSize(0, 0); cuerpo = new QVBoxLayout(this); hrzL = new QHBoxLayout(); salidaL = new QVBoxLayout(); dominioLbl = new QLabel(tr("Domain:"), this); dominioLE = new QLineEdit(this); dominioLE->setText("example.com") ; victimaLbl = new QLabel(tr("Client's IP address:"), this); victimaLE = new QLineEdit(this); victimaLE->setText("192.168.1.169") ; interfazLbl = new QLabel(tr("Network interface:"), this); interfazLE = new QLineEdit(this); interfazLE->setText("eth1") ; gatewayLbl = new QLabel(tr("Client's gateway:"), this); gatewayLE = new QLineEdit(this); gatewayLE->setText("192.168.1.1") ; docrootLbl = new QLabel(tr("Site's new root:"), this); docrootLE = new QLineEdit(this); docrootLE->setText("/var/www/") ; iniciarBtn = new QPushButton(tr("Start!"), this); salidaGB = new QGroupBox(this); salidaGB->setVisible(false); salidaLbl = new QLabel(this); hideSalidaBtn = new QPushButton(tr("Hide output"), this); connect(iniciarBtn, SIGNAL(clicked()), this, SLOT(Iniciar())); connect(iniciarBtn, SIGNAL(clicked()), this, SLOT(muestraSalida())); connect(hideSalidaBtn, SIGNAL(clicked()), this, SLOT(ocultaSalida())); cuerpo->addWidget(dominioLbl); cuerpo->addWidget(dominioLE); cuerpo->addWidget(victimaLbl); cuerpo->addWidget(victimaLE); cuerpo->addWidget(interfazLbl); cuerpo->addWidget(interfazLE); cuerpo->addWidget(gatewayLbl); cuerpo->addWidget(gatewayLE); cuerpo->addWidget(docrootLbl); cuerpo->addWidget(docrootLE); cuerpo->addLayout(hrzL); hrzL->addSpacing ( 190 ); hrzL->addWidget(iniciarBtn); cuerpo->addWidget(salidaGB); salidaGB->setLayout(salidaL); salidaGB->setTitle("Output"); salidaL->addWidget(salidaLbl); salidaL->addWidget(hideSalidaBtn); cuerpo->setSpacing(6); cuerpo->setMargin(11); } void ventanaInicio::nuevaLineaSalida (QString texto) { QString tmpQStr = salidaLbl->text(); tmpQStr.append(texto); tmpQStr.append("\n"); salidaLbl->setText(tmpQStr); } void ventanaInicio::muestraSalida() { if(*winSize == *winSizeZero) *winSize = size(); if(*winSizeExpand != *winSizeZero) setFixedSize(*winSizeExpand); salidaGB->setVisible(true); if(*winSize == *winSizeZero) *winSizeExpand = size(); } void ventanaInicio::ocultaSalida() { if(*winSizeExpand == *winSizeZero) *winSizeExpand = size(); salidaGB->setVisible(false); setFixedSize(*winSize); } bool ventanaInicio::Validar() { Validacion *valid = new Validacion(); salidaLbl->setText(""); bool dev = true ; if( ! valid->dominioValido ( dominioLE->text(), this ) ) { nuevaLineaSalida(tr("EE: domain")); dev = false ; } else { dominioLE->setText( Comun::limpiaDominio( dominioLE->text() ) ) ; std::cout << "domain ok" << std::endl ; } if( ! valid->ExisteDocRoot ( docrootLE->text() ) ) { nuevaLineaSalida("EE: root"); dev = false ; } else std::cout << "ruta ok" << std::endl ; if( ! valid->IpValida ( victimaLE->text(), this ) ) { nuevaLineaSalida("EE: client"); dev = false ; } else std::cout << "client ok" << std::endl ; if( ! valid->netdevValido (interfazLE->text()) ) { nuevaLineaSalida(tr("EE: network interface")); dev = false ; } else std::cout << "network interface ok" << std::endl ; return dev ; } void ventanaInicio::Iniciar() { UInput userInput = getUserInput() ; QString interfaz = QString() ; QString miIP = QString() ; QString dominio = QString() ; QString cliente = QString() ; QString gateway = QString() ; QString docroot = QString() ; if ( Validar() ) { interfaz = interfazLE->text() ; miIP = Comun::mi_IP(interfazLE->text()) ; dominio = dominioLE->text() ; cliente = victimaLE->text() ; gateway = gatewayLE->text() ; docroot = docrootLE->text() ; std::cout << "CONF OK\n--------" << std::endl ; muestraSalida(); salidaLbl->setText(""); nuevaLineaSalida("Please, confirm data"); ventanaConfirmInput *confirmWin = new ventanaConfirmInput(0, userInput); confirmWin->exec(); if(confirmWin->result() == QDialog::Accepted ) { muestraSalida(); salidaLbl->setText(""); nuevaLineaSalida("Confirmed & Started ..."); std::cout << "UserInput confirmed\n--------" << std::endl ; ventanaExec *winExec = new ventanaExec() ; Configurar *configurar = new Configurar( interfaz, cliente, gateway, dominio, docroot, miIP ) ; connect( configurar, SIGNAL(msgOut(QString)), winExec, SLOT(toFaseLabel(QString) ) ) ; connect( configurar, SIGNAL(msgOut(QString)), winExec, SLOT(faseCompleta() ) ) ; connect( configurar, SIGNAL(atMsgOut(QString)), winExec, SLOT(toAtOut(QString) ) ) ; connect( configurar, SIGNAL(newArpOut(QString)), winExec, SLOT(toAOut(QString)) ) ; connect( winExec, SIGNAL(accepted()), this, SLOT(parar()) ) ; connect( winExec, SIGNAL(accepted()), configurar, SLOT(pararArp()) ) ; connect( winExec, SIGNAL(rejected()), this, SLOT(parar()) ) ; connect( winExec, SIGNAL(rejected()), configurar, SLOT(pararArp()) ) ; winExec->setModal(true) ; winExec->show() ; winExec->toFaseLabel(QString("Starting ...")) ; configurar->start() ; } else { std::cout << "UserInput cancelled" << std::endl ; salidaLbl->setText(""); nuevaLineaSalida("cancelled"); muestraSalida(); } } } UInput ventanaInicio::getUserInput() { UInput uInput ; uInput.docroot = docrootLE->text(); uInput.victima = victimaLE->text(); uInput.dominio = dominioLE->text(); uInput.interfaz = interfazLE->text(); return uInput ; } void ventanaInicio::parar() { nuevaLineaSalida("Stopping..."); Config *config = new Config() ; config->Restaurar() ; salidaLbl->setText(""); nuevaLineaSalida("Stopped"); }