8d3da69039fd501f0664b6cfcf9c4945c4ad8383
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php   1) <?php
modules/vmail/include/vmail.php   2) require_once('inc/base.php');
modules/vmail/include/vmail.php   3) require_once('inc/debug.php');
modules/vmail/include/vmail.php   4) 
bernd Bugfix: Funktion-Dopplung v...

bernd authored 17 years ago

modules/vmail/include/vmail.php   5) require_once('hasdomain.php');
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php   6) 
modules/vmail/include/vmail.php   7) function empty_account()
modules/vmail/include/vmail.php   8) {
modules/vmail/include/vmail.php   9) 	$account = array(
modules/vmail/include/vmail.php  10) 		'id' => NULL,
modules/vmail/include/vmail.php  11) 		'local' => '',
modules/vmail/include/vmail.php  12) 		'domain' => NULL,
bernd Neues VMail-Interface (funk...

bernd authored 16 years ago

modules/vmail/include/vmail.php  13) 		'password' => NULL,
bernd Spam- und viren nur noch ei...

bernd authored 17 years ago

modules/vmail/include/vmail.php  14) 		'spamfilter' => 'folder',
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php  15) 		'spamexpire' => 7,
bernd Anpassung auf neues Interface

bernd authored 16 years ago

modules/vmail/include/vmail.php  16) 		'forwards' => array()
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php  17) 		);
modules/vmail/include/vmail.php  18) 	return $account;
modules/vmail/include/vmail.php  19) 
modules/vmail/include/vmail.php  20) }
modules/vmail/include/vmail.php  21) 
bernd VMail-accounts können sich...

bernd authored 16 years ago

modules/vmail/include/vmail.php  22) function get_account_details($id, $checkuid = true)
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php  23) {
modules/vmail/include/vmail.php  24) 	$id = (int) $id;
modules/vmail/include/vmail.php  25) 	$uid = (int) $_SESSION['userinfo']['uid'];
bernd VMail-accounts können sich...

bernd authored 16 years ago

modules/vmail/include/vmail.php  26) 	$uid_check = ($checkuid ? "useraccount='{$uid}' AND " : "");
modules/vmail/include/vmail.php  27) 	$result = db_query("SELECT id, local, domain, password, spamfilter, forwards from mail.v_vmail_accounts WHERE {$uid_check}id={$id} LIMIT 1");
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php  28) 	if (mysql_num_rows($result) == 0)
modules/vmail/include/vmail.php  29) 		system_failure('Ungültige ID oder kein eigener Account');
bernd Anpassung auf neues Interface

bernd authored 16 years ago

modules/vmail/include/vmail.php  30) 	$acc = empty_account();
modules/vmail/include/vmail.php  31) 	$res = mysql_fetch_assoc($result);
modules/vmail/include/vmail.php  32) 	foreach ($res AS $key => $value) {
modules/vmail/include/vmail.php  33) 	  if ($key == 'forwards')
modules/vmail/include/vmail.php  34) 	    continue;
modules/vmail/include/vmail.php  35) 	  $acc[$key] = $value;
modules/vmail/include/vmail.php  36) 	}
modules/vmail/include/vmail.php  37) 	if ($acc['forwards'] > 0) {
modules/vmail/include/vmail.php  38) 	  $result = db_query("SELECT id, spamfilter, destination FROM mail.vmail_forward WHERE account={$acc['id']};");
modules/vmail/include/vmail.php  39) 	  while ($item = mysql_fetch_assoc($result)){
modules/vmail/include/vmail.php  40) 	    array_push($acc['forwards'], array("id" => $item['id'], 'spamfilter' => $item['spamfilter'], 'destination' => $item['destination']));
modules/vmail/include/vmail.php  41) 	  }
modules/vmail/include/vmail.php  42) 	}
modules/vmail/include/vmail.php  43) 	return $acc;
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php  44) }
modules/vmail/include/vmail.php  45) 
modules/vmail/include/vmail.php  46) function get_vmail_accounts()
modules/vmail/include/vmail.php  47) {
modules/vmail/include/vmail.php  48) 	$uid = (int) $_SESSION['userinfo']['uid'];
bernd Bugfixes

bernd authored 16 years ago

