rejetto forum

command lines

raybob · 39 · 16581

0 Members and 1 Guest are viewing this topic.

Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
Is it somehow possible to create a new user account using a command line?

Thanks for any input,
Raybob
« Last Edit: March 09, 2011, 11:42:50 PM by raybob95 »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
yes, there is, but you need to make it possible with a simple script.
the first method that comes to my mind is to have an event that runs every 1 or 5 seconds, and executes a specific file/script.
That's ALT+F6, and put this code
Code: [Select]
[every 2 seconds]
{.load|automatic.txt.}
{.delete|automatic.txt.}

Now, every time you want HFS to do something, you can make a script and save (or copy) it to automatic.txt (same folder as hfs.exe)

to create an account named "test", the script is
{.new account|my test.}

more details at http://www.rejetto.com/wiki/index.php/HFS:_scripting_commands#Account_manipulation
« Last Edit: March 14, 2011, 02:19:52 PM by rejetto »


Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
My end goal here is to make it so that it is somehow possible for a user to create their own account by submitting a form on one of the webpages.

This is what I'm thinking:

I could use Apache with PHP on another port, then have the form data submitted get put into a file like "automatic.txt" in the proper format and then have HFS automatically load the script every few seconds by putting that code you posted into HFS.events . . .

Is that a viable idea?

EDIT:  I wrote this script and it works perfectly.  Now I need to write some PHP to get it to submit the form data to this file in the proper syntax:

Code: [Select]
{.mkdir|D:\PERSON.}
{.add folder|real|D:\PERSON|.person.}
{.new account|person|password=password|enabled=true|member of=can change password|redirect=/.person/.}
{.set item|.person|hide=1|access=person|delete=person|upload=person.}

Only one problem I couldn't figure out: I need to make it so that the template of the folder is changed also.  Is this possible?  



EDIT 2:  Would it be possible to use an HFS functionality rather than PHP to get form data saved as a .txt ?
« Last Edit: March 17, 2011, 12:40:28 AM by raybob95 »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
consider you don't need to pass via Apache to have a form for account creation. Indeed you can find by searching on this forum some scripts doing it.
HFS is able to handle the form's data.

just use the {.postvar|name.} command to read "name" if you are using method=post
or even easier {.?name.} if the form is not using method=post


Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
I've already written the PHP and gotten everything to work perfectly, so I'm going to use it for now.

However, there is one problem I have whether or not I use HFS or PHP for the form scripting.  That is, I need to be able to change a folder's default template in the VFS using command line manipulation, but I see nothing about it in the wiki.

Is that possible?  If not then could you include it in build 276?

Thanks,
Ray


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
i don't know if i understood you.
you want to have different templates, based on the folder?


Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
Yes.

You know how in HFS itself it lets you specify a different template for each folder?

I would like a way to specify the template with the command.

Ray


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
yes, it's possible with the {.load tpl.} command.
it works for sure if you use it in event [request].
the template shall depend on the %url%.

please describe the rule that decides the template to be used


Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
In HFS, if you go on the left, and right click a folder then hit properties, the properties box comes up.  One of the available tabs is 'Diff Template' which allows you to change the template for each specific folder, a feature that I rely on heavily.  I need a way to do this with the macro command line.

If you could go more in-depth on how to do this I would appreciate it greatly.

Thanks,
Ray


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
Quote
In HFS, if you go on the left, and right click a folder then hit properties, the properties box comes up.  One of the available tabs is 'Diff Template' which allows you to change the template for each specific folder, a feature that I rely on heavily.

if you add a directiory into the vfs as real folder, you can edit the diff template by putting the {.load tpl|"full_path_tpl".} command. or you can use a file named hfs.diff.tpl inside the folder, then it's possible to create modify or delete this last file with another application, see wiki about.

by security there is no way to modify a diff template.  ;)



Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
Yes!  Creating an hfs.diff.tpl is exactly the type of thing I was looking for.  I didn't know you could do that.    :)



Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
diff tpl is mainly designed for making changes to the current template.
but in case you need to use whole different templates, you don't need to make a copy of the template in each folder (named hfs.diff.tpl).
you can use {.load tpl.} and then {.section.} to reload the main section of the template.
another way is to load the template in events, event [request]


Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
Alright!  I got the whole thing coded out exactly as I need it.  Maybe one day when I feel up to it I'll write an HFS Script rather than PHP.  Or I could just wait until HFS can use PHP  ;D

But here's what I got in HFS.events:

Code: [Select]
[every 1 seconds]
{.load|automatic.txt.}
{.delete|automatic.txt.}

In Submitted.php in XAMPP:

Code: [Select]
<?php



// Get posted variables for Name, password, and email

$name $_POST["name"];
$password $_POST["password"];
$email $_POST["email"];



// Specify the new HFS Script and the Email Log File

$myFile "M:\automatic.txt";
$myFile2 "M:\User emails\\$name.txt";
$fh fopen($myFile'w');
$fh2 fopen($myFile2'w');



// Specify the contents of the two new files, one with the HFS Macros and the other with the user's email address

$string1 "{.mkdir|D:\\$name.}
{.add folder|real|D:\\
$name|.$name.}
{.new account|
$name|password=$password|enabled=true|member of=can change password|redirect=/.$name/.}
{.set item|.
$name|hide=1|access=$name|delete=$name|upload=$name.}";

$string2 "$email";



// Create the two files and write the new contents

fwrite($fh"$string1");
fclose($fh);

fwrite($fh2"$string2");
fclose($fh2);



// Wait 1 second for HFS to create the new directory

sleep(2);



// Copy over the HFS template to the new directory

$old "D:/hfs.diff.tpl";
$new "D:/$name/hfs.diff.tpl";

copy($old$new);



?>


I hope I'm not asking too much, but if anybody gets the time, could someone please "convert" this PHP script to HFS macros?  That would be hugely appreciated.

Thanks,
Ray

« Last Edit: March 20, 2011, 09:33:21 PM by raybob95 »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
i'm just noticing that you can't use "set item" to set the diff tpl of the folder.
if you could, you would be able to get rid of those hfs.diff.tpl in every folder.
you would just need to set the diff tpl field of the folder to D:\hfs.diff.tpl
and the content would be automatically be loaded from that.
I will add this in next release (277)

as a side note, you can have a much shorter form with php, like this

file_put_contents("M:\automatic.txt",
    "{.mkdir|D:\\$name.}
    {.add folder|real|D:\\$name|.$name.}
    {.new account|$name|password=$password|enabled=true|member of=can change password|redirect=/.$name/.}
    {.set item|.$name|hide=1|access=$name|delete=$name|upload=$name.}");


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
I hope I'm not asking too much, but if anybody gets the time, could someone please "convert" this PHP script to HFS macros?  That would be hugely appreciated.

not tested.
put this in the root/home diff template

Code: [Select]
[process-form]
{.mkdir|D:\{.$name.}.}
{.add folder|real|D:\{.$name.}|.{.$name.}.}
{.new account|{.$name.}|password={.$password.}|enabled=true|member of=can change password|redirect=/{.$name.}/.}
{.set item|{.$name.}|hide=1|access={.$name.}|delete={.$name.}|upload={.$name.}.}
{.save|M:\User emails\{.$name.}.txt|{.$email.}.}
{.copy| D:\hfs.diff.tpl | D:\{.$name.}\hfs.diff.tpl .}
Done!

then point the action of your form to /~process-form
« Last Edit: March 21, 2011, 11:45:28 AM by rejetto »