Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- /home/michail/Downloads/awkiawki-0.1/awki.cgi 2004-07-13 20:34:45.000000000 +0400
- +++ awki.cgi 2014-11-27 22:30:30.314034481 +0300
- @@ -49,11 +49,13 @@ BEGIN {
- #load external configfile
- load_config(scriptname)
- -
- +
- # PATH_INFO contains page name
- if (ENVIRON["PATH_INFO"]) {
- query["page"] = ENVIRON["PATH_INFO"]
- }
- +
- + parse_cookies(cookies)
- if (ENVIRON["REQUEST_METHOD"] == "POST") {
- if (ENVIRON["CONTENT_TYPE"] == "application/x-www-form-urlencoded") {
- @@ -94,21 +96,38 @@ BEGIN {
- #check if page is editable
- special_pages = "FullSearch|PageList|RecentChanges"
- +
- + if (cookies["id"] != "")
- + if (system("[ -f sessions/" cookies["id"] " ]") == 0)
- + auth_access = 1
- if (query["page"] ~ "("special_pages")") {
- special_page = 1
- - } else if (!localconf["write_protection"] || query["page"] !~ "("localconf["write_protection"]")") {
- + } else if (auth_access || !localconf["write_protection"] ||
- + query["page"] !~ "("localconf["write_protection"]")") {
- page_editable = 1
- }
- + if (query["login"])
- + re = login(query["username"], query["password"])
- + #set_cookie("count", cookies["count"] ? cookies["count"] + 1 : 0, "", "/")
- + #set_cookie("user", "guest", "Tue, 15-Jan-2015 21:47:38 GMT", "/")
- header(query["page"])
- + #print "#" ENVIRON["HTTP_COOKIE"] "#"
- if (query["edit"] && page_editable)
- edit(query["page"], query["filename"], query["revision"])
- else if (query["save"] && query["text"] && page_editable)
- save(query["page"], query["text"], query["string"], query["filename"])
- - else if (query["page"] ~ "PageList")
- + else if (query["auth"])
- + auth()
- + else if (query["login"]) {
- + if (re == "ok")
- + print "<span>You are logged as " query["username"] "</span>"
- + else
- + auth(re)
- + } else if (query["page"] ~ "PageList")
- special_index(localconf["datadir"])
- else if (query["page"] ~ "RecentChanges")
- special_changes(localconf["datadir"])
- @@ -125,8 +144,41 @@ BEGIN {
- }
- -# print header
- -function header(page) {
- +function set_cookie(name, value, expires, path, domain) {
- + delete cookies_header_header[name]
- + cookies_header[name]["value"] = value
- +
- + if (expires)
- + cookies_header[name]["expires"] = expires;
- + if (path)
- + cookies_header[name]["path"] = path;
- + if (domain)
- + cookies_header[name]["domain"] = domain;
- +}
- +
- +function parse_cookies(cookies, arr, n, i, key, value) {
- + gsub(/[ ]*/, "", ENVIRON["HTTP_COOKIE"]);
- +
- + if (length(ENVIRON["HTTP_COOKIE"]) == 0)
- + return;
- +
- + n = split(ENVIRON["HTTP_COOKIE"], arr, ";")
- + for (i = 1; i <= n; i++) {
- + if (match(arr[i], /=/)) {
- + key = substr(arr[i], 1, RSTART-1)
- + value = substr(arr[i], RSTART+RLENGTH)
- + cookies[key] = value
- + }
- + }
- +}
- +
- +function header(page, i) {
- + for (i in cookies_header)
- + print "Set-Cookie: " i "=" cookies_header[i]["value"] \
- + (cookies_header[i]["expires"] ? "; expires=" cookies_header[i]["expires"] : "") \
- + (cookies_header[i]["path"] ? "; path=" cookies_header[i]["path"] : "") \
- + (cookies_header[i]["domain"] ? "; domain=" cookies_header[i]["domain"] : "");
- +
- print "Content-type: text/html\n"
- print "<html>\n<head>\n<title>" page "</title>"
- if (localconf["css"])
- @@ -148,10 +200,12 @@ function footer(page) {
- print "<a href=\""scriptname"/RecentChanges\">RecentChanges</a>"
- if (localconf["rcs"] && !special_page)
- print "<a href=\""scriptname"/"page"?history=true\">PageHistory</a>"
- + print "<a href=\""scriptname"?auth=true\">Login</a>"
- print "<form action=\""scriptname"/FullSearch\" method=\"GET\" align=\"right\">"
- print "<input type=\"text\" name=\"string\">"
- print "<input type=\"submit\" value=\"search\">"
- print "</form>\n</body>\n</html>"
- +
- }
- # send page to parser script
- @@ -181,6 +235,39 @@ function special_diff(page, filename, re
- }
- }
- +function auth(error) {
- + print "<h3>Login</h3> \
- +<form action=\""scriptname"?login=true\" method=\"POST\"> \
- +<label>Username :</label> \
- +<input id=\"name\" name=\"username\" placeholder=\"username\" type=\"text\"> \
- +<p/> \
- +<label>Password :</label> \
- +<input id=\"password\" name=\"password\" placeholder=\"**********\" type=\"password\"> \
- +<input name=\"submit\" type=\"submit\" value=\"Login\">"
- + if (error)
- + print "<p/><span>" error "</span>"
- +}
- +
- +function login(username, password) {
- + if (!username || !password)
- + return "username or password are empty"
- +
- + if (username != "admin" && password != "secret")
- + return "username or password are wrong"
- +
- + create_session(username)
- + return "ok"
- +}
- +
- +function create_session(username, cmd, id) {
- + cmd = "mktemp sessions/XXXXXXXXXXXXX"
- + cmd | getline id
- + close(cmd)
- + gsub(/^sessions\//, "", id)
- + set_cookie("id", id, "", "/")
- +}
- +
- +# print header
- # print edit form
- function edit(page, filename, revision, cmd) {
- if (revision)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement