JDownloader Community - Appwork GmbH
 

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 26.06.2018, 14:35
Crusoe
Guest
 
Posts: n/a
Unhappy Reboot PC via myJDownloader Interface

Hello,

I have a little Problem:

I am not at home for a few weeks and my server is running.
Now the VPN Connection is lost and I have to reboot the Server.
Without VPN I have no SSH Connection.
But myJDownloader is still working.
I've seen that I can shutdown the PC via Webinterface of myJDownloader.
But I is possible to reboot the PC?
Maybe via EventScripter?

Thank you for your help
Reply With Quote
  #2  
Old 26.06.2018, 15:17
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,343
Default

How is the network setup that VPN is required in order to connect via SSH?

At the moment it is not possible to restart via MyJDownloader but you
could indeed use the eventscripter and let it do the reboot. For example a script
and a dummy link in list, you enable the link and the script will detect this, disable the link again and do the reboot of computer.
You can ask mgpai here in forum for help with the script.
__________________
JD-Dev & Server-Admin
Reply With Quote
  #3  
Old 26.06.2018, 15:50
Crusoe
Guest
 
Posts: n/a
Default

I have a DS-Lite Connection. From Devices / ISPs without IPv6 Support, I can't reach my Server.
For that reason I use a VPN Service. But the Service disconnected and won't reconnect automaticly.

I will ask mgpai for help with the script
Reply With Quote
  #4  
Old 26.06.2018, 15:53
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,343
Default

You could setup a bash script/cronjob
that checks the vpn connction and in case it's broken, either restart vpn connection or reboot computer.
__________________
JD-Dev & Server-Admin
Reply With Quote
  #5  
Old 26.06.2018, 15:55
Crusoe
Guest
 
Posts: n/a
Default

Yes,
but for that, I need SSH access :D
I missed it when I was setup the Server.
Nothing happens for months and now, that I am one day 1000km away from home, something went wrong^^

Last edited by Crusoe; 26.06.2018 at 15:57.
Reply With Quote
  #6  
Old 26.06.2018, 15:57
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Example Script for Windows OS

Code:
// Restart remote (JD) server via myjd WebUI
// Trigger: New Crawler Job

if (job.text == "restartserver") {
    disablePermissionChecks();
    callAsync(null, "shutdown", "-r");
}
  • Set up the script in any JD Desktop
  • Copy the script JSON from : Settings > Advanced Settings > EventScripter.scripts and paste it in WebUI advanced settings.
  • Click "Add Links" in WebUI and type "restartserver" (without quotes) and press "Continue"
Reply With Quote
  #7  
Old 26.06.2018, 16:17
Crusoe
Guest
 
Posts: n/a
Default

I can only work with myJDownloader.
The Server is headless.
If I try to paste the Script in the "EventScripter: Scripts" Window, but I will be not accepted.

EDIT: Is that normal, that I can't open the attachment below my post?
Attached Images
File Type: png Unbenannt.png (90.0 KB, 1 views)
Reply With Quote
  #8  
Old 26.06.2018, 16:23
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,343
Default

Images/Links/Attachments can only be access by support staff
You've got to setup the script with a JDownloader with GUI/eg on your computer
and then copy like explained by mgpai
__________________
JD-Dev & Server-Admin
Reply With Quote
  #9  
Old 26.06.2018, 16:27
Crusoe
Guest
 
Posts: n/a
Default

Now I understand
I'll try this.
Got a message from AVIRA while installing... Let's hope it's a false positive...
Reply With Quote
  #10  
Old 26.06.2018, 16:37
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,343
Default

It's a false positive because of the optional adware, see https://support.jdownloader.org/Know...g-installation
__________________
JD-Dev & Server-Admin
Reply With Quote
  #11  
Old 27.06.2018, 21:12
Crusoe
Guest
 
Posts: n/a
Default

I was trying a lot.
It seems, that a Terminal is necessary to execute a su command to reboot the PC.
The jdownloader User has no sudo privileges.
The hard part is, that the Script which has to be executed, must be "injected" by the Eventscripter via "echo" command. That is a hard nut to crack with a lot of special characters and new lines...

I try to inject this Script:
Code:
#!/usr/bin/expect -f
#Usage: script.sh cmd user pass

set cmd [lindex $argv 0];
set user [lindex $argv 1];
set pass [lindex $argv 2];

log_user 0
spawn su -c $cmd - $user
expect "Password: "
log_user 1
send "$pass\r"
expect "$ "
with this EventScripter Script:
Code:
[ {
  "eventTrigger" : "ON_NEW_CRAWLER_JOB",
  "enabled" : true,
  "name" : null,
  "script" : "// Restart remote (JD) server via myjd WebUI\n// Trigger: New Crawler Job\n\nif (job.text == \"restartserver\") {\n    alert(callSync(\"/bin/bash\", \"-c\", \"echo -e \\\"#!\\/usr\\/bin\\/expect -f\\r\\n#Usage: script.sh cmd user pass\\r\\n\\r\\nset cmd [lindex $argv 0];\\r\\nset user [lindex $argv 1];\\r\\nset pass [lindex $argv 2];\\r\\n\\r\\nlog_user 0\\r\\nspawn su -c $cmd - $user\\r\\nexpect \\\"Password: \\\"\\r\\nlog_user 1\\r\\nsend \\\"$pass\\\\r\\\"\\r\\nexpect \\\"$ \\\"\\\" > /tmp/test.sh\"));\n}",
  "eventTriggerSettings" : {
    "isSynchronous" : false
  },
  "id" : 1529571752984
}]
But if I try to show the content of "/tmp/test.sh" with "cat" with this Script:
Code:
[ {
  "eventTrigger" : "ON_NEW_CRAWLER_JOB",
  "enabled" : true,
  "name" : null,
  "script" : "// Restart remote (JD) server via myjd WebUI\n// Trigger: New Crawler Job\n\nif (job.text == \"restartserver\") {\n    alert(callSync(\"/bin/bash\", \"-c\", \"cat /tmp/test.sh\"));\n}",
  "eventTriggerSettings" : {
    "isSynchronous" : false
  },
  "id" : 1529571752984
}]
I get only the characters of the expected Content, no new Lines, no quotas, nothing.
I am not sure if this is a limitation of the Alert-Window which give me the message.
If I execute the /tmp/test.sh Script, I get a lot of syntax errors in nearly every line of the Script. It looks like the new line (\\r\\n) seems to work.
Reply With Quote
  #12  
Old 28.06.2018, 08:30
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,343
Default

Don't use echo to write the files! You can easily use the eventscripter to write/create a file instead of echo *workaround*
You can ask mgpai for help with this
__________________
JD-Dev & Server-Admin
Reply With Quote
  #13  
Old 28.06.2018, 10:47
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by Jiaz View Post
... You can easily use the eventscripter to write/create a file ...
Code:
// Paste in the script editor and press the "Test Run" button to create the file on disk

var myScript = "/anyExistingFolder/myScript.sh";
var myContent =
    "#!/usr/bin/expect -f\r\n" +
    "#Usage: script.sh cmd user pass\r\n" +
    "\r\n" +
    "set cmd [lindex $argv 0];\r\n" +
    "set user [lindex $argv 1];\r\n" +
    "set pass [lindex $argv 2];\r\n" +
    "\r\n" +
    "log_user 0\r\n" +
    "spawn su -c $cmd - $user\r\n" +
    "expect \"Password: \"\r\n" +
    "log_user 1\r\n" +
    "send \"$pass\\r\"\r\n" +
    "expect \"$ \"";

writeFile(myScript, myContent, false);
Reply With Quote
  #14  
Old 28.06.2018, 10:49
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,343
Default

@mgpai: must be all in one event, file creation and execution
because he has to run all remotely
__________________
JD-Dev & Server-Admin
Reply With Quote
  #15  
Old 28.06.2018, 16:28
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by Jiaz View Post
@mgpai: must be all in one event, file creation and execution
because he has to run all remotely
I think @crusoe will be able to integrate the snippet into the script. Also, I am not familiar with any linux commands, so I am not quite sure what else needs to added. In any case, here is template based on what I have understood about the subject.

Spoiler:
Code:
// Restart remote (JD) server via myjd WebUI
// Trigger: New Crawler Job

try {
    if (job.text == "restartserver") {
        disablePermissionChecks();
        var myScript = "/anyExistingFolder/myScript.sh";
        var myContent =
            "#!/usr/bin/expect -f\r\n" +
            "#Usage: script.sh cmd user pass\r\n" +
            "\r\n" +
            "set cmd [lindex $argv 0];\r\n" +
            "set user [lindex $argv 1];\r\n" +
            "set pass [lindex $argv 2];\r\n" +
            "\r\n" +
            "log_user 0\r\n" +
            "spawn su -c $cmd - $user\r\n" +
            "expect \"Password: \"\r\n" +
            "log_user 1\r\n" +
            "send \"$pass\\r\"\r\n" +
            "expect \"$ \"";

        writeFile(myScript, myContent, false);
        callSync(myScript);
        callAsync(null, "reboot");
    }
} catch (e) {
    alert("" + e);
}
Reply With Quote
  #16  
Old 29.06.2018, 02:10
Crusoe
Guest
 
Posts: n/a
Default

I think I have to surrender... :(
The Server is no more reachable over myJD.
Thank you very much for your help. It's a pity, that we could not get the Server to reboot...

Is there a button to mark this topic as "unsolved" or something like this?
Reply With Quote
  #17  
Old 29.06.2018, 10:19
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,343
Default

Sorry to hear that your computer is no longer reachable. At least you tried your best
__________________
JD-Dev & Server-Admin
Reply With Quote
  #18  
Old 29.06.2018, 12:11
Crusoe
Guest
 
Posts: n/a
Default

No... At least I learned a lot of a Javascript, which I was never useing before
Maybe I will take deeper look at Javascript. It seems to be an intersting language.
Yeah... The Server is down, that's a pity. So what... I go to the beach now
Reply With Quote
  #19  
Old 29.06.2018, 12:57
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,343
Default

Quote:
Originally Posted by Crusoe View Post
Maybe I will take deeper look at Javascript. It seems to be an intersting language.

Back off, you devil!
__________________
JD-Dev & Server-Admin
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 12:37.
Provided By AppWork GmbH | Privacy | Imprint
Parts of the Design are used from Kirsch designed by Andrew & Austin
Powered by vBulletin® Version 3.8.10 Beta 1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.