KIO
ktelnetservice.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <kapplication.h>
00024 #include <ktoolinvocation.h>
00025 #include <kauthorized.h>
00026 #include <kmessagebox.h>
00027 #include <kcmdlineargs.h>
00028 #include <kdebug.h>
00029 #include <klocale.h>
00030 #include <kconfig.h>
00031 #include <kconfiggroup.h>
00032 #include <kurl.h>
00033
00034 int main(int argc, char **argv)
00035 {
00036 KCmdLineOptions options;
00037 options.add("+url");
00038
00039 KCmdLineArgs::init(argc, argv, "ktelnetservice", "kdelibs4", ki18n("telnet service"),
00040 "unknown", ki18n("telnet protocol handler"));
00041 KCmdLineArgs::addCmdLineOptions(options);
00042
00043 KApplication app;
00044
00045 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00046
00047 if (args->count() != 1)
00048 return 1;
00049
00050 KConfig config("kdeglobals");
00051 KConfigGroup cg(&config, "General");
00052 QString terminal = cg.readPathEntry("TerminalApplication", "konsole");
00053
00054 KUrl url(args->arg(0));
00055 QStringList cmd;
00056 if (terminal == "konsole")
00057 cmd << "--noclose";
00058
00059 cmd << "-e";
00060 if ( url.protocol() == "telnet" )
00061 cmd << "telnet";
00062 else if ( url.protocol() == "ssh" )
00063 cmd << "ssh";
00064 else if ( url.protocol() == "rlogin" )
00065 cmd << "rlogin";
00066 else {
00067 kError() << "Invalid protocol " << url.protocol() << endl;
00068 return 2;
00069 }
00070
00071 if (!KAuthorized::authorize("shell_access"))
00072 {
00073 KMessageBox::sorry(0,
00074 i18n("You do not have permission to access the %1 protocol.", url.protocol()));
00075 return 3;
00076 }
00077
00078 if (!url.user().isEmpty())
00079 {
00080 cmd << "-l";
00081 cmd << url.user();
00082 }
00083
00084 QString host;
00085 if (!url.host().isEmpty())
00086 host = url.host();
00087 else if (!url.path().isEmpty())
00088 host = url.path();
00089
00090 if (host.isEmpty() || host.startsWith('-'))
00091 {
00092 kError() << "Invalid hostname " << host << endl;
00093 return 2;
00094 }
00095
00096 cmd << host;
00097
00098 if (url.port() > 0){
00099 if ( url.protocol() == "ssh" )
00100 cmd << "-p" << QString::number(url.port());
00101 else
00102 cmd << QString::number(url.port());
00103 }
00104
00105 KToolInvocation::kdeinitExec(terminal, cmd);
00106
00107 return 0;
00108 }