modules/vmail/include/vmail.php  49) 	$result = db_query("SELECT * from mail.v_vmail_accounts WHERE useraccount='{$uid}'");
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php  50) 	$ret = array();
modules/vmail/include/vmail.php  51) 	while ($line = mysql_fetch_assoc($result))
modules/vmail/include/vmail.php  52) 	{
modules/vmail/include/vmail.php  53) 		array_push($ret, $line);
modules/vmail/include/vmail.php  54) 	}
modules/vmail/include/vmail.php  55) 	DEBUG($ret);
modules/vmail/include/vmail.php  56) 	return $ret;
modules/vmail/include/vmail.php  57) }
modules/vmail/include/vmail.php  58) 
modules/vmail/include/vmail.php  59) 
modules/vmail/include/vmail.php  60) 
modules/vmail/include/vmail.php  61) function get_vmail_domains()
modules/vmail/include/vmail.php  62) {
modules/vmail/include/vmail.php  63) 	$uid = (int) $_SESSION['userinfo']['uid'];
modules/vmail/include/vmail.php  64) 	$result = db_query("SELECT id, domainname FROM mail.v_vmail_domains WHERE useraccount='{$uid}'");
modules/vmail/include/vmail.php  65) 	if (mysql_num_rows($result) == 0)
modules/vmail/include/vmail.php  66) 		system_failure('Sie haben keine Domains für virtuelle Mail-Verarbeitung');
modules/vmail/include/vmail.php  67) 	$ret = array();
modules/vmail/include/vmail.php  68) 	while ($tmp = mysql_fetch_object($result))
modules/vmail/include/vmail.php  69) 		array_push($ret, $tmp);
modules/vmail/include/vmail.php  70) 	return $ret;
modules/vmail/include/vmail.php  71) }
modules/vmail/include/vmail.php  72) 
modules/vmail/include/vmail.php  73) 
bernd VMail-accounts können sich...

bernd authored 16 years ago

