Commit 83231db3c6a34e783ddc2d5df851682771b19063

Con Kolivas 2014-02-12T20:48:46

Merge branch 'master' of github.com:ckolivas/cgminer

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
diff --git a/API-README b/API-README
index 88b29a2..3416aba 100644
--- a/API-README
+++ b/API-README
@@ -1220,20 +1220,49 @@ However, if $readonly is true, it will not display them
 ---------
 
 Default:
+ $rigport = 4028;
+
+Default port to use if any $rigs entries don't specify the port number
+
+---------
+
+Default:
  $rigs = array('127.0.0.1:4028');
 
 Set $rigs to an array of your cgminer rigs that are running
- format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
+ format: 'IP' or 'Host' or 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
 If you only have one rig, it will just show the detail of that rig
 If you have more than one rig it will show a summary of all the rigs
  with buttons to show the details of each rig -
  the button contents will be 'Name' rather than rig number, if you
  specify 'Name'
+If Port is missing or blank, it will try $rigport
 e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028:Sugoi');
 
 ---------
 
 Default:
+ $rignames = false;
+
+Set $rignames to false to not affect the display.
+Set $rignames to one of 'ip' or 'ipx' to alter the name displayed
+if the rig doesn't have a 'name' in $rigs
+Currently:
+ 'ip' means use the 4th byte of the rig IP address as an integer
+ 'ipx' means use the 4th byte of the rig IP address as 2 hex bytes
+
+---------
+
+Default:
+ $rigbuttons = true;
+
+Set $rigbuttons to false to display a link rather than a button on
+the left of any summary table with rig buttons, in order to reduce
+the height of the table cells
+
+---------
+
+Default:
  $mcast = false;
 
 Set $mcast to true to look for your rigs and ignore $rigs
diff --git a/README b/README
index f793c63..a4a7961 100644
--- a/README
+++ b/README
@@ -168,6 +168,8 @@ Options for both config file and command line:
 --avalon-options <arg> Set avalon options baud:miners:asic:timeout:freq:tech
 --avalon-temp <arg> Set avalon target temperature (default: 50)
 --balance           Change multipool strategy from failover to even share balance
+--benchfile <arg>   Run cgminer in benchmark mode using a work file - produces no shares
+--benchfile-display Display each benchfile nonce found
 --benchmark         Run cgminer in benchmark mode - produces no shares
 --bfl-range         Use nonce range on bitforce devices if supported
 --bflsc-overheat <arg> Set overheat temperature where BFLSC devices throttle, 0 to disable (default: 85)
