3 * Project Admin page to manage group's VHOST entries
5 * Portions Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
7 * Copyright 2014, Franck Villaume - TrivialDev
8 * http://fusionforge.org/
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once '../../env.inc.php';
27 require_once $gfcommon.'include/pre.php';
28 require_once $gfwww.'project/admin/project_admin_utils.php';
32 if (!forge_get_config('use_project_vhost')) {
36 $group_id = getIntFromRequest('group_id');
37 session_require_perm ('project_admin', $group_id) ;
39 $group = group_get_object($group_id);
41 if (!$group || !is_object($group)) {
42 exit_error(_('Error')._(':'), 'Error creating group object');
43 } elseif ($group->isError()) {
44 exit_error(_('Error')._(':'), $group->getErrorMessage());
47 if (getStringFromRequest('createvhost')) {
48 $vhost_name = getStringFromRequest('vhost_name');
50 $homedir = account_group_homedir($group->getUnixName());
51 $docdir = $homedir.'/htdocs/';
52 $cgidir = $homedir.'/cgi-bin/';
54 if (valid_hostname($vhost_name)) {
56 $res = db_query_params('INSERT INTO prweb_vhost(vhost_name, docdir, cgidir, group_id)
57 values ($1, $2, $3, $4)', array($vhost_name, $docdir, $cgidir, $group->getID()));
59 if (!$res || db_affected_rows($res) < 1) {
60 $error_msg = _('Cannot insert VHOST entry:').db_error();
62 $feedback = _('Virtual Host scheduled for creation.');
63 $group->addHistory('Added vhost '.$vhost_name.' ','');
68 $feedback .= sprintf(_('Not a valid hostname - %s'), $vhost_name);
74 if (getStringFromRequest('deletevhost')) {
75 $vhostid = getStringFromRequest('vhostid');
77 //schedule for deletion
79 $res = db_query_params ('
86 $row_vh = db_fetch_array($res);
88 $res = db_query_params ('
89 DELETE FROM prweb_vhost
96 if (!$res || db_affected_rows($res) < 1) {
97 $error_msg .= _('Could not delete VHOST entry:').db_error();
99 $feedback .= _('VHOST deleted');
100 $group->addHistory('Virtual Host '.$row_vh['vhost_name'].' Removed','');
106 project_admin_header(array('title'=>_('Virtual Host Management'),'group'=>$group->getID()));
108 print '<h2>' . _('Add New Virtual Host') . '</h2>';
111 printf(_('To add a new virtual host - simply point a <strong>CNAME</strong> for <em>yourhost.org</em> at <strong>%1$s.%2$s</strong>. %3$s does not currently host mail (i.e. cannot be an MX) or DNS</strong>.'), $group->getUnixName(), forge_get_config ('web_host'), forge_get_config ('forge_name'));
115 printf(_('Clicking on “Create” will schedule the creation of the Virtual Host. This will be synced to the project webservers - such that <em>yourhost.org</em> will display the material at <em>%1$s.%2$s</em>.'), $group->getUnixName(), forge_get_config ('web_host'));
120 <form name="new_vhost" action="<?php echo util_make_uri('/project/admin/?group_id='.$group->getID().'&createvhost=1'); ?>" method="post">
123 <td> <?php echo _('New Virtual Host <em>(e.g. vhost.org)</em>') ?> </td>
124 <td> <input type="text" size="15" maxlength="255" name="vhost_name" required="required" /> </td>
125 <td> <input type="submit" value="<?php echo _('Create') ?>" /> </td>
132 $res_db = db_query_params('
135 WHERE group_id=$1', array($group->getID()));
137 if (db_numrows($res_db) > 0) {
140 $title[]=_('Virtual Host');
141 $title[]=_('Operations');
142 echo $HTML->listTableTop($title);
143 while ($row_db = db_fetch_array($res_db)) {
145 $cells[][] = $row_db['vhost_name'];
146 $cells[][] = '[ <strong>'.util_make_link('/project/admin/?group_id='.$group->getID().'&vhostid='.$row_db['vhostid'].'&deletevhost=1', _('Delete')).'</strong>]';
147 echo $HTML->multiTableRow(array(), $cells);
149 echo $HTML->listTableBottom();
151 echo '<p>'._('No VHOSTs defined').'</p>';
154 project_admin_footer();