-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
beta --> master - Update functionality (#2)
Merged from base to master PR
- Loading branch information
Showing
6 changed files
with
235 additions
and
34 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
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
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,5 @@ | ||
<?php | ||
$phpuser = get_current_user(); | ||
echo $phpuser; | ||
return $phpuser; | ||
?> |
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,104 @@ | ||
<?php | ||
$GLOBALS['document_root'] = null; | ||
|
||
echo <<<EOL | ||
\n\n\n\n\n\n\n\n\n\n | ||
###### ###### | ||
# # # # # ## #### #### | ||
# # # # # # # # # | ||
###### # ###### # # #### #### | ||
# # # ###### # # | ||
# # # # # # # # # | ||
# # # # # #### #### | ||
\n | ||
PiPass installer | ||
\n | ||
EOL; | ||
|
||
sleep(5); | ||
|
||
echo "[ / ] Root user check...\n"; | ||
|
||
if (0 == posix_getuid()) { | ||
echo "[ + ] Root user check complete\n"; | ||
preInstall(); | ||
} else { | ||
echo "[ X ] Root user check failed. Please run the script with sudo.\n"; | ||
exit; | ||
} | ||
|
||
function preInstall() { | ||
|
||
echo "[ / ] DR check... Please enter your web document root. (e.g. /var/www/)\n"; | ||
$handle = fopen ("php://stdin","r"); | ||
$line = fgets($handle); | ||
if(trim($line)) { | ||
$GLOBALS['document_root'] = trim($line); | ||
} | ||
|
||
|
||
echo "[ / ] Is this the correct document root? (" .$GLOBALS['document_root'] .") [y/n]\n"; | ||
$handle = fopen ("php://stdin","r"); | ||
$line = fgets($handle); | ||
if(trim($line) != "y") { | ||
$GLOBALS['document_root'] = trim($line); | ||
echo "[ - ] DR check failed. Exiting...\n"; | ||
} else { | ||
if(is_dir($GLOBALS['document_root'])) { | ||
install(); | ||
} else { | ||
echo "[ - ] DR check failed. The directory does not exist. Exiting...\n"; | ||
exit; | ||
} | ||
} | ||
} | ||
|
||
function install() { | ||
echo "[ + ] DR check succeeded, now installing PiPass... \n"; | ||
echo "[ / ] Getting current php user...\n"; | ||
$GLOBALS['phpuser'] = exec('php getuser.php'); | ||
$localPU = $GLOBALS['phpuser']; | ||
echo "[ + ] Current php user is " .$GLOBALS['phpuser'] .".\n"; | ||
echo "[ / ] Building /etc/sudoers line to add...\n"; | ||
$sudoersline = "$localPU ALL=(ALL) NOPASSWD: /usr/local/bin/pihole -w *, /usr/local/bin/pihole -w -d *"; | ||
echo "[ / ] Checking if /etc/sudoers is already set up...\n"; | ||
$sudoersRes = exec("sudo cat /etc/sudoers | grep /usr/local/bin/pihole"); | ||
if(empty($sudoersRes)) { | ||
echo "[ / ] Adding line to /etc/sudoers...\n"; | ||
exec("echo '$sudoersline' | sudo tee -a /etc/sudoers"); | ||
echo "[ + ] Permissions have been set up successfully!\n"; | ||
} else { | ||
echo "[ / ] /etc/sudoers is already set up... not performing action.\n"; | ||
} | ||
echo "[ / ] Now making sure that your document root folder is clear...\n"; | ||
$drf_local = $GLOBALS['document_root']; | ||
$drfiles = exec("ls $drf_local | grep index"); | ||
if(!empty($drfiles)) { | ||
echo "[ - ] It looks like there are index files in your webroot. Such as index.php, index.html, etc. Please remove them or change their name to continue installation.\n"; | ||
exit; | ||
} | ||
|
||
echo "[ + ] In document root... downloading files.\n"; | ||
exec("cd $drf_local && sudo git clone https://github.com/roenw/pipass.git/"); | ||
echo "[ + ] Files downloaded. Selecting version v1.2b\n"; | ||
function get_data($url) { | ||
$ch = curl_init(); | ||
$timeout = 5; | ||
curl_setopt($ch, CURLOPT_URL, $url); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); | ||
$data = curl_exec($ch); | ||
curl_close($ch); | ||
return $data; | ||
} | ||
|
||
$latestVersion = get_data("https://apps.roen.us/pipass/currentversion/"); | ||
exec("cd $drf_local/pipass && sudo git checkout tags/v$latestVersion"); | ||
echo "[ + ] Selected version v1.2b\n"; | ||
echo "[ + ] Moving all files up a directory...\n"; | ||
exec("cd $drf_local && sudo mv pipass/* ."); | ||
echo "[ + ] Success.\n"; | ||
echo "[ + ] Installation complete. Please set your webserver to redirect all 404 pages to the homepage (web root). This function is not automated yet.\n"; | ||
echo "[ + ] NOTE: Make sure you fill out config.php or you will get stuck in a redirect loop!\n"; | ||
} | ||
?> |
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,86 @@ | ||
<?php | ||
$GLOBALS['document_root'] = null; | ||
|
||
echo <<<EOL | ||
\n\n\n\n\n\n\n\n\n\n | ||
###### ###### | ||
# # # # # ## #### #### | ||
# # # # # # # # # | ||
###### # ###### # # #### #### | ||
# # # ###### # # | ||
# # # # # # # # # | ||
# # # # # #### #### | ||
\n | ||
PiPass updater | ||
\n | ||
EOL; | ||
|
||
sleep(5); | ||
|
||
echo "[ / ] Root user check...\n"; | ||
|
||
if (0 == posix_getuid()) { | ||
echo "[ + ] Root user check complete\n"; | ||
preInstall(); | ||
} else { | ||
echo "[ X ] Root user check failed. Please run the script with sudo.\n"; | ||
exit; | ||
} | ||
|
||
function preInstall() { | ||
|
||
echo "[ / ] DR check... Please enter your web document root. (e.g. /var/www/)\n"; | ||
$handle = fopen ("php://stdin","r"); | ||
$line = fgets($handle); | ||
if(trim($line)) { | ||
$GLOBALS['document_root'] = trim($line); | ||
} | ||
|
||
|
||
echo "[ / ] Is this the correct document root? (" .$GLOBALS['document_root'] .") [y/n]\n"; | ||
$handle = fopen ("php://stdin","r"); | ||
$line = fgets($handle); | ||
if(trim($line) != "y") { | ||
$GLOBALS['document_root'] = trim($line); | ||
echo "[ - ] DR check failed. Exiting...\n"; | ||
} else { | ||
if(is_dir($GLOBALS['document_root'])) { | ||
update(); | ||
} else { | ||
echo "[ - ] DR check failed. The directory does not exist. Exiting...\n"; | ||
exit; | ||
} | ||
} | ||
} | ||
|
||
function update() { | ||
echo "[ + ] Backed up your config file. \n"; | ||
echo "[ + ] DR check succeeded, now updating PiPass... \n"; | ||
echo "[ + ] In document root... backing up config file.\n"; | ||
$drf_local = $GLOBALS['document_root']; | ||
exec("cd $drf_local && sudo mv config.php config.php.bak"); | ||
echo "[ + ] Collecting files...\n"; | ||
exec("cd $drf_local && sudo rm -r blockpage pipass && sudo rm index.php"); | ||
exec("cd $drf_local && sudo git clone https://github.com/roenw/pipass.git/"); | ||
function get_data($url) { | ||
$ch = curl_init(); | ||
$timeout = 5; | ||
curl_setopt($ch, CURLOPT_URL, $url); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); | ||
$data = curl_exec($ch); | ||
curl_close($ch); | ||
return $data; | ||
} | ||
|
||
$latestVersion = get_data("https://apps.roen.us/pipass/currentversion/"); | ||
echo "[ + ] Files downloaded. Selecting latest version v$latestVersion.\n"; | ||
exec("cd $drf_local/pipass && sudo git checkout tags/v$latestVersion"); | ||
echo "[ + ] Selected version v$latestVersion\n"; | ||
echo "[ + ] Moving all files up a directory...\n"; | ||
exec("cd $drf_local && sudo mv pipass/* ."); | ||
echo "[ + ] Success.\n"; | ||
echo "[ + ] Update complete.\n"; | ||
echo "[ + ] NOTE: Make sure you fill out config.php or you will get stuck in a redirect loop!\n"; | ||
} | ||
?> |