示例#1
0
 public function handle()
 {
     $users_file = $this->argument('users');
     $text_file = $this->argument('message');
     if (file_exists($users_file) == false) {
         echo "Impossibile aprire il file con le mail degli utenti coinvolti.\n";
         exit;
     }
     if (file_exists($text_file) == false) {
         echo "Impossibile aprire il file con il testo della mail di accompagnamento.\n";
         exit;
     }
     $text = file_get_contents($text_file);
     $mails = file($users_file);
     foreach ($mails as $m) {
         $m = strtolower(trim($m));
         if (empty($m)) {
             continue;
         }
         $user = User::where(DB::raw('LOWER(email)'), '=', $m)->first();
         if ($user != null) {
             $files = Cloud::getContents($user->username);
             $local_files = [];
             foreach ($files as $f) {
                 $filename = basename($f);
                 $path = sprintf('/tmp/%s', $filename);
                 $data = Cloud::readFile($user->username, $filename);
                 file_put_contents($path, $data);
                 $local_files[] = $path;
             }
             if (empty($local_files)) {
                 echo "Nessun file da spedire a " . $m . "\n";
                 continue;
             }
             foreach ($user->emails as $e) {
                 try {
                     Mail::send('emails.empty', ['text' => $user->group->mailtext], function ($m) use($user, $local_files, $e) {
                         $m->to($e, $user->name . ' ' . $user->surname)->subject('nuovo documento disponibile');
                         foreach ($local_files as $filepath) {
                             $m->attach($filepath);
                         }
                     });
                     echo $m . " - " . $e . ": OK\n";
                 } catch (\Exception $ex) {
                     echo $m . " - " . $e . ": FAILED\n";
                 }
             }
             foreach ($local_files as $f) {
                 unlink($f);
             }
         } else {
             echo "Utente non trovato per mail " . $m . "\n";
         }
         usleep(500000);
     }
 }
示例#2
0
 public function destroy($folder, $filename)
 {
     $user = Auth::user();
     if ($user->is('admin|groupadmin') && $user->testAccess($folder)) {
         Cloud::deleteFile($folder, $filename);
         return redirect(url('admin'));
     } else {
         abort(403);
     }
 }
示例#3
0
 public function index()
 {
     $user = Auth::user();
     if ($user->suspended) {
         return redirect(url('auth/logout'));
     }
     if ($user->is('admin|groupadmin')) {
         return redirect(url('admin'));
     } else {
         $data['user'] = $user;
         $data['files'] = Cloud::getContents($user->username);
         $data['groupfiles'] = Cloud::getContents($user->group->name);
         return Theme::view('home', $data);
     }
 }
示例#4
0
 public function handle()
 {
     $groupname = $this->argument('groupname');
     if ($groupname == '*') {
         $groups = Group::all();
     } else {
         $groups = Group::where('name', '=', $groupname)->get();
     }
     $pattern = $this->argument('pattern');
     foreach ($groups as $group) {
         foreach ($group->users as $user) {
             $files = Cloud::getContents($user->username, false);
             foreach ($files as $file) {
                 $filename = basename($file);
                 if (preg_match($pattern, $filename)) {
                     Cloud::deleteFile($user->username, $filename);
                     echo "Rimosso {$file}\n";
                 }
             }
         }
     }
 }
示例#5
0
 public static function testExistance($name)
 {
     $disk = Storage::disk('s3');
     $pattern = env('MATCHING_RULE', '');
     if (empty($pattern)) {
         if ($disk->exists($name)) {
             return $name;
         } else {
             return false;
         }
     } else {
         $folder = dirname($name);
         $filename = basename($name);
         $filename = preg_replace($pattern, 'X', $filename);
         $contents = Cloud::getContents($folder);
         foreach ($contents as $c) {
             $test = preg_replace($pattern, 'X', basename($c));
             if ($test == $filename) {
                 return $c;
             }
         }
         return false;
     }
 }
 public function getCount(Request $request, $folder)
 {
     $files = Cloud::getContents($folder, false);
     header('Folder-ID: ' . $folder);
     return count($files);
 }
示例#7
0
 public function handle()
 {
     $disk = Storage::disk('local');
     $storagePath = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix();
     $files = $disk->files('/');
     $rules = Rule::get();
     foreach ($files as $file) {
         try {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             Log::info('Manipolo file ' . $file);
             Event::fire(new FileToHandle($file));
             if ($disk->exists($file) == false) {
                 continue;
             }
             foreach ($rules as $rule) {
                 $target = $rule->apply($file);
                 if ($target != false) {
                     list($folder, $filename) = $target;
                     $filepath = $storagePath . $file;
                     $test = Cloud::testExistance($folder . '/' . $filename);
                     if ($test !== false) {
                         Tlog::write('files', 'File ' . $test . ' già caricato, sovrascrivo');
                         if ($this->dry_run == false) {
                             Cloud::deleteFile($folder, basename($test));
                             Cloud::loadFile($filepath, $folder, $filename);
                         }
                     } else {
                         if ($this->dry_run == false) {
                             Cloud::loadFile($filepath, $folder, $filename);
                         }
                         if (env('SEND_MAIL', false) == true) {
                             $user = User::where('username', '=', $folder)->first();
                             if ($user != null) {
                                 foreach ($user->emails as $e) {
                                     if ($this->dry_run == false) {
                                         Mail::send('emails.notify', ['text' => $user->group->mailtext], function ($m) use($user, $filepath, $e) {
                                             $m->to($e, $user->name . ' ' . $user->surname)->subject('nuovo documento disponibile');
                                             $m->attach($filepath);
                                         });
                                     }
                                     Log::info('Inviata mail a ' . $user->name . ' ' . $user->surname . ' ' . $e);
                                 }
                             } else {
                                 if ($this->dry_run == false) {
                                     $user = new User();
                                     $user->name = '???';
                                     $user->surname = '???';
                                     $user->username = $folder;
                                     $user->save();
                                 }
                                 Tlog::write('files', 'Creato nuovo utente ' . $user->username . ', necessario popolare l\'anagrafica e notificare account');
                             }
                         }
                     }
                     if ($this->dry_run == false) {
                         $disk->delete($file);
                     }
                     Tlog::write('files', 'Caricato ' . $file . ' in ' . $folder);
                     break;
                 }
             }
             if ($disk->exists($file)) {
                 Tlog::write('files', 'File ' . $file . ' non gestito');
             }
         } catch (\Exception $e) {
             Tlog::write('files', 'Errore nella manipolazione del file ' . $file . ': ' . $e->getMessage());
         }
         if ($this->dry_run == false) {
             usleep(500000);
         }
     }
 }