Snippets

Leslie Krause Auth Redux Database Import Script

Updated by Leslie Krause

File convert.awk Modified

  • Ignore whitespace
  • Hide word diff
 }
 
 END {
-	print "Done! " checked " of " ( checked + skipped ) " total records were imported to " output_file " (" skipped " records skipped)."
+	print "Done! " checked " of " ( checked + skipped ) " total records were imported to " db_file " (" skipped " records skipped)."
 }
Updated by Leslie Krause

File convert.awk Modified

  • Ignore whitespace
  • Hide word diff
 # required by the Auth Redux Mod. The output file will be generated in the same 
 # world directory as the original 'auth.txt' file (which will be unchanged).
 #
+# Setting the mode to 'install' will automatically install the required journal
+# and ruleset files into the world directory as well.
+#
 # EXAMPLE:
-# awk -f convert.awk ~/.minetest/worlds/world/auth.txt
+# awk -f convert.awk -v mode=convert ~/.minetest/worlds/world/auth.txt
 ################################################################################
 
 function error( msg ) {
 	skipped++;
-	print msg " at line " NR " in " FILENAME ". Skipping.";
+	print msg " at line " NR " in " FILENAME ".";
 }
 
 BEGIN {
 	checked = 0;
 	skipped = 0;
 
+	db_file = "auth.db";
+	journal_file = "auth.dbx";
+	ruleset_file = "greenlist.mt";
+
 	# determine output file name from arguments
 
-	output_file = ARGV[ 1 ]
-	if( sub( /[-_A-Za-z0-9]+\.txt$/, "auth.db", output_file ) == 0 ) {
+	path = ARGV[ 1 ]
+	if( sub( /[-_A-Za-z0-9]+\.txt$/, "", path ) == 0 ) {
 		# sanity check for nonstandard input file
-		output_file = "auth.db";
+		path = "";
+	}
+
+	# install required journal and ruleset files
+
+	if( mode == "install" ) {
+		print "Installing the required journal and ruleset files...";
+		print "" > path journal_file
+		print "pass now" > path ruleset_file
+	}		
+	else if( mode != "convert" ) {
+		print "Unknown argument, defaulting to convert mode.";
 	}
-	print "Converting " ARGV[ 1 ] "...";
 
 	# set default values for new database fields
 
 
 	# print database headline to the output file
 
-	print "auth_rx/2.1 @0" > output_file;
+	print "Converting " ARGV[ 1 ] "...";
+	print "auth_rx/2.1 @0" > path db_file;
 }
 
 NF != 4 {
 	# approved_addrs
 	# assigned_privs
 
-	print username, password, oldlogin, newlogin, lifetime, total_sessions, total_attempts, total_failures, approved_addrs, assigned_privs > output_file;
+	print username, password, oldlogin, newlogin, lifetime, total_sessions, total_attempts, total_failures, approved_addrs, assigned_privs > path db_file;
 
 	checked++;
 }
 
 END {
-	print "Done! " checked " records were imported to " output_file " (" skipped " records skipped)."
+	print "Done! " checked " of " ( checked + skipped ) " total records were imported to " output_file " (" skipped " records skipped)."
 }
Updated by Leslie Krause

File convert.awk Modified

  • Ignore whitespace
  • Hide word diff
 #!/bin/awk -f
-# Database Import Script for Auth Redux (by Leslie Krause)
+
+################################################################################
+# Database Import Script for Auth Redux Mod
+# ------------------------------------------
+# This script will convert the specified 'auth.txt' file into a database format 
+# required by the Auth Redux Mod. The output file will be generated in the same 
+# world directory as the original 'auth.txt' file (which will be unchanged).
 #
-# STEP 1: Run this script from within the world directory and redirect output to "auth.db"
-# awk -f auth.txt > auth.db
-# STEP 2: Rename 'auth.txt' to 'auth.bak' or move to a different location for safekeeping
+# EXAMPLE:
+# awk -f convert.awk ~/.minetest/worlds/world/auth.txt
+################################################################################
 
 function error( msg ) {
-	print( msg " at line " NR " in " FILENAME "." ) > "/dev/stderr"
+	skipped++;
+	print msg " at line " NR " in " FILENAME ". Skipping.";
 }
 
 BEGIN {
 	FS = ":";
+	OFS = ":";
+	checked = 0;
+	skipped = 0;
+
+	# determine output file name from arguments
+
+	output_file = ARGV[ 1 ]
+	if( sub( /[-_A-Za-z0-9]+\.txt$/, "auth.db", output_file ) == 0 ) {
+		# sanity check for nonstandard input file
+		output_file = "auth.db";
+	}
+	print "Converting " ARGV[ 1 ] "...";
 
 	# set default values for new database fields
 
 	total_attempts = 0;
 	total_sessions = 0;
 
-	# output the database header
-	# TODO: perhaps add? strftime( "%Y-%m-%d %H:%M:%S" )
+	# print database headline to the output file
 
-	print "auth_rx/2.1 @0"
+	print "auth_rx/2.1 @0" > output_file;
 }
 
 NF != 4 {
-	error( "Malformed record" )
-	next
+	error( "Malformed record" );
+	next;
 }
 
 {
 	newlogin = $4;
 
 	if( !match( username, "^[a-zA-Z0-9_-]+$" ) ) {
-		error( "Invalid username field" )
-		next
+		error( "Invalid username field" );
+		next;
 	}
 	if( !match( newlogin, "^[0-9]+$" ) && newlogin != -1 ) {
-		error( "Invalid last_login field" )
-		next
+		error( "Invalid last_login field" );
+		next;
 	}
 
 	# Database File Format
 	# approved_addrs
 	# assigned_privs
 
-	print( username ":" password ":" oldlogin ":" newlogin ":" lifetime ":" total_sessions ":" total_attempts ":" total_failures ":" approved_addrs ":" assigned_privs );
+	print username, password, oldlogin, newlogin, lifetime, total_sessions, total_attempts, total_failures, approved_addrs, assigned_privs > output_file;
+
+	checked++;
+}
+
+END {
+	print "Done! " checked " records were imported to " output_file " (" skipped " records skipped)."
 }
Created by Leslie Krause

File convert.awk Added

  • Ignore whitespace
  • Hide word diff
+#!/bin/awk -f
+# Database Import Script for Auth Redux (by Leslie Krause)
+#
+# STEP 1: Run this script from within the world directory and redirect output to "auth.db"
+# awk -f auth.txt > auth.db
+# STEP 2: Rename 'auth.txt' to 'auth.bak' or move to a different location for safekeeping
+
+function error( msg ) {
+	print( msg " at line " NR " in " FILENAME "." ) > "/dev/stderr"
+}
+
+BEGIN {
+	FS = ":";
+
+	# set default values for new database fields
+
+	approved_addrs = "";
+	oldlogin = -1;
+	lifetime = 0;
+	total_failures = 0;
+	total_attempts = 0;
+	total_sessions = 0;
+
+	# output the database header
+	# TODO: perhaps add? strftime( "%Y-%m-%d %H:%M:%S" )
+
+	print "auth_rx/2.1 @0"
+}
+
+NF != 4 {
+	error( "Malformed record" )
+	next
+}
+
+{
+	username = $1;
+	password = $2;
+	assigned_privs = $3;
+	newlogin = $4;
+
+	if( !match( username, "^[a-zA-Z0-9_-]+$" ) ) {
+		error( "Invalid username field" )
+		next
+	}
+	if( !match( newlogin, "^[0-9]+$" ) && newlogin != -1 ) {
+		error( "Invalid last_login field" )
+		next
+	}
+
+	# Database File Format
+	# --------------------
+	# username
+	# password
+	# oldlogin
+	# newlogin
+	# lifetime
+	# total_sessions
+	# total_attempts
+	# total_failures
+	# approved_addrs
+	# assigned_privs
+
+	print( username ":" password ":" oldlogin ":" newlogin ":" lifetime ":" total_sessions ":" total_attempts ":" total_failures ":" approved_addrs ":" assigned_privs );
+}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.