2006-07-18 13:07:30 +02:00
package www ;
2005-04-07 21:19:42 +02:00
// welcome.java
// -----------------------
// part of the AnomicHTTPD caching proxy
2008-07-20 19:14:51 +02:00
// (C) by Michael Peter Christen; mc@yacy.net
2005-04-07 21:19:42 +02:00
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004
2005-09-19 01:07:29 +02:00
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
2005-04-07 21:19:42 +02:00
//
// 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.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-07-20 02:21:07 +02:00
2005-05-12 19:50:45 +02:00
// You must compile this file with
2005-09-19 01:07:29 +02:00
// javac -classpath .:../classes index.java
2005-04-07 21:19:42 +02:00
// if the shell's current path is HTROOT
2007-11-04 11:36:25 +01:00
import java.io.File ;
2005-08-28 20:05:17 +02:00
import java.net.InetAddress ;
import java.net.UnknownHostException ;
2006-09-30 00:27:20 +02:00
2008-08-25 20:11:47 +02:00
import de.anomic.http.httpRequestHeader ;
2008-05-06 01:13:47 +02:00
import de.anomic.plasma.plasmaSwitchboard ;
2005-05-05 07:36:42 +02:00
import de.anomic.server.serverCore ;
2007-07-24 02:46:17 +02:00
import de.anomic.server.serverDomains ;
2005-05-05 07:36:42 +02:00
import de.anomic.server.serverObjects ;
import de.anomic.server.serverSwitch ;
2005-09-21 01:15:33 +02:00
import de.anomic.yacy.yacySeed ;
2005-04-07 21:19:42 +02:00
public class welcome {
2008-08-25 20:11:47 +02:00
public static serverObjects respond ( final httpRequestHeader header , final serverObjects post , final serverSwitch < ? > env ) {
2008-08-02 14:12:04 +02:00
final plasmaSwitchboard sb = ( plasmaSwitchboard ) env ;
2008-05-06 01:13:47 +02:00
2005-09-19 01:07:29 +02:00
// return variable that accumulates replacements
final serverObjects prop = new serverObjects ( ) ;
2005-04-07 21:19:42 +02:00
// update seed info
2008-06-04 23:34:57 +02:00
sb . updateMySeed ( ) ;
2005-04-07 21:19:42 +02:00
2007-10-24 23:38:19 +02:00
prop . putHTML ( " peername " , env . getConfig ( " peerName " , " <nameless> " ) ) ;
prop . putHTML ( " peerdomain " , env . getConfig ( " peerName " , " <nameless> " ) . toLowerCase ( ) ) ;
2009-03-13 11:34:51 +01:00
prop . putHTML ( " peeraddress " , sb . webIndex . peers ( ) . mySeed ( ) . getPublicAddress ( ) ) ;
2007-07-24 02:46:17 +02:00
prop . put ( " hostname " , serverDomains . myPublicIP ( ) ) ;
2005-09-19 01:07:29 +02:00
try {
2007-07-24 02:46:17 +02:00
prop . put ( " hostip " , InetAddress . getByName ( serverDomains . myPublicIP ( ) ) . getHostAddress ( ) ) ;
2008-08-02 14:12:04 +02:00
} catch ( final UnknownHostException e ) {
2005-09-19 01:07:29 +02:00
prop . put ( " hostip " , " Unknown Host Exception " ) ;
2006-02-17 11:53:20 +01:00
}
prop . put ( " port " , serverCore . getPortNr ( env . getConfig ( " port " , " 8080 " ) ) ) ;
2008-08-25 20:11:47 +02:00
prop . put ( " clientip " , ( String ) header . get ( httpRequestHeader . CONNECTION_PROP_CLIENTIP , " " ) ) ;
2005-04-07 21:19:42 +02:00
2009-03-13 11:34:51 +01:00
final String peertype = ( sb . webIndex . peers ( ) . mySeed ( ) = = null ) ? yacySeed . PEERTYPE_JUNIOR : sb . webIndex . peers ( ) . mySeed ( ) . get ( yacySeed . PEERTYPE , yacySeed . PEERTYPE_VIRGIN ) ;
2005-09-21 01:15:33 +02:00
final boolean senior = ( peertype . equals ( yacySeed . PEERTYPE_SENIOR ) ) | | ( peertype . equals ( yacySeed . PEERTYPE_PRINCIPAL ) ) ;
2005-09-19 01:07:29 +02:00
if ( senior ) { prop . put ( " couldcan " , " can " ) ; } else { prop . put ( " couldcan " , " could " ) ; }
2007-10-24 23:38:19 +02:00
if ( senior ) { prop . put ( " seniorinfo " , " This peer runs in senior mode which means that your peer can be accessed using the addresses shown above. " ) ; } else { prop . putHTML ( " seniorinfo " , " <b>Nobody can access your peer from the outside of your intranet. You must open your firewall and/or set a 'virtual server' in the settings of your router to enable access to the addresses as shown below.</b> " ) ; }
2008-08-02 14:12:04 +02:00
final File wwwpath = env . getConfigPath ( " htDocsPath " , " DATA/HTDOCS " ) ;
2007-11-04 11:36:25 +01:00
prop . putHTML ( " wwwpath " , wwwpath . isAbsolute ( ) ? wwwpath . getAbsolutePath ( ) : " <application_root_path>/ " + env . getConfig ( " htDocsPath " , " DATA/HTDOCS " ) ) ;
2005-09-19 01:07:29 +02:00
// return rewrite properties
return prop ;
2005-04-07 21:19:42 +02:00
}
}