Save mail password encrypted in configuration file

This commit is contained in:
bergware
2016-08-21 12:30:14 +02:00
parent f82fdef257
commit 563f39e3d6
3 changed files with 84 additions and 0 deletions
+4
View File
@@ -14,6 +14,9 @@ Title="SMTP Settings"
*/
?>
<?
require_once 'webGui/include/Encryption.php';
$ssmtp['AuthPass'] = base64_decrypt($ssmtp['AuthPass']);
$incomplete = strlen($ssmtp['root'])==0 || strlen($ssmtp['server'])==0 || strlen($ssmtp['port'])==0 || ((strlen($ssmtp['AuthUser'])==0 || strlen($ssmtp['AuthPass'])==0) && $ssmtp['AuthMethod']!='none');
?>
<script>
@@ -66,6 +69,7 @@ function settings(form, data) {
<form markdown="1" name="smtp_setup" method="POST" action="/update.php" target="progressFrame" onsubmit="return mailcheck(this)" onchange="disableTest()">
<input type="hidden" name="#file" value="dynamix/dynamix.cfg">
<input type="hidden" name="#section" value="ssmtp">
<input type="hidden" name="#include" value="/webGui/include/update.ssmtp.php">
<input type="hidden" name="#command" value="/webGui/scripts/notify">
<input type="hidden" name="#arg[1]" value="smtp-init">
Preset service:
+63
View File
@@ -0,0 +1,63 @@
<?PHP
// PHP encrypt decrypt using base64
// v1 (2013-04-14)
// http://www.geocontext.org/publ/2013/04/base64_encrypt_decrypt/
// Krystian Pietruszka
// www.geocontext.org
// info@geocontext.org
// Public domain license
// Adapted by Bergware for use in unRAID
// forced use of hash key
/*
Example encrypt:
base64_encrypt('AuthPass');
Example decrypt:
base64_decrypt('AuthPass');
*/
$abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$key = 'unraid#hash#key';
function base64_encrypt($pw) {
global $abc, $key;
$s = '';
$a = str_split('+/='.$abc);
$b = str_split(mixing_key(strrev('-_='.$abc), $key));
$t = str_split(base64_encode(substr(md5($key),0,16).$pw));
for ($i=0; $i<count($t); $i++) for ($j=0; $j<count($a); $j++) {
if ($t[$i]==$a[$j]) $s .= $b[$j];
}
return $s;
}
function base64_decrypt($pw) {
global $abc, $key;
$s = '';
$a = str_split('+/='.$abc);
$b = str_split(mixing_key(strrev('-_='.$abc), $key));
$t = str_split($pw);
for ($i=0; $i<count($t); $i++) for ($j=0; $j<count($b); $j++) {
if ($t[$i]==$b[$j]) $s .= $a[$j];
}
$s = base64_decode($s);
// return decrypted or plain password (backward compability)
return substr($s,0,16)==substr(md5($key),0,16) ? substr($s,16) : $pw;
}
function mixing_key($b, $key) {
$s = '';
$c = $b;
$t = str_split($b);
$k = str_split(sha1($key));
for ($i=0; $i<count($k); $i++) for ($j=0; $j<count($t); $j++) {
if ($k[$i]==$t[$j]) {
$c = str_replace($t[$j],'',$c);
if (!preg_match('/'.$t[$j].'/',$s)) $s .= $t[$j];
}
}
return $c.$s;
}
?>
+17
View File
@@ -0,0 +1,17 @@
<?PHP
/* Copyright 2005-2016, Lime Technology
* Copyright 2012-2016, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
require_once 'webGui/include/Encryption.php';
$_POST['AuthPass'] = base64_encrypt($_POST['AuthPass']);
?>