@@ -643,6 +645,34 @@ For example (this is wrapped, but it's all on one line for real):
 
 ---
 
+BENCHMARK
+
+The --benchmark option hashes a single fixed work item over and over and does
+not submit shares to any pools.
+
+The --benchfile <arg> option hashes the work given in the file <arg> supplied.
+The format of the work file is:
+version,merkleroot,prevhash,diffbits,noncetime
+Any empty line or any line starting with '#' or '/' is ignored.
+When it reaches the end of the file it continues back at the top.
+
+The format of the data items matches the byte ordering and format of the
+the bitcoind getblock RPC output.
+
+An example file containing bitcoin block #1 would be:
+
+# Block 1
+1,0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098,00000000001
+9d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f,1d00ffff,1231469665
+
+However, the work data should be one line without the linebreak in the middle
+
+If you use --benchfile <arg>, then --benchfile-display will output a log line,
+for each nonce found, showing the nonce value in decimal and hex and the work
+used to find it in hex.
+
+---
+
 RPC API
 
 For RPC API details see the API-README file
diff --git a/cgminer.c b/cgminer.c
index 0d4037b..cc6e28b 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -100,6 +100,29 @@ static char packagename[256];
 
 bool opt_work_update;
 bool opt_protocol;
+static struct benchfile_layout {
+	int length;
+	char *name;
+} benchfile_data[] = {
+	{ 1,	"Version" },
+	{ 64,	"MerkleRoot" },
+	{ 64,	"PrevHash" },
+	{ 8,	"DifficultyBits" },
+	{ 10,	"NonceTime" } // 10 digits
+};
+enum benchwork {
+	BENCHWORK_VERSION = 0,
+	BENCHWORK_MERKLEROOT,
+	BENCHWORK_PREVHASH,
+	BENCHWORK_DIFFBITS,
+	BENCHWORK_NONCETIME,
+	BENCHWORK_COUNT
+};
+static char *opt_benchfile;
+static bool opt_benchfile_display;
+static FILE *benchfile_in;
+static int benchfile_line;
+static int benchfile_work;
 static bool opt_benchmark;
 bool have_longpoll;
 bool want_per_device_stats;
@@ -1188,6 +1211,12 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITHOUT_ARG("--balance",
 		     set_balance, &pool_strategy,
 		     "Change multipool strategy from failover to even share balance"),
+	OPT_WITH_ARG("--benchfile",
+			opt_set_charp, opt_show_charp, &opt_benchfile,
+			"Run cgminer in benchmark mode using a work file - produces no shares"),
+	OPT_WITHOUT_ARG("--benchfile-display",
+			opt_set_bool, &opt_benchfile_display,
+			"Display each benchfile nonce found"),
 	OPT_WITHOUT_ARG("--benchmark",
 			opt_set_bool, &opt_benchmark,
 			"Run cgminer in benchmark mode - produces no shares"),
@@ -3147,6 +3176,154 @@ static void get_benchmark_work(struct work *work)
 	calc_diff(work, 0);
 }
 
