This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
KillaVanilla's profile picture

[1.3+?] Rednet Database Server - Now Supports Guest Access!

Started by KillaVanilla, 20 October 2012 - 01:13 AM
KillaVanilla #1
Posted 20 October 2012 - 03:13 AM
Hello all.

This program can store files in a "database", with a set of commands. However, there is a major difference between your typical "FTP" server and this: Each "commit", or file change, is logged and can be undone/rolled back. This server also supports authentication, so only trusted users can modify your database.
All commands are sent to the server in the form of a table, like so:

{sCommand, vParameter1, vParameter2, ...}

Commands:
  • "login" - Allows a client to modify the database, provided a correct username/password combination is provided. Only parameters needed are the username/password combination.
  • "logout" - Prevents a client from modifying the database until he/she logs back in. This requires no parameters.
  • "commit" - Sends a file to the server for storage. These are logged and can be undone. Parameters are the file's name, the data to store on the file, and an optional commit message.
  • "delete" - Deletes a file from the server. Can be undone. Parameters are the file's name.
  • "undo" or "revert" - Rolls back changes to a specific commit ID (see below). Parameters are the file's name and the commit ID to revert to.
  • "list_commits" - Sends a list of commits and associated changes for a file to the client. The only parameter needed is the file's name.
  • "read" - Retrieves a file from the database. The only parameter needed is the file's name.
  • "list" - Retrieves a list of files in the current branch.
  • "switch" - Switches to another branch (that doesn't need to exist). Only parameter needed is the branch name.
  • "clone_branch" or "copy_branch" - Copies the current branch's to form a new branch, which must not exist. Only parameter needed is the new branch's name.
  • "pastebin_get" - Downloads a file from Pastebin. Parameters needed are the paste's code, and the filename.
  • "github_get" - Downloads a file from Github. Parameters needed are the file to download to, the owner of the repository, the repository's name, the branch to download from (usually "master"), and the file's name in the repository.
How To Set Up:
  1. Download the server. Ensure that the HTTP API is enabled.
  2. Run the server software, but immediately terminate it as soon as it reports that it has "Found ARC4 Cipher".
  3. You should see a few new folders and a new file named "newUser".
  4. Run newUser like so: "newUser <user_name> <password>" for everyone who can access the database.
  5. Run "dbServ".
How to use the Client:
First, keep these things in mind:
  • Any files you download will be placed in the current directory.
  • You need to run the database software like this:
    
    db <server> <action> <parameters>
    
  • You may need to log in multiple times, because the server software automatically logs you out after 15 minutes.
  • All actions are performed in the current branch.
  • If the server has guest read-only access enabled, then you don't need to log in to use "list" and "read".
Now, to log in to a server, do this:

db <server> login <username> <password>

To list files in your current branch, do this:

db <server> list

To send files to the server, do this:

db <server> sendfile <path/to/local/file> <name of file on the server> <commit_message>

To just put raw data into a file on the server, do this:

db <server> commit <file> <data> <commit_message>

To revert to a commit:

db <server> undo <file> <commitID>

To get files from the server, run this:

db <server> read <file>

Deleting files is done similarly:

db <server> delete <file>

To move or copy files, do this:

db <server> <move/copy> <name_of_file> <name_of_new_file>

To list the commits for a particular file, do this:

db <server> list_commits <file>

To switch branches, do this:

db <server> switch <name_of_branch>

The target branch doesn't need to exist.
If you want to copy an entire branch, do this:

db <server> clone_branch <new_branch_name>
This clones the current branch.

To get the data for a commit, do:

db <server> get_commit <file> <commitID>

To make the server download a file from Pastebin, do:

db <server> pastebin_get <pastebin_code> <name_of_file> <commit_message>

To make the server download a file from Github, do:

db <server> github_get <name_of_file> <user> <repository> <branch> <file> <commit_message>

An example user might do this:

db 20 login admin adad2sx2
db 20 sendFile dev/my_awesome_program my_awesome_program
db 20 read my_other_program
db 20 logout

The user above:
  1. Logged in
  2. Sent a file to the server
  3. Downloaded a file from the server
  4. Logged out



Guest Access
If you run "dbServ" with the option "-guest_read" then the "list" and "read" functions become available without requiring the user to log in.
Guests are only allowed to get files from the "master" branch, however.

Guest Access Mode:

dbServ -guest_read


You can get it here, from pastebin: Rednet Database Server
Or you can download it from in-game by running this:

pastebin get t1StZK2k dbServ

The client can be found here: Database Server Client
Or download it from in-game by running this:

pastebin get 48aP8hfF db_client

If the HTTP API is disabled, than all passwords will be stored on the password in cleartext, but the server will attempt to use the RC4 cipher (automatically downloaded) whenever possible, which may cause problems. This is easily fixed though, only requiring that the person running the database add the users again.

Also, I'm looking for someone to make an actual UI for the client. If you'd like to (or already have one), please PM me.</password></user_name>
ChunLing #2
Posted 20 October 2012 - 03:34 AM
Nice. Lots of people ask for stuff like this in suggestions.
PixelToast #3
Posted 20 October 2012 - 04:54 AM
i have my own version but it has a metatable interface, basically you can update a variable in realtime just by modifying a tables index
i can PM you the code if you want, it uses my decentralized networking system so it might take some time to convert to normal rednet
KillaVanilla #4
Posted 20 October 2012 - 06:47 AM
i have my own version but it has a metatable interface, basically you can update a variable in realtime just by modifying a tables index
i can PM you the code if you want, it uses my decentralized networking system so it might take some time to convert to normal rednet

No thank you, I like my code to be "home-grown" (with a few exceptions). Besides, this is modeled after a certain SCM, and is not supposed to be a variable persistence solution.
chrdov #5
Posted 21 October 2012 - 05:35 PM
Nice. Lots of people ask for stuff like this in suggestions.
ikr. I Want To Try it.
KillaVanilla #6
Posted 21 October 2012 - 09:51 PM
Nice. Lots of people ask for stuff like this in suggestions.
ikr. I Want To Try it.

Well then, you're in luck. I'm developing a client program for it right now.

EDIT: Okay, the client's done. It's only command-line based for now, I hate making UIs. The code is
48aP8hfF
UMayBleed #7
Posted 22 October 2012 - 09:53 PM
Nice, I am going to be starting a Database called ccSQL here soon, instead of storing files, it will be just like MySQL databases, and have commands such as "SELECT * FROM `ccDatabase`.`computer_positions` WHERE `computerID`='45';"
KillaVanilla #8
Posted 23 October 2012 - 12:19 AM
Nice, I am going to be starting a Database called ccSQL here soon, instead of storing files, it will be just like MySQL databases, and have commands such as "SELECT * FROM `ccDatabase`.`computer_positions` WHERE `computerID`='45';"

Good luck!
iRiky #9
Posted 25 October 2012 - 08:24 PM
i've got a problem


bios:207: Attempt to write to global

how i can solve it ??
KillaVanilla #10
Posted 25 October 2012 - 09:54 PM
i've got a problem


bios:207: Attempt to write to global

how i can solve it ??

I'm looking into it…

EDIT: Waaaait a minute. In the latest version (1.46), line 207 in bios.lua is empty. Have you modified your BIOS?
iRiky #11
Posted 26 October 2012 - 01:05 PM
i use 1.42 for 1.2.5
UMayBleed #12
Posted 26 October 2012 - 01:07 PM
Nice, I am going to be starting a Database called ccSQL here soon, instead of storing files, it will be just like MySQL databases, and have commands such as "SELECT * FROM `ccDatabase`.`computer_positions` WHERE `computerID`='45';"

Good luck!

Well i have alot of experience, and it will be something quite easy to me, just time consuming.
iRiky #13
Posted 26 October 2012 - 06:21 PM
scuse me another error with 1.45…
it said me:

Server at 0 reports error:not logged in

how i solve it ??
ChunLing #14
Posted 26 October 2012 - 07:12 PM
That's not an error in the program, it's just saying that you aren't logged in to the Server.

Though it might be a good idea to not use "error" this and that outputs, that can be confusing and make people think that there is something wrong with the program.
KillaVanilla #15
Posted 27 October 2012 - 04:27 AM
That's not an error in the program, it's just saying that you aren't logged in to the Server.

Though it might be a good idea to not use "error" this and that outputs, that can be confusing and make people think that there is something wrong with the program.

Yeah, i definitely need to make the error messages more user-friendly.

EDIT: Okay, made the errors a little easier to understand. Does this help?
iRiky #16
Posted 27 October 2012 - 02:12 PM
how i use the commands to login ?
KillaVanilla #17
Posted 27 October 2012 - 02:24 PM
how i use the commands to login ?

db <server> login <username> <password>
On that note, I need to make documentation for this…
mibac138 #18
Posted 28 November 2012 - 08:47 AM
In dbServ is fail you writed allowGues you should write allowGuest ;)/>
KillaVanilla #19
Posted 28 November 2012 - 11:41 AM
In dbServ is fail you writed allowGues you should write allowGuest ;)/>

