summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opie-smb/qsmb.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/noncore/net/opie-smb/qsmb.cpp b/noncore/net/opie-smb/qsmb.cpp
index b978b46..e2ddc7f 100644
--- a/noncore/net/opie-smb/qsmb.cpp
+++ b/noncore/net/opie-smb/qsmb.cpp
@@ -1,408 +1,416 @@
1#include "qsmb.h" 1#include "qsmb.h"
2#include <qpushbutton.h> 2#include <qpushbutton.h>
3#include <qpe/qpeapplication.h> 3#include <qpe/qpeapplication.h>
4 4
5#include <string.h> 5#include <string.h>
6#include <qstring.h> 6#include <qstring.h>
7#include <qstringlist.h> 7#include <qstringlist.h>
8#include <qdir.h> 8#include <qdir.h>
9#include <qfileinfo.h> 9#include <qfileinfo.h>
10#include <qtabwidget.h> 10#include <qtabwidget.h>
11 11
12#include <qpe/process.h> 12#include <qpe/process.h>
13#include <qlabel.h> 13#include <qlabel.h>
14#include <qlineedit.h> 14#include <qlineedit.h>
15#include <qcombobox.h> 15#include <qcombobox.h>
16#include <qstringlist.h> 16#include <qstringlist.h>
17#include <qcheckbox.h> 17#include <qcheckbox.h>
18#include <qtextview.h> 18#include <qtextview.h>
19#include <qmessagebox.h> 19#include <qmessagebox.h>
20#include <qtextstream.h> 20#include <qtextstream.h>
21 21
22 22
23#include <pthread.h> 23#include <pthread.h>
24#include <signal.h> 24#include <signal.h>
25#include <ctype.h> 25#include <ctype.h>
26 26
27 27
28#include <netinet/in.h> 28#include <netinet/in.h>
29#include <arpa/inet.h> 29#include <arpa/inet.h>
30#include <rpc/clnt.h> 30#include <rpc/clnt.h>
31 31
32#include <sys/vfs.h> 32#include <sys/vfs.h>
33#include <mntent.h> 33#include <mntent.h>
34 34
35// #include <opie2/odebug.h> 35// #include <opie2/odebug.h>
36// using namespace Opie::Core; 36// using namespace Opie::Core;
37 37
38 38
39Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl ) 39Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl )
40 : FormQPESMBBase( parent, name, fl ) 40 : FormQPESMBBase( parent, name, fl )
41{ 41{
42 connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int))); 42 connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int)));
43 connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked())); 43 connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked()));
44 connect(UnmountBtn, SIGNAL(clicked()), this, SLOT(umountIt())); 44 connect(UnmountBtn, SIGNAL(clicked()), this, SLOT(umountIt()));
45 connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked())); 45 connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked()));
46 connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear())); 46 connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear()));
47 47
48 mountpt->setEditable(true); 48 mountpt->setEditable(true);
49 mountpt->insertItem("/mnt/samba1",-1); 49 mountpt->insertItem("/mnt/samba1",-1);
50 mountpt->insertItem("/mnt/samba2",-1); 50 mountpt->insertItem("/mnt/samba2",-1);
51 mountpt->insertItem("/mnt/samba3",-1); 51 mountpt->insertItem("/mnt/samba3",-1);
52 52
53// TextViewOutput 53 setTabOrder(BtnScan, username);
54 setTabOrder(username, password);
55 setTabOrder(password, CBHost);
56 setTabOrder(CBHost, TextViewOutput);
57 setTabOrder(TextViewOutput, mountpt);
58 setTabOrder(mountpt, DoItBtn);
59 setTabOrder(DoItBtn, UnmountBtn);
54 60
55 top_element = NULL; 61 top_element = NULL;
56 scanning = false; 62 scanning = false;
57} 63}
58 64
59Qsmb::~Qsmb() 65Qsmb::~Qsmb()
60{ 66{
61} 67}
62 68
63void Qsmb::clear() 69void Qsmb::clear()
64{ 70{
65 if (scanning) return; 71 if (scanning) return;
66 ListViewScan->clear(); 72 ListViewScan->clear();
67 TextViewOutput->setText(""); 73 TextViewOutput->setText("");
74 CBHost->clear();
68 top_element = NULL; 75 top_element = NULL;
69} 76}
70 77
71void Qsmb::scanClicked() 78void Qsmb::scanClicked()
72{ 79{
73 if (scanning) return; 80 if (scanning) return;
74 pthread_create(&tpid, NULL, runit, (void *)this); 81 pthread_create(&tpid, NULL, runit, (void *)this);
75} 82}
76 83
77void Qsmb::DoItClicked() 84void Qsmb::DoItClicked()
78{ 85{
79 86
80 if( !ListViewScan->selectedItem()) { 87 if( !ListViewScan->selectedItem()) {
81 QMessageBox::warning(this, tr("Error"),tr("<p>No share selected!</p>")); 88 QMessageBox::warning(this, tr("Error"),tr("<p>No share selected!</p>"));
82 return; 89 return;
83 } 90 }
84 if (scanning) return; 91 if (scanning) return;
85 pthread_create(&tpid, NULL, runitm, (void *)this); 92 pthread_create(&tpid, NULL, runitm, (void *)this);
86} 93}
87 94
88void* runit(void* arg) 95void* runit(void* arg)
89{ 96{
90 Qsmb* caller = (Qsmb*)arg; 97 Qsmb* caller = (Qsmb*)arg;
91 caller->scan(); 98 caller->scan();
92 return(0); 99 return(0);
93} 100}
94 101
95void* runitm(void* arg) 102void* runitm(void* arg)
96{ 103{
97 Qsmb* caller = (Qsmb*)arg; 104 Qsmb* caller = (Qsmb*)arg;
98 caller->DoIt(); 105 caller->DoIt();
99 return(0); 106 return(0);
100} 107}
101 108
102void Qsmb::scan() 109void Qsmb::scan()
103{ 110{
104 if (scanning) return; 111 clear();
112// if (scanning) return;
105 scanning = true; 113 scanning = true;
106 114
107 QString match; 115 QString match;
108 QString cmd; 116 QString cmd;
109 LScan->setText("Scanning..."); 117 LScan->setText("Scanning...");
110 qApp->processEvents(); 118 qApp->processEvents();
111 119
112 sockaddr_in my_addr; 120 sockaddr_in my_addr;
113 get_myaddress( &my_addr); 121 get_myaddress( &my_addr);
114 122
115 QString ip = inet_ntoa( my_addr.sin_addr); 123 QString ip = inet_ntoa( my_addr.sin_addr);
116 qWarning("IP Address : "+ip); 124 qWarning("IP Address : "+ip);
117 125
118 match = ip.left(5); 126 match = ip.left(5);
119 127
120 QStringList ccmd; 128 QStringList ccmd;
121 TextViewOutput->append("smbfind"); 129 TextViewOutput->append("smbfind");
122 130
123 QFile lmhosts("/etc/samba/lmhosts"); 131 QFile lmhosts("/etc/samba/lmhosts");
124 QTextStream lms(&lmhosts); 132 QTextStream lms(&lmhosts);
125 lmhosts.open(IO_WriteOnly); 133 lmhosts.open(IO_WriteOnly);
126 lms << "127.0.0.1 localhost\n"; 134 lms << "127.0.0.1 localhost\n";
127 135
128 /* parse output and display in ListViewScan */ 136 /* parse output and display in ListViewScan */
129 ccmd = "smbfind"; 137 ccmd = "smbfind";
130 runCommand(ccmd); 138 runCommand(ccmd);
131 139
132 QTextStream s(&out, IO_ReadOnly); 140 QTextStream s(&out, IO_ReadOnly);
133 141
134 while ( !s.atEnd() ) { 142 while ( !s.atEnd() ) {
135 QString ip_addr, host, output; 143 QString ip_addr, host, output;
136 QString tmp = s.readLine(); 144 QString tmp = s.readLine();
137 bool ok; 145 bool ok;
138 tmp.left(1).toInt( &ok, 10 ); 146 tmp.left(1).toInt( &ok, 10 );
139 if(ok) { 147 if(ok) {
140 QStringList token = QStringList::split(' ', tmp ); 148 QStringList token = QStringList::split(' ', tmp );
141 ip_addr = token[0]; 149 ip_addr = token[0];
142 host = token[1]; 150 host = token[1];
143 CBHost->insertItem( host, -1); 151 CBHost->insertItem( host, -1);
144 lms << ip_addr+" "+host+"\n"; 152 lms << ip_addr+" "+host+"\n";
145 } 153 }
146 } 154 }
147 lmhosts.close(); 155 lmhosts.close();
148 156
149 TextViewOutput->append("\n\n============================================\n"); 157 TextViewOutput->append("\n\n============================================\n");
150 LScan->setText(""); 158 LScan->setText("");
151 scanning = false; 159 scanning = false;
152} 160}
153 161
154void Qsmb::hostSelected(int /*index*/ ) 162void Qsmb::hostSelected(int /*index*/ )
155{ 163{
156 QListViewItem *element; 164 QListViewItem *element;
157// QListViewItem *parent; 165// QListViewItem *parent;
158 166
159 QString text = CBHost->currentText(); 167 QString text = CBHost->currentText();
160 ListViewScan->clear(); 168 ListViewScan->clear();
161 169
162 if (scanning) return; 170 if (scanning) return;
163 scanning = true; 171 scanning = true;
164 172
165 QString cmd; 173 QString cmd;
166 QStringList ccmd; 174 QStringList ccmd;
167 175
168 LScan->setText("Scanning..."); 176 LScan->setText("Scanning...");
169 177
170 ccmd << "/usr/bin/smbclient"; 178 ccmd << "/usr/bin/smbclient";
171 ccmd << "-L"; 179 ccmd << "-L";
172 ccmd << CBHost->currentText(); 180 ccmd << CBHost->currentText();
173 ccmd << "-N"; 181 ccmd << "-N";
174 182
175 if(username->text().isEmpty()) { 183 if(username->text().isEmpty()) {
176 //do nothing 184 //do nothing
177 } else { 185 } else {
178 ccmd << "-U"; 186 ccmd << "-U";
179 ccmd << username->text()+"\%"+ password->text(); 187 ccmd << username->text()+"\%"+ password->text();
180 } 188 }
181 runCommand(ccmd); 189 runCommand(ccmd);
182 QTextStream s(&out, IO_ReadOnly); 190 QTextStream s(&out, IO_ReadOnly);
183 191
184 while ( !s.atEnd() ) { 192 while ( !s.atEnd() ) {
185 QString share; 193 QString share;
186 QString comment; 194 QString comment;
187 QString tmp = s.readLine(); 195 QString tmp = s.readLine();
188 196
189 if( tmp.find("$") == -1 && tmp.find("Disk") != -1) { 197 if( tmp.find("$") == -1 && tmp.find("Disk") != -1) {
190 QStringList token = QStringList::split(' ', tmp ); 198 QStringList token = QStringList::split(' ', tmp );
191 share = token[0]; 199 share = token[0];
192 comment = token[2]; 200 comment = token[2];
193 share = share.stripWhiteSpace(); 201 share = share.stripWhiteSpace();
194 comment = comment.stripWhiteSpace(); 202 comment = comment.stripWhiteSpace();
195 element = new QListViewItem(ListViewScan, share, comment); 203 element = new QListViewItem(ListViewScan, share, comment);
196 element->setOpen(true); 204 element->setOpen(true);
197// top_element = element; 205// top_element = element;
198// parent = element; 206// parent = element;
199 } 207 }
200 208
201 } 209 }
202// owarn << "i="<< index << "cmd:" << cmd << oendl; 210// owarn << "i="<< index << "cmd:" << cmd << oendl;
203 211
204 TextViewOutput->append(cmd); 212 TextViewOutput->append(cmd);
205 213
206 /* run smbclient & read output */ 214 /* run smbclient & read output */
207// if ((pipe = popen(cmd.latin1(), "r")) == NULL) { 215// if ((pipe = popen(cmd.latin1(), "r")) == NULL) {
208// snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 216// snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
209// // cmd = "Error: Can't run "+cmd; 217// // cmd = "Error: Can't run "+cmd;
210// TextViewOutput->append(result); 218// TextViewOutput->append(result);
211// return; 219// return;
212// } 220// }
213 221
214 /* parse output and display in ListViewScan */ 222 /* parse output and display in ListViewScan */
215// while(fgets(result, 256, pipe) != NULL) { 223// while(fgets(result, 256, pipe) != NULL) {
216// /* put result into TextViewOutput */ 224// /* put result into TextViewOutput */
217// TextViewOutput->append(result); 225// TextViewOutput->append(result);
218 226
219// if( strchr(result, '$') == NULL ) { 227// if( strchr(result, '$') == NULL ) {
220// char share[256], *ptr1; 228// char share[256], *ptr1;
221 229
222// strcpy(share,result); 230// strcpy(share,result);
223// ptr1 = strchr(share,' '); 231// ptr1 = strchr(share,' ');
224// share[ptr1 - share]='\0'; 232// share[ptr1 - share]='\0';
225 233
226// owarn<< "add share: " << share << oendl; 234// owarn<< "add share: " << share << oendl;
227 235
228// if(top_element != NULL) { 236// if(top_element != NULL) {
229// bool found = false; 237// bool found = false;
230// element = top_element; 238// element = top_element;
231 239
232// while(element != NULL && !found) { 240// while(element != NULL && !found) {
233// if(strcmp( element->text(0).ascii(), share)==0) { 241// if(strcmp( element->text(0).ascii(), share)==0) {
234// parent = element; 242// parent = element;
235// found = true; 243// found = true;
236// } 244// }
237// element = element->nextSibling(); 245// element = element->nextSibling();
238// } 246// }
239 247
240// if(!found) { 248// if(!found) {
241// element = new QListViewItem(ListViewScan,share); 249// element = new QListViewItem(ListViewScan,share);
242// element->setOpen(true); 250// element->setOpen(true);
243// parent=element; 251// parent=element;
244// } 252// }
245// } else { 253// } else {
246// element = new QListViewItem(ListViewScan,share); 254// element = new QListViewItem(ListViewScan,share);
247// element->setOpen(true); 255// element->setOpen(true);
248// top_element = element; 256// top_element = element;
249// parent = element; 257// parent = element;
250// } 258// }
251// } 259// }
252// } 260// }
253 261
254 TextViewOutput->append("\n\n============================================\n"); 262 TextViewOutput->append("\n\n============================================\n");
255 LScan->setText(""); 263 LScan->setText("");
256 scanning = false; 264 scanning = false;
257} 265}
258 266
259 267
260void Qsmb::DoIt() 268void Qsmb::DoIt()
261{ 269{
262 270
263 QListViewItem *element; 271 QListViewItem *element;
264 element = ListViewScan->selectedItem(); 272 element = ListViewScan->selectedItem();
265 if(!element) { 273 if(!element) {
266 return; 274 return;
267 } 275 }
268 276
269 if (scanning) return; 277 if (scanning) return;
270 scanning = true; 278 scanning = true;
271 279
272 QString mount = mountpt->currentText(); 280 QString mount = mountpt->currentText();
273 if(isMounted(mount)) { 281 if(isMounted(mount)) {
274 qWarning(mount +" is already mounted"); 282 qWarning(mount +" is already mounted");
275 TextViewOutput->append(mount +" is already mounted"); 283 TextViewOutput->append(mount +" is already mounted");
276 return; 284 return;
277 } 285 }
278 286
279 bool noerr = false; 287 bool noerr = false;
280 288
281 QString share; 289 QString share;
282 QString cmd; 290 QString cmd;
283 QString cmd2; 291 QString cmd2;
284 QString text = mountpt->currentText(); 292 QString text = mountpt->currentText();
285 QStringList ccmd; 293 QStringList ccmd;
286 294
287 LScan->setText("Mounting..."); 295 LScan->setText("Mounting...");
288 qApp->processEvents(); 296 qApp->processEvents();
289 297
290 if( !QFileInfo(text).exists()) { 298 if( !QFileInfo(text).exists()) {
291 ccmd << "mkdir"; 299 ccmd << "mkdir";
292 ccmd << "-p"; 300 ccmd << "-p";
293 ccmd << text; 301 ccmd << text;
294 302
295 qWarning( "cmd: "+ ccmd.join(" ")); 303 qWarning( "cmd: "+ ccmd.join(" "));
296 runCommand(ccmd); 304 runCommand(ccmd);
297 } 305 }
298 306
299 share = element->text(0); 307 share = element->text(0);
300 qWarning("selected share is "+share); 308 qWarning("selected share is "+share);
301 309
302 QString service = CBHost->currentText(); 310 QString service = CBHost->currentText();
303 service = service.stripWhiteSpace(); 311 service = service.stripWhiteSpace();
304 if(mount.left(1) != "/") 312 if(mount.left(1) != "/")
305 mount = QDir::currentDirPath()+"/"+mount; 313 mount = QDir::currentDirPath()+"/"+mount;
306 mount = mount.stripWhiteSpace(); 314 mount = mount.stripWhiteSpace();
307 ccmd.clear(); 315 ccmd.clear();
308 316
309 ccmd << "/usr/bin/smbmount"; 317 ccmd << "/usr/bin/smbmount";
310 ccmd << "//"+ service+"/"+share; 318 ccmd << "//"+ service+"/"+share;
311 ccmd << mount; 319 ccmd << mount;
312 ccmd << "-o"; 320 ccmd << "-o";
313 ccmd << "username="+username->text()+",password="+password->text()+""; 321 ccmd << "username="+username->text()+",password="+password->text()+"";
314 322
315 TextViewOutput->append(ccmd.join(" ").latin1()); 323 TextViewOutput->append(ccmd.join(" ").latin1());
316 324
317 if(onbootBtn->isChecked()) { 325 if(onbootBtn->isChecked()) {
318 qWarning("Saving Setting permanently..."); 326 qWarning("Saving Setting permanently...");
319 QFile sambenv("/opt/QtPalmtop/etc/samba.env"); 327 QFile sambenv("/opt/QtPalmtop/etc/samba.env");
320 QTextStream smbv(&sambenv); 328 QTextStream smbv(&sambenv);
321 sambenv.open(IO_WriteOnly); 329 sambenv.open(IO_WriteOnly);
322 smbv << ccmd.join(" ") ; 330 smbv << ccmd.join(" ") ;
323 sambenv.close(); 331 sambenv.close();
324 } 332 }
325 333
326 noerr = runCommand(ccmd); 334 noerr = runCommand(ccmd);
327 335
328 LScan->setText(""); 336 LScan->setText("");
329 337
330 if(noerr) { 338 if(noerr) {
331 element->setText(2, mount); 339 element->setText(2, mount);
332 TextViewOutput->append("\n\n================CheckMounts==================\n"); 340 TextViewOutput->append("\n\n================CheckMounts==================\n");
333 ccmd = "/bin/mount"; 341 ccmd = "/bin/mount";
334 runCommand(ccmd); 342 runCommand(ccmd);
335 TextViewOutput->append("\n\n============================================\n"); 343 TextViewOutput->append("\n\n============================================\n");
336 qApp->processEvents(); 344 qApp->processEvents();
337 } else { 345 } else {
338 //do nothing 346 //do nothing
339 } 347 }
340 348
341 scanning = false; 349 scanning = false;
342} 350}
343 351
344void Qsmb::umountIt() 352void Qsmb::umountIt()
345{ 353{
346 QString mount = mountpt->currentText(); 354 QString mount = mountpt->currentText();
347 if(!isMounted(mount)) { 355 if(!isMounted(mount)) {
348 qWarning(mount +" is not mounted"); 356 qWarning(mount +" is not mounted");
349 TextViewOutput->append(mount +" is not mounted"); 357 TextViewOutput->append(mount +" is not mounted");
350 return; 358 return;
351 } 359 }
352 360
353 QStringList ccmd; 361 QStringList ccmd;
354 QString share; 362 QString share;
355 QListViewItem *element; 363 QListViewItem *element;
356 element = ListViewScan->selectedItem(); 364 element = ListViewScan->selectedItem();
357 share = element->text(0); 365 share = element->text(0);
358 qWarning("selected share is "+share); 366 qWarning("selected share is "+share);
359 367
360 if(mount.left(1) != "/") 368 if(mount.left(1) != "/")
361 mount = QDir::currentDirPath()+"/"+mount; 369 mount = QDir::currentDirPath()+"/"+mount;
362 mount = mount.stripWhiteSpace(); 370 mount = mount.stripWhiteSpace();
363 371
364 ccmd << "/usr/bin/smbumount"; 372 ccmd << "/usr/bin/smbumount";
365 ccmd << mount; 373 ccmd << mount;
366 runCommand(ccmd); 374 runCommand(ccmd);
367 375
368 element->setText(2, ""); 376 element->setText(2, "");
369 377
370 ccmd = "/bin/mount"; 378 ccmd = "/bin/mount";
371 runCommand(ccmd); 379 runCommand(ccmd);
372} 380}
373 381
374bool Qsmb::runCommand(const QStringList & command) { 382bool Qsmb::runCommand(const QStringList & command) {
375 qWarning( "runCommand " + command.join(" ") ); 383 qWarning( "runCommand " + command.join(" ") );
376 TextViewOutput->append(command.join(" ")); 384 TextViewOutput->append(command.join(" "));
377 out = ""; 385 out = "";
378 Process ipkg_status( command); 386 Process ipkg_status( command);
379 bool r = ipkg_status.exec("",out); 387 bool r = ipkg_status.exec("",out);
380 388
381 qWarning("result is %d"+ r ); 389 qWarning("result is %d"+ r );
382 qWarning("Output " + out ); 390 qWarning("Output " + out );
383 TextViewOutput->append(out); 391 TextViewOutput->append(out);
384 392
385//very hacky 393//very hacky
386 if(out.find("failed") !=-1) { 394 if(out.find("failed") !=-1) {
387 r = false; 395 r = false;
388 } 396 }
389 return r; 397 return r;
390} 398}
391 399
392 400
393bool Qsmb::isMounted(const QString &mountPoint) { 401bool Qsmb::isMounted(const QString &mountPoint) {
394 struct mntent *me; 402 struct mntent *me;
395 bool mounted = false; 403 bool mounted = false;
396 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 404 FILE *mntfp = setmntent( "/etc/mtab", "r" );
397 if ( mntfp ){ 405 if ( mntfp ){
398 while ( (me = getmntent( mntfp )) != 0 ) { 406 while ( (me = getmntent( mntfp )) != 0 ) {
399 QString deviceName = me->mnt_fsname; 407 QString deviceName = me->mnt_fsname;
400 QString mountDir = me->mnt_dir; 408 QString mountDir = me->mnt_dir;
401 QString fsType = me->mnt_type; 409 QString fsType = me->mnt_type;
402 if( fsType == "smbfs" && mountDir.find(mountPoint) !=-1) 410 if( fsType == "smbfs" && mountDir.find(mountPoint) !=-1)
403 mounted = true; 411 mounted = true;
404 } 412 }
405 } 413 }
406 endmntent( mntfp ); 414 endmntent( mntfp );
407 return mounted; 415 return mounted;
408} 416}