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

201
res/css/main.sass Executable file
View file

@ -0,0 +1,201 @@
// Variables
// COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
// MIT License
$primaryColor: #9c27b0
/* BODY */
body
font-family: "Roboto", sans-serif
background: #f6f6f6
color: #383838
margin-top: 94px
.main
height: 100%
width: 100%
margin-left: 0px
/* HEADER */
.header
background-color: $primaryColor
position: fixed
top: 0px
right: 0px
left: 0px
width: 100%
height: 64px
box-shadow: 2px 0px 2px 2px rgba(62, 62, 62, 0.45)
.title
color: #fff
font-size: 23px
text-decoration: none
line-height: 64px
vertical-align: middle
left: 75px
position: absolute
/* MAIN */
.card
margin-right: auto
margin-left: auto
width: 75%
background: #fff
border-radius: 2px
padding: 24px
box-shadow: 0px 1px 1.5px 1.5px rgba(62, 62, 62, 0.3)
margin-bottom: 40px
max-width: 1160px
.headline
font-size: 24px
color: #383838!important
text-decoration: none
display: block
padding-bottom: 8px
border-bottom: none!important
.card > p
font-size: 14px
line-height: 24px
.table-content
max-height: 200px
overflow: auto
/* FOOTER */
.footer
font-size: 12px
text-align: center
.footer a
color: #383838
text-decoration: none
border-bottom: 1px solid transparent
border-bottom-color: transparent
transition: border-bottom-color 150ms ease-in-out 100ms
.footer a:hover
border-bottom-color: #383838
/* BUTTON */
.button
text-decoration: none
color: #fff
background-color: $primaryColor
line-height: 36px
min-width: 64px
text-align: center
height: 36px
padding: 8px
border-width: 1px
border-style: solid
border-color: $primaryColor
box-shadow: 0.4px 1px 1.5px 1px #aaa
-moz-box-shadow: 0.4px 1px 1.5px 1px #aaa
-webkit-box-shadow: 0.4px 1px 1.5px 1px #aaa
border-radius: 2px
margin-top: 4px
margin-bottom: 5px
letter-spacing: 0.4px
font-weight: 700
font-size: 14px
transition-property: box-shadow
transition-delay: 50ms
transition-duration: 125ms
transition-timing-function: ease
-moz-transition-property: box-shadow
-moz-transition-delay: 50ms
-moz-transition-duration: 125ms
-moz-transition-timing-function: ease
-webkit-transition-property: box-shadow
-webkit-transition-delay: 50ms
-webkit-transition-duration: 125ms
-webkit-transition-timing-function: ease
cursor: pointer
.button:hover, .button:hover
box-shadow: 0.5px 1.8px 2.1px 1.4px #aaa
-moz-box-shadow: 0.5px 1.8px 2.1px 1.4px #aaa
-webkit-box-shadow: 0.5px 1.8px 2.1px 1.4px #aaa
input.button
padding: 0px 8px
/* INPUT FIELD */
.itextfield
border-color: transparent
border-width: 1px
font-size: 16px
line-height: 22px
width: 50%
border-bottom-color: #aaa
transition-property: border-bottom-color
transition-delay: 50ms
transition-duration: 125ms
transition-timing-function: ease
-moz-transition-property: border-bottom-color
-moz-transition-delay: 50ms
-moz-transition-duration: 125ms
-moz-transition-timing-function: ease
-webkit-transition-property: border-bottom-color
-webkit-transition-delay: 50ms
-webkit-transition-duration: 125ms
-webkit-transition-timing-function: ease
.itextfield:focus
border-bottom-color: #E91E63
border-width: 2px
outline: none
.itextarea
@extend .itextfield
min-height: 150px
.itextarea:focus
@extend .itextfield
/* FILESPREAD */
.edit_template
display: none
.edit_list
display: none
.remove_template
display: none
.edit_address
display: none
.remove_list
display: none
/* FORM */
form
margin-top: 20px
@media screen and (min-width: 1440px)
.card
width: 1160px
@media screen and (max-width: 720px)
.card
width: 82%
.title
left: 25px
.itextfield
width: 100%

4
res/js/jquery-2.1.4.min.js vendored Executable file

File diff suppressed because one or more lines are too long

251
res/js/main.coffee Executable file
View file

@ -0,0 +1,251 @@
# CoffeeScript for filespread
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
main = ->
$("#send").click ->
url = "./res/php/sendmail.php?list=" + $("#address_list").val() +
"&template=" + $("#templates_list").val()
$.get url, (data) ->
if data is "0"
alert "Mail sent!"
else
alert "Sending mail failed!"
updateAddressLists()
updateTemplateLists()
$("#address_list").change ->
updateAddresss $("#address_list").val()
$("#templates_list").change ->
updateTemplate $("#templates_list").val()
$("#edit_templates_list").change ->
template = $("#edit_templates_list").val()
if template is "none"
$(".edit_template").fadeOut()
else
updateEditTemplate template
$("#save_template").click ->
data =
template: $("#edit_templates_list").val()
subject: $("#edit_mailtitle").val()
filename: $("#edit_filename").val()
text: $("#edit_mailtext").val()
$.get "./res/php/savetemplate.php", {"data": data}, (data) ->
console.log data
if data is "0"
alert "Edit sucessfully saved."
if $("#edit_templates_list").val() is $("#templates_list").val()
updateTemplate $("#templates_list").val()
else
alert "Error while saving."
$("#create_template").click ->
filename = $("#create_template_name").val()
if filename.substring((filename.length - 4)) isnt ".txt"
alert "The filename has to end with \".txt\""
else
url = "./res/php/fileexists.php?file=templates/#{filename}"
$.get url, status = (data) ->
if data is "1"
data =
template: filename
subject: null
filename: null
text: null
$.get "./res/php/savetemplate.php", {"data": data}, (data) ->
if data is "0"
alert "Template created sucessfully"
$("#templates_list").append """
<option value="#{filename}">#{filename}</option>
"""
$("#edit_templates_list").append """
<option value="#{filename}">#{filename}</option>
"""
$("#remove-template-list").append """
<option value="#{template}">#{template}</option>
"""
else
alert "Error while creating template."
else
alert "A template with that filename already exists"
$("#remove-template-list").change ->
selected = $("#remove-template-list").val()
if selected == "none"
$(".remove_template").fadeOut()
else
$(".remove_template").fadeIn()
$("#remove-template").click ->
selected = $("#remove-template-list").val()
url = "./res/php/deletetemplate.php?template=#{selected}"
$.get url, (data) ->
if data == "0"
alert "Template deleted."
$("#templates_list").empty()
$("#edit_templates_list").empty()
$("#remove-template-list").empty()
$("#edit_templates_list").append """
<option value="none">None Selected</option>
"""
$("#remove-template-list").append """
<option value="none">None Selected</option>
"""
updateTemplateLists()
$(".remove_template").fadeOut()
else
alert "Failed to delete template."
$("#edit-address-list").change ->
selected = $("#edit-address-list").val()
if selected == "none"
$(".edit_address").fadeOut()
else
url = "./res/php/getaddresses.php?list=#{selected}"
$.getJSON url, (data) ->
text = ""
for address in data
text = text + address + "\n"
$("#edit-addresses").val(text)
$(".edit_address").fadeIn()
$("#save-addresses").click ->
data =
list: $("#edit-address-list").val()
addresses: $("#edit-addresses").val().split '\n'
if data.addresses[data.addresses.length - 1] is ""
data.addresses.pop()
$.get "./res/php/savelist.php", {"data": data}, (data) ->
if data == "0"
alert "List sucessfully changed!"
if data.list is $("#address_list")
updateAddresss data.list
else
alert "Error while saving the edit."
$("#create-list").click ->
filename = $("#create-list-name").val()
if filename.substring((filename.length - 4)) isnt ".txt"
alert "The filename has to end with \".txt\""
else
url = "./res/php/fileexists.php?file=lists/#{filename}"
$.get url, status = (data) ->
if data is "1"
data =
list: filename
addresses: [null]
$.get "./res/php/savelist.php", {"data": data}, (data) ->
if data is "0"
alert "Template created sucessfully"
$("#address_list").append """
<option value="#{filename}">#{filename}</option>
"""
$("#edit-address-list").append """
<option value="#{filename}">#{filename}</option>
"""
$("#remove-list-list").append """
<option value="#{filename}">#{filename}</option>
"""
else
alert "Error while creating template."
else
alert "A template with that filename already exists"
$("#remove-list-list").change ->
selected = $("#remove-list-list").val()
if selected == "none"
$(".remove_list").fadeOut()
else
$(".remove_list").fadeIn()
$("#remove-list").click ->
selected = $("#remove-list-list").val()
url = "./res/php/deletelist.php?list=#{selected}"
$.get url, (data) ->
if data == "0"
alert "List deleted."
$("#address_list").empty()
$("#edit-address-list").empty()
$("#remove-list-list").empty()
$("#edit-address-list").append """
<option value="none">None Selected</option>
"""
$("#remove-list-list").append """
<option value="none">None Selected</option>
"""
updateAddressLists()
$(".remove_list").fadeOut()
else
alert "Failed to delete template."
$("#edit-address-list").change ->
selected = $("#edit-address-list").val()
if selected == "none"
$(".edit_address").fadeOut()
else
url = "./res/php/getaddresses.php?list=#{selected}"
$.getJSON url, (data) ->
text = ""
for address in data
text = text + address + "\n"
$("#edit-addresses").val(text)
$(".edit_address").fadeIn()
$(document).ready main
updateTemplateLists = ->
$.getJSON './res/php/gettemplates.php', (data) ->
for templates, template of data.templates
$("#templates_list").append """
<option value="#{template}">#{template}</option>
"""
$("#edit_templates_list").append """
<option value="#{template}">#{template}</option>
"""
$("#remove-template-list").append """
<option value="#{template}">#{template}</option>
"""
updateTemplate data.templates[2]
updateAddresss = (list) ->
url = './res/php/getaddresses.php?list=' + list
$.getJSON url, (data) ->
$("#addresses").empty()
for address in data
$("#addresses").append "<p>#{address}</p>"
updateTemplate = (template) ->
url = './res/php/gettemplate.php?template=' + template
$.getJSON url, (data) ->
$("#mailtitle").val data.subject
$("#filename").val data.filename
$("#mailtext").val data.text
updateEditTemplate = (template) ->
url = './res/php/gettemplate.php?template=' + template
$.getJSON url, (data) ->
$(".edit_template").fadeIn()
$("#edit_mailtitle").val data.subject
$("#edit_filename").val data.filename
$("#edit_mailtext").val data.text
updateAddressLists = ->
$.getJSON './res/php/getlists.php', (data) ->
for lists, list of data.lists
$("#address_list").append """
<option value="#{list}">#{list}</option>
"""
$("#edit-address-list").append """
<option value="#{list}">#{list}</option>
"""
$("#remove-list-list").append """
<option value="#{list}">#{list}</option>
"""
updateAddresss data.lists[2]

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: ../../");
}