-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv.php
63 lines (52 loc) · 1.42 KB
/
csv.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
<?php
/**
* Copyright (C) 2015, 2022 Green Screens Ltd.
*
* Simple example of reading and parsing CSV file to
* automatically generate user web terminal links
*
* Read more on
* http://blog.greenscreens.io/automatic-remote-configuration/
*/
require_once "funcs.php";
// Green Screens RSA service URL to get encryption public key
$GREENSCREENS_SERVICE = "http://localhost:8080";
$CSV = "./sample.csv";
/*
* Read CSV file and process line by line
*/
function doCSV($fileName)
{
$csvFile = file($fileName);
$data = [];
foreach ($csvFile as $line) {
$data[] = str_getcsv($line);
$pieces = explode(";", $data[0][3]);
foreach ($pieces as $piece) {
$url = encryptCSVLine($data[0][0], $data[0][1], $data[0][2], $piece);
// get email from $data[0][4] and send it to the user
print $url;
print "\n";
}
}
}
/*
* Encrypt CSV line into URL
*/
function encryptCSVLine($uuid, $host, $user, $displayName)
{
global $GREENSCREENS_SERVICE;
$json_data = array('uuid' => $uuid,
'host' => $host,
'user' => $user,
'displayName' => $displayName
);
$data = json_encode($json_data);
$json = encryptJson($GREENSCREENS_SERVICE, $data);
// generate http://localhost:9080/lite?d=[HEX encrypted AES]&k=[RSA encrypted AES]
$url = jsonToURLService($GREENSCREENS_SERVICE, $json);
return $url;
}
// start procesing csv file
doCSV($CSV)
?>