diff --git a/functions/add-modv.php b/functions/add-modv.php index e58935e..283e75c 100644 --- a/functions/add-modv.php +++ b/functions/add-modv.php @@ -2,32 +2,35 @@ session_start(); if (empty($_POST['pretty_name'])) { - die("Name not specified."); + die('{"status":"error","message":"Pretty name not specified."}'); } if (empty($_POST['name'])) { - die("Slug not specified."); + die('{"status":"error","message":"Slug not specified."}'); } if (empty($_POST['version'])) { - die("Version not specified."); + die('{"status":"error","message":"Version not specified."}'); } if (empty($_POST['url'])) { - die("URL not specified."); + die('{"status":"error","message":"File URL not specified."}'); } if (empty($_POST['md5'])) { - die("Md5 not specified."); + die('{"status":"error","message":"MD5 not specified."}'); +} +if (empty($_POST['filesize'])) { + die('{"status":"error","message":"Filesize not specified."}'); } if (empty($_POST['mcversion'])) { - die("Minecraft version not specified."); + die('{"status":"error","message":"Minecraft version not specified."}'); } if (empty($_POST['loadertype'])) { - die("Loader type not specified."); + die('{"status":"error","message":"Loader type not specified."}'); } if (!$_SESSION['user']||$_SESSION['user']=="") { - die("Unauthorized request or login session has expired!"); + die('{"status":"error","message":"Unauthorized request or login session has expired!"}'); } if (substr($_SESSION['perms'], 3, 1)!=="1") { - die("Insufficient permission!"); + die('{"status":"error","message":"Insufficient permission!"}'); } $config = require("./config.php"); @@ -38,26 +41,39 @@ $db->connect(); } +$name = $db->sanitize($_POST['name']); +$md5 = $db->sanitize($_POST['md5']); +$filesize = $db->sanitize($_POST['filesize']); $link = isset($_POST['link']) ? $db->sanitize($_POST['link']) : ''; $auth = isset($_POST['author']) ? $db->sanitize($_POST['author']) : ''; $desc = isset($_POST['description']) ? $db->sanitize($_POST['description']) : ''; $donlink = isset($_POST['donlink']) ? $db->sanitize($_POST['donlink']) : ''; -$db->execute("INSERT INTO `mods` - (`name`, `pretty_name`, `md5`, `url`, `link`, `author`, `donlink`, `description`, `version`, `mcversion`, `type`, `loadertype`) VALUES ( - '".$db->sanitize($_POST['name'])."', - '".$db->sanitize($_POST['pretty_name'])."', - '".$db->sanitize($_POST['md5'])."', - '".$db->sanitize($_POST['url'])."', - '".$link."', - '".$auth."', - '".$donlink."', - '".$desc."', - '".$db->sanitize($_POST['version'])."', - '".$db->sanitize($_POST['mcversion'])."', +// we use name (slug) and md5 to determine if its already installed. +// since we have md5. otherwise we should check version,mcversion,name/slug,type,loadertype +$existsq = $db->query("SELECT 1 FROM mods WHERE name='{$name}' AND md5='{$md5}'"); +if ($existsq && sizeof($existsq)>=1) { + die('{"status":"succ","message":"Mod is already added."}'); +} + +$addq = $db->execute("INSERT INTO `mods` + (`name`, `pretty_name`, `md5`, `filesize`, `url`, `link`, `author`, `donlink`, `description`, `version`, `mcversion`, `type`, `loadertype`) VALUES ( + '{$name}', + '{$db->sanitize($_POST['pretty_name'])}', + '{$md5}', + '{$filesize}', + '{$db->sanitize($_POST['url'])}', + '{$link}', + '{$auth}', + '{$donlink}', + '{$desc}', + '{$db->sanitize($_POST['version'])}', + '{$db->sanitize($_POST['mcversion'])}', 'mod', - '".$db->sanitize($_POST['loadertype'])."', + '{$db->sanitize($_POST['loadertype'])}' )"); +if ($addq) { + die('{"status":"succ","message":"Mod successfully added."}'); +} -header("Location: ".$config['dir']."lib-mods"); -exit(); +die('{"status":"error","message":"Could not add mod."}'); diff --git a/index.php b/index.php index 9dcbb5b..4eea14d 100644 --- a/index.php +++ b/index.php @@ -123,6 +123,7 @@ function uri($uri) { + @@ -1328,17 +1329,18 @@ function uri($uri) { } ?> -
Name | +Category | +Desc. | +Author | ++ |
---|
${G(e,!0)}
`}br(e){return"An error occurred:
"+G(n.message+"",!0)+"";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}}const ne=new te;function se(e,t){return ne.parse(e,t)}se.options=se.setOptions=function(e){return ne.setOptions(e),se.defaults=ne.defaults,n(se.defaults),se},se.getDefaults=t,se.defaults=e.defaults,se.use=function(...e){return ne.use(...e),se.defaults=ne.defaults,n(se.defaults),se},se.walkTokens=function(e,t){return ne.walkTokens(e,t)},se.parseInline=ne.parseInline,se.Parser=Y,se.parser=Y.parse,se.Renderer=V,se.TextRenderer=W,se.Lexer=K,se.lexer=K.lex,se.Tokenizer=J,se.Hooks=ee,se.parse=se;const re=se.options,ie=se.setOptions,le=se.use,oe=se.walkTokens,ae=se.parseInline,ce=se,he=Y.parse,pe=K.lex;e.Hooks=ee,e.Lexer=K,e.Marked=te,e.Parser=Y,e.Renderer=V,e.TextRenderer=W,e.Tokenizer=J,e.getDefaults=t,e.lexer=pe,e.marked=se,e.options=re,e.parse=ce,e.parseInline=ae,e.parser=he,e.setOptions=ie,e.use=le,e.walkTokens=oe})); diff --git a/resources/js/page_add-mods.js b/resources/js/page_add-remote.js similarity index 100% rename from resources/js/page_add-mods.js rename to resources/js/page_add-remote.js diff --git a/resources/js/page_lib-mods.js b/resources/js/page_lib-mods.js index ade69ed..97088b7 100644 --- a/resources/js/page_lib-mods.js +++ b/resources/js/page_lib-mods.js @@ -1,3 +1,5 @@ +const SEARCH_LIMIT=20; + function remove_box(name) { $("#mod-name-title").text(name); $("#mod-name").text(name); @@ -91,14 +93,15 @@ function sendFile(file, i) { break; } } - let num_versions = response['modid'].length; - let author = response['author']; - let name = response['name']; - let pretty_name = response['pretty_name']; - let mcversion = response['mcversion']; - let version = response['version']; + // console.log(response['status']); if (response['status']!="error") { + let num_versions = response['modid'].length; + let author = response['author']; + let name = response['name']; + let pretty_name = response['pretty_name']; + let mcversion = response['mcversion']; + let version = response['version']; // console.log('add new row'); let i=0; // for (let id of response['modid']) { @@ -155,7 +158,390 @@ $("#search").on('keyup',function(){ function showFile(file, i) { $("#table-mods").append('