-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pyAref
committed
May 11, 2021
1 parent
98212cd
commit f220973
Showing
5 changed files
with
119 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#! /usr/bin/python3 | ||
|
||
from os import chdir, getcwd | ||
from http.server import HTTPServer, CGIHTTPRequestHandler | ||
|
||
|
||
class ShareFile: | ||
def __init__(self): | ||
self.current_directory = getcwd() | ||
self.__port__ = int(input(f"[!] You Are sharing \"{self.current_directory}\" on your local network.\nEnter Your port here: ")) | ||
|
||
self.ok = '\033[92m' #GREEN | ||
self.fail = '\033[31m' #RED | ||
self.reset = '\033[0m' #RESET COLOR | ||
|
||
|
||
def __color__green__(self, text): | ||
return self.ok + text + self.reset | ||
|
||
|
||
def __server__(self): | ||
chdir(".") | ||
self.server = HTTPServer(("", self.__port__), CGIHTTPRequestHandler) | ||
print(f"Server is online on 127.0.0.1:{self.__color__green__(f'{self.__port__}')}") | ||
|
||
|
||
def run(self): | ||
self.__server__() | ||
self.server.serve_forever() | ||
|
||
|
||
if __name__ == '__main__': | ||
app = ShareFile() | ||
app.run() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import re | ||
from os.path import isfile | ||
from os import WIFSTOPPED, getuid, system | ||
from shutil import copyfile | ||
from socket import gethostname | ||
|
||
|
||
class sharefolder: | ||
def __init__(self): | ||
self.ok = '\033[92m' #GREEN | ||
self.progess = "\033[034m" | ||
self.fail = '\033[31m' #RED | ||
self.reset = '\033[0m' #RESET COLOR | ||
self.__path__ = '/usr/local/bin/ShareFolder.py' | ||
|
||
|
||
# check root or not | ||
if not getuid() == 0: | ||
print(f'{self.fail}[E]{self.reset} This script must be run as root!') | ||
|
||
elif getuid() == 0: | ||
print(f"{self.ok}[ OK ]{self.reset} Start installation ..") | ||
self.install() | ||
|
||
|
||
def __bashrc__(self): | ||
# open bashrc and read | write | ||
echo_command = f"alias sharefolder='python3 {self.__path__}'" | ||
with open('/root/.bashrc', 'r+') as bashrc_write: | ||
if echo_command in bashrc_write.read(): | ||
bashrc_write.close() | ||
return True | ||
elif echo_command not in bashrc_write.read(): | ||
bashrc_write.write(echo_command) | ||
bashrc_write.close() | ||
return False | ||
|
||
|
||
def __steps__(self): | ||
# check ShareFolder.py | ||
if isfile(self.__path__) and self.__bashrc__() is True: | ||
print(f"{self.ok}[ OK ]{self.reset} The program is already installed :)") | ||
|
||
elif not isfile(self.__path__) and self.__bashrc__() is False: | ||
|
||
self.__ad__ = re.search(r"/(.*?)ShareFolder.py", self.__path__).group(1) | ||
print(f"{self.progess}[ INSTALL ]{self.reset} Copying File in System ... -> /{self.__ad__}") | ||
|
||
copyfile('./ShareFolder.py', self.__path__) | ||
print(f"{self.progess}[ INSTALL ]{self.reset} Set command in the system -> /root/.bashrc") | ||
|
||
self.__bashrc__() | ||
|
||
print(f"{self.ok}[ OK ]{self.reset} The program was successfully installed :)") | ||
print(f"{self.progess}[ OK ]{self.reset} Restart you terminal") | ||
|
||
|
||
def install(self): | ||
self.__steps__() | ||
|
||
sharefolder() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
NOCOLOR='\033[0m' | ||
ORANGE='\033[0;33m' | ||
|
||
echo -e "Hello, ${ORANGE}$(hostname)${NOCOLOR}\n"; | ||
sudo su<<EOF | ||
python3 Linux/sharefolder_installer.py | ||
EOF |