diff options
| -rw-r--r-- | moe/includes/api.php | 84 | ||||
| -rw-r--r-- | moe/includes/core.php | 545 | ||||
| -rw-r--r-- | moe/index.php | 10 | ||||
| -rw-r--r-- | moe/panel/ghetto-search.php | 7 | ||||
| -rwxr-xr-x | static/classes/Response.class.php | 204 | ||||
| -rwxr-xr-x | static/classes/UploadException.class.php | 92 | ||||
| -rw-r--r-- | static/classes/UploadedFile.class.php | 44 | ||||
| -rw-r--r-- | static/grill.php | 23 | ||||
| -rw-r--r-- | static/includes/database.inc.php | 2 | ||||
| -rw-r--r-- | static/includes/settings.inc.php | 12 | ||||
| -rw-r--r-- | static/upload.php | 327 |
11 files changed, 697 insertions, 653 deletions
diff --git a/moe/includes/api.php b/moe/includes/api.php index 123c9a8..b85cbbf 100644 --- a/moe/includes/api.php +++ b/moe/includes/api.php @@ -1,51 +1,39 @@ <?php -//error_reporting(E_ERROR | E_WARNING | E_PARSE); // This file will act as a APIish thing -// Include core file -require_once('core.php'); - -if(isset($_GET['do'])){ - - $butt = $_GET['do']; - - switch($butt){ - - case "login": - login($_POST['email'], $_POST['pass']); - break; - - case "register": - register($_POST['email'], $_POST['pass'], $_POST['code']); - break; - - case "invite-generate": - generate($_GET['email'], $_GET['level']); - break; - - case "mod": - mod($_GET['action'], $_GET['date'], $_GET['count'], $_GET['why'], $_GET['file'], $_GET['keyword'], $_GET['fileid'], $_GET['hash'], $_GET['originalname']); - break; - - case "cp": - header('Location: ../panel'); - break; - - case "search": - search($_GET['q']); - break; - - case "delete": - delete($_GET['f'],$_GET['delid']); - break; - - case "logout": - session_unset(); - session_destroy(); - session_write_close(); - header('Location: ../login'); - break; - - default: echo "We could call this a 404 not found... Or what are you doing here?"; - } +require_once 'core.php'; + +if (isset($_GET['do'])) { + $butt = $_GET['do']; + + switch ($butt) { + case 'login': + login($_POST['email'], $_POST['pass']); + break; + case 'register': + register($_POST['email'], $_POST['pass'], $_POST['code']); + break; + case 'invite-generate': + generate($_GET['email'], $_GET['level']); + break; + case 'mod': + mod($_GET['action'], $_GET['date'], $_GET['count'], $_GET['why'], $_GET['file'], $_GET['keyword'], $_GET['fileid'], $_GET['hash'], $_GET['originalname']); + break; + case 'cp': + header('Location: ../panel'); + break; + case 'search': + search($_GET['q']); + break; + case 'delete': + delete($_GET['f'], $_GET['delid']); + break; + case 'logout': + session_unset(); + session_destroy(); + session_write_close(); + header('Location: ../login'); + break; + default: + echo 'We could call this a 404 not found... Or what are you doing here?'; + } } -?> diff --git a/moe/includes/core.php b/moe/includes/core.php index 2a522f5..d0ef9d0 100644 --- a/moe/includes/core.php +++ b/moe/includes/core.php @@ -1,76 +1,93 @@ <?php -//error_reporting(E_ERROR | E_WARNING | E_PARSE); // This file will handle all functions used by Pomf's Moe Panel session_start(); -$db = new PDO('mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=pomf', 'xxx', 'xxx', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'")); - -function register ($email, $pass, $code) { - global $db; - $do = $db->prepare("SELECT code, used, level FROM invites WHERE email = (:email)"); - $do->bindParam(':email', $email); - $do->execute(); - $result = $do->fetch(); - if(!$result['code'] == $code){ - header('Location: ../register/index.html#fail2'); - }elseif($result['used'] == '1'){ - header('Location: ../register/index.html#fail3'); - }else{ - $do = $db->prepare("INSERT INTO accounts (email, pass, level) VALUES (:email, :pass, :level)"); - $do->bindParam(':email', $email); - $do->bindParam(':level', $result['level']); - $hash = password_hash($pass, PASSWORD_DEFAULT); - $do->bindParam(':pass', $hash); - $do->execute(); - $do = $db->prepare("UPDATE invites SET used = (:used) WHERE email = (:email)"); - $do->bindValue(':used', '1'); - $do->bindParam(':email', $email); - $do->execute(); - $_SESSION['id'] = $result['id']; - $_SESSION['email'] = $result['email']; - header('Location: api.php?do=cp'); - } -} -function generate ($email, $level){ - global $db; - if($_SESSION['level'] === '1'){ - $do = $db->prepare("INSERT INTO invites (email, code, level) VALUES (:email, :code, :level)"); - $do->bindParam(':email', $email); - $code = generateRandomString(); - $do->bindParam(':code', $code); - $do->bindParam(':level', $level); - $do->execute(); - require_once('Mail.php'); - $from = "Invites <invites@pomf.se>"; - $to = $email; - $subject = "Pomf.se Account Invite"; - $body = "This is a automated message from Pomf.se \n Your invite code is: ".$code."\n Your invite email is: ".$email." \n Access level: ".$level." \n Register at http://cayootie.pomf.se/user/register"; - - $host = "xxx"; - $username = "xxx"; - $password = "xxx"; - -$headers = array ('From' => $from, - 'To' => $to, - 'Subject' => $subject); - $smtp = Mail::factory('smtp', - array ('host' => $host, - 'auth' => true, - 'username' => $username, - 'password' => $password)); - - $mail = $smtp->send($to, $headers, $body); +$db = new PDO( + 'mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=pomf', + 'xxx', + 'xxx', + array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'") +); + +function register($email, $pass, $code) { + global $db; + + $do = $db->prepare("SELECT code, used, level FROM invites WHERE email = (:email)"); + $do->bindParam(':email', $email); + $do->execute(); + $result = $do->fetch(); - if (PEAR::isError($mail)) { - echo("<p>" . $mail->getMessage() . "</p>"); - } else { - echo("<p>Message successfully sent!</p>"); - } + if (!$result['code'] == $code) { + header('Location: ../register/index.html#fail2'); + } elseif ($result['used'] == '1') { + header('Location: ../register/index.html#fail3'); + } else { + $do = $db->prepare("INSERT INTO accounts (email, pass, level) VALUES (:email, :pass, :level)"); + $do->bindParam(':email', $email); + $do->bindParam(':level', $result['level']); + $hash = password_hash($pass, PASSWORD_DEFAULT); + $do->bindParam(':pass', $hash); + $do->execute(); + + $do = $db->prepare("UPDATE invites SET used = (:used) WHERE email = (:email)"); + $do->bindValue(':used', '1'); + $do->bindParam(':email', $email); + $do->execute(); - }else{ - echo 'What are you doing here? Go away!'; - } + $_SESSION['id'] = $result['id']; + $_SESSION['email'] = $result['email']; + header('Location: api.php?do=cp'); + } +} + +function generate($email, $level) { + global $db; + + if ($_SESSION['level'] === '1') { + $do = $db->prepare("INSERT INTO invites (email, code, level) VALUES (:email, :code, :level)"); + $do->bindParam(':email', $email); + $code = generateRandomString(); + $do->bindParam(':code', $code); + $do->bindParam(':level', $level); + $do->execute(); + + require_once('Mail.php'); + $from = "Invites <invites@pomf.se>"; + $to = $email; + $subject = "Pomf.se Account Invite"; + $body = "This is a automated message from Pomf.se \n Your invite code is: ".$code."\n Your invite email is: ".$email." \n Access level: ".$level." \n Register at http://cayootie.pomf.se/user/register"; + + $host = "xxx"; + $username = "xxx"; + $password = "xxx"; + + $headers = array( + 'From' => $from, + 'To' => $to, + 'Subject' => $subject + ); + + $smtp = Mail::factory( + 'smtp', + array( + 'host' => $host, + 'auth' => true, + 'username' => $username, + 'password' => $password + ) + ); + + $mail = $smtp->send($to, $headers, $body); + + if (PEAR::isError($mail)) { + echo("<p>" . $mail->getMessage() . "</p>"); + } else { + echo("<p>Message successfully sent!</p>"); + } + } else { + echo 'What are you doing here? Go away!'; + } } function generateRandomString($length = 36) { @@ -79,207 +96,217 @@ function generateRandomString($length = 36) { for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)]; } + return $randomString; } -function login ($email, $pass) { - global $db; - $do = $db->prepare("SELECT pass, id, email, level FROM accounts WHERE email = (:email)"); - $do->bindParam(':email', $email); - $do->execute(); - $result = $do->fetch(PDO::FETCH_ASSOC); - - if (password_verify($pass, $result['pass'])) { - $_SESSION['id'] = $result['id']; - $_SESSION['email'] = $result['email']; - $_SESSION['level'] = $result['level']; - header('Location: api.php?do=cp'); - }else{ - header('Location: ../login/index.html#fail'); - } +function login($email, $pass) { + global $db; + + $do = $db->prepare("SELECT pass, id, email, level FROM accounts WHERE email = (:email)"); + $do->bindParam(':email', $email); + $do->execute(); + $result = $do->fetch(PDO::FETCH_ASSOC); + + if (password_verify($pass, $result['pass'])) { + $_SESSION['id'] = $result['id']; + $_SESSION['email'] = $result['email']; + $_SESSION['level'] = $result['level']; + header('Location: api.php?do=cp'); + } else { + header('Location: ../login/index.html#fail'); + } } -function search ($word) { - if(empty($word)) return; - global $db; - $str = "%".$word."%"; - $id = $_SESSION['id']; - if($_SESSION['level'] === '1'){ - $do = $db->prepare("SELECT originalname, filename FROM files WHERE originalname LIKE (:1) OR filename LIKE (:2)"); - $do->bindParam(':1', $str); - $do->bindParam(':2', $str); - $do->execute(); - - while ($row = $do->fetch(PDO::FETCH_ASSOC)) { - print strip_tags($row['originalname']).' - '.'<a href="http://a.pomf.se/'.$row['filename'].'" target="_BLANK">'.$row['filename'].' </a> '.'<a href="http://cayootie.pomf.se/user/includes/api.php?do=delete&f='.$row['filename'].'" target="_BLANK"> Delete</a><br/>'; - } - - //Yes I love not being efficient, deal with it. - }else{ - $do = $db->prepare("SELECT originalname, filename FROM files WHERE originalname LIKE (:1) AND user = (:3) OR filename LIKE (:2) AND user = (:3)"); - $do->bindParam(':1', $str); - $do->bindParam(':2', $str); - $do->bindParam(':3', $id); - $do->execute(); - - while ($row = $do->fetch(PDO::FETCH_ASSOC)) { - print strip_tags($row['originalname']).' - '.'<a href="http://a.pomf.se/'.$row['filename'].'" target="_BLANK">'.$row['filename'].' </a> '.'<a href="http://cayootie.pomf.se/user/includes/api.php?do=delete&f='.$row['filename'].'" target="_BLANK"> Delete</a><br/>'; - } +function search($word) { + if (empty($word)) { + return; + } + + global $db; + + $str = "%".$word."%"; + $id = $_SESSION['id']; + + if ($_SESSION['level'] === '1') { + $do = $db->prepare("SELECT originalname, filename FROM files WHERE originalname LIKE (:1) OR filename LIKE (:2)"); + $do->bindParam(':1', $str); + $do->bindParam(':2', $str); + $do->execute(); + + while ($row = $do->fetch(PDO::FETCH_ASSOC)) { + print strip_tags($row['originalname']).' - '.'<a href="http://a.pomf.se/'.$row['filename'].'" target="_BLANK">'.$row['filename'].' </a> '.'<a href="http://cayootie.pomf.se/user/includes/api.php?do=delete&f='.$row['filename'].'" target="_BLANK"> Delete</a><br/>'; + } + } else { + // Yes I love not being efficient, deal with it. + $do = $db->prepare("SELECT originalname, filename FROM files WHERE originalname LIKE (:1) AND user = (:3) OR filename LIKE (:2) AND user = (:3)"); + $do->bindParam(':1', $str); + $do->bindParam(':2', $str); + $do->bindParam(':3', $id); + $do->execute(); + + while ($row = $do->fetch(PDO::FETCH_ASSOC)) { + print strip_tags($row['originalname']).' - '.'<a href="http://a.pomf.se/'.$row['filename'].'" target="_BLANK">'.$row['filename'].' </a> '.'<a href="http://cayootie.pomf.se/user/includes/api.php?do=delete&f='.$row['filename'].'" target="_BLANK"> Delete</a><br/>'; + } } } -function cfdelete ($file) { - - $butts = array( - 'a' => 'zone_file_purge', - 'tkn' => 'xxxx', - 'email' => 'xxx', - 'z' => 'pomf.se', - 'url' => urlencode('http://a.pomf.se/'.$file), - ); - - foreach($butts as $dick=>$cum) { $butts_string .= $dick.'='.$cum.'&'; } - rtrim($butts_string, '&'); - - $hue = curl_init(); - curl_setopt($hue,CURLOPT_URL, 'https://www.cloudflare.com/api_json.html'); - curl_setopt($hue,CURLOPT_POST, count($butts)); - curl_setopt($hue,CURLOPT_POSTFIELDS, $butts_string); - curl_setopt($hue,CURLOPT_RETURNTRANSFER, true); - curl_exec($hue); - curl_close($hue); +function cfdelete($file) { + $butts = array( + 'a' => 'zone_file_purge', + 'tkn' => 'xxxx', + 'email' => 'xxx', + 'z' => 'pomf.se', + 'url' => urlencode('http://a.pomf.se/'.$file), + ); + + foreach ($butts as $dick=>$cum) { + $butts_string .= $dick.'='.$cum.'&'; + } + rtrim($butts_string, '&'); + + $hue = curl_init(); + curl_setopt($hue,CURLOPT_URL, 'https://www.cloudflare.com/api_json.html'); + curl_setopt($hue,CURLOPT_POST, count($butts)); + curl_setopt($hue,CURLOPT_POSTFIELDS, $butts_string); + curl_setopt($hue,CURLOPT_RETURNTRANSFER, true); + curl_exec($hue); + curl_close($hue); +} + +function delete($filename, $deleteid, $mod) { + if (empty($filename)) { + echo "You did something wrong, baka."; + } else { + global $db; + + $do = $db->prepare("SELECT filename, delid, id, user FROM files WHERE filename = (:filename)"); + $do->bindParam(':filename', $filename); + $do->execute(); + $result = $do->fetch(PDO::FETCH_ASSOC); + + if ($_SESSION['level'] === '1' || $result['user'] === $_SESSION['id']) { + $do = $db->prepare("DELETE FROM files WHERE id = (:id)"); + $do->bindParam(':id', $result['id']); + $do->execute(); + + unlink('/home/neku/pomf/files/'.$filename); + cfdelete($filename); + + echo "<br/>File deleted and hopefully deleted from Cloudflares cache in a moment..<br/>"; + } else { + echo 'Shame on you'; + } + } } -function delete ($filename, $deleteid, $mod) { - if(empty($filename)){ - echo "You did something wrong, baka."; - }else{ - global $db; - $do = $db->prepare("SELECT filename, delid, id, user FROM files WHERE filename = (:filename)"); - $do->bindParam(':filename', $filename); - $do->execute(); - $result = $do->fetch(PDO::FETCH_ASSOC); - - if($_SESSION['level'] === '1' || $result['user'] === $_SESSION['id']){ - $do = $db->prepare("DELETE FROM files WHERE id = (:id)"); - $do->bindParam(':id', $result['id']); - $do->execute(); - unlink('/home/neku/pomf/files/'.$filename); - cfdelete($filename); - echo "<br/>File deleted and hopefully deleted from Cloudflares cache in a moment..<br/>"; - }else{ - echo 'Shame on you'; - }//hue - }//hue - }//penis - - function mod ($action, $date, $count, $why, $file, $keyword, $fileid, $hash, $oginalname) { - if($_SESSION['level'] > '0'){ - global $db; - switch($action){ - - case "fetch": - if($_SESSION['level'] > '0'){ - $do = $db->prepare("SELECT * FROM files WHERE originalname LIKE (:keyword) AND date LIKE (:date) OR filename LIKE (:keyword) AND date LIKE (:date) ORDER BY id DESC LIMIT 0,:amount"); - }else{ - $do = $db->prepare("SELECT * FROM files WHERE originalname LIKE (:keyword) AND date LIKE (:date) AND user = (:userid) OR filename LIKE (:keyword) AND date LIKE (:date) AND user = (:userid) ORDER BY id$ - $do->bindValue(':userid', $_SESSION['id']);} - - $do->bindValue(':date', "%".$date."%"); - $do->bindValue(':amount', (int) $count, PDO::PARAM_INT); - $do->bindValue(':keyword', "%".$keyword."%"); - - $do->execute(); - $i = 0; - echo'<!DOCTYPE html><html><head><title>Mod</title> - <style> - table,th,td{border:1px solid black; border-collapse:collapse;} - th,td{padding:5px;} - </style></head><body> - <p>Keep in mind that this is a alpha version of the mod panel, click <a href="http://cayootie.pomf.se/user/includes/api.php?do=logout">here</a> to logout or <a href="http://cayootie.pomf.se/user/panel" target="_BLANK">here</a> to go to the panel for your personal account.</p> - <form action="http://cayootie.pomf.se/user/includes/api.php" method="get"> - <input type="hidden" name="do" value="mod"> - <input type="hidden" name="action" value="fetch"> - Date: <input type="text" name="date" value="'.date('Y-m-d').'"> - Amount: <input type="text" name="count" value="30"> - Keyword: <input type="text" name="keyword"> - <input type="submit" value="fetch"> - </form><br> - <table id="result" style="width:100%"> - <tr><th>ID</th><th>Orginal Name</th><th>Filename</th><th>Size (bytes)</th><th>Action</th></tr>'; - while ($row = $do->fetch(PDO::FETCH_ASSOC)) { - $i++; - echo '<tr><td>'.$row['id'].'</td> - <td>'.strip_tags($row['originalname']).'</td> - <td><a href="http://a.pomf.se/'.$row['filename'].'" target="_BLANK">'.$row['filename'].'</a> ('.$row['originalname'].')</td> - <td>'.$row['size'].'</td> - <td><a href="http://cayootie.pomf.se/user/includes/api.php?do=mod&action=remove&fileid='.$row['id'].'&file='.$row['filename'].'" target="_BLANK">Remove</a></td></tr>'; - - } - echo '</table></body></html>'; - echo $i.' Files in total at being shown.'; - - break; - - case "report": - $do = $db->prepare("INSERT INTO reports (hash, date, file, fileid, reporter) VALUES (:hash, :date, :file, :fileid, :reporter)"); - $do->bindValue(':file', strip_tags($file)); - $do->bindValue(':date', date('Y-m-d')); - $do->bindValue(':reporter', $_SESSION['email']); - $do->bindValue(':fileid', $fileid); - $do->bindValue(':hash', $hash); - $do->execute(); - echo 'Thank you, report has been sent. The file will be reviewed and probably deleted.'; - break; - - case "reports": - if($_SESSION['id'] === '1'){ - $do = $db->prepare("SELECT * FROM reports WHERE status = '0'"); - $do->execute(); - - $i = 0; - echo'<!DOCTYPE html><html><head><title>Mod</title> - <style> - table,th,td{border:1px solid black; border-collapse:collapse;} - th,td{padding:5px;} - </style></head><body> - <p> Status 0 = not removed</p> - <p> Status 1 = removed (not shown)</p> - <table id="result" style="width:100%"> - <tr><th>ID</th><th>File</th><th>File ID</th><th>Reporter</th><th>Status</th><th>Action</th></tr>'; - while ($row = $do->fetch(PDO::FETCH_ASSOC)) { - $i++; - echo '<tr><td>'.$row['id'].'</td> - <td><a href="http://a.pomf.se/'.strip_tags($row['file']).'" target="_BLANK">'.strip_tags($row['file']).'</td> - <td>'.$row['fileid'].'</td> - <td>'.$row['reporter'].'</td> - <td>'.$row['status'].'</td> - <td><a href="http://cayootie.pomf.se/user/includes/api.php?do=mod&action=remove&fileid='.$row['fileid'].'&file='.$row['file'].'" target="_BLANK">Remove file</a></td></tr>'; - - } - echo '</table></body></html>'; - echo $i.' Reports in total at being shown.'; - }else{ - echo 'You are not allowed to be here, yet.'; - } - break; - - case "remove": - if($_SESSION['id'] < '0'){ - delete($file, $fileid);} - if($_SESSION['id'] > '0'){ - $do = $db->prepare("DELETE FROM files WHERE id = (:id)"); - $do->bindParam(':id', $fileid); - $do->execute(); - unlink('/home/neku/pomf/files/'.$file); - cfdelete($file); - $do = $db->prepare("UPDATE reports SET status = (:status) WHERE fileid = (:fileid)"); - $do->bindValue(':status', '1'); - $do->bindValue(':fileid', $fileid); - $do->execute(); - echo 'Deleted'; - break; - } - } - } +function mod($action, $date, $count, $why, $file, $keyword, $fileid, $hash, $oginalname) { + if ($_SESSION['level'] > '0') { + global $db; + + switch ($action) { + case "fetch": + if ($_SESSION['level'] > '0') { + $do = $db->prepare("SELECT * FROM files WHERE originalname LIKE (:keyword) AND date LIKE (:date) OR filename LIKE (:keyword) AND date LIKE (:date) ORDER BY id DESC LIMIT 0,:amount"); + } else { + $do = $db->prepare("SELECT * FROM files WHERE originalname LIKE (:keyword) AND date LIKE (:date) AND user = (:userid) OR filename LIKE (:keyword) AND date LIKE (:date) AND user = (:userid) ORDER BY id$ + $do->bindValue(':userid', $_SESSION['id']); + } + $do->bindValue(':date', "%".$date."%"); + $do->bindValue(':amount', (int) $count, PDO::PARAM_INT); + $do->bindValue(':keyword', "%".$keyword."%"); + $do->execute(); + + echo '<!DOCTYPE html><html><head><title>Mod</title> + <style> + table,th,td{border:1px solid black; border-collapse:collapse;} + th,td{padding:5px;} + </style></head><body> + <p>Keep in mind that this is a alpha version of the mod panel, click <a href="http://cayootie.pomf.se/user/includes/api.php?do=logout">here</a> to logout or <a href="http://cayootie.pomf.se/user/panel" target="_BLANK">here</a> to go to the panel for your personal account.</p> + <form action="http://cayootie.pomf.se/user/includes/api.php" method="get"> + <input type="hidden" name="do" value="mod"> + <input type="hidden" name="action" value="fetch"> + Date: <input type="text" name="date" value="'.date('Y-m-d').'"> + Amount: <input type="text" name="count" value="30"> + Keyword: <input type="text" name="keyword"> + <input type="submit" value="fetch"> + </form><br> + <table id="result" style="width:100%"> + <tr><th>ID</th><th>Orginal Name</th><th>Filename</th><th>Size (bytes)</th><th>Action</th></tr>'; + + $i = 0; + while ($row = $do->fetch(PDO::FETCH_ASSOC)) { + $i++; + echo '<tr><td>'.$row['id'].'</td> + <td>'.strip_tags($row['originalname']).'</td> + <td><a href="http://a.pomf.se/'.$row['filename'].'" target="_BLANK">'.$row['filename'].'</a> ('.$row['originalname'].')</td> + <td>'.$row['size'].'</td> + <td><a href="http://cayootie.pomf.se/user/includes/api.php?do=mod&action=remove&fileid='.$row['id'].'&file='.$row['filename'].'" target="_BLANK">Remove</a></td></tr>'; + } + echo '</table></body></html>'; + echo $i.' Files in total at being shown.'; + break; + case "report": + $do = $db->prepare("INSERT INTO reports (hash, date, file, fileid, reporter) VALUES (:hash, :date, :file, :fileid, :reporter)"); + $do->bindValue(':file', strip_tags($file)); + $do->bindValue(':date', date('Y-m-d')); + $do->bindValue(':reporter', $_SESSION['email']); + $do->bindValue(':fileid', $fileid); + $do->bindValue(':hash', $hash); + $do->execute(); + + echo 'Thank you, report has been sent. The file will be reviewed and probably deleted.'; + break; + case "reports": + if ($_SESSION['id'] === '1') { + $do = $db->prepare("SELECT * FROM reports WHERE status = '0'"); + $do->execute(); + $i = 0; + echo '<!DOCTYPE html><html><head><title>Mod</title> + <style> + table,th,td{border:1px solid black; border-collapse:collapse;} + th,td{padding:5px;} + </style></head><body> + <p> Status 0 = not removed</p> + <p> Status 1 = removed (not shown)</p> + <table id="result" style="width:100%"> + <tr><th>ID</th><th>File</th><th>File ID</th><th>Reporter</th><th>Status</th><th>Action</th></tr>'; + while ($row = $do->fetch(PDO::FETCH_ASSOC)) { + $i++; + echo '<tr><td>'.$row['id'].'</td> + <td><a href="http://a.pomf.se/'.strip_tags($row['file']).'" target="_BLANK">'.strip_tags($row['file']).'</td> + <td>'.$row['fileid'].'</td> + <td>'.$row['reporter'].'</td> + <td>'.$row['status'].'</td> + <td><a href="http://cayootie.pomf.se/user/includes/api.php?do=mod&action=remove&fileid='.$row['fileid'].'&file='.$row['file'].'" target="_BLANK">Remove file</a></td></tr>'; + } + echo '</table></body></html>'; + echo $i.' Reports in total at being shown.'; + } else { + echo 'You are not allowed to be here, yet.'; + } + break; + case "remove": + if ($_SESSION['id'] < '0') { + delete($file, $fileid); + } + if ($_SESSION['id'] > '0') { + $do = $db->prepare("DELETE FROM files WHERE id = (:id)"); + $do->bindParam(':id', $fileid); + $do->execute(); + + unlink('/home/neku/pomf/files/'.$file); + cfdelete($file); + + $do = $db->prepare("UPDATE reports SET status = (:status) WHERE fileid = (:fileid)"); + $do->bindValue(':status', '1'); + $do->bindValue(':fileid', $fileid); + $do->execute(); + + echo 'Deleted'; + break; + } + } + } +} ?> diff --git a/moe/index.php b/moe/index.php index 0ff0176..70e081b 100644 --- a/moe/index.php +++ b/moe/index.php @@ -1,8 +1,8 @@ <?php session_start(); -if(isset($_SESSION['id'])){ - header('Location: includes/api.php?do=cp'); -}else{ - header('Location: login/'); + +if (isset($_SESSION['id'])) { + header('Location: includes/api.php?do=cp'); +} else { + header('Location: login/'); } -?>
\ No newline at end of file diff --git a/moe/panel/ghetto-search.php b/moe/panel/ghetto-search.php index 31811e1..530f2ae 100644 --- a/moe/panel/ghetto-search.php +++ b/moe/panel/ghetto-search.php @@ -1,4 +1,5 @@ <?php -include_once('../includes/core.php'); -mod($action ='fetch'); -?> + +include_once '../includes/core.php'; + +mod($action = 'fetch'); diff --git a/static/classes/Response.class.php b/static/classes/Response.class.php index 41f946c..25121ce 100755 --- a/static/classes/Response.class.php +++ b/static/classes/Response.class.php @@ -1,98 +1,106 @@ -<?php
-
-class Response {
- private $type;
-
- public function __construct ($response_type = null) {
- switch ($response_type) {
- case 'csv':
- case 'gyazo':
- header('Content-Type: text/plain; charset=UTF-8');
- $this->type = $response_type;
- break;
- default:
- header('Content-Type: application/json; charset=UTF-8');
- $this->type = 'json';
- break;
- }
- }
-
- public function error ($code, $desc) {
- $response = null;
-
- switch ($this->type) {
- case 'csv':
- $response = $this->csv_error($desc);
- break;
- case 'gyazo':
- $response = $this->gyazo_error($code, $desc);
- break;
- default:
- $response = $this->json_error($code, $desc);
- break;
- }
-
- http_response_code($code);
- echo $response;
- }
-
- public function send ($files) {
- $response = null;
-
- switch ($this->type) {
- case 'csv':
- $response = $this->csv_success($files);
- break;
- case 'gyazo':
- $response = $this->gyazo_success($files);
- break;
- default:
- $response = $this->json_success($files);
- break;
- }
-
- http_response_code(200);
- echo $response;
- }
-
- private static function csv_error ($description) {
- return "error\n" . $description . "\n";
- }
-
- private static function csv_success ($files) {
- $result = "name,url,hash,size\n";
- foreach ($files as $file) {
- $result .= $file['name'] . "," .
- $file['url'] . "," .
- $file['hash'] . "," .
- $file['size'] . "\n";
- }
-
- return $result;
- }
-
- private static function gyazo_error ($code, $description) {
- return "ERROR: (" . $code . ") " . $description;
- }
-
- private static function gyazo_success ($files) {
- return POMF_URL . $files[0]['url'];
- }
-
- private static function json_error ($code, $description) {
- return json_encode(array(
- 'success' => false,
- 'errorcode' => $code,
- 'description' => $description
- ));
- }
-
- private static function json_success ($files) {
- return json_encode(array(
- 'success' => true,
- 'files' => $files
- ));
- }
-}
-
-?>
\ No newline at end of file +<?php + +class Response +{ + private $type; + + public function __construct($response_type = null) + { + switch ($response_type) { + case 'csv': + case 'gyazo': + header('Content-Type: text/plain; charset=UTF-8'); + $this->type = $response_type; + break; + default: + header('Content-Type: application/json; charset=UTF-8'); + $this->type = 'json'; + break; + } + } + + public function error($code, $desc) + { + $response = null; + + switch ($this->type) { + case 'csv': + $response = $this->csv_error($desc); + break; + case 'gyazo': + $response = $this->gyazo_error($code, $desc); + break; + default: + $response = $this->json_error($code, $desc); + break; + } + + http_response_code($code); + echo $response; + } + + public function send($files) + { + $response = null; + + switch ($this->type) { + case 'csv': + $response = $this->csv_success($files); + break; + case 'gyazo': + $response = $this->gyazo_success($files); + break; + default: + $response = $this->json_success($files); + break; + } + + http_response_code(200); + echo $response; + } + + private static function csv_error($description) + { + return "error\n".$description."\n"; + } + + private static function csv_success($files) + { + $result = "name,url,hash,size\n"; + foreach ($files as $file) { + $result .= $file['name'].','. + $file['url'].','. + $file['hash'].','. + $file['size']."\n"; + } + + return $result; + } + + private static function gyazo_error($code, $description) + { + return 'ERROR: ('.$code.') '.$description; + } + + private static function gyazo_success($files) + { + return POMF_URL.$files[0]['url']; + } + + private static function json_error($code, $description) + { + return json_encode(array( + 'success' => false, + 'errorcode' => $code, + 'description' => $description, + )); + } + + private static function json_success($files) + { + return json_encode(array( + 'success' => true, + 'files' => $files, + )); + } +} diff --git a/static/classes/UploadException.class.php b/static/classes/UploadException.class.php index b1b4839..66be853 100755 --- a/static/classes/UploadException.class.php +++ b/static/classes/UploadException.class.php @@ -1,45 +1,47 @@ -<?php
-
-// Exception class extension from: http://php.net/manual/en/features.file-upload.errors.php#89374
-// Handles files error returning a proper error description
-
-class UploadException extends Exception {
- public function __construct($code) {
- $message = $this->codeToMessage($code);
- parent::__construct($message, 500);
- }
-
- private function codeToMessage($code) {
- switch ($code) {
- case UPLOAD_ERR_INI_SIZE:
- $message = "The uploaded file exceeds the upload_max_filesize directive in php.ini";
- break;
- case UPLOAD_ERR_FORM_SIZE:
- $message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was " .
- "specified in the HTML form";
- break;
- case UPLOAD_ERR_PARTIAL:
- $message = "The uploaded file was only partially uploaded";
- break;
- case UPLOAD_ERR_NO_FILE:
- $message = "No file was uploaded";
- break;
- case UPLOAD_ERR_NO_TMP_DIR:
- $message = "Missing a temporary folder";
- break;
- case UPLOAD_ERR_CANT_WRITE:
- $message = "Failed to write file to disk";
- break;
- case UPLOAD_ERR_EXTENSION:
- $message = "File upload stopped by extension";
- break;
-
- default:
- $message = "Unknown upload error";
- break;
- }
- return $message;
- }
-}
-
-?>
\ No newline at end of file +<?php + +// Exception class extension from: http://php.net/manual/en/features.file-upload.errors.php#89374 +// Handles files error returning a proper error description + +class UploadException extends Exception +{ + public function __construct($code) + { + $message = $this->codeToMessage($code); + parent::__construct($message, 500); + } + + private function codeToMessage($code) + { + switch ($code) { + case UPLOAD_ERR_INI_SIZE: + $message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; + break; + case UPLOAD_ERR_FORM_SIZE: + $message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was '. + 'specified in the HTML form'; + break; + case UPLOAD_ERR_PARTIAL: + $message = 'The uploaded file was only partially uploaded'; + break; + case UPLOAD_ERR_NO_FILE: + $message = 'No file was uploaded'; + break; + case UPLOAD_ERR_NO_TMP_DIR: + $message = 'Missing a temporary folder'; + break; + case UPLOAD_ERR_CANT_WRITE: + $message = 'Failed to write file to disk'; + break; + case UPLOAD_ERR_EXTENSION: + $message = 'File upload stopped by extension'; + break; + + default: + $message = 'Unknown upload error'; + break; + } + + return $message; + } +} diff --git a/static/classes/UploadedFile.class.php b/static/classes/UploadedFile.class.php index 1cf8914..5e8ae1c 100644 --- a/static/classes/UploadedFile.class.php +++ b/static/classes/UploadedFile.class.php @@ -1,27 +1,29 @@ <?php -class UploadedFile { - /* Public attributes */ - public $name; - public $mime; - public $size; - public $tempfile; - public $error; +class UploadedFile +{ + /* Public attributes */ + public $name; + public $mime; + public $size; + public $tempfile; + public $error; - /* Cached checksums */ - private $sha1; - private $crc32; + /* Cached checksums */ + private $sha1; + private $crc32; - /** - * Generates the SHA1 or returns the cached SHA1 hash for the file. - * - * @return string - */ - public function get_sha1 () { - if (!$this->sha1) - $this->sha1 = sha1_file($this->tempfile); + /** + * Generates the SHA1 or returns the cached SHA1 hash for the file. + * + * @return string + */ + public function get_sha1() + { + if (!$this->sha1) { + $this->sha1 = sha1_file($this->tempfile); + } - return $this->sha1; - } + return $this->sha1; + } } -?> diff --git a/static/grill.php b/static/grill.php index 34bdce1..5984b12 100644 --- a/static/grill.php +++ b/static/grill.php @@ -1,16 +1,17 @@ <?php + $images = array( - 'img/2.png', - 'img/3.png', - 'img/4.png', - 'img/5.png', - 'img/6.png', - 'img/7.png', - 'img/8.png', - 'img/9.png', - 'img/10.png' + 'img/2.png', + 'img/3.png', + 'img/4.png', + 'img/5.png', + 'img/6.png', + 'img/7.png', + 'img/8.png', + 'img/9.png', + 'img/10.png', ); + if (headers_sent() === false) { - header('Location: ' . $images[array_rand($images)], true, 303); + header('Location: '.$images[array_rand($images)], true, 303); } -?> diff --git a/static/includes/database.inc.php b/static/includes/database.inc.php index 2ed0274..5049487 100644 --- a/static/includes/database.inc.php +++ b/static/includes/database.inc.php @@ -1,6 +1,6 @@ <?php + include_once 'settings.inc.php'; /* NOTE: we don't have to unref the PDO because we're not long-running */ $db = new PDO(POMF_DB_CONN, POMF_DB_USER, POMF_DB_PASS); -?> diff --git a/static/includes/settings.inc.php b/static/includes/settings.inc.php index b8a213c..37bc4a0 100644 --- a/static/includes/settings.inc.php +++ b/static/includes/settings.inc.php @@ -17,11 +17,9 @@ define('POMF_FILES_LENGTH', 6); define('POMF_URL', 'https://i.pantsu.cat/'); $doubledots = array_map('strrev', array( - 'tar.gz', - 'tar.bz', - 'tar.bz2', - 'tar.xz', - 'user.js' + 'tar.gz', + 'tar.bz', + 'tar.bz2', + 'tar.xz', + 'user.js', )); - -?> diff --git a/static/upload.php b/static/upload.php index 6e54ae1..0504e54 100644 --- a/static/upload.php +++ b/static/upload.php @@ -1,197 +1,214 @@ <?php + // Check if we can compress our output; if we can, we'll do it if (ini_get('zlib.output_compression') !== 'Off' - && isset($_SERVER["HTTP_ACCEPT_ENCODING"]) - && strpos($_SERVER["HTTP_ACCEPT_ENCODING"], 'gzip') !== false) - ob_start("ob_gzhandler"); + && isset($_SERVER['HTTP_ACCEPT_ENCODING']) + && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) { + ob_start('ob_gzhandler'); +} session_start(); + include_once 'classes/Response.class.php'; include_once 'classes/UploadException.class.php'; include_once 'classes/UploadedFile.class.php'; include_once 'includes/database.inc.php'; - /** - * Generates a random name for the file, retrying until we get an unused one + * Generates a random name for the file, retrying until we get an unused one. + * + * @param UploadedFile $file * - * @param UploadedFile $file * @return string */ -function generate_name ($file) { - global $db; - global $doubledots; - - // We start at N retries, and --N until we give up - $tries = POMF_FILES_RETRIES; - $length = POMF_FILES_LENGTH; - $ext = pathinfo($file->name, PATHINFO_EXTENSION); - - // Check if extension is a double-dot extension and, if true, override $ext - $revname = strrev($file->name); - foreach ($doubledots as $ddot) { - if (stripos($revname, $ddot) === 0) { - $ext = strrev($ddot); - } - } - - - do { - // Iterate until we reach the maximum number of retries - if ($tries-- == 0) throw new Exception('Gave up trying to find an unused name', 500); - - $chars = range('a', 'z'); - $name = ''; - for ($i = 0; $i < $length; $i++) { - $name .= $chars[array_rand($chars)]; - } - - // Add the extension to the file name - if (isset($ext) && $ext !== '') - $name .= '.' . strip_tags($ext); - - // Check if a file with the same name does already exist in the database - $q = $db->prepare('SELECT COUNT(name) FROM pomf WHERE name = (:name)'); - $q->bindValue(':name', $name, PDO::PARAM_STR); - $q->execute(); - $result = $q->fetchColumn(); - // If it does, generate a new name - } while($result > 0); - - return $name; +function generate_name($file) +{ + global $db; + global $doubledots; + + // We start at N retries, and --N until we give up + $tries = POMF_FILES_RETRIES; + $length = POMF_FILES_LENGTH; + $ext = pathinfo($file->name, PATHINFO_EXTENSION); + + // Check if extension is a double-dot extension and, if true, override $ext + $revname = strrev($file->name); + foreach ($doubledots as $ddot) { + if (stripos($revname, $ddot) === 0) { + $ext = strrev($ddot); + } + } + + do { + // Iterate until we reach the maximum number of retries + if ($tries-- == 0) { + throw new Exception('Gave up trying to find an unused name', 500); + } + + $chars = range('a', 'z'); + $name = ''; + for ($i = 0; $i < $length; ++$i) { + $name .= $chars[array_rand($chars)]; + } + + // Add the extension to the file name + if (isset($ext) && $ext !== '') { + $name .= '.'.strip_tags($ext); + } + + // Check if a file with the same name does already exist in the database + $q = $db->prepare('SELECT COUNT(name) FROM pomf WHERE name = (:name)'); + $q->bindValue(':name', $name, PDO::PARAM_STR); + $q->execute(); + $result = $q->fetchColumn(); + // If it does, generate a new name + } while ($result > 0); + + return $name; } /** - * Handles the uploading and db entry for a file + * Handles the uploading and db entry for a file. + * + * @param UploadedFile $file * - * @param UploadedFile $file * @return array */ -function upload_file ($file) { - global $db; - - // Handle file errors - if ($file->error) throw new UploadException($file->error); - - // Check if a file with the same hash and size (a file which is the same) does already exist in - // the database; if it does, delete the file just uploaded and return the proper link and data. - $q = $db->prepare('SELECT filename, COUNT(*) AS count FROM files WHERE hash = (:hash) ' . - 'AND size = (:size)'); - $q->bindValue(':hash', $file->get_sha1(), PDO::PARAM_STR); - $q->bindValue(':size', $file->size, PDO::PARAM_INT); - $q->execute(); - $result = $q->fetch(); - if ($result['count'] > 0) { - unlink($file->tempfile); - return array( - 'hash' => $file->get_sha1(), - 'name' => $file->name, - 'url' => POMF_URL . $result['filename'], - 'size' => $file->size - ); - } - - // Generate a name for the file - $newname = generate_name($file); - - // Attempt to move it to the static directory - if (move_uploaded_file($file->tempfile, POMF_FILES_ROOT . $newname)) { - // Need to change permissions for the new file to make it world readable - if (chmod(POMF_FILES_ROOT . $newname, 0644)) { - // Add it to the database - if (empty($_SESSION['id'])) { - // Query if user is NOT logged in - $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, ' . - 'expire, delid) VALUES (:hash, :orig, :name, :size, :date, ' . - ':exp, :del)'); - } else { - // Query if user is logged in (insert user id together with other data) - $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, ' . - 'expire, delid, user) VALUES (:hash, :orig, :name, :size, ' . - ':date, :expires, :delid, :user)'); - $q->bindValue(':user', $_SESSION['id'], PDO::PARAM_INT); - } - - // Common parameters binding - $q->bindValue(':hash', $file->get_sha1(), PDO::PARAM_STR); - $q->bindValue(':orig', strip_tags($file->name), PDO::PARAM_STR); - $q->bindValue(':name', $newname, PDO::PARAM_STR); - $q->bindValue(':size', $file->size, PDO::PARAM_INT); - $q->bindValue(':date', date('Y-m-d'), PDO::PARAM_STR); - $q->bindValue(':exp', null, PDO::PARAM_STR); - $q->bindValue(':del', sha1($file->tempfile), PDO::PARAM_STR); - $q->execute(); - - return array( - 'hash' => $file->get_sha1(), - 'name' => $file->name, - 'url' => POMF_URL . $newname, - 'size' => $file->size - ); - } else { - throw new Exception('Failed to change file permissions', 500); - } - } else { - throw new Exception('Failed to move file to destination', 500); - } +function upload_file($file) +{ + global $db; + + // Handle file errors + if ($file->error) { + throw new UploadException($file->error); + } + + // Check if a file with the same hash and size (a file which is the same) does already exist in + // the database; if it does, delete the file just uploaded and return the proper link and data. + $q = $db->prepare('SELECT filename, COUNT(*) AS count FROM files WHERE hash = (:hash) '. + 'AND size = (:size)'); + $q->bindValue(':hash', $file->get_sha1(), PDO::PARAM_STR); + $q->bindValue(':size', $file->size, PDO::PARAM_INT); + $q->execute(); + $result = $q->fetch(); + if ($result['count'] > 0) { + unlink($file->tempfile); + + return array( + 'hash' => $file->get_sha1(), + 'name' => $file->name, + 'url' => POMF_URL.$result['filename'], + 'size' => $file->size, + ); + } + + // Generate a name for the file + $newname = generate_name($file); + + // Attempt to move it to the static directory + if (move_uploaded_file($file->tempfile, POMF_FILES_ROOT.$newname)) { + // Need to change permissions for the new file to make it world readable + if (chmod(POMF_FILES_ROOT.$newname, 0644)) { + // Add it to the database + if (empty($_SESSION['id'])) { + // Query if user is NOT logged in + $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, '. + 'expire, delid) VALUES (:hash, :orig, :name, :size, :date, '. + ':exp, :del)'); + } else { + // Query if user is logged in (insert user id together with other data) + $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, '. + 'expire, delid, user) VALUES (:hash, :orig, :name, :size, '. + ':date, :expires, :delid, :user)'); + $q->bindValue(':user', $_SESSION['id'], PDO::PARAM_INT); + } + + // Common parameters binding + $q->bindValue(':hash', $file->get_sha1(), PDO::PARAM_STR); + $q->bindValue(':orig', strip_tags($file->name), PDO::PARAM_STR); + $q->bindValue(':name', $newname, PDO::PARAM_STR); + $q->bindValue(':size', $file->size, PDO::PARAM_INT); + $q->bindValue(':date', date('Y-m-d'), PDO::PARAM_STR); + $q->bindValue(':exp', null, PDO::PARAM_STR); + $q->bindValue(':del', sha1($file->tempfile), PDO::PARAM_STR); + $q->execute(); + + return array( + 'hash' => $file->get_sha1(), + 'name' => $file->name, + 'url' => POMF_URL.$newname, + 'size' => $file->size, + ); + } else { + throw new Exception('Failed to change file permissions', 500); + } + } else { + throw new Exception('Failed to move file to destination', 500); + } } /** - * Reorder files array by file + * Reorder files array by file. * * @param $_FILES + * * @return array */ -function diverse_array ($files) { - $result = array(); - foreach ($files as $key1 => $value1) - foreach ($value1 as $key2 => $value2) - $result[$key2][$key1] = $value2; +function diverse_array($files) +{ + $result = array(); - return $result; + foreach ($files as $key1 => $value1) { + foreach ($value1 as $key2 => $value2) { + $result[$key2][$key1] = $value2; + } + } + + return $result; } /** - * Reorganize the $_FILES array into something saner + * Reorganize the $_FILES array into something saner. * * @param $_FILES + * * @return array */ -function refiles ($files) { - $result = array(); - $files = diverse_array($files); - - foreach ($files as $file) { - $f = new UploadedFile(); - $f->name = $file['name']; - $f->mime = $file['type']; - $f->size = $file['size']; - $f->tempfile = $file['tmp_name']; - $f->error = $file['error']; - // 'expire' doesn't exist neither in $_FILES nor in UploadedFile; - // commented out for future implementation - //$f->expire = $file['expire']; - $result[] = $f; - } - - return $result; +function refiles($files) +{ + $result = array(); + $files = diverse_array($files); + + foreach ($files as $file) { + $f = new UploadedFile(); + $f->name = $file['name']; + $f->mime = $file['type']; + $f->size = $file['size']; + $f->tempfile = $file['tmp_name']; + $f->error = $file['error']; + // 'expire' doesn't exist neither in $_FILES nor in UploadedFile; + // commented out for future implementation + //$f->expire = $file['expire']; + $result[] = $f; + } + + return $result; } - - $type = isset($_GET['output']) ? $_GET['output'] : 'json'; $response = new Response($type); + if (isset($_FILES['files'])) { - $uploads = refiles($_FILES['files']); - try { - foreach ($uploads as $upload) - $res[] = upload_file($upload); - $response->send($res); - } catch (Exception $e) { - $response->error($e->getCode(), $e->getMessage()); - } + $uploads = refiles($_FILES['files']); + + try { + foreach ($uploads as $upload) { + $res[] = upload_file($upload); + } + $response->send($res); + } catch (Exception $e) { + $response->error($e->getCode(), $e->getMessage()); + } } else { - $response->error(400, 'No input file(s)'); + $response->error(400, 'No input file(s)'); } - -?> |
