forked from Kamoba/Lazy-Share
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
152 lines (130 loc) · 3.91 KB
/
index.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/*
Server-side PHP file to share texts and files
Featured on github.com
Developed by Kamoba https://github.com/Kamoba
*/
define('USER', 'key'); // choose your Get variables (USER and PASS)
define('PASS', 'lazy');
// write to file from ajax
if (isset($_POST["textblock"])){
$f = fopen("Text.txt", "w");
$content = $_POST["textblock"];
fwrite($f, $content);
fclose($f);
}
if (isset($_GET[USER])){
if ($_GET[USER] != PASS){ // accessible only from YOURSERVER/lazy-share?key=lazy
exit();
}
}
else{
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Lazy Share</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
</head>
<body>
<center>
<textarea id="myText" name="myText"></textarea> <br>
</center>
<button id="copy">Copy</button>
<button id="selectLine" onclick="selectLine()">Select Line</button>
<button id="select" onclick="selectAll()">Select All</button>
<button id="cut">Cut</button>
<button id="save" onclick="Save()">Save</button>
<p id="demo"></p>
<br><br><br>
<?php
include "ajaxUpload.php";
?>
<script>
/*
function writeToFile(d1, d2){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.OpenTextFile("test.txt", 8, false, 0);
fh.WriteLine(d1 + ',' + d2);
fh.Close();
}
var submit = document.getElementById("submit");
submit.onclick = function () {
var id = document.getElementById("id").value;
var content = document.getElementById("content").value;
writeToFile(id, content);
}*/
$(document).ready(function(){
$.ajaxSetup ({ // Disable caching of AJAX responses
cache: false
});
$('#myText').load('Text.txt', function() { // load file Text.txt
});
});
</script>
<script>
function Save() {
const $Text = $('#myText').val();
$.ajax({ // Send texarea content with ajax
method: 'POST',
url: 'index.php',
data: { textblock: $Text },
timeout: 3000,
success: function(data) { Success(); },
error: function() { alert('The request was unsuccessful'); }
});
}
function Success() {
document.getElementById("demo").innerHTML = "saved successfully!";
}
</script>
<script type="text/javascript">
function selectLine() {
var textarea = document.getElementById('myText');
var cursorPos = textarea.selectionStart;
var selectionEnd = textarea.selectionEnd;
// Store current scroll position
var scrollTop = textarea.scrollTop;
// Find start position of the current line
var startPos = cursorPos;
while (startPos > 0 && textarea.value[startPos - 1] !== '\n') {
startPos--;
}
// Find end position of the current line
var endPos = cursorPos;
while (endPos < textarea.value.length && textarea.value[endPos] !== '\n') {
endPos++;
}
// Set selection range to select the current line
textarea.setSelectionRange(startPos, endPos);
// Restore focus and scroll position
textarea.focus();
textarea.scrollTop = scrollTop;
// Restore selection if it was not at cursor position
if (selectionEnd !== cursorPos) {
textarea.setSelectionRange(cursorPos, selectionEnd);
}
}
// select ALL
function selectAll(){
var textBox = document.getElementById("myText");
textBox.select();
// Work around Chrome's little problem
// Prevent further mouseup intervention
textBox.onmouseup = null;
return false;
}
document.getElementById('copy').onmousedown = function() { // on copy button pressed
console.log(document.execCommand('copy'))
}
document.getElementById('cut').onmousedown = function() { // on cut button pressed
console.log(document.execCommand('cut'))
}
</script>
</body>
</html>