Merge branch 'develop' of github.com:snipe/snipe-it into develop

This commit is contained in:
snipe 2016-09-23 13:14:18 -07:00
commit c3cd329604
2 changed files with 62 additions and 34 deletions

View file

@ -231,7 +231,7 @@ class AssetsController extends Controller
$directory= public_path('uploads/assets/'); $directory= public_path('uploads/assets/');
// Check if the uploads directory exists. If not, try to create it. // Check if the uploads directory exists. If not, try to create it.
if (!file_exists($directory)) { if (!file_exists($directory)) {
mkdir($directory, 0755); mkdir($directory, 0755, true);
} }
$path = public_path('uploads/assets/'.$file_name); $path = public_path('uploads/assets/'.$file_name);
try { try {
@ -288,7 +288,7 @@ class AssetsController extends Controller
*/ */
public function getEdit($assetId = null) public function getEdit($assetId = null)
{ {
// Check if the asset exists // Check if the asset exists
if (!$asset = Asset::find($assetId)) { if (!$asset = Asset::find($assetId)) {
// Redirect to the asset management page // Redirect to the asset management page
@ -407,7 +407,7 @@ class AssetsController extends Controller
$directory= public_path('uploads/assets/'); $directory= public_path('uploads/assets/');
// Check if the uploads directory exists. If not, try to create it. // Check if the uploads directory exists. If not, try to create it.
if (!file_exists($directory)) { if (!file_exists($directory)) {
mkdir($directory, 0755); mkdir($directory, 0755, true);
} }
$file_name = str_random(25).".".$extension; $file_name = str_random(25).".".$extension;
@ -840,7 +840,7 @@ class AssetsController extends Controller
// Check if the uploads directory exists. If not, try to create it. // Check if the uploads directory exists. If not, try to create it.
if (!file_exists($path)) { if (!file_exists($path)) {
mkdir($path, 0755); mkdir($path, 0755, true);
} }
if ($handle = opendir($path)) { if ($handle = opendir($path)) {
@ -1424,7 +1424,7 @@ class AssetsController extends Controller
return View::make('hardware/labels')->with('assets', $assets)->with('settings', $settings)->with('count', $count)->with('settings', $settings); return View::make('hardware/labels')->with('assets', $assets)->with('settings', $settings)->with('count', $count)->with('settings', $settings);
} elseif (Input::get('bulk_actions')=='delete') { } elseif (Input::get('bulk_actions')=='delete') {
@ -1854,12 +1854,12 @@ class AssetsController extends Controller
$users_list = Helper::usersList(); $users_list = Helper::usersList();
// Filter out assets that are not deployable. // Filter out assets that are not deployable.
$assets = Asset::RTD()->get(); $assets = Asset::RTD()->get();
$assets_list = Company::scopeCompanyables($assets, 'assets.company_id')->lists('detailed_name', 'id')->toArray(); $assets_list = Company::scopeCompanyables($assets, 'assets.company_id')->lists('detailed_name', 'id')->toArray();
return View::make('hardware/bulk-checkout')->with('users_list', $users_list)->with('assets_list', $assets_list); return View::make('hardware/bulk-checkout')->with('users_list', $users_list)->with('assets_list', $assets_list);
} }
public function postBulkCheckout(Request $request) public function postBulkCheckout(Request $request)
{ {
@ -1869,31 +1869,31 @@ class AssetsController extends Controller
$user = User::find(e(Input::get('assigned_to'))); $user = User::find(e(Input::get('assigned_to')));
$admin = Auth::user(); $admin = Auth::user();
$asset_ids = array_filter(Input::get('selected_assets')); $asset_ids = array_filter(Input::get('selected_assets'));
if ((Input::has('checkout_at')) && (Input::get('checkout_at')!= date("Y-m-d"))) { if ((Input::has('checkout_at')) && (Input::get('checkout_at')!= date("Y-m-d"))) {
$checkout_at = e(Input::get('checkout_at')); $checkout_at = e(Input::get('checkout_at'));
} else { } else {
$checkout_at = date("Y-m-d H:i:s"); $checkout_at = date("Y-m-d H:i:s");
} }
if (Input::has('expected_checkin')) { if (Input::has('expected_checkin')) {
$expected_checkin = e(Input::get('expected_checkin')); $expected_checkin = e(Input::get('expected_checkin'));
} else { } else {
$expected_checkin = ''; $expected_checkin = '';
} }
$has_errors = false; $has_errors = false;
$errors = []; $errors = [];
DB::transaction(function() use ($user, $admin, $checkout_at, $expected_checkin, $errors, $asset_ids) DB::transaction(function() use ($user, $admin, $checkout_at, $expected_checkin, $errors, $asset_ids)
{ {
foreach($asset_ids as $asset_id) foreach($asset_ids as $asset_id)
{ {
$asset = Asset::find($asset_id); $asset = Asset::find($asset_id);
$error = $asset->checkOutToUser($user, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), null); $error = $asset->checkOutToUser($user, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), null);
if($error) if($error)
{ {
$has_errors = true; $has_errors = true;
@ -1901,12 +1901,12 @@ class AssetsController extends Controller
} }
} }
}); });
if (!$errors) { if (!$errors) {
// Redirect to the new asset page // Redirect to the new asset page
return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkout.success')); return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkout.success'));
} }
// Redirect to the asset management page with error // Redirect to the asset management page with error
return redirect()->to("hardware/bulk-checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($errors); return redirect()->to("hardware/bulk-checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($errors);
} }

View file

@ -31,9 +31,31 @@ file=master.zip
tmp=/tmp/$name tmp=/tmp/$name
fileName=snipe-it-master fileName=snipe-it-master
spin[0]="-"
spin[1]="\\"
spin[2]="|"
spin[3]="/"
rm -rf $tmp/ rm -rf $tmp/
mkdir $tmp mkdir $tmp
# Debian/Ubuntu friendly f(x)
progress () {
while kill -0 $pid > /dev/null 2>&1
do
for i in "${spin[@]}"
do
if [ -e /proc/$pid ]; then
echo -ne "\b$i"
sleep .1
else
echo -ne "\n\n"
fi
done
done
}
function isinstalled { function isinstalled {
if yum list installed "$@" >/dev/null 2>&1; then if yum list installed "$@" >/dev/null 2>&1; then
true true
@ -116,9 +138,9 @@ case $setpw in
echo -n " Q. What do you want your snipeit user password to be?" echo -n " Q. What do you want your snipeit user password to be?"
read -s mysqluserpw read -s mysqluserpw
echo "" echo ""
ans="no" ans="no"
;; ;;
*) echo " Invalid answer. Please type y or n" *) echo " Invalid answer. Please type y or n"
;; ;;
esac esac
done done
@ -149,14 +171,17 @@ case $distro in
echo "## Updating Debian packages in the background. Please be patient." echo "## Updating Debian packages in the background. Please be patient."
echo "" echo ""
apachefile=/etc/apache2/sites-available/$name.conf apachefile=/etc/apache2/sites-available/$name.conf
sudo apt-get update >> /var/log/snipeit-install.log 2>&1 sudo apt-get update >> /var/log/snipeit-install.log & pid=$! 2>&1
sudo apt-get -y upgrade >> /var/log/snipeit-install.log 2>&1 progress
sudo apt-get -y upgrade >> /var/log/snipeit-install.log & pid=$! 2>&1
progress
echo "## Installing packages." echo "## Installing packages."
sudo apt-get -y install mariadb-server mariadb-client sudo apt-get -y install mariadb-server mariadb-client
echo "## Going to suppress more messages that you don't need to worry about. Please wait." echo "## Going to suppress more messages that you don't need to worry about. Please wait."
sudo apt-get -y install apache2 >> /var/log/snipeit-install.log 2>&1 sudo apt-get -y install apache2 >> /var/log/snipeit-install.log & pid=$! 2>&1
sudo apt-get install -y git unzip php5 php5-mcrypt php5-curl php5-mysql php5-gd php5-ldap libapache2-mod-php5 curl >> /var/log/snipeit-install.log 2>&1 progress
sudo apt-get install -y git unzip php5 php5-mcrypt php5-curl php5-mysql php5-gd php5-ldap libapache2-mod-php5 curl >> /var/log/snipeit-install.log & pid=$! 2>&1
progress
# Get files and extract to web dir # Get files and extract to web dir
echo "" echo ""
@ -209,14 +234,13 @@ case $distro in
#Modify the Snipe-It files necessary for a production environment. #Modify the Snipe-It files necessary for a production environment.
echo "## Modify the Snipe-It files necessary for a production environment." echo "## Modify the Snipe-It files necessary for a production environment."
echo "## Securing Mysql" echo "## Securing Mysql"
# Have user set own root password when securing install # Have user set own root password when securing install
# and just set the snipeit database user at the beginning # and just set the snipeit database user at the beginning
/usr/bin/mysql_secure_installation /usr/bin/mysql_secure_installation
## TODO make sure mysql is set to start on boot and go ahead and start it ## TODO make sure mysql is set to start on boot and go ahead and start it
echo "Creating Mysql Database and User." echo "Creating Mysql Database and User."
echo "## Please Input your MySQL/MariaDB root password: " echo "## Please Input your MySQL/MariaDB root password: "
echo "" echo ""
@ -250,16 +274,22 @@ case $distro in
echo "" echo ""
echo "## Updating ubuntu in the background. Please be patient." echo "## Updating ubuntu in the background. Please be patient."
echo "" echo ""
echo -n "Updating with apt-get update... ${spin[0]}"
sudo apt-get update >> /var/log/snipeit-install.log & pid=$! 2>&1
progress
echo -n "Upgrading packages with apt-get upgrade... ${spin[0]}"
sudo apt-get -y upgrade >> /var/log/snipeit-install.log & pid=$! 2>&1
progress
apachefile=/etc/apache2/sites-available/$name.conf apachefile=/etc/apache2/sites-available/$name.conf
sudo apt-get update >> /var/log/snipeit-install.log 2>&1
sudo apt-get -y upgrade >> /var/log/snipeit-install.log 2>&1
echo "## Installing packages." echo "## Installing packages."
#We already established MySQL root & user PWs, so we dont need to be prompted. Let's go ahead and install Apache, PHP and MySQL. #We already established MySQL root & user PWs, so we dont need to be prompted. Let's go ahead and install Apache, PHP and MySQL.
echo "## Setting up LAMP." echo "## Setting up LAMP."
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y lamp-server^ >> /var/log/snipeit-install.log 2>&1 sudo DEBIAN_FRONTEND=noninteractive apt-get install -y lamp-server^ >> /var/log/snipeit-install.log & pid=$! 2>&1
echo ""
progress
if [ "$version" == "16.04" ]; then if [ "$version" == "16.04" ]; then
sudo apt-get install -y git unzip php php-mcrypt php-curl php-mysql php-gd php-ldap php-zip php-mbstring php-xml >> /var/log/snipeit-install.log 2>&1
sudo apt-get install -y git unzip php php-mcrypt php-curl php-mysql php-gd php-ldap php-xml php-zip php-mbstring >> /var/log/snipeit-install.log 2>&1 sudo apt-get install -y git unzip php php-mcrypt php-curl php-mysql php-gd php-ldap php-xml php-zip php-mbstring >> /var/log/snipeit-install.log 2>&1
#Enable mcrypt and rewrite #Enable mcrypt and rewrite
echo "## Enabling mcrypt and rewrite" echo "## Enabling mcrypt and rewrite"
@ -282,8 +312,6 @@ case $distro in
## TODO make sure apache is set to start on boot and go ahead and start it ## TODO make sure apache is set to start on boot and go ahead and start it
sudo ls -al /etc/apache2/mods-enabled/rewrite.load >> /var/log/snipeit-install.log 2>&1 sudo ls -al /etc/apache2/mods-enabled/rewrite.load >> /var/log/snipeit-install.log 2>&1
#Create a new virtual host for Apache. #Create a new virtual host for Apache.
@ -305,7 +333,7 @@ case $distro in
echo "## Setting up hosts file." echo "## Setting up hosts file."
echo >> $hosts "127.0.0.1 $hostname $fqdn" echo >> $hosts "127.0.0.1 $hostname $fqdn"
a2ensite $name.conf >> /var/log/snipeit-install.log 2>&1 a2ensite $name.conf >> /var/log/snipeit-install.log
cat > $webdir/$name/.env <<-EOF cat > $webdir/$name/.env <<-EOF
#Created By Snipe-it Installer #Created By Snipe-it Installer
@ -320,7 +348,7 @@ case $distro in
EOF EOF
## TODO make sure mysql is set to start on boot and go ahead and start it ## TODO make sure mysql is set to start on boot and go ahead and start it
echo "## MySQL Phase next."
# Setup Mysql, then run the command. # Setup Mysql, then run the command.
/usr/bin/mysql_secure_installation /usr/bin/mysql_secure_installation
echo "## Creating MySQL Database and user. " echo "## Creating MySQL Database and user. "