<?php

 $arContent = array();
 $arContent[] = array(
  'title' => 'RACHEL',
  'description' => '<b>R</b>emote <b>A</b>rea <b>C</b>ommunity <b>H</b>otspots for <b>E</b>ducation and <b>L</b>earning.  Includes science and math videos, subset of offline wikipedia, electronic textbooks, world literature ebooks, subset of One Laptop Per Child content, and Hesperian Health Guides. Video playback is supported on modern HTML5 web browsers.',
  'path' => 'rachel'
 );
 $arContent[] = array(
  'title' => 'Offline Wikipedia',
  'description' => 'Two libraries of offline Wikipedia content.',
  'port' => '8080',
  'path' => ''
 );
 $arContent[] = array(
  'title' => 'Khan Academy',
  'description' => 'Science and Math video lessions.',
  'path' => 'KhanAcademy'
 );

 $ip = get_ip("eth0");
 if ( ! strlen($ip) ) {
  $ip = get_ip("wlan0");
 }


function get_ip( $interface = "eth0" )
{
	$cmd = "/sbin/ifconfig $interface | grep 'inet ' | cut -d: -f2 | awk '{ print $1 }'";
	$ip = shell_exec($cmd);
	return ltrim(rtrim($ip));
} 

?>
<DOCTYPE html>
<html>
<head>
 <title>Kids on Computers - Shared Offline Content</title>
 <style>
  body { font-family: Helvetica, 'Nimbus Sans L', Arial, sans-serif; }
  table { margin: 1em; border-collapse: collapse; }
  td, th { vertical-align: top; text-align: left; padding: .3em; border: 1px #47c0f5 solid; }
  thead { background: #81d2f5; color: #ffffff; font-weight: 700; font-size: 14px; }
  tbody { background: #f9f9f9; }
  thead.header { vertical-align: top; background: #ffffff }
  tbody.header { background: #ffffff }
  td.header, th.header { vertical-align: top; padding: .3em; border: 0px; }
  h1 { margin-top: 2px; margin-bottom: 2px }
  h2 { margin-top: 2px; margin-bottom: 2px }
  h3 { margin-top: 1px; margin-bottom: 1px }
  a { font-size: 18px; color: #47c0f5; text-decoration: none }
  .rowheader { color: #ffffff; font-size: 20px; font-weight: 700 }
  .big { font-size: 145% }
 </style>
</head>

<body>

<center>
<table width='85%' align=center class=header border=0>
<tbody class=header>
<tr>
 <td class=header align=left valign=top>
  <h1>Shared Offline Content</h1>
  The computer you are accessing contains educational libraries to be shared on a local area network (LAN) or Wi-Fi. 
  <br />
  <br />
  <center>
   Server Address:<br />
   <a class=big href="http://<?php echo $ip ?>"><?php echo $ip ?></a>
  </center>
 </td>
 <td align=right valign=top>
  <a href="http://www.kidsoncomputers.org" target=_blank>
   <img src="kids_logo.png" alt="Kids on Computers" title="Kids on Computers"><br />
   www.kidsoncomputers.org
  </a>
</tr>
</table>

<hr width='90%'>

<table width='85%' align=center border=1>
<thead>
<tr>
 <th align=left width='60%'>
  <span class=rowHeader>Library</span><br />
  Details
 </th>
 <th align=left width='40%'>
  <span class=rowHeader>Location</span><br />
  Enter this address into a web browser on other computers, tablets, or smartphones
 </th>
</tr>
</thead>
<tbody>
<?php foreach( $arContent as $item ): ?>
<tr>
 <td>
  <b><?php echo $item['title'];?></b><br />
  <?php echo $item['description'];?>
 </td>
 <td nowrap>
  <?php $url = "http://" . $ip . ((isset($item['port']) && strlen($item['port'])) ? (":" . $item['port']) : "") . "/" . $item['path']; ?>
  <a href="<?php echo $url; ?>" target=_blank><?php echo $url; ?></a>
 </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>

</center>

</body>
</html>
