Check-in [2e1e35664b]
Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Comment: | Initial website implementation: project submit, index listing, projects/ page, and moderation flags. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk | 0.1 |
Files: | files | file ages | folders |
SHA1: |
2e1e35664b165b930ad224dd3b83c3a0 |
User & Date: | mario 2014-06-25 06:10:43 |
2014-06-25
| ||
21:47 | Remove debugging output in session, prettify login box, input::has() and ::no() correctly accept list of key names, add jquery check-in: f97f92af3c user: mario tags: trunk | |
06:10 | Initial website implementation: project submit, index listing, projects/ page, and moderation flags. check-in: 2e1e35664b user: mario tags: trunk, 0.1 | |
06:05 | initial empty check-in check-in: 82405bb421 user: mario tags: trunk | |
Added .htaccess.
> > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # encoding: UTF-8 # api: apache # title: RewriteRules # description: Map paths onto dispatcher script # # RewriteEngine On # strip www. prefix RewriteCond %{HTTP_HOST} ^ww+\.(\w+\.\w+)\.?$ RewriteCond %{REQUEST_METHOD} ^GET$ RewriteRule ^(.*)$ http://%1/$1 [R,QSA,L] # pages RewriteRule ^$ index.php?page=index [L,QSA] RewriteRule ^(projects|submit|flag|tags|feed|links|admin)/?(\w+)?/?$ index.php?page=$1&name=$2 [L,QSA] # deny direct invocations RewriteRule ^^^freshcode\.db.*$$$ - [F] RewriteRule ^\. - [F] RewriteRule ^(?!index\.)\w+\.php($$$|/.*)$ - [F] |
Added config.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | <?php /** * api: freshcode * title: Freshcode.club config * description: initialization code * version: 0.1 * plugin-register: include_once("$FN"); * * */ define("INPUT_QUIET", 1); define("INPUT_DIRECT", "trim"); include_once("input.php"); include_once("db.php"); db("connect", "sqlite:freshcode.db"); define("LOGIN_REQUIRED", 1); define("HTTP_HOST", $_SERVER->id["HTTP_HOST"]); include_once("deferred_openid_session.php"); // List of moderator OpenID handles $moderator_ids = array( ); #-- Additional input filters // String from 3 to 33 chars function length_3to33($s) { return (strlen($s) >= 3 and strlen($s) <= 33) ? $s : NULL; } // Length of strings in arrays > 100 function min_length_100($a) { return array_sum(array_map("strlen", $a)) >= 100; } #-- Template helpers // Wrap tag list into links function wrap_tags($tags, $r="") { foreach (str_getcsv($tags) as $id) { $id = trim($id); $r .= "<a href=\"/tags/$id\">$id</a>"; } return $r; } // Return DAY MONTH and TIME or YEAR for older entries function date_fmt($time) { $lastyear = time() - $time > 250*24*3600; return strftime($lastyear ? "%d %b %Y" : "%d %b %H:%M", $time); } // Substitute `$version` placeholders in URLs function versioned_url($url, $version) { return preg_replace("/([\$%])(version|Version|VERSION)\b\\1?/", $version, $url); } // General output preparation function prepare_output(&$entry) { $entry["download"] = versioned_url($entry["download"], $entry["version"]); $entry["image"] or $entry["image"] = "/img/nopreview.png"; $entry["formatted_date"] = date_fmt($entry["t_published"]); $entry = array_map("input::_html", $entry); } #-- Data handling function p_key_value($str) { # preg_match_all("~ [%\$]?(\w+) \s*[:=]+\s* (\S+) (?<![,.;]) ~imsx", $str, $m); preg_match_all("~ (\w+) \s*=\s* (\S+) ~imsx", $str, $m); return array_combine($m[1], $m[2]); } ?> |
Added db.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | <?php /** * title: database * description: basic db() interface for parameterized SQL and result folding * api: php * type: database * version: 0.7 * depends: pdo * license: Public Domain * author: Mario Salzer * url: http://php7framework.sourceforge.net/ * * * QUERY * * Provides simple database queries with enumerated or named parameters. It's * flexible in accepting scalar arguments and arrays. Array args get merged, * or transcribed when special placeholders are present: * * $r = db("SELECT * FROM tbl WHERE a>=? AND b IN (??)", $a, array($b)); * * Two ?? are used for interpolating arrays, which is useful for IN clauses. * The placeholder :? interpolates key names (doesn't add values). * And :& or :, or :| become a name=:assign list grouped by AND, comma, OR. * Whereas :: turns into a simple :named,:value,:list (for IN clauses). * Also configurable {TOKENS} are replaced automatically (db()->tokens[]). * * RESULT * * The returned result can be accessed as single data row, with $data->column * or using $data["column"]. * Or if it's a result list, foreach() can iterate over all returned rows. * And all PDO ->fetch() methods are still available for use on the result obj. * ArrayObjects cannot be used like real arrays in all contexts; typecasting * the data out is not possible, in string context curly braces "{$a->x}" are * necessary, and in sub-loops needed object syntax "foreach ($a->subarray as)" * * CONNECT * * The db() interface utilizes the global "$db" variable. Which could also be * instantiated separately or using: * db("connect", array("mysql:host=localhost;dbname=test","username","password")); * * RECORD WRAPPER * * There's also a simple table data gateway wrapper implemented here. It * accepts db() queries for single entries, and allows ->save()ing back, or * to ->delete() records. * You should only use it in conjuction with sql2php and its simpler wrappers. * */ /** * SQL query. * */ function db($sql=NULL, $params="...") { global $db; #-- open database if ($sql == "connect") { // DSN $params = is_array($params) ? array_values($params) : array($params,"",""); $db = new PDO($params[0], $params[1], $params[2]); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); // save settings $db->tokens = array("PREFIX"=>""); // or reference global $config $db->broken = strstr($params[0], "sqlite"); } #-- singleton use elseif (empty($sql)) { return $db; } #-- reject SQL elseif (strpos($sql, "'")) { trigger_error("SQL query contained raw data. DO NOT WANT", E_USER_WARNING); } #-- execute SQL else { #-- get $params $params2 = array(); $args = func_get_args(); array_shift($args); #-- flattening sub-arrays (works for ? enumarated and :named params) foreach ($args as $i=>$a) { if (is_array($a)) { $enum = is_int(end(array_keys($a))); // subarray corresponds to special syntax placeholder? if (preg_match("/\?\?|:\?|::|:&|:,|&\|/", $sql, $uu, PREG_OFFSET_CAPTURE)) { list($token, $pos) = $uu[0]; switch ($token) { case "??": // replace ?? array placeholders $replace = implode(",", array_fill(0, count($a), "?")); break; case ":?": // and :? name placeholder, transforms list into enumerated params $replace = implode(",", db_identifier($enum ? $a : array_keys($a)) ); $enum = 1; $a = array(); // do not actually add values break; case "::": // inject :named,:value,:list $replace = ":" . implode(",:", db_identifier(array_keys($a)) ); break; case ":&": // associative params - becomes "key=:key AND .." case ":,": // COMMA-separated case ":|": // OR-separated $fill = array(":&"=>" AND ", ":,"=>" , ", ":|"=>" OR "); $replace = array(); foreach (db_identifier(array_keys($a)) as $key) { $replace[] = "`$key`=:$key"; } $replace = implode($fill[$token], $replace); } // update SQL string $sql = substr($sql, 0, $pos) . $replace . substr($sql, $pos + strlen($token)); } // unfold if ($enum) { $params2 = array_merge($params2, $a); } else { $params2 = array_merge($params2, $a); } } else { $params2[] = $a; } } #-- placeholders if ($db->tokens && strpos($sql, "{")) { $sql = preg_replace("/\{(\w+)(.*?)\}/e", 'isset($db->token["$1"]) ? $db->token["$1"]."$2" : @$db->token["$1$2"]', $sql); } #-- SQL incompliance workarounds if ($db->broken && strpos($sql, " IN (")) { // only for ?,?,?,? enum params $sql = preg_replace("/(`?\w+`?) IN \(([?,]+)\)/e", '"($1=" . implode("OR $1=", array_fill(0, 1+strlen("$2")/2, "? ")) . ")"', $sql); } if (isset($db->test)) { print json_encode($params2)." => " . trim($sql) . "\n"; return; } #-- run $s = $db->prepare($sql); $s->setFetchMode(PDO::FETCH_ASSOC); $r = $s->execute($params2); #-- wrap return $r ? new db_result($s) : $s; } } // This is a restrictive filter function or column/table name identifiers. function db_identifier($as) { return preg_replace("/[^\w\d_.]/", "_", $as); // Can only be foregone if it's ensured that none of the passed named db() $arg keys originated from http/user input. } /** * Allows list access, or fetches first result[0] * */ class db_result extends ArrayObject implements IteratorAggregate { function __construct($results) { $this->results = $results; parent::__construct(array(), 2); } // single access function __get($name) { // get first result, transfuse into $this if ($this->results) { foreach ($this->results->fetch(PDO::FETCH_ASSOC) as $key=>$value) { $this->{$key} = $value; } unset($this->results); } // suffice __get return $this->{$name}; } // used as PDO statement function __call($func, $args) { return call_user_func_array(array($this->results, $func), $args); } // iterator function getIterator() { if (isset($this->results)) { $this->results->setFetchMode(PDO::FETCH_CLASS, "ArrayObject", array(array(), 2)); return $this->results; } else return new ArrayIterator($this); } } /** * Table data gateway. Don't use directly. * * Keeps ->_meta->table name and ->_meta->fields, * uses extendable tables with [ext] field serialization. * Doesn't cope with table joins. (yet?) * * Allows to ->set() and ->save() record back. */ class db_record /*resembles db_result*/ extends ArrayObject { // this is not purposelessly private, but to not pollute (array) typecasts with decorative data private $_meta; // initialize from db() result or array function __construct($results, $table, $fields, $keys) { // meta $this->_meta = new stdClass(); $this->_meta->table = $table; $this->_meta->fields = array_unique(array_merge(array_keys($fields), array_keys($results))); $this->_meta->keys = $keys; // db query result if (is_array($results)) { $this->_meta->new = 1; // instantiate from defaults or given row values } else { //if (is_string($results)) { // queries are handled in wrapper // $results = db($results); //} $results = $results->fetch(); // just get first result row $this->_meta->new = 0; } // unfold .ext if ($this->_meta->ext = isset($results["ext"])) { $results = array_merge($results, unserialize($results["ext"])); } // copy data // and turn object==array parent::__construct((array)$results, 2); //ArrayObject::ARRAY_AS_PROPS // fluent (hybrid constructor wrapper) return $this; } // set field function set($key, $val) { $this->{$key} = $val; return $this; // fluent } // store table back to DB function save($row=NULL) { // source if (empty($row)) { $row = $this->getArrayCopy(); } else { $row = array_merge($this->getArrayCopy(), is_array($row) ? $row : $row->getArrayCopy()); } // fold .ext if ($this->_meta->ext) { $ext = array(); foreach ($row as $key=>$val) { if (!in_array($key, $this->_meta->fields)) { $ext[$key] = $val; unset($row[$key]); } } $row["ext"] = serialize($ext); } // store if ($this->_meta->new) { db("INSERT INTO {$this->_meta->table} (:?) VALUES (??)", $row, $row); $this->_meta->new = 0; } // update else { $keys = $this->keys($row, 1); db("UPDATE {$this->_meta->table} SET :, WHERE :&", $row, $keys); } return $this; // fluent } // split $keys from $row/$this function keys(&$row, $unset=0) { $keys = array(); foreach ($this->_meta->keys as $key) { $keys[$key] = $row[$key]; if ($unset) unset($row[$key]); } return $keys; } // oh noooes function delete() { db("DELETE FROM {$this->_meta->table} WHERE :&", $this->keys($this)); return $this; // well } } ?> |
Added db.sql.
> > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # # title: freshcode database schema # version: 0.2 # CREATE TABLE [release] ([name] VARCHAR (100) NOT NULL, [title] TEXT NOT NULL, [homepage] TEXT, [description] TEXT NOT NULL, [license] VARCHAR (100), [tags] VARCHAR (200), [version] VARCHAR (100) NOT NULL, [state] VARCHAR (20), [scope] VARCHAR (20), [changes] TEXT, [download] TEXT, [urls] TEXT, [autoupdate_module] VARCHAR (20), [autoupdate_url] TEXT, [autoupdate_regex] TEXT, [t_published] INT, [t_changed] INT, [flag] INT DEFAULT(0), [deleted] BOOLEAN DEFAULT(0), [submitter_openid] TEXT, [submitter] VARCHAR (0, 50), [lock] TEXT, [hidden] BOOLEAN DEFAULT(0), [image] TEXT); CREATE INDEX idx_release ON [release] ( name , version COLLATE NOCASE , t_changed DESC ); CREATE VIEW [release_view] AS SELECT * FROM [release] WHERE NOT deleted AND NOT hidden AND flag < 5 GROUP BY version , t_changed ORDER BY t_published DESC; CREATE TABLE flags (name TEXT, reason TEXT, note TEXT, submitter_openid TEXT, submitter_ip TEXT); |
Added deferred_openid_session.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | <?php /** * api: php * title: Session startup * description: Avoids session startup until actual login occured * * Start $_SESSION only if there's already a session cookie present. * (Prevent needless cookies and tracking ids for not logged-in users.) * * The only handler that initiates any login process is `page_login.php` * */ // Kill off CloudFlare cookie when Do-Not-Track header present if ($_SERVER->has("HTTP_DNT") and $_SERVER->boolean["HTTP_DNT"]) { header("Set-Cookie: __cfduid= ; path=/; domain=.freshcode.club; HttpOnly"); } // Check for pre-existant cookie before defaulting to initiate session store if ($_COOKIE->has("USER")) { session_fresh(); } // verify incoming OpenID request if ($_GET->has("openid_mode")) { include_once("openid.php"); $openid = new LightOpenID(HTTP_HOST); if ($openid->mode) { if ($openid->validate()) { $_COOKIE->no("USER") and session_fresh(); $_SESSION["openid"] = $openid->identity; $_SESSION["name"] = $openid->getAttributes()["namePerson/friendly"]; print_r($_SESSION); } } } // Prevent some session tampering function session_fresh() { // Initiate with current session identifier if ($_COOKIE->has("USER")) { session_id($_COOKIE->id["USER"]); } session_name("USER"); session_set_cookie_params(0, "/", HTTP_HOST, false, true); session_start(); // Security by obscurity: lock client against User-Agent $useragent = $_SERVER->text->lengthβ¦30["HTTP_USER_AGENT"]; // Security by obscurity: IP subnet lock (or just major route for IPv6) $subnet = $_SERVER->ip->lengthβ¦6["REMOTE_ADDR"]; // Server-side timeout (7 days) $expire = time() + 7 * 24 * 3600; // New ID for mismatches if (empty($_SESSION["state/client"]) or $_SESSION["state/client"] != $useragent or empty($_SESSION["state/subnet"]) or $_SESSION["state/subnet"] != $subnet or empty($_SESSION["state/expire"]) or $_SESSION["state/expire"] < time() ) { session_destroy(); session_regenerate_id(true); session_start(); } // and Repopulate status fields $_SESSION["state/client"] = $useragent; $_SESSION["state/subnet"] = $subnet; $_SESSION["state/expire"] = $expire; } |
Added freshcode.css.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | * { font-family: Verdana, Arial; font-size: 12pt; } html, body { padding: 0; margin: 0; background: #fff; } a { text-decoration: none; } em { color: #723; } img { vertical-align: middle; border: 0; } #topbar { background: #555599; padding: 3pt 150pt; color: #fff; } #topbar a { color: #fec; } #topbar a:hover { color: #fc7; } #logo { padding: 10pt 150pt; height: 95pt; border-bottom: 2.5pt solid #bbb; background: #dddedf; background: linear-gradient(to bottom, #e5e6e9 0%, #dddedf 100%); } #logo img { padding: 0px 10px; } #logo .empty-box { height: 100px; margin: 5px; float: right; width: 67%; background: #fdfdfd; border: 1pt solid #777; } #tools { margin: 0 150pt; padding: 4pt; border: 1.75pt solid #bbb; border-top: 1pt solid #ccc; border-radius: 5pt; background: #e5e7e9; background: linear-gradient(to bottom, #ffffff, #fdfefe, #f5f7f9, #eaecee, #e5e7e9, #e1e3e5, #d0d1d2); position: relative; top: -15pt; } #tools a { color: #777; margin: 0 1pt; padding: 2pt 8pt; border-radius: 4pt; } #tools a.submit { background: #79d; background: linear-gradient(145deg,#e5e5ef,#d1d3df); color: #111; } #tools a:hover { color: #fff; background: #346; } #sidebar { float: right; width: 17%; margin: 25pt 150pt 25pt 25pt; min-width: 175pt; min-height: 400pt; background: #fefdfd; } #sidebar section { border: 1.5pt solid #ccc; border-radius: 5.75pt; background: #eee linear-gradient(#fcfcfc, #fafafa, #f7f7f7, #f2f2f2, #eeeeee, #dddddd); padding: 3pt; margin-bottom: 10pt; } #sidebar section h5 { margin: 1pt; border-bottom: 1px solid #ddd; } #main { margin: 20pt 150pt; width: 50%; min-height: 400pt; } #main h2, #main h3, #main h4 { background: #ddd; background: linear-gradient(#f3f3f3,#f0f0f0,#eee,#e7e7e7,#d3d3d3); border-radius: 2pt; padding: 3.5pt 5pt; margin-top: 25pt; } #main label { display: block; margin: 10pt 0; font-weight: 700; } #main label input, #main label textarea { display: block; font-weight: 400; } #main label input[type=radio] { display: inline; } #main label small { display: block; font-weight: 200; font-size: 70%; color: #777; } #main label small * { font-size: 70%; } #main label.inline { font-weight: 200; margin: 4pt; } #main label.inline input { display: inline; } #main .box { margin: 20pt; padding: 50pt; border-radius: 5pt; border: 3pt solid #357; background: #7ae; background: linear-gradient(145deg,#7ae,#39d); } #main .box input { border-radius: 5pt; border: 1.75pt solid #579; padding: 3pt; margin: 3pt; background: #f7faff; } #main .project h3 a { color: #000; } #main .project h3 a:hover, #main .project h3 a:hover .version { color: #237; } #main .project .version { font-style: normal; font-weight: 200; } #main .project .links { float: right; } #main .project .published_date { font-weight: 200; font-size: 65%; color: #777; } #main .project img.preview { padding: 3px; border: 1px solid #eee; margin: 3pt; } #main .project .description { padding-bottom: 5pt; border-bottom: 1px solid #ccc; margin-bottom: 3pt; font-size: 95%; color: #222; } #main .release-notes { margin-top: 5pt; font-size: 90%; color: #444; padding-left: 30pt; } #main .release-notes b { font-size: 90%; color: #555; } #main .project .tags a { font-size: 75%; color: #222; background: #eee linear-gradient(to bottom,#ddd,#eee); border: 1px solid #fff; border-left: 1px dotted #ccc; padding: 3px; } #main .project .tags a.license { background: #e9e3d0 linear-gradient(to bottom,#e3e0c7,#e9e3d0); } #main .project .long-tags span { border: 1px solid #ddd; background: #eee; padding: 1pt 8pt; border-radius: 4pt; margin-right: 30pt; font-size: 80%; } #main .project .long-tags a { padding: 2pt 5pt; } #main .project .long-links a, #sidebar section .long-links { border: 1px solid #79f; background: #47d; padding: 2pt 8pt; border-radius: 4pt; margin-right: 15pt; font-size: 115%; color: #fff; } #main .project .long-links a:hover { color: red; } #main .release-list div.release-entry { margin-bottom: 15pt; } #main .release-list .version, #main .release-list .published_date { background: #57b; padding: 1pt 8pt; border-radius: 5pt 0 0 5pt; color: #fff; font-size: 80%; } #main .release-list .published_date { background: #666; border-radius: 0 5pt 5pt 0; } #main .release-list .release-notes { display: block; } #spotlight { margin-top: 50pt; border-top: 3pt solid #B7C0BB; background: #E7E7D0; padding: 10pt 150pt; color: #111; height: 70pt; } #bottom { border-top: 3pt solid #5F677F; background: #444477; padding: 10pt 150pt; color: #fff; height: 50pt; } #bottom a { color: #fc9; } |
Added img/disk.png.
cannot compute difference between binary files
Added img/home.png.
cannot compute difference between binary files
Added img/nopreview.png.
cannot compute difference between binary files
Added img/tag.png.
cannot compute difference between binary files
Added index.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 | <?php /** * api: php * title: Freshcode.club * description: FLOSS software release tracking website * version: 0.1 * author: mario * license: MITL * * Implements a freshmeat/freecode-like directory for open source * release publishing / tracking. * */ #-- init include("config.php"); #-- dispatch switch ($page = $_GET->id["page"]) { case "index": case "projects": case "feed": case "links": case "tags": include("page_$page.php"); break; case "flag": case "submit": if (LOGIN_REQUIRED and empty($_SESSION["openid"])) { exit(include("page_login.php")); } include("page_$page.php"); break; case "admin": if (!in_array($_SESSION["openid"], $moderator_ids)) { exit(include("page_login.php")); } include("page_admin.php"); break; default: include("page_error.php"); } ?> |
Added input.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 | <?php /** * api: php * title: Input $_REQUEST wrappers * type: interface * description: Encapsulates input variable superglobals for easy sanitization access * version: 2.7 * revision: $Id$ * license: Public Domain * depends: php:filter, php >5.0, html_purifier * config: <const name="INPUT_DIRECT" type="multi" value="disallow" multi="disallow|raw|log" description="filter method for direct $_REQUEST[var] access" /> * <const name="INPUT_QUIET" type="bool" value="0" multi="0=report all|1=no notices|2=no warnings" description="suppress access and behaviour notices" /> * throws: E_USER_NOTICE, E_USER_WARNING, OutOfBoundsException * * Using these object wrappers ensures a single entry point and verification * spot for all user data. They wrap all superglobals and filter HTTP input * through sanitizing methods. For auditing casual and unverified access. * * Standardly they wrap: $_REQUEST, $_GET, $_POST, $_SERVER, $_COOKIE * And provide convenient access to filtered data: * $_GET->int("page_num") // method * $_POST->text["commentfield"] // array syntax * $_REQUEST->text->ascii->strtolower["xyz"] // filter chains * * Available filter methods are: * ->int * ->float * ->boolean * ->name * ->id * ->words * ->text * ->ascii * ->nocontrol * ->spaces * ->q * ->escape * ->regex * ->in_array * ->html * ->purify * ->json * ->length * ->range * ->default * And most useful methods of the php filter extension. * ->email * ->url ->uri ->http * ->ip * ->ipv4->public * PHP string modification functions: * ->urlencode * ->strip_tags * ->htmlentities * ->strtolower * Automatic filter chain handler: * ->array * Fetch multiple variables at once: * ->list["var1,key,name"] * Process multiple entries as array: * ->multi->http_build_query["id,token"] * Possible but should be used very consciously: * ->xss * ->sql * ->mysql * ->log * ->raw * * You can also pre-define a standard filter-chain for all following calls: * $_GET->nocontrol->iconv->utf7->xss->always(); * * Using $__rules[] a set of filter rules can be preset per variable name. * * Parameterized filters can alternatively use the ellipsis β¦ symbol (AltGr+:) * instead of the terminating method access syntax. * $_GET->int->rangeβ¦0β¦59["minutes"] * * Some filters are a mixture of sanitizing and validation. Basically * all can also be used independently of the superglobals with their * underscore name, $str = input::_text($str); * * For the superglobals it's also possible to count($_GET); or check with * just $_POST() if there are contents. (Use this in lieu of empty() test.) * There are also the three functions ->has ->no ->keys() for array lookup. * * Defining new filters can be done as methods, or since those are picked * up too, as plain global functions. It's also possible to assign function * aliases or attach closures: * $_POST->_newfilter = function($s) { return modified($s); } * Note that the assigned filter name must have an underscore prefixed. * * -- * * Input validation of course is no substitute for secure application logic, * parameterized sql and proper output encoding. But this methodology is a * good base and streamlines input data handling. * * Filter methods can be bypassed in any number of ways. There's no effort * made at prevention here. But it's recommended to simply use ->raw() when * needed - not all input can be filtered anyway. This way an audit handler * could always attach there - when desired. * * The goal is not to coerce, but encourage security via API *simplicity*. * */ /** * Handler name for direct $_REQUEST["array"] access. * * "raw" = reports with warning, * "disallow" = throws an exception */ defined("INPUT_DIRECT") or define("INPUT_DIRECT", "raw"); /** * Notice suppression. * * 0 = report all, * 1 = no notices, * 2 = ignore non-existant filter */ defined("INPUT_QUIET") or define("INPUT_QUIET", 0); /** * @class Request variable input wrapper. * * The methods are defined with underscore prefix, but supposed to be used without * when invoked on the superglobal arrays: * * @method int int[$field] converts input into integer * @method float float[$field] * @method name name[$field] removes any non-alphanumeric characters * @method id id[$field] alphanumeric string with dots * @method text text[$field] textual data with interpunction * */ class input implements ArrayAccess, Countable, Iterator { /** * Data filtering functions. * * These methods are usually not to be called directly. Instead use * $_GET->filtername["varname"] syntax without preceeding underscore * to access variable content. * * Categories: [e]=escape, [w]=whitelist, [b]=blacklist, [s]=sanitize, [v]=validate * */ #_session_id($name) { ... } // e.g. verify last IP, stale session, user-agent #_ /** * [w] * Integer. * */ function _int($data) { return (int)$data; } /** * [w] * Float. * */ function _float($data) { return (float)$data; } /** * [w] * Alphanumeric strings. * (e.g. var names, letters and numbers, may contain international letters) * */ function _name($data) { return preg_replace("/\W+/u", "", $data); } /** * [w] * Identifiers with underscores and dots, * like "xvar.1_2.x" * */ function _id($data) { return preg_replace("#(^[^a-z_]+)|[^\w\d_.]+|([^\w_]$)#i", "", $data); } /** * [w] * Flow text with whitespace, * minimal interpunction allowed. * */ function _words($data, $extra="") { return preg_replace("/[^\w\d\s,._\-+$extra]+/u", " ", strip_tags($data)); } /** * [w] * Human-readable text with many special/interpunction characters: * " and ' allowed, but no <, > or \ * */ function _text($data) { return preg_replace("/[^\w\d\s,._\-+?!;:\"\'\/`Β΄()*=]+/u", " ", strip_tags($data)); } /** * Acceptable filename characters. * * Alphanumerics and dot (but not as first character). * You should use `->basename` as primary filter anyway. * * @t whitelist * */ function _filename($data) { return preg_replace("/^[.\s]|[^\w._+-]/", "_", $data); } /** * [b] * Filter non-ascii text out. * Does not remove control characters. (Similar to FILTER_FLAG_STRIP_HIGH.) * */ function _ascii($data) { return preg_replace("/[\\200-\\377]+/", "", $data); } /** * [b] * Remove control characters. (Similar to FILTER_FLAG_STRIP_LOW.) * */ function _nocontrol($data) { return preg_replace("/[\\000-\\010\\013\\014\\016-\\037\\177\\377]+/", "", $data); // all except \r \n \t } /** * [e] * Exchange \r \n \t and \f \v \0 for normal spaces. * */ function _spaces($data) { return strtr($data, "\r\n\t\f\v\0", " "); } /** * [x] * Regular expression filter. * * This either extracts (preg_match) data if you have a () capture group, * or functions as filter (pref_replace) if there's a [^ character class. * */ function _regex($data, $rx="", $match=1) { # validating if (strpos($rx, "(")) { if (preg_match($rx, $data, $result)) { return($result[$match]); } } # cropping elseif (strpos($rx, "[^")) { return preg_replace($rx, "", $data); } } /** * [w] * Miximum string length. * */ function _length($data, $max=65535) { return substr($data, 0, $max); } /** * [w] * Range ensures value is between given minimum and maximum. * (Does not convert to integer itself.) * */ function _range($data, $min, $max) { return ($data > $max) ? $max : (($data < $min) ? $min : $data); } /** * [b] * Fallback value for absent/falsy values. * */ function _default($data, $default) { return empty($data) ? $default : $data; } /** * [w] * Boolean recognizes 1 or 0 and textual values like "false" and "off" or "no". * */ function _boolean($data) { if (empty($data) || $data==="0" || in_array(strtolower($data), array("false", "off", "no", "n", "wrong", "not", "-"))) { return false; } elseif ($data==="1" || in_array(strtolower($data), array("true", "on", "yes", "right", "y", "ok"))) { return true; } else return NULL; } /** * [w] * Ensures field is in array of allowed values. * * Works with arrays, but also string list. If you supply a "list,list,list" then * the comparison is case-insensitive. * */ function _in_array($data, $array) { if (is_array($array) ? in_array($data, $array) : in_array(strtolower($data), explode(",", strtolower($array)))) { return $data; } } ###### filter_var() wrappers ######### /** * [w] * Common case email syntax. * * (Close to RFC2822 but disallows square brackets or double quotes, no verification of TLDs, * doesn't restrict underscores in domain names, ignores i@an and anyone@localhost.) * */ function _email($data, $validate=1) { $data = preg_replace("/[^\w!#$%&'*+/=?_`{|}~@.\[\]\-]/", "", $data); // like filter_var if (!$validate || preg_match("/^(?!\.)[.\w!#$%&'*+/=?^_`{|}~-]+@(?:(?!-)[\w-]{2,}\.)+[\w]{2,6}$/i", trim($data))) { return $data; } } /** * [s] * URI characters. (Actually IRI) * */ function _uri($data) { # we should encode all-non chars return preg_replace("/[^-\w\d\$.+!*'(),{}\|\\~\^\[\]\`<>#%\";\/?:@&=]+/u", "", $data); // same as SANITIZE_URL } /** * [w] * URL syntax * * This is an alias for FILTER_VALIDATE_URL. Beware that it lets a few unwanted schemes * through (file:// and mailto:) and what you'd consider misformed URLs (http://http://whatever). * */ function _url($data) { return filter_var($data, FILTER_VALIDATE_URL); } /** * [v] * More restrictive HTTP/FTP url syntax. * No usernames allowed, no empty port, pathnames/qs/anchor are not checked. * # see also http://internet.ls-la.net/folklore/url-regexpr.html */ function _http($data) { return preg_match("~ (?(DEFINE) (?<byte> 2[0-4]\d |25[0-5] |1\d\d |[1-9]?\d) (?<ip>(?&byte)(\.(?&byte)){3}) (?<hex>[0-9a-fA-F]{1,4}) ) ^ (?<proto>https?|ftps?) :// # (?<user> \w+(:\w+)?@ )? ( (?<host> (?:[a-z][a-z\d_\-\$]*\.?)+) |(?<ipv6> \[ (?! [:\w]*::: # ASSERT: no triple ::: colons |(:\w+){8}|(\w+:){8} # not more than 7 : colons |(\w*:){7}\w+\. # not more than 6 : if there's a . | [:\w]*::[:\w]+:: ) # double :: colon must be unique (?= [:\w]*:: # don't count if there is one :: |(\w+:){6}\w+[:.]) # else require six : and one . or : (?: :|(?&hex):)+((?&hex)|(?&ip)|:) \]) # MATCH: combinations of HEX : IP |(?<ipv4> (?&ip) ) ) (?<port> :\d{1,5} )? # the integer isn't optional if port : colon present (unlike FILTER_VALIDATE_URL) (?<path> [/][^?#\s]* )? (?<qury> [?][^#\s]* )? (?<frgm> [#]\S* )? \z~ix", $data, $uu) ? $data : NULL;#(print_r($uu) ? $data : $data) } /** * [w] * IP address * */ function _ip($data) { return filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4|FILTER_FLAG_IPV6) ? $data : NULL; } /** * [w] * IPv4 address * */ function _ipv4($data) { return filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? $data : NULL; } /** * [w] * must be public IP address * */ function _public($data) { return filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE|FILTER_FLAG_NO_RES_RANGE) ? $data : NULL; } ###### format / representation ######### /** * [v] * HTML5 datetime / datetime_local, date, time * */ function _datetime($data) { return preg_match("/^\d{0}\d\d\d\d -(0\d|1[012]) -([012]\d|3[01]) T ([01]\d|2[0-3]) :[0-5]\d :[0-5]\d (Z|[+-]\d\d:\d\d|\.\d\d)$/x", $data) ? $data : NULL; } function _date($data) { return preg_match("/^\d\d\d\d -(0\d|1[012]) -([012]\d|3[01])$/x", $data) ? $data : NULL; } function _time($data) { return preg_match("/^([01]\d|2[0-3]) :[0-5]\d :[0-5]\d (\.\d\d)?$/x", $data) ? $data : NULL; } /** * [v] * HTML5 color * */ function _color($data) { return preg_match("/^#[0-9A-F]{6}$/i", $data) ? strtoupper($data) : NULL; } /** * [w] * Telephone numbers (HTML5 <input type=tel> makes no constraints.) * */ function _tel($data) { $data = preg_replace("#[/.\s]+#", "-", $data); if (preg_match("/^(\+|00)?(-?\d{2,}|\(\d+\)){2,}(-\d{2,}){,3}(\#\d+)?$/", $data)) { return trim($data, "-"); } } /** * [v] * Verify minimum consistency (RFC4627 regex) and decode json data. * */ function _json($data) { if (!preg_match('/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/', preg_replace('/"(\\.|[^"\\])*"/g', '', $data))) { return json_decode($data); } } /** * [v] * XML tree. * */ function _xml($data) { return simplexml_load_string($data); } /** * [w] * Clean html string via HTMLPurifier. * */ function _purify($data) { $h = new HTMLPurifier; return $h->purify( $data ); } /** * [e] * HTML escapes. * * This is actually an output filter. But might be useful to mirror input back into * form fields instantly `<input name=field value="<?= $_GET->html["field"] ?>">` * * @param $data string * @return string */ function _html($data) { return htmlspecialchars($data, ENT_QUOTES, "UTF-8", false); } /** * [e] * Escape all significant special chars. * */ function _escape($data) { return preg_replace("/[\\\\\[\]\{\}\[\]\'\"\`\Β΄\$\!\&\?\/\>\<\|\*\~\;\^]/", "\\$1", $data); } /** * [e] * Addslashes * */ function _q($data) { return addslashes($data); } /** * [b] * Minimal XSS detection. * Attempts no cleaning, just bails if anything looks suspicious. * * If something is XSS contaminated, it's spam and not worth to process further. * WEAK filters are better than no filters, but you should ultimatively use ->html purifier instead. * */ function _xss($data) { if (preg_match("/[<&>]/", $data)) { // looks remotely like html $html = $data; // remove filler $html = preg_replace("/&#(\d);*/e", "ord('$1')", $html); // escapes $html = preg_replace("/&#x(\w);*/e", "ord(dechex('$1'))", $html); // escapes $html = preg_replace("/[\x00-\x20\"\'\`\Β΄]/", "", $html); // whitespace + control characters, also any quotes $html .= preg_replace("#/\*[^<>]*\*/#", "", $html); // in-JS obfuscation comments // alert patterns if (preg_match("#[<<]/*(\?import|applet|embed|object|script|style|!\[CDATA\[|title|body|link|meta|base|i?frame|frameset|i?layer)#iUu", $html, $uu) or preg_match("#[<>]\w[^>]*(\w{3,}[=:]+(javascript|ecmascript|vbscript|jscript|python|actionscript|livescript):)#iUu", $html, $uu) or preg_match("#[<>]\w[^>]*(on(mouse\w+|key\w+|focus\w*|blur|click|dblclick|reset|select|change|submit|load|unload|error|abort|drag|Abort|Activate|AfterPrint|AfterUpdate|BeforeActivate|BeforeCopy|BeforeCut|BeforeDeactivate|BeforeEditFocus|BeforePaste|BeforePrint|BeforeUnload|Begin|Blur|Bounce|CellChange|Change|Click|ContextMenu|ControlSelect|Copy|Cut|DataAvailable|DataSetChanged|DataSetComplete|DblClick|Deactivate|Drag|DragEnd|DragLeave|DragEnter|DragOver|DragDrop|Drop|End|Error|ErrorUpdate|FilterChange|Finish|Focus|FocusIn|FocusOut|Help|KeyDown|KeyPress|KeyUp|LayoutComplete|Load|LoseCapture|MediaComplete|MediaError|MouseDown|MouseEnter|MouseLeave|MouseMove|MouseOut|MouseOver|MouseUp|MouseWheel|Move|MoveEnd|MoveStart|OutOfSync|Paste|Pause|Progress|PropertyChange|ReadyStateChange|Repeat|Reset|Resize|ResizeEnd|ResizeStart|Resume|Reverse|RowsEnter|RowExit|RowDelete|RowInserted|Scroll|Seek|Select|SelectionChange|SelectStart|Start|Stop|SyncRestored|Submit|TimeError|TrackChange|Unload|URLFlip)[^<\w=>]*[=:]+)[^<>]{3,}#iUu", $html, $uu) or preg_match("#[<>]\w[^>]*(\w{3,}[=:]+(-moz-binding:))#iUu", $html, $uu) or preg_match("#[<>]\w[^>]*(style[=:]+[^<>]*(expression\(|behaviour:|script:))#iUu", $html, $uu)) { $this->_log($data, "DETECTED XSS PATTERN ({$uu['1']}),"); $data = ""; die("input::_xss"); } } return $data; } /** * [w] * Cleans utf-8 from invalid sequences and alternative representations. * (BEWARE: performance drain) * */ function _iconv($data) { return iconv("UTF-8", "UTF-8//IGNORE", $data); } /** * [b] * Few dangerous UTF-7 sequences * (only necessary if output pages don't have a charset specified) * */ function _utf7($data) { return preg_replace("/[+]A(D[w40]|C[IYQU])(-|$)?/", "", $data);; } /** * [e] * Escape for concatenating data into sql query. * (suboptimal, use parameterized queries instead) * */ function _sql($data) { INPUT_QUIET or trigger_error("SQL escaping of input variable '$this->__varname'.", E_USER_NOTICE); return db()->quote($data); // global object } function _mysql($data) { INPUT_QUIET or trigger_error("SQL escaping of input variable '$this->__varname'.", E_USER_NOTICE); return mysql_real_escape_string($data); } ###### pseudo filters ############## /** * [x] * Unfiltered access should obviously be avoided. But it's not always possible, * so this method exists and will just trigger a notice in debug mode. * */ function _raw($data) { INPUT_QUIET or trigger_error("Unfiltered input variable \${$this->__title}['{$this->__varname}'] accessed.", E_USER_NOTICE); return $data; } /** * [x] * Unfiltered access, but logs variable name and value. * */ function _log($data, $reason="manual log") { syslog(LOG_NOTICE, "php7://input:_log@{$_SERVER['SERVER_NAME']} accessing \${$this->__title}['{$this->__varname}'] variable, $reason, content=" . substr($this->_id(json_encode($data)), 0, 48)); return $data; } /** * [b] * Abort with fatal error. (Used as fallback for INPUT_DIRECT access.) * */ function _disallow($data) { throw new OutOfBoundsException("Direct \$_REQUEST[\"$this->__varname\"] is not allowed, add ->filter method, or change INPUT_DIRECT if needed."); } /** * Validate instead of sanitize. * */ function _is($data) { $this->__filter[] = array("is_still", array()); return $data; } function _is_still($data) { return $data === $this->__vars[$this->__varname]; } ###### implementation ################################################ /** * Array data from previous superglobal. * * (It's pointless to make this a priv/proteced attribute, as raw data could be accessed * in any number of ways. Not the least would be to just not use the input filters.) * */ var $__vars = array(); /** * Name of superarray this filter object wraps. * (e.g. "_GET" or "_SERVER") * */ var $__title = ""; /** * Currently accessed array key. * */ var $__varname = ""; /** * Amassed filter list. * Each ->method->chain name will be appended here. Gets automatically reset after * a succesful variable access. * * Each entry is in `array("methodname", array("param1", 2, 3))` format. * */ var $__filter = array(); // filterchain method stack /** * Automatically appended filter list. (Simply combined with current `$__filter`s). * */ var $__always = array(); /** * Currently accessed array keys. * */ var $__rules = array( // pre-defined varname filters // "varname.." => array( array("length",array(256), array("nocontrol",array()) ), ); /** * Initialize object from * * @param array one of $_REQUEST, $_GET or $_POST etc. */ function __construct($_INPUT, $title="") { $this->__vars = $_INPUT; // stripslashes on magic_quotes_gpc might go here, but we have no word if we actually receive a superglobal or if it wasn't already corrected $this->__title = $title; } /** * Sets default filter chain. * These are ALWAYS applied in CONJUNCTION to ->manually->specified->filters. * */ function always() { $this->__always = $this->__filter; $this->__filter = array(); } /** * Normalize array keys (to UPPER case), for e.g. $_SERVER vars. * */ function key_case($case=CASE_UPPER) { $this->__vars = array_change_key_case($this->__vars, $case); } /** * Executes current filter or filter chain on given $varname. * */ function filter($varname, $reset_filter_afterwards=NULL) { // single array [["name"]] becomes varname if (is_array($varname) and count($varname)===1) { $varname = current($varname); } $this->__varname = $varname; // direct/raw access without any ->filtername prior offsetGet[] or plain filter() call if (empty($this->__filter)) { if (isset($this->__rules[$varname])) { $this->__filter = $this->rules[$varname]; // use a predefined filterset } else { $this->__filter = array( INPUT_DIRECT ); // direct access handler } } $first_handler = reset($this->__filter); // retrieve value for selected input variable $data = NULL; if (!is_scalar($varname) or $first_handler == "list" or $first_handler == "multi") { // one of the multiplex handlers supposedly picks it up } elseif (isset($this->__vars[$varname])) { // entry exists $data = $this->__vars[$varname]; } elseif (!INPUT_QUIET) { trigger_error("Undefined input variable \${$this->__title}['{$this->__varname}']", E_USER_NOTICE); // run through filters anyway (for ->log) } // implicit ->array filter handling if (is_array($data) and $first_handler != "array") { array_unshift($this->__filter, "array"); } // apply filters (we're building an ad-hoc merged array here, because ->apply works on the reference, and some filters expect ->__filter to contain the complete current list) $this->__filter = array_merge($this->__filter, $this->__always); $data = $this->apply($data, $this->__filter); // the Traversable array interface resets the filter list after each request, see ->current() if ($reset_filter_afterwards) { $this->__filter = $reset_filter_afterwards; } // done return $data; } /** * Runs list of filters on data. Uses either methods, bound closures, or global functions * if the filter name matches. * * It works on an array reference and with array_shift() because filters are allowed to * modify the list at runtime (->array requires to). * */ function apply($data, &$filterchain) { while ($f = array_shift($filterchain)) { list($filtername, $args) = is_array($f) ? $f : array($f, array()); // an override function name or closure exists if (isset($this->{"_$filtername"})) { $filtername = $this->{"_$filtername"}; } // call _filter method if (is_string($filtername) && method_exists($this, "_$filtername")) { $data = call_user_func_array(array($this, "_$filtername"), array_merge(array($data), (array)$args)); } // ordinary php function, or closure, or rebound method elseif (is_callable($filtername)) { $data = call_user_func($filtername, $data); } else { INPUT_QUIET>=2 or trigger_error("unknown filter '" . (is_scalar($filtername) ? $filtername : "closure") . "', falling back on wiping non-alpha characters from '{$this->__varname}'", E_USER_WARNING); $data = $this->_name($data); } } return $data; } /** * @multiplex * * List data / array value handling. * * This virtual filter hijacks the original filter chain, and applies it * to sub values. * */ function _array($data) { // save + swap out the current filter chain list($multiplex, $this->__filter) = array($this->__filter, array()); // iteratively apply original filter chain on each array entry $data = (array) $data; foreach (array_keys($data) as $i) { $chain = $multiplex; $data[$i] = $this->apply($data[$i], $chain); } return $data; } /** * @multiplex * * Grab a collection of input variables, names delimited by comma. * Implicitly makes it an ->_array() list. * The _array handler is implicitly used for indexed values. _list * and _multi can be used for associative arrays, given a key list. * * @example extract($_GET->list->text["name,title,date,email,comment"]); * @php5.4+ $_GET->list[['key1','key2','key3']]; * * @bugs hacky, improper way to intercept, fetches from $__vars[] directly, * uses $__varname instead of $data, may prevent replays, * main will trigger a notice anyway as VAR1,VAR2,.. is undefined * */ function _list($keys, $pass_array=FALSE) { // get key list if (is_array($this->__varname)) { $keys = $this->__varname; } else { $keys = explode(",", $this->__varname); } // slice out named values from ->__vars $data = array_intersect_key($this->__vars, array_flip($keys)); // chain to _array multiplex handler if (!$pass_array) { return $this->_array($data); } // process fetched list as array (for user-land functions like http_build_query) else { return $data; } } /** * Processes collection of input variables. * Passes list on as array to subsequent filters. * */ function _multi($keys) { return $this->_list($keys, "process_as_array"); } /** * @hide * * Ordinary method calls are captured here. Any ->method("name") will trigger * the filter and return variable data, just like ->method["name"] would. It * just allows to supply additional method parameters. * */ function __call($filtername, $args) { // can have arguments $this->__filter[] = array($filtername, array_slice($args, 1)); return $this->filter($args[0]); } /** * @hide * * Wrapper to capture ->name->chain accesses. * */ function __get($filtername) { // // we could do some heuristic chaining here, // if the last entry in the ->attrib->attrib list is not a valid method name, // but a valid varname, we should execute the filter chain rather than add. // // Unpack parameterized filter attributes, use U+2022 ellipsis β¦ as delimiter if (strpos($filtername, "β¦")) { $args = explode("β¦", $filtername); $filtername = array_shift($args); } else { $args=array(); } // Add filter to list $this->__filter[] = count($args) ? array($filtername, $args) : $filtername; // fluent interface return $this; } /** * @hide ArrayAccess * * Normal $_ARRAY["name"] syntax access is redirected through the filter here. * */ function offsetGet($varname) { // never chains return $this->filter($varname); } /** * @hide ArrayAccess * * Needed for commonplace isset($_POST["var"]) checks. * */ function offsetExists($name) { return isset($this->__vars[$name]); } /** * @hide * Sets value in array. Note that it only works for array["xy"]= top-level * assignments. Subarrays are always retrieved by value (due to filtering) * and cannot be set item-wise. * * @discouraged * Manipulating the input array is indicative for state tampering and thus * throws a notice per default. * */ function offsetSet($name, $value) { INPUT_QUIET or trigger_error("Manipulation of input variable \${$this->__title}['{$this->__varname}']", E_USER_NOTICE); $this->__vars[$name] = $value; } /** * @hide * Removes entry. * * @discouraged * Triggers a notice per default. * */ function offsetUnset($name) { INPUT_QUIET or trigger_error("Removed input variable \${$this->__title}['{$this->__varname}']", E_USER_NOTICE); unset($this->__vars[$name]); } /** * Generic array features. * Due to being reserved words `isset` and `empty` need custom method names here: * * ->has(isset) * ->no(empty) * ->keys() * * Has No Keys seems easy to remember. * */ /** * isset/array_key_exists check. * */ function has($args) { $r = 1; is_array($args) or $args = func_get_args(); foreach ($args as $name) { $r &= isset($this->__vars[$name]); } return $r; } /** * empty() probing, * Tests if variable is absent or falsy. * */ function no($name) { return empty($this->__vars[$name]); } /** * Returns list of all contained keys. * */ function keys() { return array_keys($this->__vars); } /** * @hide Traversable * * Allows to loop over all array entries in a foreach loop. A supplied filterlist * is reapplied for each iteration. * * - Basically all calls are mirrored onto ->__vars` internal array pointer. * */ function current() { return $this->filter(key($this->__vars), /*reset_filter_afterwards=to what it was before*/$this->__filter); } function key() { return key($this->__vars); } function next() { return next($this->__vars); } function rewind() { return reset($this->__vars); } function valid() { if (key($this->__vars) !== NULL) { return TRUE; } else { // also reset the filter list after we're done traversing all entries $this->__filters=array(); return FALSE; } } /** * @hide Countable * */ function count() { return count($this->__vars); } /** * @hide Allows testing variable presence with e.g. if ( $_POST() ) * Alternatively $_POST("var") is an alias to $_POST["var"]. * */ function __invoke($varname=NULL) { // treat it as variable access if (!is_null($varname)) { return $this->offsetGet($varname); } // do the count() call else { return $this->count(); } } } /** * @autorun * */ $_SERVER = new input($_SERVER, "_SERVER"); $_REQUEST = new input($_REQUEST, "_REQUEST"); $_GET = new input($_GET, "_GET"); $_POST = new input($_POST, "_POST"); $_COOKIE = new input($_COOKIE, "_COOKIE"); #$_SESSION #$_ENV #$_FILES required a special handler ?> |
Added layout_bottom.php.
> > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | </section> <footer id=spotlight> </footer> <footer id=bottom> <a href="http://fossil.include-once.org/freshcode/wiki/About">About</a> | <a href="http://fossil.include-once.org/freshcode/wiki/Privacy">Privacy / Cookie Policy / No Ads</a> | <a href="http://fossil.include-once.org/freshcode/wiki/Contribute">How to volunteer</a> <br> <small style="font-size:90%"> This is a non-commercial project. <br> All project entries are licensed as CC-BY-SA. There will be <a href="/feed">/atom+json feeds</a>.. </small> </footer> </html> |
Added layout_header.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 | <!DOCTYPE html> <html> <head> <title>freshcode.club</title> <meta charset=UTF-8> <link rel=stylesheet href="/freshcode.css"> <base href="http://freshcode/"> </head> <body> <nav id=topbar> Open source community software release tracking. <span style=float:right> <a href="//freshmeat.club/">freshmeat.club</a> | <a href="//freecode.club/">freecode.club</a> | <b><a href="//freshcode.club/">freshcode.club</a></b> </span> </nav> <footer id=logo> <a href="/" title="freshcode.club"><img src=logo.png width=200 height=110 alt=freshcode border=0></a> <div class=empty-box> </div> </footer> <nav id=tools> <a href="/">Home</a> <a href="/submit" class=submit>Submit</a> <a href="/tags">Browse Projects by Tag</a> <a href="http://fossil.include-once.org/freshcode/wiki/About">About</a> <a href="/links">Links</a> <a href="http://www.opensourcestore.org/">Forum</a> </nav> |
Added logo.png.
cannot compute difference between binary files
Added logo.svgz.
cannot compute difference between binary files
Added openid.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 | <?php /** * This class provides a simple interface for OpenID (1.1 and 2.0) authentication. * Supports Yadis discovery. * The authentication process is stateless/dumb. * * Usage: * Sign-on with OpenID is a two step process: * Step one is authentication with the provider: * <code> * $openid = new LightOpenID('my-host.example.org'); * $openid->identity = 'ID supplied by user'; * header('Location: ' . $openid->authUrl()); * </code> * The provider then sends various parameters via GET, one of them is openid_mode. * Step two is verification: * <code> * $openid = new LightOpenID('my-host.example.org'); * if ($openid->mode) { * echo $openid->validate() ? 'Logged in.' : 'Failed'; * } * </code> * * Change the 'my-host.example.org' to your domain name. Do NOT use $_SERVER['HTTP_HOST'] * for that, unless you know what you are doing. * * Optionally, you can set $returnUrl and $realm (or $trustRoot, which is an alias). * The default values for those are: * $openid->realm = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; * $openid->returnUrl = $openid->realm . $_SERVER['REQUEST_URI']; * If you don't know their meaning, refer to any openid tutorial, or specification. Or just guess. * * AX and SREG extensions are supported. * To use them, specify $openid->required and/or $openid->optional before calling $openid->authUrl(). * These are arrays, with values being AX schema paths (the 'path' part of the URL). * For example: * $openid->required = array('namePerson/friendly', 'contact/email'); * $openid->optional = array('namePerson/first'); * If the server supports only SREG or OpenID 1.1, these are automaticaly * mapped to SREG names, so that user doesn't have to know anything about the server. * * To get the values, use $openid->getAttributes(). * * * The library requires PHP >= 5.1.2 with curl or http/https stream wrappers enabled. * @author Mewp * @copyright Copyright (c) 2010, Mewp * @license http://www.opensource.org/licenses/mit-license.php MIT */ class LightOpenID { public $returnUrl , $required = array() , $optional = array() , $verify_peer = null , $capath = null , $cainfo = null , $data; private $identity, $claimed_id; protected $server, $version, $trustRoot, $aliases, $identifier_select = false , $ax = false, $sreg = false, $setup_url = null, $headers = array(); static protected $ax_to_sreg = array( 'namePerson/friendly' => 'nickname', 'contact/email' => 'email', 'namePerson' => 'fullname', 'birthDate' => 'dob', 'person/gender' => 'gender', 'contact/postalCode/home' => 'postcode', 'contact/country/home' => 'country', 'pref/language' => 'language', 'pref/timezone' => 'timezone', ); function __construct($host) { $this->trustRoot = (strpos($host, '://') ? $host : 'http://' . $host); if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ) { $this->trustRoot = (strpos($host, '://') ? $host : 'https://' . $host); } if(($host_end = strpos($this->trustRoot, '/', 8)) !== false) { $this->trustRoot = substr($this->trustRoot, 0, $host_end); } $uri = rtrim(preg_replace('#((?<=\?)|&)openid\.[^&]+#', '', $_SERVER['REQUEST_URI']), '?'); $this->returnUrl = $this->trustRoot . $uri; $this->data = ($_SERVER['REQUEST_METHOD'] === 'POST') ? $_POST : $_GET; if(!function_exists('curl_init') && !in_array('https', stream_get_wrappers())) { throw new ErrorException('You must have either https wrappers or curl enabled.'); } } function __set($name, $value) { switch ($name) { case 'identity': if (strlen($value = trim((String) $value))) { if (preg_match('#^xri:/*#i', $value, $m)) { $value = substr($value, strlen($m[0])); } elseif (!preg_match('/^(?:[=@+\$!\(]|https?:)/i', $value)) { $value = "http://$value"; } if (preg_match('#^https?://[^/]+$#i', $value, $m)) { $value .= '/'; } } $this->$name = $this->claimed_id = $value; break; case 'trustRoot': case 'realm': $this->trustRoot = trim($value); } } function __get($name) { switch ($name) { case 'identity': # We return claimed_id instead of identity, # because the developer should see the claimed identifier, # i.e. what he set as identity, not the op-local identifier (which is what we verify) return $this->claimed_id; case 'trustRoot': case 'realm': return $this->trustRoot; case 'mode': return empty($this->data['openid_mode']) ? null : $this->data['openid_mode']; } } /** * Checks if the server specified in the url exists. * * @param $url url to check * @return true, if the server exists; false otherwise */ function hostExists($url) { if (strpos($url, '/') === false) { $server = $url; } else { $server = @parse_url($url, PHP_URL_HOST); } if (!$server) { return false; } return !!gethostbynamel($server); } protected function request_curl($url, $method='GET', $params=array(), $update_claimed_id) { $params = http_build_query($params, '', '&'); $curl = curl_init($url . ($method == 'GET' && $params ? '?' . $params : '')); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/xrds+xml, */*')); if($this->verify_peer !== null) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verify_peer); if($this->capath) { curl_setopt($curl, CURLOPT_CAPATH, $this->capath); } if($this->cainfo) { curl_setopt($curl, CURLOPT_CAINFO, $this->cainfo); } } if ($method == 'POST') { curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $params); } elseif ($method == 'HEAD') { curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_NOBODY, true); } else { curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_HTTPGET, true); } $response = curl_exec($curl); if($method == 'HEAD' && curl_getinfo($curl, CURLINFO_HTTP_CODE) == 405) { curl_setopt($curl, CURLOPT_HTTPGET, true); $response = curl_exec($curl); $response = substr($response, 0, strpos($response, "\r\n\r\n")); } if($method == 'HEAD' || $method == 'GET') { $header_response = $response; # If it's a GET request, we want to only parse the header part. if($method == 'GET') { $header_response = substr($response, 0, strpos($response, "\r\n\r\n")); } $headers = array(); foreach(explode("\n", $header_response) as $header) { $pos = strpos($header,':'); if ($pos !== false) { $name = strtolower(trim(substr($header, 0, $pos))); $headers[$name] = trim(substr($header, $pos+1)); } } if($update_claimed_id) { # Updating claimed_id in case of redirections. $effective_url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); if($effective_url != $url) { $this->identity = $this->claimed_id = $effective_url; } } if($method == 'HEAD') { return $headers; } else { $this->headers = $headers; } } if (curl_errno($curl)) { throw new ErrorException(curl_error($curl), curl_errno($curl)); } return $response; } protected function parse_header_array($array, $update_claimed_id) { $headers = array(); foreach($array as $header) { $pos = strpos($header,':'); if ($pos !== false) { $name = strtolower(trim(substr($header, 0, $pos))); $headers[$name] = trim(substr($header, $pos+1)); # Following possible redirections. The point is just to have # claimed_id change with them, because the redirections # are followed automatically. # We ignore redirections with relative paths. # If any known provider uses them, file a bug report. if($name == 'location' && $update_claimed_id) { if(strpos($headers[$name], 'http') === 0) { $this->identity = $this->claimed_id = $headers[$name]; } elseif($headers[$name][0] == '/') { $parsed_url = parse_url($this->claimed_id); $this->identity = $this->claimed_id = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $headers[$name]; } } } } return $headers; } protected function request_streams($url, $method='GET', $params=array(), $update_claimed_id) { if(!$this->hostExists($url)) { throw new ErrorException("Could not connect to $url.", 404); } $params = http_build_query($params, '', '&'); switch($method) { case 'GET': $opts = array( 'http' => array( 'method' => 'GET', 'header' => 'Accept: application/xrds+xml, */*', 'ignore_errors' => true, ), 'ssl' => array( 'CN_match' => parse_url($url, PHP_URL_HOST), ), ); $url = $url . ($params ? '?' . $params : ''); break; case 'POST': $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $params, 'ignore_errors' => true, ), 'ssl' => array( 'CN_match' => parse_url($url, PHP_URL_HOST), ), ); break; case 'HEAD': # We want to send a HEAD request, # but since get_headers doesn't accept $context parameter, # we have to change the defaults. $default = stream_context_get_options(stream_context_get_default()); stream_context_get_default( array( 'http' => array( 'method' => 'HEAD', 'header' => 'Accept: application/xrds+xml, */*', 'ignore_errors' => true, ), 'ssl' => array( 'CN_match' => parse_url($url, PHP_URL_HOST), ), ) ); $url = $url . ($params ? '?' . $params : ''); $headers = get_headers ($url); if(!$headers) { return array(); } if(intval(substr($headers[0], strlen('HTTP/1.1 '))) == 405) { # The server doesn't support HEAD, so let's emulate it with # a GET. $args = func_get_args(); $args[1] = 'GET'; call_user_func_array(array($this, 'request_streams'), $args); return $this->headers; } $headers = $this->parse_header_array($headers, $update_claimed_id); # And restore them. stream_context_get_default($default); return $headers; } if($this->verify_peer) { $opts['ssl'] += array( 'verify_peer' => true, 'capath' => $this->capath, 'cafile' => $this->cainfo, ); } $context = stream_context_create ($opts); $data = file_get_contents($url, false, $context); # This is a hack for providers who don't support HEAD requests. # It just creates the headers array for the last request in $this->headers. if(isset($http_response_header)) { $this->headers = $this->parse_header_array($http_response_header, $update_claimed_id); } return $data; } protected function request($url, $method='GET', $params=array(), $update_claimed_id=false) { if (function_exists('curl_init') && (!in_array('https', stream_get_wrappers()) || !ini_get('safe_mode') && !ini_get('open_basedir')) ) { return $this->request_curl($url, $method, $params, $update_claimed_id); } return $this->request_streams($url, $method, $params, $update_claimed_id); } protected function build_url($url, $parts) { if (isset($url['query'], $parts['query'])) { $parts['query'] = $url['query'] . '&' . $parts['query']; } $url = $parts + $url; $url = $url['scheme'] . '://' . (empty($url['username'])?'' :(empty($url['password'])? "{$url['username']}@" :"{$url['username']}:{$url['password']}@")) . $url['host'] . (empty($url['port'])?'':":{$url['port']}") . (empty($url['path'])?'':$url['path']) . (empty($url['query'])?'':"?{$url['query']}") . (empty($url['fragment'])?'':"#{$url['fragment']}"); return $url; } /** * Helper function used to scan for <meta>/<link> tags and extract information * from them */ protected function htmlTag($content, $tag, $attrName, $attrValue, $valueName) { preg_match_all("#<{$tag}[^>]*$attrName=['\"].*?$attrValue.*?['\"][^>]*$valueName=['\"](.+?)['\"][^>]*/?>#i", $content, $matches1); preg_match_all("#<{$tag}[^>]*$valueName=['\"](.+?)['\"][^>]*$attrName=['\"].*?$attrValue.*?['\"][^>]*/?>#i", $content, $matches2); $result = array_merge($matches1[1], $matches2[1]); return empty($result)?false:$result[0]; } /** * Performs Yadis and HTML discovery. Normally not used. * @param $url Identity URL. * @return String OP Endpoint (i.e. OpenID provider address). * @throws ErrorException */ function discover($url) { if (!$url) throw new ErrorException('No identity supplied.'); # Use xri.net proxy to resolve i-name identities if (!preg_match('#^https?:#', $url)) { $url = "https://xri.net/$url"; } # We save the original url in case of Yadis discovery failure. # It can happen when we'll be lead to an XRDS document # which does not have any OpenID2 services. $originalUrl = $url; # A flag to disable yadis discovery in case of failure in headers. $yadis = true; # We'll jump a maximum of 5 times, to avoid endless redirections. for ($i = 0; $i < 5; $i ++) { if ($yadis) { $headers = $this->request($url, 'HEAD', array(), true); $next = false; if (isset($headers['x-xrds-location'])) { $url = $this->build_url(parse_url($url), parse_url(trim($headers['x-xrds-location']))); $next = true; } if (isset($headers['content-type']) && (strpos($headers['content-type'], 'application/xrds+xml') !== false || strpos($headers['content-type'], 'text/xml') !== false) ) { # Apparently, some providers return XRDS documents as text/html. # While it is against the spec, allowing this here shouldn't break # compatibility with anything. # --- # Found an XRDS document, now let's find the server, and optionally delegate. $content = $this->request($url, 'GET'); preg_match_all('#<Service.*?>(.*?)</Service>#s', $content, $m); foreach($m[1] as $content) { $content = ' ' . $content; # The space is added, so that strpos doesn't return 0. # OpenID 2 $ns = preg_quote('http://specs.openid.net/auth/2.0/', '#'); if(preg_match('#<Type>\s*'.$ns.'(server|signon)\s*</Type>#s', $content, $type)) { if ($type[1] == 'server') $this->identifier_select = true; preg_match('#<URI.*?>(.*)</URI>#', $content, $server); preg_match('#<(Local|Canonical)ID>(.*)</\1ID>#', $content, $delegate); if (empty($server)) { return false; } # Does the server advertise support for either AX or SREG? $this->ax = (bool) strpos($content, '<Type>http://openid.net/srv/ax/1.0</Type>'); $this->sreg = strpos($content, '<Type>http://openid.net/sreg/1.0</Type>') || strpos($content, '<Type>http://openid.net/extensions/sreg/1.1</Type>'); $server = $server[1]; if (isset($delegate[2])) $this->identity = trim($delegate[2]); $this->version = 2; $this->server = $server; return $server; } # OpenID 1.1 $ns = preg_quote('http://openid.net/signon/1.1', '#'); if (preg_match('#<Type>\s*'.$ns.'\s*</Type>#s', $content)) { preg_match('#<URI.*?>(.*)</URI>#', $content, $server); preg_match('#<.*?Delegate>(.*)</.*?Delegate>#', $content, $delegate); if (empty($server)) { return false; } # AX can be used only with OpenID 2.0, so checking only SREG $this->sreg = strpos($content, '<Type>http://openid.net/sreg/1.0</Type>') || strpos($content, '<Type>http://openid.net/extensions/sreg/1.1</Type>'); $server = $server[1]; if (isset($delegate[1])) $this->identity = $delegate[1]; $this->version = 1; $this->server = $server; return $server; } } $next = true; $yadis = false; $url = $originalUrl; $content = null; break; } if ($next) continue; # There are no relevant information in headers, so we search the body. $content = $this->request($url, 'GET', array(), true); if (isset($this->headers['x-xrds-location'])) { $url = $this->build_url(parse_url($url), parse_url(trim($this->headers['x-xrds-location']))); continue; } $location = $this->htmlTag($content, 'meta', 'http-equiv', 'X-XRDS-Location', 'content'); if ($location) { $url = $this->build_url(parse_url($url), parse_url($location)); continue; } } if (!$content) $content = $this->request($url, 'GET'); # At this point, the YADIS Discovery has failed, so we'll switch # to openid2 HTML discovery, then fallback to openid 1.1 discovery. $server = $this->htmlTag($content, 'link', 'rel', 'openid2.provider', 'href'); $delegate = $this->htmlTag($content, 'link', 'rel', 'openid2.local_id', 'href'); $this->version = 2; if (!$server) { # The same with openid 1.1 $server = $this->htmlTag($content, 'link', 'rel', 'openid.server', 'href'); $delegate = $this->htmlTag($content, 'link', 'rel', 'openid.delegate', 'href'); $this->version = 1; } if ($server) { # We found an OpenID2 OP Endpoint if ($delegate) { # We have also found an OP-Local ID. $this->identity = $delegate; } $this->server = $server; return $server; } throw new ErrorException("No OpenID Server found at $url", 404); } throw new ErrorException('Endless redirection!', 500); } protected function sregParams() { $params = array(); # We always use SREG 1.1, even if the server is advertising only support for 1.0. # That's because it's fully backwards compatibile with 1.0, and some providers # advertise 1.0 even if they accept only 1.1. One such provider is myopenid.com $params['openid.ns.sreg'] = 'http://openid.net/extensions/sreg/1.1'; if ($this->required) { $params['openid.sreg.required'] = array(); foreach ($this->required as $required) { if (!isset(self::$ax_to_sreg[$required])) continue; $params['openid.sreg.required'][] = self::$ax_to_sreg[$required]; } $params['openid.sreg.required'] = implode(',', $params['openid.sreg.required']); } if ($this->optional) { $params['openid.sreg.optional'] = array(); foreach ($this->optional as $optional) { if (!isset(self::$ax_to_sreg[$optional])) continue; $params['openid.sreg.optional'][] = self::$ax_to_sreg[$optional]; } $params['openid.sreg.optional'] = implode(',', $params['openid.sreg.optional']); } return $params; } protected function axParams() { $params = array(); if ($this->required || $this->optional) { $params['openid.ns.ax'] = 'http://openid.net/srv/ax/1.0'; $params['openid.ax.mode'] = 'fetch_request'; $this->aliases = array(); $counts = array(); $required = array(); $optional = array(); foreach (array('required','optional') as $type) { foreach ($this->$type as $alias => $field) { if (is_int($alias)) $alias = strtr($field, '/', '_'); $this->aliases[$alias] = 'http://axschema.org/' . $field; if (empty($counts[$alias])) $counts[$alias] = 0; $counts[$alias] += 1; ${$type}[] = $alias; } } foreach ($this->aliases as $alias => $ns) { $params['openid.ax.type.' . $alias] = $ns; } foreach ($counts as $alias => $count) { if ($count == 1) continue; $params['openid.ax.count.' . $alias] = $count; } # Don't send empty ax.requied and ax.if_available. # Google and possibly other providers refuse to support ax when one of these is empty. if($required) { $params['openid.ax.required'] = implode(',', $required); } if($optional) { $params['openid.ax.if_available'] = implode(',', $optional); } } return $params; } protected function authUrl_v1($immediate) { $returnUrl = $this->returnUrl; # If we have an openid.delegate that is different from our claimed id, # we need to somehow preserve the claimed id between requests. # The simplest way is to just send it along with the return_to url. if($this->identity != $this->claimed_id) { $returnUrl .= (strpos($returnUrl, '?') ? '&' : '?') . 'openid.claimed_id=' . $this->claimed_id; } $params = array( 'openid.return_to' => $returnUrl, 'openid.mode' => $immediate ? 'checkid_immediate' : 'checkid_setup', 'openid.identity' => $this->identity, 'openid.trust_root' => $this->trustRoot, ) + $this->sregParams(); return $this->build_url(parse_url($this->server) , array('query' => http_build_query($params, '', '&'))); } protected function authUrl_v2($immediate) { $params = array( 'openid.ns' => 'http://specs.openid.net/auth/2.0', 'openid.mode' => $immediate ? 'checkid_immediate' : 'checkid_setup', 'openid.return_to' => $this->returnUrl, 'openid.realm' => $this->trustRoot, ); if ($this->ax) { $params += $this->axParams(); } if ($this->sreg) { $params += $this->sregParams(); } if (!$this->ax && !$this->sreg) { # If OP doesn't advertise either SREG, nor AX, let's send them both # in worst case we don't get anything in return. $params += $this->axParams() + $this->sregParams(); } if ($this->identifier_select) { $params['openid.identity'] = $params['openid.claimed_id'] = 'http://specs.openid.net/auth/2.0/identifier_select'; } else { $params['openid.identity'] = $this->identity; $params['openid.claimed_id'] = $this->claimed_id; } return $this->build_url(parse_url($this->server) , array('query' => http_build_query($params, '', '&'))); } /** * Returns authentication url. Usually, you want to redirect your user to it. * @return String The authentication url. * @param String $select_identifier Whether to request OP to select identity for an user in OpenID 2. Does not affect OpenID 1. * @throws ErrorException */ function authUrl($immediate = false) { if ($this->setup_url && !$immediate) return $this->setup_url; if (!$this->server) $this->discover($this->identity); if ($this->version == 2) { return $this->authUrl_v2($immediate); } return $this->authUrl_v1($immediate); } /** * Performs OpenID verification with the OP. * @return Bool Whether the verification was successful. * @throws ErrorException */ function validate() { # If the request was using immediate mode, a failure may be reported # by presenting user_setup_url (for 1.1) or reporting # mode 'setup_needed' (for 2.0). Also catching all modes other than # id_res, in order to avoid throwing errors. if(isset($this->data['openid_user_setup_url'])) { $this->setup_url = $this->data['openid_user_setup_url']; return false; } if($this->mode != 'id_res') { return false; } $this->claimed_id = isset($this->data['openid_claimed_id'])?$this->data['openid_claimed_id']:$this->data['openid_identity']; $params = array( 'openid.assoc_handle' => $this->data['openid_assoc_handle'], 'openid.signed' => $this->data['openid_signed'], 'openid.sig' => $this->data['openid_sig'], ); if (isset($this->data['openid_ns'])) { # We're dealing with an OpenID 2.0 server, so let's set an ns # Even though we should know location of the endpoint, # we still need to verify it by discovery, so $server is not set here $params['openid.ns'] = 'http://specs.openid.net/auth/2.0'; } elseif (isset($this->data['openid_claimed_id']) && $this->data['openid_claimed_id'] != $this->data['openid_identity'] ) { # If it's an OpenID 1 provider, and we've got claimed_id, # we have to append it to the returnUrl, like authUrl_v1 does. $this->returnUrl .= (strpos($this->returnUrl, '?') ? '&' : '?') . 'openid.claimed_id=' . $this->claimed_id; } if ($this->data['openid_return_to'] != $this->returnUrl) { # The return_to url must match the url of current request. # I'm assuing that noone will set the returnUrl to something that doesn't make sense. return false; } $server = $this->discover($this->claimed_id); foreach (explode(',', $this->data['openid_signed']) as $item) { # Checking whether magic_quotes_gpc is turned on, because # the function may fail if it is. For example, when fetching # AX namePerson, it might containg an apostrophe, which will be escaped. # In such case, validation would fail, since we'd send different data than OP # wants to verify. stripslashes() should solve that problem, but we can't # use it when magic_quotes is off. $value = $this->data['openid_' . str_replace('.','_',$item)]; $params['openid.' . $item] = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() ? stripslashes($value) : $value; } $params['openid.mode'] = 'check_authentication'; $response = $this->request($server, 'POST', $params); return preg_match('/is_valid\s*:\s*true/i', $response); } protected function getAxAttributes() { $alias = null; if (isset($this->data['openid_ns_ax']) && $this->data['openid_ns_ax'] != 'http://openid.net/srv/ax/1.0' ) { # It's the most likely case, so we'll check it before $alias = 'ax'; } else { # 'ax' prefix is either undefined, or points to another extension, # so we search for another prefix foreach ($this->data as $key => $val) { if (substr($key, 0, strlen('openid_ns_')) == 'openid_ns_' && $val == 'http://openid.net/srv/ax/1.0' ) { $alias = substr($key, strlen('openid_ns_')); break; } } } if (!$alias) { # An alias for AX schema has not been found, # so there is no AX data in the OP's response return array(); } $attributes = array(); foreach (explode(',', $this->data['openid_signed']) as $key) { $keyMatch = $alias . '.value.'; if (substr($key, 0, strlen($keyMatch)) != $keyMatch) { continue; } $key = substr($key, strlen($keyMatch)); if (!isset($this->data['openid_' . $alias . '_type_' . $key])) { # OP is breaking the spec by returning a field without # associated ns. This shouldn't happen, but it's better # to check, than cause an E_NOTICE. continue; } $value = $this->data['openid_' . $alias . '_value_' . $key]; $key = substr($this->data['openid_' . $alias . '_type_' . $key], strlen('http://axschema.org/')); $attributes[$key] = $value; } return $attributes; } protected function getSregAttributes() { $attributes = array(); $sreg_to_ax = array_flip(self::$ax_to_sreg); foreach (explode(',', $this->data['openid_signed']) as $key) { $keyMatch = 'sreg.'; if (substr($key, 0, strlen($keyMatch)) != $keyMatch) { continue; } $key = substr($key, strlen($keyMatch)); if (!isset($sreg_to_ax[$key])) { # The field name isn't part of the SREG spec, so we ignore it. continue; } $attributes[$sreg_to_ax[$key]] = $this->data['openid_sreg_' . $key]; } return $attributes; } /** * Gets AX/SREG attributes provided by OP. should be used only after successful validaton. * Note that it does not guarantee that any of the required/optional parameters will be present, * or that there will be no other attributes besides those specified. * In other words. OP may provide whatever information it wants to. * * SREG names will be mapped to AX names. * * @return Array Array of attributes with keys being the AX schema names, e.g. 'contact/email' * @see http://www.axschema.org/types/ */ function getAttributes() { if (isset($this->data['openid_ns']) && $this->data['openid_ns'] == 'http://specs.openid.net/auth/2.0' ) { # OpenID 2.0 # We search for both AX and SREG attributes, with AX taking precedence. return $this->getAxAttributes() + $this->getSregAttributes(); } return $this->getSregAttributes(); } } |
Added page_flag.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | <?php /** * type: page * title: Flagging * description: Allows users to flag project listings for moderator attention. * * A submission here will both increase the `release`.`flag` counter, * as well as leave a documentation entry in the `flags` table. * */ include("layout_header.php"); ?> <section id=main> <?php $name = $_REQUEST->name["name"]; // submit if ($_REQUEST->has("reason", "note", "name")) { // exists if (db("SELECT note FROM flags WHERE name=? and submitter_openid=?", $name, $_SESSION["openid"])->fetch()) { print "<h2>Flag exists</h2> <p>You have previously flagged this entry. Please give us some time to deal with it.</p>"; } // new flag else { $reason = $_REQUEST->nocontrol->ascii->text["reason"]; $note = $_REQUEST->nocontrol->ascii->text["note"]; // Into `flags` table db("INSERT INTO flags (reason, note, name, submitter_openid, submitter_ip) VALUES (?,?,?,?,?)", $reason, $note, $name, $_SESSION["openid"], $_SERVER->ip["REMOTE_ADDR"] ); // Increase `release`.`flag` column (just the last entry) db("UPDATE release SET flag=flag+1 WHERE name=? ORDER BY t_changed DESC LIMIT 1", $name ); print "<h2>Thank you</h2> <p>We'll investigate. Thanks for your time and attention!</p>"; } } // notifaction form else { print <<< HTML <h2>Flag "$name" for moderator attention</h2> <p> If you feel there's a project listing here that has issues, just tell us. </p> <p> <form action="" method=POST enctype="multipart/form-data" accept-encoding="UTF-8"> <input type=hidden name=name value="$name"> <label> <input type=radio name=reason value=spam> It's just spam. </label> <label> <input type=radio name=reason value=non-english> Listing is not in English. </label> <label> <input type=radio name=reason value=low-quality> Low quality / formatting issues. </label> <label> <input type=radio name=reason value=urls> URLs are no longer working. </label> <label> <input checked type=radio name=reason value=inappropriate> Other (use the note box below in either case). </label> <label> <textarea name=note cols=50 rows=5 placeholder="Moderators, I summon thee, because ..."></textarea> </label> <label> <input type=submit value=Submit> </label> </form> </p> <p>This is also a reasonable contact mechanism if you want to report another type of bug. For reclaiming a lost OpenID logon please preferrably contact us per mail.</p> HTML; } include("layout_bottom.php"); ?> |
Added page_index.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 | <?php /** * type: page * title: Project release listing * description: Front page for listing recently submitted projects and their releases * * */ include("layout_header.php"); ?> <section id=main> <?php // query projects $releases = db(" SELECT * FROM release WHERE flag < 5 GROUP BY name, version ORDER BY t_published DESC, t_changed DESC LIMIT 50 "); // show foreach ($releases->fetchAll() as $entry) { // HTML escaping and some autogenerated fields prepare_output($entry); // Callback for varexpression function calls in heredoc $_ = "trim"; // Output print <<<HTML <article class=project> <h3> <a href="projects/$entry[name]">$entry[title] <em class=version>$entry[version]</em></a> <span class=links> <span class=published_date>$entry[formatted_date]}</span> <a href="$entry[homepage]"><img src="img/home.png" width=20 height=20 border=0 align=middle></a> <a href="$entry[download]"><img src="img/disk.png" width=20 height=20 border=0 align=middle></a> </span> </h3> <a href="$entry[homepage]"><img class=preview src="$entry[image]" align=right width=120 height=90 border=0></a> <p class=description>$entry[description]</p> <p class=release-notes><b>$entry[scope]:</b> $entry[changes]</p> <p class=tags><img src="img/tag.png" width=49 align=left height=22 border=0><a class=license>$entry[license]</a>{$_(wrap_tags($entry["tags"]))}</p> </article> HTML; } include("layout_bottom.php"); ?> |
Added page_links.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | <?php /** * title: Links to other directories * description: Collection/overview of other software tracking / link lists. * version: 0.1 * */ include("layout_header.php"); ?> <section id=main> <?php print preg_replace("~(?<![<\">])(https?://[^\s,]+)~", "<a href=\"$1\">$1</a>", <<<HTML <h2>Other FLOSS/Linux software directories</h2> <p> <a href="http://freecode.com/">Freecode.com (AKA Freshmeat.net)</a> is only an archive henceforth. But various other software repositories still exist. </p> <p> <ul> <li> <a href="http://freshcode.club/">freshcode.club</a>, <a href="http://freecode.club/">freecode.club</a> and <a href="http://freshmeat.club/">freshmeat.club</a> are supposed to become FM/FC substitutes with differing views on shared data sets. <li> <a href="http://directory.fsf.org/">http://directory.fsf.org/</a> - Free Software directory <li> http://www.ohloh.net/ - Statistically tracks open source project development. <li> http://sourceforge.net/ - The original open source development plattform is still home to and primary notification hub for many projects. <li> http://github.com/ - Is a frontend onto a distributed version control system. It's less suited for end users, but still allows searching for software. <li> http://savannah.nongnu.org/ - Provides an alternative Free software development plattform. <li> https://launchpad.net/ - Is the development hub for Ubuntu and also lists a few things that haven't made it into the package managers yet. <li> http://www.opensourcesoftwaredirectory.com/ - Lists only stable and well-known Linux software, as it's intended for end users. <li> http://www.linuxalt.com/ - Curates a list of Linux software alternatives for migrating newcomers. <li> <a href="http://www.libe.net/version/index.php">Libe.net</a> - Linux and open source software archive <li> And, of course, WP as always provides a few open source listings as well: http://en.wikipedia.org/wiki/List_of_free_and_open-source_software_packages </ul> </p> <h2>Script directories, mixed open source/commercial listing</h2> <p> The following listing directories contain web software. For the largest part their code is super ancient, and there are lots of non-free listings. </p> <p> <ul> <li> http://www.hotscripts.com/ <li> http://www.devscripts.com/ <li> http://www.developertutorials.com/scripts/ <li> http://www.bigresource.com/scripts/ <li> http://www.scripts.com/ <li> http://www.fatscripts.com/ <li> http://www.scripts20.com/ <li> http://www.needscripts.com/ <li> http://www.advancescripts.com/ </ul> </p> <h2>Paid-for listings</h2> <ul> <li> http://osliving.com/ - Kinda odd, seems to thrive on click thru ads and is primarily about receiving donations for FLOSS listings. <p> </ul> </p> <br><br>TODO: Add screenshots. HTML ); include("layout_bottom.php"); ?> |
Added page_login.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 | <?php /** * OpenID login. * * * */ // initiate verification if ($_POST->has("login_url")) { include_once("openid.php"); $openid = new LightOpenID(HTTP_HOST); $openid->identity = $_POST->uri["login_url"]; $openid->optional = array("namePerson/friendly"); exit(header("Location: " . $openid->authUrl())); } // else display form include("layout_header.php"); ?> <section id=main> <?php ?> <h3>Login</h3> <p>Please provide an OpenID handle.</p> <p> <form action="" method=POST class=box> <input type=text name=login_url size=50 value="" placeholder="http://name.openid.xy/"> <br> <input type=submit value=Login> </form> </p> <p>There are intentionally no user accounts on freshcode.club, but this prerequisite also helps eschew spam submissions.</p> <?php include("layout_bottom.php"); ?> |
Added page_projects.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | <?php /** * type: page * title: Project detail view * description: List project entry with all URLs and releases * * */ include("layout_header.php"); // query projects $releases = db(" SELECT * FROM release WHERE name = ? GROUP BY name, version ORDER BY t_published DESC, t_changed DESC LIMIT 1 ", $_REQUEST->name["name"]); // show if ($entry = $releases->fetch()) { // HTML preparation and some auto-generated fields prepare_output($entry); // callback for varexpression function calls in heredoc $_ = "trim"; // output print <<<HTML <aside id=sidebar> <section> <h5>Links</h5> <a href="$entry[homepage]"><img src="img/home.png" width=11 height=11> Project Website</a><br> <a href="$entry[download]"><img src="img/disk.png" width=11 height=11> Download</a><br> {$_(proj_links($entry["urls"], $entry))} </section> <section> <a href="/?user=$entry[submitter]">$entry[submitter]</a><br> </section> <section style="font-size:90%"> You can also help out here by:<br> <a class=long-links href="/submit/$entry[name]" style="display:inline-block; margin: 3pt 1pt;">← Updating infos</a><br> or <a href="/flag/$entry[name]">flagging</a> this entry for moderator attention. </section> </aside> <section id=main> <article class=project> <h3> <a href="projects/$entry[name]">$entry[title] <em class=version>$entry[version]</em></a> </h3> <a href="$entry[homepage]"><img class=preview src="$entry[image]" align=right width=120 height=90 border=0></a> <p class=description style="border:0">$entry[description]</p> <p class=long-tags><span>Tags</span> {$_(wrap_tags($entry["tags"]))}</p> <p class=long-tags><span>License</span> <a class=license>$entry[license]</a></p> <p class=long-links> <a href="$entry[homepage]"><img src="img/home.png" width=20 height=20 border=0 align=middle> Homepage</a> <a href="$entry[download]"><img src="img/disk.png" width=20 height=20 border=0 align=middle> Download</a> </p> </article> HTML; } // query projects $releases = db(" SELECT * FROM release WHERE name = ? AND flag < 5 GROUP BY name, version ORDER BY t_published DESC, t_changed DESC ", $_REQUEST->name["name"]); // show print " <article class=release-list> <h3>Recent Releases</h3> "; while ($entry = $releases->fetch()) { prepare_output($entry); // output print <<<HTML <div class=release-entry> <span class=version>$entry[version]</span><span class=published_date>{$_(strftime("%d %b %Y %H:%M", $entry["t_published"]))}</span> <span class=release-notes> <b>$entry[scope]:</b> $entry[changes] </span> </div> HTML; } print "</article>"; include("layout_bottom.php"); function proj_links($urls, $entry, $r="") { foreach (p_key_value($urls) as $title=>$url) { $title = ucwords($title); $url = versioned_url($url, $entry["version"]); $r .= "→ <a href=\"$url\">$title</a><br>\n"; } return $r; } ?> |
Added page_submit.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | <?php /** * api: freshcode * type: page * title: Submit/edit project or release * description: Single-page edit form for projects and their releases * version: 0.2 * category: form * * * Prepares the submission form, * handles database preparation * and merges in previous release entries. * * */ // Form field names $fields = array( "name", "title", "homepage", "description", "license", "tags", "image", "version", "state", "scope", "changes", "download", "urls", "autoupdate_module", "autoupdate_url", "autoupdate_regex", "submitter", "lock", ); // Start page output include("layout_header.php"); ?> <section id=main> <?php // Project name from request $name = $_REQUEST->nocontrol->trim->name->strtolower->length_3to33["name"]; // Check for existing project infos from database if ($data = db("SELECT * FROM release WHERE name = ?", $name)->fetch()) { $is_new = 0; } else { // Create new empty $data set $data = array_combine($fields, array_fill(0, count($fields), "")); #$data = $_REQUEST->list->nocontrol->trim[$fields]; $is_new = 1; $data["name"] = $name; $data["submitter"] = $_SESSION["name"]; $data["t_published"] = time(); } // Project entry can be locked for editing by specific OpenIDs if (LOGIN_REQUIRED and !$is_new and $data["lock"] and !in_array($_SESSION["openid"], array_merge(str_getcsv($data["lock"]), $moderator_ids))) { print "<h3>Locked</h3> <p>This entry cannot be edited with your current login. Its original author registered a different OpenID.</p>"; } #-- Fetch form input elseif ($name and $_REQUEST->has("title", "description")) { // Check field lengths if (!$_REQUEST->multi->min_length_100["title,description,homepage,changes"]) { print("<h3>Submission too short</h3> <p>You didn't fill out crucial information. Please note that our user base expects an enticing set of data points to find your project.</p>"); } // Terms and conditions elseif (array_sum($_REQUEST->array->int["req"]) < 3) { print "<h3>Terms and Conditions</h3> <p>Please go back and assert that your open source project listing is reusable under the CC-BY-SA license.</p>"; } // Passed else { // Merge input $data = array_merge( $data, $_REQUEST->list->nocontrol->trim[$fields], array( "t_changed" => time(), "flag" => 0, "submitter_openid" => $_SERVER["openid"], #"deleted" => 0, ) ); // Update project #db()->test = 1; if (db("INSERT INTO release (:?) VALUES (::)", $data, $data)) { print "<h2>Submitted</h2> <p>Your project and release informations has been saved.</p> <p>See the result in <a href='http://freshcode.org/projects/$name'>http://freshcode.org/projects/$name</a>.</p>"; } else { print "Unspecified error."; } } } #-- Output input form else { $data = array_map("input::_html", $data); $select = "form_select_options"; print <<<HTML <form action="" method=POST enctype="multipart/form-data" accept-encoding=UTF-8> <input type=hidden name=is_new value=$is_new> <h2>Submit project and/or release</h2> <p> You can submit <em title="Free, Libre, and Open Source Software">FLOSS</em> or <em title="or Solaris/Darwin/Hurd">BSD/Linux</em> software here. It's not required that you're a developer of said project. </p> <p> You can always edit the common project information together with a current release. It will show up on the frontpage whenever you update a new version number and a changelog summary. </p> <h3>General Project Info</h3> <p> <label> Project ID <input name=name size=20 placeholder=projectname value="$data[name]"> <small>A short moniker which becomes your http://freshcode.club/projects/<b>name</b>.</small> </label> <label> Title <input name=title size=50 placeholder="Awesome Software" value="$data[title]"> </label> <label> Homepage <input name=homepage size=50 type=url placeholder="http://project.example.org/" value="$data[homepage]"> </label> <label> Description <textarea cols=50 rows=8 name=description>$data[description]</textarea> <small>Please give a concise roundup of what this software does, what specific features it provides, the intended target audience, or how it compares to similar apps.</small> </label> <label> License <input name=license size=20 placeholder="MITL, BSDL, GNU GPL" value="$data[license]"> <small>Use abbreviated license names preferrably.</small> </label> <label> Tags <input name=tags size=50 placeholder="game, desktop, gtk, python" value="$data[tags]"> <small>Categorize your project using free-form tags. This can include usage context, application type, programming languages, related projects, etc. It's limited to five tags however.</small> </label> <label> Image <input name=image size=50 placeholder="http://i.imgur.com/xyzbar.png" value="$data[image]"> <small>Provide a preview image of up to 120x90 px. Supply a path to your website or use e.g. <a href="http://imgur.com/">imgur</a> for uploading.</small> </label> </p> <h3>Release Submission</h3> <p> <label> Version <input name=version size=20 placeholder=2.0.1 value="$data[version]"> <small>Prefer <a href="http://semver.org/">semantic versioning</a> for releases.</small> </label> <label> State <select name=state> {$select("initial,alpha,beta,development,prerelease,stable,mature,historic", $data["state"])} </select> <small>You can indicate the stability or target audience of the current release.</small> </label> <label> Scope <br> <select name=scope> {$select("minor feature,minor bugfix,major feature,major bugfix,security,documentation,cleanup,hidden", $data["scope"])} </select> <small>Indicate the significance and primary scope of this release.</small> </label> <label> Changes <textarea cols=50 rows=7 name=changes>$data[changes]</textarea> <small>Summarize the changes in this release. Documentation additions are as crucial as new features or fixed issues.</small> </label> <label> Download URL <input name=download size=50 type=url placeholder="http://project.example.org/" value="$data[download]"> </label> <label> Other URLs <textarea cols=50 rows=3 name=urls>$data[urls]</textarea> <small>You can add more project URLs using a comma/newline-separated list like <tt>src=http://, deb=http://</tt>. Common link types include src=, rpm=, deb=, txz=, dvcs=, forum=, changelog=, etc.</small> </label> </p> <h3>Automatic Release Tracking</h3> <p> <em>You can skip this section.</em> But instead of registering each version manually, you can later automate the process with some version control systems or e.g. your project homepage and changelog. See the <a href="http://fossil.include-once.org/freshcode/wiki/Autoupdate">Autoupdate Howto</a>. </p> <p> <label> Via <select name=autoupdate_module> {$select("none,github,sourceforge,regex", $data["autoupdate_module"])} </select> </label> <label> Autoupdate URL <input name=autoupdate_url type=url size=50 value="$data[autoupdate_url]" placeholder="https://github.com/user/project/tags.atom"> <small>Add your GitHub tags or Sourceforge project feed URL here. <br>For the Regex method this is the primary source to retrieve and read from.</small> </label> <label> Regex <textarea cols=50 rows=3 name=autoupdate_regex placeholder="version = /-(\d+\.\d+\.\d+)\.txz/">$data[autoupdate_regex]</textarea> <small> <a href="http://fossil.include-once.org/freshcode/wiki/AutoupdateRegex">Regex automated updates</a> expect a list of field=/regex/ names, like version=, changes=, download=, state=. Like-named "Other URLs" are used alternatively as extraction sources.</small> </label> </p> <h3>Publish</h3> <p> Please proofread again before saving. <label> Submitter <input name=submitter size=50 placeholder="Your name" value="$data[submitter]"> <small>Give us your name or nick name here.</small> </label> <label> Lock Entry <input name=lock size=50 placeholder="$_SESSION[openid]" value="$data[lock]"> <small>Normally all projects can be edited by everyone (WikiStyle). If you commit to yours, you can however lock this submission against an OpenID handle. (Or even provide a comma-separated list here for multiple contributors.)</small> </label> </p> <p> <b>Terms and Conditions</b> <label class=inline><input type=checkbox name="req[os]" value=1> It's open source / libre / Free software or pertains BSD/Linux.</label> <label class=inline><input type=checkbox name="req[cc]" value=1> Your entry is shareable under the <a href="http://creativecommons.org/licenses/by-sa/4.0/">CC-BY-SA</a> license.</label> <label class=inline><input type=checkbox name="req[sp]" value=1> And it's not spam.</label> </p> <p> <input type=submit value="Submit Project/Release"> </p> <p style=margin-bottom:75pt> Thanks for your time and effort! </p> </form> HTML; } include("layout_bottom.php"); // Output a list of select <option>s function form_select_options($names, $value, $r="") { foreach (str_getcsv($names) as $id) { $r .= "<option" . ($id == $value ? " selected" : "") . " value=\"$id\">$id</option>"; } return $r; } ?> |
Added page_tags.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 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 | <?php /** * type: page * title: Tags * description: Tag cloud * status: todo * * We'll need a separate `tags` table for that, populated by a cron * script (or trigger?) that splits up the `release`.`tags` column * per project id. * Display may just be handled by page_index, with an extra search * param (?tag=...; a ?user= query is needed as well). * */ include("layout_header.php"); ?> <section id=main> <h2>Tags</h2> <p> There are still too few project listings to warrant a tag cloud. </p> <?php include("layout_bottom.php"); ?> |