Thanks, I'll look into it.

Edit: And now it's fixed.
Dlcruz129 #20
Posted 28 November 2012 - 01:33 PM
Nice, Github in ComputerCraft, very cool.
CoolisTheName007 #21
Posted 16 December 2012 - 01:37 AM
Wouldn't using sha1 for dealing with passwords be safer?
Tiin57 #22
Posted 16 December 2012 - 01:39 AM
Wouldn't using sha1 for dealing with passwords be safer?
You realize how old this topic is? -.-
It is only here because of spammers.
CoolisTheName007 #23
Posted 16 December 2012 - 01:52 AM
snip
Sorry, my time metrics must be wrong; 2 months are old age then.
gknova61 #24
Posted 05 April 2013 - 05:49 PM
I know this post is old but hopefully someone can help me :D/>

I get this error whenever I try to do a list amongst other things in different branches on the server using an API that basically just does a shell run on your client program :P/>

Here is the link to the API: http://pastebin.com/gW8DNjCm

You should really make an official API IMO so we can use this in our programs :D/> I tried to learn off your client program to make one but keep crashing the server with the API whenever trying to write data, list, etc. mainly happens when I go into a different branch.

Line it's errored out on:

Server program I'm using (contains very little modifications): http://pastebin.com/f5Mc274e
App1eGenius93 #25
Posted 14 April 2013 - 07:12 PM
Hi,

Nice program, implementing it on my dev server for a central file store :D/>

I'm just wondering if you will be updating it to support the new wired modems?

Keep up the good work!