-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
79 lines (57 loc) · 1.88 KB
/
init.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/* General AWS settings */
require 'vendor/autoload.php';
$awsRegion = "us-east-1";
$awsPrefix = "siurna-";
/* S3 settings */
use Aws\S3\S3Client;
$s3Client = new Aws\S3\S3Client([
'version' => '2006-03-01',
'region' => $awsRegion
]);
$s3BucketsNeeded = array("color-", "grayscale-");
function describeS3Bucket($nameNeeded){
global $s3Client;
$s3Buckets = $s3Client->listBuckets();
foreach ($s3Buckets["Buckets"] as $bucket)
if (strpos($bucket["Name"], $nameNeeded) !== false)
return $bucket["Name"];
return false;
}
function getS3BucketsNeeded(){
global $s3BucketsNeeded;
$result = array();
foreach ($s3BucketsNeeded as $bucketNeeded)
if (!describeS3Bucket($bucketNeeded))
array_push($result, $bucketNeeded);
return $result;
}
/* RDS settings */
use Aws\Rds\RdsClient;
$rdsClient = new RdsClient([
'region' => $awsRegion,
'version' => '2014-10-31'
]);
$rdsURL = false;
$rdsUser = "tsiurna";
$rdsPass = "akmjljjlnnv2018";
$rdsDatabase = "mp1siurna";
function getRDShost(){
global $rdsClient, $rdsURL, $awsPrefix;
$rdsInstances = $rdsClient->describeDBInstances();
foreach ($rdsInstances["DBInstances"] as $rds)
if (strpos($rds["DBInstanceIdentifier"], $awsPrefix) !== false){
$rdsURL = $rds["Endpoint"]["Address"];
return $rdsURL;
}
return false;
}
function connectToRDSInstance(){
global $rdsConnection, $rdsURL, $rdsUser, $rdsPass, $rdsDatabase;
getRDShost();
$rdsConnection = new mysqli($rdsURL, $rdsUser, $rdsPass, $rdsDatabase, 3306);
// In case table does not exist. I know, not the best solution... but hey, it works!
$rdsConnection->query("CREATE TABLE IF NOT EXISTS records (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `email` VARCHAR(32), `phone` VARCHAR(32), `s3-raw-url` VARCHAR(100), `s3-finished-url` VARCHAR(100), `status` INT(1), `receipt` BIGINT);");
return true;
}
?>