From 6040d26c56a95d9f5bd09688e22009fc5b5e124d Mon Sep 17 00:00:00 2001 From: llornkcor Date: Thu, 11 Aug 2005 10:10:40 +0000 Subject: add opie-smb --- (limited to 'noncore/net') diff --git a/noncore/net/opie-smb/config.in b/noncore/net/opie-smb/config.in new file mode 100644 index 0000000..4ff78fd --- a/dev/null +++ b/noncore/net/opie-smb/config.in @@ -0,0 +1,4 @@ + config OPIESMB + boolean "opie-smb (samba front end client for Opie)" + default "n" + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE diff --git a/noncore/net/opie-smb/main.cpp b/noncore/net/opie-smb/main.cpp new file mode 100644 index 0000000..5fae972 --- a/dev/null +++ b/noncore/net/opie-smb/main.cpp @@ -0,0 +1,6 @@ +#include "qsmb.h" +#include +using namespace Opie::Core; +OPIE_EXPORT_APP( OApplicationFactory ) + + diff --git a/noncore/net/opie-smb/opie-smb.control b/noncore/net/opie-smb/opie-smb.control new file mode 100644 index 0000000..ce5c6bf --- a/dev/null +++ b/noncore/net/opie-smb/opie-smb.control @@ -0,0 +1,12 @@ +Package: smbclient +Version: 1.0 +Architecture: arm +Arch: arm +Maintainer: Kurt Korbatits (support@midget.net.au) +Section: Network +Priority: optional +Description: Gui front end for samba utilities. +Source: +Depends: smbclient + + diff --git a/noncore/net/opie-smb/opie-smb.pro b/noncore/net/opie-smb/opie-smb.pro new file mode 100644 index 0000000..90f9980 --- a/dev/null +++ b/noncore/net/opie-smb/opie-smb.pro @@ -0,0 +1,18 @@ +TEMPLATE = app +CONFIG += qte warn_on quickapp debug +HEADERS = qsmb.h +SOURCES = main.cpp qsmb.cpp +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include +DESTDIR = $(OPIEDIR)/bin +LIBS += -lqpe -lopiecore2 -lopieui2 -lpthread + +# INCLUDEPATH += $(QPEDIR)/include +# DEPENDPATH += $(QPEDIR)/include +# LIBS += + +INTERFACES = qsmbbase.ui +TARGET = opie-smb + +#DEFINES += QT_QWS_NONOPIE +include( $(OPIEDIR)/include.pro ) diff --git a/noncore/net/opie-smb/qsmb.cpp b/noncore/net/opie-smb/qsmb.cpp new file mode 100644 index 0000000..527ab38 --- a/dev/null +++ b/noncore/net/opie-smb/qsmb.cpp @@ -0,0 +1,402 @@ +#include "qsmb.h" +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +#include +#include +#include + + +#include +using namespace Opie::Core; + + +Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl ) + : FormQPESMBBase( parent, name, fl ) +{ + connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int))); + connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked())); + connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked())); + connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear())); + +//TODO configurable mount points + if(!QFileInfo("/mnt/samba1").exists()) system("mkdir /mnt/samba1"); + if(!QFileInfo("/mnt/samba2").exists()) system("mkdir /mnt/samba2"); + if(!QFileInfo("/mnt/samba2").exists()) system("mkdir /mnt/samba3"); + + mountpt->insertItem("/mnt/samba1",-1); + mountpt->insertItem("/mnt/samba2",-1); + mountpt->insertItem("/mnt/samba3",-1); + + top_element = NULL; + scanning = false; +} + +Qsmb::~Qsmb() +{ +} + +void Qsmb::clear() +{ + if (scanning) return; + ListViewScan->clear(); + TextViewOutput->setText(""); + top_element = NULL; +} + +void Qsmb::scanClicked() +{ + if (scanning) return; + pthread_create(&tpid, NULL, runit, (void *)this); +} + +void Qsmb::DoItClicked() +{ + + if(! ListViewScan->selectedItem()) { + QMessageBox::warning(this, tr("Error"),tr("

No share selected!

