-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.php
50 lines (44 loc) · 1.53 KB
/
config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/******************************************************************
* Name : config.php
* Description : MetaGlances cloud config backup
* Version : PHP (5.3.10)
* Author : spin0us (github_[at]_spin0us_[dot]_net)
* CreationDate : 17:21 16/11/2012
******************************************************************/
define('CACHE_DIRECTORY', './cache/config/'); // server cache directory
function encryptData($key, $data) {
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB, $iv);
return base64_encode($crypttext);
}
function decryptData($key, $data) {
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$cleartext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($data), MCRYPT_MODE_ECB, $iv);
return $cleartext;
}
// Check POST params
if( !isset($_POST['mail']) || !isset($_POST['pass']) ) {
header("HTTP/1.1 400 Bad Request");
die();
}
// Check token
$token = md5($_POST['mail'].$_POST['pass']);
// Store config
if(isset($_POST['conf'])) {
file_put_contents(CACHE_DIRECTORY.$_POST['mail'],encryptData($token, $_POST['conf']));
echo 'done';
}
// Restore config
else {
if(file_exists(CACHE_DIRECTORY.$_POST['mail'])) {
$conf = decryptData($token, file_get_contents(CACHE_DIRECTORY.$_POST['mail']));
$conf = trim($conf);
echo empty($conf) ? '[]' : $conf;
}
else {
echo '[]';
}
}