pezcurrel 4 years ago
parent
commit
5d02a109bf
2 changed files with 352 additions and 159 deletions
  1. 310 125
      web/admin/crawler/crawler.php
  2. 42 34
      web/admin/zzz-materiali/mastostart.sql

+ 310 - 125
web/admin/crawler/crawler.php

@@ -16,6 +16,11 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+/*
+DAFA
+- hardening sull'input: verificare tipi, truncn, truncs
+*/
+
 define('N',"\n");
 
 $link=false;
@@ -34,12 +39,13 @@ function signalHandler($signal) {
 		mysqli_close($link);
 	}
 	if ($jsonf) {
-		echo('Il file di dump json è aperto, lo chiudo.'.N);
-		fwrite($jsonf,'"Fine?": true'.N.'}'.N);
+		lecho('Il file di dump json è aperto, lo chiudo.'.N);
+// qui no, altrimenti "riprendi" fa poi casino
+//		fwrite($jsonf,'"Fine?": true'.N.'}'.N);
 		fclose($jsonf);
 	}
 	if ($logf) {
-		echo('Il file di log è aperto, lo chiudo.'.N);
+		lecho('Il file di log è aperto, lo chiudo.'.N);
 		fclose($logf);
 	}
 	exit(2);
@@ -48,7 +54,7 @@ function signalHandler($signal) {
 $opts=array(
 	'timeout'=>3,
 	'log'=>true,
-	'jsonfp'=>'instances.json',
+	'jsonfp'=>__DIR__.'/instances.json',
 	'jsonwrite'=>true,
 	'jsonread'=>false
 );
@@ -106,14 +112,29 @@ function lecho($msg,$logonly=false) {
 		fwrite($logf,$msg);
 }
 
-$logfp='crawler.log';
+$instsjfp=__DIR__.'/instances.job';
+$currinstjfp=__DIR__.'/currinst.job';
+if (file_exists($currinstjfp) && file_exists($instsjfp)) {
+	$riprendi=true;
+} else {
+	$riprendi=false;
+}
+
+$logfp=__DIR__.'/crawler.log';
 if ($opts['log']) {
-	$logf=@fopen(__DIR__.'/'.$logfp,'w')
-		or mexit('Non ho potuto aprire in scrittura il file di log «'.$logfp.'».',1);
+	if ($riprendi)
+		$mode=array('a','aggiunta');
+	else
+		$mode=array('w','scrittura');
+	$logf=@fopen($logfp,$mode[0]);
+	if ($logf===false) {
+		echo('Non ho potuto aprire in modalità '.$mode[1].' il file di log «'.$logfp.'».'.N);
+		exit(1);
+	}
 }
 
-$inifp='../sec/mastostartadmin.ini';
-$iniarr=parse_ini_file($inifp)
+$inifp=__DIR__.'/../sec/mastostartadmin.ini';
+$iniarr=@parse_ini_file($inifp)
 	or mexit('Impossibile aprire il file di configurazione «'.$inifp.'»'.N,1);
 $link=mysqli_connect($iniarr['db_host'],$iniarr['db_admin_name'],$iniarr['db_admin_password'],$iniarr['db_name'],$iniarr['db_port'],$iniarr['db_socket'])
 	or mexit(mysqli_error($link).N,1);
@@ -127,23 +148,132 @@ while ($row=mysqli_fetch_row($res)) {
 	$resb=mysqli_query($link,'SHOW COLUMNS FROM '.$row[0])
 		or mexit(mysqli_error($link).N,1);
 	$fields=array();
+// lo uso solo per alcuni tipi, quindi non sto a cercare completezza
 	while ($rowb=mysqli_fetch_assoc($resb)) {
-		preg_match('/\((.*)\)/',$rowb['Type'],$buf);
-		$fields[$rowb['Field']]=$buf[1];
+		preg_match('/(\w+)\((.*)\)( unsigned)?/',$rowb['Type'],$buf);
+		switch ($buf[1]) {
+			case 'char':
+			case 'varchar':
+			$fields[$rowb['Field']]=$buf[2];
+			break;
+			case 'tinyint':
+			if (array_key_exists(3,$buf))
+				$fields[$rowb['Field']]=array('min'=>0,'max'=>255);
+			else
+				$fields[$rowb['Field']]=array('min'=>-128,'max'=>127);
+			break;
+			case 'smallint':
+			if (array_key_exists(3,$buf))
+				$fields[$rowb['Field']]=array('min'=>0,'max'=>65535);
+			else
+				$fields[$rowb['Field']]=array('min'=>-32768,'max'=>32767);
+			break;
+			case 'mediumint':
+			if (array_key_exists(3,$buf))
+				$fields[$rowb['Field']]=array('min'=>0,'max'=>16777215);
+			else
+				$fields[$rowb['Field']]=array('min'=>-8388608,'max'=>8388607);
+			break;
+			case 'int':
+			if (array_key_exists(3,$buf))
+				$fields[$rowb['Field']]=array('min'=>0,'max'=>4294967295);
+			else
+				$fields[$rowb['Field']]=array('min'=>-2147483648,'max'=>2147483647);
+			break;
+// bigint non ci sta in php a meno di usare bcmath o gmp che non è detto siano abilitate sul server, in ogni caso poco importa perché valori bigint vengono usati solo internamente al db, non "vengono da fuori"
+			case 'bigint':
+			if (array_key_exists(3,$buf))
+				$fields[$rowb['Field']]=array('min'=>'0','max'=>'18446744073709551615');
+			else
+				$fields[$rowb['Field']]=array('min'=>'-9223372036854775808','max'=>'9223372036854775807');
+			break;
+			case 'decimal':
+// questo è da testare contro un decimale vero
+// fatto, il risultato è che in mysql devo usare decimal(14,4)
+			if (preg_match('/,/',$buf[2])===1) {
+				$lim=explode(',',$buf[2]);
+			} else {
+				$lim[0]=$buf[2];
+				$lim[1]=0;
+			}
+			$int=$lim[0]-$lim[1];
+			$sint='';
+			for ($i=0; $i<$int; $i++)
+				$sint.='9';
+			$sdec='';
+			for ($i=0; $i<$lim[1]; $i++)
+				$sdec.='9';
+			$max=$sint.'.'.$sdec;
+			if (array_key_exists(3,$buf))
+				$fields[$rowb['Field']]=array('min'=>0,'max'=>floatval($max));
+			else
+				$fields[$rowb['Field']]=array('min'=>floatval('-'.$max),'max'=>floatval($max));
+			break;
+			default:
+			$fields[$rowb['Field']]=$rowb['Type'];
+			break;
+		}
 	}
 	$tables[$row[0]]=$fields;
 }
 
-function trunc($str,$tab,$col) {
-	global $tables;
+if ($riprendi) {
+	lecho('Pare che ci sia un lavoro in sospeso, provo a riprenderlo...'.N);
+	$buf=@file($instsjfp,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)
+		or mexit('Non ho potuto aprire in lettura il file «'.$instsjfp.'».'.N,1);
+	$insts=array();
+	foreach ($buf as $line)
+		$insts[]=$line;
+	$buf=@file($currinstjfp,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)
+		or mexit('Non ho potuto aprire in lettura il file «'.$currinstjfp.'».'.N,1);
+	$buf=explode("\t",$buf[0]);
+	$currinst=array('dom'=>$buf[0], 'i'=>$buf[1], 'qok'=>$buf[2], 'qgood'=>$buf[3]);
+	$riprendi=true;
+}
+
+$tronconi=array();
+
+function flushtronc($id) {
+	global $tronconi;
+	foreach ($tronconi as $row) {
+		$row['id']=$id;
+		if ($row['tab']=='Blacklist')
+			$eurl='editblinst.php';
+		elseif ($row['tab']=='Instances')
+			$eurl='editinst.php';
+		elseif ($row['tab']=='Languages')
+			$eurl='editlang.php';
+// questo qui sotto non è errore: la tabella InstTrends non ha ID perciò non è editabile, il massimo che si può fare è andare a vedere la tabella Instances e i trends collegati (l'id che viene passato è infatti quello della tabella Instances)
+		elseif ($row['tab']=='InstTrends')
+			$eurl='editinst.php';
+		notify('Ho dovuto troncare a '.$row['size'].' caratteri il valore da inserire nella colonna «'.$row['col'].'» della tabella «'.$row['tab'].'» perché troppo lungo ('.$row['len'].' caratteri). Puoi <a href="'.$eurl.'?id='.$row['id'].'">editarlo qui</a>.',2);
+	}
+	$tronconi=array();
+}
+
+function truncs($str,$tab,$col) {
+	global $tables, $tronconi;
 	$size=$tables[$tab][$col];
-	if (mb_strlen($str,'UTF-8')>$size) {
+	$len=mb_strlen($str,'UTF-8');
+	if ($len>$size) {
+		$tronconi[]=array('id'=>null,'tab'=>$tab,'col'=>$col,'len'=>$len,'size'=>$size);
 		$str=mb_substr($str,0,$size-1,'UTF-8').'…';
-		notify('Ho dovuto troncare a '.$size.' caratteri il valore da inserire nella colonna «'.$col.'» della tabella «'.$tab.'» perché troppo lungo.',2);
 	}
 	return($str);
 }
 
+function truncn($num,$tab,$col) {
+	global $tables;
+	if ($num>$tables[$tab][$col]['max']) {
+		notify('Ho dovuto troncare «'.$num.'» al valore massimo «'.$tables[$tab][$col]['max'].'» che può avere nella colonna «'.$col.'» della tabella «'.$tab.'»).',2);
+		$num=$tables[$tab][$col]['max'];
+	} elseif ($num<$tables[$tab][$col]['min']) {
+		notify('Ho dovuto troncare «'.$num.'» al valore minimo «'.$tables[$tab][$col]['min'].'» che può avere nella colonna «'.$col.'» della tabella «'.$tab.'»).',2);
+		$num=$tables[$tab][$col]['min'];
+	}
+	return($num);
+}
+
 $contextopts=array(
 	'http'=>array(
 		'timeout'=>$opts['timeout']
@@ -170,7 +300,8 @@ function pgdatetomy($pgdate) {
 			$mtime=$mtime+floatval('0'.$buf[7]);
 		return($mtime);
 	} else {
-		return(false);
+		notify('pgdatetomy: «'.$pgdate.'» non è un formato di data riconosciuto! Ritorno il magico momento attuale.',3);
+		return(time());
 	}
 }
 
@@ -187,71 +318,98 @@ function blpgdumplinetomy($line) {
 	return($row);
 }
 
-$blacklistnew=array();
-$insts=array();
-lecho('Carico le istanze di partenza...'.N);
-$res=mysqli_query($link,'SELECT Domain FROM StartNodes')
-	or mexit(mysqli_error($link).N,3);
-lecho(mysqli_num_rows($res).' istanze di partenza.'.N);
-while($row=mysqli_fetch_assoc($res)) {
-	$insts[$row['Domain']]=null;
-	lecho('Recupero la lista delle istanze note a «'.$row['Domain'].'» ... ');
-	$buf=@file_get_contents('https://'.$row['Domain'].'/api/v1/instance/peers',false,$context);
-	if ($buf!==false) {
-		lecho('OK :-)'.N);
-		$peers=json_decode($buf,true);
-		foreach ($peers as $pdom) {
-			if (!array_key_exists($pdom,$insts) && strlen($pdom)<=64) {
-				$insts[$pdom]=null;
+if (!$riprendi) {
+	$blacklistnew=array();
+	$insts=array();
+	lecho('Carico le istanze di partenza...'.N);
+	$res=mysqli_query($link,'SELECT Domain FROM StartNodes')
+		or mexit(mysqli_error($link).N,3);
+	lecho(mysqli_num_rows($res).' istanze di partenza.'.N);
+	while($row=mysqli_fetch_assoc($res)) {
+		$insts[]=$row['Domain'];
+		lecho('Recupero la lista delle istanze note a «'.$row['Domain'].'» ... ');
+		$buf=@file_get_contents('https://'.$row['Domain'].'/api/v1/instance/peers',false,$context);
+		if ($buf!==false) {
+			lecho('OK :-)'.N);
+			$peers=json_decode($buf,true);
+			foreach ($peers as $pdom) {
+				if (willtrunc($pdom,'Instances','URI'))
+					notify('L’istanza «'.$pdom.'» non sarà considerata perché il suo dominio è troppo lungo per il campo «URI» della tabella «Instances» nel DB',1);
+				if (!in_array($pdom,$insts) && !willtrunc($pdom,'Instances','URI'))
+					$insts[]=$pdom;
 			}
+		} else {
+			lecho('ERRORE :-('.N);
 		}
-	} else {
-		lecho('ERRORE :-('.N);
-	}
-	lecho('Recupero la blacklist di «'.$row['Domain'].'» ... ');
-	$buf=@file_get_contents('https://'.$row['Domain'].'/domain_blocks.txt',false,$context);
-	if ($buf!==false) {
-		lecho('OK :-)'.N);
-		$buf=explode(N,$buf);
-		foreach ($buf as $line) {
-			if (preg_match('/(^#.*$)|(^\s*$)/',$line)===0) {
-				$brow=blpgdumplinetomy($line);
-				if (!array_key_exists($brow['Domain'],$blacklist)) {
-					$blacklistnew[$brow['Domain']]=$brow;
+		lecho('Recupero la blacklist di «'.$row['Domain'].'» ... ');
+		$buf=@file_get_contents('https://'.$row['Domain'].'/domain_blocks.txt',false,$context);
+		if ($buf!==false) {
+			lecho('OK :-)'.N);
+			$buf=explode(N,$buf);
+			foreach ($buf as $line) {
+				if (preg_match('/(^#.*$)|(^\s*$)/',$line)===0) {
+					$brow=blpgdumplinetomy($line);
+					if (!array_key_exists($brow['Domain'],$blacklist)) {
+						$blacklistnew[$brow['Domain']]=$brow;
+					}
+					$blacklist[$brow['Domain']]=$brow;
 				}
-				$blacklist[$brow['Domain']]=$brow;
 			}
+		} else {
+			lecho('ERRORE :-('.N);
 		}
-	} else {
-		lecho('ERRORE :-('.N);
 	}
-}
-//lecho('Carico le istanze note dal DB e aggiungo alla lista di quelle da controllare quelle che non ci sono già.'.N);
-$res=mysqli_query($link,'SELECT URI FROM Instances')
-	or mexit(mysqli_error($link).N,3);
-while($row=mysqli_fetch_assoc($res)) {
-	if (!array_key_exists($row['URI'],$insts))
-		$insts[$row['URI']]=null;
-}
-ksort($insts);
-ksort($blacklist);
-ksort($blacklistnew);
-lecho('Istanze recuperate: '.count($insts).N);
-lecho('Istanze blacklistate: '.count($blacklist).', di cui '.count($blacklistnew).' nuove da aggiungere al DB.'.N);
-
-foreach ($blacklistnew as $row) {
-	foreach($row as $key=>$val)
-		$row[$key]=myesc($link,$val);
-	mysqli_query($link,'INSERT INTO Blacklist (ID, Domain, CreatedAt, ModifiedAt, Severity, RejectMedia, RejectReports, PrivateComment, PublicComment) VALUES (NULL, \''.trunc($row['Domain'],'Blacklist','Domain').'\', \''.$row['CreatedAt'].'\', \''.$row['ModifiedAt'].'\', \''.$row['Severity'].'\', \''.$row['RejectMedia'].'\', \''.$row['RejectReports'].'\', NULL, \''.trunc($row['PublicComment'],'Blacklist','PublicComment').'\')')
+
+	foreach ($blacklistnew as $row) {
+		if (!willtrunc($row['Domain'],'Blacklist','Domain')) {
+			mysqli_query($link,'INSERT INTO Blacklist (ID, Domain, CreatedAt, ModifiedAt, Severity, RejectMedia, RejectReports, PrivateComment, PublicComment) VALUES (NULL, \''.myesc($link,$row['Domain']).'\', \''.myesc($link,$row['CreatedAt']).'\', \''.myesc($link,$row['ModifiedAt']).'\', \''.myesc($link,$row['Severity']).'\', \''.myesc($link,$row['RejectMedia']).'\', \''.myesc($link,$row['RejectReports']).'\', NULL, \''.myesc($link,truncs($row['PublicComment'],'Blacklist','PublicComment')).'\')')
+				or mexit(mysqli_error($link).N,3);
+			flushtronc(mysqli_insert_id($link));
+		} else {
+			notify('Non ho potuto inserire «'.$row['Domain'].'» nella tabella delle istanze blacklistate perché il dominio è troppo lungo.',2);
+		}
+	}
+
+	//lecho('Carico le istanze note dal DB e aggiungo alla lista di quelle da controllare quelle che non ci sono già.'.N);
+	$res=mysqli_query($link,'SELECT URI FROM Instances')
 		or mexit(mysqli_error($link).N,3);
+	while($row=mysqli_fetch_assoc($res)) {
+		if (!in_array($row['URI'],$insts))
+			$insts[]=$row['URI'];
+	}
+	sort($insts);
+	ksort($blacklist);
+	ksort($blacklistnew);
+	lecho('Istanze recuperate: '.count($insts).N);
+	lecho('Istanze blacklistate: '.count($blacklist).', di cui '.count($blacklistnew).' nuove aggiunte al DB.'.N);
+
+	$instsf=@fopen($instsjfp,'w')
+		or mexit('Non ho potuto aprire in scrittura il file «'.$instsjfp.'».'.N,1);
+	foreach ($insts as $dom)
+		fwrite($instsf,$dom.N);
+	fclose($instsf);
 }
 
 
-function b2i($bool) {
-	if ($bool)
-		return(1);
+
+function willtrunc($str,$tab,$col) {
+	global $tables;
+	if (mb_strlen($str,'UTF-8')>$tables[$tab][$col])
+		return(true);
 	else
+		return(false);
+}
+
+function b2i($bool,$pre) {
+	if (is_bool($bool)) {
+		if ($bool)
+			return(1);
+		else
+			return(0);
+	} else {
+		notify($pre.'il valore «'.$bool.'» non è booleano, lo assumo come falso e ritorno «0».',2);
 		return(0);
+	}
 }
 
 //is array, array key exists and value is not null
@@ -269,7 +427,7 @@ function nempty($str) {
 		return($str);
 }
 
-function subarim($glue,$key,&$arr) {
+function subarimp($glue,$key,&$arr) {
 	$str='';
 	$i=1;
 	$carr=count($arr);
@@ -284,11 +442,12 @@ function subarim($glue,$key,&$arr) {
 
 function notify($msg,$sev) {
 	global $link, $tables;
-	mysqli_query($link,'INSERT INTO Notifications (ID, Notification, Severity, Microtime) VALUES (NULL, \''.myesc($link,mb_substr($msg,0,$tables['Notifications']['Notification'],'UTF-8')).'\', '.$sev.', \''.microtime(true).'\')')
+	lecho('NOTIFICAZIÒ: '.strip_tags($msg).N);
+	mysqli_query($link,'INSERT INTO Notifications (ID, Notification, Severity, Microtime, Seen) VALUES (NULL, \''.myesc($link,mb_substr($msg,0,$tables['Notifications']['Notification'],'UTF-8')).'\', '.$sev.', \''.microtime(true).'\', 0)')
 		or mexit(mysqli_error($link).N,3);
 }
 
-function langs($isnewinst,$instid) {
+function langs($instid) {
 	global $info, $instrow, $link;
 	$instlangs=array();
 	if (akeavinn('languages',$info)) {
@@ -297,15 +456,10 @@ function langs($isnewinst,$instid) {
 			$res=mysqli_query($link,'SELECT * FROM Languages WHERE Code=\''.myesc($link,$lang).'\'')
 				or mexit(mysqli_error($link).N,3);
 			if (mysqli_num_rows($res)<1) {
-				mysqli_query($link,'INSERT INTO Languages (ID, Code, Name) VALUES (NULL, \''.myesc($link,trunc($lang,'Languages','Code')).'\', NULL)')
+				mysqli_query($link,'INSERT INTO Languages (ID, Code, ItName, OwnName) VALUES (NULL, \''.myesc($link,truncs($lang,'Languages','Code')).'\', \''.myesc($link,truncs(ucfirst(locale_get_display_name($lang,'it')),'Languages','ItName')).'\', \''.myesc($link,truncs(ucfirst(locale_get_display_name($lang,$lang)),'Languages','OwnName')).'\')')
 					or mexit(mysqli_error($link).N,3);
 				$langid=mysqli_insert_id($link);
-				if ($isnewinst) {
-					$subj='L’inserimento';
-				} else {
-					$subj='L’aggiornamento';
-				}
-				notify($subj.' dei dati relativi all’istanza «<a href="editinst.php?id='.$instid.'">'.$instrow['URI'].'</a>» ha aggiunto un codice lingua non ancora noto, «'.$lang.'», di cui non conosco il nome per esteso. Puoi <a href="editlang.php?id='.$langid.'">editarlo qui</a>.',1);
+				flushtronc($langid);
 			} else {
 				$row=mysqli_fetch_assoc($res);
 				$langid=$row['ID'];
@@ -345,15 +499,28 @@ function mdasortbykey(&$arr,$key,$rev=false) {
 */
 
 if ($opts['jsonwrite']) {
-	$jsonf=@fopen(__DIR__.'/'.$opts['jsonfp'],'w')
-		or mexit('Non ho potuto aprire in scrittura il file di dump delle info json «'.$opts['jsonfp'].'».',1);
-	fwrite($jsonf,'{'.N);
+	if ($riprendi)
+		$mode=array('a','aggiunta');
+	else
+		$mode=array('w','scrittura');
+	$jsonf=@fopen($opts['jsonfp'],$mode[0])
+		or mexit('Non ho potuto aprire in modalità '.$mode[1].' il file di dump delle info json «'.$opts['jsonfp'].'».',1);
+	if ($mode[0]=='w')
+		fwrite($jsonf,'{'.N);
 }
 $cinsts=count($insts);
 $i=0;
 $qok=0;
 $qgood=0;
-foreach ($insts as $dom=>$row) {
+if ($riprendi) {
+	$i=$currinst['i'];
+	$qok=$currinst['qok'];
+	$qgood=$currinst['qgood'];
+}
+while ($i<$cinsts) {
+	$dom=$insts[$i];
+	@file_put_contents($currinstjfp,$dom."\t".$i."\t".$qok."\t".$qgood.N)
+		or mexit('Non ho potuto aprire in scrittura il file «'.$currinstjfp.'».',1);
 	$i++;
 	$ok=true;
 	$info=null;
@@ -370,9 +537,12 @@ foreach ($insts as $dom=>$row) {
 			if ($buf!==false) {
 				lecho('OK :-)'.N);
 				$info['x-nodeinfo']=json_decode($buf,true);
+// per ora teniamo solo quelle che, se si identificano, si identificano come mastodon o corgidon (derivato di mastodon)
+// teniamo d'occhio le notifiche di cui sotto per includere eventualmente altri derivati di mastodon?
+// visti fin qui, verificare cosa sono: epicyon
 				if (is_array($info['x-nodeinfo']) && array_key_exists('software',$info['x-nodeinfo']) && array_key_exists('name',$info['x-nodeinfo']['software']) && preg_match('/^mastodon|corgidon/',$info['x-nodeinfo']['software']['name'])===0) {
 					$ok=false;
-					lecho('Il software «'.$info['x-nodeinfo']['software']['name'].'» non è mastodon o derivati.'.N);
+					notify('Il software «'.$info['x-nodeinfo']['software']['name'].'» non è mastodon o derivati.',1);
 				}
 			} else {
 				lecho('ERRORE :-('.N);
@@ -416,70 +586,72 @@ foreach ($insts as $dom=>$row) {
 				or mexit(mysqli_error($link).N,3,true);
 		}
 	}
-	if ($ok && !is_null($info) && akeavinn('uri',$info) && !is_null(nempty($info['uri'])) && akeavinn('version',$info) && preg_match('/pleroma|pixelfed/i',$info['version'])===0) {
-		$qok++;
-		lecho(json_encode($info,JSON_PRETTY_PRINT).N,true);
+	if (is_array($info) && count($info)>0) {
+		lecho('Dumpone json di tutte le info recuperate:'.N.json_encode($info,JSON_PRETTY_PRINT).N,true);
 		if ($opts['jsonwrite'])
-			fwrite($jsonf,'"'.$info['uri'].'": '.json_encode($info,JSON_PRETTY_PRINT).','.N);
-		$instrow=array('ID'=>null, 'New'=>0, 'Good'=>0, 'Chosen'=>0, 'Visible'=>0, 'BlackListed'=>0, 'URI'=>null, 'Title'=>null, 'ShortDesc'=>null, 'LongDesc'=>null, 'OurDesc'=>null, 'PlaceID'=>null, 'Email'=>null, 'Software'=>null, 'Version'=>null, 'UserCount'=>null, 'StatusCount'=>null, 'DomainCount'=>null, 'ActiveUsersMonth'=>null, 'ActiveUsersHalfYear'=>null, 'Thumb'=>null, 'RegOpen'=>null, 'RegReqApproval'=>null, 'MaxTootChars'=>null, 'AdmAccount'=>null, 'AdmDisplayName'=>null, 'AdmCreatedAt'=>null, 'AdmNote'=>null, 'AdmURL'=>null, 'AdmAvatar'=>null, 'AdmHeader'=>null);
+			fwrite($jsonf,'"'.$dom.'": '.json_encode($info,JSON_PRETTY_PRINT).','.N);
+	}
+	if ($ok && !is_null($info) && akeavinn('uri',$info) && !is_null(nempty($info['uri'])) && !willtrunc($info['uri'],'Instances','URI') && akeavinn('version',$info) && preg_match('/pleroma|pixelfed/i',$info['version'])===0) {
+		$qok++;
+		$instrow=array('ID'=>null, 'New'=>0, 'Good'=>0, 'Chosen'=>0, 'Visible'=>0, 'Blacklisted'=>0, 'URI'=>null, 'Title'=>null, 'ShortDesc'=>null, 'LongDesc'=>null, 'OurDesc'=>null, 'PlaceID'=>null, 'Email'=>null, 'Software'=>null, 'Version'=>null, 'UserCount'=>null, 'StatusCount'=>null, 'DomainCount'=>null, 'ActiveUsersMonth'=>null, 'ActiveUsersHalfYear'=>null, 'Thumb'=>null, 'RegOpen'=>null, 'RegReqApproval'=>null, 'MaxTootChars'=>null, 'AdmAccount'=>null, 'AdmDisplayName'=>null, 'AdmCreatedAt'=>null, 'AdmNote'=>null, 'AdmURL'=>null, 'AdmAvatar'=>null, 'AdmHeader'=>null);
 		if (array_key_exists($info['uri'],$blacklist))
-			$instrow['BlackListed']=1;
-		$instrow['URI']=nempty(trunc($info['uri'],'Instances','URI'));
+			$instrow['Blacklisted']=1;
+		$instrow['URI']=$info['uri'];
 		if (akeavinn('title',$info))
-			$instrow['Title']=nempty(trunc($info['title'],'Instances','Title'));
+			$instrow['Title']=nempty(truncs($info['title'],'Instances','Title'));
 		if (akeavinn('short_description',$info))
-			$instrow['ShortDesc']=nempty(trunc($info['short_description'],'Instances','ShortDesc'));
+			$instrow['ShortDesc']=nempty(truncs($info['short_description'],'Instances','ShortDesc'));
 		if (akeavinn('description',$info))
-			$instrow['LongDesc']=nempty(trunc($info['description'],'Instances','LongDesc'));
+			$instrow['LongDesc']=nempty(truncs($info['description'],'Instances','LongDesc'));
 		if (akeavinn('email',$info))
-			$instrow['Email']=nempty(trunc($info['email'],'Instances','Email'));
+			$instrow['Email']=nempty(truncs($info['email'],'Instances','Email'));
 		if (akeavinn('version',$info))
-			$instrow['Version']=nempty(trunc($info['version'],'Instances','Version'));
+			$instrow['Version']=nempty(truncs($info['version'],'Instances','Version'));
 		if (akeavinn('stats',$info)) {
 			if (akeavinn('user_count',$info['stats']))
-				 $instrow['UserCount']=$info['stats']['user_count'];
+				 $instrow['UserCount']=truncn($info['stats']['user_count'],'Instances','UserCount');
 			if (akeavinn('status_count',$info['stats']))
-				 $instrow['StatusCount']=$info['stats']['status_count'];
+				 $instrow['StatusCount']=truncn($info['stats']['status_count'],'Instances','StatusCount');
 			if (akeavinn('domain_count',$info['stats']))
-				 $instrow['DomainCount']=$info['stats']['domain_count'];
+				 $instrow['DomainCount']=truncn($info['stats']['domain_count'],'Instances','DomainCount');
 		}
 		if (akeavinn('thumbnail',$info))
-			$instrow['Thumb']=nempty(trunc($info['thumbnail'],'Instances','Thumb'));
+			$instrow['Thumb']=nempty(truncs($info['thumbnail'],'Instances','Thumb'));
 		if (akeavinn('max_toot_chars',$info))
-			$instrow['MaxTootChars']=$info['max_toot_chars'];
+			$instrow['MaxTootChars']=truncn($info['max_toot_chars'],'Instances','MaxTootChars');
 		if (akeavinn('registrations',$info))
-			$instrow['RegOpen']=b2i($info['registrations']);
+			$instrow['RegOpen']=b2i($info['registrations'],'Istanza «'.$instrow['URI'].'»: ');
 		if (akeavinn('approval_required',$info))
-			$instrow['RegReqApproval']=b2i($info['approval_required']);
+			$instrow['RegReqApproval']=b2i($info['approval_required'],'Istanza «'.$instrow['URI'].'»: ');
 		if (akeavinn('contact_account',$info)) {
 			if (akeavinn('acct',$info['contact_account']))
-				$instrow['AdmAccount']=nempty(trunc($info['contact_account']['acct'],'Instances','AdmAccount'));
+				$instrow['AdmAccount']=nempty(truncs($info['contact_account']['acct'],'Instances','AdmAccount'));
 			if (akeavinn('display_name',$info['contact_account']))
-				$instrow['AdmDisplayName']=nempty(trunc($info['contact_account']['display_name'],'Instances','AdmAccount'));
+				$instrow['AdmDisplayName']=nempty(truncs($info['contact_account']['display_name'],'Instances','AdmAccount'));
 			if (akeavinn('created_at',$info['contact_account']))
 				$instrow['AdmCreatedAt']=pgdatetomy($info['contact_account']['created_at']);
 			if (akeavinn('note',$info['contact_account']))
-				$instrow['AdmNote']=nempty(trunc(strip_tags($info['contact_account']['note'],'<a>'),'Instances','AdmNote'));
+				$instrow['AdmNote']=nempty(truncs(strip_tags($info['contact_account']['note'],'<a>'),'Instances','AdmNote'));
 			if (akeavinn('url',$info['contact_account']))
-				$instrow['AdmURL']=nempty(trunc($info['contact_account']['url'],'Instances','AdmURL'));
+				$instrow['AdmURL']=nempty(truncs($info['contact_account']['url'],'Instances','AdmURL'));
 			if (akeavinn('avatar',$info['contact_account']))
-				$instrow['AdmAvatar']=nempty(trunc($info['contact_account']['avatar'],'Instances','AdmAvatar'));
+				$instrow['AdmAvatar']=nempty(truncs($info['contact_account']['avatar'],'Instances','AdmAvatar'));
 			if (akeavinn('header',$info['contact_account']))
-				$instrow['AdmHeader']=nempty(trunc($info['contact_account']['header'],'Instances','AdmHeader'));
+				$instrow['AdmHeader']=nempty(truncs($info['contact_account']['header'],'Instances','AdmHeader'));
 		}
 		if (akeavinn('x-nodeinfo',$info)) {
 			if (akeavinn('software',$info['x-nodeinfo']) && akeavinn('name',$info['x-nodeinfo']['software']))
-				$instrow['Software']=nempty(trunc($info['x-nodeinfo']['software']['name'],'Instances','Software'));
+				$instrow['Software']=nempty(truncs($info['x-nodeinfo']['software']['name'],'Instances','Software'));
 			if (akeavinn('usage',$info['x-nodeinfo']) && akeavinn('users',$info['x-nodeinfo']['usage'])) {
 				if (akeavinn('activeMonth',$info['x-nodeinfo']['usage']['users']))
-					$instrow['ActiveUsersMonth']=$info['x-nodeinfo']['usage']['users']['activeMonth'];
+					$instrow['ActiveUsersMonth']=truncn($info['x-nodeinfo']['usage']['users']['activeMonth'],'Instances','ActiveUsersMonth');
 				if (akeavinn('activeHalfyear',$info['x-nodeinfo']['usage']['users']))
-					$instrow['ActiveUsersHalfYear']=$info['x-nodeinfo']['usage']['users']['activeHalfyear'];
+					$instrow['ActiveUsersHalfYear']=truncn($info['x-nodeinfo']['usage']['users']['activeHalfyear'],'Instances','ActiveUsersHalfYear');
 			}
 		}
 
 		$whynot=array();
-		if ($instrow['BlackListed']==1)
+		if ($instrow['Blacklisted']==1)
 			$whynot[]='è nella blacklist';
 		if (is_null($instrow['RegOpen'])) {
 			$whynot[]='non se ne conosce lo stato delle registrazioni (aperte/chiuse)';
@@ -504,8 +676,10 @@ foreach ($insts as $dom=>$row) {
 		}
 		if (count($whynot)==0) {
 			$instrow['Good']=1;
-			lecho('Siamo in presenza di un’istanza BUONA!'.N);
+			lecho('Siamo in presenza di un’istanza BUONA! :-)'.N);
 			$qgood++;
+		} else {
+			lecho('Siamo in presenza di un’istanza CATTIVA: '.implode('; ',$whynot).' :-('.N);
 		}
 
 		$res=mysqli_query($link,'SELECT * FROM Instances WHERE URI=\''.myesc($link,$instrow['URI']).'\'')
@@ -514,6 +688,7 @@ foreach ($insts as $dom=>$row) {
 		if (mysqli_num_rows($res)>0) {
 			lecho('«'.$instrow['URI'].'» è già presente nel DB, la aggiorno...'.N);
 			$oldinstrow=mysqli_fetch_assoc($res);
+			flushtronc($oldinstrow['ID']);
 			$instid=$oldinstrow['ID'];
 			$instrow['ID']=$oldinstrow['ID'];
 			$instrow['New']=$oldinstrow['New'];
@@ -525,9 +700,10 @@ foreach ($insts as $dom=>$row) {
 			$instrow['Chosen']=$oldinstrow['Chosen'];
 			$instrow['Visible']=$oldinstrow['Visible'];
 			if ($instrow['ShortDesc']!=$oldinstrow['ShortDesc'])
-				notify('<p>La «Descrizione breve» dell’istanza «<a href="editinst.php?id='.$instrow['ID'].'">'.$instrow['URI'].'</a>» è cambiata da...</p><div class="valdesc">'.$oldinstrow['ShortDesc'].'</div><p>...a...</p><div class="valdesc">«'.$instrow['ShortDesc'].'</div>',1);
+				notify('<p>La «Descrizione breve» dell’istanza «<a href="editinst.php?id='.$instrow['ID'].'">'.$instrow['URI'].'</a>» è cambiata. La vecchia era...</p><div class="valdesc">'.$oldinstrow['ShortDesc'].'</div><p>La nuova è...</p><div class="valdesc">«'.$instrow['ShortDesc'].'</div>',1);
 			if ($instrow['LongDesc']!=$oldinstrow['LongDesc'])
-				notify('<p>La «Descrizione lunga» dell’istanza «<a href="editinst.php?id='.$instrow['ID'].'">'.$instrow['URI'].'</a>» è cambiata da...</p><div class="valdesc">'.$oldinstrow['LongDesc'].'</div><p>...a...</p><div class="valdesc">«'.$instrow['LongDesc'].'</div>',1);
+				notify('<p>La «Descrizione lunga» dell’istanza «<a href="editinst.php?id='.$instrow['ID'].'">'.$instrow['URI'].'</a>» è cambiata. La vecchia era...</p><div class="valdesc">'.$oldinstrow['LongDesc'].'</div><p>La nuove è...</p><div class="valdesc">«'.$instrow['LongDesc'].'</div>',1);
+			$instrow['OurDesc']=$oldinstrow['OurDesc'];
 			$instrow['PlaceID']=$oldinstrow['PlaceID'];
 			$query='UPDATE Instances SET ';
 			foreach ($instrow as $field=>$value) {
@@ -546,9 +722,9 @@ foreach ($insts as $dom=>$row) {
 			$oldinstlangs=array();
 			while ($row=mysqli_fetch_assoc($res))
 				$oldinstlangs[]=$row;
-			$instlangs=langs(false,$instrow['ID']);
+			$instlangs=langs($instrow['ID']);
 			if ($instlangs!=$oldinstlangs) {
-				notify('La lista delle lingue utilizzate dichiarate dall’istanza «<a href="editinst.php?id='.$instrow['ID'].'">'.$instrow['URI'].'</a>» è cambiata da «'.subarim(', ','Code',$oldinstlangs).'» a «'.subarim(', ','Code',$instlangs).'».',1);
+				notify('La lista delle lingue utilizzate dichiarate dall’istanza «<a href="editinst.php?id='.$instrow['ID'].'">'.$instrow['URI'].'</a>» è cambiata da «'.subarimp(', ','Code',$oldinstlangs).'» a «'.subarimp(', ','Code',$instlangs).'».',1);
 				mysqli_query($link,'DELETE FROM InstLangs WHERE InstID='.$instrow['ID'])
 					or mexit(mysqli_error($link).N,3,true);
 				foreach ($instlangs as $row) {
@@ -575,11 +751,17 @@ foreach ($insts as $dom=>$row) {
 				or mexit(mysqli_error($link).N,3,true);
 			$instid=mysqli_insert_id($link);
 
-			$instlangs=langs(false,$instid);
+			flushtronc($instid);
+
+			$instlangs=langs($instid);
 			foreach ($instlangs as $row) {
 				mysqli_query($link,'INSERT INTO InstLangs (InstID, LangID, Pos) VALUES ('.$row['InstID'].', '.$row['LangID'].', '.$row['Pos'].')')
 					or mexit(mysqli_error($link).N,3,true);
 			}
+
+			if ($instrow['Good']==1)
+				notify('La nuova istanza «<a href="editinst.php?id=">'.$info['uri'].'</a>» è papabile!',1);
+
 		}
 
 		if (array_key_exists('x-activity',$info) && is_array($info['x-activity'])) {
@@ -594,7 +776,6 @@ foreach ($insts as $dom=>$row) {
 		}
 
 		if (array_key_exists('x-trends',$info) && is_array($info['x-trends'])) {
-			mysqli_query($link,'DELETE FROM InstTrends WHERE InstID='.$instid);
 			$trends=array();
 			foreach ($info['x-trends'] as $buf) {
 				if (akeavinn('name',$buf) && akeavinn('url',$buf) && akeavinn('history',$buf) && is_array($buf['history'])) {
@@ -606,8 +787,8 @@ foreach ($insts as $dom=>$row) {
 					$trends[]=array(
 						'InstID'=>$instid,
 						'LastDay'=>$buf['history'][0]['day'],
-						'Name'=>myesc($link,trunc($buf['name'],'InstTrends','Name')),
-						'URL'=>myesc($link,trunc($buf['url'],'InstTrends','URL')),
+						'Name'=>$buf['name'],
+						'URL'=>$buf['url'],
 						'Pos'=>null,
 						'trend'=>$trend
 					);
@@ -615,12 +796,15 @@ foreach ($insts as $dom=>$row) {
 			}
 			mdasortbykey($trends,'trend',true);
 //			print_r($trends);
+			mysqli_query($link,'DELETE FROM InstTrends WHERE InstID='.$instid);
 			$pos=0;
 			foreach ($trends as $trend) {
 				$pos++;
-				$query='INSERT INTO InstTrends (InstID, LastDay, Name, URL, Pos) VALUES ('.$instid.', \''.myesc($link,$trend['LastDay']).'\', \''.myesc($link,trunc($trend['Name'],'InstTrends','Name')).'\', \''.myesc($link,trunc($trend['URL'],'InstTrends','URL')).'\', '.$pos.')';
+				$query='INSERT INTO InstTrends (InstID, LastDay, Name, URL, Pos) VALUES ('.$trend['InstID'].', \''.$trend['LastDay'].'\', \''.myesc($link,truncs($trend['Name'],'InstTrends','Name')).'\', \''.myesc($link,truncs($trend['URL'],'InstTrends','URL')).'\', '.$pos.')';
 				mysqli_query($link,$query)
 					or mexit(mysqli_error($link).N,3,true);
+// questo qui sotto non è errore, vedi il commento relativo nella funzione
+				flushtronc($instid);
 			}
 
 		}
@@ -638,8 +822,9 @@ if ($opts['jsonwrite']) {
 	fclose($jsonf);
 }
 
-if ($opts['log'])
-	fclose($logf);
+unlink($instsjfp);
+
+unlink($currinstjfp);
 
 exit(0);
 

+ 42 - 34
web/admin/zzz-materiali/mastostart.sql

@@ -3,7 +3,7 @@
 -- https://www.phpmyadmin.net/
 --
 -- Host: localhost
--- Creato il: Dic 28, 2019 alle 22:23
+-- Creato il: Dic 30, 2019 alle 22:24
 -- Versione del server: 10.4.11-MariaDB
 -- Versione PHP: 7.4.1
 
@@ -35,13 +35,6 @@ CREATE TABLE `Admins` (
   `Password` varchar(256) COLLATE utf8mb4_unicode_ci NOT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
---
--- Dump dei dati per la tabella `Admins`
---
-
-INSERT INTO `Admins` (`ID`, `Username`, `Email`, `Password`) VALUES
-(1, 'pongrebio', 'pezcurrel@tiscali.it', '$2y$10$F8Q5pRwBIeZMkbf7COBYHe0HuO1EfPxegt7KPJsbCcPLZJpjXaeVO');
-
 -- --------------------------------------------------------
 
 --
@@ -50,14 +43,14 @@ INSERT INTO `Admins` (`ID`, `Username`, `Email`, `Password`) VALUES
 
 CREATE TABLE `Blacklist` (
   `ID` int(10) UNSIGNED NOT NULL,
-  `Domain` varchar(1024) COLLATE utf8mb4_unicode_ci NOT NULL,
-  `CreatedAt` decimal(18,6) UNSIGNED NOT NULL,
-  `ModifiedAt` decimal(18,6) UNSIGNED NOT NULL,
+  `Domain` varchar(2048) COLLATE utf8mb4_unicode_ci NOT NULL,
+  `CreatedAt` decimal(14,4) UNSIGNED NOT NULL,
+  `ModifiedAt` decimal(14,4) UNSIGNED NOT NULL,
   `Severity` tinyint(3) UNSIGNED NOT NULL,
   `RejectMedia` tinyint(1) UNSIGNED NOT NULL,
   `RejectReports` tinyint(1) UNSIGNED NOT NULL,
-  `PrivateComment` varchar(2048) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
-  `PublicComment` varchar(2048) COLLATE utf8mb4_unicode_ci DEFAULT NULL
+  `PrivateComment` varchar(4096) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+  `PublicComment` varchar(4096) COLLATE utf8mb4_unicode_ci DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
 -- --------------------------------------------------------
@@ -98,11 +91,11 @@ CREATE TABLE `Instances` (
   `Good` tinyint(1) UNSIGNED NOT NULL,
   `Chosen` tinyint(1) UNSIGNED NOT NULL,
   `Visible` tinyint(1) UNSIGNED NOT NULL,
-  `BlackListed` tinyint(1) UNSIGNED NOT NULL,
+  `Blacklisted` tinyint(1) UNSIGNED NOT NULL,
   `URI` varchar(512) COLLATE utf8mb4_unicode_ci NOT NULL,
   `Title` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
-  `ShortDesc` varchar(2048) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
-  `LongDesc` varchar(4096) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+  `ShortDesc` varchar(4096) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+  `LongDesc` varchar(5120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
   `OurDesc` varchar(2048) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
   `PlaceID` int(10) UNSIGNED DEFAULT NULL,
   `Email` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
@@ -119,8 +112,8 @@ CREATE TABLE `Instances` (
   `MaxTootChars` mediumint(8) UNSIGNED DEFAULT NULL,
   `AdmAccount` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
   `AdmDisplayName` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
-  `AdmCreatedAt` decimal(18,6) DEFAULT NULL,
-  `AdmNote` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+  `AdmCreatedAt` decimal(14,4) UNSIGNED DEFAULT NULL,
+  `AdmNote` varchar(2048) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
   `AdmURL` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
   `AdmAvatar` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
   `AdmHeader` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL
@@ -165,6 +158,19 @@ CREATE TABLE `InstLangs` (
 -- --------------------------------------------------------
 
 --
+-- Struttura della tabella `InstOurLangs`
+--
+
+CREATE TABLE `InstOurLangs` (
+  `ID` bigint(20) UNSIGNED NOT NULL,
+  `InstID` bigint(20) UNSIGNED NOT NULL,
+  `LangID` int(10) UNSIGNED NOT NULL,
+  `Pos` tinyint(3) UNSIGNED NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+-- --------------------------------------------------------
+
+--
 -- Struttura della tabella `InstPolicies`
 --
 
@@ -209,7 +215,8 @@ CREATE TABLE `InstTrends` (
 CREATE TABLE `Languages` (
   `ID` int(11) UNSIGNED NOT NULL,
   `Code` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
-  `Name` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL
+  `ItName` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+  `OwnName` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
 -- --------------------------------------------------------
@@ -222,7 +229,8 @@ CREATE TABLE `Notifications` (
   `ID` bigint(20) UNSIGNED NOT NULL,
   `Notification` varchar(15000) COLLATE utf8mb4_unicode_ci NOT NULL,
   `Severity` tinyint(3) UNSIGNED NOT NULL,
-  `Microtime` decimal(18,6) UNSIGNED NOT NULL
+  `Microtime` decimal(14,4) UNSIGNED NOT NULL,
+  `Seen` tinyint(1) UNSIGNED NOT NULL DEFAULT 0
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
 -- --------------------------------------------------------
@@ -261,18 +269,6 @@ CREATE TABLE `StartNodes` (
   `Domain` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
---
--- Dump dei dati per la tabella `StartNodes`
---
-
-INSERT INTO `StartNodes` (`ID`, `Domain`) VALUES
-(1, 'mastodon.bida.im'),
-(2, 'mastodon.cisti.org'),
-(3, 'nebbia.fail'),
-(4, 'stereodon.social'),
-(5, 'snapj.saja.freemyip.com'),
-(6, 'pantagruel.dnsup.net');
-
 -- --------------------------------------------------------
 
 --
@@ -324,6 +320,12 @@ ALTER TABLE `Instances`
   ADD PRIMARY KEY (`ID`);
 
 --
+-- Indici per le tabelle `InstOurLangs`
+--
+ALTER TABLE `InstOurLangs`
+  ADD PRIMARY KEY (`ID`);
+
+--
 -- Indici per le tabelle `Languages`
 --
 ALTER TABLE `Languages`
@@ -373,7 +375,7 @@ ALTER TABLE `Whitelist`
 -- AUTO_INCREMENT per la tabella `Admins`
 --
 ALTER TABLE `Admins`
-  MODIFY `ID` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
+  MODIFY `ID` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
 
 --
 -- AUTO_INCREMENT per la tabella `Blacklist`
@@ -394,6 +396,12 @@ ALTER TABLE `Instances`
   MODIFY `ID` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
 
 --
+-- AUTO_INCREMENT per la tabella `InstOurLangs`
+--
+ALTER TABLE `InstOurLangs`
+  MODIFY `ID` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
+
+--
 -- AUTO_INCREMENT per la tabella `Languages`
 --
 ALTER TABLE `Languages`
@@ -421,7 +429,7 @@ ALTER TABLE `Policies`
 -- AUTO_INCREMENT per la tabella `StartNodes`
 --
 ALTER TABLE `StartNodes`
-  MODIFY `ID` smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
+  MODIFY `ID` smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT;
 
 --
 -- AUTO_INCREMENT per la tabella `Tags`