")); + return; + } + if (scanning) return; + pthread_create(&tpid, NULL, runitm, (void *)this); +} + +void* runit(void* arg) +{ + Qsmb* caller = (Qsmb*)arg; + caller->scan(); + return(0); +} + +void* runitm(void* arg) +{ + Qsmb* caller = (Qsmb*)arg; + caller->DoIt(); + return(0); +} + +void Qsmb::scan() +{ + int i; + + if (scanning) return; + scanning = true; + + char match[512], lmhosts[512]; + QString cmd; + char result[256]; + + FILE *pipe, *pipe2; + + LScan->setText("Scanning..."); + qApp->processEvents(); + + cmd = "ifconfig |grep 'addr:'|awk '{print $2}'|awk 'BEGIN{FS=\":\"}{print $2}'|sed 's/\\.[0-9]*$//'|head -n1"; + + owarn << "cmd: " << cmd << oendl; + + /* run findsmb & read output */ + if ((pipe = popen(cmd.latin1(), "r")) == NULL) { + snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); + TextViewOutput->append(result); + return; + } + while(fgets(result, 256, pipe) != NULL) { + strcpy( match, result); + match[5]='\0'; + break; + } + owarn << "match: " << match << oendl; + + cmd = "/usr/bin/findsmb"; + owarn <<"cmd: " << cmd << oendl; + + TextViewOutput->append(cmd); + + snprintf(lmhosts, 512, "echo '127.0.0.1 localhost'>/etc/samba/lmhosts"); + + if ((pipe2 = popen(lmhosts, "r")) == NULL) { + snprintf(result, 256, "Error: Can't run %s", lmhosts); + //TextViewOutput->append(result); + return; + } + + /* run command & read output */ + if ((pipe = popen(cmd.latin1(), "r")) == NULL) { + snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); + TextViewOutput->append(result); + return; + } + + /* parse output and display in ListViewScan */ + while(fgets(result, 256, pipe) != NULL) { + /* put result into TextViewOutput */ + TextViewOutput->append(result); + + if( strstr(result, match) != NULL ) { + char ip_addr[256], host[256], *ptr1; + + strcpy( ip_addr, result); + ptr1 = strchr(ip_addr,' '); + strcpy( host, ptr1); + ip_addr[ptr1 - ip_addr]='\0'; + + for(i = 0; i < 256; i++) { + if(host[i]!=' ') { + strcpy( host, host + i); + break; + } + } + ptr1 = strchr(host,' '); + host[ptr1 - host] = '\0'; + + owarn << "add host: " << host << oendl; + + CBHost->insertItem( host, -1); + snprintf( lmhosts, 512, "echo '%s %s'>>/etc/samba/lmhosts", ip_addr,host); + + owarn << "lmhosts: " << lmhosts << oendl; + + if ((pipe2 = popen(lmhosts, "r")) == NULL) { + snprintf(result, 256, "Error: Can't run %s", lmhosts); + return; + } + } + } + + TextViewOutput->append("\n\n============================================\n"); + LScan->setText(""); + scanning = false; +} + +void Qsmb::hostSelected(int index) +{ + owarn << "hostSelected" << oendl; + int i; + + QListViewItem *element; + QListViewItem *parent; + + QString text = CBHost->currentText(); + + if (scanning) return; + scanning = true; + + QString cmd; + char result[256]; + + FILE *pipe; + + LScan->setText("Scanning..."); + + if((const char *)username->text() == '\0') + cmd = "/usr/bin/smbclient -L //"+CBHost->currentText()+" -N 2>&1 |grep Disk"; + else + cmd = "/usr/bin/smbclient -L //"+CBHost->currentText()+" -N -U"+username->text()+":"+password->text()+" 2>&1 |grep Disk"; + + for(i = 0; i < 512; i++) { + if(cmd[i]==':') { + cmd[i]='%'; + break; + } + if(cmd[i]=='\0') + break; + } + + owarn << "i="<< index << "cmd:" << cmd << oendl; + + TextViewOutput->append(cmd); + + /* run smbclient & read output */ + if ((pipe = popen(cmd.latin1(), "r")) == NULL) { + snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); +// cmd = "Error: Can't run "+cmd; + TextViewOutput->append(result); + return; + } + + /* parse output and display in ListViewScan */ + while(fgets(result, 256, pipe) != NULL) { + /* put result into TextViewOutput */ + TextViewOutput->append(result); + + if( strchr(result, '$') == NULL ) { + char share[256], *ptr1; + + strcpy(share,result); + ptr1 = strchr(share,' '); + share[ptr1 - share]='\0'; + + owarn<< "add share: " << share << oendl; + + if(top_element != NULL) { + bool found = false; + element = top_element; + + while(element != NULL && !found) { + if(strcmp( element->text(0).ascii(), share)==0) { + parent = element; + found = true; + } + element = element->nextSibling(); + } + + if(!found) { + element = new QListViewItem(ListViewScan,share); + element->setOpen(true); + parent=element; + } + } else { + element = new QListViewItem(ListViewScan,share); + element->setOpen(true); + top_element = element; + parent = element; + } + } + } + + TextViewOutput->append("\n\n============================================\n"); + LScan->setText(""); + scanning = false; +} + +void Qsmb::DoIt() +{ + QListViewItem *element; + element = ListViewScan->selectedItem(); + if(!element) { + QMessageBox::warning(this, tr("Error!!"),tr("

