steffen: server/kolab-webadmin/kolab-webadmin/www/admin/service index.php, NONE, 1.1 service.php, NONE, 1.1

cvs at intevation.de cvs at intevation.de
Mon May 17 17:24:29 CEST 2004


Author: steffen

Update of /kolabrepository/server/kolab-webadmin/kolab-webadmin/www/admin/service
In directory doto:/tmp/cvs-serv23429/kolab-webadmin/www/admin/service

Added Files:
	index.php service.php 
Log Message:
new webinterface for the kolab server

--- NEW FILE: index.php ---
<?php
require_once('admin/include/mysmarty.php');
require_once('admin/include/headers.php');
require_once('admin/include/authenticate.php');

$errors = array();

/**** Authentication etc. ***/
$sidx = 'service';

if( $auth->group() != 'admin') {
   array_push($errors, "Error: You don't have Permissions to access this Menu");
}

require_once('admin/include/menu.php');

/**** Submenu for current page ***/
$menuitems[$sidx]['selected'] = 'selected';

/**** Extract data from LDAP, fill forms, write back to LDAP ***/


function postvalue( $varname )
{
  if( isset($_REQUEST[$varname]) && $_REQUEST[$varname] == true ) return 'TRUE';
  else return 'FALSE';
}

function extract_ldap_values()
{
  global $ldap;
  global $pop3;
  global $pop3s;
  global $imap;
  global $imaps;
  global $sieve;
  global $ftp;
  global $http;
  global $amavis;

  // Get values from LDAP
  if (($result = ldap_read($ldap->connection, "k=kolab,".$_SESSION['base_dn'], '(objectclass=*)')) &&
	  ($entry = ldap_first_entry($ldap->connection, $result)) &&
	  ($attrs = ldap_get_attributes($ldap->connection, $entry))) {
	$pop3 = $attrs['cyrus-pop3'][0];
	$pop3s = $attrs['cyrus-pop3s'][0];
	$imap = $attrs['cyrus-imap'][0];
	$imaps = $attrs['cyrus-imaps'][0];
	$sieve = $attrs['cyrus-sieve'][0];
	$ftp = $attrs['proftpd-ftp'][0];
	$http = $attrs['apache-http'][0];
	$amavis = $attrs['postfix-enable-virus-scan'][0];
	ldap_free_result($result);
  }
}

function toboolstr( $b ) { return ( $b == 'TRUE' )?'true':'false'; }


extract_ldap_values();

// Write back to LDAP
if( $_REQUEST['submitservices'] ) {
  $attrs = array();
  if( postvalue( 'pop3' ) != $pop3 )   $attrs['cyrus-pop3'] = postvalue( 'pop3' );
  if( postvalue( 'pop3s' ) != $pop3s ) $attrs['cyrus-pop3s'] = postvalue( 'pop3s' );
  if( postvalue( 'imap' ) != $imap )   $attrs['cyrus-imap'] = postvalue( 'imap' );
  if( postvalue( 'imaps' ) != $imaps ) $attrs['cyrus-imaps'] = postvalue( 'imaps' );
  if( postvalue( 'sieve' ) != $sieve ) $attrs['cyrus-sieve'] = postvalue( 'sieve' );
  if( postvalue( 'ftp' ) != $ftp )     $attrs['proftpd-ftp'] = postvalue( 'ftp' );
  if( postvalue( 'http' ) != $http )    $attrs['apache-http'] = postvalue( 'http' );
  if( postvalue( 'amavis' ) != $amavis )  $attrs['postfix-enable-virus-scan'] = postvalue( 'amavis' );
  
  if( !($result = ldap_modify($ldap->connection, "k=kolab,".$_SESSION['base_dn'], $attrs)) ) {
	$errors[] = "LDAP Error: failed to modify kolab configuration object ".ldap_error($ldap->connection);
  }
}

