• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 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
34int 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}
KApplication
KCmdLineArgs
KCmdLineArgs::init
static void init(const KAboutData *about)
KCmdLineArgs::parsedArgs
static KCmdLineArgs * parsedArgs(const QByteArray &id=QByteArray())
KCmdLineArgs::count
int count() const
KCmdLineArgs::addCmdLineOptions
static void addCmdLineOptions(const KCmdLineOptions &options, const KLocalizedString &name=KLocalizedString(), const QByteArray &id=QByteArray(), const QByteArray &afterId=QByteArray())
KCmdLineArgs::arg
QString arg(int n) const
KCmdLineOptions
KCmdLineOptions::add
KCmdLineOptions & add(const KCmdLineOptions &options)
KConfigGroup
KConfigGroup::readPathEntry
QString readPathEntry(const char *key, const QString &aDefault) const
KConfig
KMessageBox::sorry
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
KToolInvocation::kdeinitExec
static int kdeinitExec(const QString &name, const QStringList &args=QStringList(), QString *error=0, int *pid=0, const QByteArray &startup_id=QByteArray())
KUrl
KUrl::path
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const
KUrl::user
QString user() const
KUrl::protocol
QString protocol() const
kapplication.h
kauthorized.h
kcmdlineargs.h
kconfig.h
kconfiggroup.h
kdebug.h
klocale.h
ki18n
KLocalizedString ki18n(const char *msg)
i18n
QString i18n(const char *text)
kmessagebox.h
main
int main(int argc, char **argv)
Definition: ktelnetservice.cpp:34
ktoolinvocation.h
kurl.h
KAuthorized::authorize
bool authorize(const QString &genericAction)
config
KSharedConfigPtr config()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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.14.38 API Reference

Skip menu "kdelibs-4.14.38 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