Separate the two types of access into different files, and do away with the '@' prefi...
authorpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Wed, 29 Aug 2007 21:36:06 +0000 (21:36 +0000)
committerpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Wed, 29 Aug 2007 21:36:06 +0000 (21:36 +0000)
git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@5 088b83a4-0077-4247-935c-42ec02c2848b

commands.yaml
core.pl

index 4a3e244..0364d0c 100644 (file)
@@ -9,18 +9,18 @@ LINK: |-
     my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
     my( $whom, $target ) = split( / /, $what, 2 );
 
-    unless( exists( $heap->{ 'access' }->{ uc( $target ) } ) ) {
+    unless( exists( $heap->{ 'useraccess' }->{ uc( $target ) } ) ) {
       $kernel->post( $src, $replypath, "'$target' has no access; link not allowed.", $dest );
       return;
     }
 
-    if( access2( $heap->{ 'access' }, $target, {} ) > accessLevel( $kernel, $heap, $who ) ) {
+    if( access2( $heap->{ 'useraccess' }, $target, {} ) > accessLevel( $kernel, $heap, $who ) ) {
       $kernel->post( $src, $replypath, "You may not grant access exceeding your own.", $dest );
       return;
     }
     if( exists( $heap->{ 'privs' }->{ uc( $whom ) } ) ) {
-       $heap->{ 'access' }->{ uc( $whom ) } = "~".$target;
-        DumpFile( "access.yaml", $heap->{ 'access' } );
+       $heap->{ 'useraccess' }->{ uc( $whom ) } = "~".$target;
+        DumpFile( "useraccess.yaml", $heap->{ 'useraccess' } );
         $kernel->post( $src, $replypath, "Set.", $dest );
     } else {
        $kernel->post( $src, $replypath, "'$whom' not registered.", $dest );
@@ -35,13 +35,13 @@ ACCESS: |-
        $kernel->post( $src, $replypath, "Access level should be a non-negative integer. (Did you want LINK?)", $dest );
        return;
     }
-    if( $level > access2( $heap->{ 'access' }, $who, {} ) ) {
+    if( $level > access2( $heap->{ 'useraccess' }, $who, {} ) ) {
        $kernel->post( $src, $replypath, "You may not grant access exceeding your own.", $dest );
        return;
     }
     if( exists( $heap->{ 'privs' }->{ uc( $whom ) } ) ) {
-       $heap->{ 'access' }->{ uc( $whom ) } = $level;
-        DumpFile( "access.yaml", $heap->{ 'access' } );
+       $heap->{ 'useraccess' }->{ uc( $whom ) } = $level;
+        DumpFile( "useraccess.yaml", $heap->{ 'useraccess' } );
         $kernel->post( $src, $replypath, "Set.", $dest );
     } else {
        $kernel->post( $src, $replypath, "'$whom' not registered.", $dest );
@@ -57,8 +57,8 @@ CLASSIFY: |-
        return;
     }
     if( exists( $heap->{ 'commands' }->{ uc( $cmd ) } ) ) {
-       $heap->{ 'access' }->{ "@".uc( $cmd ) } = $level;
-        DumpFile( "access.yaml", $heap->{ 'access' } );
+       $heap->{ 'cmdaccess' }->{ uc( $cmd ) } = $level;
+        DumpFile( "cmdaccess.yaml", $heap->{ 'cmdaccess' } );
         $kernel->post( $src, $replypath, "Set.", $dest );
     } else {
        $kernel->post( $src, $replypath, "'$cmd' not found.", $dest );
@@ -69,16 +69,12 @@ ACCESSLIST: |-
   sub {
     my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
     $kernel->post( $src, $replypath, "Commands:", $dest );
-    foreach( keys( %{ $heap->{ 'access' } } ) ) {
-      if( substr( $_, 0, 1 ) eq "@" ) {
-        $kernel->post( $src, $replypath, "    $_: ".$heap->{ 'access' }->{ $_ }, $dest );
-      }
+    foreach( keys( %{ $heap->{ 'cmdaccess' } } ) ) {
+      $kernel->post( $src, $replypath, "    $_: ".$heap->{ 'cmdaccess' }->{ $_ }, $dest );
     }
     $kernel->post( $src, $replypath, "Users:", $dest );
-    foreach( keys( %{ $heap->{ 'access' } } ) ) {
-      unless( substr( $_, 0, 1 ) eq "@" ) {
-        $kernel->post( $src, $replypath, "    $_: ".$heap->{ 'access' }->{ $_ }, $dest );
-      }
+    foreach( keys( %{ $heap->{ 'useraccess' } } ) ) {
+      $kernel->post( $src, $replypath, "    $_: ".$heap->{ 'useraccess' }->{ $_ }, $dest );
     }
   }
 
@@ -165,7 +161,28 @@ REGISTER: |-
   sub {
     use Digest::MD5 qw( md5_hex );
     my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
-    my( $whom, $password ) = split( / /, $what, 2 );
+    print( STDERR "register( '$what' )\n" );
+    my $nargs = ($what =~ s/ / /g);
+    if( !$nargs ) {
+       $nargs = 1;
+    } else {
+       $nargs++;
+    }
+    if( $nargs < 1 || $nargs > 2 ) {
+      $kernel->post( $src, $replypath, "Usage: REGISTER [<name>] <password>", $dest );
+      return;
+    }
+
+    my( $whom, $password );
+    if( $nargs == 1 ) {
+      $password = $what;
+      $whom = $who;
+    }
+    if( $nargs == 2 ) {
+      ( $whom, $password ) = split( / /, $what, 2 );
+    }
+
+    print( STDERR "register( $whom, $password ) == $nargs\n" );
     
     if( $password ) {
       $heap->{ 'privs' }->{ uc( $whom ) } = md5_hex( $password );
diff --git a/core.pl b/core.pl
index a5cc58d..3c7a254 100644 (file)
--- a/core.pl
+++ b/core.pl
@@ -65,11 +65,11 @@ sub on_start {
                print( "CORE: No factoids found.\n" );
        }
 
-       if( -e "access.yaml" ) {
-               $heap->{ 'access' } = \%{ LoadFile( "access.yaml" ) };
+       if( -e "cmdaccess.yaml" ) {
+               $heap->{ 'cmdaccess' } = \%{ LoadFile( "cmdaccess.yaml" ) };
                print( "CORE: Access levels loaded.\n" );
        } else {
-               $heap->{ 'access' } = { };
+               $heap->{ 'cmdaccess' } = { };
        }
 
        if( -e "privs.yaml" ) {
@@ -80,6 +80,14 @@ sub on_start {
                print( "CORE: No users found.\n" );
        }
        
+       if( -e "useraccess.yaml" ) {
+               $heap->{ 'useraccess' } = \%{ LoadFile( "useraccess.yaml" ) };
+               print( "CORE: User access loaded.\n" );
+       } else {
+               $heap->{ 'useraccess' } = { };
+               print( "CORE: No user access found.\n" );
+       }
+       
        if( -e "ignored.yaml" ) {
                $heap->{ 'ignored' } = \%{ LoadFile( "ignored.yaml" ) };
                print( "CORE: Ignored users loaded.\n" );
@@ -125,13 +133,13 @@ sub cmd {
        }
 
        if( exists( $heap->{ 'commands' }->{ uc( $cmd ) } ) ) {
-               if( !exists $heap->{ 'access' }->{ "@".uc( $cmd ) } || 
-                       $heap->{ 'access' }->{ "@".uc( $cmd ) } == 0 || (
+               if( !exists $heap->{ 'cmdaccess' }->{ uc( $cmd ) } || 
+                       $heap->{ 'cmdaccess' }->{ uc( $cmd ) } == 0 || (
                        exists $heap->{ 'identified' }->{ $src.uc( $who ) } &&
-                       accessLevel( $kernel, $heap, uc( $who ), $src ) >= $heap->{ 'access' }->{ "@".uc( $cmd ) } ) ) {
+                       accessLevel( $kernel, $heap, uc( $who ), $src ) >= $heap->{ 'cmdaccess' }->{ uc( $cmd ) } ) ) {
                        &{ $heap->{ 'commands' }->{ uc( $cmd ) } }( $kernel, $heap, $who, $subj, $src, $dest, $replypath );
                } else {
-                       $kernel->post( $src, $replypath, "$who: An access level of ".$heap->{ 'access' }->{ "@".uc( $cmd ) }." is required for '$cmd'", $dest );
+                       $kernel->post( $src, $replypath, "$who: An access level of ".$heap->{ 'cmdaccess' }->{ uc( $cmd ) }." is required for '$cmd'", $dest );
                }
        } elsif( exists( $heap->{ 'db' }->{ uc( $what ) } ) && !$noparse ) {
                &{ $heap->{ 'commands' }->{ 'PARSE' } }( $kernel, $heap, $who, $what, $src, $dest, $replypath );
@@ -146,7 +154,7 @@ sub accessLevel {
                print( "ACC: $whom isn't idenfitied.\n" );
                return 0;
        }
-       return access2( $heap->{ 'access' }, $whom, {} );
+       return access2( $heap->{ 'useraccess' }, $whom, {} );
 }
 
 # Put this in two parts so we don't get infinite loops.