• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

KIO

  • kio
  • misc
ktelnetservice.cpp
Go to the documentation of this file.
1 //krazy:excludeall=license (it's a program, not a library)
2 /*
3  Copyright (c) 2001 Malte Starostik <malte@kde.org>
4  based on kmailservice.cpp,
5  Copyright (c) 2000 Simon Hausmann <hausmann@kde.org>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; see the file COPYING. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include <kapplication.h>
24 #include <ktoolinvocation.h>
25 #include <kauthorized.h>
26 #include <kmessagebox.h>
27 #include <kcmdlineargs.h>
28 #include <kdebug.h>
29 #include <klocale.h>
30 #include <kconfig.h>
31 #include <kconfiggroup.h>
32 #include <kurl.h>
33 
34 int main(int argc, char **argv)
35 {
36  KCmdLineOptions options;
37  options.add("+url");
38 
39  KCmdLineArgs::init(argc, argv, "ktelnetservice", "kdelibs4", ki18n("telnet service"),
40  "unknown", ki18n("telnet protocol handler"));
41  KCmdLineArgs::addCmdLineOptions(options);
42 
43  KApplication app;
44 
45  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
46 
47  if (args->count() != 1)
48  return 1;
49 
50  KConfig config("kdeglobals");
51  KConfigGroup cg(&config, "General");
52  QString terminal = cg.readPathEntry("TerminalApplication", "konsole");
53 
54  KUrl url(args->arg(0));
55  QStringList cmd;
56  if (terminal == "konsole")
57  cmd << "--noclose";
58 
59  cmd << "-e";
60  if ( url.protocol() == "telnet" )
61  cmd << "telnet";
62  else if ( url.protocol() == "ssh" )
63  cmd << "ssh";
64  else if ( url.protocol() == "rlogin" )
65  cmd << "rlogin";
66  else {
67  kError() << "Invalid protocol " << url.protocol() << endl;
68  return 2;
69  }
70 
71  if (!KAuthorized::authorize("shell_access"))
72  {
73  KMessageBox::sorry(0,
74  i18n("You do not have permission to access the %1 protocol.", url.protocol()));
75  return 3;
76  }
77 
78  if (!url.user().isEmpty())
79  {
80  cmd << "-l";
81  cmd << url.user();
82  }
83 
84  QString host;
85  if (!url.host().isEmpty())
86  host = url.host(); // telnet://host
87  else if (!url.path().isEmpty())
88  host = url.path(); // telnet:host
89 
90  if (host.isEmpty() || host.startsWith('-'))
91  {
92  kError() << "Invalid hostname " << host << endl;
93  return 2;
94  }
95 
96  cmd << host;
97 
98  if (url.port() > 0){
99  if ( url.protocol() == "ssh" )
100  cmd << "-p" << QString::number(url.port());
101  else
102  cmd << QString::number(url.port());
103  }
104 
105  KToolInvocation::kdeinitExec(terminal, cmd);
106 
107  return 0;
108 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Jul 12 2013 08:54:04 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.10.5 API Reference

Skip menu "kdelibs-4.10.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal