Compare commits

...

15 Commits

Author SHA1 Message Date
Marcel Kapfer 20ab0b03f9 Changed README concerning Dart. 2017-06-16 00:14:16 +02:00
Marcel Kapfer d06ab8ab1a Removed obsolete CoffeeScript code 2017-06-16 00:05:05 +02:00
Marcel Kapfer 56e607c04a Implemented new saveAddresses method in Dart
Fixes the bug, that long list can't be sent via get methods.
2017-06-16 00:04:50 +02:00
Marcel Kapfer 9f605bb12f Added gulp-dart as a requirement to package.json 2017-06-16 00:03:43 +02:00
Marcel Kapfer 1a657aac2d Fixed dart script include
Fixed file extension (changed because of the gulp task) and made it load async.
2017-06-16 00:01:00 +02:00
Marcel Kapfer fb64ad895c Extended gitignore with *.sum 2017-06-15 23:59:40 +02:00
Marcel Kapfer 530e3c8ce2 Added dart task to gulpfile 2017-06-15 23:58:59 +02:00
Marcel Kapfer 31ea532523 set charset to utf-8 in sendmail.php script. 2017-05-23 16:47:37 +02:00
Marcel Kapfer 53421bcae0 documented the sendmail.php script. 2017-05-23 16:47:16 +02:00
Marcel Kapfer cef1650686 Send Mail without a file attachment 2017-04-20 13:32:09 +02:00
Marcel Kapfer (mmk2410) bc9f84a64c Added config file to gitignore 2016-12-08 11:02:42 +01:00
Marcel Kapfer (mmk2410) d51fd4e1f4 Maximal height for address list.
Res: T125
2016-11-24 11:22:08 +01:00
Marcel Kapfer (mmk2410) c7d14040b3 Fix: Send mail not working in subdirectory
Res: T126
2016-11-24 11:13:18 +01:00
Marcel Kapfer (mmk2410) b5303781d6 Updated readme 2016-11-21 18:09:05 +01:00
Marcel Kapfer (mmk2410) ebe2b80e87 Removed obsolete code 2016-11-20 09:06:13 +01:00
10 changed files with 119 additions and 55 deletions

2
.gitignore vendored
View File

@ -8,3 +8,5 @@ templates/
lists/
vendor/
*~
filespread.ini
*.sum

View File