modules/vmail/include/vmail.php  74) function find_account_id($accname)
modules/vmail/include/vmail.php  75) {
modules/vmail/include/vmail.php  76)   $accname = mysql_real_escape_string($accname);
modules/vmail/include/vmail.php  77)   DEBUG($accname);
modules/vmail/include/vmail.php  78)   $tmp = explode('@', $accname, 2);
modules/vmail/include/vmail.php  79)   DEBUG($tmp);
modules/vmail/include/vmail.php  80)   if (count($tmp) != 2)
modules/vmail/include/vmail.php  81)     system_failure("Der Account hat nicht die korrekte Syntax");
modules/vmail/include/vmail.php  82)   list( $local, $domainname) = $tmp;
modules/vmail/include/vmail.php  83) 
modules/vmail/include/vmail.php  84)   $result = db_query("SELECT id FROM mail.v_vmail_accounts WHERE local='{$local}' AND domainname='{$domainname}' LIMIT 1");
modules/vmail/include/vmail.php  85)   if (mysql_num_rows($result) == 0)
modules/vmail/include/vmail.php  86)     system_failure("Der Account konnte nicht gefunden werden");
modules/vmail/include/vmail.php  87)   $tmp = mysql_fetch_array($result);
modules/vmail/include/vmail.php  88)   return $tmp[0];
modules/vmail/include/vmail.php  89) }
modules/vmail/include/vmail.php  90) 
modules/vmail/include/vmail.php  91) 
modules/vmail/include/vmail.php  92) function change_vmail_password($accname, $newpass)
modules/vmail/include/vmail.php  93) {
modules/vmail/include/vmail.php  94)   $accid = find_account_id($accname);
modules/vmail/include/vmail.php  95)   $encpw = mysql_real_escape_string(encrypt_mail_password($newpass));
modules/vmail/include/vmail.php  96)   db_query("UPDATE mail.vmail_accounts SET password='{$encpw}' WHERE id={$accid} LIMIT 1;");
modules/vmail/include/vmail.php  97) }
modules/vmail/include/vmail.php  98) 
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php  99) 
modules/vmail/include/vmail.php 100) function domainselect($selected = NULL, $selectattribute = '')
modules/vmail/include/vmail.php 101) {
bernd Bugfix: Funktion-Dopplung v...

bernd authored 17 years ago

modules/vmail/include/vmail.php 102)   $domainlist = get_vmail_domains();
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 103)   $selected = (int) $selected;
modules/vmail/include/vmail.php 104) 
modules/vmail/include/vmail.php 105)   $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
modules/vmail/include/vmail.php 106)   foreach ($domainlist as $dom)
modules/vmail/include/vmail.php 107)   {
modules/vmail/include/vmail.php 108)     $s = ($selected == $dom->id) ? ' selected="selected" ': '';
modules/vmail/include/vmail.php 109)     $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->domainname}</option>\n";
modules/vmail/include/vmail.php 110)   }
modules/vmail/include/vmail.php 111)   $ret .= '</select>';
modules/vmail/include/vmail.php 112)   return $ret;
modules/vmail/include/vmail.php 113) }
modules/vmail/include/vmail.php 114) 
modules/vmail/include/vmail.php 115) 
modules/vmail/include/vmail.php 116) function encrypt_mail_password($pw)
modules/vmail/include/vmail.php 117) {
modules/vmail/include/vmail.php 118)   DEBUG("unencrypted PW: ".$pw);
modules/vmail/include/vmail.php 119)   require_once('inc/base.php');
modules/vmail/include/vmail.php 120)   $salt = random_string(8);
modules/vmail/include/vmail.php 121)   $encpw = crypt($pw, "\$1\${$salt}\$");
modules/vmail/include/vmail.php 122)   DEBUG("encrypted PW: ".$encpw);
modules/vmail/include/vmail.php 123)   return chop($encpw);
modules/vmail/include/vmail.php 124) 
modules/vmail/include/vmail.php 125) }
modules/vmail/include/vmail.php 126) 
modules/vmail/include/vmail.php 127) 
modules/vmail/include/vmail.php 128) 
modules/vmail/include/vmail.php 129) function save_vmail_account($account)
modules/vmail/include/vmail.php 130) {
modules/vmail/include/vmail.php 131)   $uid = (int) $_SESSION['userinfo']['uid'];
modules/vmail/include/vmail.php 132)   $id = $account['id'];
modules/vmail/include/vmail.php 133)   if ($id != NULL)
modules/vmail/include/vmail.php 134)   {
modules/vmail/include/vmail.php 135)     $id = (int) $id;
modules/vmail/include/vmail.php 136)     $oldaccount = get_account_details($id);
modules/vmail/include/vmail.php 137)     // Erzeugt einen system_error() wenn ID ungültig
modules/vmail/include/vmail.php 138)   }
modules/vmail/include/vmail.php 139)   // Ab hier ist $id sicher, entweder NULL oder eine gültige ID des aktuellen users
modules/vmail/include/vmail.php 140) 
modules/vmail/include/vmail.php 141)   $account['local'] = filter_input_username($account['local']);
modules/vmail/include/vmail.php 142)   if ($account['local'] == '')
modules/vmail/include/vmail.php 143)   {
modules/vmail/include/vmail.php 144)     input_error('Die E-Mail-Adresse braucht eine Angabe vor dem »@«!');
modules/vmail/include/vmail.php 145)     return false;
modules/vmail/include/vmail.php 146)   }
modules/vmail/include/vmail.php 147)   $account['domain'] = (int) $account['domain'];
modules/vmail/include/vmail.php 148)   $domainlist = get_vmail_domains();
modules/vmail/include/vmail.php 149)   $valid_domain = false;
bernd Benachrichtige vmail-userac...

bernd authored 17 years ago

modules/vmail/include/vmail.php 150)   $domainname = NULL;
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 151)   foreach ($domainlist as $dom)
modules/vmail/include/vmail.php 152)   {
modules/vmail/include/vmail.php 153)     if ($dom->id == $account['domain'])
modules/vmail/include/vmail.php 154)     {
bernd Benachrichtige vmail-userac...

bernd authored 17 years ago

modules/vmail/include/vmail.php 155)       $domainname = $dom->domainname;
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 156)       $valid_domain = true;
modules/vmail/include/vmail.php 157)       break;
modules/vmail/include/vmail.php 158)     }
modules/vmail/include/vmail.php 159)   }
modules/vmail/include/vmail.php 160)   if (($account['domain'] == 0) || (! $valid_domain))
modules/vmail/include/vmail.php 161)   {
modules/vmail/include/vmail.php 162)     input_error('Bitte wählen Sie eine Ihrer Domains aus!');
modules/vmail/include/vmail.php 163)     return false;
modules/vmail/include/vmail.php 164)   }
bernd Anpassung auf neues Interface

