Skip to content

Adding fileWrite to nodebb code

Solved Configure
  • I have a test nodebb (no live users) and I want to see what is / isnt possible, in regard to owners accessing passwords.
    In src/password.js I added
    const fs=require(‘fs’)
    and a line to write password to a txt file. It didnt even open a file (even when just writing a text string in simpler test … see screenshot)
    I also added the same to src/user/password.js as I assumed one of these files will be accessed when someone logs in.
    So why was no pasfi.txt file ever created?
    Disclamer, I would not obviously do this on a live forum, but Im curious
    Screenshot_20221010-141223_Termius~2.jpg

  • I have a test nodebb (no live users) and I want to see what is / isnt possible, in regard to owners accessing passwords.
    In src/password.js I added
    const fs=require(‘fs’)
    and a line to write password to a txt file. It didnt even open a file (even when just writing a text string in simpler test … see screenshot)
    I also added the same to src/user/password.js as I assumed one of these files will be accessed when someone logs in.
    So why was no pasfi.txt file ever created?
    Disclamer, I would not obviously do this on a live forum, but Im curious
    Screenshot_20221010-141223_Termius~2.jpg

    @eveh You’d need to recompile the password.js file for any changes to be picked up. This typically won’t work unless you use ./nodebb build && ./nodebb start. Even then, you may still require a local DEV instance of webpack.

    One other way would be to use one of the existing hooks in NodeBB and create a custom JS function for it.

  • phenomlabundefined phenomlab has marked this topic as solved on
  • @eveh You’d need to recompile the password.js file for any changes to be picked up. This typically won’t work unless you use ./nodebb build && ./nodebb start. Even then, you may still require a local DEV instance of webpack.

    One other way would be to use one of the existing hooks in NodeBB and create a custom JS function for it.

    @phenomlab thanks, tried the recompile but still nothing.
    I have it running on a test server (so not locally)
    I tried reading up about hooks but didnt fully understand.
    If I use a non-async file write command would I still need that?
    Can you help me get started with this hook / webpack thing?

  • @phenomlab thanks, tried the recompile but still nothing.
    I have it running on a test server (so not locally)
    I tried reading up about hooks but didnt fully understand.
    If I use a non-async file write command would I still need that?
    Can you help me get started with this hook / webpack thing?

    @eveh said in Adding fileWrite to nodebb code:

    If I use a non-async file write command would I still need that?

    Yes, because you are changing one of the core files

    @eveh said in Adding fileWrite to nodebb code:

    I tried reading up about hooks but didnt fully understand.

    Did you review this page ?

    https://docs.nodebb.org/development/plugins/hooks/

    @eveh said in Adding fileWrite to nodebb code:

    Can you help me get started with this hook / webpack thing?

    That’s a question probably best asked over on the community forms, as that’s where the devs are located

    https://community.nodebb/org

  • @eveh said in Adding fileWrite to nodebb code:

    If I use a non-async file write command would I still need that?

    Yes, because you are changing one of the core files

    @eveh said in Adding fileWrite to nodebb code:

    I tried reading up about hooks but didnt fully understand.

    Did you review this page ?

    https://docs.nodebb.org/development/plugins/hooks/

    @eveh said in Adding fileWrite to nodebb code:

    Can you help me get started with this hook / webpack thing?

    That’s a question probably best asked over on the community forms, as that’s where the devs are located

    https://community.nodebb/org

    @phenomlab thanks
    But something Im still not getting, Ive coded it to write to a file when that hash function is called, so I dont understand why it needs to be triggered by a hook event?
    Its like when it runs that function how can it not write the file, its not something that needs to be triggered by an action, it should just do it when that function runs?

  • @phenomlab thanks
    But something Im still not getting, Ive coded it to write to a file when that hash function is called, so I dont understand why it needs to be triggered by a hook event?
    Its like when it runs that function how can it not write the file, its not something that needs to be triggered by an action, it should just do it when that function runs?

    @eveh The hook will trigger, but not if you are modifying password.js directly as it will need to be recompiled. To execute the hook, you should use /admin/appearance/customise#custom-js

  • @eveh The hook will trigger, but not if you are modifying password.js directly as it will need to be recompiled. To execute the hook, you should use /admin/appearance/customise#custom-js

    @phenomlab
    Update, the basic file write did work, I found the txt file did have the ‘!o!’ string characters in.
    But the write of password never worked.
    I tried both (file, password…
    And then wondered if password is an object so tried unpacking it as a string, which didnt work)
    See below
    So its the way Im referencing password that might be problem?
    Screenshot_20221010-194743_Termius~2.jpg

  • @phenomlab
    Update, the basic file write did work, I found the txt file did have the ‘!o!’ string characters in.
    But the write of password never worked.
    I tried both (file, password…
    And then wondered if password is an object so tried unpacking it as a string, which didnt work)
    See below
    So its the way Im referencing password that might be problem?
    Screenshot_20221010-194743_Termius~2.jpg

    @eveh does the account you are running the under have permissions to the file storage ?

  • @eveh does the account you are running the under have permissions to the file storage ?

    @phenomlab yes, sure it does as its doimg the first write to the File,
    Just not where I reference password variable

  • @phenomlab yes, sure it does as its doimg the first write to the File,
    Just not where I reference password variable

    @eveh what’s the output if you stop NodeBB and then run it from the console as ./nodebb dev ?

  • @eveh what’s the output if you stop NodeBB and then run it from the console as ./nodebb dev ?

    @phenomlab could that make a difference if the first write is working?

  • @phenomlab could that make a difference if the first write is working?

    @eveh I don’t expect it to make a difference, no, but it should at least provide some debug logging so you can get an idea of why it fails.

  • @eveh I don’t expect it to make a difference, no, but it should at least provide some debug logging so you can get an idea of why it fails.

    @phenomlab i think issue may have been i didnt stop nodebb before i ran it again in dev

  • @phenomlab i think issue may have been i didnt stop nodebb before i ran it again in dev

    @eveh now you know why I said stop NodeBB first 😁

  • @eveh now you know why I said stop NodeBB first 😁

    @phenomlab Narrowed down this issue, its something to do with accessing these variables
    If I write text out like ‘User’ or ‘password’ that goes to the file.
    But when I try these variables or objects (whatever they are) it never works.
    Ive tried writing out User, password, JSON.stringify(password)
    I dont know how to reference what is contained in User or password
    Below screenshot of the plain text that does work!

    Screenshot_20221010-212300_Termius~2.jpg

    I dont know much about these module exports, or what is passed into the parameter

  • @phenomlab Narrowed down this issue, its something to do with accessing these variables
    If I write text out like ‘User’ or ‘password’ that goes to the file.
    But when I try these variables or objects (whatever they are) it never works.
    Ive tried writing out User, password, JSON.stringify(password)
    I dont know how to reference what is contained in User or password
    Below screenshot of the plain text that does work!

    Screenshot_20221010-212300_Termius~2.jpg

    I dont know much about these module exports, or what is passed into the parameter

    @eveh this might be a question for the NodeBB Devs themselves. In all honesty, I’m not entirely sure without having to research this myself.