+static void benchfile_dspwork(struct work *work, uint32_t nonce)
+{
+	char buf[1024];
+	uint32_t dn;
+	int i;
+
+	dn = 0;
+	for (i = 0; i < 4; i++) {
+		dn *= 0x100;
+		dn += nonce & 0xff;
+		nonce /= 0x100;
+	}
+
+	if ((sizeof(work->data) * 2 + 1) > sizeof(buf))
+		quithere(1, "BENCHFILE Invalid buf size");
+
+	__bin2hex(buf, work->data, sizeof(work->data));
+
+	applog(LOG_ERR, "BENCHFILE nonce %u=0x%08x for work=%s",
+			(unsigned int)dn, (unsigned int)dn, buf);
+
+}
+
+static bool benchfile_get_work(struct work *work)
+{
+	char buf[1024];
+	char item[1024];
+	bool got = false;
+
+	if (!benchfile_in) {
+		if (opt_benchfile)
+			benchfile_in = fopen(opt_benchfile, "r");
+		else
+			quit(1, "BENCHFILE Invalid benchfile NULL");
+
+		if (!benchfile_in)
+			quit(1, "BENCHFILE Failed to open benchfile '%s'", opt_benchfile);
+
+		benchfile_line = 0;
+
+		if (!fgets(buf, 1024, benchfile_in))
+			quit(1, "BENCHFILE Failed to read benchfile '%s'", opt_benchfile);
+
+		got = true;
+		benchfile_work = 0;
+	}
+
+	if (!got) {
+		if (!fgets(buf, 1024, benchfile_in)) {
+			if (benchfile_work == 0)
+				quit(1, "BENCHFILE No work in benchfile '%s'", opt_benchfile);
+			fclose(benchfile_in);
+			benchfile_in = NULL;
+			return benchfile_get_work(work);
+		}
+	}
+
+	do {
+		benchfile_line++;
+
+		// Empty lines and lines starting with '#' or '/' are ignored
+		if (*buf != '\0' && *buf != '#' && *buf != '/') {
+			char *commas[BENCHWORK_COUNT];
+			int i, j, len;
+			long nonce_time;
+
+			commas[0] = buf;
+			for (i = 1; i < BENCHWORK_COUNT; i++) {
+				commas[i] = strchr(commas[i-1], ',');
+				if (!commas[i]) {
+					quit(1, "BENCHFILE Invalid input file line %d"
+						" - field count is %d but should be %d",
+						benchfile_line, i, BENCHWORK_COUNT);
+				}
+				len = commas[i] - commas[i-1];
+				if (benchfile_data[i-1].length &&
+				    (len != benchfile_data[i-1].length)) {
+					quit(1, "BENCHFILE Invalid input file line %d "
+						"field %d (%s) length is %d but should be %d",
+						benchfile_line, i,
+						benchfile_data[i-1].name,
+						len, benchfile_data[i-1].length);
+				}
+
+				*(commas[i]++) = '\0';
+			}
+
+			// NonceTime may have LF's etc
+			len = strlen(commas[BENCHWORK_NONCETIME]);
+			if (len < benchfile_data[BENCHWORK_NONCETIME].length) {
+				quit(1, "BENCHFILE Invalid input file line %d field %d"
+					" (%s) length is %d but should be least %d",
+					benchfile_line, BENCHWORK_NONCETIME+1,
+					benchfile_data[BENCHWORK_NONCETIME].name, len,
+					benchfile_data[BENCHWORK_NONCETIME].length);
+			}
+
+			sprintf(item, "0000000%c", commas[BENCHWORK_VERSION][0]);
+
+			j = strlen(item);
+			for (i = benchfile_data[BENCHWORK_PREVHASH].length-8; i >= 0; i -= 8) {
+				sprintf(&(item[j]), "%.8s", &commas[BENCHWORK_PREVHASH][i]);
+				j += 8;
+			}
+
+			for (i = benchfile_data[BENCHWORK_MERKLEROOT].length-8; i >= 0; i -= 8) {
+				sprintf(&(item[j]), "%.8s", &commas[BENCHWORK_MERKLEROOT][i]);
+				j += 8;
+			}
+
+			nonce_time = atol(commas[BENCHWORK_NONCETIME]);
+
+			sprintf(&(item[j]), "%08lx", nonce_time);
+			j += 8;
+
+			strcpy(&(item[j]), commas[BENCHWORK_DIFFBITS]);
+			j += benchfile_data[BENCHWORK_DIFFBITS].length;
+
+			memset(work, 0, sizeof(*work));
+
+			hex2bin(work->data, item, j >> 1);
+
+			calc_midstate(work);
+
+			benchfile_work++;
+
+			return true;
+		}
+	} while (fgets(buf, 1024, benchfile_in));
+
+	if (benchfile_work == 0)
+		quit(1, "BENCHFILE No work in benchfile '%s'", opt_benchfile);
+	fclose(benchfile_in);
+	benchfile_in = NULL;
+	return benchfile_get_work(work);
+}
+
+static void get_benchfile_work(struct work *work)
+{
+	benchfile_get_work(work);
+	work->mandatory = true;
+	work->pool = pools[0];
+	cgtime(&work->tv_getwork);
+	copy_time(&work->tv_getwork_reply, &work->tv_getwork);
+	work->getwork_mode = GETWORK_MODE_BENCHMARK;
+	calc_diff(work, 0);
+}
+
 #ifdef HAVE_CURSES
 static void disable_curses_windows(void)
 {
@@ -3672,7 +3849,7 @@ static bool stale_work(struct work *work, bool share)
 	struct pool *pool;
 	int getwork_delay;
 
-	if (opt_benchmark)
+	if (opt_benchmark || opt_benchfile)
 		return false;
 
 	if (work->work_block != work_block) {
@@ -6207,6 +6384,9 @@ bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
 		return false;
 	}
 
+	if (opt_benchfile && opt_benchfile_display)
+		benchfile_dspwork(work, nonce);
+
 	return true;
 }
 
@@ -6227,6 +6407,10 @@ bool submit_noffset_nonce(struct thr_info *thr, struct work *work_in, uint32_t n
 	}
 	ret = true;
 	update_work_stats(thr, work);