@ -14,7 +14,7 @@ npm install
composer install
```
Make sure you have gulp installed on your system and run
Make sure you have gulp and the Dart SDK installed on your system and run
```
gulp sass
@ -24,14 +24,8 @@ gulp sass
gulp coffee
```
Make sure you have dart installed on your system and run
```
cd res/dart/
```
```
dart2js -m -o main.js main.dart
gulp dart
```
Create the folders `templates`, `assets` and `lists` and make sure that the server can write in these folders.
@ -44,4 +38,9 @@ Filespread is licensed under the MIT license.
# Contributing
Please refer to the [Contributing Guidlines](https://mmk2410.org/contribute/)
1. Fork it
2. Create a feature branch with a meaningful name (`git checkout -b my-new-feature`)
3. Add yourself to the CONTRIBUTORS file
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Push to your branch (`git push origin my-new-feature`)
6. Create a new pull request

View File

@ -4,6 +4,7 @@
gulp = require 'gulp'
coffee = require 'gulp-coffee'
sass = require 'gulp-sass'
dart = require 'gulp-dart'
gulp.task 'coffee', ->
gulp.src './res/js/*.coffee'
@ -15,6 +16,15 @@ gulp.task 'sass', ->
.pipe sass()
.pipe gulp.dest './res/css/'
gulp.task 'dart', ->
gulp.src './res/dart/*.dart'
.pipe dart {
"dest": "./res/dart/",
"minify": "true",
}
.pipe gulp.dest './res/dart/'
gulp.task 'default', ->
gulp.watch './res/js/*.coffee', ['coffee']
gulp.watch './res/css/*.sass', ['sass']
gulp.watch './res/dart/*.dart', ['dart']

View File

@ -68,6 +68,7 @@
<p>Change the text of the email if you want.</p>
<p>Title:</p><input id="mailtitle" name="title" class="itextfield" />
<p>Text:</p><textarea id="mailtext" name="text" class="itextarea"></textarea>
<p><input type="checkbox" class="icheckbox" id="nofile" />Send without file</p>
<p>Filename:</p><input id="filename" name="filename" class="itextfield" />
</section>
@ -171,6 +172,6 @@
<script src="./res/js/jquery-2.1.4.min.js"></script>
<script src="./res/js/main.js"></script>
<script src="./res/dart/main.js"></script>
<script async src="./res/dart/main.dart.js"></script>
</body>
</html>

View File

@ -11,6 +11,7 @@
"devDependencies": {
"gulp": "^3.9.1",
"gulp-coffee": "^2.3.1",
"gulp-dart": "^0.2.4",
"gulp-sass": "^2.1.0",
"node-sass": "^3.4.2"
},

View File

@ -163,6 +163,12 @@ input.button
.itextarea:focus
@extend .itextfield
.icheckbox
margin: 0
padding: 0
margin-right: 10px
vertical-align: sub
/* FILESPREAD */
.edit_template
@ -180,6 +186,11 @@ input.button
.remove_list
display: none
#addresses
max-height: 200px
overflow-x: hidden
overflow-y: auto
/* FORM */
form
margin-top: 20px

View File

@ -1,30 +1,38 @@
// Copyright (c) 2016, Marcel Kapfer (mmk2410).
// Copyright (c) 2016 - 2017, Marcel Kapfer (mmk2410).
// MIT License
/// frontend code for filespread, a simple file over email spreading web app.
import 'dart:convert';
import 'dart:html';
/// main method with click listners.
void main() {
// send mail listener
querySelector("#send").onClick.listen(sendMail);
// save address list listner
querySelector("#save-addresses").onClick.listen(saveAddresses);
}
/// function for calling the backend to send mails.
void sendMail(MouseEvent event) {
InputElement title = querySelector("#mailtitle");
InputElement text = querySelector("#mailtext");
InputElement filename = querySelector("#filename");
InputElement addresslist = querySelector("#address_list");
CheckboxInputElement nofile = querySelector("#nofile");
Map data = {
"title": title.value,
"body": text.value,
"filename": filename.value,
"list": addresslist.value
"list": addresslist.value,
"nofile": nofile.checked
};
String url = "/res/php/sendmail.php?data=${JSON.encode(data)}";
String url = "res/php/sendmail.php?data=${JSON.encode(data)}";
HttpRequest.getString(url).then((response) {
HttpRequest.getString(url).then((String response) {
if (response == "0") {
window.alert("Mails successfully sent.");
} else {
@ -32,3 +40,44 @@ void sendMail(MouseEvent event) {
}
});
}
/// function to update the addresses list in the backend.
void saveAddresses(MouseEvent event) {
TextAreaElement addresses = querySelector("#edit-addresses");
SelectElement list = querySelector("#edit-address-list");
List<String> addressesList = new List();
addresses.value.split("\n").forEach((String address) {
if (address.isNotEmpty) addressesList.add(address);
});
Map data = {"list": list.value, "addresses": addressesList};
String url = "res/php/savelist.php";
HttpRequest.postFormData(url, {"data": JSON.encode(data)}).then((HttpRequest response) {
if (response.responseText == "0") {
window.alert("Addresses sucessfully saved.");
updateAddresses(addressesList, list.value);
} else {
window.alert("Failed to save adresses.");
}
});
}
/// Updated the frontend after an address change.
void updateAddresses(List<String> addresses, String list) {
SelectElement currentList = querySelector("#address_list");
if (currentList.value == list) {
DivElement addressesContainer = querySelector("#addresses");
addressesContainer.children .removeWhere((Element child) => addressesContainer.children.contains(child));
addresses.forEach((String address) {
ParagraphElement addressElement = new ParagraphElement();
addressElement.text = address;
addressesContainer.children.add(addressElement);
});
}
}

View File

@ -3,30 +3,6 @@
# MIT License
main = ->
###
$("#send").click ->
url = "/res/php/sendmail.php"
data = new FormData
data.append "json", JSON.stringify
a: 1
b: "test"
request = new Request url,
method: 'POST'
body: data
fetch request
.then (response) ->
console.log response
###
###
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()
@ -129,20 +105,6 @@ main = ->
$("#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"

View File

@ -1,8 +1,8 @@
<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# COPYRIGHT (c) 2016-2017 Marcel Kapfer (mmk2410)
# MIT License
$content = $_GET["data"];
$content = json_decode($_POST["data"], true);
$filename = "../../lists/" . $content["list"];

View File

@ -2,12 +2,22 @@
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
/**
* configuration map
*/
$ini = parse_ini_file("../../filespread.ini");
date_default_timezone_set($ini["timezone"]);
require '../../vendor/autoload.php';
/**
* main function that is executed at the beginning.
*
* @author Marcel Kapfer <marcelmichaelkapfer@gmail.com>
*
* @param $ini an configuration map.
*/
function main($ini) {
$data = json_decode($_GET["data"], true);
@ -21,6 +31,12 @@ function main($ini) {
$filename = $data["filename"];
$nofile = $data["nofile"];
if ($nofile) {
$filename = "";
}
foreach ($addresses as $address) {
if (sendMail($title, $content, $filename, $address, $ini) != 0) {
print "-1";
@ -32,9 +48,20 @@ function main($ini) {
}
/**
* function for sending the mail.
*
* @author Marcel Kapfer <marcelmichaelkapfer@gmail.com>
*
* @param $title the subject of the mail.
* @param $content the text of the mail.
* @param $address the receiver of the mail.
* @param $ini an configuration map.
*/
function sendMail($title, $content, $filename, $address, $ini) {
$mail = new PHPMailer;
$mail->CharSet = 'UTF-8';
$mail->setFrom($ini["email"], $ini["name"]);
$mail->Subject = $title;
@ -46,7 +73,9 @@ function sendMail($title, $content, $filename, $address, $ini) {
$mail->addReplyTo($ini["reply"]);
}
$mail->AddAttachment("../../assets/file.bin", $filename);
if (!empty($filename)) {
$mail->AddAttachment("../../assets/file.bin", $filename);
}
if (!$mail->Send()) {
return -1;