├── logs
└── README.md
├── lualib
├── Cache
│ └── init.lua
├── DB
│ └── init.lua
├── httpc
│ └── ua.lua
├── template
│ ├── init.lua
│ └── html.lua
├── cloud
│ ├── tencent
│ │ ├── location.lua
│ │ └── ai.lua
│ ├── README.md
│ ├── qiniu
│ │ ├── oss.lua
│ │ ├── crypt.lua
│ │ ├── ocr.lua
│ │ └── censor.lua
│ ├── translate
│ │ ├── youdao.lua
│ │ └── baidu.lua
│ ├── location
│ │ ├── amap.lua
│ │ └── baidu.lua
│ └── paypal
│ │ └── payment.lua
├── admin
│ ├── html
│ │ ├── dashboard
│ │ │ ├── action.html
│ │ │ ├── base.html
│ │ │ ├── content.html
│ │ │ ├── head.html
│ │ │ └── header.html
│ │ ├── redirect.html
│ │ ├── login
│ │ │ ├── base.html
│ │ │ ├── head.html
│ │ │ └── content.html
│ │ ├── deny.html
│ │ └── 404.html
│ ├── db
│ │ ├── README.md
│ │ ├── view.lua
│ │ ├── permission.lua
│ │ ├── init.lua
│ │ ├── header.lua
│ │ └── token.lua
│ ├── locales
│ │ └── init.lua
│ ├── README.md
│ ├── config.lua
│ ├── cookie.lua
│ ├── token.lua
│ ├── http
│ │ └── system
│ │ │ └── init.lua
│ ├── httpctx.lua
│ └── utils
│ │ └── init.lua
├── protocol
│ ├── mqtt
│ │ ├── bit.lua
│ │ ├── bit53.lua
│ │ └── tools.lua
│ └── http
│ │ └── parser.lua
├── process
│ ├── utils.lua
│ ├── dataset.lua
│ ├── event.lua
│ ├── worker.lua
│ ├── session.lua
│ └── master.lua
├── crypt
│ ├── dh.lua
│ ├── checksum.lua
│ ├── id.lua
│ ├── rc4.lua
│ ├── init.lua
│ ├── utils.lua
│ ├── b64.lua
│ └── sha.lua
├── README.md
├── msgpack.lua
├── json
│ ├── jsonp.lua
│ └── init.lua
├── class
│ └── meta.lua
├── httpd
│ ├── Throw.lua
│ ├── Redirect.lua
│ ├── http.lua
│ ├── Response.lua
│ └── Form.lua
├── xml2lua
│ ├── init.lua
│ └── xmlhandler
│ │ └── README.md
├── protobuf
│ └── init.lua
├── mail
│ └── init.lua
├── csv.lua
└── internal
│ └── UDP.lua
├── Person.pb
├── static
├── favicon.ico
├── images
│ ├── bg.png
│ └── logo.png
├── fonts
│ ├── iconfont.eot
│ ├── iconfont.ttf
│ └── iconfont.woff
├── lib
│ └── layui
│ │ ├── font
│ │ ├── iconfont.eot
│ │ ├── iconfont.ttf
│ │ ├── iconfont.woff
│ │ └── iconfont.woff2
│ │ ├── images
│ │ └── face
│ │ │ ├── 0.gif
│ │ │ ├── 1.gif
│ │ │ ├── 2.gif
│ │ │ ├── 3.gif
│ │ │ ├── 4.gif
│ │ │ ├── 5.gif
│ │ │ ├── 6.gif
│ │ │ ├── 7.gif
│ │ │ ├── 8.gif
│ │ │ ├── 9.gif
│ │ │ ├── 10.gif
│ │ │ ├── 11.gif
│ │ │ ├── 12.gif
│ │ │ ├── 13.gif
│ │ │ ├── 14.gif
│ │ │ ├── 15.gif
│ │ │ ├── 16.gif
│ │ │ ├── 17.gif
│ │ │ ├── 18.gif
│ │ │ ├── 19.gif
│ │ │ ├── 20.gif
│ │ │ ├── 21.gif
│ │ │ ├── 22.gif
│ │ │ ├── 23.gif
│ │ │ ├── 24.gif
│ │ │ ├── 25.gif
│ │ │ ├── 26.gif
│ │ │ ├── 27.gif
│ │ │ ├── 28.gif
│ │ │ ├── 29.gif
│ │ │ ├── 30.gif
│ │ │ ├── 31.gif
│ │ │ ├── 32.gif
│ │ │ ├── 33.gif
│ │ │ ├── 34.gif
│ │ │ ├── 35.gif
│ │ │ ├── 36.gif
│ │ │ ├── 37.gif
│ │ │ ├── 38.gif
│ │ │ ├── 39.gif
│ │ │ ├── 40.gif
│ │ │ ├── 41.gif
│ │ │ ├── 42.gif
│ │ │ ├── 43.gif
│ │ │ ├── 44.gif
│ │ │ ├── 45.gif
│ │ │ ├── 46.gif
│ │ │ ├── 47.gif
│ │ │ ├── 48.gif
│ │ │ ├── 49.gif
│ │ │ ├── 50.gif
│ │ │ ├── 51.gif
│ │ │ ├── 52.gif
│ │ │ ├── 53.gif
│ │ │ ├── 54.gif
│ │ │ ├── 55.gif
│ │ │ ├── 56.gif
│ │ │ ├── 57.gif
│ │ │ ├── 58.gif
│ │ │ ├── 59.gif
│ │ │ ├── 60.gif
│ │ │ ├── 61.gif
│ │ │ ├── 62.gif
│ │ │ ├── 63.gif
│ │ │ ├── 64.gif
│ │ │ ├── 65.gif
│ │ │ ├── 66.gif
│ │ │ ├── 67.gif
│ │ │ ├── 68.gif
│ │ │ ├── 69.gif
│ │ │ ├── 70.gif
│ │ │ └── 71.gif
│ │ ├── css
│ │ └── modules
│ │ │ ├── layer
│ │ │ └── default
│ │ │ │ ├── icon.png
│ │ │ │ ├── icon-ext.png
│ │ │ │ ├── loading-0.gif
│ │ │ │ ├── loading-1.gif
│ │ │ │ └── loading-2.gif
│ │ │ └── code.css
│ │ └── lay
│ │ └── modules
│ │ ├── code.js
│ │ ├── laytpl.js
│ │ ├── flow.js
│ │ └── rate.js
├── layui_ext
│ └── dtree
│ │ └── font
│ │ ├── dtreefont.eot
│ │ ├── dtreefont.ttf
│ │ └── dtreefont.woff
├── index.html
└── css
│ ├── theme2.css
│ ├── theme1.css
│ ├── theme3.css
│ ├── theme4.css
│ ├── print.min.css
│ ├── font.css
│ ├── theme5.css
│ └── login.css
├── luaclib
├── src
│ ├── lpeg
│ │ ├── lpeg-128.gif
│ │ ├── makefile
│ │ ├── lpprint.h
│ │ ├── lpcode.h
│ │ ├── lpvm.h
│ │ ├── lpcap.h
│ │ └── lptree.h
│ ├── lcjson
│ │ ├── THANKS
│ │ ├── fpconv.h
│ │ ├── Makefile
│ │ ├── LICENSE
│ │ └── NEWS
│ ├── lfs
│ │ ├── Makefile
│ │ └── lfs.h
│ ├── lmsgpack
│ │ └── Makefile
│ ├── lpbc
│ │ └── Makefile
│ ├── lhttpparser
│ │ └── Makefile
│ ├── lz
│ │ └── Makefile
│ ├── lcrypt
│ │ ├── Makefile
│ │ ├── uuid.c
│ │ ├── url.c
│ │ ├── lcrypt.h
│ │ └── sha.c
│ ├── lchild.c
│ ├── ltimer.c
│ └── ltask.c
└── Makefile
├── Excel.csv
├── script
├── admin
│ ├── init.lua
│ ├── r1.lua
│ ├── r2.lua
│ └── r3.lua
├── test_csv.lua
├── test_msgpack.lua
├── test_lua_table.lua
├── api.lua
├── test_mail.lua
├── test_wsclient.lua
├── test_cf.lua
├── test_http_auth.lua
├── test_protobuf.lua
├── test_MQ.lua
├── test_translate.lua
├── test_lfs.lua
├── test_logging.lua
├── test_xml.lua
├── test_es.lua
├── test_system.lua
├── ws.lua
├── test_DB.lua
├── test_dingtalk.lua
├── test_dns.lua
├── test_zlib.lua
├── test_upload.lua
└── test_cfadmin.lua
├── public1024.pem
├── clean.sh
├── Person.proto
├── src
├── core.h
├── core_sys.c
├── core_memory.h
├── core_memory.c
├── Makefile
└── core_sys.h
├── docker
├── Dockerfile
├── docker-compose-with-cfadmin.yaml
├── script
│ └── ws.lua
├── docker-compose-with-traefik.yaml
├── conf.d
│ └── nginx.conf
└── docker-compose-with-nginx.yaml
├── public2048.pem
├── 3rd
├── Makefile
└── README.md
├── POST_FILE.html
├── Dockerfile
├── .gitignore
├── public4096.pem
├── Makefile
├── private1024.pem
├── LICENSE
└── private2048.pem
/logs/README.md:
--------------------------------------------------------------------------------
1 | ## 日志文件夹
2 |
3 | > 日志将会自动按照日期切割
4 |
--------------------------------------------------------------------------------
/lualib/Cache/init.lua:
--------------------------------------------------------------------------------
1 | return require "Cache.redis"
--------------------------------------------------------------------------------
/lualib/DB/init.lua:
--------------------------------------------------------------------------------
1 | return require "DB.mysql"
2 |
--------------------------------------------------------------------------------
/lualib/httpc/ua.lua:
--------------------------------------------------------------------------------
1 | return require "protocol.http.ua"
--------------------------------------------------------------------------------
/lualib/template/init.lua:
--------------------------------------------------------------------------------
1 | return require "template.new".new(false)
--------------------------------------------------------------------------------
/Person.pb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/Person.pb
--------------------------------------------------------------------------------
/lualib/cloud/tencent/location.lua:
--------------------------------------------------------------------------------
1 | return require "cloud.location.tencent"
2 |
--------------------------------------------------------------------------------
/lualib/admin/html/dashboard/action.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/favicon.ico
--------------------------------------------------------------------------------
/static/images/bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/images/bg.png
--------------------------------------------------------------------------------
/static/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/images/logo.png
--------------------------------------------------------------------------------
/static/fonts/iconfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/fonts/iconfont.eot
--------------------------------------------------------------------------------
/static/fonts/iconfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/fonts/iconfont.ttf
--------------------------------------------------------------------------------
/static/fonts/iconfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/fonts/iconfont.woff
--------------------------------------------------------------------------------
/luaclib/src/lpeg/lpeg-128.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/luaclib/src/lpeg/lpeg-128.gif
--------------------------------------------------------------------------------
/static/lib/layui/font/iconfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/font/iconfont.eot
--------------------------------------------------------------------------------
/static/lib/layui/font/iconfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/font/iconfont.ttf
--------------------------------------------------------------------------------
/static/lib/layui/images/face/0.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/0.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/1.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/2.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/3.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/4.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/4.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/5.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/5.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/6.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/6.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/7.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/7.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/8.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/8.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/9.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/9.gif
--------------------------------------------------------------------------------
/lualib/admin/db/README.md:
--------------------------------------------------------------------------------
1 | # db
2 |
3 | ## view
4 |
5 | dashboard视图的sql
6 |
7 | ## user
8 |
9 | user的sql
10 |
--------------------------------------------------------------------------------
/static/lib/layui/font/iconfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/font/iconfont.woff
--------------------------------------------------------------------------------
/static/lib/layui/font/iconfont.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/font/iconfont.woff2
--------------------------------------------------------------------------------
/static/lib/layui/images/face/10.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/10.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/11.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/11.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/12.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/12.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/13.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/13.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/14.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/14.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/15.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/15.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/16.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/16.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/17.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/17.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/18.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/18.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/19.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/19.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/20.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/20.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/21.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/21.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/22.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/22.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/23.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/23.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/24.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/24.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/25.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/25.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/26.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/26.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/27.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/27.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/28.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/28.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/29.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/29.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/30.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/30.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/31.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/31.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/32.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/32.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/33.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/33.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/34.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/34.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/35.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/35.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/36.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/36.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/37.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/37.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/38.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/38.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/39.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/39.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/40.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/40.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/41.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/41.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/42.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/42.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/43.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/43.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/44.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/44.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/45.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/45.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/46.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/46.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/47.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/47.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/48.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/48.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/49.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/49.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/50.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/50.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/51.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/51.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/52.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/52.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/53.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/53.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/54.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/54.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/55.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/55.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/56.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/56.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/57.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/57.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/58.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/58.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/59.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/59.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/60.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/60.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/61.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/61.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/62.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/62.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/63.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/63.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/64.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/64.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/65.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/65.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/66.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/66.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/67.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/67.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/68.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/68.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/69.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/69.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/70.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/70.gif
--------------------------------------------------------------------------------
/static/lib/layui/images/face/71.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/images/face/71.gif
--------------------------------------------------------------------------------
/static/layui_ext/dtree/font/dtreefont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/layui_ext/dtree/font/dtreefont.eot
--------------------------------------------------------------------------------
/static/layui_ext/dtree/font/dtreefont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/layui_ext/dtree/font/dtreefont.ttf
--------------------------------------------------------------------------------
/static/layui_ext/dtree/font/dtreefont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/layui_ext/dtree/font/dtreefont.woff
--------------------------------------------------------------------------------
/Excel.csv:
--------------------------------------------------------------------------------
1 | ID,Name,Des,Model,
2 | 1,广告,www.baidu.com,csv.png,1.1
3 | 2,公告,www.notice.com,notice.png,2.1
4 | 3,测试,www.test.com,test.png,3.1
5 |
--------------------------------------------------------------------------------
/lualib/protocol/mqtt/bit.lua:
--------------------------------------------------------------------------------
1 | -- wrapper around BitOp module
2 | return require("protocol.mqtt.bit53")
3 |
4 | -- vim: ts=4 sts=4 sw=4 noet ft=lua
5 |
--------------------------------------------------------------------------------
/lualib/admin/locales/init.lua:
--------------------------------------------------------------------------------
1 | return {
2 | ["ZH-CN"] = require "admin.locales.ZH-CN", -- 中文
3 | ["EN-US"] = require "admin.locales.EN-US", -- 英文
4 | }
5 |
--------------------------------------------------------------------------------
/static/lib/layui/css/modules/layer/default/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/css/modules/layer/default/icon.png
--------------------------------------------------------------------------------
/static/lib/layui/css/modules/layer/default/icon-ext.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/css/modules/layer/default/icon-ext.png
--------------------------------------------------------------------------------
/static/lib/layui/css/modules/layer/default/loading-0.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/css/modules/layer/default/loading-0.gif
--------------------------------------------------------------------------------
/static/lib/layui/css/modules/layer/default/loading-1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/css/modules/layer/default/loading-1.gif
--------------------------------------------------------------------------------
/static/lib/layui/css/modules/layer/default/loading-2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cfadmin-cn/cfadmin/HEAD/static/lib/layui/css/modules/layer/default/loading-2.gif
--------------------------------------------------------------------------------
/lualib/admin/html/redirect.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/lualib/admin/README.md:
--------------------------------------------------------------------------------
1 | ## admin库
2 |
3 | admin是cf内置的web后台管理模板库, 目的是为使用者快速构建后台基于web的管理系统.
4 |
5 | ## 基准
6 |
7 | 详情清参考[这里](https://candymi.github.io/LuaWeb/wiki/Benchmark.html)
8 |
--------------------------------------------------------------------------------
/script/admin/init.lua:
--------------------------------------------------------------------------------
1 | return {
2 | {route = '/r1', class = require "admin.r1"},
3 | {route = '/r2', class = require "admin.r2"},
4 | {route = '/r3', class = require "admin.r3"},
5 | }
--------------------------------------------------------------------------------
/lualib/process/utils.lua:
--------------------------------------------------------------------------------
1 | local utils = {}
2 |
3 | function utils.copy(tab)
4 | local t = {}
5 | for k, v in pairs(tab) do
6 | t[k] = v
7 | end
8 | return t
9 | end
10 |
11 | return utils
--------------------------------------------------------------------------------
/script/test_csv.lua:
--------------------------------------------------------------------------------
1 | local csv = require "csv"
2 |
3 | local LOG = require("logging")
4 |
5 | LOG:DEBUG(csv.loadfile("./Excel.csv"))
6 |
7 | LOG:DEBUG(csv.writefile("./Excel-1.csv", csv.loadfile("./Excel.csv")))
8 |
--------------------------------------------------------------------------------
/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | This is cf web framework!
9 |
10 |
11 |
--------------------------------------------------------------------------------
/script/test_msgpack.lua:
--------------------------------------------------------------------------------
1 | local Log = require ("logging"):new()
2 |
3 | local msgpack = require "msgpack"
4 |
5 | local msg = msgpack.encode({1, 2, 3, 4, name = "CandyMi"})
6 | Log:DEBUG("序列化完成:"..msg)
7 |
8 | Log:DEBUG(msgpack.decode(msg))
9 |
--------------------------------------------------------------------------------
/script/admin/r1.lua:
--------------------------------------------------------------------------------
1 | local class = require "class"
2 |
3 |
4 | local r1 = class("r1")
5 |
6 | function r1:ctor(opt)
7 |
8 | end
9 |
10 | function r1:get()
11 | return 'this request build-in '..self.__name
12 | end
13 |
14 | return r1
--------------------------------------------------------------------------------
/script/admin/r2.lua:
--------------------------------------------------------------------------------
1 | local class = require "class"
2 |
3 |
4 | local r2 = class("r2")
5 |
6 | function r2:ctor(opt)
7 |
8 | end
9 |
10 | function r2:get()
11 | return 'this request build-in '..self.__name
12 | end
13 |
14 | return r2
--------------------------------------------------------------------------------
/script/admin/r3.lua:
--------------------------------------------------------------------------------
1 | local class = require "class"
2 |
3 |
4 | local r3 = class("r3")
5 |
6 | function r3:ctor(opt)
7 |
8 | end
9 |
10 | function r3:get()
11 | return 'this request build-in '..self.__name
12 | end
13 |
14 | return r3
--------------------------------------------------------------------------------
/luaclib/src/lcjson/THANKS:
--------------------------------------------------------------------------------
1 | The following people have helped with bug reports, testing and/or
2 | suggestions:
3 |
4 | - Louis-Philippe Perron (@loopole)
5 | - Ondřej Jirman
6 | - Steve Donovan
7 | - Zhang "agentzh" Yichun
8 |
9 | Thanks!
10 |
--------------------------------------------------------------------------------
/public1024.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDc84CClRm5VqlzhvG7Izfff/VB
3 | hycuhxYEubSQp6NXT8virjlpe/g0dW94d1UENsEZYiLxepVwkHKNjxlbKMiLTjk+
4 | hs+S2g6U7bIbFLClZAdD9Bf+wuKD5YUUX7cRLzFEIFCNLn9E7HZ6/8iRkMtMmZf6
5 | Dx0LG/WmZ3WN1CnqwwIDAQAB
6 | -----END PUBLIC KEY-----
7 |
--------------------------------------------------------------------------------
/lualib/cloud/README.md:
--------------------------------------------------------------------------------
1 | # 云平台Lua SDK
2 |
3 | 框架提供一部分云平台服务调用的内置Lua版SDK.
4 |
5 | ## 七牛 SDK
6 |
7 | * 存储服务
8 |
9 | * 短信服务
10 |
11 | * 内容审核
12 |
13 | * 直播服务
14 |
15 | ## 腾讯 SDK
16 |
17 | * 位置服务
18 |
19 | ## paypal SDK
20 |
21 | * 支付业务
22 |
23 | ## 翻译SDK
24 |
25 | * 百度翻译
26 |
27 | * 有道翻译
--------------------------------------------------------------------------------
/lualib/admin/html/login/base.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | {(lualib/admin/html/login/head.html)}
4 |
5 |
6 | {(lualib/admin/html/login/content.html)}
7 | {(lualib/admin/html/login//action.html)}
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/clean.sh:
--------------------------------------------------------------------------------
1 | # This script is used to clean up build.sh to install the header files and library files brought by libev and lua. You can ignore this file when you already have lua and libev in your environment.
2 | # 此脚本为清理build.sh安装libev与lua带来的头文件与库文件, 当您的环境中已经有了lua与libev后可以忽略此文件.
3 |
4 | rm -rf libev* libeio* liblua*
5 | rm -rf src/l* src/e*.h
6 |
--------------------------------------------------------------------------------
/Person.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | message Person
4 | {
5 | message Hand
6 | {
7 | string left = 1;
8 | string right = 2;
9 | }
10 | message Foot
11 | {
12 | string left = 1;
13 | string right = 2;
14 | }
15 | string name = 1;
16 | uint32 age = 2;
17 | Hand hand = 3;
18 | Foot foot = 4;
19 | }
20 |
--------------------------------------------------------------------------------
/script/test_lua_table.lua:
--------------------------------------------------------------------------------
1 | -- 0m0.190s
2 | local t = {}
3 | local insert = table.insert
4 | for i = 1, 10000000 do
5 | insert(t, i)
6 | end
7 |
8 | -- 0m1.359s
9 | local t = {}
10 | for i = 1, 10000000 do
11 | t[#t+1] = i
12 | end
13 |
14 | -- 0m0.666s
15 | local t = {}
16 | local insert = table.insert
17 | for i = 1, 10000 do
18 | insert(t, 1, i)
19 | end
20 |
--------------------------------------------------------------------------------
/lualib/cloud/qiniu/oss.lua:
--------------------------------------------------------------------------------
1 | local token = require "cloud.qiniu.token"
2 |
3 | local oss = { __Version__ = 0.1, getUploadToken = token.getUploadToken, getDownloadToken = token.getDownloadToken }
4 |
5 | --[[
6 | 此为七牛云对象存储服务的上传与下载Token生成库的原生lua实现.
7 | 此库实现了服务端根据指定算法生成临时上传/下载的授权Token后交由客户端上传文件, 服务端不负责具体业务.
8 | 具体使用方法请参考: https://developer.qiniu.com/kodo/manual/1644/security
9 | ]]
10 |
11 | return oss
12 |
--------------------------------------------------------------------------------
/static/css/theme2.css:
--------------------------------------------------------------------------------
1 | body{
2 | background:#EEF5F9;
3 | }
4 | .container{
5 | background:#323640;
6 | }
7 | .left-nav{
8 | background:#fff;
9 | }
10 |
11 | .left-nav a{
12 | color:#686a76;
13 | }
14 | .left-nav a.active{
15 | background: #786AED !important;
16 | color: #fff;
17 | }
18 | .left-nav a:hover{
19 | background: #786AED !important;
20 | color: #fff;
21 | }
22 |
--------------------------------------------------------------------------------
/lualib/admin/config.lua:
--------------------------------------------------------------------------------
1 | local config = {
2 | cdn = '/', -- 静态文件前缀地址
3 | github = 'https://github.com/candymi/core_framework', -- 跳转地址
4 | cache = false, -- 是否缓存模板
5 | locale = "ZH-CN", -- 当前语言
6 | display_lang = true, -- 默认显示语言标签
7 | locales = require "admin.locales", -- 语言表
8 | secure = 'cfadmin', -- 生成token的secure
9 | cookie_timeout = 86400 -- Cookie超时时间
10 | }
11 |
12 | return config
13 |
--------------------------------------------------------------------------------
/lualib/admin/html/dashboard/base.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {(lualib/admin/html/dashboard/head.html)}
5 |
6 |
7 | {(lualib/admin/html/dashboard/header.html)}
8 | {(lualib/admin/html/dashboard/aside.html)}
9 | {(lualib/admin/html/dashboard/content.html)}
10 | {(lualib/admin/html/dashboard/action.html)}
11 |
12 |
13 |
--------------------------------------------------------------------------------
/lualib/cloud/qiniu/crypt.lua:
--------------------------------------------------------------------------------
1 | local crypt = require "crypt"
2 | local base64urlencode = crypt.base64urlencode
3 | local base64urldecode = crypt.base64urldecode
4 |
5 | local Crypt = {
6 | hmac_sha1 = crypt.hmac_sha1,
7 | urlencode = crypt.urlencode,
8 | urldecode = crypt.urldecode,
9 | urlsafe_base64encode = base64urlencode,
10 | urlsafe_base64decode = base64urldecode,
11 | }
12 |
13 | return Crypt
--------------------------------------------------------------------------------
/src/core.h:
--------------------------------------------------------------------------------
1 | #ifndef __CORE_H__
2 | #define __CORE_H__
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | #ifndef _GNU_SOURCE
9 | #define _GNU_SOURCE
10 | #endif
11 |
12 | #include "core_sys.h"
13 | #include "core_memory.h"
14 | #include "core_ev.h"
15 |
16 | #ifdef __cplusplus
17 | }
18 | #endif
19 | static inline void core_exit() {
20 | return _exit(EXIT_FAILURE);
21 | }
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/static/css/theme1.css:
--------------------------------------------------------------------------------
1 | body{
2 | background:#F2F1F2;
3 | }
4 | .container{
5 | background:#1A1B20;
6 | }
7 | .left-nav{
8 | background:#1A1B20;
9 | }
10 |
11 | .left-nav a{
12 | color:rgba(255,255,255,.7);
13 | }
14 | ..left-nav a.active{
15 | background: #009688 !important;
16 | color: #fff;
17 | }
18 | .left-nav a:hover{
19 | background: #009688 !important;
20 | color: #fff;
21 | }
--------------------------------------------------------------------------------
/static/css/theme3.css:
--------------------------------------------------------------------------------
1 | body{
2 | background:#E8E8E8;
3 | }
4 | .container{
5 | background:#F34743;
6 | }
7 |
8 | .left-nav{
9 | background:#F4F4F4;
10 | }
11 |
12 | .left-nav a{
13 | color:#686a76;
14 | }
15 | .left-nav a.active{
16 | background: #FEFEFE !important;
17 | color: #F34743;
18 | }
19 | .left-nav a:hover{
20 | background: #FEFEFE !important;
21 | color: #F34743;
22 | }
--------------------------------------------------------------------------------
/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM centos:7
2 | MAINTAINER CandyMi "869646063@qq.com"
3 |
4 | RUN yum install gcc file autoconf automake make libtool git openssl-devel -y \
5 | && git clone https://github.com/CandyMi/cfadmin.git /app \
6 | && cd /app && sh build.sh && make build \
7 | && rm -rf /var/cache/yum
8 |
9 | # 使用者可在启动容器时使用-v命令将您的代码目录直接挂载到/app/script目录进行调试操作
10 | WORKDIR /app
11 |
12 | ENTRYPOINT ["./cfadmin"]
13 |
--------------------------------------------------------------------------------
/lualib/admin/db/view.lua:
--------------------------------------------------------------------------------
1 | local view = {}
2 |
3 | -- 获取顶部栏
4 | function view.get_headers (db)
5 | return db:query([[SELECT id, name, url FROM cfadmin_headers WHERE active = 1 ORDER BY `id`]])
6 | end
7 |
8 | -- 获取菜单栏
9 | function view.get_menus (db)
10 | return db:query([[SELECT id, parent, name, url, icon, create_at, update_at FROM cfadmin_menus WHERE active = 1 ORDER BY `id`]])
11 | end
12 |
13 | return view
14 |
--------------------------------------------------------------------------------
/static/css/theme4.css:
--------------------------------------------------------------------------------
1 | body{
2 | background:#E4E4E4;
3 | }
4 | .container{
5 | background:#019587;
6 | }
7 | .left-nav{
8 | background:#263035;
9 | }
10 |
11 | .left-nav a{
12 | color:#fff;
13 | }
14 | .left-nav a.active{
15 | background: #212525 !important;
16 | color: #fff !important;
17 | }
18 | .left-nav a:hover{
19 | background: #212525 !important;
20 | color: #fff !important;
21 | }
--------------------------------------------------------------------------------
/lualib/crypt/dh.lua:
--------------------------------------------------------------------------------
1 | local CRYPT = require "lcrypt"
2 | local dhsecret = CRYPT.dhsecret
3 | local dhexchange = CRYPT.dhexchange
4 |
5 | local DH = {}
6 |
7 | function DH.dhsecret (...)
8 | return dhsecret(...)
9 | end
10 |
11 | function DH.dhexchange (...)
12 | return dhexchange(...)
13 | end
14 |
15 | -- 初始化函数
16 | return function (t)
17 | for k, v in pairs(DH) do
18 | t[k] = v
19 | end
20 | return DH
21 | end
--------------------------------------------------------------------------------
/lualib/protocol/mqtt/bit53.lua:
--------------------------------------------------------------------------------
1 | -- implementing some functions from BitOp (http://bitop.luajit.org/) on Lua 5.3
2 |
3 | return {
4 | lshift = function(x, n)
5 | return x << n
6 | end,
7 | rshift = function(x, n)
8 | return x >> n
9 | end,
10 | bor = function(x1, x2)
11 | return x1 | x2
12 | end,
13 | band = function(x1, x2)
14 | return x1 & x2
15 | end,
16 | }
17 |
18 | -- vim: ts=4 sts=4 sw=4 noet ft=lua
19 |
--------------------------------------------------------------------------------
/lualib/README.md:
--------------------------------------------------------------------------------
1 | ## 内置库列表
2 |
3 | * mail库
4 |
5 | * csv库
6 |
7 | * SDK库
8 |
9 | * DB库(MySQL)
10 |
11 | * Cache库(Redis)
12 |
13 | * logging库
14 |
15 | * httpc库
16 |
17 | * MQ库
18 |
19 | * crypt库
20 |
21 | * webhook库
22 |
23 | * json库
24 |
25 | * msgpack库
26 |
27 | * protobuf库
28 |
29 | * template库
30 |
31 | * cf库
32 |
33 | * admin库
34 |
35 | * xml库
36 |
37 | * httpd库
38 |
39 | * system库
--------------------------------------------------------------------------------
/public2048.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuhsl0nR17nqITIkMYqzr
3 | hbT5me5+Q+G387spzR8KWbVujoRFQa6DNzZS8HPNmBW8HjVZJ29uBAAtpWpoERdw
4 | vT31Kag+q9eSpX1d02uTd43cESNTb1bYCYd3LHdPZ9GSH3gIfD/fk2P8zJytzED7
5 | cT1gDUqzCcxi3cvH6/yHb6hmYmNsQo1MLTn3kxyzU32J3nhNEZTlHq1XE9ydqLVq
6 | DCMRPOUuOsXcIb9ASZh3ExSPU2cx+8WMAWWoCw/kO7EJ4Vinl8NDbsRoyXjweekY
7 | Z0bH9YrN4y05KLMhsQhoxBdmKdcJErPwYad17vtmhTpdwEpCriL/iZDLUDOz1G2n
8 | gwIDAQAB
9 | -----END PUBLIC KEY-----
10 |
--------------------------------------------------------------------------------
/static/css/print.min.css:
--------------------------------------------------------------------------------
1 | .printModal{font-family:sans-serif;display:flex;text-align:center;font-weight:300;font-size:30px;left:0;top:0;position:absolute;color:#0460b5;width:100%;height:100%;background-color:hsla(0,0%,100%,.91)}.printClose{position:absolute;right:10px;top:10px}.printClose:before{content:"\00D7";font-family:Helvetica Neue,sans-serif;font-weight:100;line-height:1px;padding-top:.5em;display:block;font-size:2em;text-indent:1px;overflow:hidden;height:1.25em;width:1.25em;text-align:center;cursor:pointer}
--------------------------------------------------------------------------------
/script/api.lua:
--------------------------------------------------------------------------------
1 | local class = require "class"
2 |
3 |
4 | local API = class("API")
5 |
6 | function API:ctor(opt)
7 | self.args = opt.args
8 | self.method = opt.method
9 | self.headers = opt.headers
10 | self.files = opt.files
11 | self.body = opt.body
12 | end
13 |
14 | function API:get()
15 | return '{"code":200,"message":"This is GET method request"}'
16 | end
17 |
18 | function API:post()
19 | return '{"code":200,"message":"This is POST method request"}'
20 | end
21 |
22 | return API
--------------------------------------------------------------------------------
/script/test_mail.lua:
--------------------------------------------------------------------------------
1 | local mail = require "mail"
2 |
3 | local ok, err = mail.send {
4 | host = 'smtp.qq.com', -- 收件服务器
5 | port = 465, -- 收件服务器端口
6 | username = "869646063", -- 用户名
7 | -- password = "qovppnukdbcabcdg", -- 密码或客户端授权码
8 | from = '869646063@qq.com', -- 发件人地址
9 | to = 'xwmrzg@163.com', -- 收件人地址
10 | subject = "测试邮件主题", -- 主题
11 | SSL = true, -- 该端口是否安全连接端口
12 | mime = 'html', -- 不填写该字段则为纯文本, 客户端不会解析html语法
13 | content = "这是一封测试邮件! ", -- 邮件内容
14 | }
15 |
16 | print(ok, err)
--------------------------------------------------------------------------------
/script/test_wsclient.lua:
--------------------------------------------------------------------------------
1 | local wc = require "protocol.websocket.client"
2 |
3 | -- local w = wc:new {url = "wss://[::1]/ws"}
4 | -- local w = wc:new {url = "wss://[::1]:8080/ws"}
5 | local w = wc:new {url = "ws://localhost:8080/ws"}
6 | local ok, ret = w:connect()
7 | if not ok then
8 | return print(ok, ret)
9 | end
10 |
11 | w:ping('ping')
12 |
13 | print(w:recv())
14 |
15 | while 1 do
16 | local data, typ = w:recv()
17 | print(data, typ)
18 | if not data then
19 | break
20 | end
21 | end
22 |
23 | w:close()
24 |
--------------------------------------------------------------------------------
/3rd/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY : build rebuild clean
2 |
3 | default :
4 | @echo "======================================="
5 | @echo "Please use 'make build' command to build it.."
6 | @echo "Please use 'make rebuild' command to build it.."
7 | @echo "Please use 'make clean' command to clean all."
8 | @echo "======================================="
9 |
10 | # 当您使用Make build、rebuild、clean时, 这里会被调用.
11 | # 所以, 您应该定义一套合理的脚本用于3rd内的库进行维护.
12 |
13 | build:
14 | @echo "Done."
15 |
16 | rebuild:
17 | @echo "Done."
18 |
19 | clean:
20 | @echo "Done."
21 |
--------------------------------------------------------------------------------
/lualib/crypt/checksum.lua:
--------------------------------------------------------------------------------
1 | local CRYPT = require "lcrypt"
2 | local crc32 = CRYPT.crc32
3 | local crc64 = CRYPT.crc64
4 | local adler32 = CRYPT.adler32
5 |
6 | local CHECKSUM = {}
7 |
8 | function CHECKSUM.crc32(text)
9 | return crc32(text)
10 | end
11 |
12 | function CHECKSUM.crc64(text)
13 | return crc64(text)
14 | end
15 |
16 | function CHECKSUM.adler32(text)
17 | return adler32(text)
18 | end
19 |
20 | -- 初始化函数
21 | return function (t)
22 | for k, v in pairs(CHECKSUM) do
23 | t[k] = v
24 | end
25 | return CHECKSUM
26 | end
--------------------------------------------------------------------------------
/lualib/process/dataset.lua:
--------------------------------------------------------------------------------
1 | local utils = require "process.utils"
2 | local dataset = {}
3 |
4 | local data = {}
5 |
6 | if master then
7 | data = utils.copy(master)
8 | elseif worker then
9 | data = utils.copy(worker)
10 | else
11 | error("[process error]: Cannot run in single process mode.")
12 | end
13 |
14 | ---comment 获得当前进程的数据
15 | ---@param key any
16 | function dataset.get(key)
17 | return data[key]
18 | end
19 |
20 | ---comment 修改当前进程的数据
21 | ---@param key any
22 | function dataset.set(key, val)
23 | data[key] = val
24 | end
25 |
26 | return dataset
--------------------------------------------------------------------------------
/lualib/msgpack.lua:
--------------------------------------------------------------------------------
1 | local lmsgpack = require "lmsgpack.safe"
2 | local lmsgpack_encode = lmsgpack.pack
3 | local lmsgpack_decode = lmsgpack.unpack
4 |
5 | local msgpack = {}
6 |
7 | -- 序列化
8 | function msgpack.encode (...)
9 | return lmsgpack_encode(...)
10 | end
11 |
12 | -- 反序列化
13 | function msgpack.decode (...)
14 | return lmsgpack_decode(...)
15 | end
16 |
17 | -- 序列化
18 | function msgpack.pack (...)
19 | return lmsgpack_encode(...)
20 | end
21 |
22 | -- 反序列化
23 | function msgpack.unpack (...)
24 | return lmsgpack_decode(...)
25 | end
26 |
27 |
28 | return msgpack
29 |
--------------------------------------------------------------------------------
/static/css/font.css:
--------------------------------------------------------------------------------
1 | @font-face {
2 | font-family: 'iconfont';
3 | src: url('../fonts/iconfont.eot');
4 | src: url('../fonts/iconfont.eot?#iefix') format('embedded-opentype'),
5 | url('../fonts/iconfont.woff') format('woff'),
6 | url('../fonts/iconfont.ttf') format('truetype'),
7 | url('../fonts/iconfont.svg#iconfont') format('svg');
8 | }
9 | .iconfont{
10 | font-family:"iconfont" !important;
11 | font-size:16px;font-style:normal;
12 | -webkit-font-smoothing: antialiased;
13 | -webkit-text-stroke-width: 0.2px;
14 | -moz-osx-font-smoothing: grayscale;
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/lualib/json/jsonp.lua:
--------------------------------------------------------------------------------
1 | local json = require "json"
2 | local json_encode = json.encode
3 | local json_decode = json.decode
4 |
5 | local sub = string.sub
6 | local find = string.find
7 | local concat = table.concat
8 |
9 | local jsonp = {}
10 |
11 | function jsonp.encode(callback_name, tab)
12 | return concat {callback_name, "(", json_encode(tab), ")"}
13 | end
14 |
15 | function jsonp.decode(str)
16 | local s, e = find(str, "%("), find(str, "%)", -1)
17 | if not s or not e or e <= s then
18 | return
19 | end
20 | return json_decode(sub(str, s + 1, e - 1))
21 | end
22 |
23 | return jsonp
--------------------------------------------------------------------------------
/script/test_cf.lua:
--------------------------------------------------------------------------------
1 | local cf = require "cf"
2 |
3 | cf.fork(function()
4 | local co = cf.self()
5 | print("fork", "我现在睡眠了")
6 | cf.fork(function()
7 | return cf.wakeup(co)
8 | end)
9 | cf.wait()
10 | print("fork", "我现在被唤醒了")
11 | end)
12 |
13 | local times, timer = 0, nil
14 | timer = cf.at(1, function()
15 | if times >= 3 then
16 | print("循环定时器运行次数到了.")
17 | return timer:stop()
18 | end
19 | times = times + 1
20 | print("定时器运行次数:", times)
21 | end)
22 |
23 | cf.timeout(1, function()
24 | print("一次性定时器运行.")
25 | end)
26 |
27 | -- 想不执行timeout就取消下面的注释
28 | -- timer:stop()
29 |
30 | cf.wait()
31 |
--------------------------------------------------------------------------------
/POST_FILE.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 文件上传
5 |
6 |
7 |
18 |
19 |
--------------------------------------------------------------------------------
/lualib/crypt/id.lua:
--------------------------------------------------------------------------------
1 | local CRYPT = require "lcrypt"
2 | local uuid = CRYPT.uuid
3 | local guid = CRYPT.guid
4 |
5 | local sys = require "sys"
6 | local now = sys.now
7 | local hostname = sys.hostname
8 |
9 | local modf = math.modf
10 |
11 | local ID = {}
12 |
13 | -- UUID v4实现
14 | function ID.uuid()
15 | return uuid()
16 | end
17 |
18 | -- hash(主机名)-时间戳-微秒-(1~65535的随机数)
19 | function ID.guid(host)
20 | local hi, lo = modf(now())
21 | return guid(host or hostname(), hi, lo * 1e4 // 1)
22 | end
23 |
24 | -- 初始化函数
25 | return function (t)
26 | for k, v in pairs(ID) do
27 | t[k] = v
28 | end
29 | return ID
30 | end
--------------------------------------------------------------------------------
/lualib/cloud/qiniu/ocr.lua:
--------------------------------------------------------------------------------
1 | local token = require "cloud.qiniu.token"
2 | local httpc = require "httpc"
3 | local json = require "json"
4 |
5 | local ocr = { __Version__ = 0.1, host = "ai.qiniuapi.com"}
6 |
7 | -- 身份证识别
8 | function ocr.idcard(AccessKey, SecretKey, uri)
9 | local path = "/v1/ocr/idcard"
10 | local body = json.encode { data = { uri = uri } }
11 | local Authorization = token.newAuthorization (AccessKey, SecretKey, { method = "POST", path = path, host = ocr.host, body = body })
12 | return httpc.json("http://ai.qiniuapi.com/v1/ocr/idcard", { {"Authorization", Authorization} }, body)
13 | end
14 |
15 | return ocr
--------------------------------------------------------------------------------
/luaclib/src/lcjson/fpconv.h:
--------------------------------------------------------------------------------
1 | /* Lua CJSON floating point conversion routines */
2 |
3 | /* Buffer required to store the largest string representation of a double.
4 | *
5 | * Longest double printed with %.14g is 21 characters long:
6 | * -1.7976931348623e+308 */
7 | # define FPCONV_G_FMT_BUFSIZE 32
8 |
9 | #ifdef USE_INTERNAL_FPCONV
10 | static inline void fpconv_init()
11 | {
12 | /* Do nothing - not required */
13 | }
14 | #else
15 | extern void fpconv_init();
16 | #endif
17 |
18 | extern int fpconv_g_fmt(char*, double, int);
19 | extern double fpconv_strtod(const char*, char**);
20 |
21 | /* vi:ai et sw=4 ts=4:
22 | */
23 |
--------------------------------------------------------------------------------
/luaclib/src/lfs/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY : build rebuild clean
2 |
3 | default :
4 | @echo "======================================="
5 | @echo "Please use 'make build' command to build it.."
6 | @echo "Please use 'make rebuild' command to build it.."
7 | @echo "Please use 'make clean' command to clean all."
8 | @echo "======================================="
9 |
10 | CC = cc
11 |
12 | INCLUDES += -I../../../src -I/usr/local/include
13 | LIBS = -L../ -L../../ -L../../../ -L/usr/local/lib
14 |
15 | CFLAGS = -O3 -Wall -shared -fPIC
16 | DLL = -lcore
17 |
18 | build:
19 | @$(CC) -o lfs.so lfs.c $(INCLUDES) $(LIBS) $(CFLAGS) $(DLL)
20 | @mv *.so ../../
21 |
--------------------------------------------------------------------------------
/luaclib/src/lmsgpack/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY : build rebuild clean
2 |
3 | default :
4 | @echo "======================================="
5 | @echo "Please use 'make build' command to build it.."
6 | @echo "Please use 'make rebuild' command to build it.."
7 | @echo "Please use 'make clean' command to clean all."
8 | @echo "======================================="
9 |
10 | CC = cc
11 |
12 | INCLUDES += -I../../../src -I/usr/local/include
13 | LIBS = -L../ -L../../ -L../../../ -L/usr/local/lib
14 |
15 | CFLAGS = -O3 -Wall -shared -fPIC
16 | DLL = -lcore
17 |
18 | build:
19 | @$(CC) -o lmsgpack.so lmsgpack.c $(INCLUDES) $(LIBS) $(CFLAGS) $(DLL)
20 | @mv *.so ../../
21 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM rockylinux/rockylinux:9 as builder
2 | # 设置时区与语言环境变量
3 | #ENV TIME_ZONE=Asia/Shanghai
4 | #RUN echo "${TIME_ZONE}" > /etc/timezone && ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime
5 | WORKDIR /app
6 |
7 | ADD . /app
8 | RUN yum install gcc file autoconf automake make libtool git openssl-devel zlib-devel -y && rm -rf /var/cache/yum
9 | RUN sh build.sh && make build
10 |
11 | FROM rockylinux/rockylinux:9
12 | # 设置时区与语言环境变量
13 | #ENV TIME_ZONE=Asia/Shanghai
14 | #RUN echo "${TIME_ZONE}" > /etc/timezone && ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime
15 | COPY --from=builder /app/ /app
16 | WORKDIR /app
17 | ENTRYPOINT ["./cfadmin"]
18 |
--------------------------------------------------------------------------------
/luaclib/src/lpbc/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY : build rebuild clean
2 |
3 | default :
4 | @echo "======================================="
5 | @echo "Please use 'make build' command to build it.."
6 | @echo "Please use 'make rebuild' command to build it.."
7 | @echo "Please use 'make clean' command to clean all."
8 | @echo "======================================="
9 |
10 | CC = cc
11 |
12 | INCLUDES += -I../../../src -I/usr/local/include
13 | LIBS = -L../ -L../../../ -L/usr/local/lib
14 |
15 | CFLAGS = -O3 -Wall -shared -fPIC -fno-strict-aliasing
16 | DLL = -lcore
17 |
18 | build:
19 | @$(CC) -o lprotobuf.so lpb.c $(INCLUDES) $(LIBS) $(CFLAGS) $(DLL)
20 | @mv *.so ../../
21 |
--------------------------------------------------------------------------------
/luaclib/src/lpeg/makefile:
--------------------------------------------------------------------------------
1 | .PHONY : build rebuild clean
2 |
3 | default :
4 | @echo "======================================="
5 | @echo "Please use 'make build' command to build it.."
6 | @echo "Please use 'make rebuild' command to build it.."
7 | @echo "Please use 'make clean' command to clean all."
8 | @echo "======================================="
9 |
10 | CC = cc
11 | INCLUDES += -I../../../src -I/usr/local/include
12 | LIBS = -L../ -L../../ -L../../../ -L/usr/local/lib
13 | CFLAGS = -O3 -shared -fPIC
14 | DLL = -lcore
15 |
16 | build:
17 | @$(CC) -o lpeg.so lpcap.c lpcode.c lpprint.c lptree.c lpvm.c $(CFLAGS) $(INCLUDES) $(LIBS) $(DLL)
18 | @mv *.so ../../
19 |
--------------------------------------------------------------------------------
/lualib/admin/html/deny.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Access Deny
5 |
6 |
7 |
8 |
9 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/lualib/process/event.lua:
--------------------------------------------------------------------------------
1 | local cf = require "cf"
2 | local child = require "child"
3 |
4 | local pids = {}
5 |
6 | local pid_cb = nil
7 |
8 | local co = coroutine.create(function ()
9 | while true do
10 | local pid, code = coroutine.yield()
11 | if pid_cb then
12 | cf.fork(pid_cb, pid, code)
13 | else
14 | print('exit', pid, pids[pid])
15 | end
16 | end
17 | end)
18 | coroutine.resume(co)
19 |
20 | local event = {}
21 |
22 | function event.init(pid_list)
23 | for _, pid in ipairs(pid_list) do
24 | pids[pid] = child.watch(pid, co)
25 | end
26 | end
27 |
28 | function event.setcb(func)
29 | pid_cb = func
30 | end
31 |
32 | return event
--------------------------------------------------------------------------------
/script/test_http_auth.lua:
--------------------------------------------------------------------------------
1 | -- 从httpc库导入并且使用
2 | local httpc = require "httpc"
3 |
4 | local basic_key, basic_value = httpc.basic_authorization("myusername", "mypassword")
5 | print(basic_key, basic_value)
6 |
7 | -- 从httpc类库中导入并且使用
8 | local httpc_cls = require "httpc.class"
9 | local hc = httpc_cls:new {}
10 |
11 | local basic_key, basic_value = hc:basic_authorization("myusername", "mypassword")
12 | print(basic_key, basic_value)
13 |
14 | -- 从json.jwt导出
15 | local jwt = require "json.jwt"
16 | local raw = '{"name":"Hello world."}'
17 | local enc = jwt.encode(raw, "secret", "HS256")
18 | local dec = jwt.decode(enc, "secret", "HS256")
19 | print("jwt test:", raw == dec, enc)
--------------------------------------------------------------------------------
/lualib/crypt/rc4.lua:
--------------------------------------------------------------------------------
1 | local CRYPT = require "lcrypt"
2 | local hexencode = CRYPT.hexencode
3 | local hexdecode = CRYPT.hexdecode
4 | local rc4 = CRYPT.rc4
5 |
6 | local RC4 = {}
7 |
8 | -- `RC4`加密
9 | function RC4.rc4_encrypt(key, text, hex)
10 | local hash = rc4(key, text)
11 | if hash and hex then
12 | return hexencode(hash)
13 | end
14 | return hash
15 | end
16 |
17 | -- `RC4`解密
18 | function RC4.rc4_decrypt(key, cipher, hex)
19 | if cipher and hex then
20 | cipher = hexdecode(cipher)
21 | end
22 | return rc4(key, cipher)
23 | end
24 |
25 | -- 初始化函数
26 | return function (t)
27 | for k, v in pairs(RC4) do
28 | t[k] = v
29 | end
30 | return RC4
31 | end
--------------------------------------------------------------------------------
/src/core_sys.c:
--------------------------------------------------------------------------------
1 | #include "core_sys.h"
2 |
3 | /* 此方法提供一个精确到微秒级的时间戳 */
4 | double now(void){
5 | struct timespec now = {};
6 | clock_gettime(CLOCK_REALTIME, &now);
7 | return now.tv_sec + now.tv_nsec * 1e-9;
8 | }
9 |
10 | /* 此方法可用于检查是否为有效ipv4地址*/
11 | int ipv4(const char *IP){
12 | if (!IP) return 0;
13 | struct in_addr addr = {};
14 | if (inet_pton(AF_INET, IP, &addr) == 1) return 1;
15 | return 0;
16 | }
17 |
18 | /* 此方法可用于检查是否为有效ipv6地址*/
19 | int ipv6(const char *IP){
20 | if (!IP) return 0;
21 | struct in6_addr addr = {};
22 | if (inet_pton(AF_INET6, IP, &addr) == 1) return 1;
23 | return 0;
24 | }
25 |
26 | /* 返回当前操作系统类型 */
27 | const char* os(void) {
28 | return __OS__;
29 | }
--------------------------------------------------------------------------------
/static/css/theme5.css:
--------------------------------------------------------------------------------
1 | body{
2 | background:#EEF5F9 !important;
3 | }
4 | .container{
5 | background:linear-gradient(to left, #7b4397, #2196f3);
6 | }
7 |
8 | .left-nav{
9 | background:#fff !important;
10 | }
11 |
12 | .left-nav a{
13 | color:#686a76 !important;
14 | }
15 | .left-nav a.active{
16 | background: linear-gradient(to left, #7c8ce4, #2196f3) !important;
17 | color: #fff !important;
18 | border-color: #7b4397 !important;
19 | }
20 | .left-nav a:hover{
21 | background: linear-gradient(to left, #7c8ce4, #2196f3) !important;
22 | color: #fff !important;
23 | border-color: #7b4397 !important;
24 | }
25 | .container .logo a{
26 | background: rgba(0,0,0,0) !important;
27 | }
--------------------------------------------------------------------------------
/luaclib/src/lhttpparser/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY : build rebuild clean
2 |
3 | default :
4 | @echo "======================================="
5 | @echo "Please use 'make build' command to build it.."
6 | @echo "Please use 'make rebuild' command to build it.."
7 | @echo "Please use 'make clean' command to clean all."
8 | @echo "======================================="
9 |
10 | CC = cc
11 |
12 | # 开启请先确认是否支持指令集, 经过测试http解析速度至少快2倍
13 | # CFLAGS = -O3 -Wall -shared -fPIC -msse4
14 |
15 | INCLUDES += -I../../../src -I/usr/local/include
16 | LIBS = -L../ -L../../ -L../../../ -L/usr/local/lib
17 |
18 | CFLAGS = -O3 -Wall -shared -fPIC
19 | DLL = -lcore
20 |
21 | build:
22 | @$(CC) -o lhttpparser.so httpparser.c lhttpparser.c $(INCLUDES) $(LIBS) $(CFLAGS) $(DLL)
23 | @mv *.so ../../
24 |
--------------------------------------------------------------------------------
/luaclib/src/lcjson/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY : build rebuild clean
2 |
3 | default :
4 | @echo "======================================="
5 | @echo "Please use 'make build' command to build it.."
6 | @echo "Please use 'make rebuild' command to build it.."
7 | @echo "Please use 'make clean' command to clean all."
8 | @echo "======================================="
9 |
10 | # CFLAGS = -O3 -Wall -DJEMALLOC -shared -fPIC -ljemalloc
11 | # CFLAGS = -O3 -Wall -DTCMALLOC -shared -fPIC -ltcmalloc
12 | CFLAGS = -O3 -Wall -shared -fPIC
13 | CC = cc
14 |
15 | INCLUDES = -I. -I../../../src -I/usr/local/include
16 | LIBS = -L../ -L../../ -L../../../ -L/usr/local/lib
17 | DLL = -lcore
18 |
19 | build:
20 | @$(CC) -o cjson.so lua_cjson.c fpconv.c strbuf.c $(INCLUDES) $(LIBS) $(CFLAGS) $(DLL)
21 | @mv *.so ../../
22 |
--------------------------------------------------------------------------------
/lualib/protocol/mqtt/tools.lua:
--------------------------------------------------------------------------------
1 | -- module table
2 | local tools = {}
3 |
4 | -- required modules
5 | local math = require("math")
6 | local table = require("table")
7 | local string = require("string")
8 |
9 | -- cache to locals
10 | local str_format = string.format
11 | local str_byte = string.byte
12 | local tbl_concat = table.concat
13 | local math_floor = math.floor
14 |
15 |
16 | -- Returns string encoded as HEX
17 | function tools.hex(str)
18 | local res = {}
19 | for i = 1, #str do
20 | res[i] = str_format("%02X", str_byte(str, i))
21 | end
22 | return tbl_concat(res)
23 | end
24 |
25 | -- Integer division function
26 | function tools.div(x, y)
27 | return math_floor(x / y)
28 | end
29 |
30 | -- export module table
31 | return tools
32 |
33 | -- vim: ts=4 sts=4 sw=4 noet ft=lua
34 |
--------------------------------------------------------------------------------
/luaclib/src/lz/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY : build rebuild clean
2 |
3 | default :
4 | @echo "======================================="
5 | @echo "Please use 'make build' command to build it.."
6 | @echo "Please use 'make rebuild' command to build it.."
7 | @echo "Please use 'make clean' command to clean all."
8 | @echo "======================================="
9 |
10 | CC = cc
11 |
12 | INCLUDES += -I../../../src -I/usr/local/include
13 | LIBS = -L../ -L../../ -L../../../ -L/usr/local/lib
14 |
15 | CFLAGS = -O3 -Wall -shared -fPIC -Wl,-rpath,. -Wl,-rpath,.. -Wl,-rpath,/usr/local/lib
16 |
17 | # 是用内置库
18 | # MICRO =
19 | # DLL = -lcore
20 | # 使用`zlib`
21 | MICRO = -DUSE_ZLIB=1
22 | DLL = -lcore -lz
23 |
24 | build:
25 | @$(CC) -o lz.so lzlib.c miniz.c $(INCLUDES) $(LIBS) $(CFLAGS) $(DLL) $(MICRO)
26 | @mv *.so ../../
27 |
--------------------------------------------------------------------------------
/luaclib/src/lcrypt/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY : build rebuild clean
2 |
3 | default :
4 | @echo "======================================="
5 | @echo "Please use 'make build' command to build it.."
6 | @echo "Please use 'make rebuild' command to build it.."
7 | @echo "Please use 'make clean' command to clean all."
8 | @echo "======================================="
9 |
10 | CC = cc
11 |
12 | CFLAGS = -O3 -Wall -shared -fPIC -fno-strict-aliasing -Wl,-rpath,. -Wl,-rpath,.. -Wl,-rpath,/usr/local/lib
13 | DLL = -lcore -lcrypto
14 |
15 | INCLUDES = -I../../../src -I/usr/local/include
16 | LIBS = -L../ -L../../ -L../../../ -L/usr/local/lib
17 |
18 | build:
19 | @$(CC) -o lcrypt.so lcrypt.c aes.c des.c dh.c rsa.c sha.c hmac.c hmac_ex.c b64.c crc.c url.c hex.c uuid.c sm.c rc.c $(INCLUDES) $(LIBS) $(CFLAGS) $(DLL)
20 | @mv *.so ../../
21 |
--------------------------------------------------------------------------------
/script/test_protobuf.lua:
--------------------------------------------------------------------------------
1 | local Log = require "logging"
2 |
3 | local pb = require "protobuf"
4 |
5 | --[[
6 | 测试与使用指南:
7 |
8 | 1. 安装protobuf的命令行二进制生成工具protoc.
9 |
10 | 2. 使用命令 protoc Person.proto -o Person.pb 生成协议文件.
11 |
12 | 3. 使用loadfile读取生成的协议文件Person.pb后就完成了数据结构注册与导入.
13 |
14 | 4. 这有时候就可以开始使用encode/decode方法进行代码测试.
15 |
16 | 5. 需要注意的是: protobuf协议需要"先定义(注册), 后使用", 支持protobuf v2/v3版本语法.
17 | ]]
18 |
19 | Log:DEBUG(pb.loadfile("Person.pb"))
20 |
21 | local pb_string = pb.encode("Person", {
22 | name = "CandyMi",
23 | age = 2^32 - 1,
24 | hand = {
25 | left = "左手",
26 | right = "右手",
27 | },
28 | foot = {
29 | left = "左脚",
30 | right = "右脚",
31 | }
32 | })
33 | Log:DEBUG(pb.tohex(pb_string))
34 |
35 | Log:DEBUG(pb.decode("Person", pb_string))
36 |
37 | Log:DEBUG(pb.clear("Person"))
38 |
--------------------------------------------------------------------------------
/script/test_MQ.lua:
--------------------------------------------------------------------------------
1 | -- local MQ = require "MQ.stomp"
2 | local MQ = require "MQ.redis"
3 | -- local MQ = require "MQ.mqtt"
4 |
5 | local cf = require "cf"
6 | require "utils"
7 |
8 | local mq = MQ:new {
9 | host = 'localhost',
10 | -- port = 61613,
11 | -- port = 1883,
12 | port = 6379,
13 | -- vhost = '/exchange',
14 | -- auth = "admin",
15 | -- username = "guest",
16 | -- password = "guest",
17 | }
18 |
19 | mq:on('/test', function (msg)
20 | print("收到来自/test的消息.")
21 | var_dump(msg)
22 | end)
23 |
24 | mq:on('/admin', function (msg)
25 | print("收到来自/admin的消息.")
26 | var_dump(msg)
27 | end)
28 |
29 | cf.at(0.1, function (args)
30 | print(mq:emit('/test', '{"code":'..math.random(1, 100)..',"from":"/test"}'))
31 | print(mq:emit('/admin', '{"code":'..math.random(1, 100)..',"from":"/admin"}'))
32 | end)
33 |
34 | mq:start()
35 |
--------------------------------------------------------------------------------
/lualib/admin/cookie.lua:
--------------------------------------------------------------------------------
1 | local config = require "admin.config"
2 |
3 | local Cookie = require "httpd.Cookie"
4 | local getCookie = Cookie.getCookie
5 | local setCookie = Cookie.setCookie
6 | local delCookie = Cookie.delCookie
7 |
8 | local os_time = os.time
9 |
10 | local Cookie = {}
11 |
12 | -- 登录页面需要初始化Cookie.
13 | function Cookie.init ()
14 | local session = getCookie('CFTOKEN')
15 | if session then
16 | return delCookie("CFTOKEN")
17 | end
18 | local session = getCookie('CFLANG')
19 | if not session then
20 | setCookie("CFLANG", config.locale)
21 | end
22 | end
23 |
24 | -- 设置Cookie
25 | function Cookie.setCookie (name, value)
26 | return setCookie(name, value, config.cookie_timeout + os_time())
27 | end
28 |
29 | -- 获取Cookie
30 | function Cookie.getCookie (name)
31 | return getCookie(name)
32 | end
33 |
34 | return Cookie
35 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | # *.d
3 |
4 | # Object files
5 | *.o
6 | *.ko
7 | *.obj
8 | *.elf
9 |
10 | # Linker output
11 | *.ilk
12 | *.map
13 | *.exp
14 |
15 | # Precompiled Headers
16 | *.gch
17 | *.pch
18 |
19 | # Libraries
20 | *.lib
21 | *.a
22 | *.la
23 | *.lo
24 |
25 | # Shared objects (inc. Windows DLLs)
26 | *.dll
27 | *.so
28 | *.so.*
29 | *.dylib
30 |
31 | # Executables
32 | *.exe
33 | *.out
34 | *.app
35 | *.i*86
36 | *.x86_64
37 | *.hex
38 |
39 | # Debug files
40 | *.dSYM
41 | *.su
42 | *.idb
43 | *.pdb
44 |
45 | # PID And Log
46 | *.log
47 | *.PID
48 | *.pid
49 |
50 | # Code Edit
51 | .vscode
52 | *.la
53 | *.lai
54 | src/e*.h
55 | src/l*.h
56 | build
57 | cfadmin
58 |
59 | # Kernel Module Compile Results
60 | *.mod*
61 | *.cmd
62 | .DS_Store
63 | .tmp_versions/
64 | modules.order
65 | Module.symvers
66 | Mkfile.old
67 | dkms.conf
68 |
--------------------------------------------------------------------------------
/luaclib/src/lfs/lfs.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** LuaFileSystem
3 | ** Copyright Kepler Project 2003 - 2020
4 | ** (http://keplerproject.github.io/luafilesystem)
5 | */
6 |
7 | /* Define 'chdir' for systems that do not implement it */
8 | #ifdef NO_CHDIR
9 | #define chdir(p) (-1)
10 | #define chdir_error "Function 'chdir' not provided by system"
11 | #else
12 | #define chdir_error strerror(errno)
13 | #endif
14 |
15 | #ifdef _WIN32
16 | #define chdir(p) (_chdir(p))
17 | #define getcwd(d, s) (_getcwd(d, s))
18 | #define rmdir(p) (_rmdir(p))
19 | #define LFS_EXPORT __declspec (dllexport)
20 | #ifndef fileno
21 | #define fileno(f) (_fileno(f))
22 | #endif
23 | #else
24 | #define LFS_EXPORT
25 | #endif
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | LFS_EXPORT int luaopen_lfs(lua_State * L);
32 |
33 | #ifdef __cplusplus
34 | }
35 | #endif
--------------------------------------------------------------------------------
/public4096.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqkEuMgW6/rprdpHgAdr4
3 | IoGNGSfTQpCvojGHxrt3JTj+Mir4lZJw17cvMVfbnpWkCZ0H2jcxLR9t/blCSsND
4 | bxe99Xbib6q6SfIkAtL3BvUU0TTzD5ZjZR+Ko3kA+wq6yHPa8KW49659IXJzEW9C
5 | i2SJmj6lqrTw0F0ZXDso5ILU1UjrYDJdT23hyygh4SI8geDtfmv88iP+V2emhIFg
6 | q8BKvExcxlBjX4kzUU/qDddo0OUrA/wpSSPPAkXYKZ4P/0SZqbkAHNfQFzMcGbf9
7 | sGAszXI1QjwomV95Ro0IJ8HCDG2hBvdR4AqAXI3o+DumF7kHT2pHUUP8yrodVEwW
8 | cmCjO9bPh+bm3sketDIgjs6cwukohoZFr7aYp9o9l0B6lbQXdg8isut2ebXYru+R
9 | z5KJ2Ca5fOk4PHHMbZ4murBUsQq+XT8q8Sldxl7IqPcSEKzLaW+JNMyZ4nX/njAR
10 | A9cTJDTWp38EqxUdzo1ZifVMZBeI+xIyqOuyfp/zUpaoeGbCuGQHJ8A7WHagQkh9
11 | x1gjOtlIdFuX2scSHrhbbsccmIPJJ18MquM8SnauF2cW9oLo/8n0dMmaXJFqb5sK
12 | gjitPcy+usA6e8ZquwWuDheSuEo5p/S7ti02hGhWTzCWvq/nnZnEvUp642LKcIYI
13 | 8oJxXAFEGPm3HaucWGPNuqECAwEAAQ==
14 | -----END PUBLIC KEY-----
15 |
--------------------------------------------------------------------------------
/luaclib/src/lpeg/lpprint.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lpprint.h $
3 | */
4 |
5 |
6 | #if !defined(lpprint_h)
7 | #define lpprint_h
8 |
9 |
10 | #include "lptree.h"
11 | #include "lpvm.h"
12 |
13 |
14 | #if defined(LPEG_DEBUG)
15 |
16 | void printpatt (Instruction *p, int n);
17 | void printtree (TTree *tree, int ident);
18 | void printktable (lua_State *L, int idx);
19 | void printcharset (const byte *st);
20 | void printcaplist (Capture *cap, Capture *limit);
21 | void printinst (const Instruction *op, const Instruction *p);
22 |
23 | #else
24 |
25 | #define printktable(L,idx) \
26 | luaL_error(L, "function only implemented in debug mode")
27 | #define printtree(tree,i) \
28 | luaL_error(L, "function only implemented in debug mode")
29 | #define printpatt(p,n) \
30 | luaL_error(L, "function only implemented in debug mode")
31 |
32 | #endif
33 |
34 |
35 | #endif
36 |
37 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY : build rebuild clean
2 |
3 | RM = rm -rf
4 |
5 | default :
6 | @echo "======================================="
7 | @echo "Please use 'make build' command to build it.."
8 | @echo "Please use 'make rebuild' command to rebuild it.."
9 | @echo "Please use 'make clean' command to clean all."
10 | @echo "======================================="
11 |
12 | # 如果需要修改内存分配器,请修改:
13 | # 1. src/Makefile
14 | # 2. luaclib/Makefile
15 |
16 | build :
17 | @$(MAKE) -s -C src build
18 | @echo "********** Built-in core modules **********"
19 | @cd luaclib && $(MAKE) -s internal 3part -j4
20 | @$(MAKE) -s -C 3rd build
21 |
22 | rebuild :
23 | @$(MAKE) -s clean
24 | @$(MAKE) -s build
25 |
26 | clean :
27 | @echo "********** Clean All Files **********"
28 | @echo "rm -rf cfadmin libcore luaclib/*.so 3rd/*.so"
29 | @$(RM) cfadmin cfadmin.exe libcore.so libcore.dll luaclib/*.so
30 | @$(MAKE) -s -C 3rd clean
--------------------------------------------------------------------------------
/lualib/class/meta.lua:
--------------------------------------------------------------------------------
1 | local assert, type = assert, type
2 | local getmetatable = getmetatable
3 | local setmetatable = setmetatable
4 |
5 | --`Anonymous`是所有对象的基类.
6 | local Anonymous = { __META__ = true, __name = "Anonymous" }
7 |
8 | Anonymous.__index = Anonymous
9 |
10 | Anonymous.new = function (M, ...)
11 | assert(Anonymous == getmetatable(M), "[Lua-CLASS ERROR]: Must use `:` to create object.")
12 | local ctor = M.ctor
13 | local obj = setmetatable({}, M)
14 | assert(ctor and type(ctor) == 'function' and ctor, "[Lua-CLASS ERROR]: Can't find `ctor` to init.")(obj, ...)
15 | return obj
16 | end
17 |
18 | Anonymous.__call = function (M, ...)
19 | local meta = getmetatable(M)
20 | if meta == Anonymous then
21 | return M:new(...);
22 | end
23 | return assert(getmetatable(M) == Anonymous and M['__name'], "[Lua-CLASS ERROR]: Invalid class arguments.")(M, ...);
24 | end
25 |
26 | return Anonymous
--------------------------------------------------------------------------------
/lualib/httpd/Throw.lua:
--------------------------------------------------------------------------------
1 | local type = type
2 | local assert = assert
3 | local toint = math.tointeger
4 |
5 | ---comment 检查http code是否合法.
6 | ---@param code integer @响应内容.
7 | ---@return boolean | integer
8 | local function check_code(code)
9 | code = toint(code)
10 | return code and code >= 400 and code < 600 and code or nil
11 | end
12 |
13 | ---comment 检查http response是否合法.
14 | ---@param response string @响应内容.
15 | ---@return boolean | string
16 | local function check_response (response)
17 | return type(response) == 'string' and response ~= '' and response or nil
18 | end
19 |
20 | ---comment 让注册的`USE`/`API`路由可以合法的抛出异常.
21 | ---@param code integer @HTTP状态码.
22 | ---@param response string @异常附带的响应体.
23 | return function (code, response)
24 | return { __OPCODE__ = -256, __CODE__ = assert(check_code(code), "Invalid http code."), __MSG__ = assert(check_response(response), "Invalid http response.") }
25 | end
--------------------------------------------------------------------------------
/lualib/admin/token.lua:
--------------------------------------------------------------------------------
1 | local config = require 'admin.config'
2 |
3 | local crypt = require 'crypt'
4 | local xor_str = crypt.xor_str
5 | local hexencode = crypt.hexencode
6 | local hexdecode = crypt.hexdecode
7 |
8 | local sys = require "sys"
9 | local now = sys.now
10 | local match = string.match
11 | local concat = table.concat
12 |
13 | local token = {}
14 |
15 | -- token加密与序列化
16 | function token.encode (str)
17 | return hexencode(xor_str(str, config.secure)):upper()
18 | end
19 |
20 | -- token解密与反序列化
21 | function token.decode (token)
22 | return xor_str(hexdecode(token:lower()), config.secure)
23 | end
24 |
25 | -- 生成 token
26 | function token.generate (uid)
27 | return token.encode(concat({uid, now()}, ':'))
28 | end
29 |
30 | -- 解析token
31 | -- function token.parser (token)
32 | -- local str = token.decode(token)
33 | -- return match(str, '([%d]+):([%d%.]+)')
34 | -- end
35 |
36 | return token
37 |
--------------------------------------------------------------------------------
/lualib/crypt/init.lua:
--------------------------------------------------------------------------------
1 | local CRYPT = require "lcrypt"
2 |
3 | local crypt = {
4 | -- HEX编码/解码
5 | hexencode = CRYPT.hexencode,
6 | hexdecode = CRYPT.hexdecode,
7 | -- URL编码/解码
8 | urlencode = CRYPT.urlencode,
9 | urldecode = CRYPT.urldecode,
10 | }
11 |
12 | -- UUID与GUID
13 | require "crypt.id"(crypt)
14 |
15 | -- 安全哈希与摘要算法
16 | require "crypt.sha"(crypt)
17 |
18 | -- 哈希消息认证码算法
19 | require "crypt.hmac"(crypt)
20 |
21 | -- 冗余校验算法
22 | require "crypt.checksum"(crypt)
23 |
24 | -- Base64编码/解码算法
25 | require "crypt.b64"(crypt)
26 |
27 | -- RC4算法
28 | require "crypt.rc4"(crypt)
29 |
30 | -- AES对称加密算法
31 | require "crypt.aes"(crypt)
32 |
33 | -- DES对称加密算法
34 | require "crypt.des"(crypt)
35 |
36 | -- 密钥交换算法
37 | require "crypt.dh"(crypt)
38 |
39 | -- 商用国密算法
40 | require "crypt.sm"(crypt)
41 |
42 | -- 非对称加密算法
43 | require "crypt.rsa"(crypt)
44 |
45 | -- 一些特殊算法
46 | require "crypt.utils"(crypt)
47 |
48 | return crypt
--------------------------------------------------------------------------------
/luaclib/src/lpeg/lpcode.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lpcode.h $
3 | */
4 |
5 | #if !defined(lpcode_h)
6 | #define lpcode_h
7 |
8 | #include
9 |
10 | #include "lptypes.h"
11 | #include "lptree.h"
12 | #include "lpvm.h"
13 |
14 | int tocharset (TTree *tree, Charset *cs);
15 | int checkaux (TTree *tree, int pred);
16 | int fixedlen (TTree *tree);
17 | int hascaptures (TTree *tree);
18 | int lp_gc (lua_State *L);
19 | Instruction *compile (lua_State *L, Pattern *p);
20 | void realloccode (lua_State *L, Pattern *p, int nsize);
21 | int sizei (const Instruction *i);
22 |
23 |
24 | #define PEnullable 0
25 | #define PEnofail 1
26 |
27 | /*
28 | ** nofail(t) implies that 't' cannot fail with any input
29 | */
30 | #define nofail(t) checkaux(t, PEnofail)
31 |
32 | /*
33 | ** (not nullable(t)) implies 't' cannot match without consuming
34 | ** something
35 | */
36 | #define nullable(t) checkaux(t, PEnullable)
37 |
38 |
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/private1024.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIICXQIBAAKBgQDc84CClRm5VqlzhvG7Izfff/VBhycuhxYEubSQp6NXT8virjlp
3 | e/g0dW94d1UENsEZYiLxepVwkHKNjxlbKMiLTjk+hs+S2g6U7bIbFLClZAdD9Bf+
4 | wuKD5YUUX7cRLzFEIFCNLn9E7HZ6/8iRkMtMmZf6Dx0LG/WmZ3WN1CnqwwIDAQAB
5 | AoGBAIOC7BrNZGJMks+QopEghUEiiHhYWZn4DcMCRddT8IUnmdNyn/mJMFMJEzBA
6 | 1vmLHaReJS5WKFy3nXdklVMNE0+7khDciu/sDTSgxtZJRWvBwdYmgkzNz8jjkOzH
7 | ZCQuqUu12AS5aFieLRB6i/FeGZiJGEoT+/KBMlVNi11xJXsBAkEA/uu88SwnjnbY
8 | nbMwiDyWhK3/QE3vr82DBg0Z9mrmCnw7iXjB5pKUJLQbAO0NiCbi/HEkwvRkQpgx
9 | qzh8MB4gnQJBAN3i81AnOPPUAOS2Gh1jHpNyT/zr9BZ27aKbXL7eraUky3uEdNps
10 | rWCboyXxR0aF0BSJM4K4rL+Alveqnv/M6t8CQEuTzJKcCqY8KgCnLY5WmDGB/Jku
11 | Ag/XGC9lFvttugIFzwj02lfnwTAYjaD6pvZkwQsi6Ek8d7UetisTNg52ACkCQDAA
12 | gybZ9WY6fR79jlTBNsIrPsa2vQ2HGQ3OkpfwUJyjgynrk+QVEsUNppP0yLinBkcL
13 | D4u+LBEZ3o8h6Ffqmv0CQQCKBHHaAjYAhUd3lGrseN45QSw4VpARQ7/bBKimrq+d
14 | JCNdEpTOt6eQs8t43uOCeDjZ0H33KXG8ofcLprYE5K4G
15 | -----END RSA PRIVATE KEY-----
16 |
--------------------------------------------------------------------------------
/lualib/admin/html/login/head.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | {{ locale['login.form.title'] }}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/script/test_translate.lua:
--------------------------------------------------------------------------------
1 | local baidu = require "cloud.translate.baidu"
2 | local youdao = require "cloud.translate.youdao"
3 |
4 | --[[
5 | 免费的有道词典接口, 采用https安全传输.
6 | youdao.ZH_CN2EN -- 中文 >> 英语
7 | youdao.ZH_CN2JA -- 中文 >> 日语
8 | youdao.ZH_CN2KR -- 中文 >> 韩语
9 | youdao.ZH_CN2FR -- 中文 >> 法语
10 | youdao.ZH_CN2RU -- 中文 >> 俄语
11 | youdao.ZH_CN2SP -- 中文 >> 西语
12 | youdao.EN2ZH_CN -- 英语 >> 中文
13 | youdao.JA2ZH_CN -- 日语 >> 中文
14 | youdao.KR2ZH_CN -- 韩语 >> 中文
15 | youdao.FR2ZH_CN -- 法语 >> 中文
16 | youdao.RU2ZH_CN -- 俄语 >> 中文
17 | youdao.SP2ZH_CN -- 西语 >> 中文
18 | ]]
19 |
20 | local query = "床前明月光, 疑是地上霜. 举头望明月, 低头思故乡."
21 |
22 | -- 免费
23 | local code, ret = youdao.translate(youdao.ZH_CN2EN, query)
24 | print(code, ret)
25 |
26 | -- 数量收费
27 | local app_id, app_key = "your_app_id", "your_app_key"
28 | local code, ret = baidu.translate(app_id, app_key, {
29 | q = query,
30 | to = "en",
31 | from = "zh",
32 | })
33 | print(code, ret)
--------------------------------------------------------------------------------
/lualib/xml2lua/init.lua:
--------------------------------------------------------------------------------
1 | -- 对xml2lua的简单封装, 简化xml2lua调用流程
2 | local xml2lua = require "xml2lua.xml2lua"
3 | local xml2lua_handler = require "xml2lua.xmlhandler.tree"
4 |
5 | local type = type
6 | local pcall = pcall
7 |
8 | local xml = {}
9 |
10 | -- xml字符串解析
11 | function xml.parser(xml_data)
12 | local cls = xml2lua.parser(xml2lua_handler:new())
13 | -- cls:parse(xml_data)
14 | local ok, err = pcall(cls.parse, cls, xml_data)
15 | if not ok then
16 | return err
17 | end
18 | return cls.handler.root
19 | end
20 |
21 | -- xml文件读取
22 | function xml.load(xml_path)
23 | if type(xml_path) ~= 'string' or xml_path == '' then
24 | return nil, '无效的xml文件路径.'
25 | end
26 | local xfile, error = xml2lua.loadFile(xml_path)
27 | if xfile then
28 | return xml.parser(xfile)
29 | end
30 | return xfile, error
31 | end
32 |
33 | -- 将table序列化为xml
34 | function xml.toxml( ... )
35 | return xml2lua.toXml(...)
36 | end
37 |
38 | return xml
39 |
--------------------------------------------------------------------------------
/lualib/admin/db/permission.lua:
--------------------------------------------------------------------------------
1 | local fmt = string.format
2 |
3 | local permission = {}
4 |
5 | -- 用户是否有此菜单的权限
6 | function permission.user_have_menu_permission (db, uid, url)
7 | -- 查询用户Role ID
8 | local uinfo = db:query(fmt([[SELECT id, role AS role_id FROM cfadmin_users WHERE `cfadmin_users`.id = %u AND `cfadmin_users`.active = 1 LIMIT 1]], uid))[1]
9 | if type(uinfo) ~= 'table' then
10 | return false
11 | end
12 | -- 查询菜单Menu ID
13 | local minfo = db:query(fmt([[SELECT * FROM cfadmin_menus WHERE `cfadmin_menus`.url = '%s' AND `cfadmin_menus`.active = 1 LIMIT 1]], url))[1]
14 | if type(minfo) ~= 'table' then
15 | return true
16 | end
17 | -- 检查权限
18 | local role, err = db:query(fmt([[SELECT * FROM cfadmin_permissions p WHERE p.`active` = 1 AND p.`role_id` = %u AND p.`menu_id` = %u LIMIT 1]], uinfo.role_id, minfo.id))
19 | if type(role) == 'table' then
20 | return role[1]
21 | end
22 | return role, err
23 | end
24 |
25 | return permission
26 |
--------------------------------------------------------------------------------
/script/test_lfs.lua:
--------------------------------------------------------------------------------
1 | local Log = require "logging":new()
2 |
3 | local lfs = require "lfs"
4 |
5 | -- Log:DEBUG(lfs)
6 |
7 | local function list_logs_files ()
8 | local logs = {}
9 | for filename in lfs.dir("logs") do
10 | -- mode为"directory"表示为目录, mode为"file"表示文件
11 | if lfs.attributes("logs".."/"..filename).mode == "file" then
12 | logs[#logs+1] = filename
13 | end
14 | end
15 | return logs
16 | end
17 |
18 | local function change_dir (dir)
19 | local old = "将当前目录路径["..lfs.currentdir().."]修改为"
20 | lfs.chdir(lfs.currentdir()..dir)
21 | local new = "["..lfs.currentdir().."]"
22 | return old..new
23 | end
24 |
25 | Log:DEBUG("lfs版本为:"..lfs._VERSION)
26 |
27 | Log:DEBUG(change_dir("/script"))
28 |
29 | Log:DEBUG(change_dir("/../"))
30 |
31 | Log:DEBUG("查看LICENSE文件属性:", lfs.attributes("LICENSE"))
32 |
33 | Log:DEBUG("创建test文件夹:", lfs.mkdir("test"))
34 |
35 | Log:DEBUG("删除test文件夹:", lfs.rmdir("test"))
36 |
37 | Log:DEBUG("列出logs文件夹目录", list_logs_files())
38 |
--------------------------------------------------------------------------------
/script/test_logging.lua:
--------------------------------------------------------------------------------
1 | local LOG = require "logging"
2 |
3 | --[[
4 | 日志库分为2种使用方式: 1. 初始化后使用, 2. 直接导入使用; 两者之间的差异根据不同需求不同使用.
5 |
6 | 初始化使用时为了将不同的日志打印并dump到不同的日志文件中, 这中方式在调试开发的时候非常有用.
7 |
8 | 直接导入使用不会将日志持久化到磁盘(输出到stdout), 相对于dump到本地磁盘. 它更是适用于docker这种做为集中式日志收集.
9 |
10 | `path`参数通常是一个日志文件名, 它的前缀为`logs/{your_path}`, 但是你可以根据实际情况加上路径对文件进行分割.
11 |
12 | `dump`参数决定是否将打印内容序列化到磁盘.
13 |
14 | 注意: 如果您的path中包含了目录, 需要先自行创建目录. 否则将会打印错误.
15 | ]]
16 |
17 | -- 初始化日志
18 | local log = LOG:new { path = 'admin/main' , dump = true }
19 |
20 | print()
21 |
22 | -- dump到磁盘
23 | log:INFO('this is INFO LOG', nil, 1, nil)
24 | log:DEBUG('this is DEBUG LOG', nil, nil, 1)
25 | log:WARN('this is WARN LOG', 1, nil, nil)
26 | log:ERROR('this is ERROR LOG', nil, nil, nil)
27 |
28 | print()
29 |
30 | -- 仅输出到stdout
31 | LOG:INFO('this is INFO LOG', nil, 1, nil)
32 | LOG:DEBUG('this is DEBUG LOG', nil, nil, 1)
33 | LOG:WARN('this is WARN LOG', 1, nil, nil)
34 | LOG:ERROR('this is ERROR LOG', nil, nil, nil)
35 |
--------------------------------------------------------------------------------
/script/test_xml.lua:
--------------------------------------------------------------------------------
1 | local xml2lua = require "xml2lua"
2 | require "utils"
3 |
4 | local xml = [[
5 |
6 |
7 | 老虎
8 | meta
9 |
10 |
11 | 狮子
12 | meta
13 |
14 |
15 |
16 | - 水果糖
17 | - 車先生
18 |
19 |
20 |
21 | - 买买买
22 | - 玩玩玩
23 | - 逛逛逛
24 |
25 | - 肉肉
26 | - 小宝贝
27 | - 小QQ
28 | - 車爪鱼
29 |
30 |
31 |
32 |
33 | ]]
34 |
35 | -- benchmark time: ./cfadmin 耗时:3.6xx/Sec
36 | for i = 1, 10000 do
37 | xml2lua.parser(xml)
38 | end
39 |
40 | -- 打印解析后的表结构
41 | local tab = xml2lua.parser(xml)
42 | var_dump(tab)
43 |
44 | -- 原版xml2lua打印会出现相等的情况
45 | -- 这在cf中可能导致不可预知的情况.
46 | local tab1 = xml2lua.parser(xml)
47 | local tab2 = xml2lua.parser(xml)
48 | print(tab1, tab2)
49 |
--------------------------------------------------------------------------------
/lualib/xml2lua/xmlhandler/README.md:
--------------------------------------------------------------------------------
1 | # XML Handlers
2 | This directory contains a list of handlers used by the XML parser to process a XML producing different results.
3 | There are currently 3 available handlers:
4 |
5 | - tree: generates a lua table from an XML content string (the most common used handler).
6 | - print: generates a simple event trace which outputs messages to the terminal during the XML parsing, usually for debugging purposes.
7 | - dom: generates a DOM-like node tree structure with a single ROOT node parent.
8 |
9 | # Usage
10 | To get a handler instance you must call, for instance, `handler = require("xmlhandler.tree")`.
11 | Then, you have to use one the handler instance when getting an instance of the XML parser using `parser = xml2lua.parser(handler)`.
12 | Notice the module `xml2lua` should have been loaded before using `require("xml2lua")`.
13 | This way, the handler is called internally when the `parser:parse(xml)` function is called.
14 |
15 | Check the documentation on the root directory for complete examples.
--------------------------------------------------------------------------------
/lualib/admin/html/dashboard/content.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{ locale['dashboard.crumbs.home'] }}
5 |
6 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/static/lib/layui/css/modules/code.css:
--------------------------------------------------------------------------------
1 | /** layui-v2.5.4 MIT License By https://www.layui.com */
2 | html #layuicss-skincodecss{display:none;position:absolute;width:1989px}.layui-code-h3,.layui-code-view{position:relative;font-size:12px}.layui-code-view{display:block;margin:10px 0;padding:0;border:1px solid #e2e2e2;border-left-width:6px;background-color:#F2F2F2;color:#333;font-family:Courier New}.layui-code-h3{padding:0 10px;height:32px;line-height:32px;border-bottom:1px solid #e2e2e2}.layui-code-h3 a{position:absolute;right:10px;top:0;color:#999}.layui-code-view .layui-code-ol{position:relative;overflow:auto}.layui-code-view .layui-code-ol li{position:relative;margin-left:45px;line-height:20px;padding:0 5px;border-left:1px solid #e2e2e2;list-style-type:decimal-leading-zero;*list-style-type:decimal;background-color:#fff}.layui-code-view pre{margin:0}.layui-code-notepad{border:1px solid #0C0C0C;border-left-color:#3F3F3F;background-color:#0C0C0C;color:#C2BE9E}.layui-code-notepad .layui-code-h3{border-bottom:none}.layui-code-notepad .layui-code-ol li{background-color:#3F3F3F;border-left:none}
--------------------------------------------------------------------------------
/docker/docker-compose-with-cfadmin.yaml:
--------------------------------------------------------------------------------
1 | # docker-compose.yaml
2 | version: "2"
3 | services:
4 | WebApp:
5 | image: candymi/cfweb
6 | restart: always
7 | volumes:
8 | - ./script/:/app/script/
9 | # 如需设置时区, 建议请将localtime提取到home目录下再挂在使用
10 | # - /etc/localtime:/etc/localtime
11 | ports:
12 | - 8080:8080
13 | depends_on:
14 | - WebDB
15 | links:
16 | - WebDB:WebDB
17 | networks:
18 | - Web_Net
19 |
20 | WebDB:
21 | image: mysql:5.6 #支持8.X以上版本, 但是必须开启下面的COMMAND参数.
22 | restart: always
23 | environment:
24 | - MYSQL_ROOT_PASSWORD=123456789
25 | - MYSQL_DATABASE=cfadmin
26 | # 8.x以上版本必须设置为mysql_native_password, 否则无法连接到MySQL
27 | # command: --default-authentication-plugin=mysql_native_password
28 | volumes:
29 | - ./db/:/docker-entrypoint-initdb.d/
30 | # 如需设置时区, 建议请将localtime提取到home目录下再挂在使用
31 | # - /etc/localtime:/etc/localtime
32 | ports:
33 | - 3306:3306
34 | networks:
35 | - Web_Net
36 |
37 | networks:
38 | Web_Net:
39 | driver: bridge
40 |
--------------------------------------------------------------------------------
/script/test_es.lua:
--------------------------------------------------------------------------------
1 | require "utils"
2 | local es = require "es"
3 |
4 | ---@type ElasticSearch
5 | local o = es {
6 | domain = "http://localhost:9200",
7 | -- 如果需要验证
8 | username = "elastic", password = "PV+nXLk8z*ypGBxmO55d",
9 | }
10 |
11 | assert(o:connect())
12 |
13 | -- 插入数据
14 | print(o:insert("test", { name = "車先生1", sex = 'male', age = 9 }, 1))
15 | print(o:insert("test", { name = "車太太1", sex = 'female', age = 7 }, 2))
16 | print(o:insert("test", { name = "車先生2", sex = 'male', age = 9 }, 3))
17 | print(o:insert("test", { name = "車太太2", sex = 'female', age = 7 }, 4))
18 | print(o:insert("test", { name = "車爪嘟", sex = 'female', age = 1 }, 5))
19 |
20 | -- 修改数据
21 | print(o:update("test", { doc = { age = 29 } }, 3))
22 | print(o:update("test", { doc = { age = 27 } }, 4))
23 |
24 | -- 删除数据
25 | print(o:delete("test", 1))
26 | print(o:delete("test", 2))
27 | print(o:delete_by_query("test", { query = { match_all = { } } }))
28 |
29 | -- 普通查询
30 | var_dump(o:query("test", { --[[ 查询规则 ]] }))
31 | -- SQL查询
32 | var_dump(o:sql({ query = "select * from test", --[[ 其它查询规则 ]] }))
--------------------------------------------------------------------------------
/lualib/protocol/http/parser.lua:
--------------------------------------------------------------------------------
1 | local httpparser = require "lhttpparser"
2 | local PARSER_HTTP_REQUEST = httpparser.parser_http_request
3 | local PARSER_HTTP_RESPONSE = httpparser.parser_http_response
4 | local RESPONSE_CHUNKED_PARSER = httpparser.parser_response_chunked
5 |
6 | local pcall = pcall
7 |
8 | local http_parser = {}
9 |
10 | function http_parser.PARSER_HTTP_REQUEST (buffer)
11 | local ok, method, path, version, header = pcall(PARSER_HTTP_REQUEST, buffer)
12 | if not ok then
13 | return nil
14 | end
15 | return method, path, version, header
16 | end
17 |
18 | -- 解析http回应
19 | function http_parser.PARSER_HTTP_RESPONSE (buffer)
20 | local ok, version, code, status, header = pcall(PARSER_HTTP_RESPONSE, buffer)
21 | if not ok then
22 | return nil
23 | end
24 | return version, code, status, header
25 | end
26 |
27 | -- 解析回应chunked
28 | function http_parser.RESPONSE_CHUNKED_PARSER (data)
29 | local ok, data, pos = pcall(RESPONSE_CHUNKED_PARSER, data)
30 | if not ok then
31 | return nil, -1
32 | end
33 | return data, pos
34 | end
35 |
36 | return http_parser
--------------------------------------------------------------------------------
/lualib/admin/http/system/init.lua:
--------------------------------------------------------------------------------
1 | local user = require "admin.http.system.user"
2 | local menu = require "admin.http.system.menu"
3 | local header = require "admin.http.system.header"
4 | local role = require "admin.http.system.role"
5 |
6 | return {
7 |
8 | -- 用户管理 Controller
9 | user_response = user.user_response,
10 | user_render = user.user_render,
11 | user_add_render = user.user_add_render,
12 | user_edit_render = user.user_edit_render,
13 |
14 | -- 角色管理 Controller
15 | role_response = role.role_response,
16 | role_render = role.role_render,
17 | role_add_render = role.role_add_render,
18 | role_edit_render = role.role_edit_render,
19 |
20 | -- 侧边栏 Controller
21 | menu_response = menu.menu_response,
22 | menu_render = menu.menu_render,
23 | menu_add_render = menu.menu_add_render,
24 | menu_edit_render = menu.menu_edit_render,
25 |
26 | -- 导航栏 Controller
27 | header_response = header.header_response,
28 | header_render = header.header_render,
29 | header_add_render = header.header_add_render,
30 | header_edit_render = header.header_edit_render,
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/lualib/admin/html/login/content.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
{* locale['login.form.title'] *}
5 |
6 |
18 |
19 |
--------------------------------------------------------------------------------
/lualib/admin/html/dashboard/head.html:
--------------------------------------------------------------------------------
1 |
2 | {* locale['dashboard.header.title' ] *}
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
21 |
22 |
25 |
--------------------------------------------------------------------------------
/script/test_system.lua:
--------------------------------------------------------------------------------
1 | local System = require "system"
2 |
3 | print("判断是否string类型?", System.is_string("admin"), System.is_string(1))
4 | print("空字符串是string类型么?", System.is_string(""))
5 | print("如果加了第二个参数后, 空字符串还是string类型么?", System.is_string("", true))
6 |
7 | print("判断是否整数(int/long)类型?", System.is_int(100.0), math.maxinteger)
8 |
9 | print("判断是否浮点(float)类型?", System.is_float(100.1), math.maxinteger)
10 |
11 | print("判断字符串是否合法IP地址?", System.is_ip("0.0.0."))
12 | print("判断字符串是否ipv4地址?", System.is_ipv4("1.1.1.1"))
13 | print("判断字符串是否ipv6地址?", System.is_ipv6("::1"))
14 |
15 | -- 微秒级时间返回
16 | print(string.format("%0.6f", System.now()))
17 |
18 | local array = {1, 2, 3, 4}
19 |
20 | print("1 是否在array 中.", System.is_array_member(array, 1))
21 | print("10 是否在array 中.", System.is_array_member(array, 10))
22 |
23 | local tab = {a = 'a', b = 'b', c = 'c'}
24 | print("a 是否在table 中.", System.is_table_member(tab, 'a'))
25 | print("z 是否在table 中.", System.is_table_member(tab, 'z'))
26 |
27 |
28 | print("查看今天凌晨与午夜的时间戳:", System.same_day())
29 | print("查看今天凌晨与午夜的时间戳:", System.same_day(os.time()))
30 | print("查看昨天凌晨与午夜的时间戳:", System.same_day(os.time() - 86400))
31 |
--------------------------------------------------------------------------------
/luaclib/src/lcjson/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2010-2012 Mark Pulford
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/lualib/admin/html/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {* locale['error.404.title'] *}
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
{* locale['error.404.message'] *}
19 |
3秒后将自动跳转
20 |
21 |
22 |
23 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/static/lib/layui/lay/modules/code.js:
--------------------------------------------------------------------------------
1 | /** layui-v2.5.4 MIT License By https://www.layui.com */
2 | ;layui.define("jquery",function(e){"use strict";var a=layui.$,l="http://www.layui.com/doc/modules/code.html";e("code",function(e){var t=[];e=e||{},e.elem=a(e.elem||".layui-code"),e.about=!("about"in e)||e.about,e.elem.each(function(){t.push(this)}),layui.each(t.reverse(),function(t,i){var c=a(i),o=c.html();(c.attr("lay-encode")||e.encode)&&(o=o.replace(/&(?!#?[a-zA-Z0-9]+;)/g,"&").replace(//g,">").replace(/'/g,"'").replace(/"/g,""")),c.html(''+o.replace(/[\r\t\n]+/g," ")+" "),c.find(">.layui-code-h3")[0]||c.prepend(''+(c.attr("lay-title")||e.title||"code")+(e.about?'layui.code ':"")+" ");var d=c.find(">.layui-code-ol");c.addClass("layui-box layui-code-view"),(c.attr("lay-skin")||e.skin)&&c.addClass("layui-code-"+(c.attr("lay-skin")||e.skin)),(d.find("li").length/100|0)>0&&d.css("margin-left",(d.find("li").length/100|0)+"px"),(c.attr("lay-height")||e.height)&&d.css("max-height",c.attr("lay-height")||e.height)})})}).addcss("modules/code.css","skincodecss");
--------------------------------------------------------------------------------
/lualib/crypt/utils.lua:
--------------------------------------------------------------------------------
1 | local CRYPT = require "lcrypt"
2 | local get_cert_sn = CRYPT.get_cert_sn
3 | local xor_str = CRYPT.xor_str
4 | local hashkey = CRYPT.hashkey
5 | local randomkey = CRYPT.randomkey
6 | local hexencode = CRYPT.hexencode
7 |
8 | local UTILS = {}
9 |
10 | function UTILS.xor_str (text, key, hex)
11 | local hash = xor_str(text, key)
12 | if hash and hex then
13 | return hexencode(hash)
14 | end
15 | return hash
16 | end
17 |
18 | function UTILS.randomkey(hex)
19 | local hash = randomkey(8)
20 | if hash and hex then
21 | return hexencode(hash)
22 | end
23 | return hash
24 | end
25 |
26 | function UTILS.randomkey_ex(byte, hex)
27 | local hash = randomkey(byte)
28 | if hash and hex then
29 | return hexencode(hash)
30 | end
31 | return hash
32 | end
33 |
34 | function UTILS.hashkey (key, hex)
35 | local hash = hashkey(key)
36 | if hash and hex then
37 | return hexencode(hash)
38 | end
39 | return hash
40 | end
41 |
42 | function UTILS.get_cert_sn(cert)
43 | return get_cert_sn(cert)
44 | end
45 |
46 | -- 初始化函数
47 | return function (t)
48 | for k, v in pairs(UTILS) do
49 | t[k] = v
50 | end
51 | return UTILS
52 | end
53 |
--------------------------------------------------------------------------------
/lualib/crypt/b64.lua:
--------------------------------------------------------------------------------
1 | local CRYPT = require "lcrypt"
2 | local base64encode = CRYPT.base64encode
3 | local base64decode = CRYPT.base64decode
4 |
5 | local B64 = {}
6 |
7 | ---comment 普通BASE64编码
8 | ---@param text string @等待编码的内容
9 | ---@param nopadding boolean @是否保留填充字符(默认保留)
10 | ---@return string @返回编码后的内容
11 | function B64.base64encode(text, nopadding)
12 | return base64encode(text, false, nopadding)
13 | end
14 |
15 | ---comment 普通BASE64解码
16 | ---@param text string @等待解码的内容
17 | ---@return string @返回解码后的内容
18 | function B64.base64decode(text)
19 | return base64decode(text, false)
20 | end
21 |
22 | ---comment URL安全的BASE64编码
23 | ---@param text string @等待编码的内容
24 | ---@param nopadding boolean @是否保留填充字符(默认保留)
25 | ---@return string @返回编码后的内容
26 | function B64.base64urlencode(text, nopadding)
27 | return base64encode(text, true, nopadding)
28 | end
29 |
30 | ---comment URL安全的BASE64解码
31 | ---@param text string @等待解码的内容
32 | ---@return string @返回解码后的内容
33 | function B64.base64urldecode(text)
34 | return base64decode(text, true)
35 | end
36 |
37 | -- 初始化函数
38 | return function (t)
39 | for k, v in pairs(B64) do
40 | t[k] = v
41 | end
42 | return B64
43 | end
--------------------------------------------------------------------------------
/lualib/protobuf/init.lua:
--------------------------------------------------------------------------------
1 | local lprotobuf = require "lprotobuf"
2 |
3 |
4 | local lprotobuf_tohex = lprotobuf.tohex
5 |
6 | local lprotobuf_clear = lprotobuf.clear
7 |
8 | local lprotobuf_load = lprotobuf.load
9 | local lprotobuf_loadfile = lprotobuf.loadfile
10 |
11 | local lprotobuf_encode = lprotobuf.encode
12 | local lprotobuf_decode = lprotobuf.decode
13 |
14 |
15 | local pb = {}
16 |
17 | -- 转化为16进制可读字符串
18 | function pb.tohex (pb_string)
19 | return lprotobuf_tohex(pb_string)
20 | end
21 |
22 | -- 从字符串中读取
23 | function pb.load (pb_cp_string)
24 | return lprotobuf_load(pb_cp_string)
25 | end
26 |
27 | -- 从文件中读取
28 | function pb.loadfile (filename)
29 | return lprotobuf_loadfile(filename)
30 | end
31 |
32 | -- 序列化
33 | function pb.encode (pb_registey, table)
34 | return lprotobuf_encode(pb_registey, table)
35 | end
36 |
37 | -- 反序列化
38 | function pb.decode (pb_registey, pb_string)
39 | return lprotobuf_decode(pb_registey, pb_string)
40 | end
41 |
42 | -- 清理
43 | -- When you passed A not exists message struct will get Segmentation fault.
44 | function pb.clear (...)
45 | return lprotobuf_clear(...)
46 | end
47 |
48 | -- require ("logging"):new():DEBUG(lprotobuf)
49 |
50 | return pb
51 |
--------------------------------------------------------------------------------
/docker/script/ws.lua:
--------------------------------------------------------------------------------
1 | local class = require "class"
2 | local cf = require "cf"
3 | local json = require "json"
4 | local websocket = class("websocket")
5 |
6 | function websocket:ctor(opt)
7 | self.ws = opt.ws -- websocket对象
8 | self.send_masked = false -- 掩码(默认为false, 不建议修改或者使用)
9 | self.max_payload_len = 65535 -- 最大有效载荷长度(默认为65535, 不建议修改或者使用)
10 | self.timeout = 15 -- 默认为一直等待, 非number类型会导致异常.
11 | self.count = 0
12 | end
13 |
14 | function websocket:on_open()
15 | print('on_open')
16 | self.timer = cf.at(0.01, function ( ... ) -- 定时器
17 | self.count = self.count + 1
18 | self.ws:send(tostring(self.count))
19 | end)
20 | end
21 |
22 | function websocket:on_message(data, typ)
23 | print('on_message', self.ws, data)
24 | self.ws:send('welcome')
25 | -- self.ws:close(data)
26 | end
27 |
28 | function websocket:on_error(error)
29 | print('on_error', self.ws, error)
30 | end
31 |
32 | function websocket:on_close(data)
33 | print('on_close', self.ws, data)
34 | if self.timer then -- 清理定时器
35 | print("清理定时器")
36 | self.timer:stop()
37 | self.timer = nil
38 | end
39 | end
40 |
41 | return websocket
42 |
--------------------------------------------------------------------------------
/luaclib/src/lchild.c:
--------------------------------------------------------------------------------
1 | #define LUA_LIB
2 |
3 | #include
4 |
5 | static void CHILD_CB (core_loop *loop, ev_child *w, int revents){
6 | ev_child_stop(loop, w);
7 | lua_State *co = core_get_watcher_userdata(w);
8 | if (co) {
9 | lua_pushinteger(co, w->rpid);
10 | lua_pushinteger(co, w->rstatus);
11 | int status = CO_RESUME(co, NULL, lua_status(co) == LUA_YIELD ? lua_gettop(co) : lua_gettop(co) - 1);
12 | if (status != LUA_YIELD && status != LUA_OK){
13 | LOG("ERROR", lua_tostring(co, -1));
14 | }
15 | }
16 | }
17 |
18 | /* 监听子进程状态 */
19 | static int lwatch(lua_State *L){
20 | core_child* child = lua_newuserdata(L, sizeof(core_child));
21 | core_child_init(child, CHILD_CB, luaL_checkinteger(L, 1), 0);
22 | core_child_start(core_default_loop(), child);
23 | core_set_watcher_userdata(child, (void*)lua_tothread(L, 2));
24 | return 1;
25 | }
26 |
27 | /* 发信号杀死子进程 */
28 | static int lkill(lua_State *L){
29 | kill(luaL_checkinteger(L, 1), SIGQUIT);
30 | return 0;
31 | }
32 |
33 | LUAMOD_API int luaopen_child(lua_State *L) {
34 | luaL_checkversion(L);
35 | luaL_Reg child_libs[] = {
36 | {"watch", lwatch},
37 | {"kill", lkill},
38 | {NULL, NULL},
39 | };
40 | luaL_newlib(L, child_libs);
41 | return 1;
42 | }
--------------------------------------------------------------------------------
/src/core_memory.h:
--------------------------------------------------------------------------------
1 | #ifndef __CORE_MEMORY__
2 | #define __CORE_MEMORY__
3 |
4 | #include
5 |
6 | #define malloc xmalloc
7 | #define calloc xcalloc
8 | #define realloc xrealloc
9 | #define free xfree
10 |
11 | #define xmalloc xmalloc
12 | #define xcalloc xcalloc
13 | #define xrealloc xrealloc
14 | #define xfree xfree
15 |
16 | #define strdup xstrdup
17 | #define strndup xstrndup
18 | #define realpath xrealpath
19 |
20 | char* xstrdup(const char *s);
21 | char* xstrndup(const char *s, size_t n);
22 | char* xrealpath(const char *path, char *resolved);
23 |
24 | void* xmalloc(size_t size);
25 | void* xcalloc(size_t nmemb, size_t size);
26 | void* xrealloc(void* ptr, size_t size);
27 | void xfree(void *ptr);
28 |
29 | #ifdef __cplusplus
30 | #if defined(__llvm__) || defined(__clang__)
31 | #pragma GCC diagnostic ignored "-Winline-new-delete"
32 | #endif
33 | #include
34 | /* malloc */
35 | inline void* operator new(std::size_t size) noexcept(false) { return xmalloc(size); }
36 | inline void* operator new[](std::size_t size) noexcept(false) { return xmalloc(size); }
37 | /* free */
38 | inline void operator delete(void *ptr) noexcept { xfree(ptr); }
39 | inline void operator delete[](void *ptr) noexcept { xfree(ptr); }
40 | #endif
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/lualib/process/worker.lua:
--------------------------------------------------------------------------------
1 | local dataset = require "process.dataset"
2 |
3 | local channel = require "process.channel"
4 | local channel_send = channel.send
5 |
6 | local lpack = require "pack"
7 | local lpack_encode = lpack.encode
8 |
9 | local session = require "process.session"
10 | local session_getsid = session.getsid
11 | local sessionid_wait = session.wait
12 |
13 | local process = { isWorker = true, pid = dataset.get('pid') }
14 |
15 | local mchan = nil
16 |
17 | ---comment 由框架完成进程初始化.
18 | function process.init()
19 | -- 构建进程通信通道
20 | mchan = channel:new()
21 | mchan:connect('worker')
22 | end
23 |
24 | ---comment 向`Master`进程发送消息(非阻塞)
25 | function process.send(...)
26 | channel_send(mchan, lpack_encode(nil, ...))
27 | end
28 |
29 | ---comment 向`Master`进程发送消息(会阻塞)
30 | function process.call(...)
31 | local sessionid = session_getsid()
32 | channel_send(mchan, lpack_encode(sessionid, ...))
33 | return sessionid_wait(sessionid)
34 | end
35 |
36 | ---comment 注册进程事件
37 | ---@param msg_type string @事件类型: `message`
38 | ---@param func function @回调函数: function(sessionid, ...)
39 | function process.on(msg_type, func)
40 | -- 注册消息事件
41 | if msg_type == 'message' and type(func) == 'function' then
42 | mchan:setcb(func)
43 | return
44 | end
45 | end
46 |
47 | return process
--------------------------------------------------------------------------------
/3rd/README.md:
--------------------------------------------------------------------------------
1 | ## 用户自定义库目录
2 |
3 | 此目录是用户自定义目录, cf开发者不会对3rd内部文件进行任何意义上的修改, 3rd内组织方式需要用户自行确定.
4 |
5 | 在使用者编译cf的make build, make rebuild, make clean等命令的时候将会同时传入到3rd的Makefile内.
6 |
7 | 3rd也为用户自定义库提供整合方式或联合编译(如有需要), 使用者在开发阶段可能会需要自己编写一套业务维护库.
8 |
9 | 3rd的库维护者应该(至少)维护上述三个编译命令并使其正常工作. 同时, 维护者也需要至少保证以下两点:
10 |
11 | 1. 3rd库的维护者(至少)需要保证引用名唯一性;
12 |
13 | 2. 3rd库的维护者(至少)需要保证无(除cf)的底层特殊依赖性;
14 |
15 | 注: 在无需编译的情况下, 使用者可以讲makefile看做一套自定义库代码整理集合. 有助于用户自行组织库目录.
16 |
17 | ## 如何在3rd维护自己的lua库?
18 |
19 | 1. 将文件copy到3rd目录下(这里假设直接copy到3rd根目录, 当然也可以自行构建目录结构)
20 |
21 | 2. 在main.lu文件内使用```local lib = require "3rd.you_lib_name"```
22 |
23 | 3. 开始使用.
24 |
25 | ## 如何在3rd维护自己的lua C库?
26 |
27 | 1. 按照lua C API开发模式开发完毕(可参考luaclib内的文件).
28 |
29 | 2. 将源码copy到3rd目录下, 并在修改```3rd/Makefile```进行进行联合编译.
30 |
31 | 3. 编译完成之后, 执行自己定义的脚本整理文件与路径.
32 |
33 | 4. 在main.lu文件内使用```local lib = require "3rd.you_lib_name"```
34 |
35 | 5. 开始使用.
36 |
37 | ## 最简单3rd用户库编写实例
38 |
39 | 首先, 在3rd目录下新建一个名为```printer.lua```的文件, 其内容如下:
40 |
41 | ```lua
42 | return function (...)
43 | return print(...)
44 | end
45 | ```
46 |
47 | 然后, 清空```script/main.lua```内的所有内容, 然后输入以下内容:
48 |
49 | ```lua
50 | local printer = require "3rd.printer"
51 |
52 | printer("这是我在3rd内编写的库")
53 | ```
54 |
55 | 最后, 使用```./cfadmin``` 命令运行并查看效果.
56 |
--------------------------------------------------------------------------------
/lualib/admin/db/init.lua:
--------------------------------------------------------------------------------
1 | local crypt = require "crypt"
2 | local config = require "admin.config"
3 |
4 | local log = require "logging"
5 | local Log = log:new({path = 'admin-db'})
6 |
7 | local fmt = string.format
8 | local os_time = os.time
9 | -- 作为初始化DB工作, 这个函数(must)只能运行一次.
10 | -- 一般情况下, 大家在设计完成后都会手动简历数据表并导入内容.
11 | -- 此文件仅作为作者调试与使用者开发使用, 不对此文件做任何其它保证.
12 | local create_admin = fmt([[
13 | INSERT INTO
14 | `cfadmin_users`
15 | (`id`, `name`, `username`, `password`, `email`, `phone`, `role`, `create_at`, `update_at`, `active`)
16 | VALUES
17 | ('1', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '1')]],
18 | '管理员', 'admin', crypt.sha1('admin', true), '869646063@qq.com', '13000000000', '1', os_time(), os_time())
19 |
20 | local create_admin_role = fmt([[
21 | INSERT INTO
22 | cfadmin_roles
23 | (`id`, `name`, `is_admin`, `create_at`, `update_at`, `active`)
24 | VALUES
25 | ('1', '管理员', '1', '%s', '%s', '1')
26 | ]], os_time(), os_time())
27 |
28 | return function ()
29 | local ret, err
30 | local db = config.db
31 | local now = os_time()
32 | -- 初始化用户
33 | ret, err = db:query(create_admin)
34 | if not ret then
35 | Log:ERROR(err)
36 | end
37 | -- 初始化角色
38 | ret, err = db:query(create_admin_role)
39 | if not ret then
40 | Log:ERROR(err)
41 | end
42 | return true, '初始化完成'
43 | end
44 |
--------------------------------------------------------------------------------
/lualib/cloud/translate/youdao.lua:
--------------------------------------------------------------------------------
1 | local httpc = require "httpc"
2 |
3 | local type = type
4 |
5 | --[[
6 | 免费的有道词典接口, 采用https安全传输.
7 | ]]
8 |
9 | local youdao = { __Version__ = 0.1, host = "https://fanyi.youdao.com/translate"}
10 |
11 | -- 中文 >> 英语
12 | youdao.ZH_CN2EN = "ZH_CN2EN"
13 | -- 中文 >> 日语
14 | youdao.ZH_CN2JA = "ZH_CN2JA"
15 | -- 中文 >> 韩语
16 | youdao.ZH_CN2KR = "ZH_CN2KR"
17 | -- 中文 >> 法语
18 | youdao.ZH_CN2FR = "ZH_CN2FR"
19 | -- 中文 >> 俄语
20 | youdao.ZH_CN2RU = "ZH_CN2RU"
21 | -- 中文 >> 西语
22 | youdao.ZH_CN2SP = "ZH_CN2SP"
23 | -- 英语 >> 中文
24 | youdao.EN2ZH_CN = "EN2ZH_CN"
25 | -- 日语 >> 中文
26 | youdao.JA2ZH_CN = "JA2ZH_CN"
27 | -- 韩语 >> 中文
28 | youdao.KR2ZH_CN = "KR2ZH_CN"
29 | -- 法语 >> 中文
30 | youdao.FR2ZH_CN = "FR2ZH_CN"
31 | -- 俄语 >> 中文
32 | youdao.RU2ZH_CN = "RU2ZH_CN"
33 | -- 西语 >> 中文
34 | youdao.SP2ZH_CN = "SP2ZH_CN"
35 |
36 | -- 转换
37 | function youdao.translate(translate_type, translate_text)
38 | translate_type = youdao[translate_type]
39 | if type(translate_type) ~= 'string' then
40 | translate_type = "AUTO"
41 | end
42 | if type(translate_text) ~= 'string' or translate_text == '' then
43 | return nil, "invalid translate_text."
44 | end
45 | return httpc.get(youdao.host, nil, {
46 | {"doctype", "json"},
47 | {"i", translate_text},
48 | {"type", translate_type},
49 | })
50 | end
51 |
52 | return youdao
--------------------------------------------------------------------------------
/script/ws.lua:
--------------------------------------------------------------------------------
1 | local class = require "class"
2 | local cf = require "cf"
3 | require "utils"
4 | local websocket = class("websocket")
5 |
6 |
7 | function websocket:ctor(opt)
8 | self.ws = opt.ws -- websocket对象
9 | self.args = opt.args -- GET传递的参数
10 | self.headers = opt.headers -- HTTP请求头部
11 | self.send_masked = false -- 掩码(默认为false, 不建议修改或者使用)
12 | self.max_payload_len = 65535 -- 最大有效载荷长度(默认为65535, 不建议修改或者使用)
13 | self.timeout = 15 -- 默认为一直等待, 非number类型会导致异常.
14 | self.count = 0
15 | var_dump(self.args)
16 | var_dump(self.headers)
17 | end
18 |
19 | function websocket:on_open()
20 | print('on_open')
21 | self.timer = cf.at(0.01, function ( ... ) -- 定时器
22 | self.count = self.count + 1
23 | self.ws:send(tostring(self.count))
24 | end)
25 | end
26 |
27 | function websocket:on_message(data, typ)
28 | print('on_message', self.ws, data)
29 | self.ws:send('welcome')
30 | -- self.ws:close(data)
31 | end
32 |
33 | function websocket:on_error(error)
34 | print('on_error', self.ws, error)
35 | end
36 |
37 | function websocket:on_close(data)
38 | print('on_close', self.ws, data)
39 | if self.timer then -- 清理定时器
40 | print("清理定时器")
41 | self.timer:stop()
42 | self.timer = nil
43 | end
44 | end
45 |
46 | return websocket
47 |
--------------------------------------------------------------------------------
/lualib/httpd/Redirect.lua:
--------------------------------------------------------------------------------
1 | local type = type
2 | local assert = assert
3 | local find = string.find
4 |
5 | local urldecode = require "url".decode
6 |
7 | local codes = {
8 | [301] = "301 Moved Permanently", -- (永久移动)
9 | [302] = "302 Found", -- (发现)
10 | [303] = "303 See Other", -- (查看其他)
11 | [307] = "307 Temporary Redirect", -- (临时重定向)
12 | [308] = "308 Permanent Redirect", -- (永久重定向)
13 | }
14 |
15 | ---comment 检查状态码是否在指定范围内
16 | ---@param code number @HTTP状态码
17 | ---@return boolean | integer
18 | local function check_code(code)
19 | return codes[code] and code or nil
20 | end
21 |
22 | ---comment 检查重定向的url是否合法.
23 | ---@param url string @合法的路由或http[s]地址
24 | ---@return boolean | string
25 | local function check_url(url)
26 | if type(url) ~= "string" or url == "" then
27 | return false
28 | end
29 | url = urldecode(url)
30 | if find(url, "^/.*") then
31 | return url
32 | end
33 | if find(url, "^http[s]?://.*") then
34 | return url
35 | end
36 | return false
37 | end
38 |
39 | ---comment 让注册的`USE`/`API`路由可以合法的重定向.
40 | ---@param code integer @HTTP状态码.
41 | ---@param url string @需要重定向的`URL`.
42 | return function (code, url)
43 | return { __OPCODE__ = -65536, __CODE__ = assert(check_code(code), "Invalid http code.") , __MSG__ = assert(check_url(url), "Invalid url") }
44 | end
--------------------------------------------------------------------------------
/lualib/template/html.lua:
--------------------------------------------------------------------------------
1 | local template = require "template"
2 | local escape = template.escape
3 |
4 | local setmetatable = setmetatable
5 | local concat = table.concat
6 | local pairs = pairs
7 | local type = type
8 |
9 | local function tag(name, content, attr)
10 | local r, a = {}, {}
11 | content = content or attr
12 | r[#r + 1] = "<"
13 | r[#r + 1] = name
14 | if attr then
15 | for k, v in pairs(attr) do
16 | if type(k) == "number" then
17 | a[#a + 1] = escape(v)
18 | else
19 | a[#a + 1] = k .. '="' .. escape(v) .. '"'
20 | end
21 | end
22 | if #a > 0 then
23 | r[#r + 1] = " "
24 | r[#r + 1] = concat(a, " ")
25 | end
26 | end
27 | if type(content) == "string" then
28 | r[#r + 1] = ">"
29 | r[#r + 1] = escape(content)
30 | r[#r + 1] = ""
31 | r[#r + 1] = name
32 | r[#r + 1] = ">"
33 | else
34 | r[#r + 1] = " />"
35 | end
36 | return concat(r)
37 | end
38 |
39 | local html = { __index = function(_, name)
40 | return function(attr)
41 | if type(attr) == "table" then
42 | return function(content)
43 | return tag(name, content, attr)
44 | end
45 | else
46 | return tag(name, attr)
47 | end
48 | end
49 | end }
50 |
51 | template.html = setmetatable(html, html)
52 |
53 | return template.html
--------------------------------------------------------------------------------
/lualib/httpd/http.lua:
--------------------------------------------------------------------------------
1 | local type = type
2 | local assert = assert
3 | local find = string.find
4 |
5 | ---comment 可以用来控制`before`方法内的行为.
6 | local HTTP = {}
7 |
8 | ---comment 允许`httpd.before`通过(passed)
9 | function HTTP.ok()
10 | return 200
11 | end
12 |
13 | ---comment 此方法可以让开发者在`httpd.before`函数内重定向.
14 | ---@param code integer @重定向的HTTP状态码(301,302,303,307,308)
15 | ---@param url string @重定向的url(`https://cfadmin.cn` or `/api`)
16 | ---@return integer @此方法只可用在`httpd:bedore`方法内.
17 | ---@return string @调用方法必须是`return http.redirect(code, url)`
18 | function HTTP.redirect(code, url)
19 | assert(type(url) == 'string' and url ~= '' and (find(url, '^http[s]?://.+') or find(url, '^/.*')), 'Redirection must give a string type domain name ("http[s]://domain" or "/")')
20 | if type(code) == 'number' and (code == 301 or code == 302 or code == 303 or code == 307 or code == 308) then
21 | return code, url
22 | end
23 | return 302, url
24 | end
25 |
26 | ---comment 此方法可以让开发者在`httpd.before`函数内抛出异常.
27 | ---@param code integer @`HTTP`异常状态码(`400`-`600`之间)
28 | ---@param body string @异常的具体内容(optional)
29 | ---@return integer @此方法只可用在`httpd:bedore`方法内.
30 | ---@return string? @调用方法必须是`return http.throw(code, body)`
31 | function HTTP.throw(code, body)
32 | assert(type(code) == 'number' and code >= 400 and code < 600, 'The specified error code must be within the range (400-600).')
33 | if type(body) == 'string' and body ~= '' then
34 | return code, body
35 | end
36 | return code
37 | end
38 |
39 | return HTTP
--------------------------------------------------------------------------------
/docker/docker-compose-with-traefik.yaml:
--------------------------------------------------------------------------------
1 | # docker-compose.yaml
2 | version: "2"
3 | services:
4 | WebProxy:
5 | image: traefik
6 | restart: always
7 | command: --api --docker # Enables the web UI and tells Traefik to listen to docker
8 | ports:
9 | - "80:80" # The HTTP port
10 | - "8080:8080" # The Web UI (enabled by --api)
11 | volumes:
12 | - /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
13 | networks:
14 | - local
15 |
16 | WebApp:
17 | image: candymi/cfweb:latest
18 | restart: always
19 | labels:
20 | - "traefik.port=8080"
21 | - "traefik.backend=WebApp"
22 | - "traefik.enable=true"
23 | - "traefik.domain=localhost"
24 | - "traefik.frontend.rule=Host:localhost"
25 | volumes:
26 | - ./script:/app/script/
27 | networks:
28 | - local
29 |
30 | WebDB:
31 | image: mysql:5.6 #支持8.X以上版本, 但是必须开启下面的COMMAND参数.
32 | restart: always
33 | environment:
34 | - MYSQL_ROOT_PASSWORD=123456789
35 | - MYSQL_DATABASE=cfadmin
36 | # 8.x以上版本必须设置为mysql_native_password, 否则无法连接到MySQL
37 | # command: --default-authentication-plugin=mysql_native_password
38 | volumes:
39 | - ./db/:/docker-entrypoint-initdb.d/
40 | # 如需设置时区, 建议请将localtime提取到home目录下再挂在使用
41 | # - /etc/localtime:/etc/localtime
42 | ports:
43 | - 3306:3306
44 | networks:
45 | - local
46 |
47 | networks:
48 | local:
49 | driver: bridge
50 |
--------------------------------------------------------------------------------
/lualib/process/session.lua:
--------------------------------------------------------------------------------
1 | local cf = require "cf"
2 | local cf_self = cf.self
3 | local cf_wait = cf.wait
4 | local cf_wakeup = cf.wakeup
5 |
6 | local dataset = require "process.dataset"
7 | local prefixid = dataset.get("pid")
8 | local minid, maxid = prefixid << 32 | 1, prefixid << 32 | 4294967295
9 | local sid = minid
10 |
11 | local assert = assert
12 | local mtype = math.type
13 |
14 | local session_map = {}
15 |
16 | local session = {}
17 |
18 | ---comment 获取`sessionid`
19 | ---@return integer @返回`sessionid`
20 | function session.getsid()
21 | if minid == maxid then
22 | sid = minid
23 | end
24 | local sessionid = sid
25 | sid = sid + 1
26 | return sessionid
27 | end
28 |
29 | ---comment 获取进程ID
30 | ---@param sessionid integer @会话`ID`
31 | ---@return integer @返回进程`ID`
32 | function session.get_pid(sessionid)
33 | assert(mtype(sessionid) == 'integer', "Invalide `sessionid`")
34 | return (sessionid >> 32) & 0xFFFFFFFF
35 | end
36 |
37 | ---comment 等待`sessionid`
38 | ---@param sessionid integer @会话`ID`
39 | function session.wait(sessionid)
40 | assert(mtype(sessionid) == 'integer', "Invalide `sessionid`")
41 | session_map[sessionid] = cf_self()
42 | return cf_wait()
43 | end
44 |
45 | ---comment 唤醒`sessionid`
46 | ---@param sessionid integer @会话`ID`
47 | function session.wakeup(sessionid, ...)
48 | local co = session_map[sessionid]
49 | if co then
50 | session_map[sessionid] = nil
51 | cf_wakeup(co, ...)
52 | return true
53 | end
54 | return false
55 | end
56 |
57 | return session
--------------------------------------------------------------------------------
/lualib/json/init.lua:
--------------------------------------------------------------------------------
1 | local cjson = require "cjson"
2 |
3 | local setmetatable = setmetatable
4 |
5 | local cjson_array_mt = cjson.array_mt
6 |
7 | -- this lib fork from resty cjson, only modified some compatible codes
8 | -- more details please check it.
9 |
10 | cjson.decode_array_with_array_mt(true)
11 |
12 | -- 默认允许稀疏数组
13 | cjson.encode_sparse_array(true)
14 |
15 | local json = {
16 | null = null,
17 | _VERSION = cjson._VERSION,
18 | array_mt = cjson_array_mt,
19 | empty_array = cjson.empty_array,
20 | empty_array_mt = cjson.empty_array_mt,
21 | encode_max_depth = cjson.encode_max_depth,
22 | encode_sparse_array = cjson.encode_sparse_array,
23 | decode_max_depth = cjson.decode_max_depth,
24 | decode_array_with_array_mt = cjson.decode_array_with_array_mt,
25 | encode_empty_table_as_object = cjson.encode_empty_table_as_object,
26 | }
27 |
28 | cjson = require "cjson.safe"
29 | local cjson_encode = cjson.encode
30 | local cjson_decode = cjson.decode
31 |
32 | -- 设置稀疏数组用null填充
33 | function json.sparse_array_to_null(array)
34 | return setmetatable(array, cjson_array_mt)
35 | end
36 |
37 | ---comment json序列化
38 | ---@param tab table @可序列化的`lua table`
39 | ---@return string @合法的`json`字符串
40 | function json.encode (tab)
41 | return cjson_encode(tab)
42 | end
43 |
44 | ---comment json反序列化
45 | ---@param json string @合法的json字符串
46 | ---@return table @`lua table`
47 | function json.decode (json)
48 | return cjson_decode(json)
49 | end
50 |
51 | return json
52 |
--------------------------------------------------------------------------------
/lualib/httpd/Response.lua:
--------------------------------------------------------------------------------
1 | local type = type
2 | local assert = assert
3 |
4 | local aio = require "aio"
5 | local aio_stat = aio.stat
6 |
7 | ---@comment Httpd响应构造器
8 | local Response = { __VERSION__ = 0.1 }
9 |
10 | ---@comment 文件类型
11 | ---@param filename string @合法且完整的`文件路径`(如: `static/index.html`)
12 | ---@param filetype string @合法且完整的`文件类型`(如: `text/css`)
13 | ---@param fileinline boolean @响应的文件是否需要内嵌到浏览器
14 | ---@return table @`文件`响应构造器
15 | function Response.file_response(filename, filetype, fileinline)
16 | assert(type(filename) == 'string' and filename ~= '', "[http `make_file` response] : file name does not exist.")
17 | local info = aio_stat(filename)
18 | if type(info) ~= 'table' or info.mode ~= 'file' then
19 | return assert(nil, "[http `make_file` response] : can't find file or invalid file type.")
20 | end
21 | return { __OPCODE__ = -128, __CODE__ = 200, __FILEINLINE__ = fileinline, __FILENAME__ = filename, __FILETYPE__ = type(filetype) == 'string' and filetype or nil, __FILESIZE__ = aio_stat(filename).size }
22 | end
23 |
24 | ---@comment 文本类型
25 | ---@param ctext string @合法且完整的`响应内容`(如: `Hello World.`)
26 | ---@param ctype string @合法且完整的`响应类型`(如: `text/html`)
27 | ---@return table @`文本`响应构造器
28 | function Response.text_response(ctext, ctype)
29 | assert(type(ctype) == 'string' and type(ctext) == 'string', "[http `make_text` response] : Invalid content type or response content.")
30 | return { __OPCODE__ = -128, __CODE__ = 200, __TYPE__ = ctype, __MSG__ = ctext }
31 | end
32 |
33 | return Response
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2018, Candy
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/lualib/admin/httpctx.lua:
--------------------------------------------------------------------------------
1 | local class = require "class"
2 | local Cookie = require "admin.cookie"
3 |
4 | local xml2lua = require "xml2lua"
5 |
6 | local json = require "json"
7 | local json_encode = json.encode
8 | local json_decode = json.decode
9 |
10 | local type = type
11 | local split = string.sub
12 | local find = string.find
13 |
14 | local ctx = class("ctx")
15 |
16 | function ctx:ctor (opt)
17 | self._content = opt.content
18 | end
19 |
20 | -- 获取请求path
21 | function ctx:get_path ()
22 | return split(self._content.path, 1, (find(self._content.path, '?') or 0) - 1)
23 | end
24 |
25 | -- 获取原始path
26 | function ctx:get_raw_path ()
27 | return self._content.path
28 | end
29 |
30 | -- 获取请求头部
31 | function ctx:get_headers ()
32 | return self._content.headers
33 | end
34 |
35 | -- 获取请求方法
36 | function ctx:get_method ()
37 | return self._content.method
38 | end
39 |
40 | -- 获取Cookie
41 | function ctx:get_cookie (name)
42 | return Cookie.getCookie(name)
43 | end
44 |
45 | -- 获取上传的文件
46 | function ctx:get_files ()
47 | return self._content.files
48 | end
49 |
50 | -- 获取请求参数表
51 | function ctx:get_args ()
52 | local args = self._content.args
53 | if type(args) == 'table' then
54 | return args
55 | end
56 | local body = self._content.body
57 | if body then
58 | local xml = self._content.xml
59 | local json = self._content.json
60 | if xml then
61 | args = xml2lua.parser(body)
62 | if type(args) == 'table' then
63 | return args
64 | end
65 | end
66 | if json then
67 | args = json_decode(body)
68 | if type(args) == 'table' then
69 | return args
70 | end
71 | end
72 | end
73 | end
74 |
75 | return ctx
76 |
--------------------------------------------------------------------------------
/lualib/cloud/qiniu/censor.lua:
--------------------------------------------------------------------------------
1 | local token = require "cloud.qiniu.token"
2 | local httpc = require "httpc"
3 | local json = require "json"
4 |
5 | local Censor = { __Version__ = 0.1, host = "ai.qiniuapi.com" }
6 |
7 | --[[
8 | 内容审核: image 图片审核, video 视频审核
9 | ]]
10 |
11 | -- 图片内容审核
12 | function Censor.newImageCensor (AccessKey, SecretKey, image_uri, params)
13 | local path = "/v3/image/censor"
14 | local body = json.encode({ data = { uri = image_uri or "" }, params = params or { scenes = {"pulp", "terror", "politician"} , detail = true } })
15 | local Authorization = token.newAuthorization(AccessKey, SecretKey, { method = "POST", path = path, host = Censor.host, body = body})
16 | return httpc.json("https://" .. Censor.host .. path, { {"Authorization", Authorization} }, body)
17 | end
18 |
19 | -- 视频内容审核
20 | function Censor.newVideoCensor (AccessKey, SecretKey, video_uri, params)
21 | local path = "/v3/video/censor"
22 | local body = json.encode({ data = { uri = video_uri or "" }, params = params or { scenes = {"pulp", "terror", "politician"} , cut_param = { interval_msecs = 5000 } } })
23 | local Authorization = token.newAuthorization(AccessKey, SecretKey, { method = "POST", path = path, host = Censor.host, body = body})
24 | return httpc.json("https://" .. Censor.host .. path, { {"Authorization", Authorization} }, body)
25 | end
26 |
27 | -- 根据job_id检查视频审核结果
28 | function Censor.getVideoCensorResult (AccessKey, SecretKey, job_id)
29 | local path = "/v3/jobs/video/" .. job_id
30 | local Authorization = token.newAuthorization(AccessKey, SecretKey, { method = "GET", path = path, host = Censor.host })
31 | return httpc.get("https://" .. Censor.host .. path, { {"Authorization", Authorization} })
32 | end
33 |
34 | return Censor
35 |
--------------------------------------------------------------------------------
/private2048.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIIEpAIBAAKCAQEAuhsl0nR17nqITIkMYqzrhbT5me5+Q+G387spzR8KWbVujoRF
3 | Qa6DNzZS8HPNmBW8HjVZJ29uBAAtpWpoERdwvT31Kag+q9eSpX1d02uTd43cESNT
4 | b1bYCYd3LHdPZ9GSH3gIfD/fk2P8zJytzED7cT1gDUqzCcxi3cvH6/yHb6hmYmNs
5 | Qo1MLTn3kxyzU32J3nhNEZTlHq1XE9ydqLVqDCMRPOUuOsXcIb9ASZh3ExSPU2cx
6 | +8WMAWWoCw/kO7EJ4Vinl8NDbsRoyXjweekYZ0bH9YrN4y05KLMhsQhoxBdmKdcJ
7 | ErPwYad17vtmhTpdwEpCriL/iZDLUDOz1G2ngwIDAQABAoIBAQC11cqZm0KS1NQR
8 | e6JHU073oAB0f0qNRqB2GrvX9+kkB5pS0zfb2gfIzWIyH+OUIkBgf51xY3VpoUb4
9 | JUQy1uVHcZ71qbY6LnHREfG3nZdDK68Ga66czYxdmyc8ogJKnMAZ0SzxQXNQTlR1
10 | EuzY8fD7Do2nzwGppDJBJVdb4qvt0kAEBu+0O5srUuGNzJJzktAIwzk7aFpVhw+l
11 | cCS6ZY5rRM0AeQ2tomVvf+81bs8JOG8T7JtJ+o2cL+bZjRKhCHliQZQzByEQtOZx
12 | J8s0mr3Tj9FzXfy6pUYSO1+GiWgrjV0nnaKj+sqE/MuuNam/nA64us8kLE7RA3gH
13 | n7tLJwDBAoGBAOLoQf6KuE7D0WTVj5tb/CnAtPsZ18tClvElPgex/32Cjwuwy/Du
14 | yPn/EIWO2EJX1dtRdWe34OJYtOcZk4qbFiyB/rxjsr6UAPNO/tY55nW2OqZ944Dq
15 | 3duzUb3jVeAI3HyGksvHZwBJ5t7o80BBYUdk28G2ZNjaalL1HqgXzjxjAoGBANH3
16 | rZPQU3yvuFQdL3HlV3h7PNyNwkyjVMgD+jCdIrySIw0DqisJFgWoVxNl92lhUkir
17 | ZPY8dzZ6uFh6tx12QyoO2VG6Y9Pf3GvjHC1yUQqWu///+jvHwUqdPPQgHXvwKSOU
18 | eJVaseNHwBNV35AEdRwMDOsqQUN30lhoa5fy8AJhAoGAXQR9WU2gtJlNk5qAnl2d
19 | B7i5+F3luqt3mS99OEZdyCPnZBF76S7aMLHBIh8mxDuhraC9EmGszN00e7BebWma
20 | M3Cu7qeoNLwTj6qIiWV+9i5X6LyesNCXVmMyVTeGkqrPSDUapHL/5HxnKmYwodyr
21 | dksAU27j9InFIHDfumTX5KUCgYEAoXsuCOeIvfVa+33ytlLfAe8t8KYpz80x8B52
22 | 9Zp0U7jEskamQjDbugAs7+NU87wAj5kZrfL08HZTfuDqIgOJRjhjVOLX0eRyXpst
23 | WZp4z378Gbfh2MYZV2w0q8BjTKV4zj9qudslwpm1FGnP5bA37RkrelVmGiB2Kr4s
24 | OZGCmyECgYBhXtk5BfZocI+l2/R2Yncn6Gx8s4s7bD+Fr5LE3FkU1neOuk7Yf1Uu
25 | xf41e3o5YBxbt51T+pNuzF3BMxsXvp9a5HxbPsmGE99BLFwR9DompoLKeUlJcy6f
26 | xJyXi8HBgR0OWNoTjKgaUmTgqKK5LI49C9C4Jr4c3nelo6DBb66vyw==
27 | -----END RSA PRIVATE KEY-----
28 |
--------------------------------------------------------------------------------
/lualib/admin/db/header.lua:
--------------------------------------------------------------------------------
1 | local toint = math.tointeger
2 | local os_time = os.time
3 | local fmt = string.format
4 |
5 | local header = {}
6 |
7 | -- header 列表
8 | function header.header_list (db, opt)
9 | local limit = toint(opt.limit) or 10
10 | local page = toint(opt.page) or 1
11 | return db:query(fmt([[SELECT id, name, url, create_at, update_at FROM cfadmin_headers WHERE active = 1 ORDER BY id LIMIT %s, %s]], limit * (page - 1) , limit))
12 | end
13 |
14 | -- 获取指定header
15 | function header.get_header (db, id)
16 | local ret = db:query(fmt([[ SELECT id, name, url FROM cfadmin_headers WHERE id = '%s' LIMIT 1]], id))
17 | if not ret or #ret == 0 then
18 | return
19 | end
20 | return ret[1]
21 | end
22 |
23 | -- header 总数
24 | function header.header_count (db)
25 | return db:query([[SELECT count(id) AS count FROM cfadmin_headers WHERE active = 1]])[1]['count']
26 | end
27 |
28 | -- 是否存在此header
29 | function header.header_exists (db, id)
30 | local ret = db:query(fmt([[SELECT id FROM cfadmin_headers WHERE id = '%s' AND active = 1 LIMIT 1]], id))
31 | return ret and #ret > 0
32 | end
33 |
34 | -- 删除header
35 | function header.header_delete (db, id)
36 | return db:query(fmt([[UPDATE cfadmin_headers SET active = '0', update_at = '%s' WHERE id = '%s' AND active = 1]], os_time(), id))
37 | end
38 |
39 | -- 增加header
40 | function header.header_add(db, opt)
41 | return db:query(fmt([[INSERT INTO cfadmin_headers(`name`, `url`, `create_at`, `update_at`, `active`) VALUES('%s', '%s', '%s', '%s', 1)]], opt.name, opt.url, os_time(), os_time()))
42 | end
43 |
44 | -- 修改header
45 | function header.header_update (db, opt)
46 | return db:query(fmt([[UPDATE cfadmin_headers SET name = '%s', url = '%s', update_at = '%s' WHERE id = '%s']], opt.name, opt.url, os_time(), opt.id))
47 | end
48 |
49 | return header
50 |
--------------------------------------------------------------------------------
/static/lib/layui/lay/modules/laytpl.js:
--------------------------------------------------------------------------------
1 | /** layui-v2.5.4 MIT License By https://www.layui.com */
2 | ;layui.define(function(e){"use strict";var r={open:"{{",close:"}}"},c={exp:function(e){return new RegExp(e,"g")},query:function(e,c,t){var o=["#([\\s\\S])+?","([^{#}])*?"][e||0];return n((c||"")+r.open+o+r.close+(t||""))},escape:function(e){return String(e||"").replace(/&(?!#?[a-zA-Z0-9]+;)/g,"&").replace(//g,">").replace(/'/g,"'").replace(/"/g,""")},error:function(e,r){var c="Laytpl Error:";return"object"==typeof console&&console.error(c+e+"\n"+(r||"")),c+e}},n=c.exp,t=function(e){this.tpl=e};t.pt=t.prototype,window.errors=0,t.pt.parse=function(e,t){var o=this,p=e,a=n("^"+r.open+"#",""),l=n(r.close+"$","");e=e.replace(/\s+|\r|\t|\n/g," ").replace(n(r.open+"#"),r.open+"# ").replace(n(r.close+"}"),"} "+r.close).replace(/\\/g,"\\\\").replace(n(r.open+"!(.+?)!"+r.close),function(e){return e=e.replace(n("^"+r.open+"!"),"").replace(n("!"+r.close),"").replace(n(r.open+"|"+r.close),function(e){return e.replace(/(.)/g,"\\$1")})}).replace(/(?="|')/g,"\\").replace(c.query(),function(e){return e=e.replace(a,"").replace(l,""),'";'+e.replace(/\\/g,"")+';view+="'}).replace(c.query(1),function(e){var c='"+(';return e.replace(/\s/g,"")===r.open+r.close?"":(e=e.replace(n(r.open+"|"+r.close),""),/^=/.test(e)&&(e=e.replace(/^=/,""),c='"+_escape_('),c+e.replace(/\\/g,"")+')+"')}),e='"use strict";var view = "'+e+'";return view;';try{return o.cache=e=new Function("d, _escape_",e),e(t,c.escape)}catch(u){return delete o.cache,c.error(u,p)}},t.pt.render=function(e,r){var n,t=this;return e?(n=t.cache?t.cache(e,c.escape):t.parse(t.tpl,e),r?void r(n):n):c.error("no data")};var o=function(e){return"string"!=typeof e?c.error("Template not found"):new t(e)};o.config=function(e){e=e||{};for(var c in e)r[c]=e[c]},o.v="1.2.0",e("laytpl",o)});
--------------------------------------------------------------------------------
/lualib/mail/init.lua:
--------------------------------------------------------------------------------
1 | local smtp = require "protocol.smtp"
2 |
3 | local toint = math.tointeger
4 | local match = string.match
5 |
6 | local function check_mail(mail)
7 | if match(mail, '.+@.+') then
8 | return true
9 | end
10 | return false
11 | end
12 |
13 | local mail = {}
14 |
15 | function mail.send(opt)
16 | if not opt.username or not opt.password or opt.username == '' or opt.password == '' then
17 | return nil, "Username or password cannot be empty."
18 | end
19 | if not opt.from or not opt.to or opt.from == '' or opt.to == '' or not check_mail(opt.from) or not check_mail(opt.to) then
20 | return nil, "The sender or receiver of the email cannot be empty."
21 | end
22 | if not opt.host or not opt.port or opt.host == '' or (not toint(opt.port)) or (toint(opt.port) <= 0 or toint(opt.port) > 65535) then
23 | return nil, "Invalid target mail server configuration."
24 | end
25 | if not opt.subject or opt.subject == '' then
26 | return nil, "The email subject is empty, please check the configuration parameters."
27 | end
28 | if not opt.content or opt.content == '' then
29 | return nil, "The email content is empty, please check the configuration parameters."
30 | end
31 | local s = smtp:new(opt):set_timeout(15)
32 | -- 开始发送邮件
33 | local ok, err
34 | -- 尝试连接服务器
35 | ok, err = s:connect()
36 | if not ok then
37 | return nil, err, s:close()
38 | end
39 | -- print("连接成功")
40 | -- 尝试握手包
41 | ok, err = s:hello_packet()
42 | if not ok then
43 | return nil, err, s:close()
44 | end
45 | -- print("握手成功")
46 | -- 身份认证
47 | ok, err = s:auth_packet()
48 | if not ok then
49 | return nil, err, s:close()
50 | end
51 | -- print("认证成功")
52 | -- 发送数据
53 | ok, err = s:send_mail()
54 | s:close()
55 | if not ok then
56 | return nil, err
57 | end
58 | return ok
59 | end
60 |
61 |
62 | return mail
63 |
--------------------------------------------------------------------------------
/script/test_DB.lua:
--------------------------------------------------------------------------------
1 | local LOG = require "logging"
2 | local cf = require "cf"
3 | local DB = require "DB"
4 |
5 | local db = DB:new {
6 | host = 'localhost',
7 | port = 3306,
8 | database = 'mysql',
9 | username = 'root',
10 | password = '123456789',
11 | max = 1,
12 | }
13 |
14 | local ok = db:connect()
15 | if not ok then
16 | return LOG:DEBUG("连接mysql失败")
17 | end
18 | LOG:DEBUG("连接成功")
19 |
20 | --[[
21 | /* 复制下面语句到任意管理工具即可导入测试表进行测试 */
22 |
23 | SET NAMES utf8;
24 | SET FOREIGN_KEY_CHECKS = 0;
25 | CREATE DATABASE IF NOT EXISTS `test` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
26 |
27 | CREATE TABLE IF NOT EXISTS `test`.`user` (
28 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
29 | `name` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
30 | `user` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
31 | `passwd` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
32 | PRIMARY KEY (`id`)
33 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
34 |
35 | SET FOREIGN_KEY_CHECKS = 1;
36 | --]]
37 |
38 | -- 测试普通数据库语句
39 | cf.fork(function ( ... )
40 | local ret, err = db:query("show variables like 'wait_timeout'")
41 | if not ret then
42 | return LOG:DEBUG(err)
43 | end
44 | LOG:DEBUG(ret)
45 | end)
46 |
47 | -- 测试预编译语句
48 | cf.fork(function ( ... )
49 | local ret, err = db:execute([[SELECT version() AS version]])
50 | if not ret then
51 | return LOG:DEBUG(err)
52 | end
53 | LOG:DEBUG(ret)
54 | end)
55 |
56 | -- 测试开启事务
57 | cf.fork(function ()
58 | local status, err = db:transaction(function (session)
59 | LOG:WARN(session:query("show databases"))
60 | LOG:WARN(session:execute("show tables"))
61 |
62 | -- return session:rollback()
63 | return session:commit()
64 | end)
65 | LOG:DEBUG(status, err)
66 | end)
67 |
--------------------------------------------------------------------------------
/docker/conf.d/nginx.conf:
--------------------------------------------------------------------------------
1 | worker_processes 1;
2 |
3 | error_log /var/log/nginx/error.log warn;
4 | pid /var/run/nginx.pid;
5 |
6 |
7 | events {
8 | worker_connections 65535;
9 | }
10 |
11 |
12 | http {
13 | include /etc/nginx/mime.types;
14 | default_type application/octet-stream;
15 |
16 | log_format main '$remote_addr - $remote_user [$time_local] "$request" '
17 | '$status $body_bytes_sent "$http_referer" '
18 | '"$http_user_agent" "req_time:[$request_time/Sec]" "upstream_time:[$upstream_response_time/Sec]" ';
19 |
20 | access_log /var/log/nginx/access.log main;
21 |
22 | #优化文件发送
23 | sendfile on;
24 | #tcp_nopush on;
25 | #关闭Nagle算法
26 | tcp_nodelay on;
27 |
28 | keepalive_timeout 65;
29 |
30 | gzip on;
31 | gzip_vary on;
32 | gzip_min_length 1k;
33 | gzip_comp_level 9;
34 | gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
35 | gzip_disable "MSIE [1-6]\.";
36 |
37 |
38 | upstream myweb {
39 | server webapp1:8080;
40 | server webapp2:8080;
41 | server webapp3:8080;
42 | }
43 |
44 | server {
45 | listen 80;
46 | #access_log /var/log/nginx/8080.log main;
47 |
48 | location /ws {
49 | proxy_pass http://myweb/ws;
50 | proxy_http_version 1.1;
51 | proxy_set_header Upgrade $http_upgrade;
52 | proxy_set_header Connection "upgrade";
53 | }
54 |
55 | location / {
56 | proxy_pass http://myweb;
57 | proxy_http_version 1.1;
58 | proxy_ignore_client_abort on;
59 | proxy_set_header Host $http_host;
60 | proxy_set_header X-Real-IP $remote_addr;
61 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
62 | }
63 |
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/luaclib/src/lpeg/lpvm.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lpvm.h $
3 | */
4 |
5 | #if !defined(lpvm_h)
6 | #define lpvm_h
7 |
8 | #include "lpcap.h"
9 |
10 |
11 | /* Virtual Machine's instructions */
12 | typedef enum Opcode {
13 | IAny, /* if no char, fail */
14 | IChar, /* if char != aux, fail */
15 | ISet, /* if char not in buff, fail */
16 | ITestAny, /* in no char, jump to 'offset' */
17 | ITestChar, /* if char != aux, jump to 'offset' */
18 | ITestSet, /* if char not in buff, jump to 'offset' */
19 | ISpan, /* read a span of chars in buff */
20 | IBehind, /* walk back 'aux' characters (fail if not possible) */
21 | IRet, /* return from a rule */
22 | IEnd, /* end of pattern */
23 | IChoice, /* stack a choice; next fail will jump to 'offset' */
24 | IJmp, /* jump to 'offset' */
25 | ICall, /* call rule at 'offset' */
26 | IOpenCall, /* call rule number 'key' (must be closed to a ICall) */
27 | ICommit, /* pop choice and jump to 'offset' */
28 | IPartialCommit, /* update top choice to current position and jump */
29 | IBackCommit, /* "fails" but jump to its own 'offset' */
30 | IFailTwice, /* pop one choice and then fail */
31 | IFail, /* go back to saved state on choice and jump to saved offset */
32 | IGiveup, /* internal use */
33 | IFullCapture, /* complete capture of last 'off' chars */
34 | IOpenCapture, /* start a capture */
35 | ICloseCapture,
36 | ICloseRunTime
37 | } Opcode;
38 |
39 |
40 |
41 | typedef union Instruction {
42 | struct Inst {
43 | byte code;
44 | byte aux;
45 | short key;
46 | } i;
47 | int offset;
48 | byte buff[1];
49 | } Instruction;
50 |
51 |
52 | void printpatt (Instruction *p, int n);
53 | const char *match (lua_State *L, const char *o, const char *s, const char *e,
54 | Instruction *op, Capture *capture, int ptop);
55 |
56 |
57 | #endif
58 |
59 |
--------------------------------------------------------------------------------
/script/test_dingtalk.lua:
--------------------------------------------------------------------------------
1 | local wb = require "webhook.dingtalk"
2 | local LOG = require "logging"
3 |
4 | -- dingtalk API文档: https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq
5 |
6 | local token = "just_your_token_not_url_and_token" -- such as "de2b0b8a3c4b8d454f47584354a794a12657aa9ff7ccf36b521368d566949e7f"
7 |
8 | LOG:DEBUG(wb.send_text({
9 | token = token,
10 | content = "一条测试消息哦.",
11 | -- ignore mobiles if atall equal true.
12 | -- mobiles = {18680684684, 13000000000},
13 | -- atall = true,
14 | }))
15 |
16 | LOG:DEBUG(wb.send_link {
17 | token = token,
18 | msg_title = "这是一条测试公告",
19 | msg_link = "https://github.com/candymi",
20 | -- optional
21 | msg_pic = "https://avatars2.githubusercontent.com/u/13453599",
22 | msg_describe = "这是测试公告的描述信息, 它描述了这条公告的一些外链关键内容.",
23 | })
24 |
25 | LOG:DEBUG(wb.send_actioncard{
26 | token = token,
27 | msg_title = "## 消息头部",
28 | msg_describe = "## 消息内容",
29 | single = {
30 | title = "阅读全文",
31 | url = "https://www.baidu.com"
32 | }
33 | })
34 |
35 | LOG:DEBUG(wb.send_actioncard{
36 | token = token,
37 | -- 头部
38 | msg_title = "## 消息头部",
39 | -- 描述
40 | msg_describe = "## 消息内容",
41 | -- 隐藏机器人头像
42 | hide_avatar = true,
43 | -- 设置按钮
44 | btns = {
45 | { title = "按钮1", url = "https://www.qq.com" },
46 | { title = "按钮2", url = "https://www.baidu.com" },
47 | { title = "点赞支持", url = "https://www.163.com" },
48 | { title = "残忍关闭", url = "https://www.taobao.com" }
49 | }
50 | })
51 |
52 | LOG:DEBUG(wb.send_feedcard {
53 | token = token,
54 | msg_links = {
55 | {
56 | msg_title = "第1个公告", msg_link = "https://www.baidu.com",
57 | -- msg_pic = "https://avatars2.githubusercontent.com/u/13453599" -- optional
58 | },
59 | {
60 | msg_title = "第2个公告", msg_link = "https://www.qq.com",
61 | -- optional
62 | -- msg_pic = "https://avatars2.githubusercontent.com/u/13453599"
63 | }
64 | }
65 | })
66 |
--------------------------------------------------------------------------------
/src/core_memory.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #if defined(TCMALLOC) || defined(USE_TCMALLOC)
6 | #include
7 | #define _malloc tc_malloc
8 | #define _calloc tc_calloc
9 | #define _realloc tc_realloc
10 | #define _free tc_free
11 | #elif defined(JEMALLOC) || defined(USE_JEMALLOC)
12 | #include
13 | #define _malloc je_malloc
14 | #define _calloc je_calloc
15 | #define _realloc je_realloc
16 | #define _free je_free
17 | #elif defined(MIMALLOC) || defined(USE_MIMALLOC)
18 | #include
19 | #define _malloc mi_malloc
20 | #define _calloc mi_calloc
21 | #define _realloc mi_realloc
22 | #define _free mi_free
23 | #else
24 | #define _malloc malloc
25 | #define _calloc calloc
26 | #define _realloc realloc
27 | #define _free free
28 | #endif
29 |
30 | void* xmalloc(size_t size){
31 | return _malloc(size);
32 | }
33 |
34 | void* xcalloc(size_t nmemb, size_t size){
35 | return _calloc(nmemb, size);
36 | }
37 |
38 | void* xrealloc(void* ptr, size_t size){
39 | return _realloc(ptr, size);
40 | }
41 |
42 | void xfree(void *ptr){
43 | return _free(ptr);
44 | }
45 |
46 | char* xstrdup(const char *s) {
47 | if (!s)
48 | return NULL;
49 | size_t n = strlen(s);
50 | char* p = _malloc(n + 1);
51 | if (!p)
52 | return NULL;
53 | memcpy(p, s, n);
54 | p[n] = '\x00';
55 | return p;
56 | }
57 | char* xstrndup(const char *s, size_t n) {
58 | if (!s)
59 | return NULL;
60 | char* p = _malloc(n + 1);
61 | if (!p)
62 | return NULL;
63 | memcpy(p, s, n);
64 | p[n] = '\x00';
65 | return p;
66 | }
67 |
68 | char* xrealpath(const char *path, char *resolved) {
69 | if (!path)
70 | return NULL;
71 | if (!resolved)
72 | resolved = _calloc(1, sysconf(_PC_PATH_MAX));
73 | return realpath(path, resolved);
74 | }
--------------------------------------------------------------------------------
/luaclib/src/lcjson/NEWS:
--------------------------------------------------------------------------------
1 | Version 2.1.0 (Mar 1 2012)
2 | * Added cjson.safe module interface which returns nil after an error
3 | * Improved Makefile compatibility with Solaris make
4 |
5 | Version 2.0.0 (Jan 22 2012)
6 | * Improved platform compatibility for strtod/sprintf locale workaround
7 | * Added option to build with David Gay's dtoa.c for improved performance
8 | * Added support for Lua 5.2
9 | * Added option to encode infinity/NaN as JSON null
10 | * Fixed encode bug with a raised default limit and deeply nested tables
11 | * Updated Makefile for compatibility with non-GNU make implementations
12 | * Added CMake build support
13 | * Added HTML manual
14 | * Increased default nesting limit to 1000
15 | * Added support for re-entrant use of encode and decode
16 | * Added support for installing lua2json and json2lua utilities
17 | * Added encode_invalid_numbers() and decode_invalid_numbers()
18 | * Added decode_max_depth()
19 | * Removed registration of global cjson module table
20 | * Removed refuse_invalid_numbers()
21 |
22 | Version 1.0.4 (Nov 30 2011)
23 | * Fixed numeric conversion under locales with a comma decimal separator
24 |
25 | Version 1.0.3 (Sep 15 2011)
26 | * Fixed detection of objects with numeric string keys
27 | * Provided work around for missing isinf() on Solaris
28 |
29 | Version 1.0.2 (May 30 2011)
30 | * Portability improvements for Windows
31 | - No longer links with -lm
32 | - Use "socket" instead of "posix" for sub-second timing
33 | * Removed UTF-8 test dependency on Perl Text::Iconv
34 | * Added simple CLI commands for testing Lua <-> JSON conversions
35 | * Added cjson.encode_number_precision()
36 |
37 | Version 1.0.1 (May 10 2011)
38 | * Added build support for OSX
39 | * Removed unnecessary whitespace from JSON output
40 | * Added cjson.encode_keep_buffer()
41 | * Fixed memory leak on Lua stack overflow exception
42 |
43 | Version 1.0 (May 9 2011)
44 | * Initial release
45 |
--------------------------------------------------------------------------------
/script/test_dns.lua:
--------------------------------------------------------------------------------
1 | local LOG = require "logging"
2 | local dns = require "protocol.dns"
3 | local dns_resolve = dns.resolve
4 |
5 | local cf = require "cf"
6 | local fork = cf.fork
7 | local wait = cf.wait
8 |
9 | local system = require "system"
10 | local now = system.now
11 | local fmt = string.format
12 | local find = string.find
13 | local match = string.match
14 |
15 | local pairs = pairs
16 |
17 | -- 去除ipv4->ipv6映射前缀
18 | local function delete_ipv4_prefix (ip)
19 | if system.is_ipv4(ip) then
20 | return ip
21 | end
22 | return find(ip or "", '::ffff') and match(ip, "::[fF]+:([%d%.]+)") or ip
23 | end
24 |
25 | local domains = {
26 | ["百度"] = "www.baidu.com",
27 | ["腾讯"] = "www.qq.com",
28 | ["淘宝"] = "www.taobao.com",
29 | ["谷歌"] = "www.google.com",
30 | ["网易"] = "www.163.com",
31 | ["京东"] = "www.jd.com",
32 | ["唯品会"] = "www.vip.com",
33 | ["盛大"] = "www.sdo.com",
34 | ["测试"] = "pwaj.dwauidwa.raw"
35 | }
36 |
37 | --[[
38 | 计算方式
39 | (min - max + 1) * 1 为单个域名查询总次数
40 | (min - max + 1) * #domain 为所有域名查询总次数
41 | ]]
42 | local min, max = 1, 1
43 |
44 | --[[
45 | 测试方式: 每隔3秒后为每个域名建立1万个协程进行并发查询测试;
46 | 空间消耗: 内存消耗预计在250MB左右;
47 | 时间消耗: 每次网络查询应该在0.1/Sec左右, 每次缓存查询应该在0.001/Sec左右;
48 | ]]
49 | cf.at(3, function ( )
50 | for company, domain in pairs(domains) do
51 | local start = now()
52 | local total = 0
53 | for i = min, max do
54 | fork(function (...)
55 | local t1 = now()
56 | local ok, ip = dns_resolve(domain)
57 | if not ok then
58 | LOG:WARN(fmt("测试失败: <%s>[%s]的结果:[%s]", company, domain, ip))
59 | return
60 | end
61 | total = total + (now() - t1)
62 | if i == max then
63 | LOG:DEBUG(fmt("测试完成 : <%s>[%s]的结果:[%s]; 平均消耗: %0.5f, 总计消耗: %0.8f", company, domain, delete_ipv4_prefix(ip), total / max, now() - start))
64 | end
65 | end)
66 | end
67 | end
68 | collectgarbage()
69 | end)
70 |
71 | wait()
--------------------------------------------------------------------------------
/lualib/cloud/translate/baidu.lua:
--------------------------------------------------------------------------------
1 | local httpc = require "httpc"
2 | local crypt = require "crypt"
3 | local md5 = crypt.md5
4 |
5 | local type = type
6 | local pairs = pairs
7 | local time = os.time
8 | local random = math.random
9 | local concat = table.concat
10 |
11 |
12 | local baidu = { __Version__ = 0.1, host = "https://fanyi-api.baidu.com/api/trans/vip/translate"}
13 |
14 | --[[
15 | 文档地址 :http://api.fanyi.baidu.com/api/trans/product/apidoc
16 |
17 | 语言简写 名称
18 | auto 自动检测
19 | zh 中文
20 | en 英语
21 | yue 粤语
22 | wyw 文言文
23 | jp 日语
24 | kor 韩语
25 | fra 法语
26 | spa 西班牙语
27 | th 泰语
28 | ara 阿拉伯语
29 | ru 俄语
30 | pt 葡萄牙语
31 | de 德语
32 | it 意大利语
33 | el 希腊语
34 | nl 荷兰语
35 | pl 波兰语
36 | bul 保加利亚语
37 | est 爱沙尼亚语
38 | dan 丹麦语
39 | fin 芬兰语
40 | cs 捷克语
41 | rom 罗马尼亚语
42 | slo 斯洛文尼亚语
43 | swe 瑞典语
44 | hu 匈牙利语
45 | cht 繁体中文
46 | vie 越南语
47 | ]]
48 |
49 | -- 签名
50 | local function sign(app_id, app_key, salt, opt)
51 | local sig = md5(concat({app_id, opt.q, salt, app_key}), true)
52 | local args = {{"appid", app_id}, {"salt", salt}, {"sign", sig}}
53 | for key, value in pairs(opt) do
54 | args[#args+1] = {key, value}
55 | end
56 | return args
57 | end
58 |
59 | -- 翻译接口
60 | function baidu.translate(app_id, app_key, opt)
61 | assert(type(app_id) == 'string' and app_id ~= '', "invalid baidu translate app_id.")
62 | assert(type(app_key) == 'string' and app_key ~= '', "invalid baidu translate app_key.")
63 | assert(type(opt) == 'table' and type(opt.q) == 'string' and opt.q ~= '' , "invalid baidu translate opt.")
64 | return httpc.post(baidu.host, nil, sign(app_id, app_key, random(1, time()), {
65 | q = opt.q, -- 必填(其它选填)
66 | to = opt.to or "en",
67 | from = opt.from or "auto",
68 | tts = opt.tts and 0 or 1,
69 | dict = opt.dict and 0 or 1,
70 | }))
71 | end
72 |
73 | return baidu
--------------------------------------------------------------------------------
/luaclib/src/lpeg/lpcap.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lpcap.h $
3 | */
4 |
5 | #if !defined(lpcap_h)
6 | #define lpcap_h
7 |
8 |
9 | #include "lptypes.h"
10 |
11 |
12 | /* kinds of captures */
13 | typedef enum CapKind {
14 | Cclose, /* not used in trees */
15 | Cposition,
16 | Cconst, /* ktable[key] is Lua constant */
17 | Cbackref, /* ktable[key] is "name" of group to get capture */
18 | Carg, /* 'key' is arg's number */
19 | Csimple, /* next node is pattern */
20 | Ctable, /* next node is pattern */
21 | Cfunction, /* ktable[key] is function; next node is pattern */
22 | Cquery, /* ktable[key] is table; next node is pattern */
23 | Cstring, /* ktable[key] is string; next node is pattern */
24 | Cnum, /* numbered capture; 'key' is number of value to return */
25 | Csubst, /* substitution capture; next node is pattern */
26 | Cfold, /* ktable[key] is function; next node is pattern */
27 | Cruntime, /* not used in trees (is uses another type for tree) */
28 | Cgroup /* ktable[key] is group's "name" */
29 | } CapKind;
30 |
31 |
32 | typedef struct Capture {
33 | const char *s; /* subject position */
34 | unsigned short idx; /* extra info (group name, arg index, etc.) */
35 | byte kind; /* kind of capture */
36 | byte siz; /* size of full capture + 1 (0 = not a full capture) */
37 | } Capture;
38 |
39 |
40 | typedef struct CapState {
41 | Capture *cap; /* current capture */
42 | Capture *ocap; /* (original) capture list */
43 | lua_State *L;
44 | int ptop; /* index of last argument to 'match' */
45 | const char *s; /* original string */
46 | int valuecached; /* value stored in cache slot */
47 | int reclevel; /* recursion level */
48 | } CapState;
49 |
50 |
51 | int runtimecap (CapState *cs, Capture *close, const char *s, int *rem);
52 | int getcaptures (lua_State *L, const char *s, const char *r, int ptop);
53 | int finddyncap (Capture *cap, Capture *last);
54 |
55 | #endif
56 |
57 |
58 |
--------------------------------------------------------------------------------
/luaclib/src/ltimer.c:
--------------------------------------------------------------------------------
1 | #define LUA_LIB
2 |
3 | #include
4 |
5 | /* === 定时器 === */
6 | static void TIMEOUT_CB(CORE_P_ core_timer *timer, int revents){
7 | if (revents & EV_TIMER){
8 | lua_State *co = (lua_State *) core_get_watcher_userdata(timer);
9 | int status = CO_RESUME(co, NULL, lua_gettop(co) > 0 ? lua_gettop(co) - 1 : 0);
10 | if (status != LUA_OK && status != LUA_YIELD){
11 | LOG( "ERROR", lua_tostring(co, -1));
12 | core_timer_stop(CORE_LOOP_ timer);
13 | }
14 | }
15 | }
16 |
17 | static int timer_stop(lua_State *L){
18 | core_timer *timer = (core_timer *) luaL_testudata(L, 1, "__TIMER__");
19 | if(!timer)
20 | return 0;
21 | core_timer_stop(CORE_LOOP_ timer);
22 | return 0;
23 | }
24 |
25 | static int timer_start(lua_State *L){
26 | core_timer *timer = (core_timer *) luaL_testudata(L, 1, "__TIMER__");
27 | if(!timer)
28 | return 0;
29 | lua_Number timeout = luaL_checknumber(L, 2);
30 | if (timeout <= 0 )
31 | return 0;
32 | lua_State *co = lua_tothread(L, 3);
33 | if(!co)
34 | return 0;
35 | core_set_watcher_userdata(timer, (void*)co);
36 | core_timer_start(CORE_LOOP, timer, timeout);
37 | return 0;
38 | }
39 |
40 | static int timer_new(lua_State *L){
41 | core_timer *timer = (core_timer *) lua_newuserdata(L, sizeof(core_timer));
42 | if(!timer)
43 | return 0;
44 | core_timer_init(timer, TIMEOUT_CB);
45 | luaL_setmetatable(L, "__TIMER__");
46 | return 1;
47 | }
48 |
49 | LUAMOD_API int luaopen_timer(lua_State *L){
50 | luaL_checkversion(L);
51 | luaL_newmetatable(L, "__TIMER__");
52 | lua_pushstring (L, "__index");
53 | lua_pushvalue(L, -2);
54 | lua_rawset(L, -3);
55 | lua_pushliteral(L, "__mode");
56 | lua_pushliteral(L, "kv");
57 | lua_rawset(L, -3);
58 | luaL_Reg timer_libs[] = {
59 | {"new", timer_new},
60 | {"stop", timer_stop},
61 | {"start", timer_start},
62 | {NULL, NULL},
63 | };
64 | luaL_setfuncs(L, timer_libs, 0);
65 | luaL_newlib(L, timer_libs);
66 | return 1;
67 | }
68 |
--------------------------------------------------------------------------------
/static/lib/layui/lay/modules/flow.js:
--------------------------------------------------------------------------------
1 | /** layui-v2.5.4 MIT License By https://www.layui.com */
2 | ;layui.define("jquery",function(e){"use strict";var l=layui.$,o=function(e){},t=' ';o.prototype.load=function(e){var o,i,n,r,a=this,c=0;e=e||{};var f=l(e.elem);if(f[0]){var m=l(e.scrollElem||document),u=e.mb||50,s=!("isAuto"in e)||e.isAuto,v=e.end||"没有更多了",y=e.scrollElem&&e.scrollElem!==document,d="加载更多 ",h=l('");f.find(".layui-flow-more")[0]||f.append(h);var p=function(e,t){e=l(e),h.before(e),t=0==t||null,t?h.html(v):h.find("a").html(d),i=t,o=null,n&&n()},g=function(){o=!0,h.find("a").html(t),"function"==typeof e.done&&e.done(++c,p)};if(g(),h.find("a").on("click",function(){l(this);i||o||g()}),e.isLazyimg)var n=a.lazyimg({elem:e.elem+" img",scrollElem:e.scrollElem});return s?(m.on("scroll",function(){var e=l(this),t=e.scrollTop();r&&clearTimeout(r),i||(r=setTimeout(function(){var i=y?e.height():l(window).height(),n=y?e.prop("scrollHeight"):document.documentElement.scrollHeight;n-t-i<=u&&(o||g())},100))}),a):a}},o.prototype.lazyimg=function(e){var o,t=this,i=0;e=e||{};var n=l(e.scrollElem||document),r=e.elem||"img",a=e.scrollElem&&e.scrollElem!==document,c=function(e,l){var o=n.scrollTop(),r=o+l,c=a?function(){return e.offset().top-n.offset().top+o}():e.offset().top;if(c>=o&&c<=r&&!e.attr("src")){var m=e.attr("lay-src");layui.img(m,function(){var l=t.lazyimg.elem.eq(i);e.attr("src",m).removeAttr("lay-src"),l[0]&&f(l),i++})}},f=function(e,o){var f=a?(o||n).height():l(window).height(),m=n.scrollTop(),u=m+f;if(t.lazyimg.elem=l(r),e)c(e,f);else for(var s=0;su)break}};if(f(),!o){var m;n.on("scroll",function(){var e=l(this);m&&clearTimeout(m),m=setTimeout(function(){f(null,e)},50)}),o=!0}return f},e("flow",new o)});
--------------------------------------------------------------------------------
/lualib/process/master.lua:
--------------------------------------------------------------------------------
1 | local event = require "process.event"
2 |
3 | local dataset = require "process.dataset"
4 |
5 | local channel = require "process.channel"
6 | local channel_send = channel.send
7 |
8 | local lpack = require "pack"
9 | local lpack_encode = lpack.encode
10 |
11 | local session = require "process.session"
12 | local session_get_pid = session.get_pid
13 |
14 | local type = type
15 | local pairs = pairs
16 | local assert = assert
17 |
18 | local mchan, channels
19 |
20 | local process = { isMaster = true, pid = dataset.get('pid') }
21 |
22 | ---comment 由框架完成进程初始化.
23 | function process.init(pid_list)
24 | -- 注册进程状态回调
25 | event.init(pid_list)
26 | -- 构建进程通信通道
27 | mchan = channel:new()
28 | channels = mchan:connect('master')
29 | -- 禁止二次修改
30 | process.init = nil
31 | end
32 |
33 | ---comment 向所有`Worker`进程广播消息
34 | function process.broadcast(...)
35 | local data = lpack_encode(nil, ...)
36 | for _, chan in pairs(channels) do
37 | channel_send(chan, data)
38 | end
39 | end
40 |
41 | ---comment 向指定`PID`的子进程发送消息
42 | ---@param pid integer @子进程`PID`
43 | function process.send(pid, ...)
44 | channel_send(assert(channels[pid], "Invalid `PID` session."), lpack_encode(nil, ...))
45 | end
46 |
47 | ---comment 响应消息
48 | ---@param sessionid integer @响应`sessionid`的消息
49 | function process.ret(sessionid, ...)
50 | channel_send(channels[session_get_pid(assert(sessionid, "Invalid `sessionid`"))], lpack_encode(sessionid, ...))
51 | end
52 |
53 | ---comment 注册进程事件
54 | ---@param msg_type string @事件类型: `message`, `exit`
55 | ---@param func function @回调函数: function(sessionid, ...)
56 | function process.on(msg_type, func)
57 | -- 注册退出事件
58 | if msg_type == 'exit' and type(func) == 'function' then
59 | event.setcb(func)
60 | return
61 | end
62 | -- 注册消息事件
63 | if msg_type == 'message' and type(func) == 'function' then
64 | for _, chan in pairs(channels) do
65 | chan:setcb(func)
66 | end
67 | return
68 | end
69 | end
70 |
71 | return process
--------------------------------------------------------------------------------
/docker/docker-compose-with-nginx.yaml:
--------------------------------------------------------------------------------
1 | # docker-compose.yaml
2 | version: "2"
3 | services:
4 | WebProxy:
5 | image: nginx:latest
6 | restart: always
7 | ports:
8 | - 80:80
9 | volumes:
10 | - ./conf.d/nginx.conf:/etc/nginx/nginx.conf
11 | links:
12 | - WebApp1:webapp1
13 | - WebApp2:webapp2
14 | - WebApp3:webapp3
15 | networks:
16 | - local
17 |
18 | WebApp1:
19 | image: candymi/cfweb
20 | restart: always
21 | volumes:
22 | - ./script/:/app/script/
23 | # 如需设置时区, 建议请将localtime提取到home目录下再挂在使用
24 | # - /etc/localtime:/etc/localtime
25 | depends_on:
26 | - WebDB
27 | links:
28 | - WebDB:WebDB
29 | networks:
30 | - local
31 |
32 |
33 | WebApp2:
34 | image: candymi/cfweb
35 | restart: always
36 | volumes:
37 | - ./script/:/app/script/
38 | # 如需设置时区, 建议请将localtime提取到home目录下再挂在使用
39 | # - /etc/localtime:/etc/localtime
40 | depends_on:
41 | - WebDB
42 | links:
43 | - WebDB:WebDB
44 | networks:
45 | - local
46 |
47 | WebApp3:
48 | image: candymi/cfweb
49 | restart: always
50 | volumes:
51 | - ./script/:/app/script/
52 | # 如需设置时区, 建议请将localtime提取到home目录下再挂在使用
53 | # - /etc/localtime:/etc/localtime
54 | depends_on:
55 | - WebDB
56 | links:
57 | - WebDB:WebDB
58 | networks:
59 | - local
60 |
61 | WebDB:
62 | image: mysql:5.6 #支持8.X以上版本, 但是必须开启下面的COMMAND参数.
63 | restart: always
64 | environment:
65 | - MYSQL_ROOT_PASSWORD=123456789
66 | - MYSQL_DATABASE=cfadmin
67 | # 8.x以上版本必须设置为mysql_native_password, 否则无法连接到MySQL
68 | # command: --default-authentication-plugin=mysql_native_password
69 | volumes:
70 | - ./db/:/docker-entrypoint-initdb.d/
71 | # 如需设置时区, 建议请将localtime提取到home目录下再挂在使用
72 | # - /etc/localtime:/etc/localtime
73 | ports:
74 | - 3306:3306
75 | networks:
76 | - local
77 |
78 | networks:
79 | local:
80 | driver: bridge
81 |
--------------------------------------------------------------------------------
/lualib/admin/db/token.lua:
--------------------------------------------------------------------------------
1 |
2 | local fmt = string.format
3 | local os_time = os.time
4 |
5 | local token = {}
6 |
7 | -- 写入Token
8 | function token.token_add (db, uid, name, token)
9 | return db:query(fmt(
10 | [[
11 | INSERT INTO
12 | `cfadmin_tokens`(`uid`, `name`, `token`, `create_at`)
13 | VALUES
14 | ('%s', '%s', '%s', '%s')
15 | ON DUPLICATE KEY UPDATE `token` = '%s', `name` = '%s', `create_at` = '%s'
16 | ]],
17 | uid, name, token, os_time(), token, name, os_time()))
18 | end
19 |
20 | -- 删除Token
21 | function token.token_delete (db, id, tk)
22 | return db:query(fmt([[DELETE FROM cfadmin_tokens WHERE uid = '%s' or token = '%s' LIMIT 1]], id, tk))
23 | end
24 |
25 | -- Token 是否存在
26 | function token.token_exists (db, token)
27 | local ret = db:query(fmt([[SELECT uid, name, token FROM cfadmin_tokens WHERE token = '%s']], token:gsub("['\\]", "")))
28 | if not ret or #ret == 0 then
29 | return
30 | end
31 | return ret[1]
32 | end
33 |
34 | -- 根据token查用户信息
35 | function token.token_to_userinfo (db, token)
36 | local tokens, err = db:query(fmt([[
37 | SELECT
38 | `cfadmin_users`.id,
39 | `cfadmin_users`.name,
40 | `cfadmin_users`.username,
41 | `cfadmin_users`.password,
42 | `cfadmin_tokens`.token,
43 | `cfadmin_users`.role,
44 | `cfadmin_users`.name AS role_name,
45 | `cfadmin_roles`.is_admin,
46 | `cfadmin_users`.email,
47 | `cfadmin_users`.phone,
48 | `cfadmin_users`.create_at,
49 | `cfadmin_users`.update_at
50 | FROM
51 | cfadmin_users, cfadmin_tokens, cfadmin_roles
52 | WHERE
53 | `cfadmin_tokens`.uid = `cfadmin_users`.id AND
54 | `cfadmin_roles`.id = `cfadmin_users`.role AND
55 | `cfadmin_tokens`.token = '%s'
56 | LIMIT 1]], token:gsub("['\\]", "")))
57 | if type(tokens) ~= 'table'then
58 | return nil, err
59 | end
60 | return tokens[1]
61 | end
62 |
63 | -- 删除其他用户token信息
64 | function token.flush_all(db, uid)
65 | return db:query(fmt([[DELETE FROM cfadmin_tokens WHERE uid != %u]], uid))
66 | end
67 |
68 | return token
69 |
--------------------------------------------------------------------------------
/lualib/csv.lua:
--------------------------------------------------------------------------------
1 | local concat = table.concat
2 | local type = type
3 |
4 | local csv = {}
5 |
6 | -- 读取并且解析CSV文件, 格式如下:
7 | --[[
8 | [1] = [Name1, Name2, Nam3, ..., NameN]
9 | [2] = [Value1, Value2, Value3, ..., ValueN]
10 | .
11 | ..
12 | ...
13 | [N] = [Value1, Value2, Value3, ..., ValueN]
14 | ]]
15 | -- 规则1: 第一行为所有字段的名称, 第二行开始到第N行是内容;
16 | -- 规则2: 每行不允许出现空格与逗号引号等特殊字符, 空格字符将会被删除掉;
17 | -- 规则3: 打开csv文件失败将返回nil与一个err错误信息.
18 | function csv.loadfile (path)
19 | if type(path) ~= 'string' or path == '' then
20 | return nil, "invalid args."
21 | end
22 | local file, err = io.open(path, "r")
23 | if not file then
24 | return nil, err
25 | end
26 | local tab = {}
27 | for line in file:lines() do
28 | local items = {}
29 | for item in line:gmatch("([^,\r\n]+)") do
30 | if item and item ~= '' then
31 | items[#items + 1] = item:gsub("[ \"']", "")
32 | end
33 | end
34 | if #items > 0 then
35 | tab[#tab + 1] = items
36 | end
37 | end
38 | file:close()
39 | return tab
40 | end
41 |
42 | -- 规则同上
43 | function csv.writefile (path, t)
44 | if type(path) ~= 'string' or path == '' or type(t) ~= 'table' or #t < 1 then
45 | return nil, "invalid args."
46 | end
47 | local file, err = io.open(path, "w")
48 | if not file then
49 | return nil, err
50 | end
51 | file:setvbuf("full", 1 << 20)
52 | for index = 1, #t do
53 | local contents = t[index]
54 | if type(contents) == 'table' then
55 | file:write(concat(contents, ',') .. '\n')
56 | end
57 | end
58 | file:flush()
59 | file:close()
60 | return true
61 | end
62 |
63 | function csv.loadstring (str)
64 | if type(str) ~= 'string' or str == '' then
65 | return nil, "invalid args."
66 | end
67 | local tab = {}
68 | local index = 1
69 | for line in str:gmatch("([^\r\n]-)\r\n") do
70 | local items = {}
71 | for s in line:gmatch("([^, \r\n]+)") do
72 | items[#items+1] = s
73 | end
74 | tab[#tab+1] = items
75 | end
76 | return tab
77 | end
78 |
79 | return csv
80 |
--------------------------------------------------------------------------------
/luaclib/src/lcrypt/uuid.c:
--------------------------------------------------------------------------------
1 | #include "lcrypt.h"
2 |
3 | #define UUID_V4_LENGTH 36
4 | #define GUID_V1_LENGTH 35
5 |
6 | static inline const char* uuid_v4_gen(char *buffer) {
7 | union {
8 | struct {
9 | uint32_t time_low;
10 | uint16_t time_mid;
11 | uint16_t time_hi_and_version;
12 | uint8_t clk_seq_hi_res;
13 | uint8_t clk_seq_low;
14 | uint8_t node[6];
15 | };
16 | uint8_t __rnd[16];
17 | } uuid;
18 |
19 | RAND_bytes(uuid.__rnd, sizeof(uuid));
20 |
21 | uuid.clk_seq_hi_res = (uint8_t) ((uuid.clk_seq_hi_res & 0x3F) | 0x80);
22 | uuid.time_hi_and_version = (uint16_t) ((uuid.time_hi_and_version & 0x0FFF) | 0x4000);
23 |
24 | snprintf(buffer, UUID_V4_LENGTH + 1, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
25 | uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
26 | uuid.clk_seq_hi_res, uuid.clk_seq_low,
27 | uuid.node[0], uuid.node[1], uuid.node[2],
28 | uuid.node[3], uuid.node[4], uuid.node[5]
29 | );
30 |
31 | buffer[UUID_V4_LENGTH] = '\0';
32 | return (const char*) buffer;
33 | }
34 |
35 | static inline const char* guid_v1_gen(const uint8_t *hash, char *buffer, uint32_t hi, uint32_t low) {
36 |
37 | uint8_t rand_bytes[2]; RAND_bytes(rand_bytes, 2);
38 |
39 | snprintf(buffer, GUID_V1_LENGTH + 1, "%02x%02x%02x%02x%02x%02x%02x%02x-%08x-%04x-%02x%02x",
40 | hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7],
41 | hi, low, rand_bytes[0], rand_bytes[1]
42 | );
43 |
44 | buffer[GUID_V1_LENGTH] = '\0';
45 | return (const char*) buffer;
46 | }
47 |
48 | int luuid(lua_State *L) {
49 | lua_pushlstring(L, (const char *)uuid_v4_gen(lua_newuserdata(L, UUID_V4_LENGTH + 1)), UUID_V4_LENGTH);
50 | return 1;
51 | }
52 |
53 | int lguid(lua_State *L) {
54 | if (1 != lhashkey(L))
55 | return luaL_error(L, "Invalid hashkey.");
56 | lua_pushlstring(L, (const char *)guid_v1_gen((const uint8_t *)lua_tostring(L, 4), lua_newuserdata(L, GUID_V1_LENGTH + 1), lua_tointeger(L, 2), lua_tointeger(L, 3)), GUID_V1_LENGTH);
57 | return 1;
58 | }
--------------------------------------------------------------------------------
/luaclib/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY : build rebuild clean
2 |
3 | default :
4 | @echo "======================================="
5 | @echo "Please use 'make build' command to build it.."
6 | @echo "Please use 'make rebuild' command to build it.."
7 | @echo "Please use 'make clean' command to clean all."
8 | @echo "======================================="
9 |
10 | INCLUDES += -I../src -I/usr/local/include
11 | LIBS += -L./ -L../ -L/usr/local/lib
12 | # CFLAGS = -Wall -O3 -fPIC --shared -DJEMALLOC -ljemalloc -Wl,-rpath,. -Wl,-rpath,.. -Wl,-rpath,/usr/local/lib
13 | # CFLAGS = -Wall -O3 -fPIC --shared -DTCMALLOC -ltcmalloc -Wl,-rpath,. -Wl,-rpath,.. -Wl,-rpath,/usr/local/lib
14 | CFLAGS = -Wall -O3 -fPIC --shared -Wno-unused-function -Wl,-rpath,. -Wl,-rpath,.. -Wl,-rpath,/usr/local/lib
15 |
16 | internal :
17 | @echo "CC - lsys"
18 | @$(CC) -o sys.so src/lsys.c $(CFLAGS) $(INCLUDES) $(LIBS) -lcore
19 | @echo "CC - lpack"
20 | @$(CC) -o pack.so src/lpack.c $(CFLAGS) $(INCLUDES) $(LIBS) -lcore
21 | @echo "CC - lchild"
22 | @$(CC) -o child.so src/lchild.c $(CFLAGS) $(INCLUDES) $(LIBS) -lcore
23 | @echo "CC - ludp"
24 | @$(CC) -o udp.so src/ludp.c $(CFLAGS) $(INCLUDES) $(LIBS) -lcore
25 | @echo "CC - ltask"
26 | @$(CC) -o task.so src/ltask.c $(CFLAGS) $(INCLUDES) $(LIBS) -lcore
27 | @echo "CC - ltimer"
28 | @$(CC) -o timer.so src/ltimer.c $(CFLAGS) $(INCLUDES) $(LIBS) -lcore
29 | @echo "CC - laio"
30 | @$(CC) -o laio.so src/laio.c $(CFLAGS) $(INCLUDES) $(LIBS) -lcore -leio -lpthread
31 | @echo "CC - ltcp"
32 | @$(CC) -o tcp.so src/ltcp.c $(CFLAGS) $(INCLUDES) $(LIBS) -lcore -lssl -lcrypto
33 |
34 | 3part :
35 | @echo "CC - lz"
36 | @$(MAKE) -C src/lz build
37 | @echo "CC - lfs"
38 | @$(MAKE) -C src/lfs build
39 | @echo "CC - lpbc"
40 | @$(MAKE) -C src/lpbc build
41 | @echo "CC - lpeg"
42 | @$(MAKE) -C src/lpeg build
43 | @echo "CC - lcrypt"
44 | @$(MAKE) -C src/lcrypt build
45 | @echo "CC - lcjson"
46 | @$(MAKE) -C src/lcjson build
47 | @echo "CC - lmsgpack"
48 | @$(MAKE) -C src/lmsgpack build
49 | @echo "CC - lhttpparser"
50 | @$(MAKE) -C src/lhttpparser build
51 |
--------------------------------------------------------------------------------
/script/test_zlib.lua:
--------------------------------------------------------------------------------
1 | local z = require "lz"
2 |
3 | local LOG = require "logging"
4 |
5 | local text = [[
6 |
7 | Lua 轻量级网络开发框架(A lua Lightweight Network Development Framework)
8 |
9 | 生态多 —— 集成社区库最多的框架之一, 并自行实现了一些网络协议生态.
10 |
11 | Multi-ecology —— Integrate most community third-party libraries and implement many protocols on their own.
12 |
13 | 稳定性好 —— 许多领域的企业已经开始使用,并且用户数量也在逐渐增加.
14 |
15 | Good stability —— Enterprises in many fields have begun to use, and users are gradually increasing.
16 |
17 | 高效率 —— 高效的静态语言与高效的虚拟机实现优秀的运行时框架.
18 |
19 | High efficiency - Efficient static language and efficient virtual machine to achieve excellent runtime framework.
20 |
21 | 高可维护性 —— 通俗易懂的框架编写方式可以让开发者快速适应并且上手.
22 |
23 | High readability —— The easy-to-understand framework writing method allows developers to quickly adapt and get started.
24 |
25 | 《运行》
26 |
27 | cf框架在整体构建完毕后会在项目根目录产生一个可执行文件: cfadmin, 它会根据当前目录环境执行对应的入口文件(script/main.lua).
28 |
29 | 《命令与参数》
30 |
31 | ./cfadmin, 前台执行; 使用ctrl + z、ctrl + c、ctrl + \等组合键就能让它停止执行.
32 |
33 | ./cfadmin -d, 后台执行; 通常你需要使用killall cfadmin与kill -9 PID这样的命令才能终止它.
34 |
35 | 《选择合适的运行方式》
36 |
37 | cf默认情况下会将日志输出在stdout. 在开发与测试期间通常会前台运行, 这样无论是打印日志还是定位问题都会变得较为简单.
38 |
39 | 如果您将cf放置在容器内部, 前台运行通常会是一个比较好的选择. 有利于贴合容器日志生态, 合理配合日志收集器做集中式日志检索与管理.
40 |
41 | 如果您将cf放置到原生系统下, 建议将cf至于后台运行.
42 |
43 | ]]
44 |
45 | local cp_text = z.compress(text)
46 |
47 | local raw_text = z.uncompress(cp_text)
48 |
49 | assert(raw_text == text, "测试LZ77压缩/解压方法失败")
50 |
51 | LOG:DEBUG("compress压缩前的文本长度为:" .. #raw_text, "压缩后的文本长度为:" .. #cp_text)
52 |
53 | -- 分割线 ---
54 |
55 | local cp_text = z.compress2(text)
56 |
57 | local raw_text = z.uncompress2(cp_text)
58 |
59 | assert(raw_text == text, "测试gzip压缩/解压失败")
60 |
61 | LOG:DEBUG("compress2压缩前的文本长度为:" .. #raw_text, "压缩后的文本长度为:" .. #cp_text)
62 |
63 | -- 分割线 ---
64 |
65 | local cp_text = z.gzcompress(text)
66 |
67 | local raw_text = z.gzuncompress(cp_text)
68 |
69 | assert(raw_text == text, "测试gzip压缩/解压失败")
70 |
71 | LOG:DEBUG("gzcompress压缩前的文本长度为:" .. #raw_text, "压缩后的文本长度为:" .. #cp_text)
--------------------------------------------------------------------------------
/luaclib/src/ltask.c:
--------------------------------------------------------------------------------
1 | #define LUA_LIB
2 |
3 | #include
4 |
5 | static void TASK_CB(CORE_P_ core_task *task, int revents){
6 | lua_State *co = (lua_State *) core_get_watcher_userdata(task);
7 | if (co && (lua_status(co) == LUA_YIELD || lua_status(co) == LUA_OK)){
8 | int status = CO_RESUME(co, NULL, lua_status(co) == LUA_YIELD ? lua_gettop(co) : lua_gettop(co) - 1);
9 | if (status != LUA_YIELD && status != LUA_OK){
10 | LOG("ERROR", lua_tostring(co, -1));
11 | }
12 | core_task_stop(CORE_LOOP_ task);
13 | }
14 | }
15 |
16 | static int task_new(lua_State *L){
17 | core_task *task = lua_newuserdata(L, sizeof(core_task));
18 | if (!task)
19 | return 0;
20 | core_task_init(task, TASK_CB);
21 | luaL_setmetatable(L, "__Task__");
22 | return 1;
23 | }
24 |
25 | static int task_start(lua_State *L){
26 | core_task *task = (core_task *) luaL_testudata(L, 1, "__Task__");
27 | if (!task)
28 | return luaL_error(L, "attemp to pass a invaild core_task value.");
29 | lua_State *co = lua_tothread(L, 2);
30 | if (!co)
31 | return luaL_error(L, "attemp to pass a invaild lua_State value.");
32 | /* 这里假设栈大小永远够用, 因为调用与回调都不需要传入那么多参数 */
33 | lua_xmove(L, co, lua_gettop(L) - 2);
34 | core_set_watcher_userdata(task, co);
35 | core_task_start(CORE_LOOP_ task);
36 | return 1;
37 | }
38 |
39 | static int task_stop(lua_State *L){
40 | core_task *task = (core_task *) luaL_testudata(L, 1, "__Task__");
41 | if (!task)
42 | return luaL_error(L, "attemp to pass a invaild core_task value.");
43 | core_task_stop(CORE_LOOP_ task);
44 | return 0;
45 | }
46 |
47 |
48 | LUAMOD_API int luaopen_task(lua_State *L){
49 | luaL_checkversion(L);
50 | luaL_newmetatable(L, "__Task__");
51 | lua_pushstring (L, "__index");
52 | lua_pushvalue(L, -2);
53 | lua_rawset(L, -3);
54 | lua_pushliteral(L, "__mode");
55 | lua_pushliteral(L, "kv");
56 | lua_rawset(L, -3);
57 | luaL_Reg task_libs[] = {
58 | {"new", task_new},
59 | {"start", task_start},
60 | {"stop", task_stop},
61 | {NULL, NULL}
62 | };
63 | luaL_setfuncs(L, task_libs, 0);
64 | luaL_newlib(L, task_libs);
65 | return 1;
66 | }
67 |
--------------------------------------------------------------------------------
/lualib/cloud/location/amap.lua:
--------------------------------------------------------------------------------
1 | local httpc = require "httpc"
2 | local crypt = require "crypt"
3 | local md5 = crypt.md5
4 | local urlencode = crypt.urlencode
5 |
6 | local pairs = pairs
7 | local ipairs = ipairs
8 | local sort = table.sort
9 | local concat = table.concat
10 |
11 | --[[
12 |
13 | 官网: https://lbs.amap.com
14 |
15 | 文档: https://lbs.amap.com/api/webservice/summary
16 |
17 | ]]
18 |
19 | local amap = { __Version__ = 0.1, host = "https://restapi.amap.com" }
20 |
21 | -- sn签名
22 | local function sign(app_key, secret_key, opt)
23 | local keys = {"key"}
24 | for key, value in pairs(opt) do
25 | keys[#keys+1] = key
26 | end
27 | sort(keys)
28 | local args = {}
29 | for _, key in ipairs(keys) do
30 | if key == "key" then
31 | args[#args+1] = "key=" .. app_key
32 | else
33 | args[#args+1] = key .. '=' .. urlencode(opt[key])
34 | end
35 | end
36 | args[#args+1] = "sig=" .. md5(concat(args, "&"), true) .. secret_key
37 | return concat(args, "&")
38 | end
39 |
40 | -- IP定位
41 | function amap.ip(key, secret_key, ip)
42 | return httpc.get(amap.host .. "/v3/ip?" .. sign(key, secret_key, { ip = ip, output = "JSON"}))
43 | end
44 |
45 | -- 天气预报
46 | function amap.weather(key, secret_key, city, extensions)
47 | return httpc.get(amap.host .. "/v3/weather/weatherInfo?" .. sign(key, secret_key, { output = "JSON", city = city, extensions = extensions}))
48 | end
49 |
50 | -- 坐标转换
51 | function amap.convert(key, secret_key, locations, coordsys)
52 | return httpc.get(amap.host .. "/v3/assistant/coordinate/convert?" .. sign(key, secret_key, { output = "JSON", locations = locations, coordsys = coordsys }))
53 | end
54 |
55 | -- 地理编码
56 | function amap.geo(key, secret_key, opt)
57 | return httpc.get(amap.host .. "/v3/geocode/geo?" .. sign(key, secret_key, opt))
58 | end
59 |
60 | -- 行政区域查询
61 | function amap.district(key, secret_key, opt)
62 | return httpc.get(amap.host .. "/v3/config/district?" .. sign(key, secret_key, opt))
63 | end
64 |
65 | -- 输入提示
66 | function amap.tips(key, secret_key, opt)
67 | return httpc.get(amap.host .. "/v3/assistant/inputtips?" .. sign(key, secret_key, opt))
68 | end
69 |
70 |
71 | return amap
--------------------------------------------------------------------------------
/lualib/admin/html/dashboard/header.html:
--------------------------------------------------------------------------------
1 |
2 |
46 |
47 |
--------------------------------------------------------------------------------
/luaclib/src/lcrypt/url.c:
--------------------------------------------------------------------------------
1 | #include "lcrypt.h"
2 |
3 | #define hex_char(ch) ({(uint8_t)((ch) > 9 ? (ch) + 55: (ch) + 48);})
4 |
5 | #define is_normal_char(ch) ({((ch) >= 'a' && (ch) <= 'z') || ((ch) >= 'A' && (ch) <= 'Z') || ((ch) >= '0' && (ch) <= '9') ? 1 : 0;})
6 |
7 | /* url编码 */
8 | int lurlencode(lua_State *L){
9 | size_t url_len = 0;
10 | const char* url = luaL_checklstring(L, 1, &url_len);
11 | if (!url)
12 | return luaL_error(L, "Invalid url text");
13 |
14 | luaL_Buffer convert_url;
15 | luaL_buffinit(L, &convert_url);
16 |
17 | int index;
18 | for (index = 0; index < url_len;) {
19 | uint8_t ch = (uint8_t)url[index++];
20 | if (ch == (uint8_t)' ') {
21 | luaL_addlstring(&convert_url, "%20", 3);
22 | continue;
23 | }
24 | if (is_normal_char(ch) || strchr("-_.!~*'()", ch)) {
25 | luaL_addchar(&convert_url, ch);
26 | continue;
27 | }
28 | char vert[] = {'%', hex_char(((uint8_t)ch) >> 4), hex_char(((uint8_t)ch) & 0xF)};
29 | luaL_addlstring(&convert_url, (const char *)vert, 3);
30 | }
31 |
32 | luaL_pushresult(&convert_url);
33 | return 1;
34 | }
35 |
36 | /* url解码 */
37 | int lurldecode(lua_State *L){
38 | size_t url_len = 0;
39 | const char* url = luaL_checklstring(L, 1, &url_len);
40 | if (!url)
41 | return luaL_error(L, "Invalid url text");
42 |
43 | luaL_Buffer convert_url;
44 | luaL_buffinit(L, &convert_url);
45 |
46 | int index;
47 | for (index = 0; index < url_len;) {
48 |
49 | uint8_t ch = (uint8_t)url[index++];
50 | if (ch != (uint8_t)'%') {
51 | luaL_addchar(&convert_url, ch == (uint8_t)'+' ? (uint8_t)' ' : ch);
52 | continue;
53 | }
54 |
55 | char vert[2];
56 | if (index++ == url_len) {
57 | luaL_addchar(&convert_url, '%');
58 | break;
59 | }
60 | vert[0] = url[index - 1];
61 |
62 | if (index++ == url_len) {
63 | luaL_addlstring(&convert_url, url + url_len - 2, 2);
64 | break;
65 | }
66 | vert[1] = url[index - 1];
67 | luaL_addchar(&convert_url, (uint8_t)((vert[0] - 48 - ((vert[0] >= 'A') ? 7 : 0) - ((vert[0] >= 'a') ? 32 : 0)) * 16 + (vert[1] - 48 - ((vert[1] >= 'A') ? 7 : 0) - ((vert[1] >= 'a') ? 32 : 0))));
68 | }
69 |
70 | luaL_pushresult(&convert_url);
71 | return 1;
72 | }
73 |
--------------------------------------------------------------------------------
/src/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY : build rebuild clean
2 |
3 | default :
4 | @echo "======================================="
5 | @echo "Please use 'make clean' command to clean it.."
6 | @echo "Please use 'make build' command to build it.."
7 | @echo "Please use 'make rebuild' command DEBUG it.."
8 | @echo "======================================="
9 |
10 | CC = cc
11 |
12 | LIBS += -L. -L../ -L/usr/local/lib
13 | INCLUDES += -I. -I../ -I/usr/local/include
14 |
15 | # 使用jemalloc内存分配器请启用这段
16 | # CFLAGS += -Wall -O3 -fPIC --shared -DJEMALLOC -fno-strict-aliasing -Wl,-rpath,. -Wl,-rpath,.. -Wl,-rpath,/usr/local/lib
17 | # MACRO += -O3 -Wl,-rpath,. -Wl,-rpath,.. -Wl,-rpath,/usr/local/lib/ -DJEMALLOC
18 | # DLL += -ljemalloc -lev -llua -ldl -lm
19 |
20 | # 使用tcmalloc内存分配器请启用这段
21 | # CFLAGS += -Wall -O3 -fPIC --shared -DTCMALLOC -fno-strict-aliasing -Wl,-rpath,. -Wl,-rpath,.. -Wl,-rpath,/usr/local/lib
22 | # MACRO += -O3 -Wl,-rpath,. -Wl,-rpath,.. -Wl,-rpath,/usr/local/lib -DTCMALLOC
23 | # DLL += -ltcmalloc -lev -llua -ldl -lm
24 |
25 | # 默认情况下使用系统内存分配器
26 | CFLAGS += -Wall -O3 -fPIC --shared -fno-strict-aliasing -Wl,-rpath,. -Wl,-rpath,.. -Wl,-rpath,/usr/local/lib
27 | MACRO += -O3 -Wl,-rpath,. -Wl,-rpath,.. -Wl,-rpath,/usr/local/lib
28 | DLL += -lev -llua -ldl -lm
29 |
30 | build :
31 | @echo "********** Core library and executable **********"
32 | @if [ "`uname -s`" = 'Linux' ] || [ "`uname -s`" = 'Android' ] || [ "`uname -s`" = 'Darwin' ] || \
33 | [ "`uname -s`" = 'FreeBSD' ] || [ "`uname -s`" = 'OpenBSD' ] || [ "`uname -s`" = 'NetBSD' ] || [ "`uname -s`" = 'DragonFlyBSD' ] \
34 | ; then \
35 | $$@echo "CC - libcore" ; \
36 | $$@cc -o libcore.so core.c core_ev.c core_memory.c core_sys.c $(CFLAGS) $(INCLUDES) $(LIBS) $(DLL) ; \
37 | $$@echo "CC - cfadmin" ; \
38 | $$@cc -o cfadmin core_start.c $(MACRO) $(INCLUDES) $(LIBS) -lcore ; \
39 | $$@mv *.so cfadmin ../ ; \
40 | else \
41 | $$@echo "CC - libcore" ; \
42 | $$@cc -o libcore.dll core.c core_ev.c core_memory.c core_sys.c $(CFLAGS) $(INCLUDES) $(LIBS) $(DLL) ; \
43 | $$@echo "CC - cfadmin" ; \
44 | $$@cc -o cfadmin.exe core_start.c $(MACRO) $(INCLUDES) $(LIBS) -lcore ; \
45 | $$@mv *.dll cfadmin.exe ../ ; \
46 | fi;
47 |
--------------------------------------------------------------------------------
/lualib/cloud/tencent/ai.lua:
--------------------------------------------------------------------------------
1 | local httpc = require "httpc"
2 | local crypt = require "crypt"
3 | local md5 = crypt.md5
4 | local urlencode = crypt.urlencode
5 |
6 | local modf = math.modf
7 | local now = require"sys".now
8 | local time = os.time
9 | local fmt = string.format
10 |
11 | local sort = table.sort
12 | local concat = table.concat
13 |
14 |
15 | local function sign(AppID, AppKey, opt)
16 | opt["app_id"] = AppID
17 | opt["time_stamp"] = time()
18 | opt['nonce_str'] = fmt("%x", modf(now() * 100))
19 | opt["sign"] = ""
20 | local keys = {}
21 | for k, v in pairs(opt) do
22 | keys[#keys+1] = k
23 | end
24 | sort(keys)
25 | local args = {}
26 | local sign_list = {}
27 | for _, key in ipairs(keys) do
28 | local k, v = key, opt[key]
29 | if v ~= '' then
30 | args[#args+1] = {k, v}
31 | sign_list[#sign_list+1] = k .. '=' .. urlencode(v)
32 | end
33 | end
34 | sign_list[#sign_list+1] = "app_key=" .. AppKey
35 | args[#args+1] = {"sign", md5(concat(sign_list, "&"), true):upper()}
36 | return args
37 | end
38 |
39 | local ai = { __Version__ = 0.1, host = "https://api.ai.qq.com"}
40 |
41 | -- 智能闲聊
42 | function ai.chat(AppID, AppKey, session, text)
43 | return httpc.post(ai.host .. "/fcgi-bin/nlp/nlp_textchat", nil, sign(AppID, AppKey, { session = session, question = text }))
44 | end
45 |
46 | -- 文本转换为语音
47 | function ai.text_to_voice(AppID, AppKey, opt)
48 | return httpc.post(ai.host .. "/fcgi-bin/aai/aai_tts", nil, sign(AppID, AppKey, opt))
49 | end
50 |
51 | -- 语种识别
52 | function ai.text_detect(AppID, AppKey, force, langs, text)
53 | return httpc.post(ai.host .. "/fcgi-bin/nlp/nlp_textdetect", nil, sign(AppID, AppKey, { force = force or 0, candidate_langs = langs or "zh|en|jp|kr", text = text }))
54 | end
55 |
56 | -- 文本翻译
57 | function ai.text_translate(AppID, AppKey, lang_code, text)
58 | return httpc.post(ai.host .. "/fcgi-bin/nlp/nlp_texttrans", nil, sign(AppID, AppKey, { type = lang_code, text = text }))
59 | end
60 |
61 | -- 语音翻译
62 | function ai.voice_translate(AppID, AppKey, lang_code, text)
63 | return httpc.post(ai.host .. "/fcgi-bin/nlp/nlp_texttrans", nil, sign(AppID, AppKey, { type = lang_code, text = text }))
64 | end
65 |
66 | return ai
--------------------------------------------------------------------------------
/lualib/cloud/paypal/payment.lua:
--------------------------------------------------------------------------------
1 | local httpc = require "httpc"
2 | local crypt = require "crypt"
3 | local json = require "json"
4 |
5 | --[[
6 | 1. 申请token
7 | 2. 创建订单
8 | 3. 用户确认支付 / 取消支付
9 | 4. 商家确认支付 / 取消支付
10 | 5. 交易完成 / 取消
11 | ]]
12 |
13 | local Payment = { __Version__ = 0.1 }
14 |
15 | local function basic_auth(username, password)
16 | return "Basic " .. crypt.base64encode(username .. ":" .. password)
17 | end
18 |
19 | local function Bearer_auth (accesstoken)
20 | return "Bearer " .. accesstoken
21 | end
22 |
23 | -- 申请AccessToken
24 | function Payment.getAccessToken (clientid, secret)
25 | return httpc.post("https://api.sandbox.paypal.com/v1/oauth2/token", {
26 | {"Accept", "application/json"}, {"Authorization", basic_auth(clientid, secret)}
27 | }, { {"grant_type", "client_credentials"} })
28 | end
29 |
30 | -- 创建账单
31 | function Payment.createPayment (accesstoken, opt)
32 | return httpc.json("https://api.sandbox.paypal.com/v1/payments/payment", { {"Authorization", Bearer_auth(accesstoken)} }, json.encode({
33 | intent = opt.intent, payer = opt.payer,
34 | transactions = opt.transactions,
35 | not_to_payer = opt.not_to_payer,
36 | redirect_urls = opt.redirect_urls,
37 | }))
38 | end
39 |
40 | -- 确认支付
41 | function Payment.confirmPayment (accesstoken, payment_id, payer_id)
42 | return httpc.json("https://api.sandbox.paypal.com/v1/payments/payment/".. payment_id .."/execute", { {"Authorization", Bearer_auth(accesstoken)} },
43 | json.encode({ payer_id = payer_id })
44 | )
45 | end
46 |
47 | -- 查询账单
48 | function Payment.getPaymentDetails (accesstoken, order_id)
49 | return httpc.get("https://api.sandbox.paypal.com/v1/payments/payment/" .. order_id, { {"Authorization", Bearer_auth(accesstoken)} })
50 | end
51 |
52 | -- 批量查询账单
53 | function Payment.getPaymentsDetails (accesstoken, opt)
54 | return httpc.get("https://api.sandbox.paypal.com/v1/payments/payment", { {"Authorization", Bearer_auth(accesstoken)} }, {
55 | {"count", opt.count or 10}, -- 分页数量
56 | {"start_index", opt.start_index or 1}, -- 第几页
57 | {"sort_by", opt.sort_by or "create_time"}, -- 排序字段,
58 | {"sort_order", opt.sort_order or "desc"}, -- 排序方式,
59 | })
60 | end
61 |
62 | return Payment
63 |
--------------------------------------------------------------------------------
/lualib/crypt/sha.lua:
--------------------------------------------------------------------------------
1 | local CRYPT = require "lcrypt"
2 | local md2 = CRYPT.md2
3 | local md4 = CRYPT.md4
4 | local md5 = CRYPT.md5
5 | local sha1 = CRYPT.sha1
6 | local sha224 = CRYPT.sha224
7 | local sha256 = CRYPT.sha256
8 | local sha384 = CRYPT.sha384
9 | local sha512 = CRYPT.sha512
10 | local ripemd160 = CRYPT.ripemd160
11 | local hexencode = CRYPT.hexencode
12 |
13 | local SHA = {}
14 |
15 | function SHA.md2(text, hex)
16 | local hash = md2(text)
17 | if hash and hex then
18 | return hexencode(hash)
19 | end
20 | return hash
21 | end
22 |
23 | function SHA.md4(text, hex)
24 | local hash = md4(text)
25 | if hash and hex then
26 | return hexencode(hash)
27 | end
28 | return hash
29 | end
30 |
31 | function SHA.md5(text, hex)
32 | local hash = md5(text)
33 | if hash and hex then
34 | return hexencode(hash)
35 | end
36 | return hash
37 | end
38 |
39 | function SHA.sha1(text, hex)
40 | local hash = sha1(text)
41 | if hash and hex then
42 | return hexencode(hash)
43 | end
44 | return hash
45 | end
46 |
47 | function SHA.sha128(text, hex)
48 | local hash = sha1(text)
49 | if hash and hex then
50 | return hexencode(hash)
51 | end
52 | return hash
53 | end
54 |
55 | function SHA.sha224(text, hex)
56 | local hash = sha224(text)
57 | if hash and hex then
58 | return hexencode(hash)
59 | end
60 | return hash
61 | end
62 |
63 | function SHA.sha256(text, hex)
64 | local hash = sha256(text)
65 | if hash and hex then
66 | return hexencode(hash)
67 | end
68 | return hash
69 | end
70 |
71 | function SHA.sha384(text, hex)
72 | local hash = sha384(text)
73 | if hash and hex then
74 | return hexencode(hash)
75 | end
76 | return hash
77 | end
78 |
79 | function SHA.sha512(text, hex)
80 | local hash = sha512(text)
81 | if hash and hex then
82 | return hexencode(hash)
83 | end
84 | return hash
85 | end
86 |
87 | function SHA.ripemd(text, hex)
88 | local hash = ripemd160(text)
89 | if hash and hex then
90 | return hexencode(hash)
91 | end
92 | return hash
93 | end
94 |
95 | -- 初始化函数
96 | return function (t)
97 | for k, v in pairs(SHA) do
98 | t[k] = v
99 | end
100 | return SHA
101 | end
--------------------------------------------------------------------------------
/lualib/httpd/Form.lua:
--------------------------------------------------------------------------------
1 | local url = require "url"
2 | local urlencode = url.encode
3 | local urldecode = url.decode
4 |
5 | local sys = require "sys"
6 | local new_tab = sys.new_tab
7 |
8 | local type = type
9 | local tonumber = tonumber
10 |
11 | local string = string
12 | local sub = string.sub
13 | local find = string.find
14 | local match = string.match
15 | local splite = string.gmatch
16 |
17 | local table = table
18 | local insert = table.insert
19 | -- require "utils"
20 |
21 | local form = {
22 | FILE = 0,
23 | ARGS = 1,
24 | }
25 |
26 | function form.get_args (path)
27 | if type(path) ~= 'string' or path == '' then
28 | return
29 | end
30 | local s, e = find(path, '?'), #path
31 | if not s or e - s < 3 then
32 | return
33 | end
34 | return form.urlencode(sub(path, s + 1, e))
35 | end
36 |
37 | -- 将body解析为x-www-form-urlencoded
38 | function form.urlencode(body)
39 | if type(body) ~= 'string' then
40 | return
41 | end
42 | local ARGS = {}
43 | for key, value in splite(body, "([^&]-)=([^&]+)") do
44 | local tname, keyname = match(urldecode(key), "(.+)%[(.+)%]$")
45 | if tname and keyname then
46 | local t = ARGS[tname]
47 | if not t then
48 | t = new_tab(8, 8)
49 | ARGS[tname] = t
50 | end
51 | t[tonumber(keyname) or keyname] = urldecode(value)
52 | else
53 | ARGS[urldecode(key)] = urldecode(value)
54 | end
55 | end
56 | return ARGS
57 | end
58 |
59 | -- 将body解析为multipart-form
60 | -- 目前支持2种格式:
61 | -- 1 : [ {filename = filename1, file = file1 }, {filename = filename2, file = file2 } ]
62 | -- 2 : [ [1] = {[1] = key1, [2] = value1}, [2] = {[1] = key2, [2] = value2} ]
63 | function form.multipart(body, BOUNDARY)
64 | if type(body) ~= 'string' or type(BOUNDARY) ~= 'string' then
65 | return
66 | end
67 | local FILES = {}
68 | for name, file in splite(body, 'filename="([^"]*)"\r\n[^\r\n]-\r\n\r\n(.-)\r\n[%-]-'..BOUNDARY) do
69 | if file and file ~= '' then
70 | insert(FILES, {filename = name, file = file})
71 | end
72 | end
73 | local ARGS = {}
74 | for key, value in splite(body, 'name="([^"]*)"\r\n\r\n([^%-]-)\r\n[%-]-'..BOUNDARY) do
75 | if (key and key ~= '' ) and (value and value ~= '') then
76 | insert(ARGS, {key, value})
77 | end
78 | end
79 | return FILES, ARGS
80 | end
81 |
82 |
83 | return form
84 |
--------------------------------------------------------------------------------
/luaclib/src/lpeg/lptree.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lptree.h $
3 | */
4 |
5 | #if !defined(lptree_h)
6 | #define lptree_h
7 |
8 |
9 | #include "lptypes.h"
10 |
11 |
12 | /*
13 | ** types of trees
14 | */
15 | typedef enum TTag {
16 | TChar = 0, /* 'n' = char */
17 | TSet, /* the set is stored in next CHARSETSIZE bytes */
18 | TAny,
19 | TTrue,
20 | TFalse,
21 | TRep, /* 'sib1'* */
22 | TSeq, /* 'sib1' 'sib2' */
23 | TChoice, /* 'sib1' / 'sib2' */
24 | TNot, /* !'sib1' */
25 | TAnd, /* &'sib1' */
26 | TCall, /* ktable[key] is rule's key; 'sib2' is rule being called */
27 | TOpenCall, /* ktable[key] is rule's key */
28 | TRule, /* ktable[key] is rule's key (but key == 0 for unused rules);
29 | 'sib1' is rule's pattern;
30 | 'sib2' is next rule; 'cap' is rule's sequential number */
31 | TGrammar, /* 'sib1' is initial (and first) rule */
32 | TBehind, /* 'sib1' is pattern, 'n' is how much to go back */
33 | TCapture, /* captures: 'cap' is kind of capture (enum 'CapKind');
34 | ktable[key] is Lua value associated with capture;
35 | 'sib1' is capture body */
36 | TRunTime /* run-time capture: 'key' is Lua function;
37 | 'sib1' is capture body */
38 | } TTag;
39 |
40 |
41 | /*
42 | ** Tree trees
43 | ** The first child of a tree (if there is one) is immediately after
44 | ** the tree. A reference to a second child (ps) is its position
45 | ** relative to the position of the tree itself.
46 | */
47 | typedef struct TTree {
48 | byte tag;
49 | byte cap; /* kind of capture (if it is a capture) */
50 | unsigned short key; /* key in ktable for Lua data (0 if no key) */
51 | union {
52 | int ps; /* occasional second child */
53 | int n; /* occasional counter */
54 | } u;
55 | } TTree;
56 |
57 |
58 | /*
59 | ** A complete pattern has its tree plus, if already compiled,
60 | ** its corresponding code
61 | */
62 | typedef struct Pattern {
63 | union Instruction *code;
64 | int codesize;
65 | TTree tree[1];
66 | } Pattern;
67 |
68 |
69 | /* number of children for each tree */
70 | extern const byte numsiblings[];
71 |
72 | /* access to children */
73 | #define sib1(t) ((t) + 1)
74 | #define sib2(t) ((t) + (t)->u.ps)
75 |
76 |
77 |
78 |
79 |
80 |
81 | #endif
82 |
83 |
--------------------------------------------------------------------------------
/lualib/admin/utils/init.lua:
--------------------------------------------------------------------------------
1 | local template = require "template"
2 | local config = require "admin.config"
3 |
4 | local type = type
5 | local assert = assert
6 | local ipairs = ipairs
7 |
8 | local split = string.sub
9 | local find = string.find
10 | local concat = table.concat
11 |
12 |
13 | local utils = {}
14 |
15 | -- 页面验证失败
16 | function utils.access_deny (path)
17 | return template.compile("lualib/admin/html/deny.html") {
18 | path = path or "unknown",
19 | cdn = config.cdn,
20 | }
21 | end
22 |
23 | -- 页面重定向
24 | function utils.redirect(path, args)
25 | assert(path ~= '' or type(path) ~= 'string' , '试图传递一个非法的path')
26 | assert(not args or type(args) == 'table' , '试图传递一个非法的args')
27 | local tab, arguments = { }, nil
28 | if args then
29 | for _, arg in ipairs(args) do
30 | tab[#tab+1] = concat(arg, '=')
31 | end
32 | end
33 | local arguments = concat(tab, '&')
34 | return template.compile('lualib/admin/html/redirect.html'){
35 | path = (path or config.github) .. arguments,
36 | }
37 | end
38 |
39 | -- 404错误页
40 | function utils.error_404(location)
41 | return template.compile('lualib/admin/html/404.html'){
42 | cdn = config.cdn,
43 | locale = config.locales[config.locale],
44 | location = location or config.github,
45 | }
46 | end
47 |
48 | -- 获取页面url
49 | function utils.get_path (content)
50 | return split(content['path'], 1, (find(content['path'], '?') or 0) - 1)
51 | end
52 |
53 | -- 获取语言
54 | function utils.get_locale (lang)
55 | local locale = config.locales[lang]
56 | if locale then
57 | return locale
58 | end
59 | return config.locales[config.locale]
60 | end
61 |
62 | -- 用户是否包含此权限
63 | function utils.user_have_permission (permissions, id)
64 | for _, permission in ipairs(permissions) do
65 | if permission.menu_id == id then
66 | return true
67 | end
68 | end
69 | return false
70 | end
71 |
72 | -- 角色权限组是否已经有此权限
73 | function utils.role_already_selected (permissions, id)
74 | for _, permission in ipairs(permissions) do
75 | if permission.menu_id == id then
76 | return true
77 | end
78 | end
79 | return false
80 | end
81 |
82 | -- 消除<标签>内容
83 | function utils.escape_script (str)
84 | if type(str) == 'string' then
85 | str = str:gsub('<[^><]*>', '')
86 | end
87 | return str
88 | end
89 |
90 | return utils
91 |
--------------------------------------------------------------------------------
/script/test_upload.lua:
--------------------------------------------------------------------------------
1 | local httpd = require "httpd"
2 | local json = require "json"
3 |
4 | local app = httpd:new("httpd")
5 |
6 | app:use("/upload", function(content)
7 | return [[
8 |
9 |
10 |
11 | 本地文件上传
12 |
13 |
14 |
21 |
22 |
23 | ]]
24 | end)
25 |
26 | app:api("/upload_local", function (content)
27 | if content.files then
28 | for _, item in ipairs(content.files) do
29 | local f, err = io.open("static/"..item.filename, "w+")
30 | if f then
31 | f:write(item.file)
32 | f:flush()
33 | f:close()
34 | else
35 | print("ERROR: " .. err)
36 | end
37 | end
38 | return json.encode { code = 200, status = "OK" }
39 | end
40 | return json.encode { code = 404, status = "没有上传内容." }
41 | end)
42 |
43 |
44 | app:use('/qiniu_upload', function(content)
45 | return [[
46 |
47 |
48 |
49 | 七牛文件上传
50 |
51 |
52 |
53 |
58 | 无token
59 |
60 |
66 |
67 | ]]
68 | end)
69 |
70 | local oss = require "cloud.qiniu.oss"
71 | app:api('/qiniu_token', function (content)
72 | local access_key = "your_access_key"
73 | local secret_key = "your_secret_key"
74 | return json.encode {
75 | code = 200,
76 | token = oss.getUploadToken(access_key, secret_key, {
77 | bucket = "candymi", -- 对应bucket名称(这个必填, 其它选填)
78 | }),
79 | }
80 | end)
81 |
82 | app:static("static")
83 |
84 | app:listen("0.0.0.0", 8080)
85 |
86 | app:run()
87 |
--------------------------------------------------------------------------------
/luaclib/src/lcrypt/lcrypt.h:
--------------------------------------------------------------------------------
1 | #define LUA_LIB
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #define SMALL_CHUNK 256
12 |
13 | int luuid(lua_State *L);
14 | int lguid(lua_State *L);
15 |
16 | int ltohex(lua_State *L);
17 | int lfromhex(lua_State *L);
18 |
19 | int lcrc32(lua_State *L);
20 | int lcrc64(lua_State *L);
21 |
22 | int ladler32(lua_State *L);
23 |
24 | int lb64encode(lua_State *L);
25 | int lb64decode(lua_State *L);
26 |
27 | int lurlencode(lua_State *L);
28 | int lurldecode(lua_State *L);
29 |
30 | int ldesencode(lua_State *L);
31 | int ldesdecode(lua_State *L);
32 |
33 | int ldes_encrypt(lua_State *L);
34 | int ldes_decrypt(lua_State *L);
35 |
36 | int ldhsecret(lua_State *L);
37 | int ldhexchange(lua_State *L);
38 |
39 | int lhashkey(lua_State *L);
40 | int lhmac_hash(lua_State *L);
41 |
42 | int lhmac64(lua_State *L);
43 | int lhmac64_md5(lua_State *L);
44 |
45 | int lmd4(lua_State *L);
46 | int lmd5(lua_State *L);
47 | int lsha128(lua_State *L);
48 | int lsha224(lua_State *L);
49 | int lsha256(lua_State *L);
50 | int lsha384(lua_State *L);
51 | int lsha512(lua_State *L);
52 | int lripemd160(lua_State *L);
53 |
54 | int lhmac_md4(lua_State *L);
55 | int lhmac_md5(lua_State *L);
56 | int lhmac_sha128(lua_State *L);
57 | int lhmac_sha224(lua_State *L);
58 | int lhmac_sha256(lua_State *L);
59 | int lhmac_sha384(lua_State *L);
60 | int lhmac_sha512(lua_State *L);
61 | int lhmac_ripemd160(lua_State *L);
62 | int lhmac_pbkdf2(lua_State *L);
63 |
64 | int lrc4(lua_State *L);
65 |
66 | int laes_enc(lua_State *L);
67 | int laes_dec(lua_State *L);
68 |
69 | int lrsa_public_key_encode(lua_State *L);
70 | int lrsa_private_key_decode(lua_State *L);
71 |
72 | int lrsa_private_key_encode(lua_State *L);
73 | int lrsa_public_key_decode(lua_State *L);
74 |
75 |
76 | int lrsa_sign(lua_State *L);
77 | int lrsa_verify(lua_State *L);
78 |
79 | int lsm3(lua_State *L);
80 | int lhmac_sm3(lua_State *L);
81 |
82 | int lsm2keygen(lua_State *L);
83 |
84 | int lsm2sign(lua_State *L);
85 | int lsm2verify(lua_State *L);
86 |
87 | int lsm4_cbc_encrypt(lua_State *L);
88 | int lsm4_cbc_decrypt(lua_State *L);
89 |
90 | int lsm4_ecb_encrypt(lua_State *L);
91 | int lsm4_ecb_decrypt(lua_State *L);
92 |
93 | int lsm4_ofb_encrypt(lua_State *L);
94 | int lsm4_ofb_decrypt(lua_State *L);
95 |
96 | int lsm4_ctr_encrypt(lua_State *L);
97 | int lsm4_ctr_decrypt(lua_State *L);
--------------------------------------------------------------------------------
/lualib/cloud/location/baidu.lua:
--------------------------------------------------------------------------------
1 | local httpc = require "httpc"
2 | local crypt = require "crypt"
3 | local md5 = crypt.md5
4 | local urlencode = crypt.urlencode
5 |
6 | local pairs = pairs
7 | local ipairs = ipairs
8 | local sort = table.sort
9 | local concat = table.concat
10 |
11 | --[[
12 | 官网: https://lbsyun.baidu.com
13 | 文档地址: https://lbsyun.baidu.com/index.php?title=webapi
14 | ]]
15 |
16 | local baidu = { __Version__ = 0.1, host = "https://api.map.baidu.com" }
17 |
18 | local function sign(query_str, ak, sk, opt)
19 | local keys = {}
20 | for key, _ in pairs(opt) do
21 | keys[#keys+1] = key
22 | end
23 | sort(keys)
24 | local args = {}
25 | for index, key in ipairs(keys) do
26 | args[#args+1] = key .. "=" .. urlencode(opt[key])
27 | end
28 | args[#args+1] = "ak=" .. ak
29 | args[#args+1] = "sn=" .. md5(urlencode(query_str .. concat(args, "&") ..sk), true)
30 | return concat(args, "&")
31 | end
32 |
33 | -- 智能硬件定位
34 | function baidu.locapi(ak, sk, opt)
35 | local path = "/locapi/v2?"
36 | return httpc.get(baidu.host .. path .. sign(path, ak, sk, opt))
37 | end
38 |
39 | -- 实时路况
40 | function baidu.road(ak, sk, opt)
41 | local path = "/traffic/v1/road?"
42 | return httpc.get(baidu.host .. path .. sign(path, ak, sk, opt))
43 | end
44 |
45 | -- 坐标附近上车点
46 | function baidu.parking(ak, sk, opt)
47 | local path = "/parking/search?"
48 | return httpc.get(baidu.host .. path .. sign(path, ak, sk, opt))
49 | end
50 |
51 | -- 坐标系转换
52 | function baidu.convert(ak, sk, opt)
53 | local path = "/geoconv/v1/?"
54 | return httpc.get(baidu.host .. path .. sign(path, ak, sk, opt))
55 | end
56 |
57 | -- 位置时区
58 | function baidu.timezone(ak, sk, opt)
59 | local path = "/timezone/v1?"
60 | return httpc.get(baidu.host .. path .. sign(path, ak, sk, opt))
61 | end
62 |
63 | -- 位置检索
64 | function baidu.geosearch(ak, sk, opt)
65 | local path = "/place/v2/search?"
66 | return httpc.get(baidu.host .. path .. sign(path, ak, sk, opt))
67 | end
68 |
69 | -- 位置IP
70 | function baidu.geoip(ak, sk, opt)
71 | local path = "/location/ip?"
72 | return httpc.get(baidu.host .. path .. sign(path, ak, sk, opt))
73 | end
74 |
75 | -- 坐标检索
76 | function baidu.geosuggestion(ak, sk, opt)
77 | local path = "/place/v2/suggestion?"
78 | return httpc.get(baidu.host .. path .. sign(path, ak, sk, opt))
79 | end
80 |
81 | -- 坐标编码
82 | function baidu.geo(ak, sk, opt)
83 | local path = "/geocoding/v3/?"
84 | return httpc.get(baidu.host .. path .. sign(path, ak, sk, opt))
85 | end
86 |
87 | return baidu
--------------------------------------------------------------------------------
/static/css/login.css:
--------------------------------------------------------------------------------
1 | /*
2 | * @Author: xuebingsi
3 | * @Date: 2019-04-01 13:37:17
4 | * @Last Modified by: zhibinm
5 | * @Last Modified time: 2019-04-01 13:37:19
6 | */
7 | .login-bg{
8 | /*background: #eeeeee url() 0 0 no-repeat;*/
9 | background:url(../images/bg.png) no-repeat center;
10 | background-size: cover;
11 | overflow: hidden;
12 | display: flex;
13 | align-items: center;
14 | justify-items: center;
15 | }
16 | .login{
17 | min-height: 420px;
18 | max-width: 420px;
19 | padding: 40px;
20 | background-color: #ffffff;
21 | border-radius: 4px;
22 | /* overflow-x: hidden; */
23 | box-sizing: border-box;
24 | }
25 | .login a.logo{
26 | display: block;
27 | height: 58px;
28 | width: 167px;
29 | margin: 0 auto 30px auto;
30 | background-size: 167px 42px;
31 | }
32 | .login .message {
33 | margin: 10px 0 0 -58px;
34 | padding: 18px 10px 18px 60px;
35 | background: #189F92;
36 | position: relative;
37 | color: #fff;
38 | font-size: 16px;
39 | }
40 |
41 | .login input[type=text],
42 | .login input[type=file],
43 | .login input[type=password],
44 | .login input[type=email], select {
45 | border: 1px solid #DCDEE0;
46 | vertical-align: middle;
47 | border-radius: 3px;
48 | height: 50px;
49 | padding: 0px 16px;
50 | font-size: 14px;
51 | color: #555555;
52 | outline:none;
53 | width:100%;
54 | box-sizing: border-box;
55 | }
56 | .login input[type=text]:focus,
57 | .login input[type=file]:focus,
58 | .login input[type=password]:focus,
59 | .login input[type=email]:focus, select:focus {
60 | border: 1px solid #27A9E3;
61 | }
62 | .login input[type=submit],
63 | .login input[type=button]{
64 | display: inline-block;
65 | vertical-align: middle;
66 | padding: 12px 24px;
67 | margin: 0px;
68 | font-size: 18px;
69 | line-height: 24px;
70 | text-align: center;
71 | white-space: nowrap;
72 | vertical-align: middle;
73 | cursor: pointer;
74 | color: #ffffff;
75 | background-color: #189F92;
76 | border-radius: 3px;
77 | border: none;
78 | -webkit-appearance: none;
79 | outline:none;
80 | width:100%;
81 | }
82 | .login hr {
83 | background: #fff url() 0 0 no-repeat;
84 | }
85 | .login hr.hr15 {
86 | height: 15px;
87 | border: none;
88 | margin: 0px;
89 | padding: 0px;
90 | width: 100%;
91 | }
92 | .login hr.hr20 {
93 | height: 20px;
94 | border: none;
95 | margin: 0px;
96 | padding: 0px;
97 | width: 100%;
98 | }
99 |
--------------------------------------------------------------------------------
/luaclib/src/lcrypt/sha.c:
--------------------------------------------------------------------------------
1 | #include "lcrypt.h"
2 |
3 | /*
4 | # define MD5_DIGEST_LENGTH 16
5 | # define SHA_DIGEST_LENGTH 20
6 | # define SHA224_DIGEST_LENGTH 28
7 | # define SHA256_DIGEST_LENGTH 32
8 | # define SHA384_DIGEST_LENGTH 48
9 | # define SHA512_DIGEST_LENGTH 64
10 | */
11 |
12 | static inline int sha_digest(lua_State *L, const char* text, size_t tsize, const EVP_MD *type) {
13 | unsigned int rsize = EVP_MAX_MD_SIZE;
14 | unsigned char result[rsize];
15 | EVP_Digest(text, tsize, result, &rsize, type, NULL);
16 | lua_pushlstring(L, (const char*)result, rsize);
17 | return 1;
18 | }
19 |
20 | int lmd4(lua_State *L) {
21 | size_t sz = 0;
22 | const char * text = luaL_checklstring(L, 1, &sz);
23 | if (!text || sz <= 0)
24 | return luaL_error(L, "Invalid text value.");
25 | return sha_digest(L, text, sz, EVP_md4());
26 | }
27 |
28 | int lmd5(lua_State *L) {
29 | size_t sz = 0;
30 | const char * text = luaL_checklstring(L, 1, &sz);
31 | if (!text || sz <= 0)
32 | return luaL_error(L, "Invalid text value.");
33 | return sha_digest(L, text, sz, EVP_md5());
34 | };
35 |
36 | int lsha128(lua_State *L) {
37 | size_t sz = 0;
38 | const char * text = luaL_checklstring(L, 1, &sz);
39 | if (!text || sz <= 0)
40 | return luaL_error(L, "Invalid text value.");
41 | return sha_digest(L, text, sz, EVP_sha1());
42 | };
43 |
44 | int lsha224(lua_State *L) {
45 | size_t sz = 0;
46 | const char * text = luaL_checklstring(L, 1, &sz);
47 | if (!text || sz <= 0)
48 | return luaL_error(L, "Invalid text value.");
49 | return sha_digest(L, text, sz, EVP_sha224());
50 | };
51 |
52 | int lsha256(lua_State *L) {
53 | size_t sz = 0;
54 | const char * text = luaL_checklstring(L, 1, &sz);
55 | if (!text || sz <= 0)
56 | return luaL_error(L, "Invalid text value.");
57 | return sha_digest(L, text, sz, EVP_sha256());
58 | };
59 |
60 | int lsha384(lua_State *L) {
61 | size_t sz = 0;
62 | const char * text = luaL_checklstring(L, 1, &sz);
63 | if (!text || sz <= 0)
64 | return luaL_error(L, "Invalid text value.");
65 | return sha_digest(L, text, sz, EVP_sha384());
66 | };
67 |
68 | int lsha512(lua_State *L) {
69 | size_t sz = 0;
70 | const char * text = luaL_checklstring(L, 1, &sz);
71 | if (!text || sz <= 0)
72 | return luaL_error(L, "Invalid text value.");
73 | return sha_digest(L, text, sz, EVP_sha512());
74 | };
75 |
76 | int lripemd160(lua_State *L) {
77 | size_t sz = 0;
78 | const char * text = luaL_checklstring(L, 1, &sz);
79 | if (!text || sz <= 0)
80 | return luaL_error(L, "Invalid text value.");
81 | return sha_digest(L, text, sz, EVP_ripemd160());
82 | };
--------------------------------------------------------------------------------
/lualib/internal/UDP.lua:
--------------------------------------------------------------------------------
1 | local ti = require "internal.Timer"
2 | local co = require "internal.Co"
3 | local udp = require "udp"
4 | local class = require "class"
5 |
6 | local co_new = co.new
7 | local co_self = co.self
8 | local co_wakeup = co.wakeup
9 | local co_wait = co.wait
10 |
11 | local G_Reference = {}
12 | local tab = debug.getregistry()
13 | tab['__G_UDP__'] = G_Reference
14 |
15 | local UDP = class("UDP")
16 |
17 | function UDP:ctor(opt)
18 | self.udp = udp.new()
19 | G_Reference[self] = true
20 | end
21 |
22 | -- 超时时间
23 | function UDP:timeout(Interval)
24 | if type(Interval) == 'number' and Interval >= 0 then
25 | self._timeout = Interval
26 | end
27 | return self
28 | end
29 |
30 | function UDP:connect(ip, port)
31 | self.fd = udp.connect(ip, port)
32 | if not self.fd or self.fd <= 0 then
33 | return nil, "Can't Creat UDP Socket"
34 | end
35 | return true
36 | end
37 |
38 | function UDP:recv(...)
39 | if self.udp then
40 | local co = co_self()
41 | self.read_co = co_new(function ( ... )
42 | local data, len = udp.recv(self.fd)
43 | if self.timer then
44 | self.timer:stop()
45 | self.timer = nil
46 | end
47 | udp.stop(self.udp)
48 | self.read_co = nil
49 | if data then
50 | return co_wakeup(co, data, len)
51 | end
52 | return co_wakeup(co, nil, '未知的udp错误')
53 | end)
54 | self.timer = ti.timeout(self._timeout, function ( ... )
55 | udp.stop(self.udp)
56 | self.read_co = nil
57 | self.timer = nil
58 | return co_wakeup(co, nil, 'udp_recv timout(超时)..')
59 | end)
60 | udp.start(self.udp, self.fd, self.read_co)
61 | return co_wait()
62 | end
63 | end
64 |
65 | function UDP:send(data)
66 | if type(data) ~= 'string' or not self.fd or self.fd <= 0 then
67 | return
68 | end
69 | return udp.send(self.fd, data, #data)
70 | end
71 |
72 | function UDP:close()
73 | if self.udp then
74 | udp.stop(udp)
75 | self.udp = nil
76 | end
77 |
78 | if self.timer then
79 | ti.stop(self.timer)
80 | self.timer = nil
81 | end
82 |
83 | if self.fd then
84 | udp.close(self.fd)
85 | self.fd = nil
86 | end
87 |
88 | if self._timeout then
89 | self._timeout = nil
90 | end
91 |
92 | G_Reference[self] = nil
93 | end
94 |
95 | ---comment 刷新
96 | function UDP.flush()
97 | local G_REF = {}
98 | for key, value in pairs(G_Reference) do
99 | G_REF[key] = value
100 | end
101 | G_Reference = G_REF
102 | tab['__G_UDP__'] = G_REF
103 | end
104 |
105 | return UDP
106 |
--------------------------------------------------------------------------------
/src/core_sys.h:
--------------------------------------------------------------------------------
1 | #ifndef __CORE_SYS__
2 | #define __CORE_SYS__
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | #if defined(__MSYS__) || defined(__CYGWIN__)
32 | #define __OS__ ("Windows")
33 | #elif defined(__APPLE__)
34 | #define __OS__ ("Apple")
35 | #elif defined(linux) || defined(__linux) || defined(__linux__)
36 | #define __OS__ ("Linux")
37 | #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
38 | #define __OS__ ("BSD")
39 | #else
40 | #define __OS__ ("Unix")
41 | #endif
42 |
43 | #if LUA_VERSION_NUM >= 504
44 | #ifndef CO_GCRESET
45 | #define CO_GCRESET(L) lua_gc(L, LUA_GCGEN, NULL, NULL);
46 | #endif
47 | #ifndef CO_RESUME
48 | #define CO_RESUME(L, from, nargs) ({int nout = 0; lua_resume(L, from, nargs, &nout);})
49 | #endif
50 | #else
51 | #ifndef CO_GCRESET
52 | #define CO_GCRESET(L)
53 | #endif
54 | #ifndef CO_RESUME
55 | #define CO_RESUME(L, from, nargs) lua_resume(L, from, nargs)
56 | #endif
57 | #endif
58 |
59 | #ifndef EWOULDBLOCK
60 | #define EWOULDBLOCK EAGAIN
61 | #endif
62 |
63 | // 设置子进程自动关闭进程fd.
64 | #define non_exec(socket) {fcntl(socket, F_SETFD, fcntl(socket, F_GETFL, 0) | FD_CLOEXEC);}
65 |
66 | // 设置非阻塞模式
67 | #define non_blocking(socket) {non_exec(socket); fcntl(socket, F_SETFL, fcntl(socket, F_GETFL, 0) | O_NONBLOCK);}
68 |
69 | // 设置nodelay模式
70 | #define non_delay(socket) ({int Enable = 1; setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, &Enable, sizeof(Enable));})
71 |
72 | /* [datetime][level][file][function][line][具体打印内容] */
73 | #define LOG(LEVEL, CONTENT) { \
74 | time_t t = time(NULL); struct tm* lt = localtime(&t); \
75 | fprintf(stdout, "[%04d/%02d/%02d][%02d:%02d:%02d][%s][%s][%s:%d] : %s\n", \
76 | lt->tm_year + 1900, 1 + lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, \
77 | LEVEL, __FILE__, __FUNCTION__, __LINE__, CONTENT); \
78 | fflush(stdout); \
79 | }
80 |
81 | /* 微秒级时间戳函数 */
82 | double now(void);
83 |
84 | /* 检查是否为有效ipv4地址 */
85 | int ipv4(const char *IP);
86 |
87 | /* 检查是否为有效ipv6地址 */
88 | int ipv6(const char *IP);
89 |
90 | /* 返回当前操作系统类型 */
91 | const char* os(void);
92 |
93 | #endif
94 |
--------------------------------------------------------------------------------
/static/lib/layui/lay/modules/rate.js:
--------------------------------------------------------------------------------
1 | /** layui-v2.5.4 MIT License By https://www.layui.com */
2 | ;layui.define("jquery",function(e){"use strict";var a=layui.jquery,i={config:{},index:layui.rate?layui.rate.index+1e4:0,set:function(e){var i=this;return i.config=a.extend({},i.config,e),i},on:function(e,a){return layui.onevent.call(this,n,e,a)}},l=function(){var e=this,a=e.config;return{setvalue:function(a){e.setvalue.call(e,a)},config:a}},n="rate",t="layui-rate",o="layui-icon-rate",s="layui-icon-rate-solid",u="layui-icon-rate-half",r="layui-icon-rate-solid layui-icon-rate-half",c="layui-icon-rate-solid layui-icon-rate",f="layui-icon-rate layui-icon-rate-half",v=function(e){var l=this;l.index=++i.index,l.config=a.extend({},l.config,i.config,e),l.render()};v.prototype.config={length:5,text:!1,readonly:!1,half:!1,value:0,theme:""},v.prototype.render=function(){var e=this,i=e.config,l=i.theme?'style="color: '+i.theme+';"':"";i.elem=a(i.elem),parseInt(i.value)!==i.value&&(i.half||(i.value=Math.ceil(i.value)-i.value<.5?Math.ceil(i.value):Math.floor(i.value)));for(var n='",u=1;u<=i.length;u++){var r=' ";i.half&&parseInt(i.value)!==i.value&&u==Math.ceil(i.value)?n=n+' ":n+=r}n+=" "+(i.text?''+i.value+"星":"")+" ";var c=i.elem,f=c.next("."+t);f[0]&&f.remove(),e.elemTemp=a(n),i.span=e.elemTemp.next("span"),i.setText&&i.setText(i.value),c.html(e.elemTemp),c.addClass("layui-inline"),i.readonly||e.action()},v.prototype.setvalue=function(e){var a=this,i=a.config;i.value=e,a.render()},v.prototype.action=function(){var e=this,i=e.config,l=e.elemTemp,n=l.find("i").width();l.children("li").each(function(e){var t=e+1,v=a(this);v.on("click",function(e){if(i.value=t,i.half){var o=e.pageX-a(this).offset().left;o<=n/2&&(i.value=i.value-.5)}i.text&&l.next("span").text(i.value+"星"),i.choose&&i.choose(i.value),i.setText&&i.setText(i.value)}),v.on("mousemove",function(e){if(l.find("i").each(function(){a(this).addClass(o).removeClass(r)}),l.find("i:lt("+t+")").each(function(){a(this).addClass(s).removeClass(f)}),i.half){var c=e.pageX-a(this).offset().left;c<=n/2&&v.children("i").addClass(u).removeClass(s)}}),v.on("mouseleave",function(){l.find("i").each(function(){a(this).addClass(o).removeClass(r)}),l.find("i:lt("+Math.floor(i.value)+")").each(function(){a(this).addClass(s).removeClass(f)}),i.half&&parseInt(i.value)!==i.value&&l.children("li:eq("+Math.floor(i.value)+")").children("i").addClass(u).removeClass(c)})})},v.prototype.events=function(){var e=this;e.config},i.render=function(e){var a=new v(e);return l.call(a)},e(n,i)});
--------------------------------------------------------------------------------
/script/test_cfadmin.lua:
--------------------------------------------------------------------------------
1 | local httpd = require "httpd"
2 | local DB = require "DB"
3 |
4 | --[[
5 | 请按照以下步奏初始化后台:
6 | 1. 创建一个数据库(名字任意);
7 | 2. 请手动打开lualib/db/database.sql文件, 复制里面的SQL语句在GUI工具中执行一次;
8 | 3. 执行完成之后, 将您填写的数据库替换database字段, 并且charset需要设置一致.
9 | ]]
10 |
11 | local db = DB:new({
12 | host = '10.0.0.16',
13 | port = 3306,
14 | username = 'root',
15 | password = '123456789',
16 | charset = 'utf8mb4',
17 | database = 'cfadmin',
18 | max = 100,
19 | })
20 |
21 | db:connect()
22 |
23 | -- 导入httpd对象
24 | local app = httpd:new("App")
25 | -- httpd启用Cookie扩展
26 | app:enable_cookie()
27 | -- httpd设置Cookie加密的密匙
28 | app:cookie_secure("https://github.com/CandyMi/core_framework")
29 | -- app:cookie_secure("candymi")
30 |
31 | -- 导入cf内置的admin库
32 | local cfadmin = require "admin"
33 |
34 | -- 注册后台页面路由
35 | cfadmin.init_page(app, db)
36 |
37 |
38 | -- 这个函数仅在第一次初始化数据的时候适用
39 | -- 初始化完成之后, 请不要再运行.
40 | cfadmin.init_db()
41 |
42 | -- 这里设置首页的显示的页面
43 | -- cfadmin.init_home(location or domain + path)
44 | -- cfadmin.init_home('https://www.baidu.com')
45 |
46 | local view = require "admin.view"
47 | -- 参数:
48 | -- 1. ctx是一个http req 对象, 目前内置包括: get_method, get_args, get_path, get_raw_path, get_headers, get_cookie
49 | -- 2. db初始化后的db对象, 方便用户直接使用.
50 |
51 | view.use('/admin/test1', function (ctx, db)
52 | return "hello world"
53 | end)
54 |
55 | view.api('/api/admin/test2', function (ctx, db)
56 | return '{"code":0,"msg":"hello world"}'
57 | end)
58 |
59 | app:ws('/ws', require "ws")
60 |
61 | app:api('/api', function (content)
62 | require('logging'):new():DEBUG(content.args or content.body)
63 | return '{"code":200}'
64 | end)
65 |
66 | app:use('/view', function (content)
67 | require('logging'):new():DEBUG(content.files)
68 | return 'cfadmin v0.3 '
69 | end)
70 |
71 | -- 这里是设置语言的地方
72 | -- 语言表在admin/locales内, 可参照key -> value进行填写.
73 | -- 传入一个数组表: 索引1是key, 索引2为显示内容.
74 |
75 | -- cfadmin.add_locale_item('ZH-CN', {
76 | -- {'login.form.title', '这是登录页Title'},
77 | -- {'dashboard.header.logo', '仪表盘 Logo'}
78 | -- })
79 |
80 | -- cfadmin.add_locale_item('EN-US', {
81 | -- {'login.form.title', 'This is Login Page Title'},
82 | -- {'dashboard.header.logo', 'dashboard Logo'}
83 | -- })
84 |
85 | -- 开启页面缓存能显著提升页面渲染性能. 生产环境下建议开启.
86 | -- 也因为cf缓存模板页面内容, 所以开发模式下不建议开启.
87 | -- cfadmin.cached()
88 |
89 | -- 这个方法可以用来设置静态文件域名与前缀.
90 | -- 如果静态文件在其它域名或者无法访问, 可以使用这个参数修改.(域名后必须加上'/')
91 | -- cfadmin.static('/')
92 |
93 | -- 设置cfadmin的区域语言, 默认为: ZH-CN
94 | -- cfadmin.set_locale('EN-US')
95 |
96 | -- 设置客户端静态文件ttl值内无需再次请求, 减少服务端消耗
97 | -- app:static('static', 30)
98 | app:static('static')
99 |
100 | -- httpd监听端口
101 | app:listen("0.0.0.0", 8080, 128)
102 | -- app:listenx("cfadmin.sock", 128)
103 |
104 | -- 运行
105 | app:run()
106 |
--------------------------------------------------------------------------------