Alternc  latest
Alternc logiel libre pour l'hébergement
dom_edit.inc.php
Go to the documentation of this file.
1 <?php
2 /*
3  ----------------------------------------------------------------------
4  LICENSE
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License (GPL)
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  To read the license please visit http://www.gnu.org/copyleft/gpl.html
17  ----------------------------------------------------------------------
18 */
19 
20 /**
21  * Form to edit / add subdomains,
22  * using domaine_type table to show a synamic form.
23  *
24  * @copyright AlternC-Team 2000-2017 https://alternc.com/
25  */
26 
27 require_once("../class/config.php");
28 include_once("head.php");
29 
30 function sub_domains_edit($domain, $sub_domain_id=false) {
31  global $admin, $msg, $oldid, $isedit;
32 
33 $dom=new m_dom();
34 $dom->lock();
35 
36 $r=$dom->get_domain_all($domain);
37 /*
38 if (! empty($sub)) {
39  $sd=$dom->get_sub_domain_all($domain,$sub,$type,$value);
40 }
41 */
42 $sd=$dom->get_sub_domain_all($sub_domain_id);
43 
44 $type=$sd['type'];
45 $sub=$sd['name'];
46 
47 $dom->unlock();
48 
49 ?>
50 
51 <form action="dom_subdoedit.php" method="post" name="main" id="main">
52  <?php csrf_get(); ?>
53  <table class="dom-edit-table">
54  <tr>
55  <td>
56  <input type="hidden" name="domain" value="<?php ehe($domain) ?>" />
57  <input type="hidden" name="sub_domain_id" value="<?php echo intval($sub_domain_id); ?>" />
58  <input type="hidden" name="action" value="add" />
59  <?php
60  if ($isedit) {
61  __("Edit a subdomain:");
62  } else {
63  __("Create a subdomain:");
64  }
65 ?></td><td>
66  <input type="text" class="int" name="sub" style="text-align:right" value="<?php ehe($sub); ?>" size="22" id="sub" /><span class="int" id="newsubname">.<?php ehe($domain); ?></span></td>
67  <td></td>
68  </tr>
69  <?php
70  $first_advanced=true;
71  $lst_advanced=array();
72  foreach($dom->domains_type_lst() as $dt) {
73  // If this type is disabled AND it's not the type in use here, continue
74  if ( $dt['enable'] == 'NONE' && strtoupper($type)!=strtoupper($dt['name'])) continue ;
75  // If this type is only for ADMIN and i'm not an admin, continue (oldid is to check if we are an admin who take user identity)
76  if (( $dt['enable'] == 'ADMIN') && (! $admin->enabled and ! intval($oldid))) continue;
77 
78  if ( (! $r['dns'] ) and ($dt['need_dns']) ) continue;
79  $targval=(strtoupper($type)==strtoupper($dt['name']))?$sd['dest']:'';
80 
81  if ($dt['advanced']) {
82  $lst_advanced[]=$dt['name'];
83  if ($first_advanced) {
84  $first_advanced=false;
85  echo "<tr id='domtype_show' onClick=\"domtype_advanced_show();\"><td colspan='2'><a href=\"javascript:domtype_advanced_show();\"><b>+ "; __("Show advanced options"); echo "</b></a></td></tr>";
86  echo "<tr id='domtype_hide' onClick=\"domtype_advanced_hide();\" style='display:none'><td colspan='2'><a href=\"javascript:domtype_advanced_hide();\"><b>- "; __("Hide advanced options"); echo "</b></a></td></tr>";
87  }
88  }
89  ?>
90  <tr id="tr_<?php echo $dt['name']; ?>">
91  <td>
92  <input type="radio" id="r_<?php ehe($dt['name']); ?>" class="inc" name="type" value="<?php ehe($dt['name']); ?>" <?php cbox(strtoupper($type)==strtoupper($dt['name'])); ?> OnClick="getElementById('t_<?php ehe($dt['name']); ?>').focus();"/>
93  <label for="r_<?php ehe($dt['name']); ?>"><?php __($dt['description']); ?></label>
94  </td>
95  <td>
96  <?php
97 
98  switch ($dt['target']) {
99  case "DIRECTORY": ?>
100  <input type="text" class="int" name="t_<?php ehe($dt['name']); ?>" id="t_<?php ehe($dt['name']); ?>" value="<?php ehe($targval); ?>" size="28" onKeyPress="getElementById('r_<?php ehe($dt['name']); ?>').checked=true;" />
101  <?php display_browser( $targval , "t_".$dt['name'] );
102  break;
103  case "URL": ?>
104  <input type="text" class="int" name="t_<?php ehe($dt['name']); ?>" id="t_<?php ehe($dt['name']); ?>" value="<?php ehe( (empty($targval)?'http://':$targval) ); ?>" size="50" onKeyPress="getElementById('r_<?php ehe($dt['name']); ?>').checked=true;" />
105  <small><?php __("(enter an URL here)"); ?></small><?php
106  break;;
107  case 'IP':?>
108  <input type="text" class="int" name="t_<?php ehe($dt['name']); ?>" id="t_<?php ehe($dt['name']); ?>" value="<?php ehe($targval); ?>" size="16" onKeyPress="getElementById('r_<?php ehe($dt['name']); ?>').checked=true;" />
109  <small><?php __("(enter an IPv4 address, for example 192.168.1.2)"); ?></small><?php
110  break;
111  case 'IPV6':?>
112  <input type="text" class="int" name="t_<?php ehe($dt['name']); ?>" id="t_<?php ehe($dt['name']); ?>" value="<?php ehe($targval); ?>" size="32" onKeyPress="getElementById('r_<?php ehe($dt['name']); ?>').checked=true;" />
113  <small><?php __("(enter an IPv6 address, for example 2001:0910::0)"); ?></small><?php
114  break;
115  case 'TXT':?>
116  <input type="text" class="int" name="t_<?php ehe($dt['name']); ?>" id="t_<?php ehe($dt['name']); ?>" value="<?php ehe($targval);?>" size="32" onKeyPress="getElementById('r_<?php ehe($dt['name']); ?>').checked=true;" />
117  <small><?php __("(enter a TXT content for this domain)"); ?></small><?php
118  break;
119  case 'DOMAIN':?>
120  <input type="text" class="int" name="t_<?php ehe($dt['name']); ?>" id="t_<?php ehe($dt['name']); ?>" value="<?php ehe($targval);?>" size="32" onKeyPress="getElementById('r_<?php ehe($dt['name']); ?>').checked=true;" />
121  <small><?php __("(enter a domain name or subdomain)"); ?></small><?php
122  break;
123  case "NONE":
124  default:
125  break;
126  } // switch ?>
127  </td>
128  <td>
129 <?php if ($dt['has_https_option']) { ?>
130 
131  <select class="inl" name="https_<?php ehe($dt['name']); ?>" id="https_<?php ehe($dt['name']); ?>">
132  <option value="http"<?php selected((strtoupper($type)==strtoupper($dt['name']) && $sd["https"]=="http") || false); ?>><?php __("HTTP Only (redirect HTTPS to HTTP)"); ?></option>
133  <option value="https"<?php selected((strtoupper($type)==strtoupper($dt['name']) && $sd["https"]=="https") || true); ?>><?php __("HTTPS Only (redirect HTTP to HTTPS)"); ?></option>
134  <option value="both"<?php selected((strtoupper($type)==strtoupper($dt['name']) && $sd["https"]=="both") || false); ?>><?php __("Both HTTP and HTTPS hosted at the same place"); ?></option>
135  </select>
136 <?php } ?>
137  </td>
138  </tr>
139  <?php } // foreach ?>
140 
141  <tr class="trbtn">
142  <td colspan="2"><button type="submit" class="inb ok" name="add" onclick='return check_type_selected();'><?php
143  if ($isedit) {
144  __("Edit this subdomain");
145 } else {
146  __("Add this subdomain");
147 }
148 ?></button>
149 <?php if ($isedit) { ?>
150  <button class="inb cancel" type="button" name="cancel" onclick="document.location = 'dom_edit.php?domain=<?php echo $domain; ?>'"><?php __("Cancel"); ?></button>
151 <?php } ?>
152 </td>
153  </tr>
154  </table>
155 </form>
156 
157 <script type="text/javascript">
158 
159 function check_type_selected() {
160  if ( $('input[name=type]:radio:checked').val() ) {
161  // there is a value
162  var ll = $('input[name=type]:radio:checked').val();
163  var tt = $('#t_'+ll);
164  if ( tt.length == 0 ) {
165  // this element do not exist, so OK
166  return true;
167  }
168  if ( tt.val() == '' ) {
169  alert("<?php __("Missing value for this sub-domain"); ?>");
170  return false;
171  }
172 
173  return true;
174  }
175  alert("<?php __("Please select a type for this sub-domain"); ?>");
176  return false;
177 }
178 
179 function domtype_advanced_hide() {
180  <?php foreach ($lst_advanced as $adv) echo "$(\"#tr_$adv\").hide();\n"?>
181  $("#domtype_show").show();
182  $("#domtype_hide").hide();
183 }
184 function domtype_advanced_show() {
185  <?php foreach ($lst_advanced as $adv) echo "$(\"#tr_$adv\").show();\n"?>
186  $("#domtype_show").hide();
187  $("#domtype_hide").show();
188 }
189 
190 <?php if (isset($type) && in_array($type, $lst_advanced) ) { // if it's an edit of an advanced option, we need to show the advanced options ?>
191  domtype_advanced_show();
192 <?php } else { ?>
193  domtype_advanced_hide();
194 <?php } // if advanced ?>
195 
196 </script>
197 <?php
198 } // sub_domains_edit
199 ?>
200 
$msg
Definition: bootstrap.php:75
$r
Definition: aws_add.php:75
Classe de gestion des domaines de l'hébergé.
Definition: m_dom.php:31
if(count($_POST) &&!defined("NOCSRF")) if(!defined('NOCHECK')) for($i=0; $i< count($classes); $i++) $oldid
Definition: config.php:203
sub_domains_edit($domain, $sub_domain_id=false)
Form to edit / add subdomains, using domaine_type table to show a synamic form.
$dt
Definition: dom_edit.php:133
$isedit
Definition: dom_edit.php:280
$domain
Definition: dom_import.php:36
$sub
ehe($str, $display=TRUE)
Echo the HTMLSpecialChars version of a value.
Definition: functions.php:647
selected($bool, $echo=TRUE)
ECHOes selected="selected" only if the parameter is true useful for checkboxes and radio buttons.
Definition: functions.php:366
__($str)
Definition: functions.php:404
display_browser($dir="", $caller="main.dir", $width=350, $height=450)
Show a button to select a folder on the server.
Definition: functions.php:941
cbox($test, $echo=true)
ECHOes checked="checked" only if the parameter is true useful for checkboxes and radio buttons.
Definition: functions.php:345
csrf_get($return=false)
Give a new CSRF uniq token for a form the session must be up since the CSRF is linked to the session ...
Definition: functions.php:1159
$dom
Definition: whois_test.php:10