summaryrefslogtreecommitdiff
path: root/cgi-bin
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-07-13 21:53:49 +0800
committerchai <chaifix@163.com>2018-07-13 21:53:49 +0800
commit7ca80e57f06922e464626c7a6a1d7965e716b53f (patch)
treebda9271234720424b7dfc5c2d25b9df4ba3d01df /cgi-bin
parent181b206863d3765fe5343ceea8e1e00e52ffba9e (diff)
Diffstat (limited to 'cgi-bin')
-rw-r--r--cgi-bin/.whisper.py.un~bin13233 -> 0 bytes
-rw-r--r--cgi-bin/__pycache__/path.cpython-36.pycbin793 -> 951 bytes
-rw-r--r--cgi-bin/add.py63
-rw-r--r--cgi-bin/config.ini13
-rw-r--r--cgi-bin/config.py10
-rw-r--r--cgi-bin/connect.py13
-rw-r--r--cgi-bin/delete.py36
-rw-r--r--cgi-bin/edit.py46
-rw-r--r--cgi-bin/html/ckeditor/config.js3
-rw-r--r--cgi-bin/html/imgs/1531471283.pngbin0 -> 442 bytes
-rw-r--r--cgi-bin/html/imgs/1531471337.pngbin0 -> 442 bytes
-rw-r--r--cgi-bin/html/imgs/1531471469.jpgbin0 -> 876735 bytes
-rw-r--r--cgi-bin/html/imgs/1531471899.jpgbin0 -> 876735 bytes
-rw-r--r--cgi-bin/html/imgs/1531471931.pngbin0 -> 442 bytes
-rw-r--r--cgi-bin/html/style.css5
-rw-r--r--cgi-bin/page.py75
-rw-r--r--cgi-bin/path.py20
-rw-r--r--cgi-bin/template/.whisper.html.un~bin523 -> 0 bytes
-rw-r--r--cgi-bin/template/edit.html20
-rw-r--r--cgi-bin/template/page.html37
-rw-r--r--cgi-bin/template/whisper.html10
-rw-r--r--cgi-bin/whisper.py19
22 files changed, 7 insertions, 363 deletions
diff --git a/cgi-bin/.whisper.py.un~ b/cgi-bin/.whisper.py.un~
deleted file mode 100644
index 4f409c2..0000000
--- a/cgi-bin/.whisper.py.un~
+++ /dev/null
Binary files differ
diff --git a/cgi-bin/__pycache__/path.cpython-36.pyc b/cgi-bin/__pycache__/path.cpython-36.pyc
index c1e0d7b..11d1331 100644
--- a/cgi-bin/__pycache__/path.cpython-36.pyc
+++ b/cgi-bin/__pycache__/path.cpython-36.pyc
Binary files differ
diff --git a/cgi-bin/add.py b/cgi-bin/add.py
deleted file mode 100644
index e3a7d4e..0000000
--- a/cgi-bin/add.py
+++ /dev/null
@@ -1,63 +0,0 @@
-#!D:/Programs/Python3/python.exe
-# -*- coding: utf-8 -*-
-import cgi, cgitb
-import pymysql
-import sys, codecs
-import configparser, codecs
-import connect
-from connect import Connect
-import config
-from config import Config
-import path
-from path import Path
-import time
-
-sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
-print("Content-type:text/html\n")
-
-form = cgi.FieldStorage()
-action = form.getvalue('action')
-if action == "modify":
- whisper_content = form.getvalue('whisper_content')
- if whisper_content == None:
- whisper_content = ""
- whisper_id = form.getvalue('whisper_id')
- db = Connect.produce()
- cursor = db.cursor()
- query = "update whisper set content = '{0}' where id = {1}".format(pymysql.escape_string(whisper_content), whisper_id)
- cursor.execute(query)
- db.commit()
- cursor.close()
- db.close()
- _url = Config.get("route", "url")
- redirect = """
- <html>
- <head>
- <meta http-equiv="refresh" content="0;url={0}/page.py">
- </head>
- </html>
- """.format(_url)
- print(redirect)
-elif action == "new":
- whisper_content = form.getvalue('whisper_content')
- if whisper_content == None:
- whisper_content = ""
- t = time.time()
- db = Connect.produce()
- cursor = db.cursor()
- query = "insert into whisper (content, date) values ('{0}', '{1}')".format(pymysql.escape_string(whisper_content), t)
- cursor.execute(query)
- db.commit()
- cursor.close()
- db.close()
- _url = Config.get("route", "url")
- redirect = """
- <html>
- <head>
- <meta http-equiv="refresh" content="0;url={0}/page.py">
- </head>
- </html>
- """.format(_url)
- print(redirect)
-else:
- print("Invalid action") \ No newline at end of file
diff --git a/cgi-bin/config.ini b/cgi-bin/config.ini
deleted file mode 100644
index 7dfc0e1..0000000
--- a/cgi-bin/config.ini
+++ /dev/null
@@ -1,13 +0,0 @@
-[route]
-url=/cgi-bin
-static=/html
-images=/html/imgs
-templates=./template
-[database]
-user=root
-passwd=root
-host=localhost
-port=3306
-db=whisper
-[config]
-whisper_count=15
diff --git a/cgi-bin/config.py b/cgi-bin/config.py
deleted file mode 100644
index 539ed6c..0000000
--- a/cgi-bin/config.py
+++ /dev/null
@@ -1,10 +0,0 @@
-# -*- coding: utf-8 -*-
-import configparser, codecs, sys
-
-conf = configparser.ConfigParser()
-conf.read("config.ini")
-
-class Config(object):
- @classmethod
- def get(cls, section, option):
- return conf.get(section, option)
diff --git a/cgi-bin/connect.py b/cgi-bin/connect.py
deleted file mode 100644
index 09c1942..0000000
--- a/cgi-bin/connect.py
+++ /dev/null
@@ -1,13 +0,0 @@
-import pymysql
-import config
-from config import Config
-
-host = Config.get("database", "host")
-port = Config.get("database", "port")
-user = Config.get("database", "user")
-passwd = Config.get("database", "passwd")
-db = Config.get("database", "db")
-class Connect(object):
- def produce():
- return pymysql.connect(host, user, passwd, db)
-
diff --git a/cgi-bin/delete.py b/cgi-bin/delete.py
deleted file mode 100644
index 7c728a4..0000000
--- a/cgi-bin/delete.py
+++ /dev/null
@@ -1,36 +0,0 @@
-#!D:/Programs/Python3/python.exe
-# -*- coding: utf-8 -*-
-import cgi, cgitb
-import pymysql
-import sys, codecs
-import configparser, codecs
-import connect
-from connect import Connect
-import config
-from config import Config
-import path
-from path import Path
-
-sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
-print("Content-type:text/html\n")
-form = cgi.FieldStorage()
-w = form.getvalue('w')
-if w == None:
- print("Invalid whisper")
-else:
- db = Connect.produce()
- cursor = db.cursor()
- query = "delete from whisper where id={0}".format(int(w))
- cursor.execute(query)
- db.commit()
- cursor.close()
- db.close()
- _url = Config.get("route", "url")
- redirect = """
- <html>
- <head>
- <meta http-equiv="refresh" content="0;url={0}/page.py">
- </head>
- </html>
- """.format(_url)
- print(redirect) \ No newline at end of file
diff --git a/cgi-bin/edit.py b/cgi-bin/edit.py
deleted file mode 100644
index b0a899d..0000000
--- a/cgi-bin/edit.py
+++ /dev/null
@@ -1,46 +0,0 @@
-#!D:/Programs/Python3/python.exe
-# -*- coding: utf-8 -*-
-import cgi, cgitb
-import pymysql
-import sys, codecs
-import configparser, codecs
-import connect
-from connect import Connect
-import config
-from config import Config
-import path
-from path import Path
-
-sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
-print("Content-type:text/html\n")
-form = cgi.FieldStorage()
-w = form.getvalue('w')
-if w == None:
- print("Invalid whisper")
-else:
- db = Connect.produce()
- cursor = db.cursor()
-
- query_whisper = "select * from whisper where id={0}".format(w)
- cursor.execute(query_whisper)
- whisper = cursor.fetchone()
-
- edit_file = open(Path.template("edit.html"), 'r', encoding="utf8")
- edit_templ = edit_file.read()
- edit_file.close()
-
- _url = Config.get("route", "url")
- _static = Config.get("route", "static")
-
- edit_html = edit_templ.format( \
- url = _url,
- static = _static,
- whisper_id = w,
- whisper_content = whisper[1]
- )
-
- print(edit_html)
-
- db.commit()
- cursor.close()
- db.close()
diff --git a/cgi-bin/html/ckeditor/config.js b/cgi-bin/html/ckeditor/config.js
index 048198a..39a6e85 100644
--- a/cgi-bin/html/ckeditor/config.js
+++ b/cgi-bin/html/ckeditor/config.js
@@ -35,6 +35,7 @@ CKEDITOR.editorConfig = function( config ) {
// Simplify the dialog windows.
config.removeDialogTabs = 'image:advanced;link:advanced';
- config.filebrowserImageUploadUrl = "/cgi-bin/";
+ config.filebrowserImageUploadUrl = "/chai/whisper/imguploader.py";
config.height = 100;
+ config.image_prefillDimensions = false;
};
diff --git a/cgi-bin/html/imgs/1531471283.png b/cgi-bin/html/imgs/1531471283.png
new file mode 100644
index 0000000..0d11f85
--- /dev/null
+++ b/cgi-bin/html/imgs/1531471283.png
Binary files differ
diff --git a/cgi-bin/html/imgs/1531471337.png b/cgi-bin/html/imgs/1531471337.png
new file mode 100644
index 0000000..0d11f85
--- /dev/null
+++ b/cgi-bin/html/imgs/1531471337.png
Binary files differ
diff --git a/cgi-bin/html/imgs/1531471469.jpg b/cgi-bin/html/imgs/1531471469.jpg
new file mode 100644
index 0000000..5932b51
--- /dev/null
+++ b/cgi-bin/html/imgs/1531471469.jpg
Binary files differ
diff --git a/cgi-bin/html/imgs/1531471899.jpg b/cgi-bin/html/imgs/1531471899.jpg
new file mode 100644
index 0000000..5932b51
--- /dev/null
+++ b/cgi-bin/html/imgs/1531471899.jpg
Binary files differ
diff --git a/cgi-bin/html/imgs/1531471931.png b/cgi-bin/html/imgs/1531471931.png
new file mode 100644
index 0000000..0d11f85
--- /dev/null
+++ b/cgi-bin/html/imgs/1531471931.png
Binary files differ
diff --git a/cgi-bin/html/style.css b/cgi-bin/html/style.css
index d3b9e3f..f9525f0 100644
--- a/cgi-bin/html/style.css
+++ b/cgi-bin/html/style.css
@@ -56,6 +56,11 @@
color : #3ea17c;
}
+.whisper_content img
+{
+ max-width: 100%;
+}
+
#pagejump_next
{
float:right;
diff --git a/cgi-bin/page.py b/cgi-bin/page.py
deleted file mode 100644
index b776d8e..0000000
--- a/cgi-bin/page.py
+++ /dev/null
@@ -1,75 +0,0 @@
-#!D:/Programs/Python3/python.exe
-# -*- coding: utf-8 -*-
-import cgi, cgitb
-import pymysql
-import sys, codecs
-import configparser, codecs
-import connect
-from connect import Connect
-import whisper
-from whisper import Whisper
-import config
-from config import Config
-import path
-from path import Path
-
-sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
-
-_url = Config.get("route", "url")
-_static = Config.get("route", "static")
-_whiperperpage = int(Config.get("config", "whisper_count"))
-
-page_file = open(Path.template("page.html"), 'r', encoding="utf8")
-page_templ = page_file.read()
-page_file.close()
-
-pagen = cgi.FieldStorage().getvalue('p')
-if pagen == None:
- pagen = 0
-else:
- pagen = int(pagen)
-pageprev = pagen - 1
-if pageprev < 0:
- pageprev = 0
-pagenext = pagen + 1
-
-# class PageBuilder(object):
-# def build(pagen):
-print("Content-type:text/html\n")
-
-db = Connect.produce()
-cursor = db.cursor()
-
-query_count = "select COUNT(*) from whisper"
-cursor.execute(query_count)
-whispercount = cursor.fetchone()
-whispercount = whispercount[0]
-
-query_allwhisper = "select * from whisper ORDER BY id DESC LIMIT {0}, {1}".format(pagen * _whiperperpage, _whiperperpage)
-cursor.execute(query_allwhisper)
-
-_whispers = ""
-whispersdata = cursor.fetchall()
-odd = True
-count = 0
-for whisper in whispersdata:
- count = count + 1
- _whispers += Whisper.build(whisper[0], whisper[1], whisper[2], odd, _url)
- odd = not odd
-
-if pagen * _whiperperpage + count >= whispercount:
- pagenext = pagen
-
-page = page_templ.format(\
- url = _url,
- static = _static,
- whispers = _whispers,
- page_prev = pageprev,
- page_next = pagenext
-)
-
-print(page)
-
-db.commit()
-cursor.close()
-db.close()
diff --git a/cgi-bin/path.py b/cgi-bin/path.py
deleted file mode 100644
index e4ad756..0000000
--- a/cgi-bin/path.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# -*- coding: utf-8 -*-
-import config
-from config import Config
-
-root = Config.get("route", "url")
-imgsDir = Config.get("route", "images")
-templDir = Config.get("route", "templates")
-
-class Path(object):
- # 拼接url
- def url(path):
- return root + '/' + path
-
- # 保存的图片路径
- def img(imgFile):
- return root + imgsDir + '/' + imgFile
-
- # html模板路径
- def template(templ):
- return templDir + '/' + templ
diff --git a/cgi-bin/template/.whisper.html.un~ b/cgi-bin/template/.whisper.html.un~
deleted file mode 100644
index 70eaf48..0000000
--- a/cgi-bin/template/.whisper.html.un~
+++ /dev/null
Binary files differ
diff --git a/cgi-bin/template/edit.html b/cgi-bin/template/edit.html
deleted file mode 100644
index bc8cea0..0000000
--- a/cgi-bin/template/edit.html
+++ /dev/null
@@ -1,20 +0,0 @@
-<html>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>whisper</title>
-<body>
-<link rel="stylesheet" href="{url}{static}/style.css" type="text/css" />
-<script src="{url}{static}/ckeditor/ckeditor.js"></script>
-<div id="container">
- <img src="{url}{static}/logo.png" id="logo"/>
- <br/>
- <form action="{url}/add.py?action=modify" method="post" class="form_add">
- <input type="hidden" name="whisper_id" value="{whisper_id}"/>
- <textarea name="whisper_content" id="editor" class="ckeditor" rows="5" cols="20">
- {whisper_content}
- </textarea>
- <input type="submit" value=" 推 " class="submit"/>
- <a style="float:right; color:red" href="{url}/delete.py?w={whisper_id}">删除</a>
- </form>
-</div>
-</body>
-</html> \ No newline at end of file
diff --git a/cgi-bin/template/page.html b/cgi-bin/template/page.html
deleted file mode 100644
index 672be2c..0000000
--- a/cgi-bin/template/page.html
+++ /dev/null
@@ -1,37 +0,0 @@
-<html>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>whisper</title>
-<body>
-<link rel="stylesheet" href="{url}{static}/style.css" type="text/css" />
-<script src="{url}{static}/ckeditor/ckeditor.js"></script>
-<script>
-window.onload = function()
-{{
- var dates = document.getElementsByClassName("whisper_date");
- for(var i = 0; i < dates.length; i++)
- {{
- var d = dates[i];
- var tstamp = parseInt(d.getAttribute("date"));
- var day = new Date(tstamp * 1000);
- var timestr = day.toLocaleString();
- d.innerHTML = timestr;
- }}
-}}
-</script>
-<div id="container">
- <img src="{url}{static}/logo.png" id="logo"/>
- <br/>
- <form action="{url}/add.py?action=new" method="post" class="form_add">
- <textarea name="whisper_content" id="editor" class="ckeditor" rows="5" cols="20">
- </textarea>
- <input type="submit" value=" 推 " class="submit"/>
- </form>
- <!--whispers-->
- {whispers}
- <!--whispers end-->
- <br/>
- <a href="{url}/page.py?p={page_prev}" id="pagejump_prev" class="pagejump"><上一页</a>
- <a href="{url}/page.py?p={page_next}" id="pagejump_next" class="pagejump">下一页></a>
-</div>
-</body>
-</html>
diff --git a/cgi-bin/template/whisper.html b/cgi-bin/template/whisper.html
deleted file mode 100644
index ae7ede4..0000000
--- a/cgi-bin/template/whisper.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<div class="whisper_unit whisper_unit_{oddoreven}">
- <div class="whisper_content">
- {content}
- </div>
- <div class="whisper_date" date="{date}"></div>
- <div class="whisper_edit">
- <a href="{url}/edit.py?w={id}">[编辑]</a>
- </div>
- <div style="clear:both"></div>
-</div>
diff --git a/cgi-bin/whisper.py b/cgi-bin/whisper.py
deleted file mode 100644
index aec20b6..0000000
--- a/cgi-bin/whisper.py
+++ /dev/null
@@ -1,19 +0,0 @@
-import path
-from path import Path
-import connect
-from connect import Connect
-
-whisper_file = open(Path.template("whisper.html"), 'r', encoding="utf8")
-whisper_templ = whisper_file.read()
-whisper_file.close()
-
-class Whisper(object):
- def build(_id, _content, _date, _odd, _url):
- whisper = whisper_templ.format(\
- oddoreven=((_odd == True) and "odd" or "even"),\
- content=_content,\
- date=_date,\
- url=_url,\
- id=_id\
- )
- return whisper