+
+	if (opt_benchfile && opt_benchfile_display)
+		benchfile_dspwork(work, nonce);
+
 	if (!fulltest(work->hash, work->target)) {
 		applog(LOG_INFO, "%s %d: Share above target", thr->cgpu->drv->name,
 		       thr->cgpu->device_id);
@@ -7035,7 +7219,7 @@ static void *watchpool_thread(void __maybe_unused *userdata)
 		for (i = 0; i < total_pools; i++) {
 			struct pool *pool = pools[i];
 
-			if (!opt_benchmark)
+			if (!opt_benchmark && !opt_benchfile)
 				reap_curl(pool);
 
 			/* Get a rolling utility per pool over 10 mins */
@@ -8062,12 +8246,15 @@ int main(int argc, char *argv[])
 	if (!config_loaded)
 		load_default_config();
 
-	if (opt_benchmark) {
+	if (opt_benchmark || opt_benchfile) {
 		struct pool *pool;
 
 		pool = add_pool();
 		pool->rpc_url = malloc(255);
-		strcpy(pool->rpc_url, "Benchmark");
+		if (opt_benchfile)
+			strcpy(pool->rpc_url, "Benchfile");
+		else
+			strcpy(pool->rpc_url, "Benchmark");
 		pool->rpc_user = pool->rpc_url;
 		pool->rpc_pass = pool->rpc_url;
 		enable_pool(pool);
@@ -8270,7 +8457,7 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	if (opt_benchmark)
+	if (opt_benchmark || opt_benchfile)
 		goto begin_bench;
 
 	for (i = 0; i < total_pools; i++) {
@@ -8437,7 +8624,12 @@ retry:
 			continue;
 		}
 
-		if (opt_benchmark) {
+		if (opt_benchfile) {
+			get_benchfile_work(work);
+			applog(LOG_DEBUG, "Generated benchfile work");
+			stage_work(work);
+			continue;
+		} else if (opt_benchmark) {
 			get_benchmark_work(work);
 			applog(LOG_DEBUG, "Generated benchmark work");
 			stage_work(work);
diff --git a/miner.php b/miner.php
index ff2e457..6fd0658 100644
--- a/miner.php
+++ b/miner.php
@@ -1,7 +1,8 @@
 <?php
 session_start();
 #
-global $doctype, $title, $miner, $port, $readonly, $notify, $rigs;
+global $doctype, $title, $miner, $port, $readonly, $notify;
+global $rigport, $rigs, $rignames, $rigbuttons;
 global $mcast, $mcastexpect, $mcastaddr, $mcastport, $mcastcode;
 global $mcastlistport, $mcasttimeout, $mcastretries, $allowgen;
 global $rigipsecurity, $rigtotals, $forcerigtotals;
@@ -44,10 +45,20 @@ $checklastshare = true;
 # N.B. also if $readonly is true, it will not display the fields
 $poolinputs = false;
 #
+# Default port to use if any $rigs entries don't specify the port number
+$rigport = 4028;
+#
 # Set $rigs to an array of your cgminer rigs that are running
-#  format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
+#  format: 'IP' or 'Host' or 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
 $rigs = array('127.0.0.1:4028');
 #
+# Set $rignames to false, or one of 'ip' or 'ipx'
+#  this says what to use if $rigs doesn't have a 'name'
+$rignames = false;
+#
+# Set $rigbuttons to false to display a link rather than a button
+$rigbuttons = true;
+#
 # Set $mcast to true to look for your rigs and ignore $rigs
 $mcast = false;
 #
@@ -247,6 +258,9 @@ $colourtable = array(
 $miner = null;
 $port = null;
 #
+global $rigips;
+$rigips = array();
+#
 # Ensure it is only ever shown once
 global $showndate;
 $showndate = false;
@@ -289,6 +303,14 @@ function getdom($domname)
  return getcss($domname, true);
 }
 #
+# N.B. don't call this before calling htmlhead()
+function php_pr($cmd)
+{
+ global $here, $autorefresh;
+
+ return "$here?ref=$autorefresh$cmd";
+}
+#
 function htmlhead($mcerr, $checkapi, $rig, $pg = null, $noscript = false)
 {
  global $doctype, $title, $miner_font_family, $miner_font_size;
@@ -491,9 +513,12 @@ function getrigs()
 #
 function getsock($rig, $addr, $port)
 {
- global $rigipsecurity;
+ global $rigport, $rigips, $rignames, $rigipsecurity;
  global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec;
 
+ $port = trim($port);
+ if (strlen($port) == 0)
+	$port = $rigport;
  $error = null;
  $socket = null;
  $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
@@ -534,6 +559,9 @@ function getsock($rig, $addr, $port)
 	socket_close($socket);
 	return null;
  }
+ if ($rignames !== false && !isset($rigips[$addr]))
+	if (socket_getpeername($socket, $ip) == true)
+		$rigips[$addr] = $ip;
  return $socket;
 }
 #
@@ -1536,39 +1564,67 @@ function process($cmds, $rig)
 #
 function rigname($rig, $rigname)
 {
- global $rigs;
+ global $rigs, $rignames, $rigips;
 
  if (isset($rigs[$rig]))
  {
 	$parts = explode(':', $rigs[$rig], 3);
 	if (count($parts) == 3)
 		$rigname = $parts[2];
+	else
+		if ($rignames !== false)
+		{
+			switch ($rignames)
+			{
+			case 'ip':
+				if (isset($parts[0]) && isset($rigips[$parts[0]]))
+				{
+					$ip = explode('.', $rigips[$parts[0]]);
+					if (count($ip) == 4)
+						$rigname = intval($ip[3]);
+				}
+				break;
+			case 'ipx':
+				if (isset($parts[0]) && isset($rigips[$parts[0]]))
+				{
+					$ip = explode('.', $rigips[$parts[0]]);
+					if (count($ip) == 4)
+						$rigname = intval($ip[3], 16);
+				}
+				break;
+			}
+		}
  }
 
  return $rigname;
 }
 #
-function riginput($rig, $rigname)
+function riginput($rig, $rigname, $usebuttons)
 {
  $rigname = rigname($rig, $rigname);
 
- return "<input type=button value='$rigname' onclick='pr(\"&rig=$rig\",null)'>";
+ if ($usebuttons === true)
+	return "<input type=button value='$rigname' onclick='pr(\"&rig=$rig\",null)'>";
+ else
+	return "<a href='".php_pr("&rig=$rig")."'>$rigname</a>";
 }
 #
-function rigbutton($rig, $rigname, $when, $row)
+function rigbutton($rig, $rigname, $when, $row, $usebuttons)
 {
  list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
 
  if ($rig === '')
 	$ri = '&nbsp;';
  else
-	$ri = riginput($rig, $rigname);
+	$ri = riginput($rig, $rigname, $usebuttons);
 
  return "<td align=middle$class>$ri</td>";
 }
 #
 function showrigs($anss, $headname, $rigname)
 {
+ global $rigbuttons;
+
  $dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
  showhead('', $dthead);
 
@@ -1591,7 +1647,7 @@ function showrigs($anss, $headname, $rigname)
 		foreach ($dthead as $name => $x)
 		{
 			if ($item == 'STATUS' && $name == $headname)
-				echo rigbutton($rig, $rigname.$rig, $when, null);
+				echo rigbutton($rig, $rigname.$rig, $when, null, $rigbuttons);
 			else
 			{
 				if (isset($row[$name]))
@@ -1610,7 +1666,7 @@ function showrigs($anss, $headname, $rigname)
 function doforeach($cmd, $des, $sum, $head, $datetime)
 {
  global $miner, $port;
- global $error, $readonly, $notify, $rigs;
+ global $error, $readonly, $notify, $rigs, $rigbuttons;
  global $warnfont, $warnoff, $dfmt;
  global $rigerror;
 
@@ -1629,10 +1685,13 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
 		continue;
 
 	$parts = explode(':', $rig, 3);
-	if (count($parts) >= 2)
+	if (count($parts) >= 1)
 	{
 		$miner = $parts[0];
-		$port = $parts[1];
+		if (count($parts) >= 2)
+			$port = $parts[1];
+		else
+			$port = '';
 
 		if (count($parts) > 2)
 			$name = $parts[2];
@@ -1747,7 +1806,7 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
 					echo "<td align=right$class>Total:</td>";
 				}
 				else
-					echo rigbutton($rig, "Rig $rig", $when, $row);
+					echo rigbutton($rig, "Rig $rig", $when, $row, $rigbuttons);
 			}
 			else
 			{
@@ -1780,7 +1839,7 @@ function refreshbuttons()
 #
 function pagebuttons($rig, $pg)
 {
- global $readonly, $rigs, $userlist, $ses;
+ global $readonly, $rigs, $rigbuttons, $userlist, $ses;
  global $allowcustompages, $customsummarypages;
 
  if ($rig === null)
@@ -1819,10 +1878,12 @@ function pagebuttons($rig, $pg)
  if ($userlist === null || isset($_SESSION[$ses]))
  {
 	if ($prev !== null)
-		echo riginput($prev, 'Prev').'&nbsp;';
+		echo riginput($prev, 'Prev', true).'&nbsp;';
+
 	echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
+
 	if ($next !== null)
-		echo riginput($next, 'Next').'&nbsp;';
+		echo riginput($next, 'Next', true).'&nbsp;';
 	echo '&nbsp;';
 	if (count($rigs) > 1)
 		echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
@@ -2184,6 +2245,8 @@ function secmatch($section, $field)
 #
 function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
 {
+ global $rigbuttons;
+
  foreach ($result as $sec => $row)
  {
 	$secname = preg_replace('/\d/', '', $sec);
@@ -2200,7 +2263,7 @@ function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total
 
 
 	if ($isbutton)
-		echo rigbutton($rig, $rig, $when, $row);
+		echo rigbutton($rig, $rig, $when, $row, $rigbuttons);
 	else
 	{
 		list($ignore, $class) = fmt('total', '', '', $when, $row);
@@ -2535,10 +2598,13 @@ function processcustompage($pagename, $sections, $sum, $ext, $namemap)
  foreach ($rigs as $num => $rig)
  {
 	$parts = explode(':', $rig, 3);
-	if (count($parts) >= 2)
+	if (count($parts) >= 1)
 	{
 		$miner = $parts[0];
-		$port = $parts[1];
+		if (count($parts) >= 2)
+			$port = $parts[1];
+		else
+			$port = '';
 
 		if (count($parts) > 2)
 			$name = $parts[2];
@@ -2896,10 +2962,13 @@ function display()
 		if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
 		{
 			$parts = explode(':', $rigs[$rig], 3);
-			if (count($parts) >= 2)
+			if (count($parts) >= 1)
 			{
 				$miner = $parts[0];
-				$port = $parts[1];
+				if (count($parts) >= 2)
+					$port = $parts[1];
+				else
+					$port = '';
 
 				if ($readonly !== true)
 					$preprocess = $arg;
@@ -2948,10 +3017,13 @@ function display()
  if (count($rigs) == 1)
  {
 	$parts = explode(':', $rigs[0], 3);
-	if (count($parts) >= 2)
+	if (count($parts) >= 1)
 	{
 		$miner = $parts[0];
-		$port = $parts[1];
+		if (count($parts) >= 2)
+			$port = $parts[1];
+		else
+			$port = '';
 
 		htmlhead($mcerr, true, 0);
 		doOne(0, $preprocess);
@@ -2968,10 +3040,13 @@ function display()
  if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  {
 	$parts = explode(':', $rigs[$rig], 3);
-	if (count($parts) >= 2)
+	if (count($parts) >= 1)
 	{
 		$miner = $parts[0];
-		$port = $parts[1];
+		if (count($parts) >= 2)
+			$port = $parts[1];
+		else
+			$port = '';
 
 		htmlhead($mcerr, true, 0);
 		doOne($rig, $preprocess);