Skip to content

Commit

Permalink
Python Source | Update
Browse files Browse the repository at this point in the history
  • Loading branch information
pyAref committed May 11, 2021
1 parent 98212cd commit f220973
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 12 deletions.
34 changes: 34 additions & 0 deletions Linux/ShareFolder.py
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()
12 changes: 0 additions & 12 deletions Linux/ShareYourFolder.py

This file was deleted.

61 changes: 61 additions & 0 deletions Linux/sharefolder_installer.py
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()
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ This script helps you to share any folder anywhere on your local network.
<br />it's possible to use the script on both:
* Windows ([Click here to download](https://github.com/Mehran-Seifalinia/ShareYourFolder/raw/main/Windows/ShareYourFolder.exe))
* Linux ([Show python source](https://raw.githubusercontent.com/Mehran-Seifalinia/ShareYourFolder/main/Linux/ShareYourFolder.py))
* ShareFolder Installer Source ([Show](https://raw.githubusercontent.com/Mehran-Seifalinia/ShareYourFolder/main/Linux/sharefolder_installer.py))
* Installer Linux ([Download]())
<hr>

# How to use
Expand All @@ -15,3 +17,16 @@ On the other computer you need to open browser then enter source system IP and i
<br />

![Image1](https://github.com/Mehran-Seifalinia/ShareYourFolder/blob/main/Image/Image(2).png)
## Example
![Image1](https://github.com/pyAref/ShareYourFolder/blob/main/Image/Image(3).png)


### Installation
<hr>

Linux
```
$ chmod +x sharefolder.sh
$ sh sharefolder.sh
$ sharefolder
```
9 changes: 9 additions & 0 deletions sharefolder.sh
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

0 comments on commit f220973

Please sign in to comment.