├── Makefile ├── README.md └── files └── root ├── etc ├── config │ └── wifidog ├── init.d │ └── wifidog ├── lighttpd │ └── lighttpd.conf ├── php.ini └── uci-defaults │ └── luci-wifidog ├── usr └── lib │ └── lua │ └── luci │ ├── controller │ └── wifidog.lua │ └── model │ └── cbi │ └── wifidog.lua └── www └── wifidog ├── Slim ├── Environment.php ├── Exception │ ├── Pass.php │ └── Stop.php ├── Helper │ └── Set.php ├── Http │ ├── Cookies.php │ ├── Headers.php │ ├── Request.php │ ├── Response.php │ └── Util.php ├── Log.php ├── LogWriter.php ├── Middleware.php ├── Middleware │ ├── ContentTypes.php │ ├── Flash.php │ ├── MethodOverride.php │ ├── PrettyExceptions.php │ └── SessionCookie.php ├── Route.php ├── Router.php ├── Slim.php └── View.php ├── assets ├── loader.gif ├── portal.css ├── portal.min.js ├── ratchicons.eot ├── ratchicons.svg ├── ratchicons.ttf └── ratchicons.woff ├── index.php ├── jobs ├── simple_html_dom.php └── sync.php └── templates ├── 701.html ├── show.php └── touch.php /Makefile: -------------------------------------------------------------------------------- 1 | include $(TOPDIR)/rules.mk 2 | 3 | PKG_NAME:=luci-app-wifidog 4 | PKG_VERSION=1.0 5 | PKG_RELEASE:=1 6 | 7 | PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) 8 | 9 | include $(INCLUDE_DIR)/package.mk 10 | 11 | define Package/luci-app-wifidog 12 | SECTION:=luci 13 | CATEGORY:=LuCI 14 | SUBMENU:=3. Applications 15 | DEPENDS:=+wifidog +lighttpd-mod-fastcgi +lighttpd-mod-rewrite +php5-fastcgi +php5-cli +php5-mod-ctype +php5-mod-pdo +php5-mod-pdo-sqlite +php5-mod-session +php5-mod-sqlite3 +php5-mod-tokenizer +zoneinfo-asia +zoneinfo-core 16 | TITLE:=wifidog configuration for LuCI 17 | endef 18 | 19 | define Package/luci-app-wifidog/description 20 | This package contains LuCI configuration pages for wifidog. 21 | endef 22 | 23 | define Build/Prepare 24 | endef 25 | 26 | define Build/Configure 27 | endef 28 | 29 | define Build/Compile 30 | endef 31 | 32 | define Package/luci-app-wifidog/install 33 | $(INSTALL_DIR) $(1)/etc/config 34 | $(INSTALL_DIR) $(1)/etc/lighttpd 35 | $(INSTALL_DIR) $(1)/etc/init.d 36 | $(INSTALL_DIR) $(1)/etc/uci-defaults 37 | $(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi 38 | $(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller 39 | $(INSTALL_DIR) $(1)/www 40 | $(INSTALL_DIR) $(1)/www/wifidog 41 | $(INSTALL_DIR) $(1)/www/wifidog/assets 42 | $(INSTALL_DIR) $(1)/www/wifidog/assets/images 43 | $(INSTALL_DIR) $(1)/www/wifidog/Slim 44 | $(INSTALL_DIR) $(1)/www/wifidog/Slim/Exception 45 | $(INSTALL_DIR) $(1)/www/wifidog/Slim/Helper 46 | $(INSTALL_DIR) $(1)/www/wifidog/Slim/Http 47 | $(INSTALL_DIR) $(1)/www/wifidog/Slim/Middleware 48 | $(INSTALL_DIR) $(1)/www/wifidog/templates 49 | $(INSTALL_CONF) ./files/root/etc/config/wifidog $(1)/etc/config/ 50 | $(INSTALL_CONF) ./files/root/etc/php.ini $(1)/etc/ 51 | $(INSTALL_CONF) ./files/root/etc/lighttpd/lighttpd.conf $(1)/etc/lighttpd/ 52 | $(INSTALL_BIN) ./files/root/etc/init.d/wifidog $(1)/etc/init.d/ 53 | $(INSTALL_BIN) ./files/root/etc/uci-defaults/luci-wifidog $(1)/etc/uci-defaults/ 54 | $(INSTALL_DATA) ./files/root/usr/lib/lua/luci/model/cbi/wifidog.lua $(1)/usr/lib/lua/luci/model/cbi/ 55 | $(INSTALL_DATA) ./files/root/usr/lib/lua/luci/controller/wifidog.lua $(1)/usr/lib/lua/luci/controller/ 56 | $(INSTALL_DATA) ./files/root/www/wifidog/assets/loader.gif $(1)/www/wifidog/assets/ 57 | $(INSTALL_DATA) ./files/root/www/wifidog/assets/portal.css $(1)/www/wifidog/assets/ 58 | $(INSTALL_DATA) ./files/root/www/wifidog/assets/portal.min.js $(1)/www/wifidog/assets/ 59 | $(INSTALL_DATA) ./files/root/www/wifidog/assets/ratchicons.eot $(1)/www/wifidog/assets/ 60 | $(INSTALL_DATA) ./files/root/www/wifidog/assets/ratchicons.svg $(1)/www/wifidog/assets/ 61 | $(INSTALL_DATA) ./files/root/www/wifidog/assets/ratchicons.ttf $(1)/www/wifidog/assets/ 62 | $(INSTALL_DATA) ./files/root/www/wifidog/assets/ratchicons.woff $(1)/www/wifidog/assets/ 63 | $(INSTALL_DATA) ./files/root/www/wifidog/index.php $(1)/www/wifidog/ 64 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Environment.php $(1)/www/wifidog/Slim/ 65 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Exception/Pass.php $(1)/www/wifidog/Slim/Exception/ 66 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Exception/Stop.php $(1)/www/wifidog/Slim/Exception/ 67 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Helper/Set.php $(1)/www/wifidog/Slim/Helper/ 68 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Http/Cookies.php $(1)/www/wifidog/Slim/Http/ 69 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Http/Headers.php $(1)/www/wifidog/Slim/Http/ 70 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Http/Request.php $(1)/www/wifidog/Slim/Http/ 71 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Http/Response.php $(1)/www/wifidog/Slim/Http/ 72 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Http/Util.php $(1)/www/wifidog/Slim/Http/ 73 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Log.php $(1)/www/wifidog/Slim/ 74 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/LogWriter.php $(1)/www/wifidog/Slim/ 75 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Middleware/ContentTypes.php $(1)/www/wifidog/Slim/Middleware/ 76 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Middleware/Flash.php $(1)/www/wifidog/Slim/Middleware/ 77 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Middleware/MethodOverride.php $(1)/www/wifidog/Slim/Middleware/ 78 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Middleware/PrettyExceptions.php $(1)/www/wifidog/Slim/Middleware/ 79 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Middleware/SessionCookie.php $(1)/www/wifidog/Slim/Middleware/ 80 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Middleware.php $(1)/www/wifidog/Slim/ 81 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Route.php $(1)/www/wifidog/Slim/ 82 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Router.php $(1)/www/wifidog/Slim/ 83 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/Slim.php $(1)/www/wifidog/Slim/ 84 | $(INSTALL_DATA) ./files/root/www/wifidog/Slim/View.php $(1)/www/wifidog/Slim/ 85 | $(INSTALL_DATA) ./files/root/www/wifidog/templates/701.html $(1)/www/wifidog/templates/ 86 | $(INSTALL_DATA) ./files/root/www/wifidog/templates/show.php $(1)/www/wifidog/templates/ 87 | $(INSTALL_DATA) ./files/root/www/wifidog/templates/touch.php $(1)/www/wifidog/templates/ 88 | endef 89 | 90 | define Package/luci-app-wifidog/postinst 91 | #!/bin/sh 92 | [ -n "${IPKG_INSTROOT}" ] || { 93 | ( . /etc/uci-defaults/luci-wifidog ) && rm -f /etc/uci-defaults/luci-wifidog 94 | chmod 755 /etc/init.d/wifidog >/dev/null 2>&1 95 | /etc/init.d/wifidog enable >/dev/null 2>&1 96 | exit 0 97 | } 98 | endef 99 | 100 | $(eval $(call BuildPackage,luci-app-wifidog)) 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # luci-app-wifidog 2 | This package contains LuCI configuration pages for wifidog. 3 | 4 | ## Features 5 | 1. Luci configuration page for wifidog 6 | 2. Bulit-in local authentication server with lighttp and php5 7 | 3. Sync with remote server 8 | 9 | ## Install 10 | 1. Git clone this respository in your `package` directory. 11 | 2. `make menuconfig` and select luci-app-wifidog in LUCI category and save. 12 | 3. `make luci-app-wifidog/compile` with a single package. 13 | -------------------------------------------------------------------------------- /files/root/etc/config/wifidog: -------------------------------------------------------------------------------- 1 | config settings 'settings' 2 | option gateway_host 'wanluo.tv' 3 | option gateway_hostname '万罗热点' 4 | option gateway_httpport '80' 5 | option gateway_path '/wifidog/' 6 | option gateway_connmax '50' 7 | option wifidog_enable '0' 8 | option offline_enable '0' 9 | option gatewayport '2060' 10 | option check_interval '60' 11 | option client_timeout '5' 12 | option client_time_limit '60' 13 | 14 | -------------------------------------------------------------------------------- /files/root/etc/init.d/wifidog: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | 3 | START=65 4 | 5 | EXTRA_COMMANDS="status" 6 | EXTRA_HELP=" status Print the status of the service" 7 | 8 | config_load() 9 | { 10 | wifidog_enable=$(uci get wifidog.settings.wifidog_enable) 11 | offline_enable=$(uci get wifidog.settings.offline_enable) 12 | if [[ "$wifidog_enable" -eq 0 ]]; then 13 | stop 14 | exit 0 15 | else 16 | /usr/bin/wifidog-init stop 17 | sleep 1 18 | 19 | rm -f /etc/wifidog.conf 20 | gateway_interface=$(uci get wifidog.settings.gateway_interface) 21 | gateway_eninterface=$(uci get wifidog.settings.gateway_eninterface) 22 | gateway_host=$(uci get wifidog.settings.gateway_host) 23 | gateway_httpport=$(uci get wifidog.settings.gateway_httpport) 24 | gateway_path=$(uci get wifidog.settings.gateway_path) 25 | gateway_connmax=$(uci get wifidog.settings.gateway_connmax) 26 | ssl_enable=$(uci get wifidog.settings.ssl_enable) 27 | check_interval=$(uci get wifidog.settings.check_interval) 28 | client_timeout=$(uci get wifidog.settings.client_timeout) 29 | sslport=$(uci get wifidog.settings.sslport) 30 | deamo_enable=$(uci get wifidog.settings.deamo_enable) 31 | gatewayport=$(uci get wifidog.settings.gatewayport) 32 | myz_mac=$(uci get wifidog.settings.myz_mac) 33 | bmd_url=$(uci get wifidog.settings.bmd_url) 34 | 35 | echo " 36 | GatewayInterface $gateway_interface 37 | AuthServer { 38 | Hostname $gateway_host 39 | SSLAvailable $ssl_enable 40 | SSLPort $sslport 41 | HTTPPort $gateway_httpport 42 | Path $gateway_path 43 | } 44 | Daemon $deamo_enable 45 | GatewayPort $gatewayport 46 | CheckInterval $check_interval 47 | ClientTimeout $client_timeout 48 | HTTPDMaxConn $gateway_connmax 49 | TrustedMACList $myz_mac 50 | 51 | FirewallRuleSet global { 52 | FirewallRule allow to 61.139.2.69 53 | FirewallRule allow to 8.8.8.8 54 | FirewallRule allow to 114.114.114.114 55 | } 56 | FirewallRuleSet validating-users { 57 | FirewallRule allow to 0.0.0.0/0 58 | } 59 | 60 | FirewallRuleSet known-users { 61 | FirewallRule allow to 0.0.0.0/0 62 | } 63 | 64 | FirewallRuleSet unknown-users { 65 | FirewallRule allow udp port 53 66 | FirewallRule allow tcp port 53 67 | FirewallRule allow udp port 67 68 | FirewallRule allow tcp port 67 69 | } 70 | 71 | FirewallRuleSet locked-users { 72 | FirewallRule block to 0.0.0.0/0 73 | } 74 | " >> /etc/wifidog.conf 75 | fi 76 | } 77 | 78 | start() { 79 | 80 | 81 | config_load 82 | /usr/bin/wifidog-init start 83 | [ "$offline_enable" -eq 1 ] && /etc/init.d/lighttpd start 84 | sleep 2 85 | iptables -t filter -A WiFiDog_br-lan_AuthServers -d $bmd_url -j ACCEPT 86 | iptables -t nat -A WiFiDog_br-lan_AuthServers -d $bmd_url -j ACCEPT 87 | } 88 | 89 | stop() { 90 | if /usr/bin/wifidog-init status 2> /dev/null 91 | then 92 | /usr/bin/wifidog-init stop 93 | fi 94 | sleep 2 95 | /etc/init.d/lighttpd stop 96 | } 97 | 98 | status() { 99 | /usr/bin/wifidog-init status 100 | 101 | } 102 | 103 | -------------------------------------------------------------------------------- /files/root/etc/lighttpd/lighttpd.conf: -------------------------------------------------------------------------------- 1 | # lighttpd configuration file 2 | # 3 | ## modules to load 4 | # all other module should only be loaded if really neccesary 5 | # - saves some time 6 | # - saves memory 7 | server.modules = ( 8 | "mod_rewrite", 9 | # "mod_redirect", 10 | # "mod_alias", 11 | # "mod_auth", 12 | # "mod_status", 13 | # "mod_setenv", 14 | "mod_fastcgi", 15 | # "mod_proxy", 16 | # "mod_simple_vhost", 17 | # "mod_cgi", 18 | # "mod_ssi", 19 | # "mod_usertrack", 20 | # "mod_expire", 21 | # "mod_webdav" 22 | ) 23 | 24 | # force use of the "write" backend (closes: #2401) 25 | server.network-backend = "write" 26 | 27 | ## a static document-root, for virtual-hosting take look at the 28 | ## server.virtual-* options 29 | server.document-root = "/www/wifidog/" 30 | 31 | ## where to send error-messages to 32 | #server.errorlog = "/var/log/lighttpd/error.log" 33 | 34 | ## files to check for if .../ is requested 35 | index-file.names = ( "index.html", "default.html", "index.htm", "default.htm", "index.php" ) 36 | 37 | ## mimetype mapping 38 | mimetype.assign = ( 39 | ".pdf" => "application/pdf", 40 | ".class" => "application/octet-stream", 41 | ".pac" => "application/x-ns-proxy-autoconfig", 42 | ".swf" => "application/x-shockwave-flash", 43 | ".wav" => "audio/x-wav", 44 | ".gif" => "image/gif", 45 | ".jpg" => "image/jpeg", 46 | ".jpeg" => "image/jpeg", 47 | ".png" => "image/png", 48 | ".svg" => "image/svg+xml", 49 | ".css" => "text/css", 50 | ".html" => "text/html", 51 | ".htm" => "text/html", 52 | ".js" => "text/javascript", 53 | ".txt" => "text/plain", 54 | ".dtd" => "text/xml", 55 | ".xml" => "text/xml" 56 | ) 57 | 58 | ## Use the "Content-Type" extended attribute to obtain mime type if possible 59 | #mimetypes.use-xattr = "enable" 60 | 61 | ## send a different Server: header 62 | ## be nice and keep it at lighttpd 63 | #server.tag = "lighttpd" 64 | 65 | $HTTP["url"] =~ "\.pdf$" { 66 | server.range-requests = "disable" 67 | } 68 | 69 | ## 70 | # which extensions should not be handle via static-file transfer 71 | # 72 | # .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi 73 | static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" ) 74 | 75 | ######### Options that are good to be but not neccesary to be changed ####### 76 | 77 | ## bind to port (default: 80) 78 | server.port = 81 79 | 80 | ## bind to localhost (default: all interfaces) 81 | #server.bind = "localhost" 82 | 83 | ## error-handler for status 404 84 | #server.error-handler-404 = "/error-handler.html" 85 | #server.error-handler-404 = "/error-handler.php" 86 | 87 | ## to help the rc.scripts 88 | server.pid-file = "/var/run/lighttpd.pid" 89 | 90 | 91 | ###### virtual hosts 92 | ## 93 | ## If you want name-based virtual hosting add the next three settings and load 94 | ## mod_simple_vhost 95 | ## 96 | ## document-root = 97 | ## virtual-server-root + virtual-server-default-host + virtual-server-docroot or 98 | ## virtual-server-root + http-host + virtual-server-docroot 99 | ## 100 | #simple-vhost.server-root = "/home/weigon/wwwroot/servers/" 101 | #simple-vhost.default-host = "grisu.home.kneschke.de" 102 | #simple-vhost.document-root = "/pages/" 103 | 104 | 105 | ## 106 | ## Format: .html 107 | ## -> ..../status-404.html for 'File not found' 108 | #server.errorfile-prefix = "/www/error-" 109 | 110 | ## virtual directory listings 111 | #server.dir-listing = "enable" 112 | 113 | ## send unhandled HTTP-header headers to error-log 114 | #debug.dump-unknown-headers = "enable" 115 | 116 | ### only root can use these options 117 | # 118 | # chroot() to directory (default: no chroot() ) 119 | #server.chroot = "/" 120 | 121 | ## change uid to (default: don't care) 122 | #server.username = "nobody" 123 | # 124 | server.upload-dirs = ( "/tmp" ) 125 | 126 | ## change uid to (default: don't care) 127 | #server.groupname = "nobody" 128 | 129 | #### compress module 130 | #compress.cache-dir = "/dev/null/" 131 | #compress.filetype = ("text/plain", "text/html") 132 | 133 | #### proxy module 134 | ## read proxy.txt for more info 135 | #proxy.server = ( 136 | # ".php" => ( 137 | # "localhost" => ( 138 | # "host" => "192.168.0.101", 139 | # "port" => 80 140 | # ) 141 | # ) 142 | #) 143 | 144 | #### fastcgi module 145 | ## read fastcgi.txt for more info 146 | fastcgi.server = ( 147 | ".php" => ( 148 | "localhost" => ( 149 | "socket" => "/tmp/php-fastcgi.socket", 150 | "bin-path" => "/usr/bin/php-fcgi", 151 | "min-procs" => 0, 152 | "max-procs" => 5, 153 | "idle-timeout" => 10, 154 | "bin-environment" => ( 155 | "PHP_FCGI_CHILDREN" => "2", 156 | "PHP_FCGI_MAX_REQUESTS" => "1000" 157 | ), 158 | "bin-copy-environment" => ( "PATH", "SHELL", "USER" ), 159 | "broken-scriptfilename" => "enable" 160 | ) 161 | ) 162 | ) 163 | 164 | #### CGI module 165 | ##cgi.assign = ( ".php" => "/usr/bin/php-cgi" ) 166 | 167 | #### SSL engine 168 | #ssl.engine = "enable" 169 | #ssl.pemfile = "server.pem" 170 | 171 | #### status module 172 | #status.status-url = "/server-status" 173 | #status.config-url = "/server-config" 174 | 175 | #### auth module 176 | ## read authentification.txt for more info 177 | #auth.backend = "plain" 178 | #auth.backend.plain.userfile = "lighttpd.user" 179 | #auth.backend.plain.groupfile = "lighttpd.group" 180 | #auth.require = ( 181 | # "/server-status" => ( 182 | # "method" => "digest", 183 | # "realm" => "download archiv", 184 | # "require" => "group=www|user=jan|host=192.168.2.10" 185 | # ), 186 | # "/server-info" => ( 187 | # "method" => "digest", 188 | # "realm" => "download archiv", 189 | # "require" => "group=www|user=jan|host=192.168.2.10" 190 | # ) 191 | #) 192 | 193 | #### url handling modules (rewrite, redirect, access) 194 | url.rewrite = ( "^/assets/.+" => "$0", ".*" => "/index.php" ) 195 | #url.redirect = ( "^/wishlist/(.+)" => "http://www.123.org/$1" ) 196 | 197 | #### both rewrite/redirect support back reference to regex conditional using %n 198 | #$HTTP["host"] =~ "^www\.(.*)" { 199 | # url.redirect = ( "^/(.*)" => "http://%1/$1" ) 200 | #} 201 | 202 | #### expire module 203 | #expire.url = ( "/buggy/" => "access 2 hours", "/asdhas/" => "access plus 1 seconds 2 minutes") 204 | 205 | #### ssi 206 | #ssi.extension = ( ".shtml" ) 207 | 208 | #### setenv 209 | #setenv.add-request-header = ( "TRAV_ENV" => "mysql://user@host/db" ) 210 | #setenv.add-response-header = ( "X-Secret-Message" => "42" ) 211 | 212 | #### variable usage: 213 | ## variable name without "." is auto prefixed by "var." and becomes "var.bar" 214 | #bar = 1 215 | #var.mystring = "foo" 216 | 217 | ## integer add 218 | #bar += 1 219 | ## string concat, with integer cast as string, result: "www.foo1.com" 220 | #server.name = "www." + mystring + var.bar + ".com" 221 | ## array merge 222 | #index-file.names = (foo + ".php") + index-file.names 223 | #index-file.names += (foo + ".php") 224 | 225 | #### include 226 | #include /etc/lighttpd/lighttpd-inc.conf 227 | ## same as above if you run: "lighttpd -f /etc/lighttpd/lighttpd.conf" 228 | #include "lighttpd-inc.conf" 229 | 230 | #### include_shell 231 | #include_shell "echo var.a=1" 232 | ## the above is same as: 233 | #var.a=1 234 | 235 | #### webdav 236 | #$HTTP["url"] =~ "^/webdav($|/)" { 237 | # webdav.activate = "enable" 238 | # webdav.is-readonly = "enable" 239 | # webdav.sqlite-db-name = "/var/run/lighttpd-webdav-lock.db" 240 | #} 241 | -------------------------------------------------------------------------------- /files/root/etc/php.ini: -------------------------------------------------------------------------------- 1 | [PHP] 2 | 3 | zend.ze1_compatibility_mode = Off 4 | 5 | ; Language Options 6 | 7 | engine = On 8 | ;short_open_tag = Off 9 | precision = 12 10 | y2k_compliance = On 11 | output_buffering = Off 12 | ;output_handler = 13 | zlib.output_compression = Off 14 | ;zlib.output_compression_level = -1 15 | ;zlib.output_handler = 16 | implicit_flush = Off 17 | unserialize_callback_func = 18 | serialize_precision = 100 19 | 20 | ;open_basedir = 21 | disable_functions = 22 | disable_classes = 23 | 24 | ; Colors for Syntax Highlighting mode. Anything that's acceptable in 25 | ; would work. 26 | ;highlight.string = #DD0000 27 | ;highlight.comment = #FF9900 28 | ;highlight.keyword = #007700 29 | ;highlight.bg = #FFFFFF 30 | ;highlight.default = #0000BB 31 | ;highlight.html = #000000 32 | 33 | ;ignore_user_abort = On 34 | ;realpath_cache_size = 16k 35 | ;realpath_cache_ttl = 120 36 | 37 | ; Miscellaneous 38 | 39 | expose_php = On 40 | 41 | ; Resource Limits 42 | 43 | max_execution_time = 30 ; Maximum execution time of each script, in seconds. 44 | max_input_time = 60 ; Maximum amount of time each script may spend parsing request data. 45 | ;max_input_nesting_level = 64 46 | memory_limit = 8M ; Maximum amount of memory a script may consume. 47 | 48 | ; Error handling and logging 49 | 50 | ; Error Level Constants: 51 | ; E_ALL - All errors and warnings (includes E_STRICT as of PHP 6.0.0) 52 | ; E_ERROR - fatal run-time errors 53 | ; E_RECOVERABLE_ERROR - almost fatal run-time errors 54 | ; E_WARNING - run-time warnings (non-fatal errors) 55 | ; E_PARSE - compile-time parse errors 56 | ; E_NOTICE - run-time notices (these are warnings which often result 57 | ; from a bug in your code, but it's possible that it was 58 | ; intentional (e.g., using an uninitialized variable and 59 | ; relying on the fact it's automatically initialized to an 60 | ; empty string) 61 | ; E_STRICT - run-time notices, enable to have PHP suggest changes 62 | ; to your code which will ensure the best interoperability 63 | ; and forward compatibility of your code 64 | ; E_CORE_ERROR - fatal errors that occur during PHP's initial startup 65 | ; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's 66 | ; initial startup 67 | ; E_COMPILE_ERROR - fatal compile-time errors 68 | ; E_COMPILE_WARNING - compile-time warnings (non-fatal errors) 69 | ; E_USER_ERROR - user-generated error message 70 | ; E_USER_WARNING - user-generated warning message 71 | ; E_USER_NOTICE - user-generated notice message 72 | ; E_DEPRECATED - warn about code that will not work in future versions 73 | ; of PHP 74 | ; E_USER_DEPRECATED - user-generated deprecation warnings 75 | ; 76 | ; Common Values: 77 | ; E_ALL & ~E_NOTICE (Show all errors, except for notices and coding standards warnings.) 78 | ; E_ALL & ~E_NOTICE | E_STRICT (Show all errors, except for notices) 79 | ; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors) 80 | ; E_ALL | E_STRICT (Show all errors, warnings and notices including coding standards.) 81 | ; Default Value: E_ALL & ~E_NOTICE 82 | error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT 83 | 84 | display_errors = On 85 | display_startup_errors = Off 86 | log_errors = Off 87 | log_errors_max_len = 1024 88 | ignore_repeated_errors = Off 89 | ignore_repeated_source = Off 90 | report_memleaks = On 91 | ;report_zend_debug = 0 92 | track_errors = Off 93 | ;html_errors = Off 94 | ;docref_root = "/phpmanual/" 95 | ;docref_ext = .html 96 | ;error_prepend_string = "" 97 | ;error_append_string = "" 98 | ; Log errors to specified file. 99 | ;error_log = /var/log/php_errors.log 100 | ; Log errors to syslog. 101 | ;error_log = syslog 102 | 103 | ; Data Handling 104 | 105 | ;arg_separator.output = "&" 106 | ;arg_separator.input = ";&" 107 | variables_order = "EGPCS" 108 | request_order = "GP" 109 | register_globals = Off 110 | register_long_arrays = Off 111 | register_argc_argv = On 112 | auto_globals_jit = On 113 | post_max_size = 8M 114 | ;magic_quotes_gpc = Off 115 | magic_quotes_runtime = Off 116 | magic_quotes_sybase = Off 117 | auto_prepend_file = 118 | auto_append_file = 119 | default_mimetype = "text/html" 120 | ;default_charset = "iso-8859-1" 121 | ;always_populate_raw_post_data = On 122 | 123 | ; Paths and Directories 124 | 125 | ; UNIX: "/path1:/path2" 126 | ;include_path = ".:/php/includes" 127 | ;doc_root = "/root/www" 128 | user_dir = 129 | extension_dir = "/usr/lib/php" 130 | enable_dl = On 131 | cgi.force_redirect = 1 132 | ;cgi.nph = 1 133 | ;cgi.redirect_status_env = ; 134 | cgi.fix_pathinfo=1 135 | ;fastcgi.impersonate = 1; 136 | ;fastcgi.logging = 0 137 | ;cgi.rfc2616_headers = 0 138 | 139 | ; File Uploads 140 | 141 | file_uploads = On 142 | upload_tmp_dir = "/tmp" 143 | upload_max_filesize = 2M 144 | max_file_uploads = 20 145 | 146 | ; Fopen wrappers 147 | 148 | allow_url_fopen = On 149 | allow_url_include = Off 150 | ;from="john@doe.com" 151 | ;user_agent="PHP" 152 | default_socket_timeout = 60 153 | ;auto_detect_line_endings = Off 154 | 155 | ; Dynamic Extensions 156 | 157 | extension=ctype.so 158 | extension=curl.so 159 | ;extension=dom.so 160 | ;extension=exif.so 161 | ;extension=ftp.so 162 | ;extension=gd.so 163 | ;extension=gmp.so 164 | ;extension=hash.so 165 | ;extension=iconv.so 166 | extension=json.so 167 | ;extension=ldap.so 168 | ;extension=mbstring.so 169 | ;extension=mcrypt.so 170 | ;extension=mysql.so 171 | ;extension=openssl.so 172 | ;extension=pcre.so 173 | extension=pdo.so 174 | ;extension=pdo-mysql.so 175 | ;extension=pdo-pgsql.so 176 | extension=pdo_sqlite.so 177 | ;extension=pgsql.so 178 | extension=session.so 179 | ;extension=soap.so 180 | ;extension=sockets.so 181 | ;extension=sqlite.so 182 | ;extension=sqlite3.so 183 | extension=tokenizer.so 184 | ;extension=xml.so 185 | ;extension=xmlreader.so 186 | ;extension=xmlwriter.so 187 | 188 | ; Module Settings 189 | 190 | [APC] 191 | apc.enabled = 1 192 | apc.shm_segments = 1 ;The number of shared memory segments to allocate for the compiler cache. 193 | apc.shm_size = 4M ;The size of each shared memory segment. 194 | 195 | [Date] 196 | date.timezone = 'Asia/Chongqing' 197 | ;date.default_latitude = 31.7667 198 | ;date.default_longitude = 35.2333 199 | ;date.sunrise_zenith = 90.583333 200 | ;date.sunset_zenith = 90.583333 201 | 202 | [filter] 203 | ;filter.default = unsafe_raw 204 | ;filter.default_flags = 205 | 206 | [iconv] 207 | ;iconv.input_encoding = ISO-8859-1 208 | ;iconv.internal_encoding = ISO-8859-1 209 | ;iconv.output_encoding = ISO-8859-1 210 | 211 | [sqlite] 212 | ;sqlite.assoc_case = 0 213 | 214 | [sqlite3] 215 | ;sqlite3.extension_dir = 216 | 217 | [Pdo_mysql] 218 | pdo_mysql.cache_size = 2000 219 | pdo_mysql.default_socket= 220 | 221 | [MySQL] 222 | mysql.allow_local_infile = On 223 | mysql.allow_persistent = On 224 | mysql.cache_size = 2000 225 | mysql.max_persistent = -1 226 | mysql.max_links = -1 227 | mysql.default_port = 228 | mysql.default_socket = 229 | mysql.default_host = 230 | mysql.default_user = 231 | mysql.default_password = 232 | mysql.connect_timeout = 60 233 | mysql.trace_mode = Off 234 | 235 | [PostgresSQL] 236 | pgsql.allow_persistent = On 237 | pgsql.auto_reset_persistent = Off 238 | pgsql.max_persistent = -1 239 | pgsql.max_links = -1 240 | pgsql.ignore_notice = 0 241 | pgsql.log_notice = 0 242 | 243 | [Session] 244 | session.save_handler = files 245 | session.save_path = "/tmp" 246 | session.use_cookies = 1 247 | ;session.cookie_secure = 248 | session.use_only_cookies = 1 249 | session.name = PHPSESSID 250 | session.auto_start = 0 251 | session.cookie_lifetime = 0 252 | session.cookie_path = / 253 | session.cookie_domain = 254 | session.cookie_httponly = 255 | session.serialize_handler = php 256 | session.gc_probability = 1 257 | session.gc_divisor = 100 258 | session.gc_maxlifetime = 1440 259 | session.bug_compat_42 = On 260 | session.bug_compat_warn = On 261 | session.referer_check = 262 | session.entropy_length = 0 263 | ;session.entropy_file = /dev/urandom 264 | session.entropy_file = 265 | ;session.entropy_length = 16 266 | session.cache_limiter = nocache 267 | session.cache_expire = 180 268 | session.use_trans_sid = 0 269 | session.hash_function = 0 270 | session.hash_bits_per_character = 4 271 | url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" 272 | 273 | [mbstring] 274 | ;mbstring.language = Japanese 275 | ;mbstring.internal_encoding = EUC-JP 276 | ;mbstring.http_input = auto 277 | ;mbstring.http_output = SJIS 278 | ;mbstring.encoding_translation = Off 279 | ;mbstring.detect_order = auto 280 | ;mbstring.substitute_character = none; 281 | ;mbstring.func_overload = 0 282 | ;mbstring.strict_detection = Off 283 | ;mbstring.http_output_conv_mimetype= 284 | ;mbstring.script_encoding= 285 | 286 | [gd] 287 | ;gd.jpeg_ignore_warning = 0 288 | 289 | [exif] 290 | ;exif.encode_unicode = ISO-8859-15 291 | ;exif.decode_unicode_motorola = UCS-2BE 292 | ;exif.decode_unicode_intel = UCS-2LE 293 | ;exif.encode_jis = 294 | ;exif.decode_jis_motorola = JIS 295 | ;exif.decode_jis_intel = JIS 296 | 297 | [soap] 298 | soap.wsdl_cache_enabled=1 299 | soap.wsdl_cache_dir="/tmp" 300 | soap.wsdl_cache_ttl=86400 301 | soap.wsdl_cache_limit = 5 302 | 303 | [sysvshm] 304 | ;sysvshm.init_mem = 10000 305 | 306 | [ldap] 307 | ldap.max_links = -1 308 | 309 | [mcrypt] 310 | ;mcrypt.algorithms_dir= 311 | ;mcrypt.modes_dir= 312 | -------------------------------------------------------------------------------- /files/root/etc/uci-defaults/luci-wifidog: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | uci -q batch <<-EOF >/dev/null 4 | delete ucitrack.@wifidog[-1] 5 | set ucitrack.wifidog="wifidog" 6 | set ucitrack.wifidog.exec='/etc/init.d/wifidog start' 7 | commit ucitrack 8 | EOF 9 | 10 | rm -f /tmp/luci-indexcache 11 | exit 0 12 | -------------------------------------------------------------------------------- /files/root/usr/lib/lua/luci/controller/wifidog.lua: -------------------------------------------------------------------------------- 1 | module("luci.controller.wifidog", package.seeall) 2 | 3 | 4 | function index() 5 | local fs = require "nixio.fs" 6 | if fs.access("/usr/bin/wifidog") then 7 | entry({"admin", "services","wifidog"}, cbi("wifidog"), "强制门户", 4) 8 | end 9 | 10 | end 11 | 12 | -------------------------------------------------------------------------------- /files/root/usr/lib/lua/luci/model/cbi/wifidog.lua: -------------------------------------------------------------------------------- 1 | local sys = require "luci.sys" 2 | local fs = require "nixio.fs" 3 | local uci = require "luci.model.uci".cursor() 4 | local wan_ifname = luci.util.exec("uci get network.wan.ifname") 5 | local lan_ifname = luci.util.exec("uci get network.lan.ifname") 6 | m = Map("wifidog", "强制门户", 7 | translate("强制门户是一种受限制的网络连接,所有客户端的HTTP请求都重定向到指定的站点")) 8 | 9 | if fs.access("/usr/bin/wifidog") then 10 | s = m:section(TypedSection, "settings", "认证站点配置") 11 | s.anonymous = true 12 | s.addremove = false 13 | s:tab("jbsz", translate("基本设置")) 14 | s:tab("bmd", translate("白名单")) 15 | s:tab("gjsz", translate("高级设置")) 16 | 17 | wifidog_enable = s:taboption("jbsz",Flag, "wifidog_enable", 18 | translate("启用认证"), 19 | translate("打开或关闭认证")) 20 | wifidog_enable.rmempty=false 21 | deamo_enable = s:taboption("jbsz",Flag, "deamo_enable", translate("守护进程"),"开启监护认证进程,保证认证进程时时在线") 22 | deamo_enable:depends("wifidog_enable","1") 23 | ssl_enable = s:taboption("gjsz",Flag, "ssl_enable", translate("加密传输"),"启用安全套接层协议传输,提高网络传输安全") 24 | sslport = s:taboption("gjsz",Value,"sslport","SSL传输端口号","默认443") 25 | sslport:depends("ssl_enable","1") 26 | gateway_interface = s:taboption("gjsz",Value,"gateway_interface","内网接口","设置内网接口,默认'br-lan'。") 27 | gateway_interface.default = "br-lan" 28 | gateway_interface:value(wan_ifname,wan_ifname .."" ) 29 | gateway_interface:value(lan_ifname,lan_ifname .. "") 30 | 31 | 32 | for _, e in ipairs(sys.net.devices()) do 33 | if e ~= "lo" then gateway_interface:value(e) end 34 | end 35 | 36 | gateway_host = s:taboption("jbsz",Value,"gateway_host","认证站点地址","域名或者IP") 37 | offline_enable = s:taboption("jbsz", Flag, "offline_enable", translate("启用离线认证"), "本地内建认证服务器") 38 | offline_enable.rmempty = false 39 | gateway_hostname = s:taboption("jbsz",Value,"gateway_hostname","认证站点名称","显示在标题栏上的内容") 40 | gateway_hostname:depends("offline_enable", "1") 41 | gatewayport = s:taboption("gjsz",Value,"gatewayport","认证网关端口号","默认端口号2060") 42 | gateway_httpport = s:taboption("gjsz",Value,"gateway_httpport","HTTP端口号","默认80端口") 43 | gateway_path = s:taboption("gjsz",Value,"gateway_path","认证服务器路径","最后要加/,例如:'/','/wifidog/'") 44 | gateway_connmax = s:taboption("gjsz",Value,"gateway_connmax","最大用户接入数量","以路由器性能而定,默认50") 45 | gateway_connmax.default = "50" 46 | check_interval = s:taboption("gjsz",Value,"check_interval","检查间隔","接入客户端在线检测间隔,默认60秒") 47 | check_interval.default = "60" 48 | client_timeout = s:taboption("gjsz",Value,"client_timeout","客户端超时","接入客户端认证超时,默认5分") 49 | client_timeout.default = "5" 50 | client_time_limit = s:taboption("gjsz",Value,"client_time_limit","客户端限额","接入客户端限制使用时间,默认60分") 51 | client_time_limit.default = "60" 52 | client_time_limit:depends("offline_enable", "1") 53 | --[白名单]-- 54 | bmd_url=s:taboption("bmd",Value,"bmd_url","网站URL白名单","url不认证也能打开,不能带”http://“多个URL请用”,“号隔开。如:“www.baidu.com,www.qq.com”") 55 | myz_mac=s:taboption("bmd",Value,"myz_mac","免认证设备","填入设备的MAC地址,多个设备请用“,”号隔开。如:“11:22:33:44:55:66,aa:bb:cc:dd:ff:00”") 56 | 57 | 58 | else 59 | m.pageaction = false 60 | end 61 | 62 | 63 | return m 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Environment.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim; 34 | 35 | /** 36 | * Environment 37 | * 38 | * This class creates and returns a key/value array of common 39 | * environment variables for the current HTTP request. 40 | * 41 | * This is a singleton class; derived environment variables will 42 | * be common across multiple Slim applications. 43 | * 44 | * This class matches the Rack (Ruby) specification as closely 45 | * as possible. More information available below. 46 | * 47 | * @package Slim 48 | * @author Josh Lockhart 49 | * @since 1.6.0 50 | */ 51 | class Environment implements \ArrayAccess, \IteratorAggregate 52 | { 53 | /** 54 | * @var array 55 | */ 56 | protected $properties; 57 | 58 | /** 59 | * @var \Slim\Environment 60 | */ 61 | protected static $environment; 62 | 63 | /** 64 | * Get environment instance (singleton) 65 | * 66 | * This creates and/or returns an environment instance (singleton) 67 | * derived from $_SERVER variables. You may override the global server 68 | * variables by using `\Slim\Environment::mock()` instead. 69 | * 70 | * @param bool $refresh Refresh properties using global server variables? 71 | * @return \Slim\Environment 72 | */ 73 | public static function getInstance($refresh = false) 74 | { 75 | if (is_null(self::$environment) || $refresh) { 76 | self::$environment = new self(); 77 | } 78 | 79 | return self::$environment; 80 | } 81 | 82 | /** 83 | * Get mock environment instance 84 | * 85 | * @param array $userSettings 86 | * @return \Slim\Environment 87 | */ 88 | public static function mock($userSettings = array()) 89 | { 90 | $defaults = array( 91 | 'REQUEST_METHOD' => 'GET', 92 | 'SCRIPT_NAME' => '', 93 | 'PATH_INFO' => '', 94 | 'QUERY_STRING' => '', 95 | 'SERVER_NAME' => 'localhost', 96 | 'SERVER_PORT' => 80, 97 | 'ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 98 | 'ACCEPT_LANGUAGE' => 'en-US,en;q=0.8', 99 | 'ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 100 | 'USER_AGENT' => 'Slim Framework', 101 | 'REMOTE_ADDR' => '127.0.0.1', 102 | 'slim.url_scheme' => 'http', 103 | 'slim.input' => '', 104 | 'slim.errors' => @fopen('php://stderr', 'w') 105 | ); 106 | self::$environment = new self(array_merge($defaults, $userSettings)); 107 | 108 | return self::$environment; 109 | } 110 | 111 | /** 112 | * Constructor (private access) 113 | * 114 | * @param array|null $settings If present, these are used instead of global server variables 115 | */ 116 | private function __construct($settings = null) 117 | { 118 | if ($settings) { 119 | $this->properties = $settings; 120 | } else { 121 | $env = array(); 122 | 123 | //The HTTP request method 124 | $env['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD']; 125 | 126 | //The IP 127 | $env['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR']; 128 | 129 | // Server params 130 | $scriptName = $_SERVER['SCRIPT_NAME']; // <-- "/foo/index.php" 131 | $requestUri = $_SERVER['REQUEST_URI']; // <-- "/foo/bar?test=abc" or "/foo/index.php/bar?test=abc" 132 | $slice = explode('?', $requestUri, 2); 133 | $queryString = ''; 134 | 135 | if (count($slice) == 2) { 136 | $queryString = $slice[1]; 137 | } 138 | 139 | // fix with lighttpd 140 | // $queryString = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : $queryString; // <-- "test=abc" or "" 141 | 142 | // Physical path 143 | if (strpos($requestUri, $scriptName) !== false) { 144 | $physicalPath = $scriptName; // <-- Without rewriting 145 | } else { 146 | $physicalPath = str_replace('\\', '', dirname($scriptName)); // <-- With rewriting 147 | } 148 | $env['SCRIPT_NAME'] = rtrim($physicalPath, '/'); // <-- Remove trailing slashes 149 | 150 | // Virtual path 151 | $env['PATH_INFO'] = substr_replace($requestUri, '', 0, strlen($physicalPath)); // <-- Remove physical path 152 | $env['PATH_INFO'] = str_replace('?' . $queryString, '', $env['PATH_INFO']); // <-- Remove query string 153 | $env['PATH_INFO'] = '/' . trim($env['PATH_INFO'], '/'); // <-- Ensure leading slash 154 | 155 | // Query string (without leading "?") 156 | $env['QUERY_STRING'] = $queryString; 157 | 158 | //Name of server host that is running the script 159 | $env['SERVER_NAME'] = $_SERVER['SERVER_NAME']; 160 | 161 | //Number of server port that is running the script 162 | $env['SERVER_PORT'] = $_SERVER['SERVER_PORT']; 163 | 164 | //HTTP request headers (retains HTTP_ prefix to match $_SERVER) 165 | $headers = \Slim\Http\Headers::extract($_SERVER); 166 | foreach ($headers as $key => $value) { 167 | $env[$key] = $value; 168 | } 169 | 170 | //Is the application running under HTTPS or HTTP protocol? 171 | $env['slim.url_scheme'] = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off' ? 'http' : 'https'; 172 | 173 | //Input stream (readable one time only; not available for multipart/form-data requests) 174 | $rawInput = @file_get_contents('php://input'); 175 | if (!$rawInput) { 176 | $rawInput = ''; 177 | } 178 | $env['slim.input'] = $rawInput; 179 | 180 | //Error stream 181 | $env['slim.errors'] = @fopen('php://stderr', 'w'); 182 | 183 | $this->properties = $env; 184 | } 185 | } 186 | 187 | /** 188 | * Array Access: Offset Exists 189 | */ 190 | public function offsetExists($offset) 191 | { 192 | return isset($this->properties[$offset]); 193 | } 194 | 195 | /** 196 | * Array Access: Offset Get 197 | */ 198 | public function offsetGet($offset) 199 | { 200 | if (isset($this->properties[$offset])) { 201 | return $this->properties[$offset]; 202 | } else { 203 | return null; 204 | } 205 | } 206 | 207 | /** 208 | * Array Access: Offset Set 209 | */ 210 | public function offsetSet($offset, $value) 211 | { 212 | $this->properties[$offset] = $value; 213 | } 214 | 215 | /** 216 | * Array Access: Offset Unset 217 | */ 218 | public function offsetUnset($offset) 219 | { 220 | unset($this->properties[$offset]); 221 | } 222 | 223 | /** 224 | * IteratorAggregate 225 | * 226 | * @return \ArrayIterator 227 | */ 228 | public function getIterator() 229 | { 230 | return new \ArrayIterator($this->properties); 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Exception/Pass.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Exception; 34 | 35 | /** 36 | * Pass Exception 37 | * 38 | * This Exception will cause the Router::dispatch method 39 | * to skip the current matching route and continue to the next 40 | * matching route. If no subsequent routes are found, a 41 | * HTTP 404 Not Found response will be sent to the client. 42 | * 43 | * @package Slim 44 | * @author Josh Lockhart 45 | * @since 1.0.0 46 | */ 47 | class Pass extends \Exception 48 | { 49 | } 50 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Exception/Stop.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Exception; 34 | 35 | /** 36 | * Stop Exception 37 | * 38 | * This Exception is thrown when the Slim application needs to abort 39 | * processing and return control flow to the outer PHP script. 40 | * 41 | * @package Slim 42 | * @author Josh Lockhart 43 | * @since 1.0.0 44 | */ 45 | class Stop extends \Exception 46 | { 47 | } 48 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Helper/Set.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Helper; 34 | 35 | class Set implements \ArrayAccess, \Countable, \IteratorAggregate 36 | { 37 | /** 38 | * Key-value array of arbitrary data 39 | * @var array 40 | */ 41 | protected $data = array(); 42 | 43 | /** 44 | * Constructor 45 | * @param array $items Pre-populate set with this key-value array 46 | */ 47 | public function __construct($items = array()) 48 | { 49 | $this->replace($items); 50 | } 51 | 52 | /** 53 | * Normalize data key 54 | * 55 | * Used to transform data key into the necessary 56 | * key format for this set. Used in subclasses 57 | * like \Slim\Http\Headers. 58 | * 59 | * @param string $key The data key 60 | * @return mixed The transformed/normalized data key 61 | */ 62 | protected function normalizeKey($key) 63 | { 64 | return $key; 65 | } 66 | 67 | /** 68 | * Set data key to value 69 | * @param string $key The data key 70 | * @param mixed $value The data value 71 | */ 72 | public function set($key, $value) 73 | { 74 | $this->data[$this->normalizeKey($key)] = $value; 75 | } 76 | 77 | /** 78 | * Get data value with key 79 | * @param string $key The data key 80 | * @param mixed $default The value to return if data key does not exist 81 | * @return mixed The data value, or the default value 82 | */ 83 | public function get($key, $default = null) 84 | { 85 | if ($this->has($key)) { 86 | $isInvokable = is_object($this->data[$this->normalizeKey($key)]) && method_exists($this->data[$this->normalizeKey($key)], '__invoke'); 87 | 88 | return $isInvokable ? $this->data[$this->normalizeKey($key)]($this) : $this->data[$this->normalizeKey($key)]; 89 | } 90 | 91 | return $default; 92 | } 93 | 94 | /** 95 | * Add data to set 96 | * @param array $items Key-value array of data to append to this set 97 | */ 98 | public function replace($items) 99 | { 100 | foreach ($items as $key => $value) { 101 | $this->set($key, $value); // Ensure keys are normalized 102 | } 103 | } 104 | 105 | /** 106 | * Fetch set data 107 | * @return array This set's key-value data array 108 | */ 109 | public function all() 110 | { 111 | return $this->data; 112 | } 113 | 114 | /** 115 | * Fetch set data keys 116 | * @return array This set's key-value data array keys 117 | */ 118 | public function keys() 119 | { 120 | return array_keys($this->data); 121 | } 122 | 123 | /** 124 | * Does this set contain a key? 125 | * @param string $key The data key 126 | * @return boolean 127 | */ 128 | public function has($key) 129 | { 130 | return array_key_exists($this->normalizeKey($key), $this->data); 131 | } 132 | 133 | /** 134 | * Remove value with key from this set 135 | * @param string $key The data key 136 | */ 137 | public function remove($key) 138 | { 139 | unset($this->data[$this->normalizeKey($key)]); 140 | } 141 | 142 | /** 143 | * Property Overloading 144 | */ 145 | 146 | public function __get($key) 147 | { 148 | return $this->get($key); 149 | } 150 | 151 | public function __set($key, $value) 152 | { 153 | $this->set($key, $value); 154 | } 155 | 156 | public function __isset($key) 157 | { 158 | return $this->has($key); 159 | } 160 | 161 | public function __unset($key) 162 | { 163 | return $this->remove($key); 164 | } 165 | 166 | /** 167 | * Clear all values 168 | */ 169 | public function clear() 170 | { 171 | $this->data = array(); 172 | } 173 | 174 | /** 175 | * Array Access 176 | */ 177 | 178 | public function offsetExists($offset) 179 | { 180 | return $this->has($offset); 181 | } 182 | 183 | public function offsetGet($offset) 184 | { 185 | return $this->get($offset); 186 | } 187 | 188 | public function offsetSet($offset, $value) 189 | { 190 | $this->set($offset, $value); 191 | } 192 | 193 | public function offsetUnset($offset) 194 | { 195 | $this->remove($offset); 196 | } 197 | 198 | /** 199 | * Countable 200 | */ 201 | 202 | public function count() 203 | { 204 | return count($this->data); 205 | } 206 | 207 | /** 208 | * IteratorAggregate 209 | */ 210 | 211 | public function getIterator() 212 | { 213 | return new \ArrayIterator($this->data); 214 | } 215 | 216 | /** 217 | * Ensure a value or object will remain globally unique 218 | * @param string $key The value or object name 219 | * @param Closure The closure that defines the object 220 | * @return mixed 221 | */ 222 | public function singleton($key, $value) 223 | { 224 | $this->set($key, function ($c) use ($value) { 225 | static $object; 226 | 227 | if (null === $object) { 228 | $object = $value($c); 229 | } 230 | 231 | return $object; 232 | }); 233 | } 234 | 235 | /** 236 | * Protect closure from being directly invoked 237 | * @param Closure $callable A closure to keep from being invoked and evaluated 238 | * @return Closure 239 | */ 240 | public function protect(\Closure $callable) 241 | { 242 | return function () use ($callable) { 243 | return $callable; 244 | }; 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Http/Cookies.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Http; 34 | 35 | class Cookies extends \Slim\Helper\Set 36 | { 37 | /** 38 | * Default cookie settings 39 | * @var array 40 | */ 41 | protected $defaults = array( 42 | 'value' => '', 43 | 'domain' => null, 44 | 'path' => null, 45 | 'expires' => null, 46 | 'secure' => false, 47 | 'httponly' => false 48 | ); 49 | 50 | /** 51 | * Set cookie 52 | * 53 | * The second argument may be a single scalar value, in which case 54 | * it will be merged with the default settings and considered the `value` 55 | * of the merged result. 56 | * 57 | * The second argument may also be an array containing any or all of 58 | * the keys shown in the default settings above. This array will be 59 | * merged with the defaults shown above. 60 | * 61 | * @param string $key Cookie name 62 | * @param mixed $value Cookie settings 63 | */ 64 | public function set($key, $value) 65 | { 66 | if (is_array($value)) { 67 | $cookieSettings = array_replace($this->defaults, $value); 68 | } else { 69 | $cookieSettings = array_replace($this->defaults, array('value' => $value)); 70 | } 71 | parent::set($key, $cookieSettings); 72 | } 73 | 74 | /** 75 | * Remove cookie 76 | * 77 | * Unlike \Slim\Helper\Set, this will actually *set* a cookie with 78 | * an expiration date in the past. This expiration date will force 79 | * the client-side cache to remove its cookie with the given name 80 | * and settings. 81 | * 82 | * @param string $key Cookie name 83 | * @param array $settings Optional cookie settings 84 | */ 85 | public function remove($key, $settings = array()) 86 | { 87 | $settings['value'] = ''; 88 | $settings['expires'] = time() - 86400; 89 | $this->set($key, array_replace($this->defaults, $settings)); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Http/Headers.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Http; 34 | 35 | /** 36 | * HTTP Headers 37 | * 38 | * @package Slim 39 | * @author Josh Lockhart 40 | * @since 1.6.0 41 | */ 42 | class Headers extends \Slim\Helper\Set 43 | { 44 | /******************************************************************************** 45 | * Static interface 46 | *******************************************************************************/ 47 | 48 | /** 49 | * Special-case HTTP headers that are otherwise unidentifiable as HTTP headers. 50 | * Typically, HTTP headers in the $_SERVER array will be prefixed with 51 | * `HTTP_` or `X_`. These are not so we list them here for later reference. 52 | * 53 | * @var array 54 | */ 55 | protected static $special = array( 56 | 'CONTENT_TYPE', 57 | 'CONTENT_LENGTH', 58 | 'PHP_AUTH_USER', 59 | 'PHP_AUTH_PW', 60 | 'PHP_AUTH_DIGEST', 61 | 'AUTH_TYPE' 62 | ); 63 | 64 | /** 65 | * Extract HTTP headers from an array of data (e.g. $_SERVER) 66 | * @param array $data 67 | * @return array 68 | */ 69 | public static function extract($data) 70 | { 71 | $results = array(); 72 | foreach ($data as $key => $value) { 73 | $key = strtoupper($key); 74 | if (strpos($key, 'X_') === 0 || strpos($key, 'HTTP_') === 0 || in_array($key, static::$special)) { 75 | if ($key === 'HTTP_CONTENT_LENGTH') { 76 | continue; 77 | } 78 | $results[$key] = $value; 79 | } 80 | } 81 | 82 | return $results; 83 | } 84 | 85 | /******************************************************************************** 86 | * Instance interface 87 | *******************************************************************************/ 88 | 89 | /** 90 | * Transform header name into canonical form 91 | * @param string $key 92 | * @return string 93 | */ 94 | protected function normalizeKey($key) 95 | { 96 | $key = strtolower($key); 97 | $key = str_replace(array('-', '_'), ' ', $key); 98 | $key = preg_replace('#^http #', '', $key); 99 | $key = ucwords($key); 100 | $key = str_replace(' ', '-', $key); 101 | 102 | return $key; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Http/Request.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Http; 34 | 35 | /** 36 | * Slim HTTP Request 37 | * 38 | * This class provides a human-friendly interface to the Slim environment variables; 39 | * environment variables are passed by reference and will be modified directly. 40 | * 41 | * @package Slim 42 | * @author Josh Lockhart 43 | * @since 1.0.0 44 | */ 45 | class Request 46 | { 47 | const METHOD_HEAD = 'HEAD'; 48 | const METHOD_GET = 'GET'; 49 | const METHOD_POST = 'POST'; 50 | const METHOD_PUT = 'PUT'; 51 | const METHOD_PATCH = 'PATCH'; 52 | const METHOD_DELETE = 'DELETE'; 53 | const METHOD_OPTIONS = 'OPTIONS'; 54 | const METHOD_OVERRIDE = '_METHOD'; 55 | 56 | /** 57 | * @var array 58 | */ 59 | protected static $formDataMediaTypes = array('application/x-www-form-urlencoded'); 60 | 61 | /** 62 | * Application Environment 63 | * @var \Slim\Environment 64 | */ 65 | protected $env; 66 | 67 | /** 68 | * HTTP Headers 69 | * @var \Slim\Http\Headers 70 | */ 71 | public $headers; 72 | 73 | /** 74 | * HTTP Cookies 75 | * @var \Slim\Helper\Set 76 | */ 77 | public $cookies; 78 | 79 | /** 80 | * Constructor 81 | * @param \Slim\Environment $env 82 | */ 83 | public function __construct(\Slim\Environment $env) 84 | { 85 | $this->env = $env; 86 | $this->headers = new \Slim\Http\Headers(\Slim\Http\Headers::extract($env)); 87 | $this->cookies = new \Slim\Helper\Set(\Slim\Http\Util::parseCookieHeader($env['HTTP_COOKIE'])); 88 | } 89 | 90 | /** 91 | * Get HTTP method 92 | * @return string 93 | */ 94 | public function getMethod() 95 | { 96 | return $this->env['REQUEST_METHOD']; 97 | } 98 | 99 | /** 100 | * Is this a GET request? 101 | * @return bool 102 | */ 103 | public function isGet() 104 | { 105 | return $this->getMethod() === self::METHOD_GET; 106 | } 107 | 108 | /** 109 | * Is this a POST request? 110 | * @return bool 111 | */ 112 | public function isPost() 113 | { 114 | return $this->getMethod() === self::METHOD_POST; 115 | } 116 | 117 | /** 118 | * Is this a PUT request? 119 | * @return bool 120 | */ 121 | public function isPut() 122 | { 123 | return $this->getMethod() === self::METHOD_PUT; 124 | } 125 | 126 | /** 127 | * Is this a PATCH request? 128 | * @return bool 129 | */ 130 | public function isPatch() 131 | { 132 | return $this->getMethod() === self::METHOD_PATCH; 133 | } 134 | 135 | /** 136 | * Is this a DELETE request? 137 | * @return bool 138 | */ 139 | public function isDelete() 140 | { 141 | return $this->getMethod() === self::METHOD_DELETE; 142 | } 143 | 144 | /** 145 | * Is this a HEAD request? 146 | * @return bool 147 | */ 148 | public function isHead() 149 | { 150 | return $this->getMethod() === self::METHOD_HEAD; 151 | } 152 | 153 | /** 154 | * Is this a OPTIONS request? 155 | * @return bool 156 | */ 157 | public function isOptions() 158 | { 159 | return $this->getMethod() === self::METHOD_OPTIONS; 160 | } 161 | 162 | /** 163 | * Is this an AJAX request? 164 | * @return bool 165 | */ 166 | public function isAjax() 167 | { 168 | if ($this->params('isajax')) { 169 | return true; 170 | } elseif (isset($this->headers['X_REQUESTED_WITH']) && $this->headers['X_REQUESTED_WITH'] === 'XMLHttpRequest') { 171 | return true; 172 | } else { 173 | return false; 174 | } 175 | } 176 | 177 | /** 178 | * Is this an XHR request? (alias of Slim_Http_Request::isAjax) 179 | * @return bool 180 | */ 181 | public function isXhr() 182 | { 183 | return $this->isAjax(); 184 | } 185 | 186 | /** 187 | * Fetch GET and POST data 188 | * 189 | * This method returns a union of GET and POST data as a key-value array, or the value 190 | * of the array key if requested; if the array key does not exist, NULL is returned, 191 | * unless there is a default value specified. 192 | * 193 | * @param string $key 194 | * @param mixed $default 195 | * @return array|mixed|null 196 | */ 197 | public function params($key = null, $default = null) 198 | { 199 | $union = array_merge($this->get(), $this->post()); 200 | if ($key) { 201 | return isset($union[$key]) ? $union[$key] : $default; 202 | } 203 | 204 | return $union; 205 | } 206 | 207 | /** 208 | * Fetch GET data 209 | * 210 | * This method returns a key-value array of data sent in the HTTP request query string, or 211 | * the value of the array key if requested; if the array key does not exist, NULL is returned. 212 | * 213 | * @param string $key 214 | * @param mixed $default Default return value when key does not exist 215 | * @return array|mixed|null 216 | */ 217 | public function get($key = null, $default = null) 218 | { 219 | if (!isset($this->env['slim.request.query_hash'])) { 220 | $output = array(); 221 | if (function_exists('mb_parse_str') && !isset($this->env['slim.tests.ignore_multibyte'])) { 222 | mb_parse_str($this->env['QUERY_STRING'], $output); 223 | } else { 224 | parse_str($this->env['QUERY_STRING'], $output); 225 | } 226 | $this->env['slim.request.query_hash'] = Util::stripSlashesIfMagicQuotes($output); 227 | } 228 | if ($key) { 229 | if (isset($this->env['slim.request.query_hash'][$key])) { 230 | return $this->env['slim.request.query_hash'][$key]; 231 | } else { 232 | return $default; 233 | } 234 | } else { 235 | return $this->env['slim.request.query_hash']; 236 | } 237 | } 238 | 239 | /** 240 | * Fetch POST data 241 | * 242 | * This method returns a key-value array of data sent in the HTTP request body, or 243 | * the value of a hash key if requested; if the array key does not exist, NULL is returned. 244 | * 245 | * @param string $key 246 | * @param mixed $default Default return value when key does not exist 247 | * @return array|mixed|null 248 | * @throws \RuntimeException If environment input is not available 249 | */ 250 | public function post($key = null, $default = null) 251 | { 252 | if (!isset($this->env['slim.input'])) { 253 | throw new \RuntimeException('Missing slim.input in environment variables'); 254 | } 255 | if (!isset($this->env['slim.request.form_hash'])) { 256 | $this->env['slim.request.form_hash'] = array(); 257 | if ($this->isFormData() && is_string($this->env['slim.input'])) { 258 | $output = array(); 259 | if (function_exists('mb_parse_str') && !isset($this->env['slim.tests.ignore_multibyte'])) { 260 | mb_parse_str($this->env['slim.input'], $output); 261 | } else { 262 | parse_str($this->env['slim.input'], $output); 263 | } 264 | $this->env['slim.request.form_hash'] = Util::stripSlashesIfMagicQuotes($output); 265 | } else { 266 | $this->env['slim.request.form_hash'] = Util::stripSlashesIfMagicQuotes($_POST); 267 | } 268 | } 269 | if ($key) { 270 | if (isset($this->env['slim.request.form_hash'][$key])) { 271 | return $this->env['slim.request.form_hash'][$key]; 272 | } else { 273 | return $default; 274 | } 275 | } else { 276 | return $this->env['slim.request.form_hash']; 277 | } 278 | } 279 | 280 | /** 281 | * Fetch PUT data (alias for \Slim\Http\Request::post) 282 | * @param string $key 283 | * @param mixed $default Default return value when key does not exist 284 | * @return array|mixed|null 285 | */ 286 | public function put($key = null, $default = null) 287 | { 288 | return $this->post($key, $default); 289 | } 290 | 291 | /** 292 | * Fetch PATCH data (alias for \Slim\Http\Request::post) 293 | * @param string $key 294 | * @param mixed $default Default return value when key does not exist 295 | * @return array|mixed|null 296 | */ 297 | public function patch($key = null, $default = null) 298 | { 299 | return $this->post($key, $default); 300 | } 301 | 302 | /** 303 | * Fetch DELETE data (alias for \Slim\Http\Request::post) 304 | * @param string $key 305 | * @param mixed $default Default return value when key does not exist 306 | * @return array|mixed|null 307 | */ 308 | public function delete($key = null, $default = null) 309 | { 310 | return $this->post($key, $default); 311 | } 312 | 313 | /** 314 | * Fetch COOKIE data 315 | * 316 | * This method returns a key-value array of Cookie data sent in the HTTP request, or 317 | * the value of a array key if requested; if the array key does not exist, NULL is returned. 318 | * 319 | * @param string $key 320 | * @return array|string|null 321 | */ 322 | public function cookies($key = null) 323 | { 324 | if ($key) { 325 | return $this->cookies->get($key); 326 | } 327 | 328 | return $this->cookies; 329 | // if (!isset($this->env['slim.request.cookie_hash'])) { 330 | // $cookieHeader = isset($this->env['COOKIE']) ? $this->env['COOKIE'] : ''; 331 | // $this->env['slim.request.cookie_hash'] = Util::parseCookieHeader($cookieHeader); 332 | // } 333 | // if ($key) { 334 | // if (isset($this->env['slim.request.cookie_hash'][$key])) { 335 | // return $this->env['slim.request.cookie_hash'][$key]; 336 | // } else { 337 | // return null; 338 | // } 339 | // } else { 340 | // return $this->env['slim.request.cookie_hash']; 341 | // } 342 | } 343 | 344 | /** 345 | * Does the Request body contain parsed form data? 346 | * @return bool 347 | */ 348 | public function isFormData() 349 | { 350 | $method = isset($this->env['slim.method_override.original_method']) ? $this->env['slim.method_override.original_method'] : $this->getMethod(); 351 | 352 | return ($method === self::METHOD_POST && is_null($this->getContentType())) || in_array($this->getMediaType(), self::$formDataMediaTypes); 353 | } 354 | 355 | /** 356 | * Get Headers 357 | * 358 | * This method returns a key-value array of headers sent in the HTTP request, or 359 | * the value of a hash key if requested; if the array key does not exist, NULL is returned. 360 | * 361 | * @param string $key 362 | * @param mixed $default The default value returned if the requested header is not available 363 | * @return mixed 364 | */ 365 | public function headers($key = null, $default = null) 366 | { 367 | if ($key) { 368 | return $this->headers->get($key, $default); 369 | } 370 | 371 | return $this->headers; 372 | // if ($key) { 373 | // $key = strtoupper($key); 374 | // $key = str_replace('-', '_', $key); 375 | // $key = preg_replace('@^HTTP_@', '', $key); 376 | // if (isset($this->env[$key])) { 377 | // return $this->env[$key]; 378 | // } else { 379 | // return $default; 380 | // } 381 | // } else { 382 | // $headers = array(); 383 | // foreach ($this->env as $key => $value) { 384 | // if (strpos($key, 'slim.') !== 0) { 385 | // $headers[$key] = $value; 386 | // } 387 | // } 388 | // 389 | // return $headers; 390 | // } 391 | } 392 | 393 | /** 394 | * Get Body 395 | * @return string 396 | */ 397 | public function getBody() 398 | { 399 | return $this->env['slim.input']; 400 | } 401 | 402 | /** 403 | * Get Content Type 404 | * @return string|null 405 | */ 406 | public function getContentType() 407 | { 408 | return $this->headers->get('CONTENT_TYPE'); 409 | } 410 | 411 | /** 412 | * Get Media Type (type/subtype within Content Type header) 413 | * @return string|null 414 | */ 415 | public function getMediaType() 416 | { 417 | $contentType = $this->getContentType(); 418 | if ($contentType) { 419 | $contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType); 420 | 421 | return strtolower($contentTypeParts[0]); 422 | } 423 | 424 | return null; 425 | } 426 | 427 | /** 428 | * Get Media Type Params 429 | * @return array 430 | */ 431 | public function getMediaTypeParams() 432 | { 433 | $contentType = $this->getContentType(); 434 | $contentTypeParams = array(); 435 | if ($contentType) { 436 | $contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType); 437 | $contentTypePartsLength = count($contentTypeParts); 438 | for ($i = 1; $i < $contentTypePartsLength; $i++) { 439 | $paramParts = explode('=', $contentTypeParts[$i]); 440 | $contentTypeParams[strtolower($paramParts[0])] = $paramParts[1]; 441 | } 442 | } 443 | 444 | return $contentTypeParams; 445 | } 446 | 447 | /** 448 | * Get Content Charset 449 | * @return string|null 450 | */ 451 | public function getContentCharset() 452 | { 453 | $mediaTypeParams = $this->getMediaTypeParams(); 454 | if (isset($mediaTypeParams['charset'])) { 455 | return $mediaTypeParams['charset']; 456 | } 457 | 458 | return null; 459 | } 460 | 461 | /** 462 | * Get Content-Length 463 | * @return int 464 | */ 465 | public function getContentLength() 466 | { 467 | return $this->headers->get('CONTENT_LENGTH', 0); 468 | } 469 | 470 | /** 471 | * Get Host 472 | * @return string 473 | */ 474 | public function getHost() 475 | { 476 | if (isset($this->env['HTTP_HOST'])) { 477 | if (strpos($this->env['HTTP_HOST'], ':') !== false) { 478 | $hostParts = explode(':', $this->env['HTTP_HOST']); 479 | 480 | return $hostParts[0]; 481 | } 482 | 483 | return $this->env['HTTP_HOST']; 484 | } 485 | 486 | return $this->env['SERVER_NAME']; 487 | } 488 | 489 | /** 490 | * Get Host with Port 491 | * @return string 492 | */ 493 | public function getHostWithPort() 494 | { 495 | return sprintf('%s:%s', $this->getHost(), $this->getPort()); 496 | } 497 | 498 | /** 499 | * Get Port 500 | * @return int 501 | */ 502 | public function getPort() 503 | { 504 | return (int)$this->env['SERVER_PORT']; 505 | } 506 | 507 | /** 508 | * Get Scheme (https or http) 509 | * @return string 510 | */ 511 | public function getScheme() 512 | { 513 | return $this->env['slim.url_scheme']; 514 | } 515 | 516 | /** 517 | * Get Script Name (physical path) 518 | * @return string 519 | */ 520 | public function getScriptName() 521 | { 522 | return $this->env['SCRIPT_NAME']; 523 | } 524 | 525 | /** 526 | * LEGACY: Get Root URI (alias for Slim_Http_Request::getScriptName) 527 | * @return string 528 | */ 529 | public function getRootUri() 530 | { 531 | return $this->getScriptName(); 532 | } 533 | 534 | /** 535 | * Get Path (physical path + virtual path) 536 | * @return string 537 | */ 538 | public function getPath() 539 | { 540 | return $this->getScriptName() . $this->getPathInfo(); 541 | } 542 | 543 | /** 544 | * Get Path Info (virtual path) 545 | * @return string 546 | */ 547 | public function getPathInfo() 548 | { 549 | return $this->env['PATH_INFO']; 550 | } 551 | 552 | /** 553 | * LEGACY: Get Resource URI (alias for Slim_Http_Request::getPathInfo) 554 | * @return string 555 | */ 556 | public function getResourceUri() 557 | { 558 | return $this->getPathInfo(); 559 | } 560 | 561 | /** 562 | * Get URL (scheme + host [ + port if non-standard ]) 563 | * @return string 564 | */ 565 | public function getUrl() 566 | { 567 | $url = $this->getScheme() . '://' . $this->getHost(); 568 | if (($this->getScheme() === 'https' && $this->getPort() !== 443) || ($this->getScheme() === 'http' && $this->getPort() !== 80)) { 569 | $url .= sprintf(':%s', $this->getPort()); 570 | } 571 | 572 | return $url; 573 | } 574 | 575 | /** 576 | * Get IP 577 | * @return string 578 | */ 579 | public function getIp() 580 | { 581 | $keys = array('X_FORWARDED_FOR', 'HTTP_X_FORWARDED_FOR', 'CLIENT_IP', 'REMOTE_ADDR'); 582 | foreach ($keys as $key) { 583 | if (isset($this->env[$key])) { 584 | return $this->env[$key]; 585 | } 586 | } 587 | 588 | return $this->env['REMOTE_ADDR']; 589 | } 590 | 591 | /** 592 | * Get Referrer 593 | * @return string|null 594 | */ 595 | public function getReferrer() 596 | { 597 | return $this->headers->get('HTTP_REFERER'); 598 | } 599 | 600 | /** 601 | * Get Referer (for those who can't spell) 602 | * @return string|null 603 | */ 604 | public function getReferer() 605 | { 606 | return $this->getReferrer(); 607 | } 608 | 609 | /** 610 | * Get User Agent 611 | * @return string|null 612 | */ 613 | public function getUserAgent() 614 | { 615 | return $this->headers->get('HTTP_USER_AGENT'); 616 | } 617 | } 618 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Http/Response.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Http; 34 | 35 | /** 36 | * Response 37 | * 38 | * This is a simple abstraction over top an HTTP response. This 39 | * provides methods to set the HTTP status, the HTTP headers, 40 | * and the HTTP body. 41 | * 42 | * @package Slim 43 | * @author Josh Lockhart 44 | * @since 1.0.0 45 | */ 46 | class Response implements \ArrayAccess, \Countable, \IteratorAggregate 47 | { 48 | /** 49 | * @var int HTTP status code 50 | */ 51 | protected $status; 52 | 53 | /** 54 | * @var \Slim\Http\Headers 55 | */ 56 | public $headers; 57 | 58 | /** 59 | * @var \Slim\Http\Cookies 60 | */ 61 | public $cookies; 62 | 63 | /** 64 | * @var string HTTP response body 65 | */ 66 | protected $body; 67 | 68 | /** 69 | * @var int Length of HTTP response body 70 | */ 71 | protected $length; 72 | 73 | /** 74 | * @var array HTTP response codes and messages 75 | */ 76 | protected static $messages = array( 77 | //Informational 1xx 78 | 100 => '100 Continue', 79 | 101 => '101 Switching Protocols', 80 | //Successful 2xx 81 | 200 => '200 OK', 82 | 201 => '201 Created', 83 | 202 => '202 Accepted', 84 | 203 => '203 Non-Authoritative Information', 85 | 204 => '204 No Content', 86 | 205 => '205 Reset Content', 87 | 206 => '206 Partial Content', 88 | //Redirection 3xx 89 | 300 => '300 Multiple Choices', 90 | 301 => '301 Moved Permanently', 91 | 302 => '302 Found', 92 | 303 => '303 See Other', 93 | 304 => '304 Not Modified', 94 | 305 => '305 Use Proxy', 95 | 306 => '306 (Unused)', 96 | 307 => '307 Temporary Redirect', 97 | //Client Error 4xx 98 | 400 => '400 Bad Request', 99 | 401 => '401 Unauthorized', 100 | 402 => '402 Payment Required', 101 | 403 => '403 Forbidden', 102 | 404 => '404 Not Found', 103 | 405 => '405 Method Not Allowed', 104 | 406 => '406 Not Acceptable', 105 | 407 => '407 Proxy Authentication Required', 106 | 408 => '408 Request Timeout', 107 | 409 => '409 Conflict', 108 | 410 => '410 Gone', 109 | 411 => '411 Length Required', 110 | 412 => '412 Precondition Failed', 111 | 413 => '413 Request Entity Too Large', 112 | 414 => '414 Request-URI Too Long', 113 | 415 => '415 Unsupported Media Type', 114 | 416 => '416 Requested Range Not Satisfiable', 115 | 417 => '417 Expectation Failed', 116 | 418 => '418 I\'m a teapot', 117 | 422 => '422 Unprocessable Entity', 118 | 423 => '423 Locked', 119 | //Server Error 5xx 120 | 500 => '500 Internal Server Error', 121 | 501 => '501 Not Implemented', 122 | 502 => '502 Bad Gateway', 123 | 503 => '503 Service Unavailable', 124 | 504 => '504 Gateway Timeout', 125 | 505 => '505 HTTP Version Not Supported' 126 | ); 127 | 128 | /** 129 | * Constructor 130 | * @param string $body The HTTP response body 131 | * @param int $status The HTTP response status 132 | * @param \Slim\Http\Headers|array $headers The HTTP response headers 133 | */ 134 | public function __construct($body = '', $status = 200, $headers = array()) 135 | { 136 | $this->setStatus($status); 137 | $this->headers = new \Slim\Http\Headers(array('Content-Type' => 'text/html')); 138 | $this->headers->replace($headers); 139 | $this->cookies = new \Slim\Http\Cookies(); 140 | $this->write($body); 141 | } 142 | 143 | public function getStatus() 144 | { 145 | return $this->status; 146 | } 147 | 148 | public function setStatus($status) 149 | { 150 | $this->status = (int)$status; 151 | } 152 | 153 | /** 154 | * DEPRECATION WARNING! Use `getStatus` or `setStatus` instead. 155 | * 156 | * Get and set status 157 | * @param int|null $status 158 | * @return int 159 | */ 160 | public function status($status = null) 161 | { 162 | if (!is_null($status)) { 163 | $this->status = (int) $status; 164 | } 165 | 166 | return $this->status; 167 | } 168 | 169 | /** 170 | * DEPRECATION WARNING! Access `headers` property directly. 171 | * 172 | * Get and set header 173 | * @param string $name Header name 174 | * @param string|null $value Header value 175 | * @return string Header value 176 | */ 177 | public function header($name, $value = null) 178 | { 179 | if (!is_null($value)) { 180 | $this->headers->set($name, $value); 181 | } 182 | 183 | return $this->headers->get($name); 184 | } 185 | 186 | /** 187 | * DEPRECATION WARNING! Access `headers` property directly. 188 | * 189 | * Get headers 190 | * @return \Slim\Http\Headers 191 | */ 192 | public function headers() 193 | { 194 | return $this->headers; 195 | } 196 | 197 | public function getBody() 198 | { 199 | return $this->body; 200 | } 201 | 202 | public function setBody($content) 203 | { 204 | $this->write($content, true); 205 | } 206 | 207 | /** 208 | * DEPRECATION WARNING! use `getBody` or `setBody` instead. 209 | * 210 | * Get and set body 211 | * @param string|null $body Content of HTTP response body 212 | * @return string 213 | */ 214 | public function body($body = null) 215 | { 216 | if (!is_null($body)) { 217 | $this->write($body, true); 218 | } 219 | 220 | return $this->body; 221 | } 222 | 223 | /** 224 | * Append HTTP response body 225 | * @param string $body Content to append to the current HTTP response body 226 | * @param bool $replace Overwrite existing response body? 227 | * @return string The updated HTTP response body 228 | */ 229 | public function write($body, $replace = false) 230 | { 231 | if ($replace) { 232 | $this->body = $body; 233 | } else { 234 | $this->body .= (string)$body; 235 | } 236 | $this->length = strlen($this->body); 237 | 238 | return $this->body; 239 | } 240 | 241 | public function getLength() 242 | { 243 | return $this->length; 244 | } 245 | 246 | /** 247 | * DEPRECATION WARNING! Use `getLength` or `write` or `body` instead. 248 | * 249 | * Get and set length 250 | * @param int|null $length 251 | * @return int 252 | */ 253 | public function length($length = null) 254 | { 255 | if (!is_null($length)) { 256 | $this->length = (int) $length; 257 | } 258 | 259 | return $this->length; 260 | } 261 | 262 | /** 263 | * Finalize 264 | * 265 | * This prepares this response and returns an array 266 | * of [status, headers, body]. This array is passed to outer middleware 267 | * if available or directly to the Slim run method. 268 | * 269 | * @return array[int status, array headers, string body] 270 | */ 271 | public function finalize() 272 | { 273 | // Prepare response 274 | if (in_array($this->status, array(204, 304))) { 275 | $this->headers->remove('Content-Type'); 276 | $this->headers->remove('Content-Length'); 277 | $this->setBody(''); 278 | } 279 | 280 | return array($this->status, $this->headers, $this->body); 281 | } 282 | 283 | /** 284 | * DEPRECATION WARNING! Access `cookies` property directly. 285 | * 286 | * Set cookie 287 | * 288 | * Instead of using PHP's `setcookie()` function, Slim manually constructs the HTTP `Set-Cookie` 289 | * header on its own and delegates this responsibility to the `Slim_Http_Util` class. This 290 | * response's header is passed by reference to the utility class and is directly modified. By not 291 | * relying on PHP's native implementation, Slim allows middleware the opportunity to massage or 292 | * analyze the raw header before the response is ultimately delivered to the HTTP client. 293 | * 294 | * @param string $name The name of the cookie 295 | * @param string|array $value If string, the value of cookie; if array, properties for 296 | * cookie including: value, expire, path, domain, secure, httponly 297 | */ 298 | public function setCookie($name, $value) 299 | { 300 | // Util::setCookieHeader($this->header, $name, $value); 301 | $this->cookies->set($name, $value); 302 | } 303 | 304 | /** 305 | * DEPRECATION WARNING! Access `cookies` property directly. 306 | * 307 | * Delete cookie 308 | * 309 | * Instead of using PHP's `setcookie()` function, Slim manually constructs the HTTP `Set-Cookie` 310 | * header on its own and delegates this responsibility to the `Slim_Http_Util` class. This 311 | * response's header is passed by reference to the utility class and is directly modified. By not 312 | * relying on PHP's native implementation, Slim allows middleware the opportunity to massage or 313 | * analyze the raw header before the response is ultimately delivered to the HTTP client. 314 | * 315 | * This method will set a cookie with the given name that has an expiration time in the past; this will 316 | * prompt the HTTP client to invalidate and remove the client-side cookie. Optionally, you may 317 | * also pass a key/value array as the second argument. If the "domain" key is present in this 318 | * array, only the Cookie with the given name AND domain will be removed. The invalidating cookie 319 | * sent with this response will adopt all properties of the second argument. 320 | * 321 | * @param string $name The name of the cookie 322 | * @param array $settings Properties for cookie including: value, expire, path, domain, secure, httponly 323 | */ 324 | public function deleteCookie($name, $settings = array()) 325 | { 326 | $this->cookies->remove($name, $settings); 327 | // Util::deleteCookieHeader($this->header, $name, $value); 328 | } 329 | 330 | /** 331 | * Redirect 332 | * 333 | * This method prepares this response to return an HTTP Redirect response 334 | * to the HTTP client. 335 | * 336 | * @param string $url The redirect destination 337 | * @param int $status The redirect HTTP status code 338 | */ 339 | public function redirect ($url, $status = 302) 340 | { 341 | $this->setStatus($status); 342 | $this->headers->set('Location', $url); 343 | } 344 | 345 | /** 346 | * Helpers: Empty? 347 | * @return bool 348 | */ 349 | public function isEmpty() 350 | { 351 | return in_array($this->status, array(201, 204, 304)); 352 | } 353 | 354 | /** 355 | * Helpers: Informational? 356 | * @return bool 357 | */ 358 | public function isInformational() 359 | { 360 | return $this->status >= 100 && $this->status < 200; 361 | } 362 | 363 | /** 364 | * Helpers: OK? 365 | * @return bool 366 | */ 367 | public function isOk() 368 | { 369 | return $this->status === 200; 370 | } 371 | 372 | /** 373 | * Helpers: Successful? 374 | * @return bool 375 | */ 376 | public function isSuccessful() 377 | { 378 | return $this->status >= 200 && $this->status < 300; 379 | } 380 | 381 | /** 382 | * Helpers: Redirect? 383 | * @return bool 384 | */ 385 | public function isRedirect() 386 | { 387 | return in_array($this->status, array(301, 302, 303, 307)); 388 | } 389 | 390 | /** 391 | * Helpers: Redirection? 392 | * @return bool 393 | */ 394 | public function isRedirection() 395 | { 396 | return $this->status >= 300 && $this->status < 400; 397 | } 398 | 399 | /** 400 | * Helpers: Forbidden? 401 | * @return bool 402 | */ 403 | public function isForbidden() 404 | { 405 | return $this->status === 403; 406 | } 407 | 408 | /** 409 | * Helpers: Not Found? 410 | * @return bool 411 | */ 412 | public function isNotFound() 413 | { 414 | return $this->status === 404; 415 | } 416 | 417 | /** 418 | * Helpers: Client error? 419 | * @return bool 420 | */ 421 | public function isClientError() 422 | { 423 | return $this->status >= 400 && $this->status < 500; 424 | } 425 | 426 | /** 427 | * Helpers: Server Error? 428 | * @return bool 429 | */ 430 | public function isServerError() 431 | { 432 | return $this->status >= 500 && $this->status < 600; 433 | } 434 | 435 | /** 436 | * DEPRECATION WARNING! ArrayAccess interface will be removed from \Slim\Http\Response. 437 | * Iterate `headers` or `cookies` properties directly. 438 | */ 439 | 440 | /** 441 | * Array Access: Offset Exists 442 | */ 443 | public function offsetExists($offset) 444 | { 445 | return isset($this->headers[$offset]); 446 | } 447 | 448 | /** 449 | * Array Access: Offset Get 450 | */ 451 | public function offsetGet($offset) 452 | { 453 | return $this->headers[$offset]; 454 | } 455 | 456 | /** 457 | * Array Access: Offset Set 458 | */ 459 | public function offsetSet($offset, $value) 460 | { 461 | $this->headers[$offset] = $value; 462 | } 463 | 464 | /** 465 | * Array Access: Offset Unset 466 | */ 467 | public function offsetUnset($offset) 468 | { 469 | unset($this->headers[$offset]); 470 | } 471 | 472 | /** 473 | * DEPRECATION WARNING! Countable interface will be removed from \Slim\Http\Response. 474 | * Call `count` on `headers` or `cookies` properties directly. 475 | * 476 | * Countable: Count 477 | */ 478 | public function count() 479 | { 480 | return count($this->headers); 481 | } 482 | 483 | /** 484 | * DEPRECATION WARNING! IteratorAggregate interface will be removed from \Slim\Http\Response. 485 | * Iterate `headers` or `cookies` properties directly. 486 | * 487 | * Get Iterator 488 | * 489 | * This returns the contained `\Slim\Http\Headers` instance which 490 | * is itself iterable. 491 | * 492 | * @return \Slim\Http\Headers 493 | */ 494 | public function getIterator() 495 | { 496 | return $this->headers->getIterator(); 497 | } 498 | 499 | /** 500 | * Get message for HTTP status code 501 | * @param int $status 502 | * @return string|null 503 | */ 504 | public static function getMessageForCode($status) 505 | { 506 | if (isset(self::$messages[$status])) { 507 | return self::$messages[$status]; 508 | } else { 509 | return null; 510 | } 511 | } 512 | } 513 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Http/Util.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Http; 34 | 35 | /** 36 | * Slim HTTP Utilities 37 | * 38 | * This class provides useful methods for handling HTTP requests. 39 | * 40 | * @package Slim 41 | * @author Josh Lockhart 42 | * @since 1.0.0 43 | */ 44 | class Util 45 | { 46 | /** 47 | * Strip slashes from string or array 48 | * 49 | * This method strips slashes from its input. By default, this method will only 50 | * strip slashes from its input if magic quotes are enabled. Otherwise, you may 51 | * override the magic quotes setting with either TRUE or FALSE as the send argument 52 | * to force this method to strip or not strip slashes from its input. 53 | * 54 | * @param array|string $rawData 55 | * @param bool $overrideStripSlashes 56 | * @return array|string 57 | */ 58 | public static function stripSlashesIfMagicQuotes($rawData, $overrideStripSlashes = null) 59 | { 60 | $strip = is_null($overrideStripSlashes) ? get_magic_quotes_gpc() : $overrideStripSlashes; 61 | if ($strip) { 62 | return self::stripSlashes($rawData); 63 | } else { 64 | return $rawData; 65 | } 66 | } 67 | 68 | /** 69 | * Strip slashes from string or array 70 | * @param array|string $rawData 71 | * @return array|string 72 | */ 73 | protected static function stripSlashes($rawData) 74 | { 75 | return is_array($rawData) ? array_map(array('self', 'stripSlashes'), $rawData) : stripslashes($rawData); 76 | } 77 | 78 | /** 79 | * Encrypt data 80 | * 81 | * This method will encrypt data using a given key, vector, and cipher. 82 | * By default, this will encrypt data using the RIJNDAEL/AES 256 bit cipher. You 83 | * may override the default cipher and cipher mode by passing your own desired 84 | * cipher and cipher mode as the final key-value array argument. 85 | * 86 | * @param string $data The unencrypted data 87 | * @param string $key The encryption key 88 | * @param string $iv The encryption initialization vector 89 | * @param array $settings Optional key-value array with custom algorithm and mode 90 | * @return string 91 | */ 92 | public static function encrypt($data, $key, $iv, $settings = array()) 93 | { 94 | if ($data === '' || !extension_loaded('mcrypt')) { 95 | return $data; 96 | } 97 | 98 | //Merge settings with defaults 99 | $defaults = array( 100 | 'algorithm' => MCRYPT_RIJNDAEL_256, 101 | 'mode' => MCRYPT_MODE_CBC 102 | ); 103 | $settings = array_merge($defaults, $settings); 104 | 105 | //Get module 106 | $module = mcrypt_module_open($settings['algorithm'], '', $settings['mode'], ''); 107 | 108 | //Validate IV 109 | $ivSize = mcrypt_enc_get_iv_size($module); 110 | if (strlen($iv) > $ivSize) { 111 | $iv = substr($iv, 0, $ivSize); 112 | } 113 | 114 | //Validate key 115 | $keySize = mcrypt_enc_get_key_size($module); 116 | if (strlen($key) > $keySize) { 117 | $key = substr($key, 0, $keySize); 118 | } 119 | 120 | //Encrypt value 121 | mcrypt_generic_init($module, $key, $iv); 122 | $res = @mcrypt_generic($module, $data); 123 | mcrypt_generic_deinit($module); 124 | 125 | return $res; 126 | } 127 | 128 | /** 129 | * Decrypt data 130 | * 131 | * This method will decrypt data using a given key, vector, and cipher. 132 | * By default, this will decrypt data using the RIJNDAEL/AES 256 bit cipher. You 133 | * may override the default cipher and cipher mode by passing your own desired 134 | * cipher and cipher mode as the final key-value array argument. 135 | * 136 | * @param string $data The encrypted data 137 | * @param string $key The encryption key 138 | * @param string $iv The encryption initialization vector 139 | * @param array $settings Optional key-value array with custom algorithm and mode 140 | * @return string 141 | */ 142 | public static function decrypt($data, $key, $iv, $settings = array()) 143 | { 144 | if ($data === '' || !extension_loaded('mcrypt')) { 145 | return $data; 146 | } 147 | 148 | //Merge settings with defaults 149 | $defaults = array( 150 | 'algorithm' => MCRYPT_RIJNDAEL_256, 151 | 'mode' => MCRYPT_MODE_CBC 152 | ); 153 | $settings = array_merge($defaults, $settings); 154 | 155 | //Get module 156 | $module = mcrypt_module_open($settings['algorithm'], '', $settings['mode'], ''); 157 | 158 | //Validate IV 159 | $ivSize = mcrypt_enc_get_iv_size($module); 160 | if (strlen($iv) > $ivSize) { 161 | $iv = substr($iv, 0, $ivSize); 162 | } 163 | 164 | //Validate key 165 | $keySize = mcrypt_enc_get_key_size($module); 166 | if (strlen($key) > $keySize) { 167 | $key = substr($key, 0, $keySize); 168 | } 169 | 170 | //Decrypt value 171 | mcrypt_generic_init($module, $key, $iv); 172 | $decryptedData = @mdecrypt_generic($module, $data); 173 | $res = rtrim($decryptedData, "\0"); 174 | mcrypt_generic_deinit($module); 175 | 176 | return $res; 177 | } 178 | 179 | /** 180 | * Serialize Response cookies into raw HTTP header 181 | * @param \Slim\Http\Headers $headers The Response headers 182 | * @param \Slim\Http\Cookies $cookies The Response cookies 183 | * @param array $config The Slim app settings 184 | */ 185 | public static function serializeCookies(\Slim\Http\Headers &$headers, \Slim\Http\Cookies $cookies, array $config) 186 | { 187 | if ($config['cookies.encrypt']) { 188 | foreach ($cookies as $name => $settings) { 189 | if (is_string($settings['expires'])) { 190 | $expires = strtotime($settings['expires']); 191 | } else { 192 | $expires = (int) $settings['expires']; 193 | } 194 | 195 | $settings['value'] = static::encodeSecureCookie( 196 | $settings['value'], 197 | $expires, 198 | $config['cookies.secret_key'], 199 | $config['cookies.cipher'], 200 | $config['cookies.cipher_mode'] 201 | ); 202 | static::setCookieHeader($headers, $name, $settings); 203 | } 204 | } else { 205 | foreach ($cookies as $name => $settings) { 206 | static::setCookieHeader($headers, $name, $settings); 207 | } 208 | } 209 | } 210 | 211 | /** 212 | * Encode secure cookie value 213 | * 214 | * This method will create the secure value of an HTTP cookie. The 215 | * cookie value is encrypted and hashed so that its value is 216 | * secure and checked for integrity when read in subsequent requests. 217 | * 218 | * @param string $value The insecure HTTP cookie value 219 | * @param int $expires The UNIX timestamp at which this cookie will expire 220 | * @param string $secret The secret key used to hash the cookie value 221 | * @param int $algorithm The algorithm to use for encryption 222 | * @param int $mode The algorithm mode to use for encryption 223 | * @return string 224 | */ 225 | public static function encodeSecureCookie($value, $expires, $secret, $algorithm, $mode) 226 | { 227 | $key = hash_hmac('sha1', (string) $expires, $secret); 228 | $iv = self::getIv($expires, $secret); 229 | $secureString = base64_encode( 230 | self::encrypt( 231 | $value, 232 | $key, 233 | $iv, 234 | array( 235 | 'algorithm' => $algorithm, 236 | 'mode' => $mode 237 | ) 238 | ) 239 | ); 240 | $verificationString = hash_hmac('sha1', $expires . $value, $key); 241 | 242 | return implode('|', array($expires, $secureString, $verificationString)); 243 | } 244 | 245 | /** 246 | * Decode secure cookie value 247 | * 248 | * This method will decode the secure value of an HTTP cookie. The 249 | * cookie value is encrypted and hashed so that its value is 250 | * secure and checked for integrity when read in subsequent requests. 251 | * 252 | * @param string $value The secure HTTP cookie value 253 | * @param string $secret The secret key used to hash the cookie value 254 | * @param int $algorithm The algorithm to use for encryption 255 | * @param int $mode The algorithm mode to use for encryption 256 | * @return bool|string 257 | */ 258 | public static function decodeSecureCookie($value, $secret, $algorithm, $mode) 259 | { 260 | if ($value) { 261 | $value = explode('|', $value); 262 | if (count($value) === 3 && ((int) $value[0] === 0 || (int) $value[0] > time())) { 263 | $key = hash_hmac('sha1', $value[0], $secret); 264 | $iv = self::getIv($value[0], $secret); 265 | $data = self::decrypt( 266 | base64_decode($value[1]), 267 | $key, 268 | $iv, 269 | array( 270 | 'algorithm' => $algorithm, 271 | 'mode' => $mode 272 | ) 273 | ); 274 | $verificationString = hash_hmac('sha1', $value[0] . $data, $key); 275 | if ($verificationString === $value[2]) { 276 | return $data; 277 | } 278 | } 279 | } 280 | 281 | return false; 282 | } 283 | 284 | /** 285 | * Set HTTP cookie header 286 | * 287 | * This method will construct and set the HTTP `Set-Cookie` header. Slim 288 | * uses this method instead of PHP's native `setcookie` method. This allows 289 | * more control of the HTTP header irrespective of the native implementation's 290 | * dependency on PHP versions. 291 | * 292 | * This method accepts the Slim_Http_Headers object by reference as its 293 | * first argument; this method directly modifies this object instead of 294 | * returning a value. 295 | * 296 | * @param array $header 297 | * @param string $name 298 | * @param string $value 299 | */ 300 | public static function setCookieHeader(&$header, $name, $value) 301 | { 302 | //Build cookie header 303 | if (is_array($value)) { 304 | $domain = ''; 305 | $path = ''; 306 | $expires = ''; 307 | $secure = ''; 308 | $httponly = ''; 309 | if (isset($value['domain']) && $value['domain']) { 310 | $domain = '; domain=' . $value['domain']; 311 | } 312 | if (isset($value['path']) && $value['path']) { 313 | $path = '; path=' . $value['path']; 314 | } 315 | if (isset($value['expires'])) { 316 | if (is_string($value['expires'])) { 317 | $timestamp = strtotime($value['expires']); 318 | } else { 319 | $timestamp = (int) $value['expires']; 320 | } 321 | if ($timestamp !== 0) { 322 | $expires = '; expires=' . gmdate('D, d-M-Y H:i:s e', $timestamp); 323 | } 324 | } 325 | if (isset($value['secure']) && $value['secure']) { 326 | $secure = '; secure'; 327 | } 328 | if (isset($value['httponly']) && $value['httponly']) { 329 | $httponly = '; HttpOnly'; 330 | } 331 | $cookie = sprintf('%s=%s%s', urlencode($name), urlencode((string) $value['value']), $domain . $path . $expires . $secure . $httponly); 332 | } else { 333 | $cookie = sprintf('%s=%s', urlencode($name), urlencode((string) $value)); 334 | } 335 | 336 | //Set cookie header 337 | if (!isset($header['Set-Cookie']) || $header['Set-Cookie'] === '') { 338 | $header['Set-Cookie'] = $cookie; 339 | } else { 340 | $header['Set-Cookie'] = implode("\n", array($header['Set-Cookie'], $cookie)); 341 | } 342 | } 343 | 344 | /** 345 | * Delete HTTP cookie header 346 | * 347 | * This method will construct and set the HTTP `Set-Cookie` header to invalidate 348 | * a client-side HTTP cookie. If a cookie with the same name (and, optionally, domain) 349 | * is already set in the HTTP response, it will also be removed. Slim uses this method 350 | * instead of PHP's native `setcookie` method. This allows more control of the HTTP header 351 | * irrespective of PHP's native implementation's dependency on PHP versions. 352 | * 353 | * This method accepts the Slim_Http_Headers object by reference as its 354 | * first argument; this method directly modifies this object instead of 355 | * returning a value. 356 | * 357 | * @param array $header 358 | * @param string $name 359 | * @param array $value 360 | */ 361 | public static function deleteCookieHeader(&$header, $name, $value = array()) 362 | { 363 | //Remove affected cookies from current response header 364 | $cookiesOld = array(); 365 | $cookiesNew = array(); 366 | if (isset($header['Set-Cookie'])) { 367 | $cookiesOld = explode("\n", $header['Set-Cookie']); 368 | } 369 | foreach ($cookiesOld as $c) { 370 | if (isset($value['domain']) && $value['domain']) { 371 | $regex = sprintf('@%s=.*domain=%s@', urlencode($name), preg_quote($value['domain'])); 372 | } else { 373 | $regex = sprintf('@%s=@', urlencode($name)); 374 | } 375 | if (preg_match($regex, $c) === 0) { 376 | $cookiesNew[] = $c; 377 | } 378 | } 379 | if ($cookiesNew) { 380 | $header['Set-Cookie'] = implode("\n", $cookiesNew); 381 | } else { 382 | unset($header['Set-Cookie']); 383 | } 384 | 385 | //Set invalidating cookie to clear client-side cookie 386 | self::setCookieHeader($header, $name, array_merge(array('value' => '', 'path' => null, 'domain' => null, 'expires' => time() - 100), $value)); 387 | } 388 | 389 | /** 390 | * Parse cookie header 391 | * 392 | * This method will parse the HTTP request's `Cookie` header 393 | * and extract cookies into an associative array. 394 | * 395 | * @param string 396 | * @return array 397 | */ 398 | public static function parseCookieHeader($header) 399 | { 400 | $cookies = array(); 401 | $header = rtrim($header, "\r\n"); 402 | $headerPieces = preg_split('@\s*[;,]\s*@', $header); 403 | foreach ($headerPieces as $c) { 404 | $cParts = explode('=', $c, 2); 405 | if (count($cParts) === 2) { 406 | $key = urldecode($cParts[0]); 407 | $value = urldecode($cParts[1]); 408 | if (!isset($cookies[$key])) { 409 | $cookies[$key] = $value; 410 | } 411 | } 412 | } 413 | 414 | return $cookies; 415 | } 416 | 417 | /** 418 | * Generate a random IV 419 | * 420 | * This method will generate a non-predictable IV for use with 421 | * the cookie encryption 422 | * 423 | * @param int $expires The UNIX timestamp at which this cookie will expire 424 | * @param string $secret The secret key used to hash the cookie value 425 | * @return string Hash 426 | */ 427 | private static function getIv($expires, $secret) 428 | { 429 | $data1 = hash_hmac('sha1', 'a'.$expires.'b', $secret); 430 | $data2 = hash_hmac('sha1', 'z'.$expires.'y', $secret); 431 | 432 | return pack("h*", $data1.$data2); 433 | } 434 | } 435 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Log.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim; 34 | 35 | /** 36 | * Log 37 | * 38 | * This is the primary logger for a Slim application. You may provide 39 | * a Log Writer in conjunction with this Log to write to various output 40 | * destinations (e.g. a file). This class provides this interface: 41 | * 42 | * debug( mixed $object, array $context ) 43 | * info( mixed $object, array $context ) 44 | * notice( mixed $object, array $context ) 45 | * warning( mixed $object, array $context ) 46 | * error( mixed $object, array $context ) 47 | * critical( mixed $object, array $context ) 48 | * alert( mixed $object, array $context ) 49 | * emergency( mixed $object, array $context ) 50 | * log( mixed $level, mixed $object, array $context ) 51 | * 52 | * This class assumes only that your Log Writer has a public `write()` method 53 | * that accepts any object as its one and only argument. The Log Writer 54 | * class may write or send its argument anywhere: a file, STDERR, 55 | * a remote web API, etc. The possibilities are endless. 56 | * 57 | * @package Slim 58 | * @author Josh Lockhart 59 | * @since 1.0.0 60 | */ 61 | class Log 62 | { 63 | const EMERGENCY = 1; 64 | const ALERT = 2; 65 | const CRITICAL = 3; 66 | const FATAL = 3; //DEPRECATED replace with CRITICAL 67 | const ERROR = 4; 68 | const WARN = 5; 69 | const NOTICE = 6; 70 | const INFO = 7; 71 | const DEBUG = 8; 72 | 73 | /** 74 | * @var array 75 | */ 76 | protected static $levels = array( 77 | self::EMERGENCY => 'EMERGENCY', 78 | self::ALERT => 'ALERT', 79 | self::CRITICAL => 'CRITICAL', 80 | self::ERROR => 'ERROR', 81 | self::WARN => 'WARNING', 82 | self::NOTICE => 'NOTICE', 83 | self::INFO => 'INFO', 84 | self::DEBUG => 'DEBUG' 85 | ); 86 | 87 | /** 88 | * @var mixed 89 | */ 90 | protected $writer; 91 | 92 | /** 93 | * @var bool 94 | */ 95 | protected $enabled; 96 | 97 | /** 98 | * @var int 99 | */ 100 | protected $level; 101 | 102 | /** 103 | * Constructor 104 | * @param mixed $writer 105 | */ 106 | public function __construct($writer) 107 | { 108 | $this->writer = $writer; 109 | $this->enabled = true; 110 | $this->level = self::DEBUG; 111 | } 112 | 113 | /** 114 | * Is logging enabled? 115 | * @return bool 116 | */ 117 | public function getEnabled() 118 | { 119 | return $this->enabled; 120 | } 121 | 122 | /** 123 | * Enable or disable logging 124 | * @param bool $enabled 125 | */ 126 | public function setEnabled($enabled) 127 | { 128 | if ($enabled) { 129 | $this->enabled = true; 130 | } else { 131 | $this->enabled = false; 132 | } 133 | } 134 | 135 | /** 136 | * Set level 137 | * @param int $level 138 | * @throws \InvalidArgumentException If invalid log level specified 139 | */ 140 | public function setLevel($level) 141 | { 142 | if (!isset(self::$levels[$level])) { 143 | throw new \InvalidArgumentException('Invalid log level'); 144 | } 145 | $this->level = $level; 146 | } 147 | 148 | /** 149 | * Get level 150 | * @return int 151 | */ 152 | public function getLevel() 153 | { 154 | return $this->level; 155 | } 156 | 157 | /** 158 | * Set writer 159 | * @param mixed $writer 160 | */ 161 | public function setWriter($writer) 162 | { 163 | $this->writer = $writer; 164 | } 165 | 166 | /** 167 | * Get writer 168 | * @return mixed 169 | */ 170 | public function getWriter() 171 | { 172 | return $this->writer; 173 | } 174 | 175 | /** 176 | * Is logging enabled? 177 | * @return bool 178 | */ 179 | public function isEnabled() 180 | { 181 | return $this->enabled; 182 | } 183 | 184 | /** 185 | * Log debug message 186 | * @param mixed $object 187 | * @param array $context 188 | * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled 189 | */ 190 | public function debug($object, $context = array()) 191 | { 192 | return $this->log(self::DEBUG, $object, $context); 193 | } 194 | 195 | /** 196 | * Log info message 197 | * @param mixed $object 198 | * @param array $context 199 | * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled 200 | */ 201 | public function info($object, $context = array()) 202 | { 203 | return $this->log(self::INFO, $object, $context); 204 | } 205 | 206 | /** 207 | * Log notice message 208 | * @param mixed $object 209 | * @param array $context 210 | * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled 211 | */ 212 | public function notice($object, $context = array()) 213 | { 214 | return $this->log(self::NOTICE, $object, $context); 215 | } 216 | 217 | /** 218 | * Log warning message 219 | * @param mixed $object 220 | * @param array $context 221 | * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled 222 | */ 223 | public function warning($object, $context = array()) 224 | { 225 | return $this->log(self::WARN, $object, $context); 226 | } 227 | 228 | /** 229 | * DEPRECATED for function warning 230 | * Log warning message 231 | * @param mixed $object 232 | * @param array $context 233 | * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled 234 | */ 235 | public function warn($object, $context = array()) 236 | { 237 | return $this->log(self::WARN, $object, $context); 238 | } 239 | 240 | /** 241 | * Log error message 242 | * @param mixed $object 243 | * @param array $context 244 | * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled 245 | */ 246 | public function error($object, $context = array()) 247 | { 248 | return $this->log(self::ERROR, $object, $context); 249 | } 250 | 251 | /** 252 | * Log critical message 253 | * @param mixed $object 254 | * @param array $context 255 | * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled 256 | */ 257 | public function critical($object, $context = array()) 258 | { 259 | return $this->log(self::CRITICAL, $object, $context); 260 | } 261 | 262 | /** 263 | * DEPRECATED for function critical 264 | * Log fatal message 265 | * @param mixed $object 266 | * @param array $context 267 | * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled 268 | */ 269 | public function fatal($object, $context = array()) 270 | { 271 | return $this->log(self::CRITICAL, $object, $context); 272 | } 273 | 274 | /** 275 | * Log alert message 276 | * @param mixed $object 277 | * @param array $context 278 | * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled 279 | */ 280 | public function alert($object, $context = array()) 281 | { 282 | return $this->log(self::ALERT, $object, $context); 283 | } 284 | 285 | /** 286 | * Log emergency message 287 | * @param mixed $object 288 | * @param array $context 289 | * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled 290 | */ 291 | public function emergency($object, $context = array()) 292 | { 293 | return $this->log(self::EMERGENCY, $object, $context); 294 | } 295 | 296 | /** 297 | * Log message 298 | * @param mixed $level 299 | * @param mixed $object 300 | * @param array $context 301 | * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled 302 | * @throws \InvalidArgumentException If invalid log level 303 | */ 304 | public function log($level, $object, $context = array()) 305 | { 306 | if (!isset(self::$levels[$level])) { 307 | throw new \InvalidArgumentException('Invalid log level supplied to function'); 308 | } else if ($this->enabled && $this->writer && $level <= $this->level) { 309 | $message = (string)$object; 310 | if (count($context) > 0) { 311 | if (isset($context['exception']) && $context['exception'] instanceof \Exception) { 312 | $message .= ' - ' . $context['exception']; 313 | unset($context['exception']); 314 | } 315 | $message = $this->interpolate($message, $context); 316 | } 317 | return $this->writer->write($message, $level); 318 | } else { 319 | return false; 320 | } 321 | } 322 | 323 | /** 324 | * DEPRECATED for function log 325 | * Log message 326 | * @param mixed $object The object to log 327 | * @param int $level The message level 328 | * @return int|bool 329 | */ 330 | protected function write($object, $level) 331 | { 332 | return $this->log($level, $object); 333 | } 334 | 335 | /** 336 | * Interpolate log message 337 | * @param mixed $message The log message 338 | * @param array $context An array of placeholder values 339 | * @return string The processed string 340 | */ 341 | protected function interpolate($message, $context = array()) 342 | { 343 | $replace = array(); 344 | foreach ($context as $key => $value) { 345 | $replace['{' . $key . '}'] = $value; 346 | } 347 | return strtr($message, $replace); 348 | } 349 | } 350 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/LogWriter.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim; 34 | 35 | /** 36 | * Log Writer 37 | * 38 | * This class is used by Slim_Log to write log messages to a valid, writable 39 | * resource handle (e.g. a file or STDERR). 40 | * 41 | * @package Slim 42 | * @author Josh Lockhart 43 | * @since 1.6.0 44 | */ 45 | class LogWriter 46 | { 47 | /** 48 | * @var resource 49 | */ 50 | protected $resource; 51 | 52 | /** 53 | * Constructor 54 | * @param resource $resource 55 | * @throws \InvalidArgumentException If invalid resource 56 | */ 57 | public function __construct($resource) 58 | { 59 | if (!is_resource($resource)) { 60 | throw new \InvalidArgumentException('Cannot create LogWriter. Invalid resource handle.'); 61 | } 62 | $this->resource = $resource; 63 | } 64 | 65 | /** 66 | * Write message 67 | * @param mixed $message 68 | * @param int $level 69 | * @return int|bool 70 | */ 71 | public function write($message, $level = null) 72 | { 73 | return fwrite($this->resource, (string) $message . PHP_EOL); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Middleware.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim; 34 | 35 | /** 36 | * Middleware 37 | * 38 | * @package Slim 39 | * @author Josh Lockhart 40 | * @since 1.6.0 41 | */ 42 | abstract class Middleware 43 | { 44 | /** 45 | * @var \Slim\Slim Reference to the primary application instance 46 | */ 47 | protected $app; 48 | 49 | /** 50 | * @var mixed Reference to the next downstream middleware 51 | */ 52 | protected $next; 53 | 54 | /** 55 | * Set application 56 | * 57 | * This method injects the primary Slim application instance into 58 | * this middleware. 59 | * 60 | * @param \Slim\Slim $application 61 | */ 62 | final public function setApplication($application) 63 | { 64 | $this->app = $application; 65 | } 66 | 67 | /** 68 | * Get application 69 | * 70 | * This method retrieves the application previously injected 71 | * into this middleware. 72 | * 73 | * @return \Slim\Slim 74 | */ 75 | final public function getApplication() 76 | { 77 | return $this->app; 78 | } 79 | 80 | /** 81 | * Set next middleware 82 | * 83 | * This method injects the next downstream middleware into 84 | * this middleware so that it may optionally be called 85 | * when appropriate. 86 | * 87 | * @param \Slim|\Slim\Middleware 88 | */ 89 | final public function setNextMiddleware($nextMiddleware) 90 | { 91 | $this->next = $nextMiddleware; 92 | } 93 | 94 | /** 95 | * Get next middleware 96 | * 97 | * This method retrieves the next downstream middleware 98 | * previously injected into this middleware. 99 | * 100 | * @return \Slim\Slim|\Slim\Middleware 101 | */ 102 | final public function getNextMiddleware() 103 | { 104 | return $this->next; 105 | } 106 | 107 | /** 108 | * Call 109 | * 110 | * Perform actions specific to this middleware and optionally 111 | * call the next downstream middleware. 112 | */ 113 | abstract public function call(); 114 | } 115 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Middleware/ContentTypes.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Middleware; 34 | 35 | /** 36 | * Content Types 37 | * 38 | * This is middleware for a Slim application that intercepts 39 | * the HTTP request body and parses it into the appropriate 40 | * PHP data structure if possible; else it returns the HTTP 41 | * request body unchanged. This is particularly useful 42 | * for preparing the HTTP request body for an XML or JSON API. 43 | * 44 | * @package Slim 45 | * @author Josh Lockhart 46 | * @since 1.6.0 47 | */ 48 | class ContentTypes extends \Slim\Middleware 49 | { 50 | /** 51 | * @var array 52 | */ 53 | protected $contentTypes; 54 | 55 | /** 56 | * Constructor 57 | * @param array $settings 58 | */ 59 | public function __construct($settings = array()) 60 | { 61 | $defaults = array( 62 | 'application/json' => array($this, 'parseJson'), 63 | 'application/xml' => array($this, 'parseXml'), 64 | 'text/xml' => array($this, 'parseXml'), 65 | 'text/csv' => array($this, 'parseCsv') 66 | ); 67 | $this->contentTypes = array_merge($defaults, $settings); 68 | } 69 | 70 | /** 71 | * Call 72 | */ 73 | public function call() 74 | { 75 | $mediaType = $this->app->request()->getMediaType(); 76 | if ($mediaType) { 77 | $env = $this->app->environment(); 78 | $env['slim.input_original'] = $env['slim.input']; 79 | $env['slim.input'] = $this->parse($env['slim.input'], $mediaType); 80 | } 81 | $this->next->call(); 82 | } 83 | 84 | /** 85 | * Parse input 86 | * 87 | * This method will attempt to parse the request body 88 | * based on its content type if available. 89 | * 90 | * @param string $input 91 | * @param string $contentType 92 | * @return mixed 93 | */ 94 | protected function parse ($input, $contentType) 95 | { 96 | if (isset($this->contentTypes[$contentType]) && is_callable($this->contentTypes[$contentType])) { 97 | $result = call_user_func($this->contentTypes[$contentType], $input); 98 | if ($result) { 99 | return $result; 100 | } 101 | } 102 | 103 | return $input; 104 | } 105 | 106 | /** 107 | * Parse JSON 108 | * 109 | * This method converts the raw JSON input 110 | * into an associative array. 111 | * 112 | * @param string $input 113 | * @return array|string 114 | */ 115 | protected function parseJson($input) 116 | { 117 | if (function_exists('json_decode')) { 118 | $result = json_decode($input, true); 119 | if ($result) { 120 | return $result; 121 | } 122 | } 123 | } 124 | 125 | /** 126 | * Parse XML 127 | * 128 | * This method creates a SimpleXMLElement 129 | * based upon the XML input. If the SimpleXML 130 | * extension is not available, the raw input 131 | * will be returned unchanged. 132 | * 133 | * @param string $input 134 | * @return \SimpleXMLElement|string 135 | */ 136 | protected function parseXml($input) 137 | { 138 | if (class_exists('SimpleXMLElement')) { 139 | try { 140 | $backup = libxml_disable_entity_loader(true); 141 | $result = new \SimpleXMLElement($input); 142 | libxml_disable_entity_loader($backup); 143 | return $result; 144 | } catch (\Exception $e) { 145 | // Do nothing 146 | } 147 | } 148 | 149 | return $input; 150 | } 151 | 152 | /** 153 | * Parse CSV 154 | * 155 | * This method parses CSV content into a numeric array 156 | * containing an array of data for each CSV line. 157 | * 158 | * @param string $input 159 | * @return array 160 | */ 161 | protected function parseCsv($input) 162 | { 163 | $temp = fopen('php://memory', 'rw'); 164 | fwrite($temp, $input); 165 | fseek($temp, 0); 166 | $res = array(); 167 | while (($data = fgetcsv($temp)) !== false) { 168 | $res[] = $data; 169 | } 170 | fclose($temp); 171 | 172 | return $res; 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Middleware/Flash.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Middleware; 34 | 35 | /** 36 | * Flash 37 | * 38 | * This is middleware for a Slim application that enables 39 | * Flash messaging between HTTP requests. This allows you 40 | * set Flash messages for the current request, for the next request, 41 | * or to retain messages from the previous request through to 42 | * the next request. 43 | * 44 | * @package Slim 45 | * @author Josh Lockhart 46 | * @since 1.6.0 47 | */ 48 | class Flash extends \Slim\Middleware implements \ArrayAccess, \IteratorAggregate, \Countable 49 | { 50 | /** 51 | * @var array 52 | */ 53 | protected $settings; 54 | 55 | /** 56 | * @var array 57 | */ 58 | protected $messages; 59 | 60 | /** 61 | * Constructor 62 | * @param array $settings 63 | */ 64 | public function __construct($settings = array()) 65 | { 66 | $this->settings = array_merge(array('key' => 'slim.flash'), $settings); 67 | $this->messages = array( 68 | 'prev' => array(), //flash messages from prev request (loaded when middleware called) 69 | 'next' => array(), //flash messages for next request 70 | 'now' => array() //flash messages for current request 71 | ); 72 | } 73 | 74 | /** 75 | * Call 76 | */ 77 | public function call() 78 | { 79 | //Read flash messaging from previous request if available 80 | $this->loadMessages(); 81 | 82 | //Prepare flash messaging for current request 83 | $env = $this->app->environment(); 84 | $env['slim.flash'] = $this; 85 | $this->next->call(); 86 | $this->save(); 87 | } 88 | 89 | /** 90 | * Now 91 | * 92 | * Specify a flash message for a given key to be shown for the current request 93 | * 94 | * @param string $key 95 | * @param string $value 96 | */ 97 | public function now($key, $value) 98 | { 99 | $this->messages['now'][(string) $key] = $value; 100 | } 101 | 102 | /** 103 | * Set 104 | * 105 | * Specify a flash message for a given key to be shown for the next request 106 | * 107 | * @param string $key 108 | * @param string $value 109 | */ 110 | public function set($key, $value) 111 | { 112 | $this->messages['next'][(string) $key] = $value; 113 | } 114 | 115 | /** 116 | * Keep 117 | * 118 | * Retain flash messages from the previous request for the next request 119 | */ 120 | public function keep() 121 | { 122 | foreach ($this->messages['prev'] as $key => $val) { 123 | $this->messages['next'][$key] = $val; 124 | } 125 | } 126 | 127 | /** 128 | * Save 129 | */ 130 | public function save() 131 | { 132 | $_SESSION[$this->settings['key']] = $this->messages['next']; 133 | } 134 | 135 | /** 136 | * Load messages from previous request if available 137 | */ 138 | public function loadMessages() 139 | { 140 | if (isset($_SESSION[$this->settings['key']])) { 141 | $this->messages['prev'] = $_SESSION[$this->settings['key']]; 142 | } 143 | } 144 | 145 | /** 146 | * Return array of flash messages to be shown for the current request 147 | * 148 | * @return array 149 | */ 150 | public function getMessages() 151 | { 152 | return array_merge($this->messages['prev'], $this->messages['now']); 153 | } 154 | 155 | /** 156 | * Array Access: Offset Exists 157 | */ 158 | public function offsetExists($offset) 159 | { 160 | $messages = $this->getMessages(); 161 | 162 | return isset($messages[$offset]); 163 | } 164 | 165 | /** 166 | * Array Access: Offset Get 167 | */ 168 | public function offsetGet($offset) 169 | { 170 | $messages = $this->getMessages(); 171 | 172 | return isset($messages[$offset]) ? $messages[$offset] : null; 173 | } 174 | 175 | /** 176 | * Array Access: Offset Set 177 | */ 178 | public function offsetSet($offset, $value) 179 | { 180 | $this->now($offset, $value); 181 | } 182 | 183 | /** 184 | * Array Access: Offset Unset 185 | */ 186 | public function offsetUnset($offset) 187 | { 188 | unset($this->messages['prev'][$offset], $this->messages['now'][$offset]); 189 | } 190 | 191 | /** 192 | * Iterator Aggregate: Get Iterator 193 | * @return \ArrayIterator 194 | */ 195 | public function getIterator() 196 | { 197 | $messages = $this->getMessages(); 198 | 199 | return new \ArrayIterator($messages); 200 | } 201 | 202 | /** 203 | * Countable: Count 204 | */ 205 | public function count() 206 | { 207 | return count($this->getMessages()); 208 | } 209 | 210 | 211 | 212 | } 213 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Middleware/MethodOverride.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Middleware; 34 | 35 | /** 36 | * HTTP Method Override 37 | * 38 | * This is middleware for a Slim application that allows traditional 39 | * desktop browsers to submit pseudo PUT and DELETE requests by relying 40 | * on a pre-determined request parameter. Without this middleware, 41 | * desktop browsers are only able to submit GET and POST requests. 42 | * 43 | * This middleware is included automatically! 44 | * 45 | * @package Slim 46 | * @author Josh Lockhart 47 | * @since 1.6.0 48 | */ 49 | class MethodOverride extends \Slim\Middleware 50 | { 51 | /** 52 | * @var array 53 | */ 54 | protected $settings; 55 | 56 | /** 57 | * Constructor 58 | * @param array $settings 59 | */ 60 | public function __construct($settings = array()) 61 | { 62 | $this->settings = array_merge(array('key' => '_METHOD'), $settings); 63 | } 64 | 65 | /** 66 | * Call 67 | * 68 | * Implements Slim middleware interface. This method is invoked and passed 69 | * an array of environment variables. This middleware inspects the environment 70 | * variables for the HTTP method override parameter; if found, this middleware 71 | * modifies the environment settings so downstream middleware and/or the Slim 72 | * application will treat the request with the desired HTTP method. 73 | * 74 | * @return array[status, header, body] 75 | */ 76 | public function call() 77 | { 78 | $env = $this->app->environment(); 79 | if (isset($env['HTTP_X_HTTP_METHOD_OVERRIDE'])) { 80 | // Header commonly used by Backbone.js and others 81 | $env['slim.method_override.original_method'] = $env['REQUEST_METHOD']; 82 | $env['REQUEST_METHOD'] = strtoupper($env['HTTP_X_HTTP_METHOD_OVERRIDE']); 83 | } elseif (isset($env['REQUEST_METHOD']) && $env['REQUEST_METHOD'] === 'POST') { 84 | // HTML Form Override 85 | $req = new \Slim\Http\Request($env); 86 | $method = $req->post($this->settings['key']); 87 | if ($method) { 88 | $env['slim.method_override.original_method'] = $env['REQUEST_METHOD']; 89 | $env['REQUEST_METHOD'] = strtoupper($method); 90 | } 91 | } 92 | $this->next->call(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Middleware/PrettyExceptions.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Middleware; 34 | 35 | /** 36 | * Pretty Exceptions 37 | * 38 | * This middleware catches any Exception thrown by the surrounded 39 | * application and displays a developer-friendly diagnostic screen. 40 | * 41 | * @package Slim 42 | * @author Josh Lockhart 43 | * @since 1.0.0 44 | */ 45 | class PrettyExceptions extends \Slim\Middleware 46 | { 47 | /** 48 | * @var array 49 | */ 50 | protected $settings; 51 | 52 | /** 53 | * Constructor 54 | * @param array $settings 55 | */ 56 | public function __construct($settings = array()) 57 | { 58 | $this->settings = $settings; 59 | } 60 | 61 | /** 62 | * Call 63 | */ 64 | public function call() 65 | { 66 | try { 67 | $this->next->call(); 68 | } catch (\Exception $e) { 69 | $log = $this->app->getLog(); // Force Slim to append log to env if not already 70 | $env = $this->app->environment(); 71 | $env['slim.log'] = $log; 72 | $env['slim.log']->error($e); 73 | $this->app->contentType('text/html'); 74 | $this->app->response()->status(500); 75 | $this->app->response()->body($this->renderBody($env, $e)); 76 | } 77 | } 78 | 79 | /** 80 | * Render response body 81 | * @param array $env 82 | * @param \Exception $exception 83 | * @return string 84 | */ 85 | protected function renderBody(&$env, $exception) 86 | { 87 | $title = 'Slim Application Error'; 88 | $code = $exception->getCode(); 89 | $message = $exception->getMessage(); 90 | $file = $exception->getFile(); 91 | $line = $exception->getLine(); 92 | $trace = str_replace(array('#', '\n'), array('
#', '
'), $exception->getTraceAsString()); 93 | $html = sprintf('

%s

', $title); 94 | $html .= '

The application could not run because of the following error:

'; 95 | $html .= '

Details

'; 96 | $html .= sprintf('
Type: %s
', get_class($exception)); 97 | if ($code) { 98 | $html .= sprintf('
Code: %s
', $code); 99 | } 100 | if ($message) { 101 | $html .= sprintf('
Message: %s
', $message); 102 | } 103 | if ($file) { 104 | $html .= sprintf('
File: %s
', $file); 105 | } 106 | if ($line) { 107 | $html .= sprintf('
Line: %s
', $line); 108 | } 109 | if ($trace) { 110 | $html .= '

Trace

'; 111 | $html .= sprintf('
%s
', $trace); 112 | } 113 | 114 | return sprintf("%s%s", $title, $html); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Middleware/SessionCookie.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim\Middleware; 34 | 35 | /** 36 | * Session Cookie 37 | * 38 | * This class provides an HTTP cookie storage mechanism 39 | * for session data. This class avoids using a PHP session 40 | * and instead serializes/unserializes the $_SESSION global 41 | * variable to/from an HTTP cookie. 42 | * 43 | * You should NEVER store sensitive data in a client-side cookie 44 | * in any format, encrypted (with cookies.encrypt) or not. If you 45 | * need to store sensitive user information in a session, you should 46 | * rely on PHP's native session implementation, or use other middleware 47 | * to store session data in a database or alternative server-side cache. 48 | * 49 | * Because this class stores serialized session data in an HTTP cookie, 50 | * you are inherently limited to 4 Kb. If you attempt to store 51 | * more than this amount, serialization will fail. 52 | * 53 | * @package Slim 54 | * @author Josh Lockhart 55 | * @since 1.6.0 56 | */ 57 | class SessionCookie extends \Slim\Middleware 58 | { 59 | /** 60 | * @var array 61 | */ 62 | protected $settings; 63 | 64 | /** 65 | * Constructor 66 | * 67 | * @param array $settings 68 | */ 69 | public function __construct($settings = array()) 70 | { 71 | $defaults = array( 72 | 'expires' => '20 minutes', 73 | 'path' => '/', 74 | 'domain' => null, 75 | 'secure' => false, 76 | 'httponly' => false, 77 | 'name' => 'slim_session', 78 | ); 79 | $this->settings = array_merge($defaults, $settings); 80 | if (is_string($this->settings['expires'])) { 81 | $this->settings['expires'] = strtotime($this->settings['expires']); 82 | } 83 | 84 | /** 85 | * Session 86 | * 87 | * We must start a native PHP session to initialize the $_SESSION superglobal. 88 | * However, we won't be using the native session store for persistence, so we 89 | * disable the session cookie and cache limiter. We also set the session 90 | * handler to this class instance to avoid PHP's native session file locking. 91 | */ 92 | ini_set('session.use_cookies', 0); 93 | session_cache_limiter(false); 94 | session_set_save_handler( 95 | array($this, 'open'), 96 | array($this, 'close'), 97 | array($this, 'read'), 98 | array($this, 'write'), 99 | array($this, 'destroy'), 100 | array($this, 'gc') 101 | ); 102 | } 103 | 104 | /** 105 | * Call 106 | */ 107 | public function call() 108 | { 109 | $this->loadSession(); 110 | $this->next->call(); 111 | $this->saveSession(); 112 | } 113 | 114 | /** 115 | * Load session 116 | */ 117 | protected function loadSession() 118 | { 119 | if (session_id() === '') { 120 | session_start(); 121 | } 122 | 123 | $value = $this->app->getCookie($this->settings['name']); 124 | 125 | if ($value) { 126 | try { 127 | $_SESSION = unserialize($value); 128 | } catch (\Exception $e) { 129 | $this->app->getLog()->error('Error unserializing session cookie value! ' . $e->getMessage()); 130 | } 131 | } else { 132 | $_SESSION = array(); 133 | } 134 | } 135 | 136 | /** 137 | * Save session 138 | */ 139 | protected function saveSession() 140 | { 141 | $value = serialize($_SESSION); 142 | 143 | if (strlen($value) > 4096) { 144 | $this->app->getLog()->error('WARNING! Slim\Middleware\SessionCookie data size is larger than 4KB. Content save failed.'); 145 | } else { 146 | $this->app->setCookie( 147 | $this->settings['name'], 148 | $value, 149 | $this->settings['expires'], 150 | $this->settings['path'], 151 | $this->settings['domain'], 152 | $this->settings['secure'], 153 | $this->settings['httponly'] 154 | ); 155 | } 156 | // session_destroy(); 157 | } 158 | 159 | /******************************************************************************** 160 | * Session Handler 161 | *******************************************************************************/ 162 | 163 | /** 164 | * @codeCoverageIgnore 165 | */ 166 | public function open($savePath, $sessionName) 167 | { 168 | return true; 169 | } 170 | 171 | /** 172 | * @codeCoverageIgnore 173 | */ 174 | public function close() 175 | { 176 | return true; 177 | } 178 | 179 | /** 180 | * @codeCoverageIgnore 181 | */ 182 | public function read($id) 183 | { 184 | return ''; 185 | } 186 | 187 | /** 188 | * @codeCoverageIgnore 189 | */ 190 | public function write($id, $data) 191 | { 192 | return true; 193 | } 194 | 195 | /** 196 | * @codeCoverageIgnore 197 | */ 198 | public function destroy($id) 199 | { 200 | return true; 201 | } 202 | 203 | /** 204 | * @codeCoverageIgnore 205 | */ 206 | public function gc($maxlifetime) 207 | { 208 | return true; 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Route.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim; 34 | 35 | /** 36 | * Route 37 | * @package Slim 38 | * @author Josh Lockhart, Thomas Bley 39 | * @since 1.0.0 40 | */ 41 | class Route 42 | { 43 | /** 44 | * @var string The route pattern (e.g. "/books/:id") 45 | */ 46 | protected $pattern; 47 | 48 | /** 49 | * @var mixed The route callable 50 | */ 51 | protected $callable; 52 | 53 | /** 54 | * @var array Conditions for this route's URL parameters 55 | */ 56 | protected $conditions = array(); 57 | 58 | /** 59 | * @var array Default conditions applied to all route instances 60 | */ 61 | protected static $defaultConditions = array(); 62 | 63 | /** 64 | * @var string The name of this route (optional) 65 | */ 66 | protected $name; 67 | 68 | /** 69 | * @var array Key-value array of URL parameters 70 | */ 71 | protected $params = array(); 72 | 73 | /** 74 | * @var array value array of URL parameter names 75 | */ 76 | protected $paramNames = array(); 77 | 78 | /** 79 | * @var array key array of URL parameter names with + at the end 80 | */ 81 | protected $paramNamesPath = array(); 82 | 83 | /** 84 | * @var array HTTP methods supported by this Route 85 | */ 86 | protected $methods = array(); 87 | 88 | /** 89 | * @var array[Callable] Middleware to be run before only this route instance 90 | */ 91 | protected $middleware = array(); 92 | 93 | /** 94 | * @var bool Whether or not this route should be matched in a case-sensitive manner 95 | */ 96 | protected $caseSensitive; 97 | 98 | /** 99 | * Constructor 100 | * @param string $pattern The URL pattern (e.g. "/books/:id") 101 | * @param mixed $callable Anything that returns TRUE for is_callable() 102 | * @param bool $caseSensitive Whether or not this route should be matched in a case-sensitive manner 103 | */ 104 | public function __construct($pattern, $callable, $caseSensitive = true) 105 | { 106 | $this->setPattern($pattern); 107 | $this->setCallable($callable); 108 | $this->setConditions(self::getDefaultConditions()); 109 | $this->caseSensitive = $caseSensitive; 110 | } 111 | 112 | /** 113 | * Set default route conditions for all instances 114 | * @param array $defaultConditions 115 | */ 116 | public static function setDefaultConditions(array $defaultConditions) 117 | { 118 | self::$defaultConditions = $defaultConditions; 119 | } 120 | 121 | /** 122 | * Get default route conditions for all instances 123 | * @return array 124 | */ 125 | public static function getDefaultConditions() 126 | { 127 | return self::$defaultConditions; 128 | } 129 | 130 | /** 131 | * Get route pattern 132 | * @return string 133 | */ 134 | public function getPattern() 135 | { 136 | return $this->pattern; 137 | } 138 | 139 | /** 140 | * Set route pattern 141 | * @param string $pattern 142 | */ 143 | public function setPattern($pattern) 144 | { 145 | $this->pattern = $pattern; 146 | } 147 | 148 | /** 149 | * Get route callable 150 | * @return mixed 151 | */ 152 | public function getCallable() 153 | { 154 | return $this->callable; 155 | } 156 | 157 | /** 158 | * Set route callable 159 | * @param mixed $callable 160 | * @throws \InvalidArgumentException If argument is not callable 161 | */ 162 | public function setCallable($callable) 163 | { 164 | $matches = array(); 165 | if (is_string($callable) && preg_match('!^([^\:]+)\:([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$!', $callable, $matches)) { 166 | $class = $matches[1]; 167 | $method = $matches[2]; 168 | $callable = function() use ($class, $method) { 169 | static $obj = null; 170 | if ($obj === null) { 171 | $obj = new $class; 172 | } 173 | return call_user_func_array(array($obj, $method), func_get_args()); 174 | }; 175 | } 176 | 177 | if (!is_callable($callable)) { 178 | throw new \InvalidArgumentException('Route callable must be callable'); 179 | } 180 | 181 | $this->callable = $callable; 182 | } 183 | 184 | /** 185 | * Get route conditions 186 | * @return array 187 | */ 188 | public function getConditions() 189 | { 190 | return $this->conditions; 191 | } 192 | 193 | /** 194 | * Set route conditions 195 | * @param array $conditions 196 | */ 197 | public function setConditions(array $conditions) 198 | { 199 | $this->conditions = $conditions; 200 | } 201 | 202 | /** 203 | * Get route name 204 | * @return string|null 205 | */ 206 | public function getName() 207 | { 208 | return $this->name; 209 | } 210 | 211 | /** 212 | * Set route name 213 | * @param string $name 214 | */ 215 | public function setName($name) 216 | { 217 | $this->name = (string)$name; 218 | } 219 | 220 | /** 221 | * Get route parameters 222 | * @return array 223 | */ 224 | public function getParams() 225 | { 226 | return $this->params; 227 | } 228 | 229 | /** 230 | * Set route parameters 231 | * @param array $params 232 | */ 233 | public function setParams($params) 234 | { 235 | $this->params = $params; 236 | } 237 | 238 | /** 239 | * Get route parameter value 240 | * @param string $index Name of URL parameter 241 | * @return string 242 | * @throws \InvalidArgumentException If route parameter does not exist at index 243 | */ 244 | public function getParam($index) 245 | { 246 | if (!isset($this->params[$index])) { 247 | throw new \InvalidArgumentException('Route parameter does not exist at specified index'); 248 | } 249 | 250 | return $this->params[$index]; 251 | } 252 | 253 | /** 254 | * Set route parameter value 255 | * @param string $index Name of URL parameter 256 | * @param mixed $value The new parameter value 257 | * @throws \InvalidArgumentException If route parameter does not exist at index 258 | */ 259 | public function setParam($index, $value) 260 | { 261 | if (!isset($this->params[$index])) { 262 | throw new \InvalidArgumentException('Route parameter does not exist at specified index'); 263 | } 264 | $this->params[$index] = $value; 265 | } 266 | 267 | /** 268 | * Add supported HTTP method(s) 269 | */ 270 | public function setHttpMethods() 271 | { 272 | $args = func_get_args(); 273 | $this->methods = $args; 274 | } 275 | 276 | /** 277 | * Get supported HTTP methods 278 | * @return array 279 | */ 280 | public function getHttpMethods() 281 | { 282 | return $this->methods; 283 | } 284 | 285 | /** 286 | * Append supported HTTP methods 287 | */ 288 | public function appendHttpMethods() 289 | { 290 | $args = func_get_args(); 291 | $this->methods = array_merge($this->methods, $args); 292 | } 293 | 294 | /** 295 | * Append supported HTTP methods (alias for Route::appendHttpMethods) 296 | * @return \Slim\Route 297 | */ 298 | public function via() 299 | { 300 | $args = func_get_args(); 301 | $this->methods = array_merge($this->methods, $args); 302 | 303 | return $this; 304 | } 305 | 306 | /** 307 | * Detect support for an HTTP method 308 | * @param string $method 309 | * @return bool 310 | */ 311 | public function supportsHttpMethod($method) 312 | { 313 | return in_array($method, $this->methods); 314 | } 315 | 316 | /** 317 | * Get middleware 318 | * @return array[Callable] 319 | */ 320 | public function getMiddleware() 321 | { 322 | return $this->middleware; 323 | } 324 | 325 | /** 326 | * Set middleware 327 | * 328 | * This method allows middleware to be assigned to a specific Route. 329 | * If the method argument `is_callable` (including callable arrays!), 330 | * we directly append the argument to `$this->middleware`. Else, we 331 | * assume the argument is an array of callables and merge the array 332 | * with `$this->middleware`. Each middleware is checked for is_callable() 333 | * and an InvalidArgumentException is thrown immediately if it isn't. 334 | * 335 | * @param Callable|array[Callable] 336 | * @return \Slim\Route 337 | * @throws \InvalidArgumentException If argument is not callable or not an array of callables. 338 | */ 339 | public function setMiddleware($middleware) 340 | { 341 | if (is_callable($middleware)) { 342 | $this->middleware[] = $middleware; 343 | } elseif (is_array($middleware)) { 344 | foreach ($middleware as $callable) { 345 | if (!is_callable($callable)) { 346 | throw new \InvalidArgumentException('All Route middleware must be callable'); 347 | } 348 | } 349 | $this->middleware = array_merge($this->middleware, $middleware); 350 | } else { 351 | throw new \InvalidArgumentException('Route middleware must be callable or an array of callables'); 352 | } 353 | 354 | return $this; 355 | } 356 | 357 | /** 358 | * Matches URI? 359 | * 360 | * Parse this route's pattern, and then compare it to an HTTP resource URI 361 | * This method was modeled after the techniques demonstrated by Dan Sosedoff at: 362 | * 363 | * http://blog.sosedoff.com/2009/09/20/rails-like-php-url-router/ 364 | * 365 | * @param string $resourceUri A Request URI 366 | * @return bool 367 | */ 368 | public function matches($resourceUri) 369 | { 370 | //Convert URL params into regex patterns, construct a regex for this route, init params 371 | $patternAsRegex = preg_replace_callback( 372 | '#:([\w]+)\+?#', 373 | array($this, 'matchesCallback'), 374 | str_replace(')', ')?', (string)$this->pattern) 375 | ); 376 | if (substr($this->pattern, -1) === '/') { 377 | $patternAsRegex .= '?'; 378 | } 379 | 380 | $regex = '#^' . $patternAsRegex . '$#'; 381 | 382 | if ($this->caseSensitive === false) { 383 | $regex .= 'i'; 384 | } 385 | 386 | //Cache URL params' names and values if this route matches the current HTTP request 387 | if (!preg_match($regex, $resourceUri, $paramValues)) { 388 | return false; 389 | } 390 | foreach ($this->paramNames as $name) { 391 | if (isset($paramValues[$name])) { 392 | if (isset($this->paramNamesPath[$name])) { 393 | $this->params[$name] = explode('/', urldecode($paramValues[$name])); 394 | } else { 395 | $this->params[$name] = urldecode($paramValues[$name]); 396 | } 397 | } 398 | } 399 | 400 | return true; 401 | } 402 | 403 | /** 404 | * Convert a URL parameter (e.g. ":id", ":id+") into a regular expression 405 | * @param array $m URL parameters 406 | * @return string Regular expression for URL parameter 407 | */ 408 | protected function matchesCallback($m) 409 | { 410 | $this->paramNames[] = $m[1]; 411 | if (isset($this->conditions[$m[1]])) { 412 | return '(?P<' . $m[1] . '>' . $this->conditions[$m[1]] . ')'; 413 | } 414 | if (substr($m[0], -1) === '+') { 415 | $this->paramNamesPath[$m[1]] = 1; 416 | 417 | return '(?P<' . $m[1] . '>.+)'; 418 | } 419 | 420 | return '(?P<' . $m[1] . '>[^/]+)'; 421 | } 422 | 423 | /** 424 | * Set route name 425 | * @param string $name The name of the route 426 | * @return \Slim\Route 427 | */ 428 | public function name($name) 429 | { 430 | $this->setName($name); 431 | 432 | return $this; 433 | } 434 | 435 | /** 436 | * Merge route conditions 437 | * @param array $conditions Key-value array of URL parameter conditions 438 | * @return \Slim\Route 439 | */ 440 | public function conditions(array $conditions) 441 | { 442 | $this->conditions = array_merge($this->conditions, $conditions); 443 | 444 | return $this; 445 | } 446 | 447 | /** 448 | * Dispatch route 449 | * 450 | * This method invokes the route object's callable. If middleware is 451 | * registered for the route, each callable middleware is invoked in 452 | * the order specified. 453 | * 454 | * @return bool 455 | */ 456 | public function dispatch() 457 | { 458 | foreach ($this->middleware as $mw) { 459 | call_user_func_array($mw, array($this)); 460 | } 461 | 462 | $return = call_user_func_array($this->getCallable(), array_values($this->getParams())); 463 | return ($return === false) ? false : true; 464 | } 465 | } 466 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/Router.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim; 34 | 35 | /** 36 | * Router 37 | * 38 | * This class organizes, iterates, and dispatches \Slim\Route objects. 39 | * 40 | * @package Slim 41 | * @author Josh Lockhart 42 | * @since 1.0.0 43 | */ 44 | class Router 45 | { 46 | /** 47 | * @var Route The current route (most recently dispatched) 48 | */ 49 | protected $currentRoute; 50 | 51 | /** 52 | * @var array Lookup hash of all route objects 53 | */ 54 | protected $routes; 55 | 56 | /** 57 | * @var array Lookup hash of named route objects, keyed by route name (lazy-loaded) 58 | */ 59 | protected $namedRoutes; 60 | 61 | /** 62 | * @var array Array of route objects that match the request URI (lazy-loaded) 63 | */ 64 | protected $matchedRoutes; 65 | 66 | /** 67 | * @var array Array containing all route groups 68 | */ 69 | protected $routeGroups; 70 | 71 | /** 72 | * Constructor 73 | */ 74 | public function __construct() 75 | { 76 | $this->routes = array(); 77 | $this->routeGroups = array(); 78 | } 79 | 80 | /** 81 | * Get Current Route object or the first matched one if matching has been performed 82 | * @return \Slim\Route|null 83 | */ 84 | public function getCurrentRoute() 85 | { 86 | if ($this->currentRoute !== null) { 87 | return $this->currentRoute; 88 | } 89 | 90 | if (is_array($this->matchedRoutes) && count($this->matchedRoutes) > 0) { 91 | return $this->matchedRoutes[0]; 92 | } 93 | 94 | return null; 95 | } 96 | 97 | /** 98 | * Return route objects that match the given HTTP method and URI 99 | * @param string $httpMethod The HTTP method to match against 100 | * @param string $resourceUri The resource URI to match against 101 | * @param bool $reload Should matching routes be re-parsed? 102 | * @return array[\Slim\Route] 103 | */ 104 | public function getMatchedRoutes($httpMethod, $resourceUri, $reload = false) 105 | { 106 | if ($reload || is_null($this->matchedRoutes)) { 107 | $this->matchedRoutes = array(); 108 | foreach ($this->routes as $route) { 109 | if (!$route->supportsHttpMethod($httpMethod) && !$route->supportsHttpMethod("ANY")) { 110 | continue; 111 | } 112 | 113 | if ($route->matches($resourceUri)) { 114 | $this->matchedRoutes[] = $route; 115 | } 116 | } 117 | } 118 | 119 | return $this->matchedRoutes; 120 | } 121 | 122 | /** 123 | * Add a route object to the router 124 | * @param \Slim\Route $route The Slim Route 125 | */ 126 | public function map(\Slim\Route $route) 127 | { 128 | list($groupPattern, $groupMiddleware) = $this->processGroups(); 129 | 130 | $route->setPattern($groupPattern . $route->getPattern()); 131 | $this->routes[] = $route; 132 | 133 | 134 | foreach ($groupMiddleware as $middleware) { 135 | $route->setMiddleware($middleware); 136 | } 137 | } 138 | 139 | /** 140 | * A helper function for processing the group's pattern and middleware 141 | * @return array Returns an array with the elements: pattern, middlewareArr 142 | */ 143 | protected function processGroups() 144 | { 145 | $pattern = ""; 146 | $middleware = array(); 147 | foreach ($this->routeGroups as $group) { 148 | $k = key($group); 149 | $pattern .= $k; 150 | if (is_array($group[$k])) { 151 | $middleware = array_merge($middleware, $group[$k]); 152 | } 153 | } 154 | return array($pattern, $middleware); 155 | } 156 | 157 | /** 158 | * Add a route group to the array 159 | * @param string $group The group pattern (ie. "/books/:id") 160 | * @param array|null $middleware Optional parameter array of middleware 161 | * @return int The index of the new group 162 | */ 163 | public function pushGroup($group, $middleware = array()) 164 | { 165 | return array_push($this->routeGroups, array($group => $middleware)); 166 | } 167 | 168 | /** 169 | * Removes the last route group from the array 170 | * @return bool True if successful, else False 171 | */ 172 | public function popGroup() 173 | { 174 | return (array_pop($this->routeGroups) !== null); 175 | } 176 | 177 | /** 178 | * Get URL for named route 179 | * @param string $name The name of the route 180 | * @param array $params Associative array of URL parameter names and replacement values 181 | * @throws \RuntimeException If named route not found 182 | * @return string The URL for the given route populated with provided replacement values 183 | */ 184 | public function urlFor($name, $params = array()) 185 | { 186 | if (!$this->hasNamedRoute($name)) { 187 | throw new \RuntimeException('Named route not found for name: ' . $name); 188 | } 189 | $search = array(); 190 | foreach ($params as $key => $value) { 191 | $search[] = '#:' . preg_quote($key, '#') . '\+?(?!\w)#'; 192 | } 193 | $pattern = preg_replace($search, $params, $this->getNamedRoute($name)->getPattern()); 194 | 195 | //Remove remnants of unpopulated, trailing optional pattern segments, escaped special characters 196 | return preg_replace('#\(/?:.+\)|\(|\)|\\\\#', '', $pattern); 197 | } 198 | 199 | /** 200 | * Add named route 201 | * @param string $name The route name 202 | * @param \Slim\Route $route The route object 203 | * @throws \RuntimeException If a named route already exists with the same name 204 | */ 205 | public function addNamedRoute($name, \Slim\Route $route) 206 | { 207 | if ($this->hasNamedRoute($name)) { 208 | throw new \RuntimeException('Named route already exists with name: ' . $name); 209 | } 210 | $this->namedRoutes[(string) $name] = $route; 211 | } 212 | 213 | /** 214 | * Has named route 215 | * @param string $name The route name 216 | * @return bool 217 | */ 218 | public function hasNamedRoute($name) 219 | { 220 | $this->getNamedRoutes(); 221 | 222 | return isset($this->namedRoutes[(string) $name]); 223 | } 224 | 225 | /** 226 | * Get named route 227 | * @param string $name 228 | * @return \Slim\Route|null 229 | */ 230 | public function getNamedRoute($name) 231 | { 232 | $this->getNamedRoutes(); 233 | if ($this->hasNamedRoute($name)) { 234 | return $this->namedRoutes[(string) $name]; 235 | } else { 236 | return null; 237 | } 238 | } 239 | 240 | /** 241 | * Get named routes 242 | * @return \ArrayIterator 243 | */ 244 | public function getNamedRoutes() 245 | { 246 | if (is_null($this->namedRoutes)) { 247 | $this->namedRoutes = array(); 248 | foreach ($this->routes as $route) { 249 | if ($route->getName() !== null) { 250 | $this->addNamedRoute($route->getName(), $route); 251 | } 252 | } 253 | } 254 | 255 | return new \ArrayIterator($this->namedRoutes); 256 | } 257 | } 258 | -------------------------------------------------------------------------------- /files/root/www/wifidog/Slim/View.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2011 Josh Lockhart 7 | * @link http://www.slimframework.com 8 | * @license http://www.slimframework.com/license 9 | * @version 2.4.2 10 | * @package Slim 11 | * 12 | * MIT LICENSE 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining 15 | * a copy of this software and associated documentation files (the 16 | * "Software"), to deal in the Software without restriction, including 17 | * without limitation the rights to use, copy, modify, merge, publish, 18 | * distribute, sublicense, and/or sell copies of the Software, and to 19 | * permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be 23 | * included in all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | namespace Slim; 34 | 35 | /** 36 | * View 37 | * 38 | * The view is responsible for rendering a template. The view 39 | * should subclass \Slim\View and implement this interface: 40 | * 41 | * public render(string $template); 42 | * 43 | * This method should render the specified template and return 44 | * the resultant string. 45 | * 46 | * @package Slim 47 | * @author Josh Lockhart 48 | * @since 1.0.0 49 | */ 50 | class View 51 | { 52 | /** 53 | * Data available to the view templates 54 | * @var \Slim\Helper\Set 55 | */ 56 | protected $data; 57 | 58 | /** 59 | * Path to templates base directory (without trailing slash) 60 | * @var string 61 | */ 62 | protected $templatesDirectory; 63 | 64 | /** 65 | * Constructor 66 | */ 67 | public function __construct() 68 | { 69 | $this->data = new \Slim\Helper\Set(); 70 | } 71 | 72 | /******************************************************************************** 73 | * Data methods 74 | *******************************************************************************/ 75 | 76 | /** 77 | * Does view data have value with key? 78 | * @param string $key 79 | * @return boolean 80 | */ 81 | public function has($key) 82 | { 83 | return $this->data->has($key); 84 | } 85 | 86 | /** 87 | * Return view data value with key 88 | * @param string $key 89 | * @return mixed 90 | */ 91 | public function get($key) 92 | { 93 | return $this->data->get($key); 94 | } 95 | 96 | /** 97 | * Set view data value with key 98 | * @param string $key 99 | * @param mixed $value 100 | */ 101 | public function set($key, $value) 102 | { 103 | $this->data->set($key, $value); 104 | } 105 | 106 | /** 107 | * Set view data value as Closure with key 108 | * @param string $key 109 | * @param mixed $value 110 | */ 111 | public function keep($key, \Closure $value) 112 | { 113 | $this->data->keep($key, $value); 114 | } 115 | 116 | /** 117 | * Return view data 118 | * @return array 119 | */ 120 | public function all() 121 | { 122 | return $this->data->all(); 123 | } 124 | 125 | /** 126 | * Replace view data 127 | * @param array $data 128 | */ 129 | public function replace(array $data) 130 | { 131 | $this->data->replace($data); 132 | } 133 | 134 | /** 135 | * Clear view data 136 | */ 137 | public function clear() 138 | { 139 | $this->data->clear(); 140 | } 141 | 142 | /******************************************************************************** 143 | * Legacy data methods 144 | *******************************************************************************/ 145 | 146 | /** 147 | * DEPRECATION WARNING! This method will be removed in the next major point release 148 | * 149 | * Get data from view 150 | */ 151 | public function getData($key = null) 152 | { 153 | if (!is_null($key)) { 154 | return isset($this->data[$key]) ? $this->data[$key] : null; 155 | } else { 156 | return $this->data->all(); 157 | } 158 | } 159 | 160 | /** 161 | * DEPRECATION WARNING! This method will be removed in the next major point release 162 | * 163 | * Set data for view 164 | */ 165 | public function setData() 166 | { 167 | $args = func_get_args(); 168 | if (count($args) === 1 && is_array($args[0])) { 169 | $this->data->replace($args[0]); 170 | } elseif (count($args) === 2) { 171 | // Ensure original behavior is maintained. DO NOT invoke stored Closures. 172 | if (is_object($args[1]) && method_exists($args[1], '__invoke')) { 173 | $this->data->set($args[0], $this->data->protect($args[1])); 174 | } else { 175 | $this->data->set($args[0], $args[1]); 176 | } 177 | } else { 178 | throw new \InvalidArgumentException('Cannot set View data with provided arguments. Usage: `View::setData( $key, $value );` or `View::setData([ key => value, ... ]);`'); 179 | } 180 | } 181 | 182 | /** 183 | * DEPRECATION WARNING! This method will be removed in the next major point release 184 | * 185 | * Append data to view 186 | * @param array $data 187 | */ 188 | public function appendData($data) 189 | { 190 | if (!is_array($data)) { 191 | throw new \InvalidArgumentException('Cannot append view data. Expected array argument.'); 192 | } 193 | $this->data->replace($data); 194 | } 195 | 196 | /******************************************************************************** 197 | * Resolve template paths 198 | *******************************************************************************/ 199 | 200 | /** 201 | * Set the base directory that contains view templates 202 | * @param string $directory 203 | * @throws \InvalidArgumentException If directory is not a directory 204 | */ 205 | public function setTemplatesDirectory($directory) 206 | { 207 | $this->templatesDirectory = rtrim($directory, DIRECTORY_SEPARATOR); 208 | } 209 | 210 | /** 211 | * Get templates base directory 212 | * @return string 213 | */ 214 | public function getTemplatesDirectory() 215 | { 216 | return $this->templatesDirectory; 217 | } 218 | 219 | /** 220 | * Get fully qualified path to template file using templates base directory 221 | * @param string $file The template file pathname relative to templates base directory 222 | * @return string 223 | */ 224 | public function getTemplatePathname($file) 225 | { 226 | return $this->templatesDirectory . DIRECTORY_SEPARATOR . ltrim($file, DIRECTORY_SEPARATOR); 227 | } 228 | 229 | /******************************************************************************** 230 | * Rendering 231 | *******************************************************************************/ 232 | 233 | /** 234 | * Display template 235 | * 236 | * This method echoes the rendered template to the current output buffer 237 | * 238 | * @param string $template Pathname of template file relative to templates directory 239 | * @param array $data Any additonal data to be passed to the template. 240 | */ 241 | public function display($template, $data = null) 242 | { 243 | echo $this->fetch($template, $data); 244 | } 245 | 246 | /** 247 | * Return the contents of a rendered template file 248 | * 249 | * @param string $template The template pathname, relative to the template base directory 250 | * @param array $data Any additonal data to be passed to the template. 251 | * @return string The rendered template 252 | */ 253 | public function fetch($template, $data = null) 254 | { 255 | return $this->render($template, $data); 256 | } 257 | 258 | /** 259 | * Render a template file 260 | * 261 | * NOTE: This method should be overridden by custom view subclasses 262 | * 263 | * @param string $template The template pathname, relative to the template base directory 264 | * @param array $data Any additonal data to be passed to the template. 265 | * @return string The rendered template 266 | * @throws \RuntimeException If resolved template pathname is not a valid file 267 | */ 268 | protected function render($template, $data = null) 269 | { 270 | $templatePathname = $this->getTemplatePathname($template); 271 | if (!is_file($templatePathname)) { 272 | throw new \RuntimeException("View cannot render `$template` because the template does not exist"); 273 | } 274 | 275 | $data = array_merge($this->data->all(), (array) $data); 276 | extract($data); 277 | ob_start(); 278 | require $templatePathname; 279 | 280 | return ob_get_clean(); 281 | } 282 | } 283 | -------------------------------------------------------------------------------- /files/root/www/wifidog/assets/loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ewinds/luci-app-wifidog/657f1115b36e141881fa9b06d8d8f44836714d96/files/root/www/wifidog/assets/loader.gif -------------------------------------------------------------------------------- /files/root/www/wifidog/assets/ratchicons.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ewinds/luci-app-wifidog/657f1115b36e141881fa9b06d8d8f44836714d96/files/root/www/wifidog/assets/ratchicons.eot -------------------------------------------------------------------------------- /files/root/www/wifidog/assets/ratchicons.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Copyright (C) 2014 by original authors @ fontello.com 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /files/root/www/wifidog/assets/ratchicons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ewinds/luci-app-wifidog/657f1115b36e141881fa9b06d8d8f44836714d96/files/root/www/wifidog/assets/ratchicons.ttf -------------------------------------------------------------------------------- /files/root/www/wifidog/assets/ratchicons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ewinds/luci-app-wifidog/657f1115b36e141881fa9b06d8d8f44836714d96/files/root/www/wifidog/assets/ratchicons.woff -------------------------------------------------------------------------------- /files/root/www/wifidog/index.php: -------------------------------------------------------------------------------- 1 | gwAddress = trim(shell_exec('uci get wifidog.settings.gateway_host')); 8 | $app->gwPort = trim(shell_exec('uci get wifidog.settings.gatewayport')); 9 | $app->gwName = trim(shell_exec('uci get wifidog.settings.gateway_hostname')); 10 | $app->timeLimit = trim(shell_exec('uci get wifidog.settings.client_time_limit')); 11 | $app->gwMac = preg_replace('/(.+)HWaddr (.+)/i', '${2}', trim(shell_exec('ifconfig br-lan | grep HWaddr'))); 12 | $app->gwId = str_replace(':', '', $app->gwMac); 13 | 14 | $app->get('/hello/:name', function ($name) use ($app) { 15 | echo "Hello, ".$name."
"; 16 | }); 17 | 18 | $app->get('/login', function () use ($app) { 19 | $db = $app->dao; 20 | parse_str($app->environment['QUERY_STRING']); 21 | $isReturnUser = $app->getCookie('is_return_user'); 22 | // $user = $db->query("SELECT * FROM users WHERE mac = '{$mac}'"); 23 | 24 | if(!$isReturnUser) { 25 | // echo 'mac was not found.'; 26 | $app->render('touch.php', array('mac' => $mac, 'title' => $app->gwName)); 27 | } 28 | else { 29 | $app->render('touch.php', array('title' => $app->gwName)); 30 | } 31 | 32 | $db = null; 33 | }); 34 | 35 | $app->post('/users', function() use ($app) { 36 | $db = $app->dao; 37 | $params = $app->request->post(); 38 | $user = $db->query("SELECT * FROM users WHERE phone = '{$params['phone']}'")->fetch(); 39 | 40 | if(!$user) { 41 | $db->exec("INSERT INTO users (phone, mac) 42 | VALUES ('{$params['phone']}', '{$params['mac']}')"); 43 | } 44 | else { 45 | $db->exec("UPDATE users SET mac = '{$params['mac']}', updated_at = datetime('now', 'localtime') WHERE id = {$user['id']}"); 46 | } 47 | 48 | $db = null; 49 | $app->setCookie('is_return_user', true, '365 days'); 50 | $app->halt(200, '{ "error": "" }'); 51 | }); 52 | 53 | $app->get('/portal', function() use ($app) { 54 | $app->render('show.php', array('title' => $app->gwName, 'id' => $app->gwId)); 55 | }); 56 | 57 | $app->get('/portal/touch', function() use ($app) { 58 | $db = $app->dao; 59 | $uuid = $app->uuid; 60 | $id = $app->uuid; 61 | $offset = $app->timeLimit; 62 | $db->exec("INSERT INTO connections (id, token, expires_on) 63 | VALUES ('{$id}', '{$uuid}', datetime(datetime('now','localtime'), '+{$offset} minutes'))"); 64 | $db = null; 65 | $app->redirect("http://{$app->gwAddress}:{$app->gwPort}/wifidog/auth?token={$uuid}"); 66 | }); 67 | 68 | $app->get('/ping', function () use ($app) { 69 | $db = $app->dao; 70 | parse_str($app->environment['QUERY_STRING']); 71 | $db->exec("UPDATE gateways SET sys_uptime = {$sys_uptime}, sys_load = {$sys_load}, sys_memfree = {$sys_memfree}, wifidog_uptime = {$wifidog_uptime}, last_seen = datetime('now','localtime'), updated_at = datetime('now','localtime') WHERE id = 1"); 72 | $db = null; 73 | $app->halt(200, 'Pong'); 74 | }); 75 | 76 | $app->get('/auth', function () use ($app) { 77 | $auth = 0; 78 | $db = $app->dao; 79 | parse_str($app->environment['QUERY_STRING']); 80 | $connection = $db->query("SELECT * FROM connections WHERE token = '{$token}'")->fetch(); 81 | 82 | if (!$connection) { 83 | $auth = 6; 84 | } 85 | else { 86 | switch ($stage) { 87 | case 'login': 88 | $expires_on = $connection['expires_on']; 89 | echo (strtotime($expires_on) < strtotime('now')); 90 | 91 | if ($connection['used_on'] != '' || ($expires_on != '' && strtotime($expires_on) < strtotime('now'))) { 92 | // Tried to login with used or expired token 93 | $auth = 6; 94 | } else { 95 | # Login normal 96 | $db->exec("UPDATE connections SET used_on = datetime('now', 'localtime'), updated_at = datetime('now', 'localtime') WHERE id = '{$connection['id']}'"); 97 | $auth = 1; 98 | } 99 | 100 | break; 101 | 102 | case 'counters': 103 | $expires_on = $connection['expires_on']; 104 | 105 | if ($expires_on == '' || strtotime($expires_on) > strtotime('now')) { 106 | $db->exec("UPDATE connections SET ip = '{$ip}', mac = '{$mac}', incoming_bytes = {$incoming}, outgoing_bytes = {$outgoing}, updated_at = datetime('now', 'localtime') WHERE id = '{$connection['id']}'"); 107 | $auth = 1; 108 | } 109 | 110 | break; 111 | 112 | case 'logout': 113 | $db->exec("UPDATE connections SET expires_on = datetime('now', 'localtime'), updated_at = datetime('now', 'localtime') WHERE id = '{$connection['id']}'"); 114 | break; 115 | 116 | default: 117 | # code... 118 | break; 119 | } 120 | } 121 | 122 | $db = null; 123 | $app->halt(200, "Auth: {$auth}"); 124 | }); 125 | 126 | $app->get('/cnzz/:id', function ($id) use ($app) { 127 | $app->render('701.html'); 128 | }); 129 | 130 | $app->get('/info', function () use ($app) { 131 | phpinfo(); 132 | }); 133 | 134 | $app->get('/list_images', function () use ($app) { 135 | if ($handle = opendir('./assets/ads')) { 136 | 137 | while (false !== ($entry = readdir($handle))) { 138 | 139 | if ($entry != "." && $entry != "..") { 140 | 141 | echo "$entry\n"; 142 | } 143 | } 144 | 145 | closedir($handle); 146 | } 147 | }); 148 | 149 | $app->dao = function () use ($app) { 150 | $db = null; 151 | 152 | try { 153 | $db = new PDO('sqlite:/tmp/wifidog.sqlite3'); 154 | //$db->setAttribute(PDO::ATTR_ERRMODE, 155 | // PDO::ERRMODE_EXCEPTION); 156 | $result = $db->query('SELECT * FROM gateways'); 157 | 158 | if(!$result) { 159 | // echo "gateways was not existed."; 160 | $db->exec("CREATE TABLE IF NOT EXISTS gateways ( 161 | id INTEGER PRIMARY KEY, 162 | sys_uptime INTEGER DEFAULT 0, 163 | sys_load INTEGER DEFAULT 0, 164 | sys_memfree INTEGER DEFAULT 0, 165 | wifidog_uptime INTEGER DEFAULT 0, 166 | last_seen DATETIME, 167 | created_at DATETIME DEFAULT (datetime('now','localtime')), 168 | updated_at DATETIME DEFAULT (datetime('now','localtime')))"); 169 | 170 | $db->exec("CREATE TABLE IF NOT EXISTS connections ( 171 | id VARCHAR(255) PRIMARY KEY, 172 | token VARCHAR(255), 173 | expires_on DATETIME, 174 | used_on DATETIME, 175 | ip VARCHAR(255), 176 | mac VARCHAR(255), 177 | incoming_bytes INTEGER DEFAULT 0, 178 | outgoing_bytes INTEGER DEFAULT 0, 179 | created_at DATETIME DEFAULT (datetime('now','localtime')), 180 | updated_at DATETIME DEFAULT (datetime('now','localtime')))"); 181 | 182 | $db->exec("CREATE TABLE IF NOT EXISTS users ( 183 | id INTEGER PRIMARY KEY AUTOINCREMENT, 184 | mac VARCHAR(255), 185 | phone VARCHAR(255), 186 | created_at DATETIME DEFAULT (datetime('now','localtime')), 187 | updated_at DATETIME DEFAULT (datetime('now','localtime')))"); 188 | 189 | $db->exec("INSERT INTO gateways (id) VALUES (1)"); 190 | } 191 | //var_dump($result); 192 | //echo count($result); 193 | } 194 | catch(PDOException $e) { 195 | echo $e->getMessage(); 196 | $db = null; 197 | } 198 | 199 | return $db; 200 | }; 201 | $app->uuid = function() { 202 | return exec('uuidgen'); 203 | }; 204 | 205 | $app->run(); -------------------------------------------------------------------------------- /files/root/www/wifidog/jobs/sync.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php-cli -q 2 | find('pre') as $element) { 8 | // echo $element->innertext; 9 | // } 10 | $db = new PDO('sqlite:/tmp/wifidog.sqlite3'); 11 | $gwMac = preg_replace('/(.+)HWaddr (.+)/i', '${2}', trim(shell_exec('ifconfig br-lan | grep HWaddr'))); 12 | $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 13 | $db->exec("UPDATE connections SET expires_on = datetime('now', 'localtime'), updated_at = datetime('now', 'localtime') WHERE used_on is not null and updated_at <= datetime(datetime('now','localtime'), '-5 minutes') and expires_on > datetime('now', 'localtime')"); 14 | $gateway = $db->query("SELECT * FROM gateways WHERE id = '1'")->fetch(PDO::FETCH_ASSOC); 15 | $users = $db->query("SELECT * FROM users WHERE updated_at > datetime(datetime('now','localtime'), '-5 minutes')")->fetchAll(PDO::FETCH_ASSOC); 16 | $connections = $db->query("SELECT * FROM connections WHERE used_on is not null and updated_at > datetime(datetime('now','localtime'), '-5 minutes')")->fetchAll(PDO::FETCH_ASSOC); 17 | $data = array('gw_id' => $gwMac, 'gateway' => $gateway, 'users' => $users, 'connections' => $connections); 18 | $data_string = json_encode($data); 19 | $db = null; 20 | // echo $data_string; 21 | 22 | $ch = curl_init('http://392a21d6.ngrok.com/portal/sync.json'); 23 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 24 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 25 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 26 | curl_setopt($ch, CURLOPT_HTTPHEADER, array( 27 | 'Content-Type: application/json', 28 | 'Content-Length: ' . strlen($data_string)) 29 | ); 30 | 31 | $result = curl_exec($ch); 32 | // var_dump($result); 33 | $response = curl_getinfo( $ch ); 34 | // var_dump($response); 35 | curl_close ( $ch ); 36 | ?> -------------------------------------------------------------------------------- /files/root/www/wifidog/templates/701.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 7 | 8 | 9 | 10 |
11 |
12 |

The page you were looking for doesn't exist.

13 |

You may have mistyped the address or the page may have moved.

14 |
15 |

If you are the application owner check the logs for more information.

16 |
17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /files/root/www/wifidog/templates/show.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | <?= $title ?> 10 | 11 | 12 | 13 | 14 | 15 |
16 |

17 |
18 | 20 |
21 | 24 |
    25 |
  • 26 |
    正在连接免费Wi-Fi网络, 27 |
    秒后点击完成上网
    28 |
  • 29 |
30 |
31 |
32 |
Loader 33 |
34 |
35 |
    36 |
  • 37 |
38 |
39 |
40 | 60 | 65 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /files/root/www/wifidog/templates/touch.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | <?= $title ?> 10 | 11 | 12 | 13 | 14 | 15 |
16 |

17 |
18 |
19 |
20 |
21 |
22 | 23 |
24 |
25 | 26 |
27 |
28 |
    29 |
  • 30 |
31 |
32 | 33 |
34 |
35 | 36 |
37 |
    38 |
  • 39 |

    为了向您提供安全可靠的免费Wi-Fi服务,用户首次使用需获取手机短信验证码注册

  • 40 |
  • 41 | 42 | 43 |
  • 44 |
  • 45 | 47 |
    48 |
    49 |
    50 |
  • 51 |
52 |
53 |
54 | 55 |
56 | 57 |
    58 |
  • 59 |

    欢迎您再次使用万罗热点,享受免费Wi-Fi服务

    60 |
  • 61 |
  • 62 | 64 |
    65 |
    66 |
    67 |
  • 68 |
69 |
70 | 71 |
72 | 73 |
74 | 89 | 91 | 192 | 193 | 194 | --------------------------------------------------------------------------------