// Fill in output form
extract_ldap_values();
$entries = array( array( 'service' => 'pop3', 'name'  => 'POP3 Service', 'enabled' => toboolstr( $pop3 ) ),
				  array( 'service' => 'pop3s', 'name' => 'POP3/SSL service (TCP port 995)', 'enabled' => toboolstr( $pop3s ) ),
				  array( 'service' => 'imap', 'name'  => 'IMAP Service', 'enabled' => toboolstr( $imap ) ),
				  array( 'service' => 'imaps', 'name' => 'IMAP/SSL Service (TCP port 993)', 'enabled' => toboolstr( $imaps ) ),
				  array( 'service' => 'sieve', 'name' => 'Sieve service (TCP port 2000)', 'enabled' => toboolstr( $sieve ) ),
				  array( 'service' => 'ftp', 'name'   => 'FTP FreeBusy Service', 'enabled' => toboolstr( $ftp ) ),
				  array( 'service' => 'http', 'name'  => 'HTTP FreeBusy Service', 'enabled' => toboolstr( $http ) ),
				  array( 'service' => 'amavis', 'name' => 'Amavis Virus Scanning', 'enabled' => toboolstr( $amavis ) ) );

/**** Insert into template and output ***/
$smarty = new MySmarty();
$smarty->assign( 'errors', $errors );
$smarty->assign( 'uid', $auth->uid() );
$smarty->assign( 'group', $auth->group() );
$smarty->assign( 'page_title', $menuitems[$sidx]['title'] );
$smarty->assign( 'entries', $entries );
$smarty->assign( 'menuitems', $menuitems );
$smarty->assign( 'submenuitems', 
				 array_key_exists('submenu', 
								  $menuitems[$sidx])?$menuitems[$sidx]['submenu']:array() );
$smarty->assign( 'maincontent', 'service.tpl' );
$smarty->display('page.tpl');

/*
  Local variables:
  mode: php
  indent-tabs-mode: t
  tab-width: 4
  buffer-file-coding-system: utf-8
  End:
 */
?>

--- NEW FILE: service.php ---
<?php
/*
 (c) 2003 Tassilo Erlewein <tassilo.erlewein at erfrakon.de>
 (c) 2003 Martin Konold <martin.konold at erfrakon.de>
 This program is Free Software under the GNU General Public License (>=v2).
 Read the file COPYING that comes with this packages for details.
*/
require_once('admin/include/authenticate.php');

// checks if this file is openend by another file
include_once("head.php");
This("service/");
Head();
?>
<div class="maintitle">Enable or Disable individual Services</div>
<div class="contentsimple">
<p>Using legacy services poses a security thread due to leakage of cleartext passwords, lack of authenticity and privacy.</p>
<p>The legacy Freebusy Support (FTP and HTTP) is only required for Outlook2000 clients. 
Under all other circumstances it is advised to use the secure <a href="http://www.webdav.org">WebDAV</a> 
over TLS instead (WebDAV is enabled by default and may not be deactivated).</p>
<p>Further details with regards to security considerations are available on the 
internet at the <a href="http://kolab.kde.org">Kolab</a> webserver.</p>
</div>
<?php

function debug ($a) {
//   print "debug: $a<br>\n";
}

debug("debug is on");
$errors = array();

// user authentication 
$uid = $auth->uid();
$bind_dn = $auth->dn();
$group = $auth->group();
$link = $ldap->connection;

if (!$errors && $group != "admin")
   array_push($errors, "Error: You don't have the required Permissions");

debug("givenuid=$uid, bind_dn=$bind_dn, group=$group");

$myself = $_SERVER['PHP_SELF'];

$allowed = array('TRUE','FALSE'); // implement LDAP Boolean Syntax
$attrs = array();
if (!empty($HTTP_GET_VARS['pop3'])) {
   $pop3 = urldecode($HTTP_GET_VARS['pop3']);
   if (in_array($pop3, $allowed)) $attrs['cyrus-pop3'] = $pop3; 
}

if (!empty($HTTP_GET_VARS['pop3s'])) {
   $pop3s = urldecode($HTTP_GET_VARS['pop3s']);
   if (in_array($pop3s, $allowed)) $attrs['cyrus-pop3s'] = $pop3s;
}

if (!empty($HTTP_GET_VARS['imaps'])) {
   $imaps = urldecode($HTTP_GET_VARS['imaps']);
   if (in_array($imaps, $allowed)) $attrs['cyrus-imaps'] = $imaps;
}

if (!empty($HTTP_GET_VARS['ftp'])) {
   $ftp= urldecode($HTTP_GET_VARS['ftp']);
   if (in_array($ftp, $allowed)) $attrs['proftpd-ftp'] = $ftp;
}

if (!empty($HTTP_GET_VARS['http'])) {
   $http= urldecode($HTTP_GET_VARS['http']);
   if (in_array($http, $allowed)) $attrs['apache-http'] = $http;
}

if (!empty($HTTP_GET_VARS['sieve'])) {
   $sieve = urldecode($HTTP_GET_VARS['sieve']);
   if (in_array($sieve, $allowed)) $attrs['cyrus-sieve'] = $sieve;
}

if( !empty($HTTP_GET_VARS['amavis']) ) {
  $amavis = urldecode($HTTP_GET_VARS['amavis']);
   if (in_array($amavis, $allowed)) $attrs['postfix-enable-virus-scan'] = $amavis;  
}

#array_push($errors, "http $http ftp $ftp imap $imap imaps $imaps pop3 $pop3 pop3s $pop3s sieve $sieve");

if ( ( isset($http) || isset($ftp) || isset($imaps) || 
       isset($pop3) || isset($pop3s) || isset($sieve) || isset($amavis) ) && 
       !($result = ldap_modify($link, "k=kolab,".$_SESSION['base_dn'], $attrs)) )
     array_push($errors, "LDAP Error: failed to modify kolab configuration object ".ldap_error($link));

if (($result = ldap_read($link, "k=kolab,".$_SESSION['base_dn'], '(objectclass=*)')) &&
    ($entry = ldap_first_entry($link, $result)) &&
    ($attrs = ldap_get_attributes($link, $entry))) {
   $pop3 = $attrs['cyrus-pop3'][0];
   $pop3s = $attrs['cyrus-pop3s'][0];
   $imap = $attrs['cyrus-imap'][0];
   $imaps = $attrs['cyrus-imaps'][0];
   $sieve = $attrs['cyrus-sieve'][0];
   $ftp = $attrs['proftpd-ftp'][0];
   $http = $attrs['apache-http'][0];
   $amavis = $attrs['postfix-enable-virus-scan'][0];
   ldap_free_result($result);
}
?>
<div class="contenttable">
<TABLE class="content" nosave>
<tr><th class="border"> Service </th><th class="border"> Status </th><th class="border"> Action </th></tr>
<tr><td class="content"> POP3 service </td><td class="content">
<? if ($pop3=="TRUE") 
   print("<span class=\"active\">active</span></td><td class=\"content\"><a href=\"index.php?pop3=FALSE\">disable pop3</a>"); 
   else print("<span class=\"inactive\">disabled</span></td><td class=\"content\"><a href=\"index.php?pop3=TRUE\">activate pop3</a>"); 
?></td></tr>

<tr><td class="content"> POP3/SSL service (TCP port 995) </td><td class="content"> 
<? if ($pop3s=="TRUE")
   print("<span class=\"active\">active</span></td><td class=\"content\"><a href=\"index.php?pop3s=FALSE\">disable pop3s</a>");
   else print("<span class=\"inactive\">disabled</span></td><td class=\"content\"><a href=\"index.php?pop3s=TRUE\">activate pop3s</a>");
?></td></tr>

<tr><td class="content"> IMAP service </td><td class="content">
<? if ($imap=="TRUE") 
   print("<span class=\"active\">active</span></td><td class=\"content\"><em class=\"unuseable\">(may not be deactivated)</em>");
?></td></tr>

