summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opie-smb/qsmb.cpp83
-rw-r--r--noncore/net/opie-smb/qsmb.h11
2 files changed, 50 insertions, 44 deletions
diff --git a/noncore/net/opie-smb/qsmb.cpp b/noncore/net/opie-smb/qsmb.cpp
index 880573b..8aa4987 100644
--- a/noncore/net/opie-smb/qsmb.cpp
+++ b/noncore/net/opie-smb/qsmb.cpp
@@ -1,88 +1,84 @@
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 <qdir.h> 7#include <qdir.h>
8#include <qfileinfo.h> 8#include <qfileinfo.h>
9 9
10#include <qpe/process.h>
10#include <qlabel.h> 11#include <qlabel.h>
11#include <qlineedit.h> 12#include <qlineedit.h>
12#include <qcombobox.h> 13#include <qcombobox.h>
13#include <qstringlist.h> 14#include <qstringlist.h>
14#include <qcheckbox.h> 15#include <qcheckbox.h>
15#include <qtextview.h> 16#include <qtextview.h>
16#include <qmessagebox.h> 17#include <qmessagebox.h>
17 18
18 19
19#include <pthread.h> 20#include <pthread.h>
20#include <signal.h> 21#include <signal.h>
21#include <ctype.h> 22#include <ctype.h>
22 23
23 24
24#include <opie2/odebug.h> 25#include <opie2/odebug.h>
25using namespace Opie::Core; 26using namespace Opie::Core;
26 27
27 28
28Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl ) 29Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl )
29 : FormQPESMBBase( parent, name, fl ) 30 : FormQPESMBBase( parent, name, fl )
30{ 31{
31 connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int))); 32 connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int)));
32 connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked())); 33 connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked()));
33 connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked())); 34 connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked()));
34 connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear())); 35 connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear()));
35 36
36//TODO configurable mount points
37 if(!QFileInfo("/mnt/samba1").exists()) system("mkdir /mnt/samba1");
38 if(!QFileInfo("/mnt/samba2").exists()) system("mkdir /mnt/samba2");
39 if(!QFileInfo("/mnt/samba2").exists()) system("mkdir /mnt/samba3");
40
41 mountpt->insertItem("/mnt/samba1",-1); 37 mountpt->insertItem("/mnt/samba1",-1);
42 mountpt->insertItem("/mnt/samba2",-1); 38 mountpt->insertItem("/mnt/samba2",-1);
43 mountpt->insertItem("/mnt/samba3",-1); 39 mountpt->insertItem("/mnt/samba3",-1);
44 40
45 top_element = NULL; 41 top_element = NULL;
46 scanning = false; 42 scanning = false;
47} 43}
48 44
49Qsmb::~Qsmb() 45Qsmb::~Qsmb()
50{ 46{
51} 47}
52 48
53void Qsmb::clear() 49void Qsmb::clear()
54{ 50{
55 if (scanning) return; 51 if (scanning) return;
56 ListViewScan->clear(); 52 ListViewScan->clear();
57 TextViewOutput->setText(""); 53 TextViewOutput->setText("");
58 top_element = NULL; 54 top_element = NULL;
59} 55}
60 56
61void Qsmb::scanClicked() 57void Qsmb::scanClicked()
62{ 58{
63 if (scanning) return; 59 if (scanning) return;
64 pthread_create(&tpid, NULL, runit, (void *)this); 60 pthread_create(&tpid, NULL, runit, (void *)this);
65} 61}
66 62
67void Qsmb::DoItClicked() 63void Qsmb::DoItClicked()
68{ 64{
69 65
70 if(! ListViewScan->selectedItem()) { 66 if(! ListViewScan->selectedItem()) {
71 QMessageBox::warning(this, tr("Error"),tr("<p>No share selected!</p>")); 67 QMessageBox::warning(this, tr("Error"),tr("<p>No share selected!</p>"));
72 return; 68 return;
73 } 69 }
74 if (scanning) return; 70 if (scanning) return;
75 pthread_create(&tpid, NULL, runitm, (void *)this); 71 pthread_create(&tpid, NULL, runitm, (void *)this);
76} 72}
77 73
78void* runit(void* arg) 74void* runit(void* arg)
79{ 75{
80 Qsmb* caller = (Qsmb*)arg; 76 Qsmb* caller = (Qsmb*)arg;
81 caller->scan(); 77 caller->scan();
82 return(0); 78 return(0);
83} 79}
84 80
85void* runitm(void* arg) 81void* runitm(void* arg)
86{ 82{
87 Qsmb* caller = (Qsmb*)arg; 83 Qsmb* caller = (Qsmb*)arg;
88 caller->DoIt(); 84 caller->DoIt();
@@ -158,245 +154,252 @@ void Qsmb::scan()
158 for(i = 0; i < 256; i++) { 154 for(i = 0; i < 256; i++) {
159 if(host[i]!=' ') { 155 if(host[i]!=' ') {
160 strcpy( host, host + i); 156 strcpy( host, host + i);
161 break; 157 break;
162 } 158 }
163 } 159 }
164 ptr1 = strchr(host,' '); 160 ptr1 = strchr(host,' ');
165 host[ptr1 - host] = '\0'; 161 host[ptr1 - host] = '\0';
166 162
167 owarn << "add host: " << host << oendl; 163 owarn << "add host: " << host << oendl;
168 164
169 CBHost->insertItem( host, -1); 165 CBHost->insertItem( host, -1);
170 snprintf( lmhosts, 512, "echo '%s %s'>>/etc/samba/lmhosts", ip_addr,host); 166 snprintf( lmhosts, 512, "echo '%s %s'>>/etc/samba/lmhosts", ip_addr,host);
171 167
172 owarn << "lmhosts: " << lmhosts << oendl; 168 owarn << "lmhosts: " << lmhosts << oendl;
173 169
174 if ((pipe2 = popen(lmhosts, "r")) == NULL) { 170 if ((pipe2 = popen(lmhosts, "r")) == NULL) {
175 snprintf(result, 256, "Error: Can't run %s", lmhosts); 171 snprintf(result, 256, "Error: Can't run %s", lmhosts);
176 return; 172 return;
177 } 173 }
178 } 174 }
179 } 175 }
180 176
181 TextViewOutput->append("\n\n============================================\n"); 177 TextViewOutput->append("\n\n============================================\n");
182 LScan->setText(""); 178 LScan->setText("");
183 scanning = false; 179 scanning = false;
184} 180}
185 181
186void Qsmb::hostSelected(int index) 182void Qsmb::hostSelected(int index)
187{ 183{
188 owarn << "hostSelected" << oendl; 184 owarn << "hostSelected" << oendl;
189 int i; 185 int i;
190 186
191 QListViewItem *element; 187 QListViewItem *element;
192 QListViewItem *parent; 188 QListViewItem *parent;
193 189
194 QString text = CBHost->currentText(); 190 QString text = CBHost->currentText();
195 191
196 if (scanning) return; 192 if (scanning) return;
197 scanning = true; 193 scanning = true;
198 194
199 QString cmd; 195 QString cmd;
200 char result[256]; 196 char result[256];
201 197
202 FILE *pipe; 198 FILE *pipe;
203 199
204 LScan->setText("Scanning..."); 200 LScan->setText("Scanning...");
205 201
206 if((const char *)username->text() == '\0') 202 if(username->text().isEmpty())
207 cmd = "/usr/bin/smbclient -L //"+CBHost->currentText()+" -N 2>&1 |grep Disk"; 203 cmd = "/usr/bin/smbclient -L //"+CBHost->currentText()+" -N 2>&1 |grep Disk";
208 else 204 else
209 cmd = "/usr/bin/smbclient -L //"+CBHost->currentText()+" -N -U"+username->text()+":"+password->text()+" 2>&1 |grep Disk"; 205 cmd = "/usr/bin/smbclient -L //"+CBHost->currentText()+" -N -U "+username->text()+"\%"+password->text()+" 2>&1 |grep Disk";
210 206
211 for(i = 0; i < 512; i++) { 207// for(i = 0; i < 512; i++) {
212 if(cmd[i]==':') { 208// if(cmd[i]==':') {
213 cmd[i]='%'; 209// cmd[i]='%';
214 break; 210// break;
215 } 211// }
216 if(cmd[i]=='\0') 212// if(cmd[i]=='\0')
217 break; 213// break;
218 } 214// }
219 215
220 owarn << "i="<< index << "cmd:" << cmd << oendl; 216 owarn << "i="<< index << "cmd:" << cmd << oendl;
221 217
222 TextViewOutput->append(cmd); 218 TextViewOutput->append(cmd);
223 219
224 /* run smbclient & read output */ 220 /* run smbclient & read output */
225 if ((pipe = popen(cmd.latin1(), "r")) == NULL) { 221 if ((pipe = popen(cmd.latin1(), "r")) == NULL) {
226 snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 222 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
227// cmd = "Error: Can't run "+cmd; 223// cmd = "Error: Can't run "+cmd;
228 TextViewOutput->append(result); 224 TextViewOutput->append(result);
229 return; 225 return;
230 } 226 }
231 227
232 /* parse output and display in ListViewScan */ 228 /* parse output and display in ListViewScan */
233 while(fgets(result, 256, pipe) != NULL) { 229 while(fgets(result, 256, pipe) != NULL) {
234 /* put result into TextViewOutput */ 230 /* put result into TextViewOutput */
235 TextViewOutput->append(result); 231 TextViewOutput->append(result);
236 232
237 if( strchr(result, '$') == NULL ) { 233 if( strchr(result, '$') == NULL ) {
238 char share[256], *ptr1; 234 char share[256], *ptr1;
239 235
240 strcpy(share,result); 236 strcpy(share,result);
241 ptr1 = strchr(share,' '); 237 ptr1 = strchr(share,' ');
242 share[ptr1 - share]='\0'; 238 share[ptr1 - share]='\0';
243 239
244 owarn<< "add share: " << share << oendl; 240 owarn<< "add share: " << share << oendl;
245 241
246 if(top_element != NULL) { 242 if(top_element != NULL) {
247 bool found = false; 243 bool found = false;
248 element = top_element; 244 element = top_element;
249 245
250 while(element != NULL && !found) { 246 while(element != NULL && !found) {
251 if(strcmp( element->text(0).ascii(), share)==0) { 247 if(strcmp( element->text(0).ascii(), share)==0) {
252 parent = element; 248 parent = element;
253 found = true; 249 found = true;
254 } 250 }
255 element = element->nextSibling(); 251 element = element->nextSibling();
256 } 252 }
257 253
258 if(!found) { 254 if(!found) {
259 element = new QListViewItem(ListViewScan,share); 255 element = new QListViewItem(ListViewScan,share);
260 element->setOpen(true); 256 element->setOpen(true);
261 parent=element; 257 parent=element;
262 } 258 }
263 } else { 259 } else {
264 element = new QListViewItem(ListViewScan,share); 260 element = new QListViewItem(ListViewScan,share);
265 element->setOpen(true); 261 element->setOpen(true);
266 top_element = element; 262 top_element = element;
267 parent = element; 263 parent = element;
268 } 264 }
269 } 265 }
270 } 266 }
271 267
272 TextViewOutput->append("\n\n============================================\n"); 268 TextViewOutput->append("\n\n============================================\n");
273 LScan->setText(""); 269 LScan->setText("");
274 scanning = false; 270 scanning = false;
275} 271}
276 272
277void Qsmb::DoIt() 273void Qsmb::DoIt()
278{ 274{
279 QListViewItem *element; 275 QListViewItem *element;
280 element = ListViewScan->selectedItem(); 276 element = ListViewScan->selectedItem();
281 if(!element) { 277 if(!element) {
282 QMessageBox::warning(this, tr("Error!!"),tr("<p><b>No</b> share selected!!</p>")); 278 QMessageBox::warning(this, tr("Error!!"),tr("<p><b>No</b> share selected!!</p>"));
283 return; 279 return;
284 } 280 }
285 281
286 if (scanning) return; 282 if (scanning) return;
287 scanning = true; 283 scanning = true;
288 284
289 int i; 285 int i;
290 286
291 char share[512]; 287 char share[512];
292 QString cmd; 288 QString cmd;
293 QString cmd2; 289 QString cmd2;
294 char result[256]; 290 char result[256];
295// QString result; 291// QString result;
296 QString text = mountpt->currentText(); 292 QString text = mountpt->currentText();
297 293
298 FILE *pipe,*pipe2; 294 FILE *pipe,*pipe2;
299 295
300 LScan->setText("Mounting..."); 296 LScan->setText("Mounting...");
301 qApp->processEvents(); 297 qApp->processEvents();
302
303 cmd = "mkdir -p "+ text;
304
305 owarn<<"cmd: "<< cmd << oendl;
306 298
307 /* make sure mount exists! */
308 if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) {
309
310 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
311 // result = "Error: Can't run " + cmd;
312 TextViewOutput->append(result);
313 return;
314 }
315 299
316 while(fgets(result, 256, pipe2) != NULL) { 300 if(! QFileInfo(text).exists()) {
317 /* put result into TextViewOutput */ 301 cmd = "mkdir -p "+ text;
318 TextViewOutput->append(result); 302 owarn<<"cmd: "<< cmd << oendl;
303 /* make sure mount exists! */
304 if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) {
305 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
306 // result = "Error: Can't run " + cmd;
307 TextViewOutput->append(result);
308 return;
309 }
310 while(fgets(result, 256, pipe2) != NULL) {
311 /* put result into TextViewOutput */
312 TextViewOutput->append(result);
313 }
319 } 314 }
320 315
321 316
322 strcpy(share,(const char *)element->text(0)); 317 strcpy(share,(const char *)element->text(0));
323 318
324 for(i = 0; i < 256; i++) { 319 for(i = 0; i < 256; i++) {
325 if(isalpha( share[i])) { 320 if(isalpha( share[i])) {
326 strcpy( share, share + i); 321 strcpy( share, share + i);
327 break; 322 break;
328 } 323 }
329 } 324 }
330 325
331 cmd = "/usr/bin/smbmount //"+CBHost->currentText()+"/"+share+" "+mountpt->currentText()+" -U"+username->text()+":"+password->text(); 326 cmd = "/usr/bin/smbmount //"+CBHost->currentText()+"/"+share+" "+mountpt->currentText()+" -o username="+username->text()+",password="+password->text();
332
333 for(i = 0; i < 512; i++) {
334 if(cmd[i]==':') {
335 cmd[i]='%';
336 break;
337 }
338 if(cmd[i]=='\0')
339 break;
340 }
341 327
342 owarn << "cmd: " << cmd << oendl; 328 owarn << "cmd: " << cmd << oendl;
343 TextViewOutput->append(cmd.latin1()); 329 TextViewOutput->append(cmd.latin1());
344 330
345 331
346 if(onbootBtn->isChecked()) { 332 if(onbootBtn->isChecked()) {
347 owarn << "Saving Setting permanently..." << oendl; 333 owarn << "Saving Setting permanently..." << oendl;
348 cmd2 = "echo '" + cmd + "'>/opt/QtPalmtop/etc/samba.env"; 334 cmd2 = "echo '" + cmd + "'>/opt/QtPalmtop/etc/samba.env";
349 335
350 /* run command & read output */ 336 /* run command & read output */
351 if ((pipe = popen(cmd2.latin1(), "r")) == NULL) { 337 if ((pipe = popen(cmd2.latin1(), "r")) == NULL) {
352 338
353 snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 339 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
354// result = "Error: Can't run "+ cmd; 340// result = "Error: Can't run "+ cmd;
355 //TextViewOutput->append(result); 341 //TextViewOutput->append(result);
356 return; 342 return;
357 } 343 }
358 /* parse output and display in ListViewScan */ 344 /* parse output and display in ListViewScan */
359 while(fgets(result, 256, pipe) != NULL) { 345 while(fgets(result, 256, pipe) != NULL) {
360 /* put result into TextViewOutput */ 346 /* put result into TextViewOutput */
361 //TextViewOutput->append(result); 347 //TextViewOutput->append(result);
362 } 348 }
363 } 349 }
364 350
365 /* run command & read output */ 351 /* run command & read output */
366 if ((pipe = popen(cmd.latin1(), "r")) == NULL) { 352 if ((pipe = popen(cmd.latin1(), "r")) == NULL) {
367 353
368// result = "Error: Can't run "+ cmd; 354// result = "Error: Can't run "+ cmd;
369 snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 355 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
370 356
371 TextViewOutput->append(result); 357 TextViewOutput->append(result);
372 return; 358 return;
373 } 359 }
374 360
375 /* parse output and display in ListViewScan */ 361 /* parse output and display in ListViewScan */
376 while(fgets(result, 256, pipe) != NULL) { 362 while(fgets(result, 256, pipe) != NULL) {
377 /* put result into TextViewOutput */ 363 /* put result into TextViewOutput */
378 TextViewOutput->append(result); 364 TextViewOutput->append(result);
379 } 365 }
380 TextViewOutput->append("\n\n================CheckMounts==================\n"); 366 TextViewOutput->append("\n\n================CheckMounts==================\n");
381 LScan->setText(""); 367 LScan->setText("");
382 368
383 cmd = "/bin/mount 2>&1"; 369 cmd = "/bin/mount 2>&1";
384 owarn << "cmd: " << cmd << oendl; 370 owarn << "cmd: " << cmd << oendl;
385 371
386 if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) { 372 if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) {
387 373
388 snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 374 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
389// result = "Error: Can't run "+ cmd; 375// result = "Error: Can't run "+ cmd;
390 376
391 TextViewOutput->append(result); 377 TextViewOutput->append(result);
392 return; 378 return;
393 } 379 }
394 /* parse output and display in ListViewScan */ 380 /* parse output and display in ListViewScan */
395 while(fgets(result, 256, pipe2) != NULL) { 381 while(fgets(result, 256, pipe2) != NULL) {
396 /* put result into TextViewOutput */ 382 /* put result into TextViewOutput */
397 TextViewOutput->append(result); 383 TextViewOutput->append(result);
398 } 384 }
399 385
400 TextViewOutput->append("\n\n============================================\n"); 386 TextViewOutput->append("\n\n============================================\n");
401 scanning = false; 387 scanning = false;
402} 388}
389
390bool Qsmb::runCommand(const QStringList & command) {
391 owarn << "runCommand " << command.join(" ") << oendl;
392 out = "";
393 Process ipkg_status( command);
394 bool r = ipkg_status.exec("",out);
395
396 if(!r) {
397 QMessageBox::warning(this, tr("Error!!"),tr("<p>"+out+"</p>"));
398 }
399
400 owarn << "Output " << out << oendl;
401 TextViewOutput->append(out.latin1());
402 return r;
403}
404
405
diff --git a/noncore/net/opie-smb/qsmb.h b/noncore/net/opie-smb/qsmb.h
index 8fefe91..b406a1e 100644
--- a/noncore/net/opie-smb/qsmb.h
+++ b/noncore/net/opie-smb/qsmb.h
@@ -1,39 +1,42 @@
1#ifndef QSMB_H 1#ifndef QSMB_H
2#define QSMB_H 2#define QSMB_H
3 3
4#include "qsmbbase.h" 4#include "qsmbbase.h"
5 5
6#include <stdlib.h> 6#include <stdlib.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <stdio.h> 8#include <stdio.h>
9 9
10#include <qlistview.h> 10#include <qlistview.h>
11#include <pthread.h> 11#include <pthread.h>
12 12
13class Qsmb : public FormQPESMBBase 13class Qsmb : public FormQPESMBBase
14{ 14{
15 Q_OBJECT 15 Q_OBJECT
16 16
17public: 17public:
18 static QString appName() { return QString::fromLatin1("opie-smb"); } 18 static QString appName() { return QString::fromLatin1("opie-smb"); }
19 Qsmb( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 19 Qsmb( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
20 ~Qsmb(); 20 ~Qsmb();
21 void scan(); 21 void scan();
22 void DoIt(); 22 void DoIt();
23 23
24private: 24private:
25 QListViewItem *top_element; 25 QListViewItem *top_element;
26 QComboBox *hosts; 26 QComboBox *hosts;
27 pthread_t tpid; 27 pthread_t tpid;
28 bool scanning; 28 bool scanning;
29 29
30public slots: 30public slots:
31 void clear(); 31 void clear();
32 void scanClicked(); 32 void scanClicked();
33 void hostSelected(int); 33 void hostSelected(int);
34 void DoItClicked(); 34 void DoItClicked();
35 QString out;
36 bool runCommand(const QStringList &);
37
35}; 38};
36void* runit(void *arg); 39void* runit(void *arg);
37void* runitm(void *arg); 40void* runitm(void *arg);
38 41
39#endif // QSMB_H 42#endif // QSMB_H