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