summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opie-smb/qsmb.cpp77
1 files changed, 39 insertions, 38 deletions
diff --git a/noncore/net/opie-smb/qsmb.cpp b/noncore/net/opie-smb/qsmb.cpp
index 8aa4987..d6d1b23 100644
--- a/noncore/net/opie-smb/qsmb.cpp
+++ b/noncore/net/opie-smb/qsmb.cpp
@@ -1,36 +1,43 @@
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 <qdir.h> 8#include <qdir.h>
8#include <qfileinfo.h> 9#include <qfileinfo.h>
9 10
10#include <qpe/process.h> 11#include <qpe/process.h>
11#include <qlabel.h> 12#include <qlabel.h>
12#include <qlineedit.h> 13#include <qlineedit.h>
13#include <qcombobox.h> 14#include <qcombobox.h>
14#include <qstringlist.h> 15#include <qstringlist.h>
15#include <qcheckbox.h> 16#include <qcheckbox.h>
16#include <qtextview.h> 17#include <qtextview.h>
17#include <qmessagebox.h> 18#include <qmessagebox.h>
18 19
19 20
20#include <pthread.h> 21#include <pthread.h>
21#include <signal.h> 22#include <signal.h>
22#include <ctype.h> 23#include <ctype.h>
23 24
24 25
26#include <netinet/in.h>
27#include <arpa/inet.h>
28
29#include <rpc/clnt.h>
30
31
25#include <opie2/odebug.h> 32#include <opie2/odebug.h>
26using namespace Opie::Core; 33using namespace Opie::Core;
27 34
28 35
29Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl ) 36Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl )
30 : FormQPESMBBase( parent, name, fl ) 37 : FormQPESMBBase( parent, name, fl )
31{ 38{
32 connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int))); 39 connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int)));
33 connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked())); 40 connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked()));
34 connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked())); 41 connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked()));
35 connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear())); 42 connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear()));
36 43
@@ -83,49 +90,41 @@ void* runitm(void* arg)
83 Qsmb* caller = (Qsmb*)arg; 90 Qsmb* caller = (Qsmb*)arg;
84 caller->DoIt(); 91 caller->DoIt();
85 return(0); 92 return(0);
86} 93}
87 94
88void Qsmb::scan() 95void Qsmb::scan()
89{ 96{
90 int i; 97 int i;
91 98
92 if (scanning) return; 99 if (scanning) return;
93 scanning = true; 100 scanning = true;
94 101
95 char match[512], lmhosts[512]; 102 QString match;
103 char lmhosts[512];
96 QString cmd; 104 QString cmd;
97 char result[256]; 105 char result[256];
98 106
99 FILE *pipe, *pipe2; 107 FILE *pipe, *pipe2;
100 108
101 LScan->setText("Scanning..."); 109 LScan->setText("Scanning...");
102 qApp->processEvents(); 110 qApp->processEvents();
103 111
104 cmd = "ifconfig |grep 'addr:'|awk '{print $2}'|awk 'BEGIN{FS=\":\"}{print $2}'|sed 's/\\.[0-9]*$//'|head -n1"; 112 sockaddr_in my_addr;
113 get_myaddress( &my_addr);
105 114
106 owarn << "cmd: " << cmd << oendl; 115 QString ip = inet_ntoa( my_addr.sin_addr);
116 owarn << "IP Address : " << ip<< oendl;
107 117
108 /* run findsmb & read output */ 118 match = ip.left(5);
109 if ((pipe = popen(cmd.latin1(), "r")) == NULL) {
110 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
111 TextViewOutput->append(result);
112 return;
113 }
114 while(fgets(result, 256, pipe) != NULL) {
115 strcpy( match, result);
116 match[5]='\0';
117 break;
118 }
119 owarn << "match: " << match << oendl;
120 119
121 cmd = "smbfind"; 120 cmd = "smbfind";
122 owarn <<"cmd: " << cmd << oendl; 121 owarn <<"cmd: " << cmd << oendl;
123 122
124 TextViewOutput->append(cmd); 123 TextViewOutput->append(cmd);
125 124
126 snprintf(lmhosts, 512, "echo '127.0.0.1 localhost'>/etc/samba/lmhosts"); 125 snprintf(lmhosts, 512, "echo '127.0.0.1 localhost'>/etc/samba/lmhosts");
127 126
128 if ((pipe2 = popen(lmhosts, "r")) == NULL) { 127 if ((pipe2 = popen(lmhosts, "r")) == NULL) {
129 snprintf(result, 256, "Error: Can't run %s", lmhosts); 128 snprintf(result, 256, "Error: Can't run %s", lmhosts);
130 //TextViewOutput->append(result); 129 //TextViewOutput->append(result);
131 return; 130 return;
@@ -134,25 +133,25 @@ void Qsmb::scan()
134 /* run command & read output */ 133 /* run command & read output */
135 if ((pipe = popen(cmd.latin1(), "r")) == NULL) { 134 if ((pipe = popen(cmd.latin1(), "r")) == NULL) {
136 snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 135 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
137 TextViewOutput->append(result); 136 TextViewOutput->append(result);
138 return; 137 return;
139 } 138 }
140 139
141 /* parse output and display in ListViewScan */ 140 /* parse output and display in ListViewScan */
142 while(fgets(result, 256, pipe) != NULL) { 141 while(fgets(result, 256, pipe) != NULL) {
143 /* put result into TextViewOutput */ 142 /* put result into TextViewOutput */
144 TextViewOutput->append(result); 143 TextViewOutput->append(result);
145 144
146 if( strstr(result, match) != NULL ) { 145 if( strstr(result, match.latin1()) != NULL ) {
147 char ip_addr[256], host[256], *ptr1; 146 char ip_addr[256], host[256], *ptr1;
148 147
149 strcpy( ip_addr, result); 148 strcpy( ip_addr, result);
150 ptr1 = strchr(ip_addr,' '); 149 ptr1 = strchr(ip_addr,' ');
151 strcpy( host, ptr1); 150 strcpy( host, ptr1);
152 ip_addr[ptr1 - ip_addr]='\0'; 151 ip_addr[ptr1 - ip_addr]='\0';
153 152
154 for(i = 0; i < 256; i++) { 153 for(i = 0; i < 256; i++) {
155 if(host[i]!=' ') { 154 if(host[i]!=' ') {
156 strcpy( host, host + i); 155 strcpy( host, host + i);
157 break; 156 break;
158 } 157 }
@@ -274,104 +273,106 @@ void Qsmb::DoIt()
274{ 273{
275 QListViewItem *element; 274 QListViewItem *element;
276 element = ListViewScan->selectedItem(); 275 element = ListViewScan->selectedItem();
277 if(!element) { 276 if(!element) {
278 QMessageBox::warning(this, tr("Error!!"),tr("<p><b>No</b> share selected!!</p>")); 277 QMessageBox::warning(this, tr("Error!!"),tr("<p><b>No</b> share selected!!</p>"));
279 return; 278 return;
280 } 279 }
281 280
282 if (scanning) return; 281 if (scanning) return;
283 scanning = true; 282 scanning = true;
284 283
285 int i; 284 int i;
285 bool err = false;
286 286
287 char share[512]; 287 char share[512];
288 QString cmd; 288 QString cmd;
289 QString cmd2; 289 QString cmd2;
290 char result[256]; 290 char result[256];
291// QString result; 291// QString result;
292 QString text = mountpt->currentText(); 292 QString text = mountpt->currentText();
293 293
294 FILE *pipe,*pipe2; 294 FILE *pipe,*pipe2;
295 295
296 LScan->setText("Mounting..."); 296 LScan->setText("Mounting...");
297 qApp->processEvents(); 297 qApp->processEvents();
298 298
299 299
300 if(! QFileInfo(text).exists()) { 300 if(! QFileInfo(text).exists()) {
301 cmd = "mkdir -p "+ text; 301// /* make sure mount exists! */
302 owarn<<"cmd: "<< cmd << oendl; 302
303 /* make sure mount exists! */ 303// cmd = "mkdir -p "+ text;
304 if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) { 304// owarn<<"cmd: "<< cmd << oendl;
305 snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 305// if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) {
306 // result = "Error: Can't run " + cmd; 306// snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
307 TextViewOutput->append(result); 307// TextViewOutput->append(result);
308 return; 308// return;
309 } 309// }
310 while(fgets(result, 256, pipe2) != NULL) { 310// while(fgets(result, 256, pipe2) != NULL) {
311 /* put result into TextViewOutput */ 311// /* put result into TextViewOutput */
312 TextViewOutput->append(result); 312// TextViewOutput->append(result);
313 } 313// }
314 QStringList ccmd;
315 ccmd << "mkdir";
316 ccmd << "-p";
317 ccmd << text;
318
319 owarn<<"cmd: "<< ccmd << oendl;
320 runCommand(ccmd);
314 } 321 }
315 322
316 323
317 strcpy(share,(const char *)element->text(0)); 324 strcpy(share,(const char *)element->text(0));
318 325
319 for(i = 0; i < 256; i++) { 326 for(i = 0; i < 256; i++) {
320 if(isalpha( share[i])) { 327 if(isalpha( share[i])) {
321 strcpy( share, share + i); 328 strcpy( share, share + i);
322 break; 329 break;
323 } 330 }
324 } 331 }
325 332
326 cmd = "/usr/bin/smbmount //"+CBHost->currentText()+"/"+share+" "+mountpt->currentText()+" -o username="+username->text()+",password="+password->text(); 333 cmd = "/usr/bin/smbmount //"+CBHost->currentText()+"/"+share+" "+mountpt->currentText()+" -o username="+username->text()+",password="+password->text();
327 334
328 owarn << "cmd: " << cmd << oendl; 335 owarn << "cmd: " << cmd << oendl;
329 TextViewOutput->append(cmd.latin1()); 336 TextViewOutput->append(cmd.latin1());
330 337
331 338
332 if(onbootBtn->isChecked()) { 339 if(onbootBtn->isChecked()) {
333 owarn << "Saving Setting permanently..." << oendl; 340 owarn << "Saving Setting permanently..." << oendl;
334 cmd2 = "echo '" + cmd + "'>/opt/QtPalmtop/etc/samba.env"; 341 cmd2 = "echo '" + cmd + "'>/opt/QtPalmtop/etc/samba.env";
335
336 /* run command & read output */ 342 /* run command & read output */
337 if ((pipe = popen(cmd2.latin1(), "r")) == NULL) { 343 if ((pipe = popen(cmd2.latin1(), "r")) == NULL) {
338
339 snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 344 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
340// result = "Error: Can't run "+ cmd;
341 //TextViewOutput->append(result);
342 return; 345 return;
343 } 346 }
344 /* parse output and display in ListViewScan */ 347 /* parse output and display in ListViewScan */
345 while(fgets(result, 256, pipe) != NULL) { 348 while(fgets(result, 256, pipe) != NULL) {
346 /* put result into TextViewOutput */
347 //TextViewOutput->append(result);
348 } 349 }
349 } 350 }
350 351
352
351 /* run command & read output */ 353 /* run command & read output */
352 if ((pipe = popen(cmd.latin1(), "r")) == NULL) { 354 if ((pipe = popen(cmd.latin1(), "r")) == NULL) {
353
354// result = "Error: Can't run "+ cmd;
355 snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 355 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
356
357 TextViewOutput->append(result); 356 TextViewOutput->append(result);
358 return; 357 return;
359 } 358 }
360 359
361 /* parse output and display in ListViewScan */ 360 /* parse output and display in ListViewScan */
362 while(fgets(result, 256, pipe) != NULL) { 361 while(fgets(result, 256, pipe) != NULL) {
363 /* put result into TextViewOutput */ 362 /* put result into TextViewOutput */
364 TextViewOutput->append(result); 363 TextViewOutput->append(result);
365 } 364 }
365
366
366 TextViewOutput->append("\n\n================CheckMounts==================\n"); 367 TextViewOutput->append("\n\n================CheckMounts==================\n");
367 LScan->setText(""); 368 LScan->setText("");
368 369
369 cmd = "/bin/mount 2>&1"; 370 cmd = "/bin/mount 2>&1";
370 owarn << "cmd: " << cmd << oendl; 371 owarn << "cmd: " << cmd << oendl;
371 372
372 if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) { 373 if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) {
373 374
374 snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 375 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
375// result = "Error: Can't run "+ cmd; 376// result = "Error: Can't run "+ cmd;
376 377
377 TextViewOutput->append(result); 378 TextViewOutput->append(result);