<tr><td class="content"> IMAP/SSL service (TCP port 993) </td><td class="content">
<? if ($imaps=="TRUE")
   print("<span class=\"active\">active</span></td><td class=\"content\"><a href=\"index.php?imaps=FALSE\">disable imaps</a>");
   else print("<span class=\"inactive\">disabled</span></td><td class=\"content\"><a href=\"index.php?imaps=TRUE\">activate imaps</a>");
?></td></tr>

<tr><td class="content"> Sieve service (TCP port 2000) </td><td class="content">
<? if ($sieve=="TRUE") 
   print("<span class=\"active\">active</span></td><td class=\"content\"><a href=\"index.php?sieve=FALSE\">disable sieve</a>");
   else print("<span class=\"inactive\">disabled</span></td><td class=\"content\"><a href=\"index.php?sieve=TRUE\">activate sieve</a>");
?></td></tr>

<tr><td class="content"> FTP free-busy service </td><td class="content">
<? if ($ftp=="TRUE") 
   print("<span class=\"active\">active</span></td><td class=\"content\"><a href=\"index.php?ftp=FALSE\">disable ftp</a>");
   else print("<span class=\"inactive\">disabled</span></td><td class=\"content\"><a href=\"index.php?ftp=TRUE\">activate ftp</a>"); 
?></td></tr>

<tr><td class="content"> HTTP free-busy service </td><td class="content">
<? if ($http=="TRUE") 
   print("<span class=\"active\">active</span></td><td class=\"content\"><a href=\"index.php?http=FALSE\">disable http</a>");
   else print("<span class=\"inactive\">disabled</span></td><td class=\"content\"><a href=\"index.php?http=TRUE\">activate http</a>"); 
?>
</td></tr>

<tr><td class="content"> Amavis Virus Scanning </td><td class="content">
<? if ($amavis=="TRUE") 
   print("<span class=\"active\">active</span></td><td class=\"content\"><a href=\"index.php?amavis=FALSE\">disable amavis</a>");
   else print("<span class=\"inactive\">disabled</span></td><td class=\"content\"><a href=\"index.php?amavis=TRUE\">activate amavis</a>"); 
?>
</td></tr>

<!-- <tr><center><td> HTTPS service (TCP port 443) </td>
<td> <span style="color:#00FF00">active</span></td><td> (informational) </td></center></tr>

<tr><center><td> SMTP service (TCP port 25) </td>
<td> <span style="color:#00FF00">active</span></td><td> (informational) </td></center></tr>

<tr><center><td> LDAP service (TCP port 389) </td>
<td> <span style="color:#00FF00">active</span></td><td> (informational) </td></center></tr>
-->

</table>
</div>
<? echo "\n\n"; ?>
<div class="server">
<?
// server configuration
?>
<div class="maintitle">Server Settings</div>
<?

$hostname = "";
$mydomain = ""; 
$change = "";

// print_r($HTTP_GET_VARS);

if (isset($HTTP_GET_VARS['change'])) $change = trim(urldecode($HTTP_GET_VARS['change']));
if (isset($HTTP_GET_VARS['hostname'])) $hostname = trim(urldecode($HTTP_GET_VARS['hostname']));
if (isset($HTTP_GET_VARS['mydomain'])) $mydomain = trim(urldecode($HTTP_GET_VARS['mydomain']));

if ($group != "admin") array_push($errors, "Error: invalid permissions");

if (isset($_SESSION['base_dn'])) $base_dn = $_SESSION['base_dn'];
   else $base_dn = 'k=kolab' ;

$myself=$_SERVER['PHP_SELF'];

