Skip to content

Instantly share code, notes, and snippets.

@Battleroid
Last active December 15, 2015 21:29
Show Gist options
  • Save Battleroid/5326084 to your computer and use it in GitHub Desktop.
Save Battleroid/5326084 to your computer and use it in GitHub Desktop.
PHP script to setup batch file for download which in turn starts cgminer with specified arguments. Notes: added rtrim to remove trailing slashes on URL.
<?php
/* Feel free to use this to your heart's content, but please link back here somewhere, I'd appreciate it. Thanks.
Also if you find any problems, let me know, I'll get to fixing them. */
function addHTTP($url) {
if (!preg_match("~^(?:f|ht)tps?://~i", $url))
$url = "http://" . $url;
return $url;
}
// Setup variables
$address = addHTTP((empty($_POST["url"])) ? "checkersthecat.com" : rtrim($_POST["url"], "/"));
$port = (empty($_POST["port"]) ? 9332 : $_POST["port"]);
$user = (empty($_POST["workername"]) ? "CHANGE_ME" : $_POST["workername"]);
$pass = (empty($_POST["workerpass"]) ? "CHANGE_ME" : $_POST["workerpass"]);
$int = (empty($_POST["intensity"])) ? 13 : $_POST["intensity"];
$preset = $_POST["preset"];
$enable_preset = $_POST["use-preset"];
$worksize = (empty($_POST["worksize"])) ? false : $_POST["worksize"];
$conc = (empty($_POST["conc"])) ? false : $_POST["conc"];
$threads = (empty($_POST["threads-per-gpu"])) ? false : $_POST["threads-per-gpu"];
$gap = $_POST["gap"];
$arglist = "";
if ($int > 20)
$int = 20;
else if ($int < -10)
$int = -10;
function createArglist($lsize, $lconc, $lthreads, $lgap) {
$output = "";
global $worksize;
global $conc;
global $threads;
global $gap;
// create list if items are set
if ($lsize != false) {
$output .= (!$worksize) ? "--worksize {$lsize} " : "--worksize {$worksize} ";
}
if ($lconc != false) {
$output .= (!$conc) ? "--thread-concurrency {$lconc} " : "--thread-concurrency {$conc} ";
}
if ($lthreads != false) {
$output .= (!$threads) ? "-g {$lthreads} " : "-g {$threads} ";
}
if ($lgap != false) {
$output .= (!$gap) ? "--lookup-gap {$lgap} " : "--lookup-gap {$gap} ";
}
return $output;
}
// Create arguments based on preset
if (isset($enable_preset) && $enable_preset == true) {
if ($preset == "6770") {
$arglist = createArglist(256, 8192, 1, 2);
} else if ($preset == "6850") {
$arglist = createArglist(256, 6144, false, false);
} else if ($preset == "6870") {
$arglist = createArglist(256, 8192, 1, 2);
} else if ($preset == "6950") {
$arglist = createArglist(256, 5632, false, false);
} else if ($preset == "6970") {
$arglist = "";
} else if ($preset == "6990") {
$arglist = createArglist(256, 8144, 1, 2);
} else if ($preset == "7770") {
$arglist = createArglist(256, 6144, 1, 2);
} else if ($preset == "7850") {
$arglist = "";
} else if ($preset == "7950") {
$arglist = createArglist(256, 24576, 1, 2);
} else if ($preset == "7970") {
$arglist = createArglist(256, 24576, 2, 2);
}
} else {
$arglist = createArglist($worksize, $conc, $threads, $gap);
}
// Create batchfile
//header("Content-disposition: attachment; filename=mine.bat"); disabled because it saves as text file, not batch
header("Content-type: text/plain");
echo "@echo off\ncls";
echo "\nREM Save as \"mine.bat\" and place in directory of cgminer.exe";
echo "\necho Created using Battleroid's config creator\npause";
echo "\ncgminer.exe -o {$address}:{$port} -u {$user} -p {$pass} -I {$int} --scrypt {$arglist}";
?>
<html>
<head>
<title>cgminer config creator</title>
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Open+Sans);
body {font: 14px/25px "Open Sans", sans-serif;}
#wrapper {width: 500px;margin:0 auto;}
label {display:block;width:150px;float:left;clear:left;margin:0 0 5px 0;}
label:after {content:": ";}
input {margin:0 0 10px 0;width:65%;display:block;}
input[type=checkbox] {margin:15px;width:auto;}
input[type=submit] {width:100%;margin-top:15px;}
.dd {margin: 0 0 10px;}
.note {margin-top:0;font-size:13px;}
</style>
</head>
<body>
<div id="wrapper">
<h3>Litecoin mining setup by your neighborhood Battleroid</h3>
<form action="custom-dl.php" method="post">
<fieldset>
<legend>Pool Information</legend>
<label for="url">Address</label>
<input type="text" name="url" placeholder="http://checkersthecat.com" />
<label for="port">Port</label>
<input type="text" name="port" placeholder="9327" />
<label for="workername">Username</label>
<input type="text" name="workername" placeholder="wallet address" />
<label for="workerpass">Password</label>
<input type="text" name="workerpass" placeholder="x" />
</fieldset>
<fieldset>
<legend>Preset</legend>
<p class="note">Values entered in the advanced section will override preset parameters.</p>
<p class="note">Parameters for the presets were taken from the litecoin mining comparison charts. I used values from the submissions that achieved the best hash rate, however, I did not include overclocking parameters. <strong>Use at your own risk.</strong></p>
<label for="use-preset">Use a preset?</label>
<input type="checkbox" name="use-preset" value="true" />
<label for="preset">GPU preset</label>
<select name="preset" class="dd">
<option value="6770">6770</option>
<option value="6850">6850</option>
<option value="6870">6870</option>
<option value="6950">6950</option>
<option value="6970">6970</option>
<option value="6990">6990</option>
<option value="7770">7770</option>
<option value="7850">7850</option>
<option value="7950">7950</option>
<option value="7970">7970</option>
</select>
</fieldset>
<fieldset>
<legend>Advanced Information</legend>
<label for="intensity">Intensity (-10 to 20)</label>
<input type="text" name="intensity" placeholder="17" />
<label for="worksize">Worksize</label>
<input type="text" name="worksize" placeholder="256" />
<label for="conc">Thread concurrency</label>
<input type="text" name="conc" placeholder="8192" />
<label for="threads-per-gpu">Threads per GPU</label>
<input type="text" name="threads-per-gpu" placeholder="2" />
<label for="gap">Lookup Gap</label>
<input type="text" name="gap" placeholder="2" />
</fieldset>
<input type="submit" value="Generate" />
</form>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment