Location: PHPKode > projects > XMail PHP Admin Interface (XPAI) > xpai/includes/domainadd.php
<?php
if (!$in_xpai)
  die;

if (!isset($postmaster_users))
  $postmaster_users = array("postmaster");

if ($_SESSION['loginstatus'] == $login_level['LoginSuperuser'])
{
  $javahelp = "javascript:help('no_help.html','530','550')";

  echo "<h1><a href=\"javascript:help('xpai_help.html#domainadd','".$helpwidth."','".$helpheight."')\"><img src='gfx/ico_help.png' alt='Help' border='0'></a>&nbsp;&nbsp;";
  echo "Create new mail domain</h1>";
  if (!isset($_REQUEST['Go']))
  {
?>

    <form name='frmNewDomain' action='main.php' method='post'>
      <input type='hidden' name='action' value='domainadd'>
      <input type='hidden' name='Go' value='true'>
      <table border='0' class='tbl'>
        <tr>
          <td>&nbsp;</td>
          <td><strong>Domain Name:<strong></td>
<?php
          if ((isset($_REQUEST['redo_domainadd']) && $_REQUEST['redo_domainadd'] == true))
            echo "<td><input type='text' name='edit_domain' size='30' style='width: 400px;' value='".$_REQUEST['dom_addname']."' tabindex='1'>></td>";
          else
            echo "<td><input type='text' name='edit_domain' size='30' style='width: 400px;' tabindex='1'></td>";
?>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><strong>Postmaster password:</strong></td>
          <td><input type='password' name='password1' size='30' style='width: 400px;' tabindex='2'></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><strong>Postmaster password (repeat):</strong></td>
          <td><input type='password' name='password2' size='30' style='width: 400px;' tabindex='3'></td>
        </tr>
<?php
  if (isset($enable_filters) && $enable_filters && count($filter_files)) {
    $first = true;
    foreach ($filter_files as $filter_key => $filter_value) {
?>
        <tr>
          <td>&nbsp;</td>
<?php
          if ($first) { 
            echo "<td><strong>Filter settings</strong></td>";
            $first = false;
          } else {
            echo "<td></td>";
          }
?>
          <td>
            &nbsp;<input type='checkbox' name='filter_<?php echo $filter_value; ?>'>
            <strong><?php echo $filter_key; ?><strong>
          </td>
        </tr>
<?php
     }
   }
?>        
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><input type='submit' value='submit'></td>
        </tr>
      </table>
    </form>
    <script language="JavaScript" type="text/javascript">
    <!--
      document.frmNewDomain.edit_domain.focus();
    //-->
    </script>
  
<?php
  } else {
    if (!strcmp(htmlentities($_REQUEST['edit_domain']), $_REQUEST['edit_domain']))
    {
       if (!strcmp($_REQUEST['password1'], $_REQUEST['password2']) && $_REQUEST['password1'] != "")
      {
         $_SESSION['edit_domain'] = $_REQUEST['edit_domain'];
        $multi_success = true;
         $restore_secondaries = false;
        if (isset($handle_secondaries) && $handle_secondaries)
        {
            foreach ($_SESSION['secondary-ip'] as $secondary)
           {
            if (!$mail_server->custdomset($_SESSION['edit_domain'], $_SESSION['secondary-mode']."\t".$_SESSION['secondary-dest'], $secondary['ip'], $secondary['port']))
             {
              $multi_success = false;
               $restore_secondaries = true;
              $secondary_error_source = $secondary['ip']." ".$secondary['port'];
              echo "Error adding domain <strong>".$_SESSION['edit_domain']."</strong> to secondary ".$secondary['ip'].".<br>";
               break;
            } else {
              echo "Added domain <strong>".$_SESSION['edit_domain']."</strong> to secondary ".$secondary['ip'].".<br>";
            } 
          }
          echo "<br>";
        } 
        if ($multi_success)
        {
          if ($mail_server->domainadd($_SESSION['edit_domain']))
          {
            echo "New domain <strong>".$_SESSION['edit_domain']."</strong> was created successfully.";
            echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
            foreach ($postmaster_users as $pm_user)
            {
              if ($mail_server->useradd($_SESSION['edit_domain'], $pm_user, $_REQUEST['password1'], 'U'))
              {
                echo "<br>New user <strong>".$pm_user."@".$_SESSION['edit_domain']."</strong> was created successfully.";
                echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
                $_SESSION['edit_user'] = $pm_user;
                if (isset($enable_filters) && $enable_filters && count($filter_files))
                {
                  foreach ($filter_files as $filter_value)
                  {
                    $filter_name = ereg_replace("\.", "_", $filter_value);
                    $mail_server->upd_filtersin($_SESSION['edit_user']."@".$_SESSION['edit_domain'], $filter_value, (isset($_REQUEST["filter_".$filter_name]) ? 1 : 0)); 
                  }
                  echo "<br>Filter settings for <strong>".$_SESSION['edit_user']."@".$_SESSION['edit_domain']."</strong> were set successfully.";
                  echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
                }
                if (isset($enable_IMAP) && $enable_IMAP && $IMAP_default_status)
                {
                   $mail_server->uservarsset($_SESSION['edit_domain'], $_SESSION['edit_user'], $IMAP_configword."\t1\n");
                  if ($mail_server->update_IMAP($_SESSION['edit_user']."@".$_SESSION['edit_domain'], $_SESSION['edit_user'], $_SESSION['edit_domain'], $_REQUEST['password1'], "CREATE", true, true, true))
                  {
                     echo "<br>IMAP settings for <strong>".$_SESSION['edit_user']."@".$_SESSION['edit_domain']."</strong> were set successfully.";
                    echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
                  } else {
                     echo "<br>IMAP settings for <strong>".$_SESSION['edit_user']."@".$_SESSION['edit_domain']."</strong> could not be set.";
                    echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
                  }
                } 
              } else {
                echo "<br>Could not add user <strong>".$pm_user."@".$_SESSION['edit_domain']."</strong>.<br>";
                echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
                $_SESSION['edit_user'] = "*";
              }
            }
          } else {
             $restore_secondaries = true;
            echo "Could not add domain <strong>".$_SESSION['edit_domain']."</strong>.<br>";
            echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
            $_SESSION['edit_domain'] = "*";
            $_SESSION['edit_user'] = "*";
          }
          $do_menu_update = true;
        }
        if (isset($handle_secondaries) && $handle_secondaries && $restore_secondaries)
         {
           foreach ($_SESSION['secondary-ip'] as $secondary)
          {
             $mail_server->custdomset($_SESSION['edit_domain'], "", $secondary['ip'], $secondary['port']);
          }
        } 
        if (isset($handle_secondaries) && $handle_secondaries && !$multi_success)
        {
          echo "Could not add domain <strong>".$_SESSION['edit_domain']."</strong>.<br>";
          echo "Error on secondary server <strong>".$secondary_error_source."</strong><br><br>";
          $_SESSION['edit_domain'] = "*";
          $_SESSION['edit_user'] = "*";
        } 
?>
        <form action='main.php' method='get'>
          <input type='hidden' name='action' value='domainlist'>
          <input type='submit' name='click' style='width: 50px;' value=' OK '>
        </form>
<?php
      } else {
        echo "Postmaster passwords are not identical or empty - creation failed.<br>";
        $_SESSION['edit_domain'] = '*';
?>
        <form action='main.php' method='post'>
          <input type='hidden' name='action' value='domainadd'>
          <input type='hidden' name='dom_addname' value='<?php echo $_REQUEST['edit_domain']; ?>'>
           <input type='hidden' name='redo_domainadd' value='true'>
           <input type='submit' name='click' style='width: 50px;' value=' OK '>
         </form>
<?php
       }
    } else {
      echo "Domain name contains illegal characters.<br>";
      $_SESSION['edit_domain'] = '*';      
?>
      <form action='main.php' method='post'>
        <input type='hidden' name='action' value='domainadd'>
        <input type='hidden' name='dom_addname' value='<?php echo $_REQUEST['edit_domain']; ?>'>
         <input type='hidden' name='redo_domainadd' value='true'>
         <input type='submit' name='click' style='width: 50px;' value=' OK '>
       </form>
<?php
    }
  }
} else {
  echo "<br><br><h2>Authorization failed to access this function!</h2><br><br>";
}
?>

Return current item: XMail PHP Admin Interface (XPAI)