bernd authored 16 years ago

modules/vmail/include/vmail.php 165)   
modules/vmail/include/vmail.php 166)   $forwards = array();
modules/vmail/include/vmail.php 167)   if (count($account['forwards']) > 0) 
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 168)   {
bernd Anpassung auf neues Interface

bernd authored 16 years ago

modules/vmail/include/vmail.php 169)     for ($i=0;$i < count($account['forwards']); $i++)
modules/vmail/include/vmail.php 170)     {
modules/vmail/include/vmail.php 171)       if ($account['forwards'][$i]['spamfilter'] != 'tag' && $account['forwards'][$i]['spamfilter'] != 'delete')
modules/vmail/include/vmail.php 172)         $account['forwards'][$i]['spamfilter'] = '';
modules/vmail/include/vmail.php 173)       $account['forwards'][$i]['destination'] = filter_input_general($account['forwards'][$i]['destination']);
modules/vmail/include/vmail.php 174)       if (! check_emailaddr($account['forwards'][$i]['destination']))
modules/vmail/include/vmail.php 175)         system_failure('Das Weiterleitungs-Ziel »'.$account['forwards'][$i]['destination'].'« ist keine E-Mail-Adresse!');
modules/vmail/include/vmail.php 176)     }
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 177)   }
bernd Anpassung auf neues Interface

bernd authored 16 years ago

modules/vmail/include/vmail.php 178)     
modules/vmail/include/vmail.php 179)   $password='NULL';
modules/vmail/include/vmail.php 180)   if ($account['password'] != '')
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 181)   {
bernd Anpassung auf neues Interface

bernd authored 16 years ago

modules/vmail/include/vmail.php 182)     $account['password'] = stripslashes($account['password']);
modules/vmail/include/vmail.php 183)     $crack = strong_password($account['password']);
modules/vmail/include/vmail.php 184)     if ($crack !== true)
modules/vmail/include/vmail.php 185)     {
modules/vmail/include/vmail.php 186)       input_error('Ihr Passwort ist zu einfach. bitte wählen Sie ein sicheres Passwort!'."\nDie Fehlermeldung lautet: »{$crack}«");
modules/vmail/include/vmail.php 187)       return false;
modules/vmail/include/vmail.php 188)     }
modules/vmail/include/vmail.php 189)     $password = "'".encrypt_mail_password($account['password'])."'";
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 190)   }
bernd Anpassung auf neues Interface

bernd authored 16 years ago

modules/vmail/include/vmail.php 191)   $set_password = ($id == NULL || $password != 'NULL');
modules/vmail/include/vmail.php 192)   if ($account['password'] === NULL)
modules/vmail/include/vmail.php 193)     $set_password=true;
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 194) 
modules/vmail/include/vmail.php 195)   $spam = 'NULL';
modules/vmail/include/vmail.php 196)   switch ($account['spamfilter'])
modules/vmail/include/vmail.php 197)   {
modules/vmail/include/vmail.php 198)     case 'folder':
modules/vmail/include/vmail.php 199)       $spam = "'folder'";
modules/vmail/include/vmail.php 200)       break;
modules/vmail/include/vmail.php 201)     case 'tag':
modules/vmail/include/vmail.php 202)       $spam = "'tag'";
modules/vmail/include/vmail.php 203)       break;
modules/vmail/include/vmail.php 204)     case 'delete':
modules/vmail/include/vmail.php 205)       $spam = "'delete'";
modules/vmail/include/vmail.php 206)       break;
modules/vmail/include/vmail.php 207)   }
modules/vmail/include/vmail.php 208) 
modules/vmail/include/vmail.php 209)   $account['local'] = mysql_real_escape_string($account['local']);
bernd Anpassung auf neues Interface

bernd authored 16 years ago

modules/vmail/include/vmail.php 210)   $account['password'] = mysql_real_escape_string($account['password']);
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 211)   $account['spamexpire'] = (int) $account['spamexpire'];
modules/vmail/include/vmail.php 212) 
modules/vmail/include/vmail.php 213)   $query = '';
modules/vmail/include/vmail.php 214)   if ($id == NULL)
modules/vmail/include/vmail.php 215)   {
bernd Anpassung auf neues Interface

bernd authored 16 years ago

modules/vmail/include/vmail.php 216)     $query = "INSERT INTO mail.vmail_accounts (local, domain, spamfilter, spamexpire, password) VALUES ";
bernd Bei neuen Accounts wurde da...

