/**
  * @inheritdoc
  */
 public function handle($arguments)
 {
     if (!Cache::has('site-' . $arguments)) {
         $this->replyWithMessage("Não foi encontrado nenhum site com esse argumento.");
         return;
     }
     $site = Cache::get('site-' . $arguments);
     // Validate if the URL isn't on the database yet
     if (Site::where('url', '=', $site)->first() != null) {
         $this->replyWithMessage("O site {$site} já se encontra na base de dados.");
         return;
     }
     $site_obj = new Site();
     $site_obj->url = $site;
     $site_obj->save();
     $this->replyWithMessage($site . " foi adicionado à base de dados.", true);
     // Notify the sitesbloqueados.pt about the new site
     $url = 'https://sitesbloqueados.pt/wp-json/ahoy/refresh';
     $cmd = "curl -X GET -H 'Content-Type: application/json'";
     $cmd .= " " . "'" . $url . "'";
     $cmd .= " > /dev/null 2>&1 &";
     exec($cmd, $output);
     // Flush the PAC cache
     Cache::tags(['generate_pac'])->flush();
     // Remove the cache
     Cache::forget('site-' . $arguments);
     Cache::forget('site-list');
 }
Esempio n. 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $site = new Site();
     $site->name = $request->input('name');
     $site->url = $request->input('url');
     $site->user_id = $request->user()->id;
     $site->save();
     return redirect('site')->with(['msg' => '添加成功', 'type' => 'success']);
 }
Esempio n. 3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Site $site, Request $request)
 {
     $validator = Validator::make($request->all(), ['name' => 'sometimes|required', 'slug' => 'sometimes|required|max:10', 'domain_controller' => 'sometimes|required|integer', 'hex_color' => 'sometimes|required|max:6|min:6', 'type' => 'sometimes|required|max:10', 'trust' => 'sometimes|required|integer']);
     $site->name = $request->name ? $request->name : $site->name;
     $site->slug = $request->slug ? $request->slug : $site->slug;
     $site->domain_controller_id = $request->domain_controller ? $request->domain_controller : $site->domain_controller_id;
     $site->hex_color = $request->hex_color ? $request->hex_color : $site->hex_color;
     $site->type = $request->type ? $request->type : $site->_type;
     $site->trust_id = $request->trust ? $request->trust : $site->trust_id;
     if ($site->save()) {
         return $this->respondWithItem($site, new SiteTransformer());
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // Retrieve the path
     $csv_path = $this->argument('csv');
     $file = file($csv_path);
     $dry_run = $this->option('dry');
     $domains = array_map('str_getcsv', $file);
     if ($dry_run) {
         $this->warn('Running on dry-mode');
     }
     $success = 0;
     foreach ($domains as $domain) {
         // Set the time
         $date = strtotime($domain[1]);
         if ($date === false) {
             $date = time();
         }
         $date = date('Y-m-d H:i:s', $date);
         // Set the domain
         $domain = strtolower($domain[0]);
         // Domain already exists, skip.
         if (Site::where('url', '=', $domain)->first() != null) {
             $this->error(" * " . $domain . " already exists. Skipping.");
             continue;
         }
         $new_site = new Site();
         $new_site->url = $domain;
         $new_site->setCreatedAt($date);
         if ($dry_run) {
             $this->info(" * Should add " . $domain . " at " . $date . ".");
         } else {
             $this->info(" * Added add " . $domain . " at " . $date . ".");
             $new_site->save();
         }
         $success++;
     }
     $this->info("\nDone! Added {$success} new sites");
 }
Esempio n. 5
0
 /**
  * @return array|bool
  */
 public function csv()
 {
     $filename = __DIR__ . '/csv_asr.csv';
     $delimiter = ";";
     //if (!file_exists($filename) || !is_readable($filename))
     //return FALSE;
     $header = NULL;
     $data = array();
     if (($handle = fopen($filename, 'r')) !== FALSE) {
         while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
             if (!$header) {
                 $header = $row;
             } else {
                 $data[] = array_combine($header, $row);
             }
         }
         fclose($handle);
     }
     //var_dump($data);
     foreach ($data as $d) {
         $site = new Site();
         $site->name = $d['l'];
         $site->nemonico = $d['Nemonico'];
         $site->address = $d['Direccion'];
         $site->owner_id = 1;
         $site->siteid = $d['ID'];
         $site->instance = $d['Instancia'];
         $site->tecnology = $d['Tecnologia'];
         $site->emplz = $d['ID Emplz'];
         $site->comuna = $d['Comuna'];
         $site->provincia = $d['Provincia'];
         $site->region = $d['Region'];
         $site->category = $d['Categoria'];
         $site->save();
     }
     return "ok";
 }
 public function handleEditSiteinfo()
 {
     $rules = array('title' => 'required', 'logo' => 'mimes:jpeg,bmp,png', 'terms_conditions' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         $messages = $validator->messages();
         return Redirect::action('CommonController@editSiteinfo')->withErrors($validator)->withInput();
     } else {
         $site = Site::all()->first();
         if ($site == null) {
             $site = new Site();
         }
         $site->title = Input::get('title');
         $logo_val = Input::file('logo');
         if (!empty($logo_val)) {
             $extension = Input::file('logo')->getClientOriginalExtension();
             $imageName = 'logo.' . $extension;
             Input::file('logo')->move(base_path() . '/public/uploads/site/', $imageName);
             $site->logo = $imageName;
         }
         $site->terms_conditions = html_entity_decode(Input::get('terms_conditions'));
         $site->save();
         return Redirect::action('CommonController@admincontrol');
     }
 }