No share selected!!

")); + return; + } + + if (scanning) return; + scanning = true; + + int i; + + char share[512]; + QString cmd; + QString cmd2; + char result[256]; +// QString result; + QString text = mountpt->currentText(); + + FILE *pipe,*pipe2; + + LScan->setText("Mounting..."); + qApp->processEvents(); + + cmd = "mkdir -p "+ text; + + owarn<<"cmd: "<< cmd << oendl; + + /* make sure mount exists! */ + if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) { + + snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); + // result = "Error: Can't run " + cmd; + TextViewOutput->append(result); + return; + } + + while(fgets(result, 256, pipe2) != NULL) { + /* put result into TextViewOutput */ + TextViewOutput->append(result); + } + + + strcpy(share,(const char *)element->text(0)); + + for(i = 0; i < 256; i++) { + if(isalpha( share[i])) { + strcpy( share, share + i); + break; + } + } + + cmd = "/usr/bin/smbmount //"+CBHost->currentText()+"/"+share+" "+mountpt->currentText()+" -U"+username->text()+":"+password->text(); + + for(i = 0; i < 512; i++) { + if(cmd[i]==':') { + cmd[i]='%'; + break; + } + if(cmd[i]=='\0') + break; + } + + owarn << "cmd: " << cmd << oendl; + TextViewOutput->append(cmd.latin1()); + + + if(onbootBtn->isChecked()) { + owarn << "Saving Setting permanently..." << oendl; + cmd2 = "echo '" + cmd + "'>/opt/QtPalmtop/etc/samba.env"; + + /* run command & read output */ + if ((pipe = popen(cmd2.latin1(), "r")) == NULL) { + + snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); +// result = "Error: Can't run "+ cmd; + //TextViewOutput->append(result); + return; + } + /* parse output and display in ListViewScan */ + while(fgets(result, 256, pipe) != NULL) { + /* put result into TextViewOutput */ + //TextViewOutput->append(result); + } + } + + /* run command & read output */ + if ((pipe = popen(cmd.latin1(), "r")) == NULL) { + +// result = "Error: Can't run "+ cmd; + snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); + + TextViewOutput->append(result); + return; + } + + /* parse output and display in ListViewScan */ + while(fgets(result, 256, pipe) != NULL) { + /* put result into TextViewOutput */ + TextViewOutput->append(result); + } + TextViewOutput->append("\n\n================CheckMounts==================\n"); + LScan->setText(""); + + cmd = "/bin/mount 2>&1"; + owarn << "cmd: " << cmd << oendl; + + if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) { + + snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); +// result = "Error: Can't run "+ cmd; + + TextViewOutput->append(result); + return; + } + /* parse output and display in ListViewScan */ + while(fgets(result, 256, pipe2) != NULL) { + /* put result into TextViewOutput */ + TextViewOutput->append(result); + } + + TextViewOutput->append("\n\n============================================\n"); + scanning = false; +} diff --git a/noncore/net/opie-smb/qsmb.h b/noncore/net/opie-smb/qsmb.h new file mode 100644 index 0000000..8fefe91 --- a/dev/null +++ b/noncore/net/opie-smb/qsmb.h @@ -0,0 +1,39 @@ +#ifndef QSMB_H +#define QSMB_H + +#include "qsmbbase.h" + +#include +#include +#include + +#include +#include + +class Qsmb : public FormQPESMBBase +{ + Q_OBJECT + +public: + static QString appName() { return QString::fromLatin1("opie-smb"); } + Qsmb( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + ~Qsmb(); + void scan(); + void DoIt(); + +private: + QListViewItem *top_element; + QComboBox *hosts; + pthread_t tpid; + bool scanning; + +public slots: + void clear(); + void scanClicked(); + void hostSelected(int); + void DoItClicked(); +}; +void* runit(void *arg); +void* runitm(void *arg); + +#endif // QSMB_H diff --git a/noncore/net/opie-smb/qsmbbase.cpp b/noncore/net/opie-smb/qsmbbase.cpp new file mode 100644 index 0000000..21cd306 --- a/dev/null +++ b/noncore/net/opie-smb/qsmbbase.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** Form implementation generated from reading ui file 'qsmbbase.ui' +** +** Created: Thu Aug 11 19:30:44 2005 +** by: The User Interface Compiler (uic) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ +#include "qsmbbase.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Constructs a FormQPESMBBase which is a child of 'parent', with the + * name 'name' and widget flags set to 'f' + */ +FormQPESMBBase::FormQPESMBBase( QWidget* parent, const char* name, WFlags fl ) + : QWidget( parent, name, fl ) +{ + if ( !name ) + setName( "FormQPESMBBase" ); + resize( 254, 352 ); + QFont f( font() ); + setFont( f ); + setCaption( tr( "Opie Smb" ) ); + FormQPESMBBaseLayout = new QGridLayout( this ); + FormQPESMBBaseLayout->setSpacing( 2 ); + FormQPESMBBaseLayout->setMargin( 0 ); + + TabWidget2 = new QTabWidget( this, "TabWidget2" ); + + tab = new QWidget( TabWidget2, "tab" ); + tabLayout = new QGridLayout( tab ); + tabLayout->setSpacing( 0 ); + tabLayout->setMargin( 2 ); + + CBHost = new QComboBox( FALSE, tab, "CBHost" ); + + tabLayout->addMultiCellWidget( CBHost, 1, 1, 0, 3 ); + + mountpt = new QComboBox( FALSE, tab, "mountpt" ); + + tabLayout->addMultiCellWidget( mountpt, 4, 4, 1, 3 ); + + LScan = new QLabel( tab, "LScan" ); + LScan->setText( tr( "" ) ); + + tabLayout->addWidget( LScan, 0, 3 ); + + textLabel1 = new QLabel( tab, "textLabel1" ); + textLabel1->setText( tr( "mount pt:" ) ); + + tabLayout->addWidget( textLabel1, 4, 0 ); + + ListViewScan = new QListView( tab, "ListViewScan" ); + ListViewScan->addColumn( tr( "Shares" ) ); + + tabLayout->addMultiCellWidget( ListViewScan, 2, 2, 0, 3 ); + + BtnScan = new QPushButton( tab, "BtnScan" ); + BtnScan->setText( tr( "&Scan" ) ); + + tabLayout->addMultiCellWidget( BtnScan, 0, 0, 0, 1 ); + + BtnClear = new QPushButton( tab, "BtnClear" ); + BtnClear->setText( tr( "&Clear" ) ); + + tabLayout->addWidget( BtnClear, 0, 2 ); + + onbootBtn = new QCheckBox( tab, "onbootBtn" ); + onbootBtn->setText( tr( "Reconnect on boot" ) ); + + tabLayout->addMultiCellWidget( onbootBtn, 3, 3, 0, 2 ); + + DoItBtn = new QPushButton( tab, "DoItBtn" ); + DoItBtn->setText( tr( "&Login" ) ); + + tabLayout->addMultiCellWidget( DoItBtn, 5, 5, 0, 1 ); + + Layout6 = new QGridLayout; + Layout6->setSpacing( 6 ); + Layout6->setMargin( 0 ); + + Layout2 = new QHBoxLayout; + Layout2->setSpacing( 6 ); + Layout2->setMargin( 0 ); + + pwdlabel = new QLabel( tab, "pwdlabel" ); + pwdlabel->setText( tr( "password" ) ); + Layout2->addWidget( pwdlabel ); + + password = new QLineEdit( tab, "password" ); + Layout2->addWidget( password ); + + Layout6->addLayout( Layout2, 1, 0 ); + + Layout5 = new QHBoxLayout; + Layout5->setSpacing( 6 ); + Layout5->setMargin( 0 ); + + usrlabel = new QLabel( tab, "usrlabel" ); + usrlabel->setText( tr( "username" ) ); + Layout5->addWidget( usrlabel ); + + username = new QLineEdit( tab, "username" ); + Layout5->addWidget( username ); + + Layout6->addLayout( Layout5, 0, 0 ); + + tabLayout->addMultiCellLayout( Layout6, 5, 5, 2, 3 ); + TabWidget2->insertTab( tab, tr( "Scan" ) ); + + tab_2 = new QWidget( TabWidget2, "tab_2" ); + tabLayout_2 = new QGridLayout( tab_2 ); + tabLayout_2->setSpacing( 6 ); + tabLayout_2->setMargin( 11 ); + + TextViewOutput = new QTextView( tab_2, "TextViewOutput" ); + TextViewOutput->setTextFormat( QTextView::PlainText ); + + tabLayout_2->addWidget( TextViewOutput, 0, 0 ); + TabWidget2->insertTab( tab_2, tr( "SMB Output" ) ); + + FormQPESMBBaseLayout->addWidget( TabWidget2, 0, 0 ); +} + +/* + * Destroys the object and frees any allocated resources + */ +FormQPESMBBase::~FormQPESMBBase() +{ + // no need to delete child widgets, Qt does it all for us +} + diff --git a/noncore/net/opie-smb/qsmbbase.h b/noncore/net/opie-smb/qsmbbase.h new file mode 100644 index 0000000..3ee2f57 --- a/dev/null +++ b/noncore/net/opie-smb/qsmbbase.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** Form interface generated from reading ui file 'qsmbbase.ui' +** +** Created: Thu Aug 11 19:30:41 2005 +** by: The User Interface Compiler (uic) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ +#ifndef FORMQPESMBBASE_H +#define FORMQPESMBBASE_H + +#include +#include +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class QCheckBox; +class QComboBox; +class QLabel; +class QLineEdit; +class QListView; +class QListViewItem; +class QPushButton; +class QTabWidget; +class QTextView; + +class FormQPESMBBase : public QWidget +{ + Q_OBJECT + +public: + FormQPESMBBase( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + ~FormQPESMBBase(); + + QTabWidget* TabWidget2; + QWidget* tab; + QComboBox* CBHost; + QComboBox* mountpt; + QLabel* LScan; + QLabel* textLabel1; + QListView* ListViewScan; + QPushButton* BtnScan; + QPushButton* BtnClear; + QCheckBox* onbootBtn; + QPushButton* DoItBtn; + QLabel* pwdlabel; + QLineEdit* password; + QLabel* usrlabel; + QLineEdit* username; + QWidget* tab_2; + QTextView* TextViewOutput; + +protected: + QGridLayout* FormQPESMBBaseLayout; + QGridLayout* tabLayout; + QGridLayout* Layout6; + QHBoxLayout* Layout2; + QHBoxLayout* Layout5; + QGridLayout* tabLayout_2; +}; + +#endif // FORMQPESMBBASE_H diff --git a/noncore/net/opie-smb/qsmbbase.ui b/noncore/net/opie-smb/qsmbbase.ui new file mode 100644 index 0000000..35a1aec --- a/dev/null +++ b/noncore/net/opie-smb/qsmbbase.ui @@ -0,0 +1,298 @@ + +FormQPESMBBase + + QWidget + + name + FormQPESMBBase + + + geometry + + 0 + 0 + 254 + 352 + + + + font + + + + + caption + Opie Smb + + + layoutMargin + + + layoutSpacing + + + + margin + 0 + + + spacing + 2 + + + QTabWidget + + name + TabWidget2 + + + layoutMargin + + + layoutSpacing + + + QWidget + + name + tab + + + title + Scan + + + + margin + 2 + + + spacing + 0 + + + QComboBox + + name + CBHost + + + + QComboBox + + name + mountpt + + + + QLabel + + name + LScan + + + text + + + + + QLabel + + name + textLabel1 + + + text + mount pt: + + + + QListView + + + text + Shares + + + clickable + true + + + resizeable + true + + + + name + ListViewScan + + + + QPushButton + + name + BtnScan + + + text + &Scan + + + + QPushButton + + name + BtnClear + + + text + &Clear + + + + QCheckBox + + name + onbootBtn + + + text + Reconnect on boot + + + + QPushButton + + name + DoItBtn + + + text + &Login + + + + QLayoutWidget + + name + Layout6 + + + + margin + 0 + + + spacing + 6 + + + QLayoutWidget + + name + Layout2 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + pwdlabel + + + text + password + + + + QLineEdit + + name + password + + + + + + QLayoutWidget + + name + Layout5 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + usrlabel + + + text + username + + + + QLineEdit + + name + username + + + + + + + + + + QWidget + + name + tab + + + title + SMB Output + + + + margin + 11 + + + spacing + 6 + + + QTextView + + name + TextViewOutput + + + textFormat + PlainText + + + + + + + + -- cgit v0.9.0.2