diff options
Diffstat (limited to 'tdeioslave/finger')
-rw-r--r-- | tdeioslave/finger/CMakeLists.txt | 37 | ||||
-rw-r--r-- | tdeioslave/finger/Makefile.am | 27 | ||||
-rw-r--r-- | tdeioslave/finger/finger.protocol | 9 | ||||
-rw-r--r-- | tdeioslave/finger/kio_finger.cpp | 266 | ||||
-rw-r--r-- | tdeioslave/finger/kio_finger.css | 69 | ||||
-rw-r--r-- | tdeioslave/finger/kio_finger.h | 64 | ||||
-rw-r--r-- | tdeioslave/finger/kio_finger.pl | 175 |
7 files changed, 647 insertions, 0 deletions
diff --git a/tdeioslave/finger/CMakeLists.txt b/tdeioslave/finger/CMakeLists.txt new file mode 100644 index 000000000..096b483d0 --- /dev/null +++ b/tdeioslave/finger/CMakeLists.txt @@ -0,0 +1,37 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### other data ################################ + +install( FILES finger.protocol DESTINATION ${SERVICES_INSTALL_DIR} ) +install( FILES kio_finger.pl kio_finger.css DESTINATION ${DATA_INSTALL_DIR}/tdeio_finger ) + + +##### kio_finger (module) ####################### + +set( target kio_finger ) + +tde_add_kpart( ${target} AUTOMOC + SOURCES kio_finger.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdeioslave/finger/Makefile.am b/tdeioslave/finger/Makefile.am new file mode 100644 index 000000000..9c2792df3 --- /dev/null +++ b/tdeioslave/finger/Makefile.am @@ -0,0 +1,27 @@ +## Makfile.am for kio_finger +## Edit from Makefile.am of tdebase/tdeioslave/man + +INCLUDES= $(all_includes) +AM_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_KIO) -ltdetexteditor + +####### Files + +kde_module_LTLIBRARIES = kio_finger.la + +kio_finger_la_SOURCES = kio_finger.cpp +kio_finger_la_LIBADD = -lkio +kio_finger_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) + +noinst_HEADERS = kio_finger.h + +kdelnk_DATA = finger.protocol +kdelnkdir = $(kde_servicesdir) + +kio_finger_data_DATA = kio_finger.pl kio_finger.css +kio_finger_datadir = $(kde_datadir)/tdeio_finger +EXTRA_DIST=$(kio_finger_data_DATA) + +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/tdeio_finger.pot diff --git a/tdeioslave/finger/finger.protocol b/tdeioslave/finger/finger.protocol new file mode 100644 index 000000000..8e2cdc80f --- /dev/null +++ b/tdeioslave/finger/finger.protocol @@ -0,0 +1,9 @@ +[Protocol] +exec=kio_finger +protocol=finger +input=none +output=stream +reading=true +defaultMimetype=text/html +DocPath=tdeioslave/finger.html +Icon=tdmconfig diff --git a/tdeioslave/finger/kio_finger.cpp b/tdeioslave/finger/kio_finger.cpp new file mode 100644 index 000000000..b223e1024 --- /dev/null +++ b/tdeioslave/finger/kio_finger.cpp @@ -0,0 +1,266 @@ + +/*************************************************************************** + kio_finger.cpp - description + ------------------- + begin : Sun Aug 12 2000 + copyright : (C) 2000 by Andreas Schlapbach + email : schlpbch@iam.unibe.ch + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <string.h> + +#include <tqtextstream.h> +#include <tqdict.h> +#include <tqcstring.h> +#include <tqfile.h> +#include <tqregexp.h> + +#include <kdebug.h> +#include <kinstance.h> +#include <kglobal.h> +#include <kstandarddirs.h> +#include <klocale.h> +#include <kurl.h> + +#include "kio_finger.h" + + +using namespace TDEIO; + +static const TQString defaultRefreshRate = "60"; + +extern "C" +{ + KDE_EXPORT int kdemain( int argc, char **argv ) + { + TDEInstance instance( "kio_finger" ); + + //kdDebug() << "*** Starting kio_finger " << getpid() << endl; + + if (argc != 4) + { + fprintf(stderr, "Usage: kio_finger protocol domain-socket1 domain-socket2\n"); + exit(-1); + } + + FingerProtocol slave(argv[2], argv[3]); + slave.dispatchLoop(); + + //kdDebug() << "*** kio_finger Done" << endl; + return 0; + } +} + + +/* ---------------------------------------------------------------------------------- */ + + +FingerProtocol::FingerProtocol(const TQCString &pool_socket, const TQCString &app_socket) + : TQObject(), SlaveBase("finger", pool_socket, app_socket) +{ + myStdStream = new TQString(); + getProgramPath(); +} + + +/* ---------------------------------------------------------------------------------- */ + + +FingerProtocol::~FingerProtocol() +{ + //kdDebug() << "FingerProtocol::~FingerProtocol()" << endl; + delete myURL; + delete myPerlPath; + delete myFingerPath; + delete myFingerPerlScript; + delete myFingerCSSFile; + delete myStdStream; +} + + +/* ---------------------------------------------------------------------------------- */ + + +void FingerProtocol::get(const KURL& url ) +{ + //kdDebug() << "kio_finger::get(const KURL& url)" << endl ; + + this->parseCommandLine(url); + + //kdDebug() << "myURL: " << myURL->prettyURL() << endl; + + // Reset the stream + *myStdStream=""; + + TQString query = myURL->query(); + TQString refreshRate = defaultRefreshRate; + + //kdDebug() << "query: " << query << endl; + + // Check the validity of the query + + TQRegExp regExp("?refreshRate=[0-9][0-9]*", true, true); + if (query.contains(regExp)) { + //kdDebug() << "looks like a valid query" << endl; + TQRegExp regExp( "([0-9]+)" ); + regExp.search(query); + refreshRate = regExp.cap(0); + } + + //kdDebug() << "Refresh rate: " << refreshRate << endl; + + myTDEProcess = new TDEProcess(); + *myTDEProcess << *myPerlPath << *myFingerPerlScript + << *myFingerPath << *myFingerCSSFile + << refreshRate << myURL->host() << myURL->user() ; + + connect(myTDEProcess, TQT_SIGNAL(receivedStdout(TDEProcess *, char *, int)), + this, TQT_SLOT(slotGetStdOutput(TDEProcess *, char *, int))); + //connect(myTDEProcess, TQT_SIGNAL(receivedStderr(TDEProcess *, char *, int)), + // this, TQT_SLOT(slotGetStdOutput(TDEProcess *, char *, int))); + + myTDEProcess->start(TDEProcess::Block, TDEProcess::All); + + data(TQCString(TQString(*myStdStream).local8Bit())); + + data(TQByteArray()); + finished(); + + //clean up + + delete myTDEProcess; +} + + +/* ---------------------------------------------------------------------------------- */ + + +void FingerProtocol::slotGetStdOutput(TDEProcess* /* p */, char *s, int len) +{ + //kdDebug() << "void FingerProtocol::slotGetStdoutOutput()" << endl; + *myStdStream += TQString::fromLocal8Bit(s, len); +} + + +/* ---------------------------------------------------------------------------------- */ + + +void FingerProtocol::mimetype(const KURL & /*url*/) +{ + mimeType("text/html"); + finished(); +} + + +/* ---------------------------------------------------------------------------------- */ + + +void FingerProtocol::getProgramPath() +{ + //kdDebug() << "kfingerMainWindow::getProgramPath()" << endl; + // Not to sure wether I'm using the right error number here. - schlpbch - + + myPerlPath = new TQString(TDEGlobal::dirs()->findExe("perl")); + if (myPerlPath->isEmpty()) + { + //kdDebug() << "Perl command not found" << endl; + this->error(ERR_CANNOT_LAUNCH_PROCESS, + i18n("Could not find the Perl program on your system, please install.")); + exit(); + } + else + { + //kdDebug() << "Perl command found:" << *myPerlPath << endl; + } + + myFingerPath = new TQString(TDEGlobal::dirs()->findExe("finger")); + if ((myFingerPath->isEmpty())) + { + //kdDebug() << "Finger command not found" << endl; + this->error(ERR_CANNOT_LAUNCH_PROCESS, + i18n("Could not find the Finger program on your system, please install.")); + exit(); + } + else + { + //kdDebug() << "Finger command found:" << *myFingerPath << endl; + } + + myFingerPerlScript = new TQString(locate("data","kio_finger/tdeio_finger.pl")); + if (myFingerPerlScript->isEmpty()) + { + //kdDebug() << "kio_finger.pl script not found" << endl; + this->error(ERR_CANNOT_LAUNCH_PROCESS, + i18n("kio_finger Perl script not found.")); + exit(); + } + else + { + //kdDebug() << "kio_finger perl script found: " << *myFingerPerlScript << endl; + } + + myFingerCSSFile = new TQString(locate("data","kio_finger/tdeio_finger.css")); + if (myFingerCSSFile->isEmpty()) + { + //kdDebug() << "kio_finger.css file not found" << endl; + this->warning(i18n("kio_finger CSS script not found. Output will look ugly.")); + } + else + { + //kdDebug() << "kio_finger CSS file found: " << *myFingerCSSFile << endl; + } +} + + +/* --------------------------------------------------------------------------- */ + + +void FingerProtocol::parseCommandLine(const KURL& url) +{ + myURL = new KURL(url); + + /* + * Generate a valid finger url + */ + + if(myURL->isEmpty() || !myURL->isValid() || + (myURL->user().isEmpty() && myURL->host().isEmpty())) + { + myURL->setProtocol("finger"); + myURL->setUser(""); + myURL->setHost("localhost"); + } + + /* + * If no specific port is specified, set it to 79. + */ + + if(myURL->port() == 0) { + myURL->setPort(79); + } + + /* + * If no refresh rate is given, set it to defaultRefreshRate + */ + + if (myURL->query().isEmpty()) { + myURL->setQuery("?refreshRate="+defaultRefreshRate); + } +} + +/* ---------------------------------------------------------------------------------- */ +#include "kio_finger.moc" +/* ---------------------------------------------------------------------------------- */ + diff --git a/tdeioslave/finger/kio_finger.css b/tdeioslave/finger/kio_finger.css new file mode 100644 index 000000000..06deb81aa --- /dev/null +++ b/tdeioslave/finger/kio_finger.css @@ -0,0 +1,69 @@ +BODY { + color: #FFFFCC; + background-color: #000000; + padding: 2em; + margin: auto; +} + +A:link {color: #82A7D0} +A:visited {color: #999999} +A:active {color: #999999} + +H1 { + color: #999999; + background-color: #000000; + font: 200% Helvetica, sans-serif; + font-variant: normal; + padding: 1em; + margin: auto; +} + +.mainTable { + background-color: #000000; + border: thin solid; + margin: auto; +} + + +.courierText { + color: #FFFFCC; + background-color: #000000; + font: 120% Courier, sans-serif; + font-variant: normal; + text-align: left; + padding: 0em; +} + +.commandText { + color: #FFFFCC; + background-color: #000000; + font: 120% Courier, sans-serif; + font-variant: normal; + text-align: center; + padding: 0.5em; +} + +.niceText { + color: #009999; + background-color: #000000; + font: 120% Arial, sans-serif; + font-variant: normal; + text-align: center; + padding: 0.5em; +} + +.finger { color: #82A7D0} +.domainName { color: #D0A000} +.ipNumber { color: #D0A000} +.os { color: #82A7D0} +.username { color: #82A7D0} +.directory { color: #D0A000} +.shell { color: #D0A000} +.notLoggedIn { color: #00A000} +.loggedIn { color: #B00000} +.newMail { color: #82A7D0} +.plan { color: #D0A000} +.noNewMail { color: #BB0000} +.noPlan { color: #BB0000} + + diff --git a/tdeioslave/finger/kio_finger.h b/tdeioslave/finger/kio_finger.h new file mode 100644 index 000000000..eac8ad291 --- /dev/null +++ b/tdeioslave/finger/kio_finger.h @@ -0,0 +1,64 @@ + +/*************************************************************************** + kio_finger.h - description + ------------------- + begin : Sun Aug 12 2000 + copyright : (C) 2000 by Andreas Schlapbach + email : schlpbch@iam.unibe.ch + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + + +#ifndef __kio_finger_h__ +#define __kio_finger_h__ + +#include <tqstring.h> +#include <tqcstring.h> + +#include <kurl.h> +#include <kprocess.h> +#include <tdeio/global.h> +#include <tdeio/slavebase.h> + +class FingerProtocol : public TQObject, public TDEIO::SlaveBase +{ + Q_OBJECT + +public: + + FingerProtocol(const TQCString &pool_socket, const TQCString &app_socket); + virtual ~FingerProtocol(); + + virtual void mimetype(const KURL& url); + virtual void get(const KURL& url); + +private slots: + void slotGetStdOutput(TDEProcess*, char*, int); + +private: + KURL *myURL; + + QString *myPerlPath; + TQString *myFingerPath; + TQString *myFingerPerlScript; + TQString *myFingerCSSFile; + + QString *myStdStream; + + + TDEProcess *myTDEProcess; + + void getProgramPath(); + void parseCommandLine(const KURL& url); +}; + + +#endif diff --git a/tdeioslave/finger/kio_finger.pl b/tdeioslave/finger/kio_finger.pl new file mode 100644 index 000000000..8965ea523 --- /dev/null +++ b/tdeioslave/finger/kio_finger.pl @@ -0,0 +1,175 @@ +##!/usr/bin/perl +# +# Copyright Andreas Schlapbach, schlpbch@iam.unibe.ch, 2001 +# http://iamexwiwww.unibe.ch/studenten/kfinger +# +# Touch at your own risk. + + +# Highlight mail addresses or url + +$mails = '<A HREF="mailto:'; +$urls = '<A HREF="'; +$urlspace = '">'; +$urlend = '</A>'; + +# Highlight various information, configurable via the CSS file, + +$finger = '<CODE class="finger">'; +$domainName = '<CODE class="domainName">'; +$ipNumber = '<CODE class="ipNumber">'; +$os = '<CODE class="os">'; +$username = '<CODE class="username">'; +$directory = '<CODE class="directory">'; +$shell = '<CODE class="shell">'; +$notLoggedIn = '<CODE class="Login">'; +$loggedIn = '<CODE class="noLogin">'; +$newMail = '<CODE class="newMail">'; +$plan = '<CODE class="plan">'; +$noNewMail = '<CODE class="noNewMail">'; +$noPlan = '<CODE class="noPlan">'; +$close = '</CODE>'; + +# Those names get skipped, so if there's a user with such a name, bad luck. + +@keywords=('Welcome','Login','finger','No'); +$keywordlist = join '|', @keywords; + +$FINGERCMD = "$ARGV[0]"; # The complete path to the finger cmd +$CSSFILE = "$ARGV[1]"; # The complete path to the CSS file +$REFRESHRATE = "$ARGV[2]"; # The intervals in seconds until the page gets updated +$HOST = "$ARGV[3]"; # host name +$USER = "$ARGV[4]"; # user name + +$HOST =~ s/&/&/g; +$HOST =~ s/</</g; +$HOST =~ s/>/>/g; + +$USER =~ s/&/&/g; +$USER =~ s/</</g; +$USER =~ s/>/>/g; + +# HTML Header + +print <<HTMLHeader; +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<HTML> +<HEAD> + <meta http-equiv="refresh" content="$REFRESHRATE"> + <TITLE>finger $USER\@$HOST</TITLE> + <LINK type="text/css" rel="stylesheet" href="file:$CSSFILE"> +</HEAD> +<BODY> + <TABLE class="mainTable" cellspacing="0"> + <TR> + <TH colspan="1"> + <H1>finger $USER\@$HOST</H1> + </TH> + </TR> + <TR> + <TH> + <TABLE class="courierText" cellpadding="0" cellspacing="2"> +HTMLHeader + +# Run finger command and save it into a buffer + +open(F, "-|") || exec $FINGERCMD, "$USER\@$HOST"; +@lines = <F>; +close(F); + +# Do highlighting using perl regular expressions on every line received. +# Order is important here. + +foreach $output (@lines) + { + $output =~ s/((\w)+\@((\w)+(.))*(\w)+)/$mails$1$urlspace$1$urlend/gi; # Highlight email address + $output =~ s/((http|ftp)(:\/\/)(\S)+)/$urls$1$urlspace$1$urlend/gi; # Highlight urls + $output =~ s/((\d)+\.(\d)+\.(\d)+\.(\d)+)/$ipNumber$1$close/gi; # Highlight IP number + $output =~ s/((\w)+\.(\w)+\.(\w|-)+\s)/$domainName$1$close/gi; # Highlight domain name (\s is important) + $output =~ s/(finger:)/$finger$1$close/gim; # Highlight finger + $output =~ s/(Linux)/$os$1$close/gim; # Highlight Linux + if ($USER) # is $USER nil ? + { + $output =~ s/^Login:\s*(\w*)/Login: $mails$1\@$HOST$urlspace$1$urlend/gi; + $output =~ s/^Login Name:\s*(\w*)/Login Name:$mails$1\@$HOST$urlspace$1$urlend/gi; + $output =~ s/Name:(((\s*)(\w+))+\n)/Name:$username$1$close\n/gi; # Linux + $output =~ s/In real life:(((\s*)(\w+))+\n)/In real life:$username$1$close\n/gi; # Solaris + $output =~ s/^Directory:((\s*)(\/(\w)+)+)/Directory:$directory$1$close/gi; # Highlight Directory + $output =~ s/Shell:((\s*)(\/(\w)+)+)/Shell:$shell$1$close/gi; # Highlight Shell + $output =~ s/(not presently logged)/$notLoggedIn$1$close/gi; + $output =~ s/con (\w*)/con $loggedIn$1$close/gi; + $output =~ s/^(New mail)/$newMail$1$close/gi; + $output =~ s/^(No mail.)/$noNewMail$1$close/gim; + $output =~ s/^(Plan:)/$plan$1$close/gi; + $output =~ s/^(No plan.)/$noPlan$1$close/gim; + } + else + { + $output =~ s/^(\w+)/$mails$1\@$HOST$urlspace$1$urlend/m unless ($output =~ m/$keywordlist/m); + } + # line consists of white space only? + if ($output =~ m/\S/gi) + { + print " <TR><TD><PRE>$output</PRE></TD></TR>\n"; + } + else + { + print " <TR><TD><PRE> </PRE></TD></TR>\n"; + } +} + +print " </TABLE>\n"; +print " </TH>\n"; + +# Finger-Talk options + +if ($USER) # is $USER nil ? +{ +print <<UserQuery; + </TR> + <TR> + <TH class="commandText" colspan="2"> + <A HREF='finger://$USER\@$HOST'>finger</A> + </TH> + </TR> +UserQuery +} +else +{ +print <<HostQueryHead; + <TH> + <TABLE class="courierText" cellpadding="0" cellspacing="2"> +HostQueryHead + + @lines = split /^/m, $buffer; + foreach $output2 (@lines) + { + if ($output2 =~ m/^(\w+)/gi and not ($output2 =~ m/$keywordlist/m)) + { + $USER = $&; + print " <TR><TD><PRE><A HREF='finger://$USER\@$HOST'>finger</A>\n</PRE></TD></TR>\n"; + # - <A HREF='talk://$USER\@$HOST'>talk</A>\n</PRE></TD></TR>\n"; + } + else + { + print " <TR><TD><PRE> </PRE></TD></TR>\n"; + } + } + +print <<HostQueryTail; + </TABLE> + </TH> + </TR> +HostQueryTail +} + +# HTMLTail + +print <<HTMLTail; + <TR> + <TH class="niceText">refresh rate: $REFRESHRATE seconds.</TH> + </TR> +</TABLE> +</BODY> +</HTML> +HTMLTail |