Initial commit

This commit is contained in:
mmk2410 2016-04-06 17:30:05 +02:00
commit 78a4e70036
24 changed files with 1067 additions and 0 deletions

11
res/php/deletelist.php Normal file
View file

@ -0,0 +1,11 @@
<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
$filename = "../../lists/" . $_GET["list"];
if (unlink($filename)) {
echo 0;
} else {
echo 1;
}

View file

@ -0,0 +1,11 @@
<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
$filename = "../../templates/" . $_GET["template"];
if (unlink($filename)) {
echo 0;
} else {
echo 1;
}

10
res/php/fileexists.php Normal file
View file

@ -0,0 +1,10 @@
<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
$file = "../../" . $_GET["file"];
if (file_exists($file)) {
echo 0;
} else {
echo 1;
}

13
res/php/getaddresses.php Executable file
View file

@ -0,0 +1,13 @@
<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
$file = "../../lists/" . $_GET["list"];
$addresses = file($file);
$res = array();
$i = 0;
foreach ($addresses as $address) {
$res[] = substr($address, 0, strlen($address) - 1);
$i++;
}
echo json_encode($res);

21
res/php/getlists.php Normal file
View file

@ -0,0 +1,21 @@
<?php
/**
* FileSpread
* php for json string of lists
*
* Copyright (c) 2016 Marcel Kapfer (mmk2410)
* MIT License
*/
$dir = '../../lists/';
$files = scandir($dir);
$i = 0;
foreach ($files as $file) {
if ( in_array($file, array(".", "..")) ) {
unset($files[$i]);
}
$i++;
}
echo json_encode(array("lists" => $files));

17
res/php/gettemplate.php Normal file
View file

@ -0,0 +1,17 @@
<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
$file = "../../templates/" . $_GET["template"];
$content = file($file);
$title = substr($content[0], 7);
$filename = substr($content[1], 10);
$text = substr($content[2], 6);
for ($i = 3; $i < count($content); $i++) {
$text = $text . $content[$i];
}
echo json_encode(array("subject" => $title, "filename" => $filename, "text" => $text));

21
res/php/gettemplates.php Normal file
View file

@ -0,0 +1,21 @@
<?php
/**
* FileSpread
* php for json string of templates
*
* Copyright (c) 2016 Marcel Kapfer (mmk2410)
* MIT License
*/
$dir = '../../templates/';
$files = scandir($dir);
$i = 0;
foreach ($files as $file) {
if ( in_array($file, array(".", "..")) ) {
unset($files[$i]);
}
$i++;
}
echo json_encode(array("templates" => $files));

21
res/php/savelist.php Normal file
View file

@ -0,0 +1,21 @@
<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
$content = $_GET["data"];
$filename = "../../lists/" . $content["list"];
$file = "";
foreach ($content["addresses"] as $address) {
$file = $file . $address . "\n";
}
$handle = fopen($filename, "w");
if (fwrite($handle, $file)) {
echo "0";
} else {
echo "1";
}

19
res/php/savetemplate.php Normal file
View file

@ -0,0 +1,19 @@
<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
$content = $_GET["data"];
$filename = "../../templates/" . $content["template"];
$file = "Title: " . $content["subject"] . "\n";
$file = $file . "Filename: " . $content["filename"] . "\n";
$file = $file . "Text: " . $content["text"];
$handle = fopen($filename, "w");
if (fwrite($handle, $file)) {
echo "0";
} else {
echo "1";
}

53
res/php/sendmail.php Executable file
View file

@ -0,0 +1,53 @@
<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
$ini = pParse_ini_file("../../filespread.ini");
date_default_timezone_set($ini["timezone"]);
require '../../vendor/autoload.php';
$list = "../../lists/" . $_GET["list"];
$template = "../../templates/" . $_GET["template"];
$addresses = file($list);
$content = file($template);
$email = new PHPMailer;
$email->setFrom($ini["email"], $ini["name"]);
$email->Subject = parseSubject($content);
$email->Body = parseText($content);
foreach ($addresses as $address) {
$email->AddAddress($address);
}
$file_to_attach = '../../assets/file.bin';
$filename = parseFilename($content);
$email->AddAttachment($file_to_attach, $filename);
if (!$email->Send()) {
echo "-1";
echo $email->ErrorInfo;
} else {
echo "0";
}
function parseSubject($content) {
return substr($content[0], 7);
}
function parseFilename($content) {
return substr($content[1], 10);
}
function parseText($content) {
$text = substr($content[2], 6);
for ($i = 3; $i < count($content); $i++) {
$text = $text . $content[$i];
}
return $text;
}

10
res/php/upload.php Executable file
View file

@ -0,0 +1,10 @@
<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
if (0 < $_FILES['userfile']['error']) P{
echo "Error: " . $_FILES['userfile']['error'] . "<br>";
} else {
move_uploaded_file($_FILES['userfile']['tmp_name'], "../../assets/file.bin");
header("Location: ../../");
}