PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/sites/domain_view.php

https://github.com/hggh/cpves
PHP | 362 lines | 296 code | 31 blank | 35 comment | 70 complexity | 6f3fed4ff82e343332cff5a2fca7087e MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. /******************************************************************************
  3. * Copyright (C) 2006 Jonas Genannt <jonas.genannt@brachium-system.net>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. ******************************************************************************/
  19. if ( (isset($_SESSION['superadmin']) &&
  20. isset($_GET['did']) &&
  21. is_numeric($_GET['did']) &&
  22. $_SESSION['superadmin']=='1') || (
  23. isset($_SESSION['admin']) &&
  24. $_SESSION['admin']=='1' &&
  25. isset($_GET['did']) &&
  26. is_numeric($_GET['did']) &&
  27. $access_domain ) )
  28. {
  29. //Enable or Disable EMAIL BEGIN
  30. if (isset($_GET['eid']) && is_numeric($_GET['eid']) && isset($_GET['state']) && isset($_GET['type']) )
  31. {
  32. if ($_GET['type'] == "catchall" && $_GET['state'] == "delete")
  33. { // loesche den catchall
  34. $sql=sprintf("DELETE FROM forwardings WHERE id='%s' AND efrom REGEXP '^@'",
  35. $db->escapeSimple($_GET['eid']));
  36. $result=&$db->query($sql);
  37. }
  38. if ($_GET['type'] == "email")
  39. {
  40. $table="users";
  41. $sql=sprintf("SELECT email FROM users WHERE id='%s'",
  42. $db->escapeSimple($_GET['eid']));
  43. $result=&$db->query($sql);
  44. $mail=$result->fetchrow(DB_FETCHMODE_ASSOC);
  45. $email=$mail['email'];
  46. }
  47. elseif ($_GET['type'] == "forward")
  48. {
  49. $table="forwardings";
  50. $sql=sprintf("SELECT * FROM forwardings WHERE id='%s'",
  51. $db->escapeSimple($_GET['eid']));
  52. $result=&$db->query($sql);
  53. $mail=$result->fetchrow(DB_FETCHMODE_ASSOC);
  54. $email=$mail['efrom'];
  55. }
  56. elseif ($_GET['type'] == 'list')
  57. {
  58. $table = 'lists';
  59. $sql = sprintf("SELECT address FROM lists WHERE id = %d",
  60. $db->escapeSimple($_GET['eid']));
  61. $res = &$db->query($sql);
  62. $row = $res->fetchrow(DB_FETCHMODE_ASSOC);
  63. $email = $row['address'];
  64. }
  65. if ($_GET['state']=='disable')
  66. {
  67. $sql=sprintf("UPDATE %s SET ACCESS='0' WHERE id='%s'",
  68. $table,
  69. $db->escapeSimple($_GET['eid']));
  70. }
  71. else if ($_GET['state']=='enable')
  72. {
  73. $sql=sprintf("UPDATE %s SET ACCESS='1' WHERE id='%s'",
  74. $table,
  75. $db->escapeSimple($_GET['eid']));
  76. }
  77. if (isset($email) && strpos($email, 'postmaster') === false)
  78. {
  79. $result=&$db->query($sql);
  80. if (!$result)
  81. {
  82. echo "ERROR! Something went wrong!";
  83. }
  84. }
  85. else
  86. {
  87. $smarty->assign('error_msg','y');
  88. $smarty->assign('if_error_postmaster' , 'y');
  89. }
  90. }
  91. //ENABLE or DISABLE EMAIL
  92. //Whitelist add:
  93. if (isset($_POST['sa_whitelist_data_add_submit']) && ($_SESSION['spamassassin']==1||$_SESSION['superadmin']== '1') ) {
  94. if (!isset($_POST['sa_whitelist_data_add']) || empty($_POST['sa_whitelist_data_add'])) {
  95. $smarty->assign('error_msg', 'y');
  96. $smarty->assign('sa_whitelist_data_add_empty', 'y');
  97. }
  98. elseif (check_whitelist_addr($_POST['sa_whitelist_data_add'])== 0) {
  99. $smarty->assign('error_msg', 'y');
  100. $smarty->assign('sa_whitelist_data_add_wrong', 'y');
  101. }
  102. else {
  103. $addr=trim(strtolower($_POST['sa_whitelist_data_add']));
  104. $sql=sprintf("INSERT INTO sa_wb_listing SET domainid='%s',email='0',sa_from='%s',type='1'",
  105. $db->escapeSimple($_GET['did']),
  106. $db->escapeSimple($addr));
  107. $result=&$db->query($sql);
  108. }
  109. }
  110. //Whitelist add (END)
  111. //Whitelist del:
  112. if (isset($_POST['sa_whitelist_data_del']) && !empty($_POST['sa_whitelist_data'])) {
  113. foreach($_POST['sa_whitelist_data'] as $key) {
  114. $sql=sprintf("DELETE FROM sa_wb_listing WHERE domainid='%d' AND id='%d'",
  115. $db->escapeSimple($_GET['did']),
  116. $db->escapeSimple($key));
  117. $db->query($sql);
  118. unset($sql);
  119. }
  120. }
  121. //Whitelist del (END)
  122. if (isset($_SESSION['superadmin']) && $_SESSION['superadmin']=='1') {
  123. //change MAX_forwards in database:
  124. if (isset($_POST['max_forwards']) && is_numeric($_POST['max_forwards']) ) {
  125. $sql=sprintf("UPDATE domains SET max_forward='%d' WHERE id='%d'",
  126. $db->escapeSimple($_POST['max_forwards']),
  127. $db->escapeSimple($_GET['did']));
  128. $db->query($sql);
  129. }
  130. //change MAX_emailss in database:
  131. if (isset($_POST['max_emails']) && is_numeric($_POST['max_emails']) ) {
  132. $sql=sprintf("UPDATE domains SET max_email='%d' WHERE id='%d'",
  133. $db->escapeSimple($_POST['max_emails']),
  134. $db->escapeSimple($_GET['did']));
  135. $db->query($sql);
  136. }
  137. //Domain Notiz aendern:
  138. if (isset($_POST['dnote'])) {
  139. $sql=sprintf("UPDATE domains SET dnote='%s' WHERE id='%d'",
  140. $db->escapeSimple(clean_input(substr($_POST['dnote'],0,30))),
  141. $db->escapeSimple($_GET['did']));
  142. $db->query($sql);
  143. }
  144. } // superadmin END
  145. // del domain_forward from domains_forward
  146. if (isset($_GET['sub'])&& $_GET['sub']=="do_fwd" && isset($_GET['act']) && $_GET['act']=="del" &&
  147. isset($_GET['do_fwd_id']) && is_numeric($_GET['do_fwd_id']) && $_SESSION['superadmin']== '1') {
  148. $sql=sprintf("DELETE FROM domains_forward WHERE id='%s' AND fr_domain='%s'",
  149. $db->escapeSimple($_GET['do_fwd_id']),
  150. $db->escapeSimple($_GET['did']));
  151. $db->query($sql);
  152. }
  153. //Domain features veraendern ANFANG
  154. if (isset($_SESSION['superadmin']) && $_SESSION['superadmin']=='1' && isset($_GET['fstate'])&& isset($_GET['f']))
  155. {
  156. if ($_GET['f']=='spamassassin' && $_GET['f']==0) {
  157. change_domain_feature($_GET['did'],'bogofilter','0');
  158. change_domain_feature($_GET['did'],'spam_del','0');
  159. change_domain_feature($_GET['did'],'sa_wb_listing','0');
  160. change_domain_feature($_GET['did'],'sa_learn','0');
  161. }
  162. if ($_GET['f']=='bogofilter'
  163. && !check_domain_feature($_GET['did'], 'p_spamassassin')) {
  164. $smarty->assign('error_msg', 'y');
  165. $smarty->assign('if_error_sa_disabled_enable_bogofilter','y');
  166. }
  167. elseif ($_GET['f']=='spam_del'
  168. && !check_domain_feature($_GET['did'], 'p_spamassassin')) {
  169. $smarty->assign('error_msg', 'y');
  170. $smarty->assign('if_error_sa_disable_enable_spam_del', 'y');
  171. }
  172. elseif ($_GET['f']=='sa_wb_listing'
  173. && !check_domain_feature($_GET['did'], 'p_spamassassin')) {
  174. $smarty->assign('error_msg', 'y');
  175. $smarty->assign('if_error_sa_disable_enable_sa_wb_listing', 'y');
  176. }
  177. elseif($_GET['f']=='sa_learn'
  178. && !check_domain_feature($_GET['did'], 'p_spamassassin')) {
  179. $smarty->assign('error_msg', 'y');
  180. $smarty->assign('if_error_sa_disable_enable_sa_learn', 'y');
  181. }
  182. else {
  183. if ($_GET['f'] == 'check_polw' && $config['recipient_classes_polw']==0) {
  184. }
  185. elseif($_GET['f'] == 'check_grey' && $config['recipient_classes_grey']==0) {
  186. }
  187. else {
  188. change_domain_feature($_GET['did'],$_GET['f'],$_GET['fstate']);
  189. }
  190. }
  191. }
  192. // Domain feature veraendern ENDE
  193. $sql=sprintf("SELECT * FROM domains WHERE id='%s' LIMIT 1",
  194. $db->escapeSimple($_GET['did']));
  195. $result=&$db->query($sql);
  196. $data=$result->fetchrow(DB_FETCHMODE_ASSOC);
  197. $smarty->assign('dnsname', $data['dnsname']);
  198. $smarty->assign('domain', $data);
  199. $smarty->assign('max_emails', $data['max_email']);
  200. $smarty->assign('max_fwd', $data['max_forward']);
  201. $smarty->assign('emails', get_forem_domain($_GET['did'],'users', $db));
  202. $smarty->assign('forwardings', get_forem_domain($_GET['did'],'forwardings', $db));
  203. //get forward domain
  204. if (do_fwd_get_fwd_domain($_GET['did'])== false) {
  205. $smarty->assign('domain_fwd',0);
  206. }
  207. else {
  208. $smarty->assign('domain_fwd', do_fwd_get_fwd_domain($_GET['did']));
  209. }
  210. // get points domains
  211. $sql=sprintf("SELECT a.fr_domain,b.dnsname FROM domains_forward AS a LEFT JOIN domains AS b ON b.id=a.fr_domain WHERE a.to_domain='%s' ORDER BY b.dnsname",
  212. $db->escapeSimple($_GET['did']));
  213. $result=&$db->query($sql);
  214. if ($result->numRows()>0) {
  215. $smarty->assign('domains_points_to_me',1);
  216. $table_domain_points=array();
  217. while($data=$result->fetchrow(DB_FETCHMODE_ASSOC)) {
  218. array_push($table_domain_points, array(
  219. 'fr_domain' => $data['fr_domain'],
  220. 'fr_domain_name' => $data['dnsname']));
  221. }
  222. $smarty->assign('table_domain_points',$table_domain_points);
  223. } else {
  224. $smarty->assign('domains_points_to_me',0);
  225. }
  226. //FIXME: deleted email addresses!!!
  227. $sql=sprintf("SELECT email,id,access,mb_size FROM users WHERE domainid='%s' AND enew!='0' ORDER BY email",
  228. $db->escapeSimple($_GET['did']));
  229. $result=&$db->query($sql);
  230. $table_email = array();
  231. while($data=$result->fetchrow(DB_FETCHMODE_ASSOC))
  232. {
  233. $autoresponder=0;
  234. $sql=sprintf("SELECT id FROM autoresponder WHERE email='%d' AND active='y'",
  235. $db->escapeSimple($data['id']));
  236. $res=&$db->query($sql);
  237. if ($res->numRows()== 1)
  238. {
  239. $autoresponder=1;
  240. }
  241. array_push($table_email, array(
  242. 'id' => $data['id'],
  243. 'did' => $_GET['did'],
  244. 'email' =>$data['email'],
  245. 'access' =>$data['access'],
  246. 'mb_size' => mailbox_size_human($data['mb_size']),
  247. 'autoresponder' => $autoresponder) );
  248. } //ENDE WHILE eMails
  249. $sql=sprintf("SELECT * FROM forwardings WHERE domainid='%s' ORDER BY efrom",
  250. $db->escapeSimple($_GET['did']));
  251. $result=&$db->query($sql);
  252. echo mysql_error();
  253. $table_forward = array();
  254. while($data=$result->fetchrow(DB_FETCHMODE_ASSOC))
  255. {
  256. if (!ereg('^@',$data['efrom'])) //show no @catchall
  257. {
  258. array_push($table_forward, array(
  259. 'id' => $data['id'],
  260. 'did' => $_GET['did'],
  261. 'from' =>$data['efrom'],
  262. 'to' => get_first_forward($data['eto']),
  263. 'if_multif' => check_multi_forward($data['eto']),
  264. 'access' =>$data['access']));
  265. }
  266. } //ENDE WHILE forward
  267. if ($config['mailinglists'] == '1') { //Run ML-Code only ==1
  268. $sql = sprintf("SELECT id,COUNT(*) as num FROM list_recp GROUP BY id",
  269. $db->escapeSimple($_GET['did']));
  270. $res = &$db->query($sql);
  271. $list_recps = array();
  272. while( $row = $res->fetchrow(DB_FETCHMODE_ASSOC) ) {
  273. $list_recps[$row['id']] = $row['num'];
  274. }
  275. $sql = sprintf("SELECT * FROM lists WHERE domainid = %d ORDER BY address",
  276. $db->escapeSimple($_GET['did']));
  277. $res = &$db->query($sql);
  278. $table_list = array();
  279. while( $row = $res->fetchrow(DB_FETCHMODE_ASSOC) ) {
  280. if( isset($list_recps[$row['id']]) ) $recps = $list_recps[$row['id']]; else $recps = 0;
  281. array_push($table_list, array(
  282. 'id' => $row['id'],
  283. 'domain'=> $row['domainid'],
  284. 'address' => $row['address'],
  285. 'access' => $row['access'],
  286. 'public' => $row['public'],
  287. 'recps' => $recps
  288. )
  289. );
  290. }
  291. } //Run ML-Code only == 1
  292. //look at catchall `efrom` REGEXP '^@'
  293. $sql=sprintf("SELECT eto,id,access FROM forwardings WHERE domainid='%d' AND efrom REGEXP '^@'",
  294. $db->escapeSimple($_GET['did']));
  295. $result=&$db->query($sql);
  296. if ($result->numRows()==1) {
  297. $data=$result->fetchrow(DB_FETCHMODE_ASSOC);
  298. $smarty->assign('if_catchall' , 'y');
  299. $smarty->assign('catchall_to',$data['eto'] );
  300. $smarty->assign('catchall_id',$data['id'] );
  301. $smarty->assign('catchall_access',$data['access'] );
  302. }
  303. else {
  304. $smarty->assign('if_catchall' , 'n');
  305. }
  306. //get Spamfilter whitelist
  307. if ($_SESSION['spamassassin']==1 ||$_SESSION['superadmin'] == '1') {
  308. $sql=sprintf("SELECT id,sa_from FROM sa_wb_listing WHERE domainid='%s' ORDER BY sa_from",
  309. $db->escapeSimple($_GET['did']));
  310. $result=&$db->query($sql);
  311. $table_sa_whitelist=array();
  312. while($row=$result->fetchrow(DB_FETCHMODE_ASSOC)) {
  313. array_push($table_sa_whitelist,array(
  314. 'id' => $row['id'],
  315. 'sa_from' => $row['sa_from']));
  316. }
  317. $smarty->assign('table_sa_whitelist',$table_sa_whitelist);
  318. }
  319. //get Spamfilter whitelist END
  320. }//Access OK
  321. else
  322. {
  323. $access_domain=false;
  324. }
  325. $smarty->assign('access_domain', $access_domain);
  326. $smarty->assign('did',$_GET['did']);
  327. $smarty->assign('table_email', $table_email);
  328. $smarty->assign('table_list', $table_list);
  329. $smarty->assign('table_forward', $table_forward);
  330. $smarty->assign('template','domain_view.tpl');
  331. ?>