From 9e9d77b4072de4f8c73e8bbade07a8f27734e4bd Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 6 Feb 2010 23:14:56 +0100 Subject: Initial commit Signed-off-by: Florian Pritz --- system/application/config/.gitignore | 1 + system/application/config/example/.gitignore | 1 + system/application/config/example/autoload.php | 116 ++++++++ system/application/config/example/config.php | 348 ++++++++++++++++++++++ system/application/config/example/constants.php | 43 +++ system/application/config/example/database.php | 55 ++++ system/application/config/example/doctypes.php | 15 + system/application/config/example/hooks.php | 16 + system/application/config/example/mimes.php | 105 +++++++ system/application/config/example/routes.php | 47 +++ system/application/config/example/smileys.php | 66 ++++ system/application/config/example/user_agents.php | 175 +++++++++++ system/application/config/index.html | 10 + system/application/controllers/file.php | 231 ++++++++++++++ system/application/controllers/index.html | 10 + system/application/errors/error_404.php | 35 +++ system/application/errors/error_db.php | 34 +++ system/application/errors/error_general.php | 34 +++ system/application/errors/error_php.php | 10 + system/application/errors/index.html | 10 + system/application/helpers/index.html | 10 + system/application/hooks/index.html | 10 + system/application/index.html | 10 + system/application/language/english/index.html | 10 + system/application/libraries/index.html | 10 + system/application/models/file_mod.php | 164 ++++++++++ system/application/models/index.html | 10 + system/application/views/file/footer.php | 3 + system/application/views/file/header.php | 19 ++ system/application/views/file/non_existant.php | 3 + system/application/views/file/show_url.php | 4 + system/application/views/file/too_big.php | 3 + system/application/views/file/upload_error.php | 4 + system/application/views/file/upload_form.php | 18 ++ system/application/views/index.html | 10 + 35 files changed, 1650 insertions(+) create mode 100644 system/application/config/.gitignore create mode 100644 system/application/config/example/.gitignore create mode 100755 system/application/config/example/autoload.php create mode 100755 system/application/config/example/config.php create mode 100755 system/application/config/example/constants.php create mode 100755 system/application/config/example/database.php create mode 100755 system/application/config/example/doctypes.php create mode 100755 system/application/config/example/hooks.php create mode 100755 system/application/config/example/mimes.php create mode 100755 system/application/config/example/routes.php create mode 100755 system/application/config/example/smileys.php create mode 100755 system/application/config/example/user_agents.php create mode 100755 system/application/config/index.html create mode 100644 system/application/controllers/file.php create mode 100644 system/application/controllers/index.html create mode 100644 system/application/errors/error_404.php create mode 100644 system/application/errors/error_db.php create mode 100644 system/application/errors/error_general.php create mode 100644 system/application/errors/error_php.php create mode 100644 system/application/errors/index.html create mode 100644 system/application/helpers/index.html create mode 100644 system/application/hooks/index.html create mode 100644 system/application/index.html create mode 100644 system/application/language/english/index.html create mode 100644 system/application/libraries/index.html create mode 100644 system/application/models/file_mod.php create mode 100644 system/application/models/index.html create mode 100644 system/application/views/file/footer.php create mode 100644 system/application/views/file/header.php create mode 100644 system/application/views/file/non_existant.php create mode 100644 system/application/views/file/show_url.php create mode 100644 system/application/views/file/too_big.php create mode 100644 system/application/views/file/upload_error.php create mode 100644 system/application/views/file/upload_form.php create mode 100644 system/application/views/index.html (limited to 'system/application') diff --git a/system/application/config/.gitignore b/system/application/config/.gitignore new file mode 100644 index 000000000..cde8069e1 --- /dev/null +++ b/system/application/config/.gitignore @@ -0,0 +1 @@ +*.php diff --git a/system/application/config/example/.gitignore b/system/application/config/example/.gitignore new file mode 100644 index 000000000..f9be8dfe0 --- /dev/null +++ b/system/application/config/example/.gitignore @@ -0,0 +1 @@ +!* diff --git a/system/application/config/example/autoload.php b/system/application/config/example/autoload.php new file mode 100755 index 000000000..9cd7a4fce --- /dev/null +++ b/system/application/config/example/autoload.php @@ -0,0 +1,116 @@ + '', + 'xhtml1-strict' => '', + 'xhtml1-trans' => '', + 'xhtml1-frame' => '', + 'html5' => '', + 'html4-strict' => '', + 'html4-trans' => '', + 'html4-frame' => '' + ); + +/* End of file doctypes.php */ +/* Location: application/config/doctypes.php */ \ No newline at end of file diff --git a/system/application/config/example/hooks.php b/system/application/config/example/hooks.php new file mode 100755 index 000000000..5e98a9b46 --- /dev/null +++ b/system/application/config/example/hooks.php @@ -0,0 +1,16 @@ + 'application/mac-binhex40', + 'cpt' => 'application/mac-compactpro', + 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'), + 'bin' => 'application/macbinary', + 'dms' => 'application/octet-stream', + 'lha' => 'application/octet-stream', + 'lzh' => 'application/octet-stream', + 'exe' => 'application/octet-stream', + 'class' => 'application/octet-stream', + 'psd' => 'application/x-photoshop', + 'so' => 'application/octet-stream', + 'sea' => 'application/octet-stream', + 'dll' => 'application/octet-stream', + 'oda' => 'application/oda', + 'pdf' => array('application/pdf', 'application/x-download'), + 'ai' => 'application/postscript', + 'eps' => 'application/postscript', + 'ps' => 'application/postscript', + 'smi' => 'application/smil', + 'smil' => 'application/smil', + 'mif' => 'application/vnd.mif', + 'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'), + 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'), + 'wbxml' => 'application/wbxml', + 'wmlc' => 'application/wmlc', + 'dcr' => 'application/x-director', + 'dir' => 'application/x-director', + 'dxr' => 'application/x-director', + 'dvi' => 'application/x-dvi', + 'gtar' => 'application/x-gtar', + 'gz' => 'application/x-gzip', + 'php' => 'application/x-httpd-php', + 'php4' => 'application/x-httpd-php', + 'php3' => 'application/x-httpd-php', + 'phtml' => 'application/x-httpd-php', + 'phps' => 'application/x-httpd-php-source', + 'js' => 'application/x-javascript', + 'swf' => 'application/x-shockwave-flash', + 'sit' => 'application/x-stuffit', + 'tar' => 'application/x-tar', + 'tgz' => 'application/x-tar', + 'xhtml' => 'application/xhtml+xml', + 'xht' => 'application/xhtml+xml', + 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'), + 'mid' => 'audio/midi', + 'midi' => 'audio/midi', + 'mpga' => 'audio/mpeg', + 'mp2' => 'audio/mpeg', + 'mp3' => array('audio/mpeg', 'audio/mpg'), + 'aif' => 'audio/x-aiff', + 'aiff' => 'audio/x-aiff', + 'aifc' => 'audio/x-aiff', + 'ram' => 'audio/x-pn-realaudio', + 'rm' => 'audio/x-pn-realaudio', + 'rpm' => 'audio/x-pn-realaudio-plugin', + 'ra' => 'audio/x-realaudio', + 'rv' => 'video/vnd.rn-realvideo', + 'wav' => 'audio/x-wav', + 'bmp' => 'image/bmp', + 'gif' => 'image/gif', + 'jpeg' => array('image/jpeg', 'image/pjpeg'), + 'jpg' => array('image/jpeg', 'image/pjpeg'), + 'jpe' => array('image/jpeg', 'image/pjpeg'), + 'png' => array('image/png', 'image/x-png'), + 'tiff' => 'image/tiff', + 'tif' => 'image/tiff', + 'css' => 'text/css', + 'html' => 'text/html', + 'htm' => 'text/html', + 'shtml' => 'text/html', + 'txt' => 'text/plain', + 'text' => 'text/plain', + 'log' => array('text/plain', 'text/x-log'), + 'rtx' => 'text/richtext', + 'rtf' => 'text/rtf', + 'xml' => 'text/xml', + 'xsl' => 'text/xml', + 'mpeg' => 'video/mpeg', + 'mpg' => 'video/mpeg', + 'mpe' => 'video/mpeg', + 'qt' => 'video/quicktime', + 'mov' => 'video/quicktime', + 'avi' => 'video/x-msvideo', + 'movie' => 'video/x-sgi-movie', + 'doc' => 'application/msword', + 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'word' => array('application/msword', 'application/octet-stream'), + 'xl' => 'application/excel', + 'eml' => 'message/rfc822' + ); + + +/* End of file mimes.php */ +/* Location: ./system/application/config/mimes.php */ \ No newline at end of file diff --git a/system/application/config/example/routes.php b/system/application/config/example/routes.php new file mode 100755 index 000000000..1edd3f93c --- /dev/null +++ b/system/application/config/example/routes.php @@ -0,0 +1,47 @@ + array('grin.gif', '19', '19', 'grin'), + ':lol:' => array('lol.gif', '19', '19', 'LOL'), + ':cheese:' => array('cheese.gif', '19', '19', 'cheese'), + ':)' => array('smile.gif', '19', '19', 'smile'), + ';-)' => array('wink.gif', '19', '19', 'wink'), + ';)' => array('wink.gif', '19', '19', 'wink'), + ':smirk:' => array('smirk.gif', '19', '19', 'smirk'), + ':roll:' => array('rolleyes.gif', '19', '19', 'rolleyes'), + ':-S' => array('confused.gif', '19', '19', 'confused'), + ':wow:' => array('surprise.gif', '19', '19', 'surprised'), + ':bug:' => array('bigsurprise.gif', '19', '19', 'big surprise'), + ':-P' => array('tongue_laugh.gif', '19', '19', 'tongue laugh'), + '%-P' => array('tongue_rolleye.gif', '19', '19', 'tongue rolleye'), + ';-P' => array('tongue_wink.gif', '19', '19', 'tongue wink'), + ':P' => array('raspberry.gif', '19', '19', 'raspberry'), + ':blank:' => array('blank.gif', '19', '19', 'blank stare'), + ':long:' => array('longface.gif', '19', '19', 'long face'), + ':ohh:' => array('ohh.gif', '19', '19', 'ohh'), + ':grrr:' => array('grrr.gif', '19', '19', 'grrr'), + ':gulp:' => array('gulp.gif', '19', '19', 'gulp'), + '8-/' => array('ohoh.gif', '19', '19', 'oh oh'), + ':down:' => array('downer.gif', '19', '19', 'downer'), + ':red:' => array('embarrassed.gif', '19', '19', 'red face'), + ':sick:' => array('sick.gif', '19', '19', 'sick'), + ':shut:' => array('shuteye.gif', '19', '19', 'shut eye'), + ':-/' => array('hmm.gif', '19', '19', 'hmmm'), + '>:(' => array('mad.gif', '19', '19', 'mad'), + ':mad:' => array('mad.gif', '19', '19', 'mad'), + '>:-(' => array('angry.gif', '19', '19', 'angry'), + ':angry:' => array('angry.gif', '19', '19', 'angry'), + ':zip:' => array('zip.gif', '19', '19', 'zipper'), + ':kiss:' => array('kiss.gif', '19', '19', 'kiss'), + ':ahhh:' => array('shock.gif', '19', '19', 'shock'), + ':coolsmile:' => array('shade_smile.gif', '19', '19', 'cool smile'), + ':coolsmirk:' => array('shade_smirk.gif', '19', '19', 'cool smirk'), + ':coolgrin:' => array('shade_grin.gif', '19', '19', 'cool grin'), + ':coolhmm:' => array('shade_hmm.gif', '19', '19', 'cool hmm'), + ':coolmad:' => array('shade_mad.gif', '19', '19', 'cool mad'), + ':coolcheese:' => array('shade_cheese.gif', '19', '19', 'cool cheese'), + ':vampire:' => array('vampire.gif', '19', '19', 'vampire'), + ':snake:' => array('snake.gif', '19', '19', 'snake'), + ':exclaim:' => array('exclaim.gif', '19', '19', 'excaim'), + ':question:' => array('question.gif', '19', '19', 'question') // no comma after last item + + ); + +/* End of file smileys.php */ +/* Location: ./system/application/config/smileys.php */ \ No newline at end of file diff --git a/system/application/config/example/user_agents.php b/system/application/config/example/user_agents.php new file mode 100755 index 000000000..c01b2767d --- /dev/null +++ b/system/application/config/example/user_agents.php @@ -0,0 +1,175 @@ + 'Windows Longhorn', + 'windows nt 5.2' => 'Windows 2003', + 'windows nt 5.0' => 'Windows 2000', + 'windows nt 5.1' => 'Windows XP', + 'windows nt 4.0' => 'Windows NT 4.0', + 'winnt4.0' => 'Windows NT 4.0', + 'winnt 4.0' => 'Windows NT', + 'winnt' => 'Windows NT', + 'windows 98' => 'Windows 98', + 'win98' => 'Windows 98', + 'windows 95' => 'Windows 95', + 'win95' => 'Windows 95', + 'windows' => 'Unknown Windows OS', + 'os x' => 'Mac OS X', + 'ppc mac' => 'Power PC Mac', + 'freebsd' => 'FreeBSD', + 'ppc' => 'Macintosh', + 'linux' => 'Linux', + 'debian' => 'Debian', + 'sunos' => 'Sun Solaris', + 'beos' => 'BeOS', + 'apachebench' => 'ApacheBench', + 'aix' => 'AIX', + 'irix' => 'Irix', + 'osf' => 'DEC OSF', + 'hp-ux' => 'HP-UX', + 'netbsd' => 'NetBSD', + 'bsdi' => 'BSDi', + 'openbsd' => 'OpenBSD', + 'gnu' => 'GNU/Linux', + 'unix' => 'Unknown Unix OS' + ); + + +// The order of this array should NOT be changed. Many browsers return +// multiple browser types so we want to identify the sub-type first. +$browsers = array( + 'Opera' => 'Opera', + 'MSIE' => 'Internet Explorer', + 'Internet Explorer' => 'Internet Explorer', + 'Shiira' => 'Shiira', + 'Firefox' => 'Firefox', + 'Chimera' => 'Chimera', + 'Phoenix' => 'Phoenix', + 'Firebird' => 'Firebird', + 'Camino' => 'Camino', + 'Netscape' => 'Netscape', + 'OmniWeb' => 'OmniWeb', + 'Mozilla' => 'Mozilla', + 'Safari' => 'Safari', + 'Konqueror' => 'Konqueror', + 'icab' => 'iCab', + 'Lynx' => 'Lynx', + 'Links' => 'Links', + 'hotjava' => 'HotJava', + 'amaya' => 'Amaya', + 'IBrowse' => 'IBrowse' + ); + +$mobiles = array( + // legacy array, old values commented out + 'mobileexplorer' => 'Mobile Explorer', +// 'openwave' => 'Open Wave', +// 'opera mini' => 'Opera Mini', +// 'operamini' => 'Opera Mini', +// 'elaine' => 'Palm', + 'palmsource' => 'Palm', +// 'digital paths' => 'Palm', +// 'avantgo' => 'Avantgo', +// 'xiino' => 'Xiino', + 'palmscape' => 'Palmscape', +// 'nokia' => 'Nokia', +// 'ericsson' => 'Ericsson', +// 'blackberry' => 'BlackBerry', +// 'motorola' => 'Motorola' + + // Phones and Manufacturers + 'motorola' => "Motorola", + 'nokia' => "Nokia", + 'palm' => "Palm", + 'iphone' => "Apple iPhone", + 'ipod' => "Apple iPod Touch", + 'sony' => "Sony Ericsson", + 'ericsson' => "Sony Ericsson", + 'blackberry' => "BlackBerry", + 'cocoon' => "O2 Cocoon", + 'blazer' => "Treo", + 'lg' => "LG", + 'amoi' => "Amoi", + 'xda' => "XDA", + 'mda' => "MDA", + 'vario' => "Vario", + 'htc' => "HTC", + 'samsung' => "Samsung", + 'sharp' => "Sharp", + 'sie-' => "Siemens", + 'alcatel' => "Alcatel", + 'benq' => "BenQ", + 'ipaq' => "HP iPaq", + 'mot-' => "Motorola", + 'playstation portable' => "PlayStation Portable", + 'hiptop' => "Danger Hiptop", + 'nec-' => "NEC", + 'panasonic' => "Panasonic", + 'philips' => "Philips", + 'sagem' => "Sagem", + 'sanyo' => "Sanyo", + 'spv' => "SPV", + 'zte' => "ZTE", + 'sendo' => "Sendo", + + // Operating Systems + 'symbian' => "Symbian", + 'SymbianOS' => "SymbianOS", + 'elaine' => "Palm", + 'palm' => "Palm", + 'series60' => "Symbian S60", + 'windows ce' => "Windows CE", + + // Browsers + 'obigo' => "Obigo", + 'netfront' => "Netfront Browser", + 'openwave' => "Openwave Browser", + 'mobilexplorer' => "Mobile Explorer", + 'operamini' => "Opera Mini", + 'opera mini' => "Opera Mini", + + // Other + 'digital paths' => "Digital Paths", + 'avantgo' => "AvantGo", + 'xiino' => "Xiino", + 'novarra' => "Novarra Transcoder", + 'vodafone' => "Vodafone", + 'docomo' => "NTT DoCoMo", + 'o2' => "O2", + + // Fallback + 'mobile' => "Generic Mobile", + 'wireless' => "Generic Mobile", + 'j2me' => "Generic Mobile", + 'midp' => "Generic Mobile", + 'cldc' => "Generic Mobile", + 'up.link' => "Generic Mobile", + 'up.browser' => "Generic Mobile", + 'smartphone' => "Generic Mobile", + 'cellphone' => "Generic Mobile" + ); + +// There are hundreds of bots but these are the most common. +$robots = array( + 'googlebot' => 'Googlebot', + 'msnbot' => 'MSNBot', + 'slurp' => 'Inktomi Slurp', + 'yahoo' => 'Yahoo', + 'askjeeves' => 'AskJeeves', + 'fastcrawler' => 'FastCrawler', + 'infoseek' => 'InfoSeek Robot 1.0', + 'lycos' => 'Lycos' + ); + +/* End of file user_agents.php */ +/* Location: ./system/application/config/user_agents.php */ \ No newline at end of file diff --git a/system/application/config/index.html b/system/application/config/index.html new file mode 100755 index 000000000..c942a79ce --- /dev/null +++ b/system/application/config/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/application/controllers/file.php b/system/application/controllers/file.php new file mode 100644 index 000000000..d22cb9dfe --- /dev/null +++ b/system/application/controllers/file.php @@ -0,0 +1,231 @@ + + * + * Licensed under GPLv3 + * (see COPYING for full license text) + * + */ + +class File extends Controller { + // TODO: Add comments + + function __construct() + { + parent::Controller(); + $this->load->helper('form'); + $this->load->model('file_mod'); + } + + function index() + { + $this->upload_form(); + } + + function upload_form() + { + $data = array(); + $data['title'] = 'Upload'; + + $this->load->view('file/header', $data); + $this->load->view('file/upload_form', $data); + $this->load->view('file/footer', $data); + } + + function delete() + { + $id = $this->uri->segment(3); + $password = $this->input->post('password'); + if ($password !== false && $this->file_mod->id_exists($id)) { + $this->file_mod->delete_id($id, $password); + echo $id." deleted\n"; + } else { + echo 'Couldn\'t delete '.$id."\n"; + } + die(); + } + + function do_upload() + { + $data = array(); + if(isset($_FILES['userfile'])) { + if ($_FILES['userfile']['error'] === 0) { + $filesize = filesize($_FILES['userfile']['tmp_name']); + if ($filesize >= $this->config->item('upload_max_size')) { + $this->load->view('file/header', $data); + $this->load->view('file/too_big'); + } else { + $password = $this->input->post('password'); + $extension = $this->input->post('extension'); + if ($password !== false) { + $password = $this->file_mod->hash_password($password); + } else { + $password = 'NULL'; + } + + $id = $this->file_mod->new_id(); + $file_hash = md5_file($_FILES['userfile']['tmp_name']); + $file_name = $_FILES['userfile']['name']; + $folder = $this->file_mod->folder($file_hash); + file_exists($folder) || mkdir ($folder); + $file = $folder.'/'.$file_hash; + + $sql = ' + INSERT INTO `files` (`hash`, `id`, `filename`, `password`, `date`) + VALUES (?, ?, ?, ?, ?)'; + $query = $this->db->query($sql, array($file_hash, $id, $file_name, $password, time())); + + move_uploaded_file($_FILES['userfile']['tmp_name'], $file); + chmod($file, 0600); + + redirect($this->config->item('paste_show_url').$id.'/'.$extension); + } + } else { + $this->index(); + } + } else { + $this->load->view('file/header', $data); + $this->load->view('file/upload_error', $data); + $this->load->view('file/footer', $data); + } + } + + function show_url() + { + $data = array(); + $id = $this->uri->segment(3); + $mode = $this->uri->segment(4); + + if ($mode) { + $data['url'] = site_url($this->config->item('paste_download_url').$id.'/'.$mode); + } else { + $data['url'] = site_url($this->config->item('paste_download_url').$id).'/'; + } + + if (strstr($_SERVER['HTTP_USER_AGENT'], 'libcurl')) { + echo $data['url']; + } else { + $this->load->view('file/header', $data); + $this->load->view('file/show_url', $data); + $this->load->view('file/footer', $data); + } + } + + function download() + { + $data = array(); + $id = $this->uri->segment(3); + $mode = $this->uri->segment(4); + + $filedata = $this->file_mod->get_filedata($id); + + $folder = $this->file_mod->folder($filedata['hash']); + $file = $folder.'/'.$filedata['hash']; + + if ($this->file_mod->id_exists($id) && file_exists($file)) { + // MODIFIED SINCE SUPPORT -- START + // helps to keep traffic low when reloading an image + // TODO: check for bugs, find source of code again + $filedate = filectime($file); + $etag = strtolower(md5_file($file)); + $modified = true; + + if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) { + $oldtag = trim(strtolower($_SERVER['HTTP_IF_NONE_MATCH']), '"'); + if($oldtag == $etag) { + $modified = false; + } else { + $modified = true; + } + } + + if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { + $olddate = date_parse(trim(strtolower($_SERVER['HTTP_IF_MODIFIED_SINCE']))); + $olddate = gmmktime($olddate['hour'], + $olddate['minute'], + $olddate['second'], + $olddate['month'], + $olddate['day'], + $olddate['year']); + if($olddate >= $filedate) { + $modified = false; + } else { + $modified = true; + } + } + // MODIFIED SINCE SUPPORT -- END + + $type = exec('/usr/bin/perlbin/vendor/mimetype -b '.escapeshellarg($file)); + + if (!$mode && substr_count(ltrim($this->uri->uri_string(), "/"), '/') >= 3) { + $mode = $this->file_mod->mime2extension($type); + } + + if (!$modified) { + header("HTTP/1.1 304 Not Modified"); + header('Etag: "'.$etag.'"'); + } else { + if ($mode + && $this->file_mod->mime2extension($type) + && filesize($file) <= $this->config->item('upload_max_text_size') + ) { + header("Content-Type: text/html\n"); + // TODO: move to own file + echo '' + .''.$filedata['filename'].'' + .' ' + .' ' + .'' + .'
' + .' Raw' + .' ' + .'
';
+          // TODO: implement in PHP
+          echo shell_exec('/usr/bin/seq 1 $(/usr/bin/wc -l '.escapeshellarg($file).' | /bin/cut -d\  -f1) | sed -r \'s/^(.*)$/\1<\/a>/g\'');
+          echo '  
'."\n";
+          echo shell_exec(FCPATH.'scripts/syntax-highlighting.sh '.$filedata['filename'].'.'.$mode.' < '.escapeshellarg($file));
+          echo '
'; + } else { + header("Content-Type: ".$type."\n"); + header("Content-disposition: inline; filename=\"".$filedata['filename']."\"\n"); + header("Content-Length: ".filesize($file)."\n"); + header("Last-Modified: ".date('D, d M Y H:i:s', $filedate)." GMT"); + header('Etag: "'.$etag.'"'); + $fp = fopen($file,"r"); + while (!feof($fp)) { + $buff = fread($fp,4096); + echo $buff; + } + fclose($fp); + } + } + exit(); + } else { + $this->load->view('file/header', $data); + $this->load->view('file/non_existant'); + $this->load->view('file/footer', $data); + } + } + + function cron() + { + $oldest_time = (time()-$this->config->item('upload_max_age')); + $query = $this->db->query('SELECT hash, id FROM files WHERE date < ?', + array($oldest_time)); + + foreach($query->result_array() as $row) { + $file = $this->config->item('upload_path').'/'.substr($row['hash'], 0, 3).'/'.$row['hash']; + if(filemtime($file) < $oldest_time) { + unlink($file); + $this->db->query('DELETE FROM files WHERE hash = ?', array($row['hash'])); + } else { + $this->db->query('DELETE FROM files WHERE id = ?', array($row['id'])); + } + } + } +} + +/* End of file file.php */ +/* Location: ./system/application/controllers/file.php */ diff --git a/system/application/controllers/index.html b/system/application/controllers/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/application/controllers/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/application/errors/error_404.php b/system/application/errors/error_404.php new file mode 100644 index 000000000..bfe9444b2 --- /dev/null +++ b/system/application/errors/error_404.php @@ -0,0 +1,35 @@ + + + +404 Page Not Found + + + +
+

+ +
+ + \ No newline at end of file diff --git a/system/application/errors/error_db.php b/system/application/errors/error_db.php new file mode 100644 index 000000000..1ce52dfc9 --- /dev/null +++ b/system/application/errors/error_db.php @@ -0,0 +1,34 @@ + + +Database Error + + + +
+

+ +
+ + \ No newline at end of file diff --git a/system/application/errors/error_general.php b/system/application/errors/error_general.php new file mode 100644 index 000000000..d8610702b --- /dev/null +++ b/system/application/errors/error_general.php @@ -0,0 +1,34 @@ + + +Error + + + +
+

+ +
+ + \ No newline at end of file diff --git a/system/application/errors/error_php.php b/system/application/errors/error_php.php new file mode 100644 index 000000000..f085c2037 --- /dev/null +++ b/system/application/errors/error_php.php @@ -0,0 +1,10 @@ +
+ +

A PHP Error was encountered

+ +

Severity:

+

Message:

+

Filename:

+

Line Number:

+ +
\ No newline at end of file diff --git a/system/application/errors/index.html b/system/application/errors/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/application/errors/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/application/helpers/index.html b/system/application/helpers/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/application/helpers/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/application/hooks/index.html b/system/application/hooks/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/application/hooks/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/application/index.html b/system/application/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/application/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/application/language/english/index.html b/system/application/language/english/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/application/language/english/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/application/libraries/index.html b/system/application/libraries/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/application/libraries/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/application/models/file_mod.php b/system/application/models/file_mod.php new file mode 100644 index 000000000..96415bc2f --- /dev/null +++ b/system/application/models/file_mod.php @@ -0,0 +1,164 @@ + + * + * Licensed under GPLv3 + * (see COPYING for full license text) + * + */ + +class File_mod extends Model { + + function __construct() + { + parent::Model(); + } + + function new_id() + { + $id = $this->random_id(3,6); + + if ($this->id_exists($id)) { + return $this->new_id(); + } else { + return $id; + } + } + + function id_exists($id) + { + $sql = ' + SELECT id + FROM `files` + WHERE `id` = ?'; + $query = $this->db->query($sql, array($id)); + + if ($query->num_rows() == 1) { + return true; + } else { + return false; + } + } + + function get_filedata($id) + { + $sql = ' + SELECT hash,filename + FROM `files` + WHERE `id` = ?'; + $query = $this->db->query($sql, array($id)); + + if ($query->num_rows() == 1) { + $return = $query->result_array(); + return $return[0]; + } else { + return false; + } + } + + function folder($hash) { + return $this->config->item('upload_path').'/'.substr($hash, 0, 3); + } + + function hash_password($password) + { + // TODO: move salt to config + return sha1('w9yFMeU6ITrkrPBlRJfA'.$password); + } + + private function unused_file($hash) + { + $sql = ' + SELECT id + FROM `files` + WHERE `hash` = ?'; + $query = $this->db->query($sql, array($hash)); + + if ($query->num_rows() == 0) { + return true; + } else { + return false; + } + } + + function delete_id($id, $password) + { + $filedata = $this->get_filedata($id); + $password = $this->hash_password($password); + + $sql = ' + DELETE + FROM `files` + WHERE `id` = ? + AND password = ? + LIMIT 1'; + $query = $this->db->query($sql, array($id, $password)); + + if($this->unused_file($filedata['hash'])) { + unlink($this->config->item('upload_path').'/'.substr($filedata['hash'], 0, 3).'/'.$filedata['hash']); + // TODO: remove empty folders + } + } + + private function random_id($min_length, $max_length) + { + $random = ''; + $char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + $char_list .= "abcdefghijklmnopqrstuvwxyz"; + $char_list .= "1234567890"; + + for($i = 0; $i < $max_length; $i++) { + if (strlen($random) >= $min_length) { + if (rand()%2 == 1) { + break; + } + } + $random .= substr($char_list,(rand()%(strlen($char_list))), 1); + } + return $random; + } + + function mime2extension($type) + { + $typearray = array( + 'text/plain' => 'txt', + 'text/x-python' => 'py', + 'text/x-csrc' => 'c', + 'text/x-chdr' => 'h', + 'text/x-c++hdr' => 'h', + 'text/x-c++src' => 'cpp', + 'text/x-patch' => 'diff', + 'text/x-lua' => 'lua', + 'text/x-haskell' => 'hs', + 'text/x-literate-haskell' => 'hs', + 'text/x-subviewer' => 'sh', + #'text/x-makefile' => 'make', + #'text/x-log' => 'log', + 'text/html' => 'html', + 'text/css' => 'css', + #'image/svg+xml' => 'xml', + 'application/x-perl' => 'pl', + 'application/xml' => 'xml', + 'application/javascript' => 'js', + 'application/x-desktop' => 'txt', + 'application/x-m4' => 'txt', + 'application/x-awk' => 'awk', + 'application/x-java' => 'java', + 'application/x-php' => 'php', + 'application/x-ruby' => 'rb', + 'application/x-shellscript' => 'sh', + 'application/x-x509-ca-cert' => 'txt', + 'application/mbox' => 'txt' + ); + if (array_key_exists($type, $typearray)) return $typearray[$type]; + + if (strpos($type, 'text/') === 0) return 'txt'; + + # default + return false; + } + +} + +/* End of file file_mod.php */ +/* Location: ./system/application/models/file_mod.php */ diff --git a/system/application/models/index.html b/system/application/models/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/application/models/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/application/views/file/footer.php b/system/application/views/file/footer.php new file mode 100644 index 000000000..eda863585 --- /dev/null +++ b/system/application/views/file/footer.php @@ -0,0 +1,3 @@ +
+ + diff --git a/system/application/views/file/header.php b/system/application/views/file/header.php new file mode 100644 index 000000000..76d21e076 --- /dev/null +++ b/system/application/views/file/header.php @@ -0,0 +1,19 @@ + + + + + <?php echo isset($title) ? $title : ''; ?> + + + + + +
+ +
+ +
+ +
diff --git a/system/application/views/file/non_existant.php b/system/application/views/file/non_existant.php new file mode 100644 index 000000000..418007782 --- /dev/null +++ b/system/application/views/file/non_existant.php @@ -0,0 +1,3 @@ +
+ I'm sorry, but the requested file doesn't exist. +
diff --git a/system/application/views/file/show_url.php b/system/application/views/file/show_url.php new file mode 100644 index 000000000..62d34c661 --- /dev/null +++ b/system/application/views/file/show_url.php @@ -0,0 +1,4 @@ +
+ You can get your file here:
+

+
diff --git a/system/application/views/file/too_big.php b/system/application/views/file/too_big.php new file mode 100644 index 000000000..e5dd5bd6a --- /dev/null +++ b/system/application/views/file/too_big.php @@ -0,0 +1,3 @@ +
+ Sorry, the file you uploaded is too big. +
diff --git a/system/application/views/file/upload_error.php b/system/application/views/file/upload_error.php new file mode 100644 index 000000000..807ca6071 --- /dev/null +++ b/system/application/views/file/upload_error.php @@ -0,0 +1,4 @@ +
+ An error occured while uploading.
+ Most likely your file is too big. +
diff --git a/system/application/views/file/upload_form.php b/system/application/views/file/upload_form.php new file mode 100644 index 000000000..b39088c4e --- /dev/null +++ b/system/application/views/file/upload_form.php @@ -0,0 +1,18 @@ +
+ + File: + + +
+

+Uploads are deleted after 5 days.
+
+If you want to you can use my script (needs python and curl) to upload files, paste text (with syntax highlighting of course) or delete your uploads:
+http://git.server-speed.net/bin/plain/fb
+
+If you experience any problems feel free to contact me.
+
+
+
+ This service is provided without warranty of any kind and may not be used to distribute copyrighted content. +
diff --git a/system/application/views/index.html b/system/application/views/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/application/views/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b