Did this solution help you?
Did you find the suggested solution useful? Why not buy me a coffee? It's a nice gesture, and a great way to show your appreciation 💗

Related Topics
  • 3 Votes
    1 Posts
    30 Views
    No one has replied
  • how to prevent DDoS attacks ?

    Solved Vulnerability
    34
    17 Votes
    34 Posts
    3k Views
    @phenomlab thank you very much, this was helpful. Everything looks ok
  • NodeBB: Favicon upload issue

    Solved Configure
    12
    1
    3 Votes
    12 Posts
    714 Views
    @phenomlab I am on a Mac, so I used the “Option + Command + I”, and then performed the steps. It loaded my favicon! I checked on Firefox which I haven’t used before, and it showed my favicon also! That’s fantastic and thank you for the help!
  • NodeBB: Upgrading to NodeBB v3.x

    Solved Configure
    6
    0 Votes
    6 Posts
    459 Views
    @mventures You’d need to connect to the server and execute it directly - not on your local terminal. Review the guide below, which will show you how to gain access via SSH to your server https://docs.ovh.com/gb/en/dedicated/ssh-introduction/ Once you have access, you’ll need to navigate to the actual folder where NodeBB is installed You’ll then need to change to the directory as shown below /home/unbuntu/nodebb [image: 1680448167972-fdffe673-bf63-4b6d-a728-5506fddc1aff-image.png] In most cases, initial access takes you to the root of the file system. You can always issue pwd in a Linux terminal which will show you the Present Working Directory. From there, you can issue the command cd /home/ubuntu/nodebb Once in the NodeBB directory, you’d use the below commands ./nodebb stop git fetch && git checkout develop && git reset --hard origin/develop ./nodebb upgrade ./nodebb start Line 1 stops the NodeBB instance Line 2 gets the latest files from GIT (repository) and then checks out the development branch. It then resets the version you are using to the development branch ready for v3 Line 3 Runs the upgrade once the new branch is set, and code pulled Line 4 Restarts the NodeBB instance after the upgrade has completed Note that when you restart NodeBB and log back in, things will look very different to what you had in v2.
  • who is read NodeBB

    Customisation
    6
    0 Votes
    6 Posts
    737 Views
    @cagatay You should ask in the NodeBB forums. Perhaps reference this post https://discuss.flarum.org/d/23066-who-read
  • Podcast Share NodeBB

    Solved Configure
    15
    4 Votes
    15 Posts
    966 Views
    @cagatay You could experiment with nodebb-plugin-ns-embed but I expect the x-origin tag on the remote site to prevent playback.
  • [NODEBB] Welcome Message

    Solved Customisation
    20
    2
    13 Votes
    20 Posts
    3k Views
    @DownPW the ‘js’ code for the banner takes the time from the client, so what it displays really depends on the regional settings for the operating system. I’ve not seen this issue myself but would like to see some examples of screenshots if possible.
  • nodebb dropdown menu

    Solved Configure
    5
    1
    0 Votes
    5 Posts
    646 Views
    @phenomlab said in nodebb dropdown menu: @kurulumu-net You set it like the below example taken from this site [image: 1637939951821-aae36790-3257-4bb2-ad5a-0d744309876a-image.png] Which presents this [image: 1637939983445-77f47260-2941-4afe-9614-8e17dcfc8c19-image.png] Very interesting… I actually thought this wasn’t possible, as I remember it being asked in the NodeBB forum. Is this something new that’s been implemented? I’ll 100% be doing that when I’m on the laptop over the weekend.