if (!$errors) {

   switch ($change) {
      case  "change":
         $attrs = array();
         if ($hostname) $attrs['fqhostname'][0] = $hostname; 
         if ($mydomain) {
             if (($result = ldap_read($link, "k=kolab,".$base_dn, "(objectclass=*)")) &&
                 ($entry = ldap_first_entry($link,$result)) &&
                 ($dattrs = ldap_get_attributes($link,$entry))) {
                $domain = $dattrs['postfix-mydomain'][0];
                ldap_free_result($result);
             }
             $attrs['postfix-mydomain'][0] = $mydomain;
             # now we go through the whole LDAP tree and change the email domain
             $result = ldap_search($link, $base_dn, "(|(mail=*)(alias=*))");
             if ($result) {
              $entry = ldap_first_entry($link, $result);
              if ($entry) {
                   $dn = ldap_get_dn($link,$entry);
                 do {
                    $newattrs = array();
                      $person = ldap_get_attributes($link,$entry);
                    if (!empty($person['mail']) && stristr($person['mail'][0], $domain)) {
                         $newattrs['mail'] =
                          substr($person['mail'][0], 0, strpos($person['mail'][0],'@'))."@".$mydomain;
                      }
                      if (!empty($person['alias'])) {
                      for ($i=0; $i < $person['alias']['count']; $i++) {
                         if (!empty($person['alias'][$i]) &&
                             stristr($person['alias'][$i], $domain)) {
                            $newattrs['alias'][$i] =
                               substr($person['alias'][$i], 0, strpos($person['alias'][$i],'@'))."@".$mydomain;
                         }
                        }
                      }
                      if (!ldap_modify($link, $dn, $newattrs))
                         array_push($errors, "LDAP Error: could not modify object $dn ".ldap_error($link));
                      $entry = ldap_next_entry($link, $entry);
                   } while ($entry);
                }
                ldap_free_result($result);
             }
         }

         if (!ldap_modify ($link,"k=kolab,".$_SESSION['base_dn'],$attrs)) 
            array_push($errors, "LDAP Error: failed to modify kolab config object ".ldap_error($link));
         break;
   }
  
   if (($result = ldap_read($link, "k=kolab,".$_SESSION['base_dn'], "(objectclass=*)")) &&
       ($entry = ldap_first_entry($link, $result)) &&
       ($attrs = ldap_get_attributes($link, $entry))) {
      $hostname = $attrs['fqhostname'][0]; 
      $mydomain = $attrs['postfix-mydomain'][0];
      ldap_free_result($result);
   } else array_push($errors, "LDAP Error: could not kolab configuration object ".ldap_error($link));

   ldap_close($link);
   print("<div class=\"contenttable\"><form method=\"GET\" action=\"$myself\">\n");
   print("<TABLE class=\"contentform\" nosave>\n");
   print("<tr><th> Attribute </th><th> Value </th><th> Comment </th></tr>\n");
   print("<tr><td> Hostname</td>\n");
   print("<td><input type=\"text\" name=\"hostname\" size=25 maxlength=80 value=\"$hostname\"></td>\n");
   print("<td> This hostname will be given by the Mail Server and the IMAP Server to the clients </td></tr>\n");
   print("<tr><td> E-Mail Domain</td>\n");
   print("<td><input type=\"text\" name=\"mydomain\" size=25 maxlength=80 value=\"$mydomain\"></td>\n");
   print("<td> Be advised that renaming the E-Mail Domain affects all E-Mail Addresses! </td></tr>\n");
   print("</table>\n");
   print("<input type=\"hidden\" name=\"change\" value=\"change\">\n");

   print("<table class=\"button\"><tr>\n"); 
   printf("<td><input type=\"image\" src=\"../pics/button_ok.png\" name=\"change\"></td>");
   printf("<td><a href=\"../index.php\"> <img src=\"../pics/button_cancel.png\" alt=\"cancel\"></a></td></tr>\n");
   printf("</table></form></div>\n");
}
print("</div");

if ($errors) {
   print("<TABLE style=\"errors\">\n");
   print("<TR><TD class=\"head\"> There were Errors : </TD></TR>\n");
   print("<TR><TD class=\"body\">\n");
   foreach ($errors as $message) print($message); 
   print("</TD></TR>\n");
   print("</TABLE>\n");
}

?>
<?  Foot();  ?>





More information about the commits mailing list