bernd authored 16 years ago

modules/vmail/include/vmail.php 217)     $query .= "('{$account['local']}', {$account['domain']}, {$spam}, {$account['spamexpire']}, {$password});";
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 218)   }
modules/vmail/include/vmail.php 219)   else
modules/vmail/include/vmail.php 220)   {
bernd Anpassung auf neues Interface

bernd authored 16 years ago

modules/vmail/include/vmail.php 221)     if ($set_password)
modules/vmail/include/vmail.php 222)       $password=", password={$password}";
modules/vmail/include/vmail.php 223)     else
modules/vmail/include/vmail.php 224)       $password='';
modules/vmail/include/vmail.php 225)     $query = "UPDATE mail.vmail_accounts SET local='{$account['local']}', domain={$account['domain']}{$password}, ";
modules/vmail/include/vmail.php 226)     $query .= "spamfilter={$spam}, spamexpire={$account['spamexpire']} ";
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 227)     $query .= "WHERE id={$id} LIMIT 1;";
modules/vmail/include/vmail.php 228)   }
modules/vmail/include/vmail.php 229)   db_query($query); 
bernd Bugfixes

bernd authored 16 years ago

modules/vmail/include/vmail.php 230)   if ($id)
modules/vmail/include/vmail.php 231)     db_query("DELETE FROM mail.vmail_forward WHERE account={$id}");
bernd VMail-accounts können sich...

bernd authored 16 years ago

modules/vmail/include/vmail.php 232)   else
modules/vmail/include/vmail.php 233)     $id = mysql_insert_id();
modules/vmail/include/vmail.php 234) 
bernd Anpassung auf neues Interface

bernd authored 16 years ago

modules/vmail/include/vmail.php 235)   if (count($account['forwards']) > 0)
modules/vmail/include/vmail.php 236)   {
modules/vmail/include/vmail.php 237)     $forward_query = "INSERT INTO mail.vmail_forward (account,spamfilter,destination) VALUES ";
modules/vmail/include/vmail.php 238)     $first = true;
modules/vmail/include/vmail.php 239)     for ($i=0;$i < count($account['forwards']); $i++)
modules/vmail/include/vmail.php 240)     { 
modules/vmail/include/vmail.php 241)       if ($first)
modules/vmail/include/vmail.php 242)         $first = false;
modules/vmail/include/vmail.php 243)       else
modules/vmail/include/vmail.php 244)         $forward_query .= ', ';
modules/vmail/include/vmail.php 245)       $forward_query .= "({$id}, ".maybe_null($account['forwards'][$i]['spamfilter']).", '{$account['forwards'][$i]['destination']}')";
modules/vmail/include/vmail.php 246)     }
modules/vmail/include/vmail.php 247)     db_query($forward_query);
modules/vmail/include/vmail.php 248)   }
modules/vmail/include/vmail.php 249)   if ($account['password'] != 'NULL')
bernd Benachrichtige vmail-userac...

bernd authored 17 years ago

modules/vmail/include/vmail.php 250)   {
modules/vmail/include/vmail.php 251)     # notify the vmail subsystem of this new account
modules/vmail/include/vmail.php 252)     mail('vmail@schokokeks.org', 'command', "user={$account['local']}\nhost={$domainname}", "X-schokokeks-org-message: command");
modules/vmail/include/vmail.php 253)   }
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 254) }
modules/vmail/include/vmail.php 255) 
modules/vmail/include/vmail.php 256) 
modules/vmail/include/vmail.php 257) 
bernd Löschen geht jetzt auch

bernd authored 17 years ago

modules/vmail/include/vmail.php 258) function delete_account($id)
modules/vmail/include/vmail.php 259) {
modules/vmail/include/vmail.php 260)   $account = get_account_details($id);
bernd Anpassung auf neues Interface

bernd authored 16 years ago

modules/vmail/include/vmail.php 261)   db_query("DELETE FROM mail.vmail_accounts WHERE id={$account['id']};");
bernd Löschen geht jetzt auch

bernd authored 17 years ago

modules/vmail/include/vmail.php 262) }
modules/vmail/include/vmail.php 263) 
bernd Erste Version des vmail-Modul

bernd authored 17 years ago

modules/vmail/include/vmail.php 264)