2004-07-24 02:06:07 +00:00
package net.i2p.router.web ;
2009-10-19 13:49:47 +00:00
import java.io.IOException ;
2009-02-24 22:59:59 +00:00
import java.text.Collator ;
2004-07-24 02:06:07 +00:00
import java.text.DecimalFormat ;
2009-02-24 22:59:59 +00:00
import java.util.ArrayList ;
2012-06-07 04:42:52 +00:00
import java.util.Arrays ;
2009-02-24 22:59:59 +00:00
import java.util.Collections ;
import java.util.Comparator ;
import java.util.List ;
2012-06-07 02:51:22 +00:00
import java.util.Map ;
2012-06-07 04:42:52 +00:00
import java.util.TreeSet ;
2004-07-24 02:06:07 +00:00
import net.i2p.data.DataHelper ;
2005-02-16 jrandom
* (Merged the 0.5-pre branch back into CVS HEAD)
* Replaced the old tunnel routing crypto with the one specified in
router/doc/tunnel-alt.html, including updates to the web console to view
and tweak it.
* Provide the means for routers to reject tunnel requests with a wider
range of responses:
probabalistic rejection, due to approaching overload
transient rejection, due to temporary overload
bandwidth rejection, due to persistent bandwidth overload
critical rejection, due to general router fault (or imminent shutdown)
The different responses are factored into the profiles accordingly.
* Replaced the old I2CP tunnel related options (tunnels.depthInbound, etc)
with a series of new properties, relevent to the new tunnel routing code:
inbound.nickname (used on the console)
inbound.quantity (# of tunnels to use in any leaseSets)
inbound.backupQuantity (# of tunnels to keep in the ready)
inbound.length (# of remote peers in the tunnel)
inbound.lengthVariance (if > 0, permute the length by adding a random #
up to the variance. if < 0, permute the length
by adding or subtracting a random # up to the
variance)
outbound.* (same as the inbound, except for the, uh, outbound tunnels
in that client's pool)
There are other options, and more will be added later, but the above are
the most relevent ones.
* Replaced Jetty 4.2.21 with Jetty 5.1.2
* Compress all profile data on disk.
* Adjust the reseeding functionality to work even when the JVM's http proxy
is set.
* Enable a poor-man's interactive-flow in the streaming lib by choking the
max window size.
* Reduced the default streaming lib max message size to 16KB (though still
configurable by the user), also doubling the default maximum window
size.
* Replaced the RouterIdentity in a Lease with its SHA256 hash.
* Reduced the overall I2NP message checksum from a full 32 byte SHA256 to
the first byte of the SHA256.
* Added a new "netId" flag to let routers drop references to other routers
who we won't be able to talk to.
* Extended the timestamper to get a second (or third) opinion whenever it
wants to actually adjust the clock offset.
* Replaced that kludge of a timestamp I2NP message with a full blown
DateMessage.
* Substantial memory optimizations within the router and the SDK to reduce
GC churn. Client apps and the streaming libs have not been tuned,
however.
* More bugfixes thank you can shake a stick at.
2005-02-13 jrandom
* Updated jbigi source to handle 64bit CPUs. The bundled jbigi.jar still
only contains 32bit versions, so build your own, placing libjbigi.so in
your install dir if necessary. (thanks mule!)
* Added support for libjbigi-$os-athlon64 to NativeBigInteger and CPUID
(thanks spaetz!)
2005-02-16 22:23:47 +00:00
import net.i2p.data.Destination ;
2009-08-11 16:22:43 +00:00
import net.i2p.data.Hash ;
2005-02-16 jrandom
* (Merged the 0.5-pre branch back into CVS HEAD)
* Replaced the old tunnel routing crypto with the one specified in
router/doc/tunnel-alt.html, including updates to the web console to view
and tweak it.
* Provide the means for routers to reject tunnel requests with a wider
range of responses:
probabalistic rejection, due to approaching overload
transient rejection, due to temporary overload
bandwidth rejection, due to persistent bandwidth overload
critical rejection, due to general router fault (or imminent shutdown)
The different responses are factored into the profiles accordingly.
* Replaced the old I2CP tunnel related options (tunnels.depthInbound, etc)
with a series of new properties, relevent to the new tunnel routing code:
inbound.nickname (used on the console)
inbound.quantity (# of tunnels to use in any leaseSets)
inbound.backupQuantity (# of tunnels to keep in the ready)
inbound.length (# of remote peers in the tunnel)
inbound.lengthVariance (if > 0, permute the length by adding a random #
up to the variance. if < 0, permute the length
by adding or subtracting a random # up to the
variance)
outbound.* (same as the inbound, except for the, uh, outbound tunnels
in that client's pool)
There are other options, and more will be added later, but the above are
the most relevent ones.
* Replaced Jetty 4.2.21 with Jetty 5.1.2
* Compress all profile data on disk.
* Adjust the reseeding functionality to work even when the JVM's http proxy
is set.
* Enable a poor-man's interactive-flow in the streaming lib by choking the
max window size.
* Reduced the default streaming lib max message size to 16KB (though still
configurable by the user), also doubling the default maximum window
size.
* Replaced the RouterIdentity in a Lease with its SHA256 hash.
* Reduced the overall I2NP message checksum from a full 32 byte SHA256 to
the first byte of the SHA256.
* Added a new "netId" flag to let routers drop references to other routers
who we won't be able to talk to.
* Extended the timestamper to get a second (or third) opinion whenever it
wants to actually adjust the clock offset.
* Replaced that kludge of a timestamp I2NP message with a full blown
DateMessage.
* Substantial memory optimizations within the router and the SDK to reduce
GC churn. Client apps and the streaming libs have not been tuned,
however.
* More bugfixes thank you can shake a stick at.
2005-02-13 jrandom
* Updated jbigi source to handle 64bit CPUs. The bundled jbigi.jar still
only contains 32bit versions, so build your own, placing libjbigi.so in
your install dir if necessary. (thanks mule!)
* Added support for libjbigi-$os-athlon64 to NativeBigInteger and CPUID
(thanks spaetz!)
2005-02-16 22:23:47 +00:00
import net.i2p.data.LeaseSet ;
2008-06-20 20:22:38 +00:00
import net.i2p.data.RouterAddress ;
2012-04-12 14:48:18 +00:00
import net.i2p.data.RouterInfo ;
2005-08-10 23:55:40 +00:00
import net.i2p.router.CommSystemFacade ;
2004-07-24 02:06:07 +00:00
import net.i2p.router.Router ;
2012-06-07 02:51:22 +00:00
import net.i2p.router.RouterContext ;
2004-07-24 02:06:07 +00:00
import net.i2p.router.RouterVersion ;
2005-02-16 jrandom
* (Merged the 0.5-pre branch back into CVS HEAD)
* Replaced the old tunnel routing crypto with the one specified in
router/doc/tunnel-alt.html, including updates to the web console to view
and tweak it.
* Provide the means for routers to reject tunnel requests with a wider
range of responses:
probabalistic rejection, due to approaching overload
transient rejection, due to temporary overload
bandwidth rejection, due to persistent bandwidth overload
critical rejection, due to general router fault (or imminent shutdown)
The different responses are factored into the profiles accordingly.
* Replaced the old I2CP tunnel related options (tunnels.depthInbound, etc)
with a series of new properties, relevent to the new tunnel routing code:
inbound.nickname (used on the console)
inbound.quantity (# of tunnels to use in any leaseSets)
inbound.backupQuantity (# of tunnels to keep in the ready)
inbound.length (# of remote peers in the tunnel)
inbound.lengthVariance (if > 0, permute the length by adding a random #
up to the variance. if < 0, permute the length
by adding or subtracting a random # up to the
variance)
outbound.* (same as the inbound, except for the, uh, outbound tunnels
in that client's pool)
There are other options, and more will be added later, but the above are
the most relevent ones.
* Replaced Jetty 4.2.21 with Jetty 5.1.2
* Compress all profile data on disk.
* Adjust the reseeding functionality to work even when the JVM's http proxy
is set.
* Enable a poor-man's interactive-flow in the streaming lib by choking the
max window size.
* Reduced the default streaming lib max message size to 16KB (though still
configurable by the user), also doubling the default maximum window
size.
* Replaced the RouterIdentity in a Lease with its SHA256 hash.
* Reduced the overall I2NP message checksum from a full 32 byte SHA256 to
the first byte of the SHA256.
* Added a new "netId" flag to let routers drop references to other routers
who we won't be able to talk to.
* Extended the timestamper to get a second (or third) opinion whenever it
wants to actually adjust the clock offset.
* Replaced that kludge of a timestamp I2NP message with a full blown
DateMessage.
* Substantial memory optimizations within the router and the SDK to reduce
GC churn. Client apps and the streaming libs have not been tuned,
however.
* More bugfixes thank you can shake a stick at.
2005-02-13 jrandom
* Updated jbigi source to handle 64bit CPUs. The bundled jbigi.jar still
only contains 32bit versions, so build your own, placing libjbigi.so in
your install dir if necessary. (thanks mule!)
* Added support for libjbigi-$os-athlon64 to NativeBigInteger and CPUID
(thanks spaetz!)
2005-02-16 22:23:47 +00:00
import net.i2p.router.TunnelPoolSettings ;
2008-09-06 13:47:56 +00:00
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade ;
2013-05-02 14:12:53 +00:00
import net.i2p.router.transport.TransportUtil ;
2008-07-16 13:42:54 +00:00
import net.i2p.stat.Rate ;
import net.i2p.stat.RateStat ;
2012-10-19 20:26:08 +00:00
import net.i2p.util.PortMapper ;
2004-07-24 02:06:07 +00:00
/ * *
* Simple helper to query the appropriate router for data necessary to render
* the summary sections on the router console .
2012-01-21 15:27:58 +00:00
*
* For the full summary bar use renderSummaryBar ( )
2004-07-24 02:06:07 +00:00
* /
2009-01-29 02:16:18 +00:00
public class SummaryHelper extends HelperBase {
2010-12-19 00:04:55 +00:00
// Opera 10.63 doesn't have the char, TODO check UA
//static final String THINSP = " / ";
static final String THINSP = " / " ;
2012-06-05 02:12:30 +00:00
private static final char S = ',' ;
2012-06-09 13:48:26 +00:00
static final String PROP_SUMMARYBAR = " routerconsole.summaryBar. " ;
2012-06-05 02:12:30 +00:00
2012-07-08 22:11:05 +00:00
static final String DEFAULT_FULL =
2012-06-05 02:12:30 +00:00
" HelpAndFAQ " + S +
" I2PServices " + S +
" I2PInternals " + S +
" General " + S +
" NetworkReachability " + S +
" UpdateStatus " + S +
" RestartStatus " + S +
" Peers " + S +
" FirewallAndReseedStatus " + S +
" Bandwidth " + S +
" Tunnels " + S +
" Congestion " + S +
" TunnelStatus " + S +
" Destinations " + S +
" " ;
2012-07-08 22:11:05 +00:00
static final String DEFAULT_MINIMAL =
2012-06-05 02:12:30 +00:00
" ShortGeneral " + S +
" NewsHeadings " + S +
" UpdateStatus " + S +
" NetworkReachability " + S +
2012-07-24 12:05:34 +00:00
" RestartStatus " + S +
2012-06-05 02:12:30 +00:00
" FirewallAndReseedStatus " + S +
" Destinations " + S +
" " ;
2010-12-19 00:04:55 +00:00
2004-07-24 02:06:07 +00:00
/ * *
* Retrieve the shortened 4 character ident for the router located within
* the current JVM at the given context .
*
* /
public String getIdent ( ) {
if ( _context = = null ) return " [no router] " ;
if ( _context . routerHash ( ) ! = null )
return _context . routerHash ( ) . toBase64 ( ) . substring ( 0 , 4 ) ;
else
return " [unknown] " ;
}
/ * *
* Retrieve the version number of the router .
*
* /
public String getVersion ( ) {
2009-05-01 12:31:38 +00:00
return RouterVersion . FULL_VERSION ;
2004-07-24 02:06:07 +00:00
}
/ * *
* Retrieve a pretty printed uptime count ( ala 4d or 7h or 39m )
*
* /
public String getUptime ( ) {
if ( _context = = null ) return " [no router] " ;
Router router = _context . router ( ) ;
if ( router = = null )
return " [not up] " ;
else
2010-11-06 12:28:38 +00:00
return DataHelper . formatDuration2 ( router . getUptime ( ) ) ;
2004-07-24 02:06:07 +00:00
}
2005-02-22 07:07:29 +00:00
2009-12-19 16:47:18 +00:00
/ * *
this displayed offset , not skew - now handled in reachability ( )
2009-08-03 20:02:28 +00:00
private String timeSkew ( ) {
2005-02-22 07:07:29 +00:00
if ( _context = = null ) return " " ;
2009-08-03 20:02:28 +00:00
//if (!_context.clock().getUpdatedSuccessfully())
// return " (Unknown skew)";
2005-02-22 07:07:29 +00:00
long ms = _context . clock ( ) . getOffset ( ) ;
2009-05-20 22:50:14 +00:00
long diff = Math . abs ( ms ) ;
2009-08-03 20:02:28 +00:00
if ( diff < 3000 )
return " " ;
2010-11-06 12:28:38 +00:00
return " ( " + DataHelper . formatDuration2 ( diff ) + " " + _ ( " skew " ) + " ) " ;
2005-02-22 07:07:29 +00:00
}
2009-12-19 16:47:18 +00:00
* * /
2005-02-22 07:07:29 +00:00
public boolean allowReseed ( ) {
2009-06-15 21:58:28 +00:00
return _context . netDb ( ) . isInitialized ( ) & &
2012-09-28 17:50:41 +00:00
( _context . netDb ( ) . getKnownRouters ( ) < 30 ) | |
_context . getBooleanProperty ( " i2p.alwaysAllowReseed " ) ;
2005-02-22 07:07:29 +00:00
}
2005-03-23 21:13:03 +00:00
2009-08-02 11:54:14 +00:00
/** subtract one for ourselves, so if we know no other peers it displays zero */
public int getAllPeers ( ) { return Math . max ( _context . netDb ( ) . getKnownRouters ( ) - 1 , 0 ) ; }
2005-08-10 23:55:40 +00:00
public String getReachability ( ) {
2009-12-19 16:47:18 +00:00
return reachability ( ) ; // + timeSkew();
2010-02-13 01:20:23 +00:00
// testing
//return reachability() +
// " Offset: " + DataHelper.formatDuration(_context.clock().getOffset()) +
// " Slew: " + DataHelper.formatDuration(((RouterClock)_context.clock()).getDeltaOffset());
2009-08-03 20:02:28 +00:00
}
private String reachability ( ) {
2012-01-10 00:02:20 +00:00
if ( _context . commSystem ( ) . isDummy ( ) )
return " VM Comm System " ;
2009-03-02 16:07:48 +00:00
if ( _context . router ( ) . getUptime ( ) > 60 * 1000 & & ( ! _context . router ( ) . gracefulShutdownInProgress ( ) ) & &
! _context . clientManager ( ) . isAlive ( ) )
2009-10-27 13:35:27 +00:00
return _ ( " ERR-Client Manager I2CP Error - check logs " ) ; // not a router problem but the user should know
2009-12-19 16:47:18 +00:00
// Warn based on actual skew from peers, not update status, so if we successfully offset
// the clock, we don't complain.
//if (!_context.clock().getUpdatedSuccessfully())
2010-02-13 01:20:23 +00:00
long skew = _context . commSystem ( ) . getFramedAveragePeerClockSkew ( 33 ) ;
2009-12-19 16:47:18 +00:00
// Display the actual skew, not the offset
2010-02-13 01:20:23 +00:00
if ( Math . abs ( skew ) > 30 * 1000 )
2010-11-06 12:28:38 +00:00
return _ ( " ERR-Clock Skew of {0} " , DataHelper . formatDuration2 ( Math . abs ( skew ) ) ) ;
2008-10-26 17:24:11 +00:00
if ( _context . router ( ) . isHidden ( ) )
2009-10-27 13:35:27 +00:00
return _ ( " Hidden " ) ;
2012-04-12 14:48:18 +00:00
RouterInfo routerInfo = _context . router ( ) . getRouterInfo ( ) ;
if ( routerInfo = = null )
return _ ( " Testing " ) ;
2008-10-26 17:24:11 +00:00
2005-08-10 23:55:40 +00:00
int status = _context . commSystem ( ) . getReachabilityStatus ( ) ;
switch ( status ) {
case CommSystemFacade . STATUS_OK :
2012-04-12 14:48:18 +00:00
RouterAddress ra = routerInfo . getTargetAddress ( " NTCP " ) ;
2014-06-07 13:16:19 +00:00
if ( ra = = null )
return _ ( " OK " ) ;
byte [ ] ip = ra . getIP ( ) ;
if ( ip = = null )
return _ ( " ERR-Unresolved TCP Address " ) ;
2013-05-02 14:12:53 +00:00
// TODO set IPv6 arg based on configuration?
2014-06-07 13:16:19 +00:00
if ( TransportUtil . isPubliclyRoutable ( ip , true ) )
2009-10-27 13:35:27 +00:00
return _ ( " OK " ) ;
return _ ( " ERR-Private TCP Address " ) ;
2005-08-10 23:55:40 +00:00
case CommSystemFacade . STATUS_DIFFERENT :
2009-10-27 13:35:27 +00:00
return _ ( " ERR-SymmetricNAT " ) ;
2005-08-10 23:55:40 +00:00
case CommSystemFacade . STATUS_REJECT_UNSOLICITED :
2012-04-12 14:48:18 +00:00
if ( routerInfo . getTargetAddress ( " NTCP " ) ! = null )
2009-10-27 13:35:27 +00:00
return _ ( " WARN-Firewalled with Inbound TCP Enabled " ) ;
2008-09-06 13:47:56 +00:00
if ( ( ( FloodfillNetworkDatabaseFacade ) _context . netDb ( ) ) . floodfillEnabled ( ) )
2009-10-27 13:35:27 +00:00
return _ ( " WARN-Firewalled and Floodfill " ) ;
2011-08-26 13:50:58 +00:00
//if (_context.router().getRouterInfo().getCapabilities().indexOf('O') >= 0)
// return _("WARN-Firewalled and Fast");
2009-10-27 13:35:27 +00:00
return _ ( " Firewalled " ) ;
2012-10-20 17:28:00 +00:00
case CommSystemFacade . STATUS_DISCONNECTED :
return _ ( " Disconnected - check network cable " ) ;
2008-06-17 13:47:54 +00:00
case CommSystemFacade . STATUS_HOSED :
2009-10-27 13:35:27 +00:00
return _ ( " ERR-UDP Port In Use - Set i2np.udp.internalPort=xxxx in advanced config and restart " ) ;
2005-08-10 23:55:40 +00:00
case CommSystemFacade . STATUS_UNKNOWN : // fallthrough
default :
2012-04-12 14:48:18 +00:00
ra = routerInfo . getTargetAddress ( " SSU " ) ;
2008-12-20 01:04:19 +00:00
if ( ra = = null & & _context . router ( ) . getUptime ( ) > 5 * 60 * 1000 ) {
2009-12-19 16:47:18 +00:00
if ( getActivePeers ( ) < = 0 )
return _ ( " ERR-No Active Peers, Check Network Connection and Firewall " ) ;
else if ( _context . getProperty ( ConfigNetHelper . PROP_I2NP_NTCP_HOSTNAME ) = = null | |
2008-12-03 18:53:57 +00:00
_context . getProperty ( ConfigNetHelper . PROP_I2NP_NTCP_PORT ) = = null )
2009-10-27 13:35:27 +00:00
return _ ( " ERR-UDP Disabled and Inbound TCP host/port not set " ) ;
2008-12-03 18:53:57 +00:00
else
2009-10-27 13:35:27 +00:00
return _ ( " WARN-Firewalled with UDP Disabled " ) ;
2008-12-03 18:53:57 +00:00
}
2009-10-27 13:35:27 +00:00
return _ ( " Testing " ) ;
2005-08-10 23:55:40 +00:00
}
}
2004-08-11 22:23:48 +00:00
/ * *
* Retrieve amount of used memory .
*
* /
2009-08-13 15:15:41 +00:00
/ * * * * * * * *
2004-08-11 22:23:48 +00:00
public String getMemory ( ) {
2004-08-16 20:27:06 +00:00
DecimalFormat integerFormatter = new DecimalFormat ( " ###,###,##0 " ) ;
2004-08-11 22:23:48 +00:00
long used = ( Runtime . getRuntime ( ) . totalMemory ( ) - Runtime . getRuntime ( ) . freeMemory ( ) ) / 1024 ;
long usedPc = 100 - ( ( Runtime . getRuntime ( ) . freeMemory ( ) * 100 ) / Runtime . getRuntime ( ) . totalMemory ( ) ) ;
2004-08-16 20:27:06 +00:00
return integerFormatter . format ( used ) + " KB ( " + usedPc + " %) " ;
2004-08-11 22:23:48 +00:00
}
2009-08-13 15:15:41 +00:00
* * * * * * * * /
2004-07-24 02:06:07 +00:00
/ * *
2004-09-09 02:26:42 +00:00
* How many peers we are talking to now
2004-07-24 02:06:07 +00:00
*
* /
public int getActivePeers ( ) {
2004-09-09 02:26:42 +00:00
if ( _context = = null )
return 0 ;
else
return _context . commSystem ( ) . countActivePeers ( ) ;
}
2009-08-13 18:46:14 +00:00
/ * *
* Should we warn about a possible firewall problem ?
* /
public boolean showFirewallWarning ( ) {
return _context ! = null & &
_context . netDb ( ) . isInitialized ( ) & &
_context . router ( ) . getUptime ( ) > 2 * 60 * 1000 & &
2012-01-10 00:02:20 +00:00
( ! _context . commSystem ( ) . isDummy ( ) ) & &
2009-08-13 18:46:14 +00:00
_context . commSystem ( ) . countActivePeers ( ) < = 0 & &
_context . netDb ( ) . getKnownRouters ( ) > 5 ;
}
2004-09-09 02:26:42 +00:00
/ * *
* How many active identities have we spoken with recently
*
* /
public int getActiveProfiles ( ) {
2004-07-24 02:06:07 +00:00
if ( _context = = null )
return 0 ;
else
return _context . profileOrganizer ( ) . countActivePeers ( ) ;
}
/ * *
* How many active peers the router ranks as fast .
*
* /
public int getFastPeers ( ) {
if ( _context = = null )
return 0 ;
else
return _context . profileOrganizer ( ) . countFastPeers ( ) ;
}
/ * *
* How many active peers the router ranks as having a high capacity .
*
* /
public int getHighCapacityPeers ( ) {
if ( _context = = null )
return 0 ;
else
return _context . profileOrganizer ( ) . countHighCapacityPeers ( ) ;
}
/ * *
* How many active peers the router ranks as well integrated .
*
* /
public int getWellIntegratedPeers ( ) {
if ( _context = = null )
return 0 ;
2011-07-21 15:34:23 +00:00
//return _context.profileOrganizer().countWellIntegratedPeers();
return _context . peerManager ( ) . getPeersByCapability ( FloodfillNetworkDatabaseFacade . CAPABILITY_FLOODFILL ) . size ( ) ;
2004-07-24 02:06:07 +00:00
}
/ * *
* How many peers the router ranks as failing .
*
* /
2009-08-13 15:15:41 +00:00
/ * * * * * * * *
2004-07-24 02:06:07 +00:00
public int getFailingPeers ( ) {
if ( _context = = null )
return 0 ;
else
return _context . profileOrganizer ( ) . countFailingPeers ( ) ;
}
2009-08-13 15:15:41 +00:00
* * * * * * * * /
2004-07-24 02:06:07 +00:00
/ * *
* How many peers totally suck .
*
* /
2009-08-13 15:15:41 +00:00
/ * * * * * * * *
2012-10-26 16:24:31 +00:00
public int getBanlistedPeers ( ) {
2004-07-24 02:06:07 +00:00
if ( _context = = null )
return 0 ;
else
2012-10-26 16:24:31 +00:00
return _context . banlist ( ) . getRouterCount ( ) ;
2004-07-24 02:06:07 +00:00
}
2009-08-13 15:15:41 +00:00
* * * * * * * * /
2004-07-24 02:06:07 +00:00
/ * *
2010-05-10 14:22:37 +00:00
* @return " x.xx / y.yy {K|M} "
2004-07-24 02:06:07 +00:00
* /
2010-05-10 14:22:37 +00:00
public String getSecondKBps ( ) {
2004-07-24 02:06:07 +00:00
if ( _context = = null )
2010-05-10 14:22:37 +00:00
return " 0 / 0 " ;
return formatPair ( _context . bandwidthLimiter ( ) . getReceiveBps ( ) ,
_context . bandwidthLimiter ( ) . getSendBps ( ) ) ;
2004-07-24 02:06:07 +00:00
}
/ * *
2010-05-10 14:22:37 +00:00
* @return " x.xx / y.yy {K|M} "
2004-07-24 02:06:07 +00:00
* /
2010-05-10 14:22:37 +00:00
public String getFiveMinuteKBps ( ) {
2004-07-24 02:06:07 +00:00
if ( _context = = null )
2010-05-10 14:22:37 +00:00
return " 0 / 0 " ;
2004-07-24 02:06:07 +00:00
2005-09-12 02:58:13 +00:00
RateStat receiveRate = _context . statManager ( ) . getRate ( " bw.recvRate " ) ;
2010-05-10 14:22:37 +00:00
double in = 0 ;
if ( receiveRate ! = null ) {
Rate r = receiveRate . getRate ( 5 * 60 * 1000 ) ;
if ( r ! = null )
in = r . getAverageValue ( ) ;
}
RateStat sendRate = _context . statManager ( ) . getRate ( " bw.sendRate " ) ;
double out = 0 ;
if ( sendRate ! = null ) {
Rate r = sendRate . getRate ( 5 * 60 * 1000 ) ;
if ( r ! = null )
out = r . getAverageValue ( ) ;
}
return formatPair ( in , out ) ;
2004-07-24 02:06:07 +00:00
}
/ * *
2010-05-10 14:22:37 +00:00
* @return " x.xx / y.yy {K|M} "
2004-07-24 02:06:07 +00:00
* /
2010-05-10 14:22:37 +00:00
public String getLifetimeKBps ( ) {
2004-07-24 02:06:07 +00:00
if ( _context = = null )
2010-05-10 14:22:37 +00:00
return " 0 / 0 " ;
2004-07-24 02:06:07 +00:00
2005-09-12 02:58:13 +00:00
RateStat receiveRate = _context . statManager ( ) . getRate ( " bw.recvRate " ) ;
2010-05-10 14:22:37 +00:00
double in ;
if ( receiveRate = = null )
in = 0 ;
else
in = receiveRate . getLifetimeAverageValue ( ) ;
RateStat sendRate = _context . statManager ( ) . getRate ( " bw.sendRate " ) ;
double out ;
if ( sendRate = = null )
out = 0 ;
else
out = sendRate . getLifetimeAverageValue ( ) ;
return formatPair ( in , out ) ;
2004-07-24 02:06:07 +00:00
}
/ * *
2010-05-10 14:22:37 +00:00
* @return " x.xx / y.yy {K|M} "
2004-07-24 02:06:07 +00:00
* /
2010-05-10 14:22:37 +00:00
private static String formatPair ( double in , double out ) {
boolean mega = in > = 1024 * 1024 | | out > = 1024 * 1024 ;
// scale both the same
if ( mega ) {
in / = 1024 * 1024 ;
out / = 1024 * 1024 ;
} else {
in / = 1024 ;
out / = 1024 ;
}
// control total width
DecimalFormat fmt ;
if ( in > = 1000 | | out > = 1000 )
fmt = new DecimalFormat ( " #0 " ) ;
else if ( in > = 100 | | out > = 100 )
fmt = new DecimalFormat ( " #0.0 " ) ;
else
fmt = new DecimalFormat ( " #0.00 " ) ;
2010-12-19 00:04:55 +00:00
return fmt . format ( in ) + THINSP + fmt . format ( out ) + " " +
2010-05-10 14:22:37 +00:00
( mega ? 'M' : 'K' ) ;
2004-07-24 02:06:07 +00:00
}
2010-05-10 14:22:37 +00:00
2004-07-24 02:06:07 +00:00
/ * *
* How much data have we received since the router started ( pretty printed
* string with 2 decimal places and the appropriate units - GB / MB / KB / bytes )
*
* /
public String getInboundTransferred ( ) {
if ( _context = = null )
2009-01-22 04:02:41 +00:00
return " 0 " ;
2004-07-24 02:06:07 +00:00
long received = _context . bandwidthLimiter ( ) . getTotalAllocatedInboundBytes ( ) ;
2010-11-06 12:28:38 +00:00
return DataHelper . formatSize2 ( received ) + 'B' ;
2004-07-24 02:06:07 +00:00
}
/ * *
* How much data have we sent since the router started ( pretty printed
* string with 2 decimal places and the appropriate units - GB / MB / KB / bytes )
*
* /
public String getOutboundTransferred ( ) {
if ( _context = = null )
2009-01-22 04:02:41 +00:00
return " 0 " ;
2004-07-24 02:06:07 +00:00
long sent = _context . bandwidthLimiter ( ) . getTotalAllocatedOutboundBytes ( ) ;
2010-11-06 12:28:38 +00:00
return DataHelper . formatSize2 ( sent ) + 'B' ;
2004-07-24 02:06:07 +00:00
}
2004-07-30 20:28:19 +00:00
/ * *
2010-01-06 14:52:53 +00:00
* Client destinations connected locally .
2004-07-30 20:28:19 +00:00
*
* @return html section summary
* /
public String getDestinations ( ) {
2010-01-06 14:52:53 +00:00
// convert the set to a list so we can sort by name and not lose duplicates
2013-11-21 11:31:50 +00:00
List < Destination > clients = new ArrayList < Destination > ( _context . clientManager ( ) . listClients ( ) ) ;
2005-02-16 jrandom
* (Merged the 0.5-pre branch back into CVS HEAD)
* Replaced the old tunnel routing crypto with the one specified in
router/doc/tunnel-alt.html, including updates to the web console to view
and tweak it.
* Provide the means for routers to reject tunnel requests with a wider
range of responses:
probabalistic rejection, due to approaching overload
transient rejection, due to temporary overload
bandwidth rejection, due to persistent bandwidth overload
critical rejection, due to general router fault (or imminent shutdown)
The different responses are factored into the profiles accordingly.
* Replaced the old I2CP tunnel related options (tunnels.depthInbound, etc)
with a series of new properties, relevent to the new tunnel routing code:
inbound.nickname (used on the console)
inbound.quantity (# of tunnels to use in any leaseSets)
inbound.backupQuantity (# of tunnels to keep in the ready)
inbound.length (# of remote peers in the tunnel)
inbound.lengthVariance (if > 0, permute the length by adding a random #
up to the variance. if < 0, permute the length
by adding or subtracting a random # up to the
variance)
outbound.* (same as the inbound, except for the, uh, outbound tunnels
in that client's pool)
There are other options, and more will be added later, but the above are
the most relevent ones.
* Replaced Jetty 4.2.21 with Jetty 5.1.2
* Compress all profile data on disk.
* Adjust the reseeding functionality to work even when the JVM's http proxy
is set.
* Enable a poor-man's interactive-flow in the streaming lib by choking the
max window size.
* Reduced the default streaming lib max message size to 16KB (though still
configurable by the user), also doubling the default maximum window
size.
* Replaced the RouterIdentity in a Lease with its SHA256 hash.
* Reduced the overall I2NP message checksum from a full 32 byte SHA256 to
the first byte of the SHA256.
* Added a new "netId" flag to let routers drop references to other routers
who we won't be able to talk to.
* Extended the timestamper to get a second (or third) opinion whenever it
wants to actually adjust the clock offset.
* Replaced that kludge of a timestamp I2NP message with a full blown
DateMessage.
* Substantial memory optimizations within the router and the SDK to reduce
GC churn. Client apps and the streaming libs have not been tuned,
however.
* More bugfixes thank you can shake a stick at.
2005-02-13 jrandom
* Updated jbigi source to handle 64bit CPUs. The bundled jbigi.jar still
only contains 32bit versions, so build your own, placing libjbigi.so in
your install dir if necessary. (thanks mule!)
* Added support for libjbigi-$os-athlon64 to NativeBigInteger and CPUID
(thanks spaetz!)
2005-02-16 22:23:47 +00:00
2009-07-01 16:00:43 +00:00
StringBuilder buf = new StringBuilder ( 512 ) ;
2012-06-09 06:08:44 +00:00
buf . append ( " <h3><a href= \" /i2ptunnelmgr \" target= \" _top \" title= \" " ) . append ( _ ( " Add/remove/edit & control your client and server tunnels " ) ) . append ( " \" > " ) . append ( _ ( " Local Destinations " ) ) . append ( " </a></h3><hr class= \" b \" ><div class= \" tunnels \" > " ) ;
2010-05-05 16:51:54 +00:00
if ( ! clients . isEmpty ( ) ) {
2010-01-06 14:52:53 +00:00
Collections . sort ( clients , new AlphaComparator ( ) ) ;
buf . append ( " <table> " ) ;
2005-02-16 jrandom
* (Merged the 0.5-pre branch back into CVS HEAD)
* Replaced the old tunnel routing crypto with the one specified in
router/doc/tunnel-alt.html, including updates to the web console to view
and tweak it.
* Provide the means for routers to reject tunnel requests with a wider
range of responses:
probabalistic rejection, due to approaching overload
transient rejection, due to temporary overload
bandwidth rejection, due to persistent bandwidth overload
critical rejection, due to general router fault (or imminent shutdown)
The different responses are factored into the profiles accordingly.
* Replaced the old I2CP tunnel related options (tunnels.depthInbound, etc)
with a series of new properties, relevent to the new tunnel routing code:
inbound.nickname (used on the console)
inbound.quantity (# of tunnels to use in any leaseSets)
inbound.backupQuantity (# of tunnels to keep in the ready)
inbound.length (# of remote peers in the tunnel)
inbound.lengthVariance (if > 0, permute the length by adding a random #
up to the variance. if < 0, permute the length
by adding or subtracting a random # up to the
variance)
outbound.* (same as the inbound, except for the, uh, outbound tunnels
in that client's pool)
There are other options, and more will be added later, but the above are
the most relevent ones.
* Replaced Jetty 4.2.21 with Jetty 5.1.2
* Compress all profile data on disk.
* Adjust the reseeding functionality to work even when the JVM's http proxy
is set.
* Enable a poor-man's interactive-flow in the streaming lib by choking the
max window size.
* Reduced the default streaming lib max message size to 16KB (though still
configurable by the user), also doubling the default maximum window
size.
* Replaced the RouterIdentity in a Lease with its SHA256 hash.
* Reduced the overall I2NP message checksum from a full 32 byte SHA256 to
the first byte of the SHA256.
* Added a new "netId" flag to let routers drop references to other routers
who we won't be able to talk to.
* Extended the timestamper to get a second (or third) opinion whenever it
wants to actually adjust the clock offset.
* Replaced that kludge of a timestamp I2NP message with a full blown
DateMessage.
* Substantial memory optimizations within the router and the SDK to reduce
GC churn. Client apps and the streaming libs have not been tuned,
however.
* More bugfixes thank you can shake a stick at.
2005-02-13 jrandom
* Updated jbigi source to handle 64bit CPUs. The bundled jbigi.jar still
only contains 32bit versions, so build your own, placing libjbigi.so in
your install dir if necessary. (thanks mule!)
* Added support for libjbigi-$os-athlon64 to NativeBigInteger and CPUID
(thanks spaetz!)
2005-02-16 22:23:47 +00:00
2013-11-28 11:56:54 +00:00
for ( Destination client : clients ) {
2010-01-06 14:52:53 +00:00
String name = getName ( client ) ;
Hash h = client . calculateHash ( ) ;
buf . append ( " <tr><td align= \" right \" ><img src= \" /themes/console/images/ " ) ;
if ( _context . clientManager ( ) . shouldPublishLeaseSet ( h ) )
2014-02-10 18:33:32 +00:00
buf . append ( " server.png \" alt= \" Server \" title= \" " ) . append ( _ ( " Server " ) ) . append ( " \" > " ) ;
2010-01-06 14:52:53 +00:00
else
2014-02-10 18:33:32 +00:00
buf . append ( " client.png \" alt= \" Client \" title= \" " ) . append ( _ ( " Client " ) ) . append ( " \" > " ) ;
2010-11-17 22:26:31 +00:00
buf . append ( " </td><td align= \" left \" ><b><a href= \" tunnels# " ) . append ( h . toBase64 ( ) . substring ( 0 , 4 ) ) ;
2014-02-10 18:33:32 +00:00
buf . append ( " \" target= \" _top \" title= \" " ) . append ( _ ( " Show tunnels " ) ) . append ( " \" > " ) ;
2011-05-20 12:48:58 +00:00
if ( name . length ( ) < 18 )
2010-01-06 14:52:53 +00:00
buf . append ( name ) ;
else
buf . append ( name . substring ( 0 , 15 ) ) . append ( " … " ) ;
buf . append ( " </a></b></td> \ n " ) ;
LeaseSet ls = _context . netDb ( ) . lookupLeaseSetLocally ( h ) ;
2010-02-02 15:18:22 +00:00
if ( ls ! = null & & _context . tunnelManager ( ) . getOutboundClientTunnelCount ( h ) > 0 ) {
2010-01-06 14:52:53 +00:00
long timeToExpire = ls . getEarliestLeaseDate ( ) - _context . clock ( ) . now ( ) ;
if ( timeToExpire < 0 ) {
// red or yellow light
2010-11-06 12:28:38 +00:00
buf . append ( " <td><img src= \" /themes/console/images/local_inprogress.png \" alt= \" " ) . append ( _ ( " Rebuilding " ) ) . append ( " … \" title= \" " ) . append ( _ ( " Leases expired " ) ) . append ( " " ) . append ( DataHelper . formatDuration2 ( 0 - timeToExpire ) ) ;
2010-01-06 14:52:53 +00:00
buf . append ( " " ) . append ( _ ( " ago " ) ) . append ( " . " ) . append ( _ ( " Rebuilding " ) ) . append ( " … \" ></td></tr> \ n " ) ;
} else {
// green light
buf . append ( " <td><img src= \" /themes/console/images/local_up.png \" alt= \" Ready \" title= \" " ) . append ( _ ( " Ready " ) ) . append ( " \" ></td></tr> \ n " ) ;
}
2009-10-11 22:51:43 +00:00
} else {
2010-01-06 14:52:53 +00:00
// yellow light
buf . append ( " <td><img src= \" /themes/console/images/local_inprogress.png \" alt= \" " ) . append ( _ ( " Building " ) ) . append ( " … \" title= \" " ) . append ( _ ( " Building tunnels " ) ) . append ( " … \" ></td></tr> \ n " ) ;
2005-02-16 jrandom
* (Merged the 0.5-pre branch back into CVS HEAD)
* Replaced the old tunnel routing crypto with the one specified in
router/doc/tunnel-alt.html, including updates to the web console to view
and tweak it.
* Provide the means for routers to reject tunnel requests with a wider
range of responses:
probabalistic rejection, due to approaching overload
transient rejection, due to temporary overload
bandwidth rejection, due to persistent bandwidth overload
critical rejection, due to general router fault (or imminent shutdown)
The different responses are factored into the profiles accordingly.
* Replaced the old I2CP tunnel related options (tunnels.depthInbound, etc)
with a series of new properties, relevent to the new tunnel routing code:
inbound.nickname (used on the console)
inbound.quantity (# of tunnels to use in any leaseSets)
inbound.backupQuantity (# of tunnels to keep in the ready)
inbound.length (# of remote peers in the tunnel)
inbound.lengthVariance (if > 0, permute the length by adding a random #
up to the variance. if < 0, permute the length
by adding or subtracting a random # up to the
variance)
outbound.* (same as the inbound, except for the, uh, outbound tunnels
in that client's pool)
There are other options, and more will be added later, but the above are
the most relevent ones.
* Replaced Jetty 4.2.21 with Jetty 5.1.2
* Compress all profile data on disk.
* Adjust the reseeding functionality to work even when the JVM's http proxy
is set.
* Enable a poor-man's interactive-flow in the streaming lib by choking the
max window size.
* Reduced the default streaming lib max message size to 16KB (though still
configurable by the user), also doubling the default maximum window
size.
* Replaced the RouterIdentity in a Lease with its SHA256 hash.
* Reduced the overall I2NP message checksum from a full 32 byte SHA256 to
the first byte of the SHA256.
* Added a new "netId" flag to let routers drop references to other routers
who we won't be able to talk to.
* Extended the timestamper to get a second (or third) opinion whenever it
wants to actually adjust the clock offset.
* Replaced that kludge of a timestamp I2NP message with a full blown
DateMessage.
* Substantial memory optimizations within the router and the SDK to reduce
GC churn. Client apps and the streaming libs have not been tuned,
however.
* More bugfixes thank you can shake a stick at.
2005-02-13 jrandom
* Updated jbigi source to handle 64bit CPUs. The bundled jbigi.jar still
only contains 32bit versions, so build your own, placing libjbigi.so in
your install dir if necessary. (thanks mule!)
* Added support for libjbigi-$os-athlon64 to NativeBigInteger and CPUID
(thanks spaetz!)
2005-02-16 22:23:47 +00:00
}
}
2010-01-06 14:52:53 +00:00
buf . append ( " </table> " ) ;
} else {
buf . append ( " <center><i> " ) . append ( _ ( " none " ) ) . append ( " </i></center> " ) ;
2004-07-30 20:28:19 +00:00
}
2012-01-22 16:15:18 +00:00
buf . append ( " </div> \ n " ) ;
2005-02-16 jrandom
* (Merged the 0.5-pre branch back into CVS HEAD)
* Replaced the old tunnel routing crypto with the one specified in
router/doc/tunnel-alt.html, including updates to the web console to view
and tweak it.
* Provide the means for routers to reject tunnel requests with a wider
range of responses:
probabalistic rejection, due to approaching overload
transient rejection, due to temporary overload
bandwidth rejection, due to persistent bandwidth overload
critical rejection, due to general router fault (or imminent shutdown)
The different responses are factored into the profiles accordingly.
* Replaced the old I2CP tunnel related options (tunnels.depthInbound, etc)
with a series of new properties, relevent to the new tunnel routing code:
inbound.nickname (used on the console)
inbound.quantity (# of tunnels to use in any leaseSets)
inbound.backupQuantity (# of tunnels to keep in the ready)
inbound.length (# of remote peers in the tunnel)
inbound.lengthVariance (if > 0, permute the length by adding a random #
up to the variance. if < 0, permute the length
by adding or subtracting a random # up to the
variance)
outbound.* (same as the inbound, except for the, uh, outbound tunnels
in that client's pool)
There are other options, and more will be added later, but the above are
the most relevent ones.
* Replaced Jetty 4.2.21 with Jetty 5.1.2
* Compress all profile data on disk.
* Adjust the reseeding functionality to work even when the JVM's http proxy
is set.
* Enable a poor-man's interactive-flow in the streaming lib by choking the
max window size.
* Reduced the default streaming lib max message size to 16KB (though still
configurable by the user), also doubling the default maximum window
size.
* Replaced the RouterIdentity in a Lease with its SHA256 hash.
* Reduced the overall I2NP message checksum from a full 32 byte SHA256 to
the first byte of the SHA256.
* Added a new "netId" flag to let routers drop references to other routers
who we won't be able to talk to.
* Extended the timestamper to get a second (or third) opinion whenever it
wants to actually adjust the clock offset.
* Replaced that kludge of a timestamp I2NP message with a full blown
DateMessage.
* Substantial memory optimizations within the router and the SDK to reduce
GC churn. Client apps and the streaming libs have not been tuned,
however.
* More bugfixes thank you can shake a stick at.
2005-02-13 jrandom
* Updated jbigi source to handle 64bit CPUs. The bundled jbigi.jar still
only contains 32bit versions, so build your own, placing libjbigi.so in
your install dir if necessary. (thanks mule!)
* Added support for libjbigi-$os-athlon64 to NativeBigInteger and CPUID
(thanks spaetz!)
2005-02-16 22:23:47 +00:00
return buf . toString ( ) ;
2004-07-30 20:28:19 +00:00
}
2014-06-15 16:14:13 +00:00
/ * *
* Compare translated nicknames - put " shared clients " first in the sort
* Inner class , can ' t be Serializable
* /
2010-01-24 02:16:36 +00:00
private class AlphaComparator implements Comparator < Destination > {
2012-10-14 13:54:38 +00:00
private final String xsc = _ ( " shared clients " ) ;
2010-01-24 02:16:36 +00:00
public int compare ( Destination lhs , Destination rhs ) {
String lname = getName ( lhs ) ;
String rname = getName ( rhs ) ;
2009-10-28 18:26:50 +00:00
if ( lname . equals ( xsc ) )
2009-02-24 22:59:59 +00:00
return - 1 ;
2009-10-28 18:26:50 +00:00
if ( rname . equals ( xsc ) )
2009-02-24 22:59:59 +00:00
return 1 ;
return Collator . getInstance ( ) . compare ( lname , rname ) ;
}
}
2009-10-28 18:26:50 +00:00
/** translate here so collation works above */
2009-02-24 22:59:59 +00:00
private String getName ( Destination d ) {
TunnelPoolSettings in = _context . tunnelManager ( ) . getInboundSettings ( d . calculateHash ( ) ) ;
String name = ( in ! = null ? in . getDestinationNickname ( ) : null ) ;
if ( name = = null ) {
TunnelPoolSettings out = _context . tunnelManager ( ) . getOutboundSettings ( d . calculateHash ( ) ) ;
name = ( out ! = null ? out . getDestinationNickname ( ) : null ) ;
if ( name = = null )
name = d . calculateHash ( ) . toBase64 ( ) . substring ( 0 , 6 ) ;
2009-10-28 18:26:50 +00:00
else
name = _ ( name ) ;
} else {
name = _ ( name ) ;
2009-02-24 22:59:59 +00:00
}
return name ;
}
2004-07-24 02:06:07 +00:00
/ * *
* How many free inbound tunnels we have .
*
* /
public int getInboundTunnels ( ) {
if ( _context = = null )
return 0 ;
else
return _context . tunnelManager ( ) . getFreeTunnelCount ( ) ;
}
/ * *
* How many active outbound tunnels we have .
*
* /
public int getOutboundTunnels ( ) {
if ( _context = = null )
return 0 ;
else
return _context . tunnelManager ( ) . getOutboundTunnelCount ( ) ;
}
2005-12-09 08:05:44 +00:00
/ * *
* How many inbound client tunnels we have .
*
* /
public int getInboundClientTunnels ( ) {
if ( _context = = null )
return 0 ;
else
return _context . tunnelManager ( ) . getInboundClientTunnelCount ( ) ;
}
/ * *
* How many active outbound client tunnels we have .
*
* /
public int getOutboundClientTunnels ( ) {
if ( _context = = null )
return 0 ;
else
return _context . tunnelManager ( ) . getOutboundClientTunnelCount ( ) ;
}
2004-07-24 02:06:07 +00:00
/ * *
* How many tunnels we are participating in .
*
* /
public int getParticipatingTunnels ( ) {
if ( _context = = null )
return 0 ;
else
return _context . tunnelManager ( ) . getParticipatingCount ( ) ;
}
2010-01-18 14:57:03 +00:00
/** @since 0.7.10 */
public String getShareRatio ( ) {
if ( _context = = null )
return " 0 " ;
double sr = _context . tunnelManager ( ) . getShareRatio ( ) ;
DecimalFormat fmt = new DecimalFormat ( " ##0.00 " ) ;
return fmt . format ( sr ) ;
}
2004-07-24 02:06:07 +00:00
/ * *
* How lagged our job queue is over the last minute ( pretty printed with
* the units attached )
*
* /
public String getJobLag ( ) {
if ( _context = = null )
2011-08-22 19:09:09 +00:00
return " 0 " ;
2004-07-24 02:06:07 +00:00
2011-07-13 14:19:34 +00:00
RateStat rs = _context . statManager ( ) . getRate ( " jobQueue.jobLag " ) ;
if ( rs = = null )
2011-08-22 19:09:09 +00:00
return " 0 " ;
2011-07-13 14:19:34 +00:00
Rate lagRate = rs . getRate ( 60 * 1000 ) ;
2010-11-06 12:28:38 +00:00
return DataHelper . formatDuration2 ( ( long ) lagRate . getAverageValue ( ) ) ;
2004-07-24 02:06:07 +00:00
}
/ * *
* How long it takes us to pump out a message , averaged over the last minute
* ( pretty printed with the units attached )
*
* /
public String getMessageDelay ( ) {
if ( _context = = null )
2011-08-22 19:09:09 +00:00
return " 0 " ;
2004-07-24 02:06:07 +00:00
2010-11-06 12:28:38 +00:00
return DataHelper . formatDuration2 ( _context . throttle ( ) . getMessageDelay ( ) ) ;
2004-07-24 02:06:07 +00:00
}
/ * *
* How long it takes us to test our tunnels , averaged over the last 10 minutes
* ( pretty printed with the units attached )
*
* /
public String getTunnelLag ( ) {
if ( _context = = null )
2011-08-22 19:09:09 +00:00
return " 0 " ;
2004-07-24 02:06:07 +00:00
2010-11-06 12:28:38 +00:00
return DataHelper . formatDuration2 ( _context . throttle ( ) . getTunnelLag ( ) ) ;
2004-07-24 02:06:07 +00:00
}
2005-03-23 21:13:03 +00:00
2008-05-05 14:07:40 +00:00
public String getTunnelStatus ( ) {
if ( _context = = null )
return " " ;
return _context . throttle ( ) . getTunnelStatus ( ) ;
}
2006-04-08 06:15:43 +00:00
public String getInboundBacklog ( ) {
if ( _context = = null )
return " 0 " ;
return String . valueOf ( _context . tunnelManager ( ) . getInboundBuildQueueSize ( ) ) ;
}
2009-08-13 15:15:41 +00:00
/ * * * * * * *
2008-06-20 20:22:38 +00:00
public String getPRNGStatus ( ) {
Rate r = _context . statManager ( ) . getRate ( " prng.bufferWaitTime " ) . getRate ( 60 * 1000 ) ;
int use = ( int ) r . getLastEventCount ( ) ;
int i = ( int ) ( r . getAverageValue ( ) + 0 . 5 ) ;
if ( i < = 0 ) {
r = _context . statManager ( ) . getRate ( " prng.bufferWaitTime " ) . getRate ( 10 * 60 * 1000 ) ;
i = ( int ) ( r . getAverageValue ( ) + 0 . 5 ) ;
}
String rv = i + " / " ;
r = _context . statManager ( ) . getRate ( " prng.bufferFillTime " ) . getRate ( 60 * 1000 ) ;
i = ( int ) ( r . getAverageValue ( ) + 0 . 5 ) ;
if ( i < = 0 ) {
r = _context . statManager ( ) . getRate ( " prng.bufferFillTime " ) . getRate ( 10 * 60 * 1000 ) ;
i = ( int ) ( r . getAverageValue ( ) + 0 . 5 ) ;
}
rv = rv + i + " ms " ;
// margin == fill time / use time
if ( use > 0 & & i > 0 )
rv = rv + ' ' + ( 60 * 1000 / ( use * i ) ) + 'x' ;
return rv ;
}
2009-08-13 15:15:41 +00:00
* * * * * * * * /
2008-06-20 20:22:38 +00:00
2012-10-19 20:26:08 +00:00
private boolean updateAvailable ( ) {
Big refactor of the router console update subsystem, in preparation for
implementing out-of-console updaters like i2psnark.
- Add new update interfaces in net.i2p.update
- All update implementations moved to routerconsole update/
- Implement an UpdateManager that registers with the RouterContext
- UpdateManager handles multiple types of things to update
(router, plugins, news, ...) and methods of updating (HTTP, ...)
- UpdateManager maintains list of installed, downloaded, and available versions of everything
- Define Updaters that can check for a new version and/or download an item
- Individual Updaters register with the UpdateManager obtained from
I2PAppContext, identifying the type of update item and
update method they can handle.
- Updaters need only core libs, no router.jar or routerconsole access required.
- All checks and updates are initiated via the UpdateManager.
- All status on checks and updates in-progress or completed are
obtained from the UpdateManager. No more use of System properties
to broadcast update state.
- All update and checker tasks are intantiated on demand and threaded;
no more static references left over.
- Split out the Runners and Checkers from the Handlers and make the inheritance more sane.
- No more permanent NewsFetcher thread; run on the SimpleScheduler queue
and thread a checker task only to fetch the news.
- No more static NewsFetcher instance in routerconsole.
All helper methods that are still required are moved to NewsHelper.
The UpdateManager implements the policy for when to check and download.
All requests go through the UpdateManager.
For each update type, there's several parts:
- The xxxUpdateHandler implements the Updater
- The xxxUpdateChecker implements the UpdateTask for checking
- The xxxUpdateRunner implements the UpdateTask for downloading
New and moved classes:
web/ update/
---- -------
new ConsoleUpdateManager.java
new PluginUpdateChecker.java from PluginUpdateChecker
PluginUpdateChecker -> PluginUpdateHandler.java
PluginUpdateHandler.java -> PluginUpdateRunner
new UnsignedUpdateHandler.java
UnsignedUpdateHandler -> UnsignedUpdateRunner.java
new UnsignedUpdateChecker from NewsFetcher
UpdateHandler.java remains
new UpdateHandler.java
new UpdateRunner.java from UpdateHandler
move NewsHandler from NewsFetcher
new NewsFetcher
new NewsTimerTask
new DummyHandler
Initial checkin. Unfinished, untested, unpolished.
2012-06-18 22:09:45 +00:00
return NewsHelper . isUpdateAvailable ( ) ;
2005-03-24 01:19:52 +00:00
}
2009-02-24 22:59:59 +00:00
2012-10-19 20:26:08 +00:00
private boolean unsignedUpdateAvailable ( ) {
Big refactor of the router console update subsystem, in preparation for
implementing out-of-console updaters like i2psnark.
- Add new update interfaces in net.i2p.update
- All update implementations moved to routerconsole update/
- Implement an UpdateManager that registers with the RouterContext
- UpdateManager handles multiple types of things to update
(router, plugins, news, ...) and methods of updating (HTTP, ...)
- UpdateManager maintains list of installed, downloaded, and available versions of everything
- Define Updaters that can check for a new version and/or download an item
- Individual Updaters register with the UpdateManager obtained from
I2PAppContext, identifying the type of update item and
update method they can handle.
- Updaters need only core libs, no router.jar or routerconsole access required.
- All checks and updates are initiated via the UpdateManager.
- All status on checks and updates in-progress or completed are
obtained from the UpdateManager. No more use of System properties
to broadcast update state.
- All update and checker tasks are intantiated on demand and threaded;
no more static references left over.
- Split out the Runners and Checkers from the Handlers and make the inheritance more sane.
- No more permanent NewsFetcher thread; run on the SimpleScheduler queue
and thread a checker task only to fetch the news.
- No more static NewsFetcher instance in routerconsole.
All helper methods that are still required are moved to NewsHelper.
The UpdateManager implements the policy for when to check and download.
All requests go through the UpdateManager.
For each update type, there's several parts:
- The xxxUpdateHandler implements the Updater
- The xxxUpdateChecker implements the UpdateTask for checking
- The xxxUpdateRunner implements the UpdateTask for downloading
New and moved classes:
web/ update/
---- -------
new ConsoleUpdateManager.java
new PluginUpdateChecker.java from PluginUpdateChecker
PluginUpdateChecker -> PluginUpdateHandler.java
PluginUpdateHandler.java -> PluginUpdateRunner
new UnsignedUpdateHandler.java
UnsignedUpdateHandler -> UnsignedUpdateRunner.java
new UnsignedUpdateChecker from NewsFetcher
UpdateHandler.java remains
new UpdateHandler.java
new UpdateRunner.java from UpdateHandler
move NewsHandler from NewsFetcher
new NewsFetcher
new NewsTimerTask
new DummyHandler
Initial checkin. Unfinished, untested, unpolished.
2012-06-18 22:09:45 +00:00
return NewsHelper . isUnsignedUpdateAvailable ( ) ;
2009-08-09 14:28:20 +00:00
}
2012-10-19 20:26:08 +00:00
private String getUpdateVersion ( ) {
Big refactor of the router console update subsystem, in preparation for
implementing out-of-console updaters like i2psnark.
- Add new update interfaces in net.i2p.update
- All update implementations moved to routerconsole update/
- Implement an UpdateManager that registers with the RouterContext
- UpdateManager handles multiple types of things to update
(router, plugins, news, ...) and methods of updating (HTTP, ...)
- UpdateManager maintains list of installed, downloaded, and available versions of everything
- Define Updaters that can check for a new version and/or download an item
- Individual Updaters register with the UpdateManager obtained from
I2PAppContext, identifying the type of update item and
update method they can handle.
- Updaters need only core libs, no router.jar or routerconsole access required.
- All checks and updates are initiated via the UpdateManager.
- All status on checks and updates in-progress or completed are
obtained from the UpdateManager. No more use of System properties
to broadcast update state.
- All update and checker tasks are intantiated on demand and threaded;
no more static references left over.
- Split out the Runners and Checkers from the Handlers and make the inheritance more sane.
- No more permanent NewsFetcher thread; run on the SimpleScheduler queue
and thread a checker task only to fetch the news.
- No more static NewsFetcher instance in routerconsole.
All helper methods that are still required are moved to NewsHelper.
The UpdateManager implements the policy for when to check and download.
All requests go through the UpdateManager.
For each update type, there's several parts:
- The xxxUpdateHandler implements the Updater
- The xxxUpdateChecker implements the UpdateTask for checking
- The xxxUpdateRunner implements the UpdateTask for downloading
New and moved classes:
web/ update/
---- -------
new ConsoleUpdateManager.java
new PluginUpdateChecker.java from PluginUpdateChecker
PluginUpdateChecker -> PluginUpdateHandler.java
PluginUpdateHandler.java -> PluginUpdateRunner
new UnsignedUpdateHandler.java
UnsignedUpdateHandler -> UnsignedUpdateRunner.java
new UnsignedUpdateChecker from NewsFetcher
UpdateHandler.java remains
new UpdateHandler.java
new UpdateRunner.java from UpdateHandler
move NewsHandler from NewsFetcher
new NewsFetcher
new NewsTimerTask
new DummyHandler
Initial checkin. Unfinished, untested, unpolished.
2012-06-18 22:09:45 +00:00
return NewsHelper . updateVersion ( ) ;
2009-08-09 14:28:20 +00:00
}
2012-10-19 20:26:08 +00:00
private String getUnsignedUpdateVersion ( ) {
Big refactor of the router console update subsystem, in preparation for
implementing out-of-console updaters like i2psnark.
- Add new update interfaces in net.i2p.update
- All update implementations moved to routerconsole update/
- Implement an UpdateManager that registers with the RouterContext
- UpdateManager handles multiple types of things to update
(router, plugins, news, ...) and methods of updating (HTTP, ...)
- UpdateManager maintains list of installed, downloaded, and available versions of everything
- Define Updaters that can check for a new version and/or download an item
- Individual Updaters register with the UpdateManager obtained from
I2PAppContext, identifying the type of update item and
update method they can handle.
- Updaters need only core libs, no router.jar or routerconsole access required.
- All checks and updates are initiated via the UpdateManager.
- All status on checks and updates in-progress or completed are
obtained from the UpdateManager. No more use of System properties
to broadcast update state.
- All update and checker tasks are intantiated on demand and threaded;
no more static references left over.
- Split out the Runners and Checkers from the Handlers and make the inheritance more sane.
- No more permanent NewsFetcher thread; run on the SimpleScheduler queue
and thread a checker task only to fetch the news.
- No more static NewsFetcher instance in routerconsole.
All helper methods that are still required are moved to NewsHelper.
The UpdateManager implements the policy for when to check and download.
All requests go through the UpdateManager.
For each update type, there's several parts:
- The xxxUpdateHandler implements the Updater
- The xxxUpdateChecker implements the UpdateTask for checking
- The xxxUpdateRunner implements the UpdateTask for downloading
New and moved classes:
web/ update/
---- -------
new ConsoleUpdateManager.java
new PluginUpdateChecker.java from PluginUpdateChecker
PluginUpdateChecker -> PluginUpdateHandler.java
PluginUpdateHandler.java -> PluginUpdateRunner
new UnsignedUpdateHandler.java
UnsignedUpdateHandler -> UnsignedUpdateRunner.java
new UnsignedUpdateChecker from NewsFetcher
UpdateHandler.java remains
new UpdateHandler.java
new UpdateRunner.java from UpdateHandler
move NewsHandler from NewsFetcher
new NewsFetcher
new NewsTimerTask
new DummyHandler
Initial checkin. Unfinished, untested, unpolished.
2012-06-18 22:09:45 +00:00
return NewsHelper . unsignedUpdateVersion ( ) ;
2009-08-09 14:28:20 +00:00
}
2009-10-19 13:49:47 +00:00
2012-01-21 15:27:58 +00:00
/ * *
* The update status and buttons
* @since 0 . 8 . 13 moved from SummaryBarRenderer
* /
public String getUpdateStatus ( ) {
StringBuilder buf = new StringBuilder ( 512 ) ;
// display all the time so we display the final failure message, and plugin update messages too
Big refactor of the router console update subsystem, in preparation for
implementing out-of-console updaters like i2psnark.
- Add new update interfaces in net.i2p.update
- All update implementations moved to routerconsole update/
- Implement an UpdateManager that registers with the RouterContext
- UpdateManager handles multiple types of things to update
(router, plugins, news, ...) and methods of updating (HTTP, ...)
- UpdateManager maintains list of installed, downloaded, and available versions of everything
- Define Updaters that can check for a new version and/or download an item
- Individual Updaters register with the UpdateManager obtained from
I2PAppContext, identifying the type of update item and
update method they can handle.
- Updaters need only core libs, no router.jar or routerconsole access required.
- All checks and updates are initiated via the UpdateManager.
- All status on checks and updates in-progress or completed are
obtained from the UpdateManager. No more use of System properties
to broadcast update state.
- All update and checker tasks are intantiated on demand and threaded;
no more static references left over.
- Split out the Runners and Checkers from the Handlers and make the inheritance more sane.
- No more permanent NewsFetcher thread; run on the SimpleScheduler queue
and thread a checker task only to fetch the news.
- No more static NewsFetcher instance in routerconsole.
All helper methods that are still required are moved to NewsHelper.
The UpdateManager implements the policy for when to check and download.
All requests go through the UpdateManager.
For each update type, there's several parts:
- The xxxUpdateHandler implements the Updater
- The xxxUpdateChecker implements the UpdateTask for checking
- The xxxUpdateRunner implements the UpdateTask for downloading
New and moved classes:
web/ update/
---- -------
new ConsoleUpdateManager.java
new PluginUpdateChecker.java from PluginUpdateChecker
PluginUpdateChecker -> PluginUpdateHandler.java
PluginUpdateHandler.java -> PluginUpdateRunner
new UnsignedUpdateHandler.java
UnsignedUpdateHandler -> UnsignedUpdateRunner.java
new UnsignedUpdateChecker from NewsFetcher
UpdateHandler.java remains
new UpdateHandler.java
new UpdateRunner.java from UpdateHandler
move NewsHandler from NewsFetcher
new NewsFetcher
new NewsTimerTask
new DummyHandler
Initial checkin. Unfinished, untested, unpolished.
2012-06-18 22:09:45 +00:00
String status = NewsHelper . getUpdateStatus ( ) ;
2012-10-22 20:25:01 +00:00
boolean needSpace = false ;
2012-01-21 15:27:58 +00:00
if ( status . length ( ) > 0 ) {
2012-06-11 05:32:53 +00:00
buf . append ( " <h4> " ) . append ( status ) . append ( " </h4> \ n " ) ;
2012-10-22 20:25:01 +00:00
needSpace = true ;
2012-01-21 15:27:58 +00:00
}
2012-10-19 20:26:08 +00:00
String dver = NewsHelper . updateVersionDownloaded ( ) ;
if ( dver = = null )
dver = NewsHelper . unsignedVersionDownloaded ( ) ;
if ( dver ! = null & &
! NewsHelper . isUpdateInProgress ( ) & &
! _context . router ( ) . gracefulShutdownInProgress ( ) ) {
2012-10-22 20:25:01 +00:00
if ( needSpace )
buf . append ( " <hr> " ) ;
else
needSpace = true ;
2012-10-19 20:26:08 +00:00
buf . append ( " <h4><b> " ) . append ( _ ( " Update downloaded " ) ) . append ( " <br> " ) ;
if ( _context . hasWrapper ( ) )
buf . append ( _ ( " Click Restart to install " ) ) ;
else
buf . append ( _ ( " Click Shutdown and restart to install " ) ) ;
buf . append ( ' ' ) . append ( _ ( " Version {0} " , dver ) ) ;
buf . append ( " </b></h4> " ) ;
}
2013-09-20 18:56:54 +00:00
boolean avail = updateAvailable ( ) ;
boolean unsignedAvail = unsignedUpdateAvailable ( ) ;
String constraint = avail ? NewsHelper . updateConstraint ( ) : null ;
if ( avail & & constraint ! = null & &
! NewsHelper . isUpdateInProgress ( ) & &
! _context . router ( ) . gracefulShutdownInProgress ( ) ) {
if ( needSpace )
buf . append ( " <hr> " ) ;
else
needSpace = true ;
buf . append ( " <h4><b> " ) . append ( _ ( " Update available " ) ) . append ( " :<br> " ) ;
buf . append ( _ ( " Version {0} " , getUpdateVersion ( ) ) ) . append ( " <br> " ) ;
2014-04-01 13:01:13 +00:00
buf . append ( constraint ) . append ( " </b></h4> " ) ;
2013-09-20 18:56:54 +00:00
avail = false ;
}
if ( ( avail | | unsignedAvail ) & &
2012-10-19 20:26:08 +00:00
! NewsHelper . isUpdateInProgress ( ) & &
! _context . router ( ) . gracefulShutdownInProgress ( ) & &
_context . portMapper ( ) . getPort ( PortMapper . SVC_HTTP_PROXY ) > 0 & & // assume using proxy for now
getAction ( ) = = null & &
getUpdateNonce ( ) = = null ) {
2012-10-22 20:25:01 +00:00
if ( needSpace )
buf . append ( " <hr> " ) ;
2012-01-21 15:27:58 +00:00
long nonce = _context . random ( ) . nextLong ( ) ;
String prev = System . getProperty ( " net.i2p.router.web.UpdateHandler.nonce " ) ;
if ( prev ! = null )
System . setProperty ( " net.i2p.router.web.UpdateHandler.noncePrev " , prev ) ;
System . setProperty ( " net.i2p.router.web.UpdateHandler.nonce " , nonce + " " ) ;
String uri = getRequestURI ( ) ;
buf . append ( " <form action= \" " ) . append ( uri ) . append ( " \" method= \" POST \" > \ n " ) ;
buf . append ( " <input type= \" hidden \" name= \" updateNonce \" value= \" " ) . append ( nonce ) . append ( " \" > \ n " ) ;
2013-09-20 18:56:54 +00:00
if ( avail ) {
2012-01-21 15:27:58 +00:00
buf . append ( " <button type= \" submit \" class= \" download \" name= \" updateAction \" value= \" signed \" > " )
// Note to translators: parameter is a version, e.g. "0.8.4"
. append ( _ ( " Download {0} Update " , getUpdateVersion ( ) ) )
. append ( " </button><br> \ n " ) ;
}
2013-09-20 18:56:54 +00:00
if ( unsignedAvail ) {
2012-01-21 15:27:58 +00:00
buf . append ( " <button type= \" submit \" class= \" download \" name= \" updateAction \" value= \" Unsigned \" > " )
// Note to translators: parameter is a date and time, e.g. "02-Mar 20:34 UTC"
// <br> is optional, to help the browser make the lines even in the button
// If the translation is shorter than the English, you should probably not include <br>
. append ( _ ( " Download Unsigned<br>Update {0} " , getUnsignedUpdateVersion ( ) ) )
. append ( " </button><br> \ n " ) ;
}
2012-06-11 05:32:53 +00:00
buf . append ( " </form> \ n " ) ;
2012-01-21 15:27:58 +00:00
}
return buf . toString ( ) ;
}
/ * *
* The restart status and buttons
* @since 0 . 8 . 13 moved from SummaryBarRenderer
* /
public String getRestartStatus ( ) {
return ConfigRestartBean . renderStatus ( getRequestURI ( ) , getAction ( ) , getConsoleNonce ( ) ) ;
}
2012-01-25 15:01:19 +00:00
/ * *
* The firewall status and reseed status / buttons
* @since 0 . 9 moved from SummaryBarRenderer
* /
public String getFirewallAndReseedStatus ( ) {
StringBuilder buf = new StringBuilder ( 256 ) ;
if ( showFirewallWarning ( ) ) {
buf . append ( " <h4><a href= \" /confignet \" target= \" _top \" title= \" " )
. append ( _ ( " Help with firewall configuration " ) )
. append ( " \" > " )
. append ( _ ( " Check network connection and NAT/firewall " ) )
. append ( " </a></h4> " ) ;
}
2012-03-22 19:47:44 +00:00
boolean reseedInProgress = _context . netDb ( ) . reseedChecker ( ) . inProgress ( ) ;
2012-01-25 15:01:19 +00:00
// If showing the reseed link is allowed
if ( allowReseed ( ) ) {
if ( reseedInProgress ) {
// While reseed occurring, show status message instead
2012-03-22 19:47:44 +00:00
buf . append ( " <i> " ) . append ( _context . netDb ( ) . reseedChecker ( ) . getStatus ( ) ) . append ( " </i><br> " ) ;
2012-01-25 15:01:19 +00:00
} else {
// While no reseed occurring, show reseed link
long nonce = _context . random ( ) . nextLong ( ) ;
String prev = System . getProperty ( " net.i2p.router.web.ReseedHandler.nonce " ) ;
if ( prev ! = null ) System . setProperty ( " net.i2p.router.web.ReseedHandler.noncePrev " , prev ) ;
System . setProperty ( " net.i2p.router.web.ReseedHandler.nonce " , nonce + " " ) ;
String uri = getRequestURI ( ) ;
buf . append ( " <p><form action= \" " ) . append ( uri ) . append ( " \" method= \" POST \" > \ n " ) ;
buf . append ( " <input type= \" hidden \" name= \" reseedNonce \" value= \" " ) . append ( nonce ) . append ( " \" > \ n " ) ;
buf . append ( " <button type= \" submit \" class= \" reload \" value= \" Reseed \" > " ) . append ( _ ( " Reseed " ) ) . append ( " </button></form></p> \ n " ) ;
}
}
// If a new reseed ain't running, and the last reseed had errors, show error message
if ( ! reseedInProgress ) {
2012-03-22 19:47:44 +00:00
String reseedErrorMessage = _context . netDb ( ) . reseedChecker ( ) . getError ( ) ;
2012-01-25 15:01:19 +00:00
if ( reseedErrorMessage . length ( ) > 0 ) {
buf . append ( " <i> " ) . append ( reseedErrorMessage ) . append ( " </i><br> " ) ;
}
}
if ( buf . length ( ) < = 0 )
return " " ;
return buf . toString ( ) ;
}
2012-06-05 12:44:17 +00:00
private NewsHelper _newshelper ;
public void storeNewsHelper ( NewsHelper n ) { _newshelper = n ; }
public NewsHelper getNewsHelper ( ) { return _newshelper ; }
2012-06-09 13:48:26 +00:00
public List < String > getSummaryBarSections ( String page ) {
2012-06-11 05:29:27 +00:00
String config = " " ;
2012-07-30 13:15:58 +00:00
if ( " home " . equals ( page ) ) {
2012-07-08 22:11:05 +00:00
config = _context . getProperty ( PROP_SUMMARYBAR + page , DEFAULT_MINIMAL ) ;
2012-07-30 13:15:58 +00:00
} else {
config = _context . getProperty ( PROP_SUMMARYBAR + page ) ;
2012-06-11 05:29:27 +00:00
if ( config = = null )
2012-07-08 22:11:05 +00:00
config = _context . getProperty ( PROP_SUMMARYBAR + " default " , DEFAULT_FULL ) ;
2012-07-30 13:15:58 +00:00
}
2012-06-07 04:42:52 +00:00
return Arrays . asList ( config . split ( " " + S ) ) ;
2012-06-05 07:36:24 +00:00
}
2012-06-09 13:48:26 +00:00
static void saveSummaryBarSections ( RouterContext ctx , String page , Map < Integer , String > sections ) {
2012-06-05 07:36:24 +00:00
StringBuilder buf = new StringBuilder ( 512 ) ;
2012-06-07 02:51:22 +00:00
for ( String section : sections . values ( ) )
buf . append ( section ) . append ( S ) ;
2012-06-09 13:48:26 +00:00
ctx . router ( ) . saveConfig ( PROP_SUMMARYBAR + page , buf . toString ( ) ) ;
2012-06-05 07:36:24 +00:00
}
2009-10-19 13:49:47 +00:00
/** output the summary bar to _out */
public void renderSummaryBar ( ) throws IOException {
SummaryBarRenderer renderer = new SummaryBarRenderer ( _context , this ) ;
renderer . renderSummaryHTML ( _out ) ;
}
/* below here is stuff we need to get from summarynoframe.jsp to SummaryBarRenderer */
private String _action ;
public void setAction ( String s ) { _action = s ; }
public String getAction ( ) { return _action ; }
private String _consoleNonce ;
public void setConsoleNonce ( String s ) { _consoleNonce = s ; }
public String getConsoleNonce ( ) { return _consoleNonce ; }
private String _updateNonce ;
public void setUpdateNonce ( String s ) { _updateNonce = s ; }
public String getUpdateNonce ( ) { return _updateNonce ; }
private String _requestURI ;
public void setRequestURI ( String s ) { _requestURI = s ; }
2012-11-05 17:17:31 +00:00
/ * *
* @return non - null ; " /home " if ( strangely ) not set by jsp
* /
public String getRequestURI ( ) {
return _requestURI ! = null ? _requestURI : " /home " ;
}
2012-06-07 02:51:22 +00:00
public String getConfigTable ( ) {
2012-06-07 04:42:52 +00:00
String [ ] allSections = SummaryBarRenderer . ALL_SECTIONS ;
2012-07-17 20:36:57 +00:00
Map < String , String > sectionNames = SummaryBarRenderer . SECTION_NAMES ;
2012-06-09 13:48:26 +00:00
List < String > sections = getSummaryBarSections ( " default " ) ;
2013-11-21 11:31:50 +00:00
TreeSet < String > sortedSections = new TreeSet < String > ( ) ;
2012-06-07 04:42:52 +00:00
for ( int i = 0 ; i < allSections . length ; i + + ) {
String section = allSections [ i ] ;
if ( ! sections . contains ( section ) )
sortedSections . add ( section ) ;
}
2012-07-10 11:42:20 +00:00
String theme = _context . getProperty ( CSSHelper . PROP_THEME_NAME , CSSHelper . DEFAULT_THEME ) ;
String imgPath = CSSHelper . BASE_THEME_PATH + theme + " /images/ " ;
2012-06-07 04:42:52 +00:00
StringBuilder buf = new StringBuilder ( 2048 ) ;
2012-07-10 22:48:59 +00:00
buf . append ( " <table class= \" sidebarconf \" ><tr><th> " )
2012-06-07 02:51:22 +00:00
. append ( _ ( " Remove " ) )
. append ( " </th><th> " )
. append ( _ ( " Name " ) )
2012-07-10 23:35:54 +00:00
. append ( " </th><th colspan= \" 2 \" > " )
. append ( _ ( " Order " ) )
2012-06-07 02:51:22 +00:00
. append ( " </th></tr> \ n " ) ;
2012-06-07 04:42:52 +00:00
for ( String section : sections ) {
int i = sections . indexOf ( section ) ;
2012-06-07 02:51:22 +00:00
buf . append ( " <tr><td align= \" center \" ><input type= \" checkbox \" class= \" optbox \" name= \" delete_ " )
. append ( i )
2012-07-10 23:35:54 +00:00
. append ( " \" ></td><td align= \" left \" > " )
2012-07-17 20:36:57 +00:00
. append ( _ ( sectionNames . get ( section ) ) )
2012-07-10 23:35:54 +00:00
. append ( " </td><td align= \" right \" ><input type= \" hidden \" name= \" order_ " )
2014-02-10 18:33:32 +00:00
. append ( i ) . append ( '_' ) . append ( section )
2012-06-07 02:51:22 +00:00
. append ( " \" value= \" " )
. append ( i )
2012-07-09 07:59:41 +00:00
. append ( " \" > " ) ;
if ( i > 0 ) {
2012-11-25 02:39:49 +00:00
buf . append ( " <button type= \" submit \" class= \" buttonTop \" name= \" action \" value= \" move_ " )
2012-07-09 07:59:41 +00:00
. append ( i )
2012-11-25 02:39:49 +00:00
. append ( " _top \" ><img alt= \" " )
2012-07-09 07:59:41 +00:00
. append ( _ ( " Top " ) )
2012-11-25 02:39:49 +00:00
. append ( " \" src= \" " + imgPath + " move_top.png \" /></button> " ) ;
buf . append ( " <button type= \" submit \" class= \" buttonUp \" name= \" action \" value= \" move_ " )
2012-07-09 07:59:41 +00:00
. append ( i )
2012-11-25 02:39:49 +00:00
. append ( " _up \" ><img alt= \" " )
2012-07-09 07:59:41 +00:00
. append ( _ ( " Up " ) )
2012-11-25 02:39:49 +00:00
. append ( " \" src= \" " + imgPath + " move_up.png \" /></button> " ) ;
2012-07-09 07:59:41 +00:00
}
2012-07-10 11:57:40 +00:00
buf . append ( " </td><td align= \" left \" > " ) ;
2012-07-09 07:59:41 +00:00
if ( i < sections . size ( ) - 1 ) {
2012-11-25 02:39:49 +00:00
buf . append ( " <button type= \" submit \" class= \" buttonDown \" name= \" action \" value= \" move_ " )
2012-07-09 07:59:41 +00:00
. append ( i )
2012-11-25 02:39:49 +00:00
. append ( " _down \" ><img alt= \" " )
2012-07-09 07:59:41 +00:00
. append ( _ ( " Down " ) )
2012-11-25 02:39:49 +00:00
. append ( " \" src= \" " + imgPath + " move_down.png \" /></button> " ) ;
buf . append ( " <button type= \" submit \" class= \" buttonBottom \" name= \" action \" value= \" move_ " )
2012-07-09 07:59:41 +00:00
. append ( i )
2012-11-25 02:39:49 +00:00
. append ( " _bottom \" ><img alt= \" " )
2012-07-09 07:59:41 +00:00
. append ( _ ( " Bottom " ) )
2012-11-25 02:39:49 +00:00
. append ( " \" src= \" " + imgPath + " move_bottom.png \" /></button> " ) ;
2012-07-09 07:59:41 +00:00
}
2012-07-10 23:35:54 +00:00
buf . append ( " </td></tr> \ n " ) ;
2012-06-07 02:51:22 +00:00
}
2012-07-11 21:20:35 +00:00
buf . append ( " <tr><td align= \" center \" > " +
" <input type= \" submit \" name= \" action \" class= \" delete \" value= \" " )
. append ( _ ( " Delete selected " ) )
. append ( " \" ></td><td align= \" left \" ><b> " )
. append ( _ ( " Add " ) ) . append ( " :</b> " +
2012-06-07 04:42:52 +00:00
" <select name= \" name \" > \ n " +
" <option value= \" \" selected= \" selected \" > " )
. append ( _ ( " Select a section to add " ) )
. append ( " </option> \ n " ) ;
for ( String s : sortedSections ) {
buf . append ( " <option value= \" " ) . append ( s ) . append ( " \" > " )
2012-07-17 20:36:57 +00:00
. append ( sectionNames . get ( s ) ) . append ( " </option> \ n " ) ;
2012-06-07 04:42:52 +00:00
}
2012-07-11 21:20:35 +00:00
buf . append ( " </select> \ n " +
" <input type= \" hidden \" name= \" order \" value= \" " )
2012-07-10 23:35:54 +00:00
. append ( sections . size ( ) )
2012-07-11 21:20:35 +00:00
. append ( " \" ></td> " +
" <td align= \" center \" colspan= \" 2 \" > " +
" <input type= \" submit \" name= \" action \" class= \" add \" value= \" " )
. append ( _ ( " Add item " ) )
2012-07-10 23:35:54 +00:00
. append ( " \" ></td></tr> " )
2012-06-07 04:42:52 +00:00
. append ( " </table> \ n " ) ;
2012-06-07 02:51:22 +00:00
return buf . toString ( ) ;
}
2005-12-09 08:05:44 +00:00
}