Commit 289740e0 authored by Michael Murtaugh's avatar Michael Murtaugh
Browse files

(working) touch command in index

parent 681cee21
#!/usr/bin/env python
import hashlib, os, json
import cgi
import cgi, sys
import cgitb; cgitb.enable()
from uri_to_path import *
import subprocess
env = os.environ
pwd = env.get("PWD", env.get("PATH_TRANSLATED"))
fs = cgi.FieldStorage()
ruri = fs.getvalue("uri", "")
path = uri_to_path(ruri, os.environ)
path = fs.getvalue("path", "").strip("/")
if os.path.isfile(path):
subprocess.call(["touch", path])
referer = os.environ.get("HTTP_REFERER")
if referer and fs.getvalue("return"):
print "Location: {0}".format(referer)
if path:
abspath = os.path.join(pwd, path)
try:
result = subprocess.call(["touch", abspath])
print "Content-type: application/json;charset=utf-8"
print
else:
print "Content-type: text/html"
print
print "ok"
else:
print "Content-type:text/plain"
print
print path
print json.dumps({'result': result})
sys.exit(0)
except IOError as e:
print json.dumps({'result': result, msg: e.toString()})
sys.exit(0)
print "Content-type: text/html"
print
print "nothing to do"
......@@ -22,6 +22,52 @@
<tr class="{{item.classes}}"><td valign="top"><img src="/__makeserver__/icons/{% if item.is_text %}text{%else%}generic{%endif%}.symbolic.png" alt="[ ]"></td><td><a href="{{item.link}}">{{item.label}}</a>{{item.buttons}}</td><td align="right">{% if item.lastmod %}{{item.lastmod | strftime("%Y-%m-%d %H:%M")}}{%else%}&mdash;{%endif%} </td><td align="right">{{item.size|humanize_bytes}}</td><td>&nbsp;</td></tr>
{% endif %}
{% endfor %}
</ul>
</table>
<div style="margin-top: 1em">
<button id="touch">touch</button>
</div>
<script>
function getjson (url, callback) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
if (callback === undefined) {
callback = function (err, response) {
if (err) {
console.log("getjson.error");
} else {
console.log("getjson", response);
}
};
}
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
callback(null, JSON.parse(request.responseText));
} else {
callback("server error");
}
};
request.onerror = function() {
callback("connection error");
};
request.send();
}
var touch = document.getElementById("touch");
touch.addEventListener("click", function () {
var name = prompt("touch");
if (name) {
var path = window.location.pathname + name;
getjson("/__makeserver__/cgi-bin/touch.cgi?path=" + encodeURIComponent(path),function (err, data) {
console.log("data", data);
if (data.result === 0) {
console.log("refreshing page")
window.location.reload();
} else {
alert("that didn't work (" + data.result + ")");
}
});
}
}, false);
</script>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment