Windows 10 – switching between starts with batch file / bash script

I'm new to coding scripts (both bash and batch) and trying to figure out if what I'm trying is possible at all. I want to create an application that simplifies the dual booting of Windows and Ubuntu. Basically, the app will have two parts (Windows 10 part and Ubuntu 18.04 part), on the Windows side I want to run a batch file that restarts and boots in Ubuntu while the Ubuntu page restarts and with bash in Windows boots.

Basically, I want to know which operating system boots after the reboot. I suspect the script must change the boot order in the UEFI settings and then restart the computer. Can you do that with Bash and Batch?

Vulnerability of file shares vs ssh or sftp, in "reverse direction"?

I work for a city administration and mainly use windows server. In recent days, several similar governments in our geographic area have been successfully attacked by ransomware. Therefore, our security people are alarmed and have (among other things) decided not to use SMB file sharing to upload files from the "internal" network to the DMZ. I have a PowerShell script that does just that to migrate databases. There are many other cases where file shares are used, such as file shares. Eg uploading websites.

They say we need to convert to SSH or SFTP to transfer files. Okay, that would be possible, but it would have to run a setup on every DMZ server and change all of our current processes, and for what? (We do not have enough people to do that and everything else, though we've tried to have more warm bodies in the budget.) Anyway, I do not see that's safer. If the DMZ server D monitors a release and the firewall prevents access only from authorized internal workstations or servers A, B, and C, this can pose a security risk (in particular, the risk of malware on server D) going in the other direction and A , B or C compromise as server D listening on an SFTP port or an SSH port with the same firewall restrictions?

If the problem is something like "File sharing is open all the time, but SSH is not", this is reasonably understandable. If necessary, you can cancel or release the assignment to the releases. But I do not think that's her reasoning; I think it's something else. Actually, I have the impression that there is a kind of vague "feeling" on their part that file shares are inherent and material less secure in the "backward" direction, even if the firewall is protected as described above. If so, why? I just do not see it. Actually, I do not understand why any of these logs would pose a risk in the "backward" direction.

Javascript – Use the Dropbox API to retrieve the latest file from the Github Pages site

I am currently trying to use the Dropbox API in a Github Web site to retrieve the most recent file in Dropbox and use its title to change the CSS background color. However, I can not figure out how to write the js to use the Dropbox API. I have the access token that I replaced in the code I specified with Insert_Access_Token_Here. The following is a test that should print my files in the console, but not. Can anyone tell me from scratch how to use the Dropbox API to at least get the name of the latest file? Many thanks


The error message I keep getting in the console is

net :: ERR_ABORTED 404

S3Zilla – A GUI / Tkinter-based file transfer program coded in Python

Here is the repository. It uses the S3 API to transfer files. You can select multiple files to upload / download and delete. A "File System Explorer" shows / updates both the local system and all of your S3 buckets. A new S3 bucket can also be created. Even if you try to upload a directory instead of a file, it is automatically converted to a ZIP archive before being uploaded. The code is validated pep8 / pycodestyle.

The Windows version is basically the same except for some sizes of the Tkinter widget.

I was having trouble viewing a newly created S3 bucket from the Bucket Name drop-down menu (after using the Create Bucket feature). My hacking solution was to use execl to restart the program after creating a new bucket (because existing buckets are automatically loaded into the drop-down menu when the application launches). Otherwise, everything in the program is very dynamic and is updated automatically.

#! /usr/bin/python3
from tkinter import *
from tkinter.filedialog import askdirectory
from os import listdir, remove, execl
from shutil import rmtree, make_archive
from getpass import getuser, getpass
from os.path import isdir, basename
from time import sleep
from sys import executable, argv
try:
    import boto3
    from botocore.exceptions import ClientError
except ImportError as e:
    print("Unable to import boto3n%s" % e)
    exit()


class S3Zilla:
    def __init__(self, master):
        error_msg = "Ensure S3 is configured on your machine:"
        try:
            self.s3 = boto3.resource('s3')
        except Exception as e:
            print("%s: %s" % (error_msg, e))
            exit(1)
        try:
            self.s3c = boto3.client('s3')
        except Exception as err:
            print("%s: %s" % (error_msg, err))
            exit(1)
        self.colors = {
            'light-grey': '#D9D9D9',
            'blue': '#2B547E',
            'black': '#000000',
            'red': '#FF3346',
            'grey': '#262626',
            'cyan': '#80DFFF'
        }
        self.master = master
        self.master.title("Amazon S3 File Transfer Client")
        self.master.configure(bg=self.colors('grey'))
        self.master.geometry("885x645")
        menu = Menu(self.master)
        menu.config(
            background=self.colors('grey'),
            fg=self.colors('light-grey')
        )
        self.master.config(menu=menu)
        file = Menu(menu)
        file.add_command(
            label="Exit",
            command=self.quit
        )
        menu.add_cascade(
            label="File",
            menu=file
        )
        refresh = Menu(menu)
        refresh.add_command(
            label="Local",
            command=self.refresh_local
        )
        refresh.add_command(
            label="S3",
            command=self.refresh_s3
        )
        menu.add_cascade(label="Refresh", menu=refresh)
        self.dir, self.drp_sel, self.bucket_name = '', '', ''
        self.folder_path = StringVar()
        self.dropdown = StringVar()
        self.dropdown_data = self.populate_dropdown()
        if not self.dropdown_data:
            self.dropdown_data = ('none available')
        self.deleted = False
        self.local_sel, self.s3_sel = (() for i in range(2))
        self.title_label = Label(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('grey'),
            font="Helvetica 10 bold",
            width=120
        )
        self.local_label = Label(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('grey'),
            text="LOCAL FILE SYSTEM",
            font="Helvetica 10 bold underline",
            width=60
        )
        self.s3_label = Label(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('grey'),
            text="AMAZON  S3",
            font="Helvetica 10 bold underline",
            underline=True,
            width=60
        )
        self.dropdown_box = OptionMenu(
            master,
            self.dropdown,
            *self.dropdown_data,
            command=self.set_drop_val
        )
        self.dropdown_box.configure(
            fg=self.colors('light-grey'),
            bg=self.colors('blue'),
            width=27,
            highlightbackground=self.colors('black'),
            highlightthickness=2
        )
        self.browse_button = Button(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('blue'),
            text="Browse",
            width=30,
            highlightbackground=self.colors('black'),
            highlightthickness=2,
            command=self.load_dir
        )
        self.browse_label = Label(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('grey'),
            text="No directory selected",
            width=37,
            font="Helvetica 10"
        )
        self.bucket_label = Label(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('grey'),
            text="No bucket selected",
            width=37,
            font="Helvetica 10"
        )
        self.refresh_btn_local = Button(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('blue'),
            text="REFRESH",
            width=30,
            highlightbackground=self.colors('black'),
            highlightthickness=2,
            command=self.refresh_local
        )
        self.refresh_btn_s3 = Button(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('blue'),
            text="REFRESH",
            width=30,
            highlightbackground=self.colors('black'),
            highlightthickness=2,
            command=self.refresh_s3
        )
        self.explorer_label_local = Label(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('blue'),
            width=30,
            text="Local File System:  "
        )
        self.explorer_label_s3 = Label(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('black'),
            width=30,
            text="S3 File System"
        )
        self.ex_loc = Listbox(
            master,
            fg=self.colors('cyan'),
            bg=self.colors('black'),
            width=49,
            height=18,
            highlightcolor=self.colors('black'),
            selectmode="multiple"
        )
        self.ex_s3 = Listbox(
            master,
            fg=self.colors('cyan'),
            bg=self.colors('black'),
            width=49,
            height=18,
            highlightcolor=self.colors('black'),
            selectmode="multiple"
        )
        self.upload_button = Button(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('blue'),
            text="Upload ->",
            width=20,
            highlightbackground=self.colors('black'),
            highlightthickness=2,
            command=self.upload
        )
        self.download_button = Button(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('blue'),
            text="<- Download",
            width=20,
            highlightbackground=self.colors('black'),
            highlightthickness=2,
            command=self.download
        )
        self.delete_local = Button(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('red'),
            text="DELETE",
            width=20,
            highlightbackground=self.colors('black'),
            command=self.delete_local_records
        )
        self.delete_s3 = Button(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('red'),
            text="DELETE",
            width=20,
            highlightbackground=self.colors('black'),
            command=self.delete_s3_records
        )
        self.found_label_local = Label(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('grey'),
            text="found local",
            width=54
        )
        self.found_label_s3 = Label(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('grey'),
            text="found s3",
            width=54
        )
        self.status_label = Label(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('grey'),
            text="Hello " + getuser(),
            width=54
        )
        self.create_bucket_label = Label(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('grey'),
            text="New Bucket:",
        )
        self.create_bucket_name = Text(
            master,
            fg=self.colors('cyan'),
            bg=self.colors('black'),
            width=25,
            height=1
        )
        self.create_bucket_button = Button(
            master,
            fg=self.colors('light-grey'),
            bg=self.colors('blue'),
            text="Create",
            width=5,
            highlightbackground=self.colors('black'),
            highlightthickness=2,
            command=self.create_bucket
        )
        # ####### begin grid placement ####### #
        self.title_label.grid(
            row=0,
            sticky=E+W,
            padx=20,
            pady=5
        )
        self.local_label.grid(
            row=0,
            sticky=W,
            padx=8,
            pady=5
        )
        self.s3_label.grid(
            row=0,
            sticky=E,
            padx=0,
            pady=5
        )
        self.browse_button.grid(
            row=1,
            sticky=W,
            padx=86,
            pady=10
        )
        self.dropdown_box.grid(
            row=1,
            sticky=E,
            padx=86,
            pady=5
        )
        self.browse_label.grid(
            row=2,
            sticky=W,
            padx=86,
            pady=5
        )
        self.bucket_label.grid(
            row=2,
            sticky=E,
            padx=86,
            pady=5
        )
        self.refresh_btn_local.grid(
            row=3,
            sticky=W,
            padx=86,
            pady=10
        )
        self.refresh_btn_s3.grid(
            row=3,
            sticky=E,
            padx=86,
            pady=10
        )
        self.explorer_label_local.grid(
            row=4,
            sticky=W,
            padx=20
        )
        self.explorer_label_s3.grid(
            row=4,
            sticky=E,
            padx=20
        )
        self.ex_loc.grid(
            row=4,
            sticky=W,
            padx=20
        )
        self.ex_s3.grid(
            row=4,
            sticky=E,
            padx=20
        )
        self.upload_button.grid(
            row=5,
            sticky=W,
            padx=224,
            pady=0
        )
        self.download_button.grid(
            row=5,
            sticky=E,
            padx=224,
            pady=0
        )
        self.delete_local.grid(
            row=5,
            sticky=W,
            padx=20,
            pady=0
        )
        self.delete_s3.grid(
            row=5,
            sticky=E,
            padx=20,
            pady=0
        )
        self.found_label_local.grid(
            row=6,
            sticky=W,
            padx=0,
            pady=20
        )
        self.found_label_s3.grid(
            row=6,
            sticky=E,
            padx=0,
            pady=20
        )
        self.status_label.grid(
            row=7,
            sticky=W,
            padx=0,
            pady=20
        )
        self.create_bucket_label.grid(
            row=7,
            sticky=E,
            padx=330,
            pady=0
        )
        self.create_bucket_name.grid(
            row=7,
            sticky=E,
            padx=100,
            pady=0
        )
        self.create_bucket_button.grid(
            row=7,
            sticky=E,
            padx=20,
            pady=0
        )
        n1 = "%s files found" % str(self.ex_loc.size())
        self.set_found_local_label(n1)
        n2 = "%s files found" % str(self.ex_s3.size())
        self.set_found_s3_label(n2)

    def quit(self):
        exit()

    def get_local_sel(self):
        return (self.ex_loc.get(i) for i in self.ex_loc.curselection())

    def get_s3_sel(self):
        return (self.ex_s3.get(i) for i in self.ex_s3.curselection())

    def set_drop_val(self, selection):
        self.drp_sel = selection

    def delete_local_records(self):
        files = self.get_local_sel()
        if not files:
            message = "Please select a file(s) to delete"
            self.set_status_label(message)
        else:
            self.del_local(files)

    def del_local(self, files_remaining):
        if len(files_remaining) > 0:
            f = files_remaining.pop(0)
            if not isdir(self.dir + "/" + f):
                try:
                    remove("%s/%s" % (self.dir, f))
                except Exception as err:
                    self.set_status_label("%s" % err)
                    self.status_label.update_idletasks()
                self.del_local(files_remaining)
            else:
                try:
                    rmtree("%s/%s" % (self.dir, f))
                except Exception as e:
                    self.set_status_label("%s" % e)
                    self.status_label.update_idletasks()
                self.del_local(files_remaining)
        self.deleted = True
        self.refresh_local()

    def delete_s3_records(self):
        removal = ''
        if not self.drp_sel:
            m = "Please select a bucket..."
            self.set_status_label(m)
        else:
            removal = self.get_s3_sel()
        if not removal:
            m = "Please select at least 1 object to delete"
            self.set_status_label(m)
        else:
            bucket = self.s3.Bucket(self.drp_sel)
            for rm in removal:
                for k in bucket.objects.all():
                    if k.key != rm:
                        continue
                    k.delete()
                    break
            self.deleted = True
            self.refresh_s3()

    def load_dir(self):
        self.dir = askdirectory()
        self.set_local_browse_label(self.dir)

    def refresh_local(self):
        if not self.dir:
            m = "Use the browse button to select a directory"
            self.set_status_label(m)
        else:
            self.set_local_browse_label(self.dir)
            self.ex_loc.delete(0, 'end')
            x = self.dir + "/"
            d = (f if not isdir(x+f) else f + '/' for f in sorted(listdir(x)))
            self.ex_loc.insert('end', *d)
            if not self.deleted:
                m = "Hello %s" % getuser()
            else:
                m = "FINISHED DELETING"
                self.deleted = False
            self.set_status_label(m)
            n = "%s files found" % str(self.ex_loc.size())
            self.set_found_local_label(n)

    def refresh_s3(self):
        if 'none available' in self.dropdown_data:
            m = "Please create at least one S3 bucket"
            self.set_status_label(m)
        elif not self.drp_sel:
            m = "Please select a bucket from the drop-down list"
            self.set_status_label(m)
        else:
            self.ex_s3.delete(0, 'end')
            self.ex_s3.insert('end', *self.get_bucket_contents())
            self.set_status_label("Hello %s" % getuser())
            self.set_s3_bucket_label(self.drp_sel)
            n = "%s files found" % str(self.ex_s3.size())
            self.set_found_s3_label(n)
            self.found_label_s3.update_idletasks()
            if not self.deleted:
                m = "Hello %s" % getuser()
            else:
                m = "FINISHED DELETING"
                self.deleted = False
            self.set_status_label(m)

    def finished(self, incoming_message):
        d = "FINISHED %s" % incoming_message
        for letter in enumerate(d):
            self.set_status_label(d(0:letter(0) + 1))
            self.status_label.update_idletasks()
            sleep(.1)

    def upload(self):
        if not self.drp_sel or not self.dir:
            m = "Ensure a local path and S3 bucket are selected"
            self.set_status_label(m)
        elif not self.get_local_sel():
            m = "Ensure files are selected to upload"
            self.set_status_label(m)
        else:
            for selection in self.get_local_sel():
                file_ = "%s/%s" % (self.dir, selection)
                if not isdir(file_):
                    self.s3c.upload_file(file_, self.drp_sel, basename(file_))
                else:
                    zipd = make_archive(file_, 'zip', self.dir, selection)
                    self.s3c.upload_file(zipd, self.drp_sel, basename(zipd))
                    remove(zipd)
                m = "Uploaded: %s" % selection
                self.set_status_label(m)
                self.status_label.update_idletasks()
            self.refresh_s3()
            self.finished("UPLOAD")

    def download(self):
        if not self.drp_sel or not self.dir:
            m = "Ensure a file and bucket have been selected"
            self.set_status_label(m)
        elif not self.get_s3_sel():
            m = "Ensure files are selected to download"
            self.set_status_label(m)
        else:
            for selection in self.get_s3_sel():
                file_ = "%s/%s" % (self.dir, selection)
                self.s3c.download_file(self.drp_sel, selection, file_)
            self.refresh_local()
            self.finished("DOWNLOAD")

    def get_bucket_contents(self):
        bucket = self.s3.Bucket(self.drp_sel)
        return (s3_file.key for s3_file in bucket.objects.all())

    def populate_dropdown(self):
        return (bucket.name for bucket in self.s3.buckets.all())

    def set_local_browse_label(self, incoming):
        if len(incoming) > 35:
            self.browse_label.config(text=basename(incoming) + '/')
        else:
            self.browse_label.config(text=incoming)

    def set_s3_bucket_label(self, incoming):
        self.bucket_label.config(text=incoming)

    def set_status_label(self, incoming):
        self.status_label.config(text=incoming)

    def set_found_local_label(self, incoming):
        self.found_label_local.config(text=incoming)

    def set_found_s3_label(self, incoming):
        self.found_label_s3.config(text=incoming)

    def create_bucket(self):
        self.bucket_name = self.create_bucket_name.get("1.0", END).strip()
        if not self.bucket_name:
            m = "Please enter a new bucket name"
            self.set_status_label(m)
        else:
            pre_exists = False
            try:
                self.s3.create_bucket(Bucket=self.bucket_name)
            except ClientError as ce:
                pre_exists = True
                m = "Bucket name is already in use. "
                m += "Choose a different name."
                self.set_status_label(m)
            if not pre_exists:
                m = "%s created: restarting..." % self.bucket_name
                self.set_status_label(m)
                self.status_label.update_idletasks()
                res = executable
                execl(res, res, *argv)


if __name__ == "__main__":
    root = Tk()
    s3_zilla = S3Zilla(root)
    root.mainloop()

How can I customize the file path for 404 redirection in PHP?

I've created a plugin with a custom post type postcard,
Most of postcards are private.

I'd like to redirect the logged-out user to a specific PHP file in my plug-in instead of the one 404.php or achive.php,

I tried it template_redirect Action as follows:

add_action( "template_redirect", array( "MyClass", "is_redirection" ) );

Class MyClass{

    public static function is_redirection(){
        if( is_404() ) {
            global $post_type;
            if( $post_type === "postcard" ){
                $templates_dir = get_current_plugin_templates_dir_path();
                $page404 = $templates_dir . "/404-" . $post_type . ".php";
                if ( file_exists( $page404 ) ) {
                   wp_redirect( $page404 );
                   exit;
                }
            }
        }
    }  
}

My problem is here $page404 is a file path, not a URL …
How can I do this without using .htaccess?

8 – Grant permission to the FileSystem.php file

I navigate to admin/config/media/file-system in the Drupal admin interface. I get this mistake Warning: mkdir(): Permission denied in DrupalCoreFileFileSystem->mkdirCall() (line 244 of core/lib/Drupal/Core/File/FileSystem.php) I have granted permission to the site folder with the following commands chown -R www-data:www-data sites and chmod -R g+rw sitesbut the error still occurs.

Any advice?

python – Indexing values ​​from a file

I'm desperately trying to get a job off the job, and I just can not figure it out.
Short description:
I need to monitor a file that generates some values. I can isolate the values ​​in a separate file, and I'm a string to assign an index to each value.

Description:

My specified file (file A) will look like this, but with more than 10000 entries:

402
506
223
123
5667
17430
9921
9232

All the values ​​in it are basically integers ranging between 103 and 17431. For every single number from File A, I have to assign an index value from 0 to 9.
My first approach was to use sed This will replace any string from file A with the specified value of the given index, but it takes too long for my large file.
Another approach that was recommended to me was to use awk but I fail too. My script looked like this:

awk '($0>=363 && $0<=499) || ($0>=4645 && $0<=4646) {$0="0"}1' tmp >tmp2

awk '($0>=2174 && $0<=2193)  {$0="1"}1' tmp >tmp2

awk '($0==500) || ($0>=12308 && $0<=12356) {$0="2"}1' tmp >tmp2

awk '($0>=103 && $0<=220) || ($0>=252 && $0<=299) || ($0>=1980 && $0<=1986) || ($0>=2921 && $0<=2922) {$0="3"}1' tmp >priority

awk '($0>=221 && $0<=251) || ($0>=8085 && $0<=8091) || ($0==8350) || ($0>=12809 && $0<=12945) || ($0>=16834 && $0<=17033)  {$0="4"}1' tmp >tmp2

awk '($0>=300 && $0<=362) || ($0=522) || ($0>=2923 && $0<=2925) || ($0>=3441 && $0<=3442) || ($0=4644)|| ($0>=5677 && $0<=5695) || ($0>=8082 && $0<=8083)|| ($0>=8093 && $0<=8349) || ($0>=12946 && $0<=12947) || ($0>=21986 && $0<=13215) || ($0>=13309 && $0<=13311)  {$0="5"}1' tmp >tmp2

I had hoped for an issue like:

5
3
3
2
1
6
7
7

Does not happen. I declare the ranges for each index and try to replace each value accordingly, but it does not work. Im trying to take afor loopor anotherwiseapproach but i do not know how just because II'm new to this.
If someone can help me with a syntax that helps me?
I tried to write something similar with:

x=value from file list.csv
for x in rage1 or range2 or range3 
 replace x with 0
for x in range 3 or range 4 or range 5
 replace x with 1

OR an if/else approach

x=values from list.csv
if x in range1 or range2 or range3 
  then replace x with 0
else if x in range4 range5 range6
  then replace x with 1

Can somebody help me with it? I'm trying to make it as good as possible (Bash, Pearl, Python …) so any idea is welcome as long as it's explained a bit how to say I'm new to it. Many thanks.

Audio – Using ffmpeg to convert a G711 U-Law or A-Law file to WAV

One of our applications allows the user to upload multiple audio formats such as MP3, G711 U-Law or A-Law, etc., and uses FFMPEG to convert these formats to WAV.

The conversion from mp3 to wav seems to be easy with the following command. With which parameters can I convert u-law or a-law to wav?
ffmpeg -i input.mp3 output.wav